IPython工作流程(编辑,运行) [英] IPython workflow (edit, run)

查看:117
本文介绍了IPython工作流程(编辑,运行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有IPython的GUI允许我打开/运行/编辑Python文件?我在IDLE中的工作方式是打开两个窗口:shell和.py文件。我编辑.py文件,运行它,并与shell中的结果进行交互。

Is there a GUI for IPython that allows me to open/run/edit Python files? My way of working in IDLE is to have two windows open: the shell and a .py file. I edit the .py file, run it, and interact with the results in the shell.

是否可以像这样使用IPython?或者有另一种工作方式吗?

Is it possible to use IPython like this? Or is there an alternative way of working?

推荐答案

当我使用python时,我通常打开两个终端窗口 - 一个是IPython,另一个是相当自定义的Vim。

When I'm working with python, I usually have two terminal windows open - one with IPython, and the other with a fairly customized Vim.

两个好的资源:

  • http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/
  • http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/

虽然听起来像你想要的是IPython的神奇功能%ed / %edit

Though it sounds like what you want is IPython's magic function %ed/%edit:

您可以做的一个示例:

In [72]: %ed
IPython will make a temporary file named: c:\docume~1\wjwe312\locals~1\temp\ipython_edit_ar8veu.py

在我放的文件中:

x = "Hello World"
print 3

保存并退出文件后:

Editing... done. Executing edited code...
3
Out[72]: "x = 'Hello world'\nprint 3\n"

In [73]: x
Out[73]: 'Hello world'

您可以定义函数或其他任何东西 - 只需请记住,当你关闭它时,文件的内容将被执行。

You can define functions or anything else - just remember that the contents of the file will be executed when you close it.

另一个类似的工作流程是 cd to包含您使用自己喜欢的编辑器编辑的Python脚本的目录。然后你可以从IPython中%run 脚本,你就可以访问文件中定义的所有内容。例如,如果您在 / home / myself 目录中的文件 test.py 中有以下内容:

Another similar workflow is to cd to the directory containing your Python script that you're editing with your favorite editor. Then you can %run the script from within IPython and you'll have access to everything defined in the file. For instance, if you have the following in the file test.py in your /home/myself directory:

    class Tester(object):
        def __init__(self):
            print "hi"

    def knightme(name):
        print "Hello, Sir ", name

然后你可以做以下事情:

Then you can do the following:

In [42]: cd /home/myself
/home/myself

In [43]: %run test.py # <Tab> autocomplete also works

In [44]: knightme('John')
Hello, Sir  John

In [45]: t = Tester()
Hi

混合或其中一个工作流程应该给你一些非常类似于你的方式习惯于在IDLE工作。

Either a mix or one of those workflows should give you something very similar to the way you're used to working in IDLE.

这篇关于IPython工作流程(编辑,运行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