Disappearing global variables
Andrei Kulakov
ak at silmarill.org
Sat Apr 20 16:52:26 EDT 2002
Hello,
When I run book.read() method, instances that were in global namespace
disappear. I made a small function loc() that prints 0 if 'local' is in
global namespace (the name has nothing to do with namespaces - it just
means local list of books stored on hard drive). I run it right before
calling book.read() and it prints 1, I run it from inside book.read()
right after calling it, and it prints 0. I'm using python2.1.
def loc():
print 'loc',
print 'local' in globals().keys()
# method of Book class
def read(self):
"""Read the book."""
loc()
arg = ""
if self not in local.lst:
# to scroll past gutenberg licence stuff..
if viewer.endswith("vim"):
arg = "+/\*END\*"
self.download()
if last.lst and self != last.lst[-1]:
last.compress()
if self.gzip:
self.uncompress()
last.add(self)
if viewer.endswith("vim"):
# -N not fully vi-compat; -u <vimrc> use vimrc
arg = " -N -u %s %s " % (VIMRC, arg)
os.system(viewer + arg + self.l_fname)
You can look at full program at silmarill.org/pybook/pybook.py - it's
a little over 500 lines.
I have to say I'm really puzzled. Any hints?
- Andrei
--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org
More information about the Python-list
mailing list