[Tutor] What is `if __name__ == "__main__"` for?

2011-05-20 Thread Ganesh Kumar
Hi Gurus,

I am new python programming.. I see many programs
if __name__ == '__main__':
 when I check __name__ always eq __main__.
what purpose use these structure.. please guide me..

-Ganesh

-- 
Did I learn something today? If not, I wasted it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is `if __name__ == "__main__"` for?

2011-05-20 Thread Walter Prins
On 20 May 2011 12:09, Ganesh Kumar  wrote:

> Hi Gurus,
>
> I am new python programming.. I see many programs
> if __name__ == '__main__':
>  when I check __name__ always eq __main__.
> what purpose use these structure.. please guide me..
>
> -Ganesh


Here you go:

http://lmgtfy.com/?q=What+is+the+purpose+of+if+__name__+%3D+%27__main__%27

;)

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is `if __name__ == "__main__"` for?

2011-05-20 Thread spawgi
If the module is run as a program, then the __name__ is assigned the value
__main__ .
If the module is imported, then the value is not assigned.

Please see here -
http://stackoverflow.com/questions/419163/what-does-if-name-main-do


On Fri, May 20, 2011 at 4:39 PM, Ganesh Kumar  wrote:

> Hi Gurus,
>
> I am new python programming.. I see many programs
> if __name__ == '__main__':
>  when I check __name__ always eq __main__.
> what purpose use these structure.. please guide me..
>
> -Ganesh
>
> --
> Did I learn something today? If not, I wasted it.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
http://spawgi.wordpress.com
We can do it and do it better.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is `if __name__ == "__main__"` for?

2011-05-20 Thread Christian Witts

On 2011/05/20 01:09 PM, Ganesh Kumar wrote:

Hi Gurus,

I am new python programming.. I see many programs
if __name__ == '__main__':
  when I check __name__ always eq __main__.
what purpose use these structure.. please guide me..

-Ganesh



If you execute the script directly ie. python script.py the __name__ 
will be __main__ but if you import it it's the name of the file.


#first.py
print __name__

#second.py
import first

$ python first.py
__main__

$ python second.py
first

--
Christian Witts
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is `if __name__ == "__main__"` for?

2011-05-20 Thread Christian Witts

On 2011/05/20 01:29 PM, Christian Witts wrote:

On 2011/05/20 01:09 PM, Ganesh Kumar wrote:

Hi Gurus,

I am new python programming.. I see many programs
if __name__ == '__main__':
when I check __name__ always eq __main__.
what purpose use these structure.. please guide me..

-Ganesh



If you execute the script directly ie. python script.py the __name__
will be __main__ but if you import it it's the name of the file.

#first.py
print __name__

#second.py
import first

$ python first.py
__main__

$ python second.py
first



Sorry, forgot to add before sending that the reason I use the `if 
__name__ == '__main__'` structure is so that I can have a standalone 
application that has it's defined entry point and then if I want to 
reuse functions in the application I can import it without having to 
worry that it will execute the entire thing.


--
Christian Witts
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is `if __name__ == "__main__"` for?

2011-05-20 Thread Hilton Fernandes
Hi, Ganesh !

An important use of this feature is the so-called modular testing, aka
unit testing. I mean: that way you can provide functionality in your
module to test it independently of any application it may be contained
in.

Unit testing in general is easier and quicker to do than to test the
whole application in which any given module is contained, along with
probably lots of other modules.

The Wikipedia article Unit Testing, at
https://secure.wikimedia.org/wikipedia/en/wiki/Unit_testing

will make things clear.

All the best,
hilton

On Fri, May 20, 2011 at 8:31 AM, Christian Witts  wrote:
> On 2011/05/20 01:29 PM, Christian Witts wrote:
>>
>> On 2011/05/20 01:09 PM, Ganesh Kumar wrote:
>>>
>>> Hi Gurus,
>>>
>>> I am new python programming.. I see many programs
>>> if __name__ == '__main__':
>>> when I check __name__ always eq __main__.
>>> what purpose use these structure.. please guide me..
>>>
>>> -Ganesh
>>>
>>
>> If you execute the script directly ie. python script.py the __name__
>> will be __main__ but if you import it it's the name of the file.
>>
>> #first.py
>> print __name__
>>
>> #second.py
>> import first
>>
>> $ python first.py
>> __main__
>>
>> $ python second.py
>> first
>>
>
> Sorry, forgot to add before sending that the reason I use the `if __name__
> == '__main__'` structure is so that I can have a standalone application that
> has it's defined entry point and then if I want to reuse functions in the
> application I can import it without having to worry that it will execute the
> entire thing.
>
> --
> Christian Witts
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is `if __name__ == "__main__"` for?

2011-05-20 Thread Hilton Garcia Fernandes
Hi, Ganesh !

Adding to what Christian already stated, i'd like to tell you that an
important use of this feature is the so-called modular testing, aka
unit testing. I mean: that way you can provide functionality in your
module to test it independently of any application it may be contained
in.

Unit testing in general is easier and quicker to do than to test the
whole application in which any given module is contained, along with
probably lots of other modules.

The Wikipedia article Unit Testing, at
https://secure.wikimedia.org/wikipedia/en/wiki/Unit_testing

will make things clear.

All the best,
hilton

On Fri, Maio 20, 2011, Christian Witts  said:

> On 2011/05/20 01:29 PM, Christian Witts wrote:
>> On 2011/05/20 01:09 PM, Ganesh Kumar wrote:
>>> Hi Gurus,
>>>
>>> I am new python programming.. I see many programs
>>> if __name__ == '__main__':
>>> when I check __name__ always eq __main__.
>>> what purpose use these structure.. please guide me..
>>>
>>> -Ganesh
>>>
>>
>> If you execute the script directly ie. python script.py the __name__
>> will be __main__ but if you import it it's the name of the file.
>>
>> #first.py
>> print __name__
>>
>> #second.py
>> import first
>>
>> $ python first.py
>> __main__
>>
>> $ python second.py
>> first
>>
> 
> Sorry, forgot to add before sending that the reason I use the `if 
> __name__ == '__main__'` structure is so that I can have a standalone 
> application that has it's defined entry point and then if I want to 
> reuse functions in the application I can import it without having to 
> worry that it will execute the entire thing.
> 
> -- 
> Christian Witts
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
Hilton Garcia Fernandes
Nucleo de Tecnologias sem Fio (NTSF) -- Wireless Technologies Team
Lab de Sistemas Integraveis Tecnologico (LSI) -- Integrable Systems Lab
Escola Politecnica (Poli) -- Engineering School
Univ S Paulo (USP)
Tel: (5511)3091-5311 (work)
 (5511)8131-5213 (mobile)
Av. Prof. Luciano Gualberto,158 trav.3 CEP 05508-900
S. Paulo -- SP -- Brazil
Pagina inicial: http://www.lsi.usp.br/~hgfernan

Blog
http://bit.ly/8YITGc

com espelhamento em
http://bit.ly/4SIgzO




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] STRING PROC

2011-05-20 Thread Spyros Charonis
Hello List,

A quick string processing query. If I have an entry in a list such as
['>NAME\n'],
is there a way to split it into two separate lines:

>
NAME
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] STRING PROC

2011-05-20 Thread Alan Gauld


"Spyros Charonis"  wrote

A quick string processing query. If I have an entry in a list such 
as

['>NAME\n'],
is there a way to split it into two separate lines:




NAME


Yes if you know where the linebreak will be.

s = ">NAME\n"
twolines = [s[0],s[1:]]   # list of two strings

for line in twolines; print line

or if you really just want a newline inserted:

twolines = s[0] + '\n' + s[1:]  insert newline

or use replace:

twolines = s.replace( '>' , '>\n' )

If you want more sophistication you could
use  a regex to determine the split point.

hth,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] STRING PROC

2011-05-20 Thread spawgi
You can also try this

>>> a = '>> a
'>> a.partition('<')
('', '<', 'NAME')
>>> splitstring = a.partition('<')
>>> splitstring
('', '<', 'NAME')
>>> splitstring[0]
''
>>> splitstring[1]
'<'
>>> splitstring[2]
'NAME'

I guess you can use this tuple.

Hope this helps.

Thanks and Regards,
Sumod

On Fri, May 20, 2011 at 6:42 PM, Spyros Charonis wrote:

> Hello List,
>
> A quick string processing query. If I have an entry in a list such as
> ['>NAME\n'],
> is there a way to split it into two separate lines:
>
> >
> NAME
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
http://spawgi.wordpress.com
We can do it and do it better.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] STRING PROC

2011-05-20 Thread Alan Gauld


 wrote


a.partition('<')

('', '<', 'NAME')



Ooh! A new string method for me. I've never notioced partition before.
Thanks for posting.

Alan G.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Making a script part of the terminal

