0

I write a basic file write code -

    f = open('workfile', 'r+')

    f.write('0123456789abcdef')

I run the file at cmd at the same folder where I put workfile.txt file but I get the error -

IOError: [Errno 2] No such file or directory: 'workfile'

I tried also to convert to exe file with py2exe and run the exe file but nothing...

what is the problem?

thanks!

====================

the full error massage when check on compiler-

    Traceback (most recent call last):                                                                                                                               
    File "/home/ubuntu/workspace/.c9/metadata/workspace/2.py", line 1, in     <module>                                                                                 
    f = open('workfile', 'r+')                                                                                                                                   
    IOError: [Errno 2] No such file or directory: 'workfile'                                                                                                         
3
  • 2
    you missed the file extension in your code Commented Mar 10, 2016 at 16:56
  • Do you have a file called workfile? No, it's called workfile.txt. Commented Mar 10, 2016 at 17:05
  • With "r+" mode, the file must already exist. Obviously, "workfile" doesn't exist. Commented Mar 10, 2016 at 17:10

1 Answer 1

1

rename 'workfile' to 'workfile.txt':

f = open('workfile.txt', 'r+')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.