472,353 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

import pickle succeeds only after two tries??

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.
import pickle 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 import pickle
dir(pickle)

['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

Jul 18 '05 #1
2 2411
On Tue, Sep 23, 2003 at 10:59:03AM +0200, Bram Stolk wrote:
The first 'import pickle' fails with "ImportError: No module named StringIO"
If I immediately do a second 'import pickle', it works????
<snip>
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.
import foo Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "foo.py", line 1, in ?
print hello
NameError: name 'hello' is not defined import foo


--
Nick Welch aka mackstann | mack @ incise.org | http://incise.org
When you make your mark in the world, watch out for guys with erasers.
-- The Wall Street Journal

Jul 18 '05 #2
Bram Stolk wrote:
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 ---
import test 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
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: David McNab | last post by:
Hi, I'm writing a web app framework which stores pickles in client cookies. The obvious security risk is that some 5cr1p7 X1ddi35 will...
9
by: Larry goodman | last post by:
Hi, Im an old C++ salt who is doing his first large project using python/wxPython. Fantastically productive are python and wxWindows. If you could...
16
by: Manlio Perillo | last post by:
Hi. I'm a new user of Python but I have noted a little problem. Python is a very good language but it is evolving, in particular its library is...
3
by: Christoph Zwerschke | last post by:
Just hitting a strange problem with Python import behavior. It is the same on all Python 2.x versions and it is probably correct, but I currently...
1
by: Nick Coghlan | last post by:
Several standard library modules (e.g., cPickle/pickle, cStringIO/StringIO, threading/dummy_threading) have versions which may not be available on...
2
by: praveenkumar.117 | last post by:
Hi all, I am facing a problem while importing a file in python script. After doing import file i am updating that file. Later i am accessing a...
1
by: Nick Craig-Wood | last post by:
I've been dumping a database in a python code format (for use with Python on S60 mobile phone actually) and I've noticed that it uses absolutely...
0
by: =?Utf-8?B?cmVkbW9uZA==?= | last post by:
Using the below code for posting xml content throws "Badrequest (400)" and only succeeeds after 3 or 4 tries. Hugely appreciate if somebody knows...
3
by: fizilla | last post by:
Hello all! I have the following weird problem and since I am new to Python I somehow cannot figure out an elegant solution. The problem reduces to...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.