iPython debugger raises `NameError: name … is not defined`
A possible solution/workaround is to run globals().update(locals()) before running the list comprehension in (i)pdb.
A possible solution/workaround is to run globals().update(locals()) before running the list comprehension in (i)pdb.
Python doesn’t scope code to the local class automatically; you need to tell it to. pp = self.foobar(arg1, arg2) http://docs.python.org/tutorial/classes.html
Since test() doesn’t know who is abc, that msg NameError: global name ‘abc’ is not defined you see should happen when you invoke b.test() (calling b.abc() is fine), change it to: class a: def abc(self): print “haha” def test(self): self.abc() # abc() b = a() b.abc() # ‘haha’ is printed b.test() # ‘haha’ is printed
You need to call self.a() to invoke a from b. a is not a global function, it is a method on the class. You may want to read through the Python tutorial on classes some more to get the finer details down.
Define the class before you use it: class Something: def out(self): print(“it works”) s = Something() s.out() You need to pass self as the first argument to all instance methods.
In Python 3.x, use int instead of long. From What’s New In Python 3.0, Integers: PEP 237: Essentially, long renamed to int. That is, there is only one built-in integral type, named int; but it behaves mostly like the old long type.
Guessing on the basis of whatever little information provided in the question, I think you might have forgotten to add the following import in your urls.py file. from django.conf.urls import include
This error comes when you append this line os.path.join(os.path.dirname(__file__)) in python interactive shell. Python Shell doesn’t detect current file path in __file__ and it’s related to your filepath in which you added this line So you should write this line os.path.join(os.path.dirname(__file__)) in file.py. and then run python file.py, It works because it takes your filepath.
Python 3 renamed the unicode type to str, the old str type has been replaced by bytes. if isinstance(unicode_or_str, str): text = unicode_or_str decoded = False else: text = unicode_or_str.decode(encoding) decoded = True You may want to read the Python 3 porting HOWTO for more such details. There is also Lennart Regebro’s Porting to Python … Read more
Default argument values are evaluated at function define-time, but self is an argument only available at function call time. Thus arguments in the argument list cannot refer each other. It’s a common pattern to default an argument to None and add a test for that in code: def p(self, b=None): if b is None: b … Read more