473,396 Members | 1,921 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.

Compile the current file

9
How can I compile to a .pyc the current file by putting the command in the tool menu of Python??
Apr 17 '08 #1
7 3130
How can I compile to a .pyc the current file by putting the command in the tool menu of Python??
I'm sorry i don't understand what you mean?

The .pyc file will be generated the first time you run a python program .... eg. if you have a program called "date.py" then to run it you type "python date.py" and you should now have a "date.pyc" file in your current directory.

I don't understand what you mean about the tool menu in python? Are you using IDLE? Are you on Windows/Mac/Linux etc.?

More info please
Apr 18 '08 #2
pmstel
9
OK I need to admit it, I was not clear.

1st - I have python 2.3.5 where I added Python Win #208

In the ineractive windows of PythonWin, like any other version, you type:

import py_compile
py_compile.compile( "your_script.py" )

Saying that, this command will create your pyc file.

Now, under pull-down menu "View" clicking Option then going on tab "Tools Menu" you can add a command line there which is gonna be added to your pull down menu "Tools". I would like to incorporate the command mention above (ie: import py_compile;py_compile.compile("your_script.py")

But I just don't know how I can retrieve the actual script name loaded in memory to compile it automatically without having to type all the time:

import py_compile
py_compile.compile( "your_script.py" )

I have tried ==> import py_compile;py_compile.compile( self ) and it returns me self is not define. So I am not exactly sure how to catch on the fly the name of my script.
Apr 18 '08 #3
jlm699
314 100+
Perhaps this will help?

Expand|Select|Wrap|Line Numbers
  1. >>> import sys
  2. >>> sys.argv[0]
  3. 'C:\\Python24\\Lib\\site-packages\\wx-2.8-msw-unicode\\wx\\py\\PyCrust.py'
  4. >>>
The first element of argv is always the program name (as if typed into a console) and is the absolute path... so after a quick find and slice you'll be good to go.
Apr 18 '08 #4
pmstel
9
That works good except for one little thing. When I do the compile manually in interactive window of PythonWin, it will compile only the current last save as file. Let say I have "test_A.py" and "test_B.py" open. If I do a save as of test_B.py then I do py_compile.compile("test_B.py") I will get my pyc file. If I do right away py_compile.compile("test_A.py"), it will not work until I do a save as of "test_A.py" prior to compile it.

Now the sys.argv have work but it is not working for a second file. It works only with the first file loaded in PythonWin editor. No matter if I do a save as of another file, it will not work unless I close PythonWin and reopen PythonWin with the other file.

Any idea?? Still sys.argv work fine.
Apr 18 '08 #5
jlm699
314 100+
I've never used PythonWin but the problem is just with what file is loaded or last called... not something that I can explain here.

Anyway, what exactly does having this functionality do for you?
I can't imagine a time when this would ever be useful...
Apr 18 '08 #6
pmstel
9
I'm going back and forth in different module that I have built to add new function in it or create new one or just create a new module with new function. Those modules and function can't run stand alone in Python, they work with a specific detailing software.

So having 5 or 6 different module open, when I use save as, I need to compile them before publishing it in our detailing software database. So trying to get a shortcut to compile the last save as file will save me time. I can do that compile command many times per day. this is where is usefull for me.
Apr 18 '08 #7
pmstel
9
I finally found compielall. So in the option to set the shortcut that I mention on a previous post I have just entered the following:

Expand|Select|Wrap|Line Numbers
  1. import compileall;compileall.compile_dir('c:\\my_python_dir\\dev_dir')
This will compile all py file within the current directory specified inside the command ans all sub directory. Not to bad ;)

I still look to compile the last saved py file but at least I have a temporary workaround or permanent workaround. Who knows!
Apr 18 '08 #8

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

Similar topics

17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
5
by: Brice Prunier | last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...) The context is the following : Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema: no TargetNamespace )...
8
by: Vavel | last post by:
Hi all! I used google, but I found nothing. I have got smiple code: #include <sql.h> int main() { } when I compiled this in Borland C++ 5.5.1 for Win32 Copyright (c) 1993,
3
by: Daren Fox | last post by:
I am writing an application that will require new commands to be added while the program is still running. I thought I had found the answer in .nets compiler facilities. I would seperate my...
1
by: electrixnow | last post by:
Help!, I need to compile this code with static libs so it run on another XP machine that does'nt have MS Studio installed. When I compile now I get an ERROR: 1>------ Rebuild All started:...
0
by: %NAME% | last post by:
Hi, I am trying to create stored procedure in DB2. I am using version v7.1.0.40, on Solaris. The procedure is written in SQL PL and is very simple. However, I could not build it. I got...
7
by: news.microsoft.com | last post by:
I have an asp.net 2.0 project that when I change the build configuration to release I get the following error: Command line error BC2014: the value 'None' is invalid for option 'debug'. If I...
4
by: samueltilden | last post by:
How can I get the machine name on which the C# code is compiled and then reference that value within the executable code, as in a "Help -- Preferably embed the answer in a .dll. Worst case would...
3
by: tshad | last post by:
I have a file that I converted from VB.Net to C# that works fine in VB.Net when I compile but not in C# using the same libraries. The error I am getting is: PageInit.cs(9,7): error CS0138: A...
5
by: Torben Laursen | last post by:
Hi Is it possible to write a macro that compiles a file set (cpp/h). I can find it on the menu if I right click on a cpp file but it would be nice to just have a macro that I could call using a...
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
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...
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.