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

Newbie: Compiling a Python Script

I am new to python and I am wondering if there is a way to take a python script and turn it into an object of some kind such that the python system doesn't have to take the script and compile it down to python code every time i try to run the script in my program.

I have a lot of scripts and they are getting used a lot so this is a performance question really.

If anybody knows how to take the .py file and "compile" it into byte code that i can pass to python directly I would appreciate it. I have seen people talk about compiling the script but it seems like it is a pre-run time operation and I need something that is during run time because my scripts can change during run time if the user wants.
Mar 10 '07 #1
2 1655
bartonc
6,596 Expert 4TB
I am new to python and I am wondering if there is a way to take a python script and turn it into an object of some kind such that the python system doesn't have to take the script and compile it down to python code every time i try to run the script in my program.

I have a lot of scripts and they are getting used a lot so this is a performance question really.

If anybody knows how to take the .py file and "compile" it into byte code that i can pass to python directly I would appreciate it. I have seen people talk about compiling the script but it seems like it is a pre-run time operation and I need something that is during run time because my scripts can change during run time if the user wants.
Ok, let's see if I can make this clear.
Modules (scripts) are only compiled after they have been changed (or created the first time, of course). It is possible to treat modules as objects, but the goal you are after is taken care of automaticly. Any time your script does
Expand|Select|Wrap|Line Numbers
  1. import moduleA
python checks to see if has been modified and compiles it if it has been. You can prove this by removing the .py file so that moduleA.pyc is all that's left in the directory that you are working in. The import will still work.
Have fun and keep posting,
Barton
PS, welcome to the Python Forum on TheScripts.com.
Mar 10 '07 #2
bartonc
6,596 Expert 4TB
Ok, let's see if I can make this clear.
Modules (scripts) are only compiled after they have been changed (or created the first time, of course). It is possible to treat modules as objects, but the goal you are after is taken care of automaticly. Any time your script does
Expand|Select|Wrap|Line Numbers
  1. import moduleA
python checks to see if has been modified and compiles it if it has been. You can prove this by removing the .py file so that moduleA.pyc is all that's left in the directory that you are working in. The import will still work.
Have fun and keep posting,
Barton
PS, welcome to the Python Forum on TheScripts.com.
I've been clocking an app packed into an exe with py2exe vs a many-module version of the same program. Clock speeds are the same in both cases.
Mar 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mike S. | last post by:
Hello, Has anyone had success compiling the informixdb-1.3 module under python 2.2? It seems the absense of makefile.pre.in in python 2.2 causes the break under py2.2. Is there an easy way...
2
by: Giraud, Sebastien | last post by:
Ok I was still looking for a 'make like' software and found one : MacMillan Entreprise Just work fine even if it's not easy to handle it... -----Message d'origine----- De :...
0
by: phoolimin | last post by:
Dear all, I am trying to embed python into another scripting language, to do this I need to solve a number of problems on importing or compiling python script. First let me state what exactly I...
2
by: Luis Speciale | last post by:
Hi I'm trying to build mod_pyton on Leopard 10.5.4 on a Mac G5 with this cvs version http://svn.apache.org/repos/asf/quetzalcoatl/mod_python/trunk with this Python python Python 2.5.2...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.