By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,025 Members | 2,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,025 IT Pros & Developers. It's quick & easy.

Need compile python code

P: n/a
Need compile python code, source is in html and starts with parameters:

#!/bin/sh -
"exec" "python" "-O" "$0" "$@"

I have installed ActivePython for windows.

Sep 23 '06 #1
Share this Question
Share on Google+
14 Replies


P: n/a
mistral wrote:
Need compile python code, source is in html and starts with
parameters:
Excuse me?
#!/bin/sh -
"exec" "python" "-O" "$0" "$@"
Is the line break intended?
I have installed ActivePython for windows.
What exactly do you want?

Python code is always compiled (to byte code) before it's run.

Regards,
Bjrn

--
BOFH excuse #359:

YOU HAVE AN I/O ERROR -Incompetent Operator error

Sep 23 '06 #2

P: n/a

Bjoern Schliessmann писал(а):
mistral wrote:
Need compile python code, source is in html and starts with
parameters:

Excuse me?
#!/bin/sh -
"exec" "python" "-O" "$0" "$@"

Is the line break intended?
I have installed ActivePython for windows.

What exactly do you want?

Python code is always compiled (to byte code) before it's run.

Regards,
Björn

--
Just to comple python ode - it creates html page, nothing more, nothing
else.. Just generate one html page.

mistral

Sep 23 '06 #3

P: n/a

Bjoern Schliessmann писал(а):
mistral wrote:
Need compile python code, source is in html and starts with
parameters:

Excuse me?
#!/bin/sh -
"exec" "python" "-O" "$0" "$@"

Is the line break intended?
I have installed ActivePython for windows.

What exactly do you want?

Python code is always compiled (to byte code) before it's run.

Regards,
Björn

--
Just to comple python ode - it creates html page, nothing more, nothing
else.. Just generate one html page.

mistral

Sep 23 '06 #4

P: n/a
mistral wrote:
Just to comple python ode - it creates html page, nothing more, nothing
else.. Just generate one html page.
I *think* this is what you want:

python -O -m py_compile file.py
python file.pyo

See: http://docs.python.org/lib/module-pycompile.html

Regards,
Jordan

Sep 23 '06 #5

P: n/a

MonkeeSage писал(а):
mistral wrote:
Just to comple python ode - it creates html page, nothing more, nothing
else.. Just generate one html page.

I *think* this is what you want:

python -O -m py_compile file.py
python file.pyo

See: http://docs.python.org/lib/module-pycompile.html

Regards,
Jordan
----------
this not work for me, show compilation error. Is there simple way
compile pythone file? its absolutely unclear with command line. Just
show me exact command I need run(from python interactive shell?)

Sep 23 '06 #6

P: n/a
mistral wrote:
this not work for me, show compilation error. Is there simple way
compile pythone file? its absolutely unclear with command line. Just
show me exact command I need run(from python interactive shell?)
OK...

# cd to where the file.py is
$ cd /some/dir

# start python interactively, enable optimized compiling
$ python -O
....

# import your file.py -- if this doesn't work then
# your file has errors and will not compile --
# if it works then your file is now compiled --
# file.pyo should now exist with file.py
>>import file
# you can also do it explicitly --
# import the compiler
>>import py_compile
py_compiler.compile('file.py')
If that still doesn't work, show us the error, or we can't help you
very easily.

Regards,
Jordan

Sep 23 '06 #7

P: n/a
MonkeeSage wrote:
>import py_compile
py_compiler.compile('file.py')
^^^^^^^^^^^

Should be:
>>py_compile.compile('file.py')
Sep 23 '06 #8

P: n/a

MonkeeSage wrote:
mistral wrote:
this not work for me, show compilation error. Is there simple way
compile pythone file? its absolutely unclear with command line. Just
show me exact command I need run(from python interactive shell?)

OK...

# cd to where the file.py is
$ cd /some/dir

# start python interactively, enable optimized compiling
$ python -O
...

# import your file.py -- if this doesn't work then
# your file has errors and will not compile --
# if it works then your file is now compiled --
# file.pyo should now exist with file.py
>import file

# you can also do it explicitly --
# import the compiler
>import py_compile
py_compiler.compile('file.py')

If that still doesn't work, show us the error, or we can't help you
very easily.

Regards,
Jordan
---

No, something is wrong there. what I need is just compile one python
file which will generate html page, with parameters:
"exec" "python" "-O" "$0" "$@"

just need simple way do this(script is correct), i will not set any
patches anywhere, can i do this wrom normal GUI?

Sep 23 '06 #9

P: n/a
On 23 Sep 2006 12:24:58 -0700, mistral wrote
No, something is wrong there. what I need is just compile one python
file which will generate html page, with parameters:
"exec" "python" "-O" "$0" "$@"
This is not a python script. It appears to be a Unix shell script that calls a
python script.

Maybe it would help if you told us exactly what you're trying to accomplish
and why you think you need to "compile python code".

-Carsten

Sep 23 '06 #10

P: n/a
mistral wrote:
No, something is wrong there. what I need is just compile one python
file which will generate html page, with parameters:
"exec" "python" "-O" "$0" "$@"

just need simple way do this(script is correct), i will not set any
patches anywhere, can i do this wrom normal GUI?
Hmmm... Are you talking about _RUNNING_ python scripts? Is that what
you mean by "compile" -- you mean execute? Is that what this broken
shell script means?

"exec" "python" "-O" "$0" "$@"

You don't need exec, the double quote on every word breaks it, and
passing $0 (which is the shell script itself) to python is sure to
break. Try this:

#!/bin/sh
python -O "$@"

Then:

$ run_python.sh file.py arg1 arg2 arg3

Regards,
Jordan

Sep 23 '06 #11

P: n/a

MonkeeSage писал(а):
mistral wrote:
No, something is wrong there. what I need is just compile one python
file which will generate html page, with parameters:
"exec" "python" "-O" "$0" "$@"

just need simple way do this(script is correct), i will not set any
patches anywhere, can i do this wrom normal GUI?

Hmmm... Are you talking about _RUNNING_ python scripts? Is that what
you mean by "compile" -- you mean execute? Is that what this broken
shell script means?

"exec" "python" "-O" "$0" "$@"

You don't need exec, the double quote on every word breaks it, and
passing $0 (which is the shell script itself) to python is sure to
break. Try this:

#!/bin/sh
python -O "$@"

Then:

$ run_python.sh file.py arg1 arg2 arg3

Regards,
Jordan
-------
the html page just encoded within that py script. To get it, i need run
this python file.
Since i can no work with this command line, i tried via Python IDE
interface: I run this IDE, select File Run specify file name, in
'Parameters' box type parameters:

exec python -O $0 $@

and run. I got some file in output - unknown file type, then I renamed
it and got something look like a page i need. Dont know is this right
way or not, but it provided some result.. (unlike useless command line
interface)
All this extremelly inconvenient however. This ActivePython wrote in my
Registry 243 registry entries..

mistral

Sep 23 '06 #12

P: n/a

mistral wrote:
<various_othersписал(а):
There seems to be a rather large communication gap. Consider asking
your question in a Russian-speaking Python-related forum, for example:
http://zope.net.ru/

Regards,
John

Sep 23 '06 #13

P: n/a
>>>>"MonkeeSage" <Mo********@gmail.com(M) wrote:
>Mmistral wrote:
>>No, something is wrong there. what I need is just compile one python
file which will generate html page, with parameters:
"exec" "python" "-O" "$0" "$@"

just need simple way do this(script is correct), i will not set any
patches anywhere, can i do this wrom normal GUI?
>MHmmm... Are you talking about _RUNNING_ python scripts? Is that what
Myou mean by "compile" -- you mean execute? Is that what this broken
Mshell script means?
>M"exec" "python" "-O" "$0" "$@"
>MYou don't need exec, the double quote on every word breaks it, and
Mpassing $0 (which is the shell script itself) to python is sure to
Mbreak. Try this:
I guess this is a trick to use a python script as a shell script that
executes itself. In other words it is both a shell script and a python
script and when executed as a shell script then it passes itself to the
python interpreter. When executed as a python script the first line is a
comment and the second line is a string (equal to 'execpython-O$0$@'), so
both are skipped.

You can't use that in windows, or maybe there is an equivalent trick.
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Sep 25 '06 #14

P: n/a

Piet van Oostrum писал(а):
>>>"MonkeeSage" <Mo********@gmail.com(M) wrote:
Mmistral wrote:
>No, something is wrong there. what I need is just compile one python
file which will generate html page, with parameters:
"exec" "python" "-O" "$0" "$@"

just need simple way do this(script is correct), i will not set any
patches anywhere, can i do this wrom normal GUI?
MHmmm... Are you talking about _RUNNING_ python scripts? Is that what
Myou mean by "compile" -- you mean execute? Is that what this broken
Mshell script means?
M"exec" "python" "-O" "$0" "$@"
MYou don't need exec, the double quote on every word breaks it, and
Mpassing $0 (which is the shell script itself) to python is sure to
Mbreak. Try this:

I guess this is a trick to use a python script as a shell script that
executes itself. In other words it is both a shell script and a python
script and when executed as a shell script then it passes itself to the
python interpreter. When executed as a python script the first line is a
comment and the second line is a string (equal to 'execpython-O$0$@'), so
both are skipped.

You can't use that in windows, or maybe there is an equivalent trick.
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
-----------

anyway, this is a wrong and clumsy way writing of scripts, rather than
write clear and correct code comfortable to work.

mistral

Sep 25 '06 #15

This discussion thread is closed

Replies have been disabled for this discussion.