473,569 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't load bytecode with execfile ?

I have a number of files compiled to bytecode using py_compile.comp ile().
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 3100
Bo Jacobsen wrote:
I have a number of files compiled to bytecode using py_compile.comp ile().
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(filena me[, 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
5233
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
2177
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 on line 5, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details in one place (preferably at execfile() call)?
2
1787
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") #doesn't work
0
1012
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 information in a dictionary and write it in a file. So, after that when a user wants to retrieve something, only with an execfile i'll have all the...
8
2293
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 getting is
10
2638
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 filename
5
9374
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 convenience of pickle with the readability of Python. So far each configuration is contained in a single standalone file; different configurations are...
2
1627
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, this program needs to execute another python script, let's call it script2.py. In script1.py I have the statement: execfile('script2.py')...
4
7067
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 with execfile('') once in the Python interactive shell?
0
7693
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...
0
7605
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...
0
7917
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. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
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...
0
7962
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...
0
6277
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...
1
5501
isladogs
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...
0
3651
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...

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.