[Tutor] Tkinter and python

Arun Kumar PG arunkumarpg at gmail.com
Mon Oct 9 06:01:03 CEST 2006


> python <module.py> on the command prompt/bash shell the script gets
> executed.

Hey Dave,

Thanks for correcting me. I should read what I am writing before I hit the
send button :). It was a stupid mistake..

Appending path to PYTHONPATH will allow us to import the module in some
other Python script without requiring us to do sys.path.apend(). To execute
the script from bash what Dave suggests is correct.

Also, if you don't want to append path to PYTHONPATH you can also place the
module under site-packages directory under Python home directory.

Thanks,

- A

On 10/8/06, Dave Kuhlman <dkuhlman at rexx.com> wrote:
>
> On Sun, Oct 08, 2006 at 08:36:31PM +0530, Arun Kumar PG wrote:
> > Hi,
> >
> > You can try:
> >
> > >>import sys
> > >>sys.path.append('<absolute_path_to_program_dir>')
> > >>import <module.py>
> >
> > Or else you can append the path to global PYTHONPATH environment
> variable
> > and whenever you will type:
> >
> > python <module.py> on the command prompt/bash shell the script gets
> > executed.
> >
>
> Not true, if I understand you correctly.  PYTHONPATH affects where
> Python looks for modules to be imported.  But if I type the
> following at the command line:
>
>     $ python mymodule.py
>
> it is the shell (in my case bash) that looks for mymodule.py, not
> Python.  It analogous to my typing:
>
>     $ vi mymodule.py
>
> or (trying to avoid a fight between vi and emacs fanatics):
>
>     $ emacs mymodule.py
>
> Neither vi nor emacs try to find mymodule.py; the (bash or other)
> shell does.
>
> So perhaps a solution to the problem is to make mymodule.py
> executable and put it somewhere on your path.  Then execute it by
> typing at the command line:
>
>     $ mymodule.py
>
> Now the shell will run it just like any other executable script and
> it will use Python as the interpreter for that script.
>
> How you make the script executable probably depends on which shell
> you are using.  For bash, you could do the following:
>
> 1. Insert the following line as the first line of your script:
>
>        #!/usr/bin/env python
>
> 2. Change the priveleges of the script to make it executable.
>    Example:
>
>        $ chmod u+x mymodule.py
>
> 3. Put mymodule.py on your path, that is, in a directory that is in
>    your PATH environment variable.  Alternatively, add the path to
>    the directory containing mymodule.py to your PATH environment
>    variable.
>
> Dave
>
> --
> Dave Kuhlman
> http://www.rexx.com/~dkuhlman
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061009/930b1553/attachment.html 


More information about the Tutor mailing list