2011-05-20 Thread michael scott
Okay, my title might be undescriptive, let me try to explain it better. I want 
to take a script I've written and make it usable by typing its name in the 
terminal. Perfect example is the python interpreter. You just type in the word 
python to the terminal and then the interpreter runs. I know other programs can 
do this as well (like mozilla or nautilus or rhythmbox).  So how do I make my 
scripts executable from the terminal?

 
What is it about you... that intrigues me so?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread James Reynolds
We just had a similar question yesterday.

Just make sure Python is on your PATH. CD to the directory where your file
is located and then you can just type "python myfile.py" where myfile is the
name of your file.

On Fri, May 20, 2011 at 1:43 PM, michael scott wrote:

> Okay, my title might be undescriptive, let me try to explain it better. I
> want to take a script I've written and make it usable by typing its name in
> the terminal. Perfect example is the python interpreter. You just type in
> the word python to the terminal and then the interpreter runs. I know other
> programs can do this as well (like mozilla or nautilus or rhythmbox).  So
> how do I make my scripts executable from the terminal?
>
> 
> What is it about you... that intrigues me so?
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread Timo

On 20-05-11 19:43, michael scott wrote:
Okay, my title might be undescriptive, let me try to explain it 
better. I want to take a script I've written and make it usable by 
typing its name in the terminal. Perfect example is the python 
interpreter. You just type in the word python to the terminal and then 
the interpreter runs. I know other programs can do this as well (like 
mozilla or nautilus or rhythmbox).  So how do I make my scripts 
executable from the terminal?
I can only speak for Linux, but your script should be in a directory 
that is in the PATH variable of your environment. The reason why you can 
just enter a program name in the terminal, is because these should be in 
/usr/bin or /usr/local/bin and these are in PATH.


Type this in the terminal to see which ones:
echo $PATH

You can either put your script in one of those directories or add on to 
PATH.


Cheers,
Timo



What is it about you... that intrigues me so?


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread Edgar Almonte
hey ! i can answer that !

birst in the fist line of you script put something like this

#!/usr/local/bin/python

change the path for where you have python ( try using 'whereis python' )

sencond make the file executable add the +x attribute ( using chmod )

third  put the script in some place and and that path to the PATH
enviroment variable.

good luck


On Fri, May 20, 2011 at 1:43 PM, michael scott  wrote:
> Okay, my title might be undescriptive, let me try to explain it better. I
> want to take a script I've written and make it usable by typing its name in
> the terminal. Perfect example is the python interpreter. You just type in
> the word python to the terminal and then the interpreter runs. I know other
> programs can do this as well (like mozilla or nautilus or rhythmbox).  So
> how do I make my scripts executable from the terminal?
>
> 
> What is it about you... that intrigues me so?
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread r...@schoenian-online.de
Hello Michael,
 
first you have to give your script an executable bit. Just type chmod +x
your_script.py
Furhtermore, your script has to be in a directory that is also part of your
search path. Type in echo $PATH to see how your path is set. You can either link
or copy your script to an approprate location.
 
Regards,
Ralf 
 



michael scott  hat am 20. Mai 2011 um 19:43 geschrieben:


> 
> Okay, my title might be undescriptive, let me try to explain it better. I want
> to take a script I've written and make it usable by typing its name in the
> terminal. Perfect example is the python interpreter. You just type in the word
> python to the terminal and then the interpreter runs. I know other programs
> can do this as well (like mozilla or nautilus or rhythmbox).  So how do I make
> my scripts executable from the terminal?
> 
>  
> What is it about you... that intrigues me so?
>___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread Noah Hall
On Fri, May 20, 2011 at 6:43 PM, michael scott  wrote:
> Okay, my title might be undescriptive, let me try to explain it better. I
> want to take a script I've written and make it usable by typing its name in
> the terminal. Perfect example is the python interpreter. You just type in
> the word python to the terminal and then the interpreter runs. I know other
> programs can do this as well (like mozilla or nautilus or rhythmbox).  So
> how do I make my scripts executable from the terminal?


Since you've mentioned Linux applications, I'm going to guess you mean
on Linux only. This is easy. In Unix scripts, we use something called
a shebang. A shebang is the very first line which basically tells the
terminal what program to use to run the script. For Python, it should
be "#! /usr/bin/python" (or where ever your python interpreter is, you
can find this out by using "which python")

Hope this helps.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread michael scott
Thank you for the reply, but thats not exactly what I mean. Perhaps I should 
say, how do I install a program to my computer, so that I can use it by its 
self 
without running it with python. No matter what directory I'm in I can type 
mozilla in and it runs, no matter what directory I'm in if I type sudo 
natutilus 
it will run, no matter what directory I'm in if I type gedit it will run. 


