Why won't this work?

A forum for general discussion of the Python programming language.

Why won't this work?

Postby bbesase » Thu May 09, 2013 1:18 pm

Code: Select all
from datetime import datetime


today = datetime.now().date()
#def createFile():

path = "C:\Users\bgbes\Documents\Brent\ParsePractice\Test " + str(today) + ".txt"
f = open(path, 'w')
f.write('Hello')
f.close()


Here is the code.


Code: Select all
Traceback (most recent call last):
  File "C:/Users/bgbes/Documents/Ben/Python_tut/createFile.py", line 8, in <module>
    f = open(path, 'w')
IOError: [Errno 22] invalid mode ('w') or filename: 'C:\\Users\x08gbes\\Documents\\Ben\\ParsePractice\\Test 2013-05-09.txt'



There is the error message.

All I'm trying to do is create a file and save it to that path, but I can't get it to work.
bbesase
 
Posts: 18
Joined: Wed May 08, 2013 1:57 pm

Re: Why won't this work?

Postby bbesase » Thu May 09, 2013 1:29 pm

Never mind, figured it out. :D
bbesase
 
Posts: 18
Joined: Wed May 08, 2013 1:57 pm

Re: Why won't this work?

Postby Kebap » Fri May 10, 2013 8:37 am

Maybe you want to mention the solution though, as for anybody reading this with a similar question. :)
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 366
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Discussions

Who is online

Users browsing this forum: mighty and 3 guests