Python函数定义在控制台中工作,但不能导入到ipython笔记本中

Python函数定义在控制台中工作,但不能导入到ipython笔记本中,python,ipython,ipython-notebook,Python,Ipython,Ipython Notebook,我正在为一个项目开发一些助手函数,我倾向于使用ipython笔记本来帮助开发。无论如何,我遇到了一个奇怪的情况,我的函数定义是从python控制台、ipython控制台工作的,或者如果我将函数定义粘贴到ipython笔记本单元中 但是,每当我试图从ipython笔记本中加载模块并随后运行该函数时,我都会出现以下错误。此外,如果我从控制台运行函数并像往常一样导入,或者在ipython控制台中导入,那么一切都可以正常工作。我可以导入该函数,它可以正常工作 为了清楚起见,我实际上可以将该函数导入ipy

我正在为一个项目开发一些助手函数,我倾向于使用ipython笔记本来帮助开发。无论如何,我遇到了一个奇怪的情况,我的函数定义是从python控制台、ipython控制台工作的,或者如果我将函数定义粘贴到ipython笔记本单元中

但是,每当我试图从ipython笔记本中加载模块并随后运行该函数时,我都会出现以下错误。此外,如果我从控制台运行函数并像往常一样导入,或者在ipython控制台中导入,那么一切都可以正常工作。我可以导入该函数,它可以正常工作

为了清楚起见,我实际上可以将该函数导入ipython笔记本,但在导入后实际运行该函数会产生以下错误。其中,在导入和运行同一函数时,ipython笔记本以外的其他方法不会产生相同的错误,尽管代码完全相同

TypeError                                 Traceback (most recent call last)
<ipython-input-53-f4cd5ccd5841> in <module>()
----> 1 fr(100, 1000, c_unit='micro', i_unit='micro')

TypeError: resonant_frequency() got an unexpected keyword argument 'c_unit'

导入数学后对我来说很好。共振频率1001000,c_unit='micro',i_unit='micro'返回503.2921210448704。是否加载了该函数没有c_unit关键字的模块的早期版本?如果是这样,这可能是一个常见问题:导入时没有重新加载模块,您需要尝试重新加载或退出并重新启动IPython,然后导入更新的模块。@F先生,您是对的。最初,我加载了一个不包含kwargs的版本,这样才有意义。我关闭了笔记本,重新加载了所有内容,现在一切正常了。非常感谢。
def resonant_frequency(capacitance, inductance, c_unit='base', i_unit='base'):
    ''' *** electronics.electronics.py
        * Useful for LC circuit work
        * Both the capacitance and inductance should be in there
          base measurment units. I.e. 100 uHz (micro-hertz) should 
          be 0.0001 Hz etc.

        * Resonant frequency equation is fr = 1 / (2Pi * squrt(capacitance * inductance))

        **********************************************************************************
        TODO make this function discriminate bewtween units so that a unit can be suffixed
        to the output, irregardless of what the inputs were (strings with unit suffixes in
        this case )
        **********************************************************************************
        Unit Table
        ----------

        |Text|Symbol|Factor|
        --------------------
        tera    T      1 000 000 000 000
        giga    G      1 000 000 000
        mega    M      1 000 000
        kilo    k      1 000
        hecto   h      1 00
        deca    da     10 # prob. will not ever use this but it's here
        (none)  (none) 1
        deci    d      0.1
        centi   c      0.01
        milli   m      0.001
        micro   µ      0.000 001 # the letter 'u' can be used here
        nano    n      0.000 000 001
        pico    p      0.000 000 000 001

        *******************************************

        **kwargs can be 'base' (automatic) or any of the prefix
        letters of above

        '''
    # convert capacitance and inductance from strings
    # to there respective base values
    units = {
        'T'   : 1000000000000,
        'G'   : 1000000000,
        'M'   : 1000000,
        'k'   : 1000,
        'h'   : 100,
        'da'  : 10,
        'base': 1,
        'd'   : .1,
        'c'   : .01,
        'm'   : .001,
        'u'   : .000001,
        'n'   : .000000001,
        'p'   : 0.000000000001
    }

    units1 = {
        'tera'   : 1000000000000,
        'giga'   : 1000000000,
        'mega'   : 1000000,
        'kilo'   : 1000,
        'hecta'  : 100,
        'deca'   : 10,
        'base'   : 1,
        'deci'   : 0.1,
        'centi'  : 0.01,
        'milli'  : 0.001,
        'micro'  : 0.000001,
        'nano'   : 0.000000001,
        'pico'   : 0.000000000001
    }

    # This should return frequency in Hz 
    if c_unit == 'base' and i_unit == 'base':
        return 1/((2*math.pi) * math.sqrt(float(capacitance) * float(inductance)))  

    elif c_unit in units and i_unit in units:
        return  1/((2*math.pi) * math.sqrt((float(capacitance)* units[c_unit])\
                * (float(inductance)*units[i_unit])))

    elif c_unit in units1 and i_unit in units1:
        return 1/((2*math.pi) * math.sqrt((float(capacitance)* units1[c_unit])\
                * (float(inductance)*units1[i_unit])))