[Tutor] Configure Problems
D-Man
dsh8290@rit.edu
Tue, 14 Mar 2000 23:34:41 -0500
You aren't doing anything wrong. Any file can only be found under one
of 3 conditions:
1) it is in the path
2) you are in the directory containing the file
3) you specify the path to the directory containing the file
All you need to do is make sure you are in your directory
(/home/charly/Mydir) when you work with the python files.
I haven't read the book that you referred to, but in my experience, if
running the program as a script the .py is necessary. It is also
necessary when invoking the python interpreter and providing the file as
a command line argument. Where the .py extension is not required is in
the import statements in the python files.
-D
> Charles Takacs wrote:
>
> I am a Newbie with Linux as well as Programming. Trying to lean Python
> as my First language I bought "Learning Python". Using RH-6.1. I am
> trying to follow the book's instruction but things are not as they
> supposed to be. The problems seem to be in configuring to use "Module
> Files and Script Files. I would really appreciate some helping hand.
>
> This is what I did.
> 1. For the purpose of Practice in my home directory I created a
> Sub-directory where I want to keep my practice .py files.
> as follows; /home/charly/Mydir
> 2. In also modified the /home/charly/.bsh_profile file by adding
> "/home/charly/Mydir:.:"
> 3.Using Emacs I created as Script file "myfile.py"
> (since in my RH distribution Python is in /usr/bin and not in
> /usr/local/bin)
> in the file according to the book I typed as follows:
> #!/usr/bin/python
> print 'Hello World'
>
> Then chmod +x myfile.py
> could only be donw when I changed to the /home/charly/Mydir directory.
>
> The following problem seem to occur.
> 1. To run the file at the "Shell promt" (as a shell script)
> a. I can only do it if first I cd to the files directory (i.e
> /home/charly/Python)
> b. I must also add the .py file extension otherwise an error
> occures that
> there is no suchfile. But according to the book the .py
> extension is not
> needed. I also get the error if I try to run the file
> when I am in another dir.
>
> 2. If I am not in the Subdirectory /home/charly/Mydir when I run
> python (in xterm)
> I type :
> python
> import myfile
> then python gives en error. Hoever if I first cd to the
> /Mydir and type the above. then the Hello World is printed.
>
> I don't know what I am doing wrong to fix this seemingly basic
> problems.
> I was my understanding that Python would find a .py extension file
> regardless of in which directory it is. also it is my understanding,
> that if a Path is put into the
> bash_profile file the the shell would find it and it is not necessary
> to give the
> .py extension.
>
> I am completely at loss and need some advice. Thanks in advance.
> Charles Takacs
>
>
>