newbie question: [Errno 2] No such file or directory

This is the place for queries that don't fit in any of the other categories.

newbie question: [Errno 2] No such file or directory

Postby Jankosha » Sun Jul 21, 2013 9:51 pm

Hello,
Recently I wanted to learn about programming on my own, and I decided to start with Python. But, for last few days I've been stuck on this error, and I know I am missing something very simple, but I cannot figure out what it is, so I decided to come to this forum and seek help from experienced people.
So, i am studying from a book ' Programming in Python, 4th edition'. English is not my native language so maybe the problem is simple misunderstanding.
I created a simple file, helloshell.py which does one thing: print('The meaning of life'). I saved it to C:\Python33 file. I set my PATH to include C:\Python33.
When I go to Command Prompt, and to already written C:\Users\Korisnik> add python C:\Python33\helloshell.py, it executes like this:
C:\Users\Korisnik>python C:\Python33\helloshell.py
The meaning of life

The problem is, when I want to use that file helloshell.py for some other tasks, like os.system('python helloshell.py'), it returns error:
python: can't open file 'helloshell.py': [Errno 2] No such file or directory
2

So, that's it, my whole program. Maybe I am missing something fundamental, or I just do not possess talent for programming, you may find it funny :D , but I am really stuck here.
Any tips/solutions would be greatly appreciated.
Thanks in advance :)
Jankosha
 
Posts: 2
Joined: Sun Jul 21, 2013 9:25 pm

Re: newbie question: [Errno 2] No such file or directory

Postby Yoriz » Sun Jul 21, 2013 10:10 pm

Hi,
When working with files and your current working directory is not the same as the file is located, use the full path to the file rather then just its filename.
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Yoriz
 
Posts: 1671
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: newbie question: [Errno 2] No such file or directory

Postby metulburr » Mon Jul 22, 2013 12:10 am

' Programming in Python, 4th edition

What Author? If you mean from O'Reilly written by Mark Lutz, that book is way too advanced for you if you do not know how to handle paths. It would be considered the second book in the series.

http://lifehacker.com/5633909/who-needs ... t-anything
http://www.cs.princeton.edu/courses/arc ... rompt.html
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
metulburr
 
Posts: 2228
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: newbie question: [Errno 2] No such file or directory

Postby Jankosha » Mon Jul 22, 2013 12:33 pm

Thanks for answer Yoriz, it helped. I was just confused with CWD, now I understand it, i knew I was missing something basic.

Metulburr, I already read the first book, and generally I understood alot of it, except for the part about using command prompt, so i didn't bother with it then, expecting to learn it as I begin working on more practic stuff, and less theoretic as in the first book. Thanks for those link, I will study them carefully.

Thanks again for help! :)
Jankosha
 
Posts: 2
Joined: Sun Jul 21, 2013 9:25 pm


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 6 guests