473,396 Members | 1,773 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,396 software developers and data experts.

Can't load bytecode with execfile ?

I have a number of files compiled to bytecode using py_compile.compile().
The .pyc files can be invoked by python directly ($python file.pyc), but
"loading" them by execfile just throws an exception ?

Any suggestions

Bo.
Jul 18 '05 #1
1 3087
Bo Jacobsen wrote:
I have a number of files compiled to bytecode using py_compile.compile().
The .pyc files can be invoked by python directly ($python file.pyc), but
"loading" them by execfile just throws an exception ?


Py> help(execfile)
Help on built-in function execfile in module __builtin__:

execfile(...)
execfile(filename[, globals[, locals]])

Read and execute a Python _SCRIPT_ from a file.
The globals and locals are dictionaries, defaulting to the current
globals and locals. If only globals is given, locals defaults to it.

(Emphasis Added)

Execfile doesn't go through the "is it bytecode?" check that the import
machinery or the -m command line switch use. It tries to interpret anything you
give it as Python source code - which is why you get a syntax error when you try
to use it on compiled bytecode.

Allowing it to handle compiled bytecode might make a reasonable feature request,
though.

Cheers,
Nick.

--
Nick Coghlan | nc******@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
Jul 18 '05 #2

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

Similar topics

2
by: Enrique | last post by:
Hello all! I've a little and no important question: Suppose 2 scripts ##ex.py### a=execfile('scr.py') print "return value: ", a ##scr.py### print "i'm scr.py"
4
by: Roman Suzi | last post by:
hi! One of my old web projects uses execfile alot, because its data are stored in Python. How do I suppress all those warnings DeprecationWarning: Non-ASCII character '\xd2' in file ffff.py...
2
by: Wensheng | last post by:
I have a py program below: -------------------------------- class someclass: def __init__(self): self.var = "hell, world" def printitout(self): execfile("printit.py") #__import__("printit")...
0
by: Enrique Palomo Jiménez | last post by:
On friday i wrote a this message: I'm writing an application who needs to handle a lot of information of several files. So, i think the better way is design a batch process to catch that...
8
by: Eric_Dexter | last post by:
I was looking for a simple way to load a simple python program from another python program. I tried os.system(cabel) The file name is cabel.py a csound instrument editor.. The error I am...
10
by: leonel.gayard | last post by:
Hi all, I have a script responsible for loading and executing scripts on a daily basis. Something like this: import time t = time.gmtime() filename = t + '-' + t + '-' + t + '.py' import...
5
by: George Sakkis | last post by:
I maintain a few configuration files in Python syntax (mainly nested dicts of ints and strings) and use execfile() to read them back to Python. This has been working great; it combines the...
2
by: Igor Kaplan | last post by:
Hello python gurus. I got quite unusual problem and all my searches to find the answer on my own were not successful. Here is the scenario: I have the python program, let's call it script1.py,...
4
by: TP | last post by:
Hello, I have a script that uses the "optparse" package to parse the command line. For example: $ script.py --help # displays help about script.py Is this possible to call such a script...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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,...
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.