f



help - python can't find file

-learning python with limited knowledge of linux.
-get error msg 21 "file or directory does not exist"
-running Suse linux 10.
-haven't had a problem before
- rebooted several times.
-python opened in shell/terminal program Konsole window like this
user1@linux!~ - shell - Konsole
Sessions View Bookmark Settings Help

-first line in window gives me a linux prompt:
user1#linux:~>

- whereupon I type python and get >>> a command line I think it is  
called or type python pyfilename.py and it runs/interprets/opens
  the file on screen 

- but now I get a error message 21 saying file or directory doesn't
exist.

- my py files are created with editor gedit
- clicking on any py file and linux asks me to open it with what
  program and I choose utilities/editdors/gedit and it works.

-all my py files contain the following lines at the beginning 
#! /usr/bin/env python
# -*- coding: utf-8 -*-

# filename: blankpy.py  (for example of a file name)


- my linux file structure is as follows shown under Konqueror window:
rootfolder
bin 
boot
dev
etc
home
 user1
 bin
 desktop
 documents
lib
media 
 dvdrecorder
 floppy 

- (for example, and continues on, of course) 


- none of my python books or linux books show that I can type 
  python /dev/sda/ blankpy.py and get python to open it like in 
  windows98 or dos python A:\blankpy.py  

embarrassed and frustrated
0
braindead (10)
5/21/2007 12:48:33 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

3 Replies
252 Views

Similar Articles

[PageSpeed] 7

On Mon, 21 May 2007 12:48:33 GMT, enquiring mind
<braindead@braindead.com> declaimed the following in comp.lang.python:

> -first line in window gives me a linux prompt:
> user1#linux:~>
> 
> - whereupon I type python and get >>> a command line I think it is  

	Okay, you've now started the INTERACTIVE interpreter mode...

> called or type python pyfilename.py and it runs/interprets/opens
>   the file on screen 

	The interpreter has no idea of how to process a statement starting
with the word "python"
 
> - but now I get a error message 21 saying file or directory doesn't
> exist.
>
	Should be invalid syntax... (the following is M$ Windows, but the
concept should still apply).

E:\UserData\Dennis Lee Bieber\My Documents\Python Progs>python
ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python t.py
  File "<stdin>", line 1
    python t.py
           ^
SyntaxError: invalid syntax
>>> ^Z


E:\UserData\Dennis Lee Bieber\My Documents\Python Progs>python t.py
pre: 5032

	In the first, "I" try to run a program by typing "python filename"
inside the interpreter. The second is what should be done to run a
program from a file -- you type everything at the terminal window
prompt.
 
> - my py files are created with editor gedit
> - clicking on any py file and linux asks me to open it with what
>   program and I choose utilities/editdors/gedit and it works.
> 
> -all my py files contain the following lines at the beginning 
> #! /usr/bin/env python
> # -*- coding: utf-8 -*-
> 
> # filename: blankpy.py  (for example of a file name)
> 
> 
> - my linux file structure is as follows shown under Konqueror window:
> rootfolder
> bin 
> boot
> dev
> etc
> home
>  user1
>  bin
>  desktop
>  documents
> lib
> media 
>  dvdrecorder
>  floppy 
> 
> - (for example, and continues on, of course) 
> 
> 
> - none of my python books or linux books show that I can type 
>   python /dev/sda/ blankpy.py and get python to open it like in 
>   windows98 or dos python A:\blankpy.py  
> 
> embarrassed and frustrated
-- 
	Wulfraed	Dennis Lee Bieber		KD6MOG
	wlfraed@ix.netcom.com		wulfraed@bestiaria.com
		HTTP://wlfraed.home.netcom.com/
	(Bestiaria Support Staff:		web-asst@bestiaria.com)
		HTTP://www.bestiaria.com/
0
wlfraed (4596)
5/21/2007 4:28:10 PM
quoth the enquiring mind:

> - but now I get a error message 21 saying file or directory doesn't
> exist.

You must be in the same directory (in konsole) as the python script for this 
to work, else enter the relative path to the file:

Assuming you are in your home directory (this is where a new konsole will 
start you), and the py scripts are in a directory 'pythondir': 

$ cd pythondir
$ python myscript.py

or:

$ python pythondir/myscript.py

You could also chmod the script to be executable and run it as a regular 
command ...however... I don't mean this to sound like RTFM but I do think 
that you could use some reading on Linux CLI usage. You say you have some 
Linux books?

I say this as my reading of your message indicates your problems lie with 
misunderstanding the shell/paths etc, not with Python itself...

-d  
--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972
0
bulliver (132)
5/21/2007 5:09:20 PM
darren, 

thanks for your explanation.  I copied my paths and listed them in my 
code file
#! /bin/user1/ python

and python finds the file and interprets it so that will keep me going
until my buddy returns to the city to explain my errors.  It appears
that my problem arose from taking lesson code out of text books and
copying the pathing that is I guess slightly different than mine. 

Thanks ever so much.
tk

darren kirby wrote:




> 
> quoth the enquiring mind:
> 
> > - but now I get a error message 21 saying file or directory doesn't
> > exist.
> 
> You must be in the same directory (in konsole) as the python script for this
> to work, else enter the relative path to the file:
> 
> Assuming you are in your home directory (this is where a new konsole will
> start you), and the py scripts are in a directory 'pythondir':
> 
> $ cd pythondir
> $ python myscript.py
> 
> or:
> 
> $ python pythondir/myscript.py
> 
> You could also chmod the script to be executable and run it as a regular
> command ...however... I don't mean this to sound like RTFM but I do think
> that you could use some reading on Linux CLI usage. You say you have some
> Linux books?
> 
> I say this as my reading of your message indicates your problems lie with
> misunderstanding the shell/paths etc, not with Python itself...
> 
> -d
> --
> darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
> "...the number of UNIX installations has grown to 10, with more expected..."
> - Dennis Ritchie and Ken Thompson, June 1972
0
braindead (10)
5/22/2007 11:48:10 AM
Reply: