import pickle succeeds only after two tries??

B

Bram Stolk

Hello,


I am using python-2.2.2 on linux-ARM.
Python itself works OK.
However, importing pickle gives me *very* strange results:

The first 'import pickle' fails with "ImportError: No module named StringIO"
If I immediately do a second 'import pickle', it works????

See this log:

Python 2.2.2 (#1, Mar 26 2003, 03:05:45)
[GCC 2.95.3 20010315 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/pickle.py", line 971, in ?
from StringIO import StringIO
ImportError: No module named StringIO['APPEND', 'APPENDS', 'BINFLOAT', 'BINGET', 'BININT', 'BININT1',
'BININT2', 'BINPERSID', 'BINPUT', 'BINSTRING', 'BINUNICODE', 'BUILD',
'BufferType', 'BuiltinFunctionType', 'BuiltinMethodType', 'ClassType',
'CodeType', 'ComplexType', 'DICT', 'DUP', 'DictProxyType', 'DictType',
'DictionaryType', 'EMPTY_DICT', 'EMPTY_LIST', 'EMPTY_TUPLE',
'EllipsisType', 'FLOAT', 'FileType', 'FloatType', 'FrameType',
'FunctionType', 'GET', 'GLOBAL', 'GeneratorType', 'INST', 'INT',
'InstanceType', 'IntType', 'LIST', 'LONG', 'LONG_BINGET', 'LONG_BINPUT',
'LambdaType', 'ListType', 'LongType', 'MARK', 'MethodType',
'ModuleType', 'NONE', 'NoneType', 'OBJ', 'ObjectType', 'PERSID', 'POP',
'POP_MARK', 'PUT', 'PickleError', 'Pickler', 'PicklingError',
'PyStringMap', 'REDUCE', 'SETITEM', 'SETITEMS', 'SHORT_BINSTRING',
'STOP', 'STRING', 'SliceType', 'StringType', 'StringTypes', 'TUPLE',
'TracebackType', 'TupleType', 'TypeType', 'UNICODE',
'UnboundMethodType', 'UnicodeType', 'Unpickler', 'UnpicklingError',
'XRangeType', '_EmptyClass', '_Stop', '__all__', '__builtins__',
'__doc__', '__file__', '__name__', '__version__', '_keep_alive',
'classmap', 'compatible_formats', 'dispatch_table', 'format_version',
'marshal', 'mdumps', 'mloads', 're', 'safe_constructors', 'struct',
'sys', 'whichmodule', 'x']

I find this extremely strange.
What could be going on here?

Thanks in advance,

Bram Stolk
 
N

Nick Welch

The first 'import pickle' fails with "ImportError: No module named StringIO"
If I immediately do a second 'import pickle', it works????
I find this extremely strange.
What could be going on here?

Not sure about the exact problem you're having with pickle, however, the
import issue you are having is a general Python issue, not specific to
pickle or anything.

death@two ~ % echo 'print hello' > foo.py
death@two ~ % python
Python 2.3+ (#2, Sep 8 2003, 20:36:54)
[GCC 3.3.1 20030626 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "foo.py", line 1, in ?
print hello
NameError: name 'hello' is not defined
 
P

Peter Otten

Bram said:
I am using python-2.2.2 on linux-ARM.
Python itself works OK.
However, importing pickle gives me *very* strange results:

The first 'import pickle' fails with "ImportError: No module named
StringIO" If I immediately do a second 'import pickle', it works????

The first import puts the module into sys.modules, then executes it.
I execution succeds, the module object is assigned to a variable in the
current global namespace, if it fails, no such assignment is performed.

The second import tries to find the module in sys.modules, finds it and
therefore does not execute it again.

The effects are strange, for example:

--- test.py ---
def alpha():
pass

print unknown

def beta():
pass
--- end test.py ---
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "test.py", line 5, in ?
print unknown
NameError: name 'unknown' is not defined
import test
dir(test) ['__builtins__', '__doc__', '__file__', '__name__', 'alpha']

Note that beta() is missing while alpha() is there. I doubt that this
behaviour is intentional.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top