Handling global variables (Newbie)
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sat Mar 15 04:25:39 EDT 2008
En Thu, 13 Mar 2008 02:25:12 -0200, David S <davids at evertech.com.au>
escribi�:
> I have an error occurring at
> self.build_root = os.path.abspath(os.path.split(__file__)[0])
>
> The error states 'NameError: global name '__file__' is not defined'
>
> In Python 2.5 I ran my script as a module in IDLE gui. How does _file_
> get
> defined?
If you type your code directly into IDLE (or the commmand line Python
interpreter) __file__ doesn't even exist; it only has any sense when the
code is read from an actual file.
Save your code on disk, let's say you name it example.py
Then you can execute it using
> python example.py
from the command line; from inside IDLE, go to File | Open, locate
example.py, press F5
--
Gabriel Genellina
More information about the Python-list
mailing list