473,769 Members | 3,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bad marshal data

Hi,

I am using the marshal module in python to save a data structure to a
file. It does not appear to be portable. The data is saved on a Linux
machine. Loading that same data on a Mac gives me the bad marshal data
message.

Is this data really not portable or I am doing something wrong here. I
thought the whole point of using Python and similar cross platform
scripting languages to write once run everywhere, does that not hold
for data too?

Marshal should save the data in a readable text format, but I guess it
does not.

Any help would be appreciated,

Michael

Dec 13 '05 #1
4 6869
"Michael McGarry" <mi************ *@gmail.com> writes:
Marshal should save the data in a readable text format, but I guess it
does not.

Any help would be appreciated,


RTFM. Marshal is not intended for what you're doing. Use Pickle,
which is.
Dec 13 '05 #2
Michael McGarry <mi************ *@gmail.com> wrote:
I am using the marshal module in python to save a data structure to a
file. It does not appear to be portable. The data is saved on a Linux
machine. Loading that same data on a Mac gives me the bad marshal data
message.
If you're using identical versions of Python and exactly the same bits
in both cases, this should not happen. For example, I run on Linux,
with Python 2.4.1:
foo=open('foo', 'wb')
marshal.dump({1 :23, 2:[3,4]}, foo)
foo.close()
Then I scp foo to my Mac, and there, again with Python 2.4.1:
import marshal
marshal.load(op en('foo', 'rb'))

{1: 23, 2: [3, 4]}

It would be OK if either version was, say, 2.4.2 (compatibility is
guaranteed across bugfix-only releases), but not, e.g., 2.3.5 (no
guarantee across minor-releases).

Is this data really not portable or I am doing something wrong here. I
thought the whole point of using Python and similar cross platform
scripting languages to write once run everywhere, does that not hold
for data too?
If you need portability across Python releases, you can use pickle.
marshal is a lower-level module, intended for simple (essentially
elementary) data, to be serialized with min size, max speed.
Marshal should save the data in a readable text format, but I guess it
does not.


It most definitely should *NOT* use "readable text format", as that
would make it impossible to minimize size and maximize speed. pickle
uses an (unreadable but portable) text format by default, but the binary
format (and even more, the mode 2, most-modern pickle format) are
generally better, unless you need portability to very old Python
releases. (sharing binary data across machines is no big deal anyway;
and you can always b64-encode it if you must send it by email...).
Alex
Dec 14 '05 #3
Pickle is working well for me. I do not need speed or small file size.
Flexibility is more important for me. If speed was important I would
write the app in C.

Dec 15 '05 #4
Michael McGarry <mi************ *@gmail.com> wrote:
Pickle is working well for me. I do not need speed or small file size.
Flexibility is more important for me. If speed was important I would
write the app in C.


Coding an app in C which writes very large text files would probably be
the wrong choice for speed if the app was I/O bound (as is likely when
the files get large enough, or get pushed through some narrow bandwidth
bottleneck, e.g. on a network filesystem): using Python and writing
small binary files instead might easily get better optimization with
less effort.
Alex
Dec 15 '05 #5

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

Similar topics

1
2428
by: wbaccay | last post by:
I have a byte of binary data received from a NetworkStream (C# code) that I need to pass to the IWMWriter object in a DLL written in Managed extensions for C++ (since the Windows Media SDK is not usable in C#) whose WriteSample function takes a byte* parameter Do I need to marshal data? I thought I did, so I ran into alot of issues with converting the byte to a string and then, in the MC++ DLL, marshalling that to an IntPtr via...
1
3740
by: Marquee | last post by:
Hello, This is my first program c#, my background is c++. One thing I would like to do is put binary data (e.g. a record from disk, or network packet) in a struct. In C++ I would create the struct and memcpy() the data into it thus creating a structured overlay. The struct can have variable length e.g. struct CRecord //Just for example {
21
2578
by: Mike | last post by:
Hi, The example below shows that result of a marshaled data structure is nothing but a string >>> data = {2:'two', 3:'three'} >>> import marshal >>> bytes = marshal.dumps(data) >>> type(bytes) <type 'str'>
1
3030
by: _DD | last post by:
Existing problem: A function that runs on a thread needs to return data to the UI thread. When the data is returned, that will trigger secondary tasks, including access to form controls and lookup of data within a database. I'm not sure of the implications of using data returned by the thread within database access code, but I do know about InvokeRequired() etc for access to forms controls. I've used that often when individual...
5
5244
by: TiNo | last post by:
Hi, I have installed python two days ago on a USB memory stick (I am on the move and have no laptop.) I am on windows computers, mostly XP, all the time. Now, after pluging it in to a different computer, I get the following message when I run pyhthon: 'import site' failed; use -v for traceback
7
4083
by: Lou | last post by:
I have a class that uses the serial port class Private SerialPort as New SerialPort When I receive the asyncronous serial port response it appears that data is on a different thread than my UI. When I try to raise an event in my class my frmMain doesn't get the callback. i think this is a threading issue. Question is how do I get the serial port response from my vb class to my main form.
2
7207
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get Marshal.PtrToStructure to copy the all the data into the "other" array? unsafe public struct DeadReckoning {
2
15944
by: O.B. | last post by:
I have operation within a class that marshals the data into a byte array. Below are three different ways that work. Are there any downsides to using one over the the other? public virtual byte ToRaw1() { byte byteArray = new byte; IntPtr pointer = Marshal.AllocHGlobal(Size); Marshal.StructureToPtr(this, pointer, false); Marshal.Copy(pointer, byteArray, 0, Size);
0
1000
by: grndvl1 | last post by:
Here is what I have: I have a Structure, TM_Response that is 3 structures inside of it plus 3 other byte fields. One of the internal structures has a byte array of variable size. I am calling an unmanaged dll and the function returns bool but has pointers to the two structures you pass into it. I need help with this big time. So what will the marshaled structures look like? I have attached the code with the example and the dll too so that...
0
9589
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
10214
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
9996
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
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
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
6674
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
5304
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
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.