So I'm trying to achieve this with the script I wrote. I don't know the 
terminology to ask the question correctly, so forgive me.

 
What is it about you... that intrigues me so?





From: James Reynolds 
To: michael scott 
Cc: tutor@python.org
Sent: Fri, May 20, 2011 1:57:57 PM
Subject: Re: [Tutor] Making a script part of the terminal

We just had a similar question yesterday.

Just make sure Python is on your PATH. CD to the directory where your file is 
located and then you can just type "python myfile.py" where myfile is the name 
of your file.


On Fri, May 20, 2011 at 1:43 PM, michael scott  wrote:

Okay, my title might be undescriptive, let me try to explain it better. I want 
to take a script I've written and make it usable by typing its name in the 
terminal. Perfect example is the python interpreter. You just type in the word 
python to the terminal and then the interpreter runs. I know other programs can 
do this as well (like mozilla or nautilus or rhythmbox).  So how do I make my 
scripts executable from the terminal?
>
> 
>What is it about you... that intrigues me so?
>
>
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread michael scott
Thank you gentlemen so much, I believe I have all that I need to do what I wish.

 
What is it about you... that intrigues me so?___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread ian douglas
To expand further, some distributions of Linux set a 'bin' path under 
your home folder as part of your native PATH, even if it doesn't exist.


So if your Linux username is, say, "mscott", see if "echo $PATH" already 
includes something like "/home/mscott/bin" in the path already. If so, 
simply create a bin folder:


mkdir ~/bin

and then place your Python scripts within that folder, and follow 
Edgar's other advice about adding #!/usr/local/bin/python and using 
"chmod +x filename.py" etc.


If you're on a non-Linux platform, I'm sure others can provide further help.

-id



On 05/20/2011 11:03 AM, Edgar Almonte wrote:

hey ! i can answer that !

birst in the fist line of you script put something like this

#!/usr/local/bin/python

change the path for where you have python ( try using 'whereis python' )

sencond make the file executable add the +x attribute ( using chmod )

third  put the script in some place and and that path to the PATH
enviroment variable.

good luck


On Fri, May 20, 2011 at 1:43 PM, michael scott  wrote:

Okay, my title might be undescriptive, let me try to explain it better. I
want to take a script I've written and make it usable by typing its name in
the terminal. Perfect example is the python interpreter. You just type in
the word python to the terminal and then the interpreter runs. I know other
programs can do this as well (like mozilla or nautilus or rhythmbox).  So
how do I make my scripts executable from the terminal?


What is it about you... that intrigues me so?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread Andre' Walker-Loud
Hi Michael,

You have to do three (four) things.

1 - make a directory where you want your executables to live (after you have 
created them)
on my machine, I copy everything to /usr/local/walkloud/bin/  which requires 
sudo, but you can put them anywhere in your $PATH


2 - in your .tcshrc or .cshrc or equivalent file (to figure it out, type echo 
$SHELL to figure out your shell if you have no idea what I am talking about), 
you must append your path.  eg. with tcshrc (in the .tcshrc file) - the .tcshrc 
file is located in your $HOME dir.

setenv PATH /usr/local/walkloud/bin:$PATH

3 - if you haven't, in the directory where your script lives
chmod +x your_script

4 - cp your script to this directory in 1-

launch a new terminal and it should work.


Andre



On May 20, 2011, at 11:10 AM, michael scott wrote:

> Thank you for the reply, but thats not exactly what I mean. Perhaps I should 
> say, how do I install a program to my computer, so that I can use it by its 
> self without running it with python. No matter what directory I'm in I can 
> type mozilla in and it runs, no matter what directory I'm in if I type sudo 
> natutilus it will run, no matter what directory I'm in if I type gedit it 
> will run. 
> 
> So I'm trying to achieve this with the script I wrote. I don't know the 
> terminology to ask the question correctly, so forgive me.
>  
> 
> What is it about you... that intrigues me so?
> 
> 
> From: James Reynolds 
> To: michael scott 
> Cc: tutor@python.org
> Sent: Fri, May 20, 2011 1:57:57 PM
> Subject: Re: [Tutor] Making a script part of the terminal
> 
> We just had a similar question yesterday.
> 
> Just make sure Python is on your PATH. CD to the directory where your file is 
> located and then you can just type "pythonmyfile.py" where myfile is the name 
> of your file.
> 
> On Fri, May 20, 2011 at 1:43 PM, michael scott  wrote:
> Okay, my title might be undescriptive, let me try to explain it better. I 
> want to take a script I've written and make it usable by typing its name in 
> the terminal. Perfect example is the python interpreter. You just type in the 
> word python to the terminal and then the interpreter runs. I know other 
> programs can do this as well (like mozilla or nautilus or rhythmbox).  So how 
> do I make my scripts executable from the terminal?
>  
> 
> What is it about you... that intrigues me so?
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread Joel Goldstick
On Fri, May 20, 2011 at 2:10 PM, michael scott wrote:

> Thank you for the reply, but thats not exactly what I mean. Perhaps I
> should say, how do I install a program to my computer, so that I can use it
> by its self without running it with python. No matter what directory I'm in
> I can type mozilla in and it runs, no matter what directory I'm in if I type
> sudo natutilus it will run, no matter what directory I'm in if I type gedit
> it will run.
>
> So I'm trying to achieve this with the script I wrote. I don't know the
> terminology to ask the question correctly, so forgive me.
>
>
> 
> What is it about you... that intrigues me so?
>
>
> --
> *From:* James Reynolds 
> *To:* michael scott 
> *Cc:* tutor@python.org
> *Sent:* Fri, May 20, 2011 1:57:57 PM
> *Subject:* Re: [Tutor] Making a script part of the terminal
>
> We just had a similar question yesterday.
>
> Just make sure Python is on your PATH. CD to the directory where your file
> is located and then you can just type "python myfile.py" where myfile is
> the name of your file.
>
> On Fri, May 20, 2011 at 1:43 PM, michael scott wrote:
>
>> Okay, my title might be undescriptive, let me try to explain it better. I
>> want to take a script I've written and make it usable by typing its name in
>> the terminal. Perfect example is the python interpreter. You just type in
>> the word python to the terminal and then the interpreter runs. I know other
>> programs can do this as well (like mozilla or nautilus or rhythmbox).  So
>> how do I make my scripts executable from the terminal?
>>
>> 
>> What is it about you... that intrigues me so?
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

You need to do the #!/usr/bin/env python or #!/usr/bin/python  thing in your
file
Then change it to being executable as described above
Lastly, you need to put your program in a directly where the $PATH
environment variable knows to look for it
-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread davidheiserca

I think I understand.

One thing you can do is create a "myprogram.bat" file with an entry something 
like:

python c:/myprogrampath/myprogram.py

Put the "myprogram.bat" file in the root directory or any directory in the 
PATH. Then it will behave like an executable.

In Linux, it would be "myprogram.sh" with the executable bit set.



  - Original Message - 
  From: michael scott 
  To: tutor@python.org 
  Sent: Friday, May 20, 2011 11:10 AM
  Subject: Re: [Tutor] Making a script part of the terminal


  Thank you for the reply, but thats not exactly what I mean. Perhaps I should 
say, how do I install a program to my computer, so that I can use it by its 
self without running it with python. No matter what directory I'm in I can type 
mozilla in and it runs, no matter what directory I'm in if I type sudo 
natutilus it will run, no matter what directory I'm in if I type gedit it will 
run. 

  So I'm trying to achieve this with the script I wrote. I don't know the 
terminology to ask the question correctly, so forgive me.


  
  What is it about you... that intrigues me so?





--
  From: James Reynolds 
  To: michael scott 
  Cc: tutor@python.org
  Sent: Fri, May 20, 2011 1:57:57 PM
  Subject: Re: [Tutor] Making a script part of the terminal

  We just had a similar question yesterday.


  Just make sure Python is on your PATH. CD to the directory where your file is 
located and then you can just type "python myfile.py" where myfile is the name 
of your file.


  On Fri, May 20, 2011 at 1:43 PM, michael scott  wrote:

Okay, my title might be undescriptive, let me try to explain it better. I 
want to take a script I've written and make it usable by typing its name in the 
terminal. Perfect example is the python interpreter. You just type in the word 
python to the terminal and then the interpreter runs. I know other programs can 
do this as well (like mozilla or nautilus or rhythmbox).  So how do I make my 
scripts executable from the terminal?



What is it about you... that intrigues me so?



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor






--


  ___
  Tutor maillist  -  Tutor@python.org
  To unsubscribe or change subscription options:
  http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread Alan Gauld


"michael scott"  wrote 

say, how do I install a program to my computer, so that 
I can use it by its self without running it with python. 


Just to be clear, Python programs are interpreted by 
the Python interpreter. So while you can set things up 
such that you don't need to explicitly cakll Pyhon, 
it will always be there in the background. And if 
you try to run your script on a machine that 
doesn't have Python installed it will fail.


You probably knew that already but I just want to 
set your expectations...



--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor