Hi,
I have some problems just to write a simple string output to some txt.file.
That is my test code:

test = open('Test.txt', 'w')
test.write("Teststring")
test.close()

I use Python 2.6.5 and PyScripter

If I direcly enter the code in the IDLE SHELL, sometimes it works, sometimes only the file is generated and sometimes I get this Error message without changing anything in the Code.

>>> test = open('Test.txt', 'w')

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    test = open('Test.txt', 'w')
IOError: [Errno 13] Permission denied: 'Test.txt'

I am working with windows 7, could this be some operating system configuration problem?
I have asolutly no idea about this matter.

Thanks
Brutus2000

What is your current working directory when you are running the program? To find out, run the following commands from whatever editor you are going to use to test your program.

import os
print os.getcwd()

I suspect that you don't have all the necessary permissions to create and write to a file in the current working directory when you get the IO error. You can avoid the problem by including the path to a directory where you know you can create and update files, in your filename, like this:

>>> test = open('/home/david/Programming/Python/Test.txt', 'w')
>>> test.write('Hi there!')
>>> test.close()
>>>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.