473,698 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pickle format question

The documentation says, that the output from pickle.dumps() consists of
"printable ASCII" characters. Does it mean the range from ASCII 32 to
127? Or the expected character range is different?

It would be best, if the character 127 was also excluded :-)

I need this information for creating the text file containing the
pickled Python data (strings, numbers, tuples, lists, nothing else) in
the encoded (enciphered) form.

--
Tomasz Lisowski
Jul 18 '05 #1
2 1922
Pickle output at least includes "\n" in addition to ASCII 32..126.

I believe that '\x7f' (ascii 127) will not be present in the output:
Strings are dumped in repr-like form, so ASCII 127 will be ouput as a
\x-sequence. Numbers (floats, ints and longs) are also dumped in
repr-like form, and tuples and lists use just a few printable ASCII
characters in 32..126.
string.printabl e '0123456789abcd efghijklmnopqrs tuvwxyzABCDEFGH IJKLMNOPQRSTUVW XYZ!"#$%&\'()*+ ,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c' for c in pickle.dumps([(None), {1j:1L}, "\x7f", 1, 1.]): ... if c not in string.printabl e: raise ValueError, ord(c)
...


Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFBcVmxJd0 1MZaTXX0RAgONAK CIrog9C3i8e9YCv MEYVmqaDg6qmgCg kEji
Nd7Lkv0w2uYRfc4 2yXrXotM=
=fXkp
-----END PGP SIGNATURE-----

Jul 18 '05 #2
The documentation says, that the output from pickle.dumps() consists of
"printable ASCII" characters. Does it mean the range from ASCII 32 to
127? Or the expected character range is different?

It would be best, if the character 127 was also excluded :-)

I need this information for creating the text file containing the
pickled Python data (strings, numbers, tuples, lists, nothing else) in
the encoded (enciphered) form.


Test it out on your data. Encoding those objects using:
pickle.dumps(ob j, 0)
I was not able to find any instances of character 127, but that may be
due to my data.

- Josiah

Jul 18 '05 #3

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

Similar topics

1
3503
by: A.B., Khalid | last post by:
I wonder if someone can explain what is wrong here. I am pickling a list of dictionaries (see code attached) and unpickling it back using the HIGHEST_PROTOCOL of pickle and cPickle. I am getting an error message and trace backs if the list exceeds eight items. Whether I use pickle or cPickle does not matter, i.e., the eight number causes a problem in both modules, although the trace backs are of course dissimilar. This pickling and...
14
2430
by: simonwittber | last post by:
I've written a simple module which serializes these python types: IntType, TupleType, StringType, FloatType, LongType, ListType, DictType It available for perusal here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/415503 It appears to work faster than pickle, however, the decode process is much slower (5x) than the encode process. Has anyone got any tips on
0
1781
by: Mike P. | last post by:
Hi all, I'm working on a simulation (can be considered a game) in Python where I want to be able to dump the simulation state to a file and be able to load it up later. I have used the standard Python pickle module and it works fine pickling/unpickling from files. However, I want to be able to use a third party tool like an XML editor (or other custom tool) to setup the initial state of the simulation, so I have been playing around...
8
2849
by: Gabriel Genellina | last post by:
Hello I want to convert from pickle format to python source code. That is, given an existing pickle, I want to produce a textual representation which, when evaluated, yields the original object (as if I had unpickled the pickle). I know of some transformations pickle/xml (Zope comes with one such tool, gnosis xml is another) so I believe I could build something based on them. But I dont want to reinvent the wheel, I wonder if anyone...
2
1618
by: DurumDara | last post by:
Hi ! I want to create a database from datas. I want to store my datas in lists/dicts/normal variables. I thinking about that I can use the pickle to serialize/load my datas from the file. But: I remember that in the year of 2004(?) I tried this thing. I store my CD informations in pickled objects (in files).
10
4439
by: crystalattice | last post by:
I'm creating an RPG for experience and practice. I've finished a character creation module and I'm trying to figure out how to get the file I/O to work. I've read through the python newsgroup and it appears that shelve probably isn't the best option for various reasons. This lead me to try messing w/ pickle, but I can't figure out how to use it with classes. I've found many examples of using pickle w/ non-OOP code but nothing that...
9
1315
by: tonyr1988 | last post by:
I'm a complete python n00b writing my first program (or attempting to, anyway). I'm trying to make the transition from Java, so if you could help me, it would be greatly appreciated. Here's the code I'm stuck on (It's very basic): class DemoClass: def __init__(self): self.title = def WriteToFile(self, path = "test.txt"):
3
2319
by: Jeffrey Barish | last post by:
I have a class derived from string that is used in a pickle. In the new version of my program, I moved the module containing the definition of the class. Now the unpickle fails because it doesn't find the module. I was thinking that I could make the unpickle work by putting a copy of the module in the original location and then redefine the class by sticking a __setstate__ in the class thusly: def __setstate__(self, state):...
3
6094
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")
0
144
by: Gabriel Genellina | last post by:
En Thu, 17 Jul 2008 09:40:29 -0300, <DWebre@dotd.la.govescribi�: The example doesn't have any readline(). Make sure you open the file in binary format ('wb' or 'rb'). If you have a list of objects: just write the list. It takes a single call to pickle.dump(), and later, a single call to picle.load() If you have too many objects and don't want to save/load all of them at once, write them one at a time using pickle.dump(element,...
0
8678
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9166
Oralloy
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...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7737
agi2029
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...
0
5861
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();...
0
4371
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...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.