English 中文(简体)
pydev - ide就进口单元本身提出申诉
原标题:pydev - ide complains about module importing itself
  • 时间:2011-10-14 16:08:25
  •  标签:
  • python
  • pydev

www.un.org/Depts/DGACM/index_spanish.htm 我没有接受答案,因为我的真正问题是,为什么这被说成是汇编错误。 我投了“TorelTwiddler”的回答,因为他做了工作,但我想理解这个问题。


我有一个包含自我测试代码的简单模块。 为了便于在互动会议上使用,自动测试代码本身重新载荷(模块)。

在PyDev(RunAs)和互动窗口(在人工修改sys.path<>/code>和进口之后)中均使用K;但PyDev IDE仍然对线上编辑/红X错误。

import Mod1  

由于Iimport Mod1 本身的原因,该名称必须在任何情形下重新确定 。 例如,如果你从新的互动窗口进口<代码>MyMain,请上reload。 由于不知道Mod1的名字,如果没有进口,就会失败。

我是否能够确定这一点? <代码>Mod1是一个大得多的项目的一部分,其标志一贯不兼容,使得发展更加困难......

问题模块:

# Mod1.py
def Test():
    """ 
    run the self-test, but first force a reload of the module under test (this mod)
    """        
    import Mod1      # ***** COMPILE  ERROR HERE******  
    import imp
    Mod1 = imp.reload(Mod1)

    TestImpl()

def TestImpl():
    """
    self test here
    since I reload above, I can change this code and re-run from an interactive window
    this has to be a seperate function for the reload in Test to have an effect on this code
    """ 
    print(input("enter"))

只在PyDev(因此我可以操作)使用的排泄装置模块

# MyMain.py
import Mod1
Mod1.Test()

PyDev/Project PYTHONPATH (appears better, this rafter is at the fundamental of my workspace). 既然实际上在PyDev OK,那肯定是正确的?

/MyDirectory

感谢!

问题回答

如果你自行重载一个模块,就会形成一种无限的循环,因为你只能重载该模块,以便再次重载该模块。

在您的<代码>MyMain.py上 您可以这样做:

import Mod1
reload(Mod1)

Mod1.Test()

我猜测,如果不进一步编码,就很难精确测量WHY,你必须完全重载该模块,但如果你必须这样做,那就应当做到(在模块中不作此改动)。

不过,如果你更愿意保持目前的形式,那么你可以在行文结尾处添加“条码”编号“编号@ UnresoledImport,从而忽略这一错误(Ctrl-1号标本)。

在关于Snaxib的答复的讨论中添加一个单独的答复,以便格式化。

有一个作t改动的模块, 试验MyStuff,另一个单元,经您的改动更新,.

#TestMyStuff.py
def go():
    import TheTest
    reload(TheTest)
    TheTest.runTest()

以及

#TheTest.py
def runTest():
    #run my tests 以及 change things often here.
    print(input("enter"))

现在,从原封不动的炮弹中,你应当能够操作<代码>。 缩略语 试验每当其运行时重载。

我拿到了#@ UnresolvedImport通知,告诉PySide无视这一通知。 在我的案件中,没有真正的工作关系,因为在使用 pick(通过亚穆勒间接使用)时,正确的进口途径取决于一个模块是如何装载的。 如果你想从单元外挑出一个物体,如果从内部采集,就不会奏效。 自我进口给你带来了这种可能性。





相关问题
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 ]="...