Well, I'm a begginer in Python coding, and at DaniWeb. My problem is: I can't open any files!

I tried:

>>> f = open('C:\teste.txt', 'w')

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    f = open('C:\teste.txt', 'w')
IOError: [Errno 22] invalid mode ('w') or filename: 'C:\teste.txt'
>>> f = 'C:\teste.txt'
>>> open(f)

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    open(f)
IOError: [Errno 22] invalid mode ('r') or filename: 'C:\teste.txt'
>>> open ('C:\teste.txt', 'r')

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    open('C:\teste.txt', 'r')
IOError: [Errno 22] invalid mode ('r') or filename: 'C:\teste.txt'

Tried in Python Shell & Cmm Line...
Using Python 2.6.4 for WinXp installed in C:\Python 26

Recommended Answers

Use this f = open('C:/teste.txt', 'w') .
Or this f = open('C:\\teste.txt', 'w') . \ count as newline \\ == Backslash (\)

In windows i always use this c:/ .
http://docs.python.org/reference/lexical_analysis.html#string-literals

Jump to Post

All 2 Replies

Be a part of the DaniWeb community

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