473,395 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

"compile()" portability

Vio
I would like to know if executing:

c = compile('a=5\nprint a','<string>','exec')
on a Linux box, then pickling+beaming the result on a Windows box, will give me the expecting result:
exec(c)

5

In other words, does 'compile()' generate platform-dependent code?

Regards,
Vio


Jul 18 '05 #1
2 1632
In article <ma************************************@python.org >,
Vio <vm*******@sympatico.ca> wrote:
I would like to know if executing:

c = compile('a=5\nprint a','<string>','exec')
on a Linux box, then pickling+beaming the result on a Windows box, will give
me the expecting result:
exec(c)

5

In other words, does 'compile()' generate platform-dependent code?


If you mean "marshal" instead of "pickle", and use the same (major)
Python version on both ends, then yes.

Just
Jul 18 '05 #2
Just wrote:
I would like to know if executing:

c = compile('a=5\nprint a','<string>','exec')

on a Linux box, then pickling+beaming the result on a Windows box, will give
me the expecting result:
>> exec(c)

5

In other words, does 'compile()' generate platform-dependent code?


If you mean "marshal" instead of "pickle", and use the same (major)
Python version on both ends, then yes.


to make sure both sites are using the same byte code revision,
check the imp.get_magic() string.

something like this should work:

code = compile(...)
data = imp.get_magic() + marshal.dumps(code)

...

magic = imp.get_magic()
if not data.startswith(magic):
raise ValueError("cannot run this bytecode")
code = marshal.loads(data[len(magic):])

(len(magic) is currently 4, and will probably remain so for the
foreseeable 2.X future, but one never knows what happens in
3.X...)

</F>


Jul 18 '05 #3

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

Similar topics

2
by: Alexander Bartzas | last post by:
I'm trying to compile route.cpp part of the NetBench Suite (UCLA) and...: > g++ packet.cpp radix.cpp route.cpp -o route There is no problem in the compilation of the code but when I try to run...
22
by: Qopit | last post by:
Hi there, I'm pretty new to Python and am trying to figure out how to get "will this code compile?"-like code checking. To me this is a pretty basic language/environment requirement, especially...
1
by: Steve | last post by:
I get this message when I tried to make a .MDE of my database. "Compile error in hidden module: Form_frmPurchaseReq" I have been using this database for several months and just thought I would...
3
by: Randy Yates | last post by:
How-to-do? -- % Randy Yates % "And all that I can do %% Fuquay-Varina, NC % is say I'm sorry, %%% 919-577-9882 % that's the way it goes..." %%%%...
10
by: Chris LaJoie | last post by:
Our company has been developing a program in C# for some time now, and we haven't had any problems with it, but just last night something cropped up that has me, and everyone else, stumped. I...
2
by: Happy Li | last post by:
Need help! I have a project with one crystal report. How can I compile it with csc.exe. I have tried the following command line .it compile successfully..but when I run, it display error 'Unable...
2
by: Lasse Edsvik | last post by:
Hello was wondering, lets say i have like 1000 asp.net pages on a serv, and i need to reboot server, will all pages need to be recompiled with that jit-thing so it would take 1-4 secs to load...
16
by: John Kelsey | last post by:
Back in the "old" days with C, I used to do something like... struct { char Description; float price; } Items = { {"Apple", 1.99}, {"Banana", 2.04}
2
by: yinglcs | last post by:
I have the following code, which use template as the parent class of my other class. But I have "instantiated from here" compile error at this line: class C: public B2<A>. Can some one...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.