English 中文(简体)
• 如何在IPython展示动态创作的源代码(“cus”)?
原标题:How to show source code for dynamically created ("custom") function in IPython?

在IPython会议上,我通常界定习俗职能......有时,我想看到这些职能的实际守则。 迄今为止,我未能找到办法显示这一点。 如何使用? 简单地说,回报是“以数字方式产生的功能”。 无源代码 是否有办法显示用户界定职能的源代码?

问题回答

如果你寻找来源,以互动方式界定职能,你可以发现在“iPython”历史上对它的最新定义:

[i for (i, l) in  enumerate(_ih) if l.startswith( def foo( )][-1]

那么,你就可以将这一条线推上:

%edit 42

它打开了“灯塔”或带有功能定义的另一版主。

或者,你可以保存档案:

%save foo.py 42

我正在使用Python 2.7.4和IPython0.13.2。

在职能名称之前,我可以看到在iPython使用的动态功能的来源?:

In [8]: ??sort_words
Type:       function
String Form:<function sort_words at 0x189b938>
File:       /tmp/ipython_edit_yc1TIo.py
Definition: sort_words(s)
Source:
def sort_words(s):
    x = re.findall(r W+(w+) , s)
    x.sort()
    for i in x:
        print i

可否在更新的版本的iPython中提供这种信息? 你们使用什么版本?

搜索历史:

In [22]: for l in _ih:
   ....:     if l.startswith( def f ):
   ....:         print l
   ....:         
   ....:         
def f():
    a= 1
    b = 2
    return a*b

虽然这是非常基本的情况,但较好的版本将压制/管理历史,看你能否恢复功能。

如果:

  • 这些方案由另一个职能创建。 在这种情况下,当事人没有来源法,根本不存在。

  • 他们在不同的名称空间中被提及,没有资料说明他们原先的哪一个名称空间。 在该案中,他们最初是和经营的? 来自那里。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签