nameerror

Python class NameError. Var is not defined [duplicate]

左心房为你撑大大i 提交于 2021-02-17 07:10:43
问题 This question already has answers here : Short description of the scoping rules? (9 answers) How can I access “static” class variables within class methods in Python? (6 answers) Closed 3 years ago . class Gui(): var = None def refreshStats(args): print(str(var)) clas = Gui() clas.refreshStats() Trace File "sample.py", line 5, in refreshStats print(str(var)) NameError: name 'var' is not defined. Why? 回答1: If you want your variables to be visible within the scope of your class functions, pass

NameError: global name 'NAME' is not defined

好久不见. 提交于 2021-02-08 07:04:14
问题 I have been having an interesting time building a little web scraper and I think I am doing something wrong with my variable or function scope. Whenever I try to pull out some of the functionality into separate functions it gives me the NameError: global name 'NAME' is not defined. I see that a lot of people are having a similar problem but there seems to be a lot of variation with the same error and I can't figure it out. import urllib2, sys, urlparse, httplib, imageInfo from BeautifulSoup

Python NameError when using an imported function

我的未来我决定 提交于 2021-02-05 11:51:35
问题 When I import and use a function in a python(2.6.5) program, I get an error: from Localization import MSGR title = Localization.MSGR("Logfile from Ctf2Rrl.") NameError: global name 'Localization' is not defined Could you please explain why? Regards, 回答1: If you import your method like this, you can user MSGR but not Localization.MSGR :) If you want to use Localization.MSGR , you can just import Localization 回答2: The import statement of the form: from foo import bar Doesn't introduce the

Python NameError when using an imported function

。_饼干妹妹 提交于 2021-02-05 11:50:56
问题 When I import and use a function in a python(2.6.5) program, I get an error: from Localization import MSGR title = Localization.MSGR("Logfile from Ctf2Rrl.") NameError: global name 'Localization' is not defined Could you please explain why? Regards, 回答1: If you import your method like this, you can user MSGR but not Localization.MSGR :) If you want to use Localization.MSGR , you can just import Localization 回答2: The import statement of the form: from foo import bar Doesn't introduce the

Python NameError: name is not defined (related to having default input argument types)

拟墨画扇 提交于 2021-02-05 07:43:55
问题 I have a problem with the fact that I am calling len(myByteArray) in the input arguments to a function I am declaring. I'd like that to be a default argument, but Python doesn't seem to like it. myByteArray is of type bytearray . See documentation on bytearray here. I am accessing its built-in find function, documented here (see "bytes.find"). My function: def circularFind(myByteArray, searchVal, start=0, end=len(myByteArray)): """ Return the first-encountered index in bytearray where

Python NameError: name is not defined (related to having default input argument types)

百般思念 提交于 2021-02-05 07:43:13
问题 I have a problem with the fact that I am calling len(myByteArray) in the input arguments to a function I am declaring. I'd like that to be a default argument, but Python doesn't seem to like it. myByteArray is of type bytearray . See documentation on bytearray here. I am accessing its built-in find function, documented here (see "bytes.find"). My function: def circularFind(myByteArray, searchVal, start=0, end=len(myByteArray)): """ Return the first-encountered index in bytearray where

NameError within class definition

你说的曾经没有我的故事 提交于 2021-02-04 08:34:07
问题 I wanted to define a class as follows: class ConfigManager: @classmethod def load_config(cls): # do some complex stuff to load something return config __CONFIG = ConfigManager.load_config() @classmethod def get_config(cls): return cls.__CONFIG And then when I run the following code, it reports a NameError : x = ConfigManager.get_config() Traceback (most recent call last): File "test.py", line 1, in <module> class ConfigManager: File "test.py", line 7, in ConfigManager __CONFIG = ConfigManager

How to ref a TextInput from one screen in another screen in Kivy/Python?

狂风中的少年 提交于 2021-01-29 18:41:03
问题 I'm trying to make an app that can calculate the volume of a cone(so far). I have a screen named ConeVolumeScreen that has two TextInput widgets. <ConeVolumeScreen>: BoxLayout: orientation: ... padding: ... spacing: ... Label: text: 'Radius:' TextInput: id: cone_vol_radius multiline: False input_type: 'number' Label: text: 'Height:' TextInput: id: cone_vol_height multiline: False input_type: 'number' Button: text: 'Solve' on_release: app.root.changeScreen('solve cone volume') A person is

python import results in nameerror

梦想的初衷 提交于 2021-01-29 08:53:05
问题 This seems pretty basic, so I must be missing something obvious. Goal is to import a module from the same directory. I've broken it down about as simple as I can and I'm getting the nameerror . file import_this.py : def my_function(number) : print number + 2 file import_test.py : import import_this my_function(2) Do I have to specify the directory the import file is in? (It's in the same as the test file). Also, can I test to see what modules are imported? 回答1: You are accessing the function

Newbie inquiry about NameError

杀马特。学长 韩版系。学妹 提交于 2020-11-30 02:08:50
问题 Total Newbie question for which I have searched the site. I am running a really simple program in Chapter 2 of Automate the Boring Stuff and I keep getting a NameError. The first line is if name == 'Alice': And it results in NameError: name 'name' is not defined Any thoughts on this. Cannot find this NameError in the index or any sites. Thanks 回答1: In the book you missed this comment above the code: " (Pretend name was assigned some value earlier.) ". So you need to do that. For example