Issue1053604
Created on 2004-10-25 09:06 by markus_gritsch, last changed 2004-10-26 01:50 by rhettinger. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg22843 - (view) | Author: Markus Gritsch (markus_gritsch) | Date: 2004-10-25 09:06 | |
The following short script produces a "SyntaxWarning:
name 'cPickle' is assigned to before global
declaration", which is IMO not correct.
mode = 'pickle'
def main():
if mode == 'pickle':
global cPickle
import cPickle
elif mode == 'socket':
global cPickle, socket
import cPickle, socket
elif mode == 'sqlite':
global sqlite
import sqlite
else:
print 'Warning: Unknown mode.'
def test():
print cPickle.__doc__
if __name__ == '__main__':
main()
test()
|
|||
| msg22844 - (view) | Author: Jim Jewett (jimjjewett) | Date: 2004-10-25 21:59 | |
Logged In: YES user_id=764593 The indenting was lost. If I guess correctly, cPickle is global for modes pickle and socket, but not otherwise. The problem is that it imports cpickle (for mode pickle) before running the global cpickle (for mode socket). It would be nice if the interpreter were smart enough to realize that the paths are exclusive, but I'm inclined to call it a feature request rather than a bug. |
|||
| msg22845 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2004-10-26 01:50 | |
Logged In: YES user_id=80475 Sorry, this isn't a bug. Per the language reference, the global statement is not executed like other python statements. Instead, it is a parser directive. Hence, it doesn't matter whether the globals are wrapped inside if blocks. The presence of the first occurrence of cPickle is sufficient to define so that the subsequently parsed (not executed) global directive cannot work. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2004-10-25 09:06:43 | markus_gritsch | create | |
