Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Converting .py files to batch files. (http://www.velocityreviews.com/forums/t635475-re-converting-py-files-to-batch-files.html)

Matias Surdi 09-15-2008 07:04 PM

Re: Converting .py files to batch files.
 
aditya shukla escribió:
> How can we convert .py files to batch files? is there any library for this?
>
>
> Aditya
>
>
> ------------------------------------------------------------------------
>
> --
> http://mail.python.org/mailman/listinfo/python-list


Maybe py2exe can help you.


Michael Palmer 09-15-2008 11:36 PM

Re: Converting .py files to batch files.
 
On Sep 15, 3:04 pm, Matias Surdi <matiassu...@gmail.com> wrote:
> aditya shukla escribió:
>
> > How can we convert .py files to batch files? is there any library for this?

>
> > Aditya

>
> > ------------------------------------------------------------------------

>
> > --
> >http://mail.python.org/mailman/listinfo/python-list

>
> Maybe py2exe can help you.


I assume you are on Windows? Let's assume you have a file stuff.py
that reads:

import os
print os.listdir('.') # list current directory, good enough for
testing...

Then, insert the following line at the top:

@setlocal enableextensions & python -x %~f0 %* & goto :EOF

Now save this file as stuff.cmd somewhere along your PATH. Now calling
'stuff' should execute your file.
On Linux, you would instead insert the shebang line that points to
your python interpreter, such as

#!/usr/bin/python

at the top and also set the executable bit, but I suppose if you use
Linux at all you know that.

Gabriel Genellina 09-16-2008 04:56 AM

Re: Converting .py files to batch files.
 
En Mon, 15 Sep 2008 20:36:05 -0300, Michael Palmer <m_palmer45@yahoo.ca>
escribió:
>> aditya shukla escribió:
>>
>> > How can we convert .py files to batch files? is there any library for

>> this?

>
> I assume you are on Windows? Let's assume you have a file stuff.py
> that reads:
>
> import os
> print os.listdir('.') # list current directory, good enough for
> testing...
>
> Then, insert the following line at the top:
>
> @setlocal enableextensions & python -x %~f0 %* & goto :EOF
>
> Now save this file as stuff.cmd somewhere along your PATH. Now calling
> 'stuff' should execute your file.


Cool! I'd enclose the first argument in quotes "%~f0" - in case the path
contains any whitespace.

--
Gabriel Genellina


r0g 09-17-2008 04:46 PM

Re: Converting .py files to batch files.
 
Michael Palmer wrote:
> On Sep 15, 3:04 pm, Matias Surdi <matiassu...@gmail.com> wrote:
>> aditya shukla escribió:
>>
>>> How can we convert .py files to batch files? is there any library for this?
>>> Aditya
>>> ------------------------------------------------------------------------

<snip>> On Linux, you would instead insert the shebang line that points to
> your python interpreter, such as
>
> #!/usr/bin/python
>
> at the top and also set the executable bit, but I suppose if you use
> Linux at all you know that.


Doh! I'm new to Linux and so I didn't know that, thanks!
One small snag though, it doesn't work on my system :-(
I did both steps, the shebang and the execute bit but nada...

r0g@steppa:~/Desktop/py$ ls
kickstart.py kickstart.py~ kicktest.py kicktest.py~
r0g@steppa:~/Desktop/py$ kickstart.py
bash: kickstart.py: command not found

Any ideas why this might be? A path thing? I'm on Ubuntu 8.04 / Py2.5

Thanks,

Roger.

r0g 09-17-2008 06:07 PM

Re: Converting .py files to batch files.
 
Grant Edwards wrote:
> On 2008-09-17, r0g <aioe.org@technicalbloke.com> wrote:
>
>> r0g@steppa:~/Desktop/py$ ls
>> kickstart.py kickstart.py~ kicktest.py kicktest.py~
>> r0g@steppa:~/Desktop/py$ kickstart.py
>> bash: kickstart.py: command not found
>>
>> Any ideas why this might be?

>
> Yes.
>
>> A path thing?

>
> Yes.
>
> Linux systems generally don't have the current directory in the
> PATH that's searched for executbles (it's regarded as a rather
> serious security problem if you do).
>
> Try doing this:
>
> ./kickstart.py
>


Brilliant! :D Thanks v.much for that, turns out the very same thing had
been driving me nuts a few days earlier when I was trying to run an
installer I had downloaded, bit of an Izzard Printer moment LOL -
http://www.youtube.com/watch?v=2wHEqDepAXo

Thanks again!

Roger.

http://www.technicalbloke.com
http://movingtoubuntu.technicalbloke.co.uk


All times are GMT. The time now is 04:04 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.