English 中文(简体)
粗略粗略项目的名称
原标题:NameError in pretty much nested project

I m having serious trouble sorting out scoping error in my project. My project looks something like this:

这份主要文件载有这一进程,并用警棍打造了全球调查。

interfaceAndProcess.pyw
import lib1
...
#do something with tkinter
filePath = askopenfilename(filetypes=(("All files", "*.*")))
...
lib1.checkSomeDocument(filePath)

然后,我有“其他平衡”职能。

moalibs.py

def parseSomething(lookForStringX)
  position = line.index(lookForStringX, 0)
  return(position)

def bla():
  ...

def blabla():
  ...

这里是使用分子方法的许多平衡之一。 y

lib1.py
from moalibs import *
def checkSomeDocument(filePath)
global line
  fileContent = open(filePath,  r )
  for line in fileContent:
    tmpVar = parseSomething(lookForStringX)
    ...
    tmpVar = bla()
    ...
    tmpVar = blabla()
    ...
    tmpVar = bla()
    # In any of my many libs the methods from moalib are called
    # serveral times in different orders, that s why this part
    # is pretty "hard coded"
    

我的问题是,实施接口。 pyw向以下线投掷了名词:“名称线没有界定”。

为什么可以打上<条码>。 见《瓦尔<条码>。

当我把<代码>parseSomething列入moalibs.py。 正在做的是罚款。

I m sorry for this question to be pretty specific but I m searching and trying for for more than two hours now. Been playing with global line inside the methods, been defining line inside interfaceAndProcess.pyw, nothing...

任何建议?

Edit: Ok, I understood that what I have tried can t work as I expected. How would I achieve this without passing the variable as an argument?

问题回答

对于开端人来说,global keyword isn t do any for a changing have been used in the high-level namespace (as is line in this case). The Stack Overflow question Discussiones why.

您重新获得姓名是因为lib1.py 进口<代码>moalibs.py,而不是副面。 页: 1 页: 1

To see what I mean, you can ask each module to tell you its current namespace contents by using the dir() function. You ll find that lib1.py is fully aware of all of moalibs.py s identifiers, but moalibs.py is not aware of lib1.py s identifiers.





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