473,704 Members | 3,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

import pickle succeeds only after two tries??

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 "ImportErro r: 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

'BufferType', 'BuiltinFunctio nType', 'BuiltinMethodT ype', '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' ,
'STOP', 'STRING', 'SliceType', 'StringType', 'StringTypes', 'TUPLE',
'TracebackType' , 'TupleType', 'TypeType', 'UNICODE',
'UnboundMethodT ype', 'UnicodeType', 'Unpickler', 'UnpicklingErro r',
'XRangeType', '_EmptyClass', '_Stop', '__all__', '__builtins__',
'__doc__', '__file__', '__name__', '__version__', '_keep_alive',
'classmap', 'compatible_for mats', 'dispatch_table ', 'format_version ',
'marshal', 'mdumps', 'mloads', 're', 'safe_construct ors', '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 2494
On Tue, Sep 23, 2003 at 10:59:03AM +0200, Bram Stolk wrote:
The first 'import pickle' fails with "ImportErro r: 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.
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 "ImportErro r: 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():

print unknown

def beta():
--- 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.

Jul 18 '05 #3

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

Similar topics

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 inevitably try tampering with the cookie and malforming it in an attempt to get the server-side python code to run arbitrary code, or something similarly undesirable. To protect against this, I've subclassed pickle.Unpickler, and added
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 bear with me, I have a couple of questions for people who have implemented python projects with similar characterstics. I'm building a client/server app where the client is a windows or linux desktop and the back end is pyhton middleware (im going to write) running on linux with a postgres SQL...
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 evolving. This can be a problem when, ad example, a module change its interface or its implementation in a fundamental way (an example: wxPython). This, I think, can be resolved by allowing an user to explicitly say what version of a module it wants (sush as version numbers in Linux shared...
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 don't understand why this happens. I have created a directory "dir" with the following three module, __init__, hello, and test2; and another module test1 in the parent directory, like that: --- test1.py ----------
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 all platforms, and pure Python fallbacks that work on any platform Python supports. Flicking through the latest version of the Python Cookbook, I noticed many recipes that included module fallback suggestions along the lines of: try: import cPickle as pickle except ImportError: import pickle
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 dictionary contained in that file. Eventhough changes are reflected in the file... When i access a dictionary those changes are not there. I believe that it is accessing from the object file that is created when i did import at the start of the script. I will be kind enough if somebody
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 tons of memory as compared to how much the data structure actually needs once it is loaded in memory. The programs below create a file (z.py) with a data structure in which looks like this -- z.py ---------------------------------------------------- z = {
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 how to fix this. oHttpRequest = (HttpWebRequest)WebRequest.Create(GlobalConfiguration.GetPartnerSetting(PARTNER_NAME, "ResidentURL")); oHttpRequest.Timeout = int.Parse(GlobalConfiguration.GetPartnerSetting(PARTNER_NAME, "GatewayTimeoutMS")); oHttpRequest.Method = "post";
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 the following question: How to pickle a collections.defaultdict object that has set the default_factory property? For Example (from the IDLE console): >>> words = collections.defaultdict(lambda: 1) >>> f = file("temp","w")
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.