I'm trying to write a little procedure that write (append would be even better) a line in a file with Python, like this:
def getNewNum(nlist):
newNum = ''
for i in nlist:
newNum += i+' '
return newNum
def writeDoc(st):
openfile = open("numbers.txt", w)
openfile.write(st)
newLine = ["44", "299", "300"]
writeDoc(getNewNum(newLine))
But when I run this, I get the error:
openfile = open("numbers.txt", w)
NameError: global name 'w' is not defined
If I drop the "w" paremeter, I get this other error:
line 9, in writeDoc
openfile.write(st)
IOError: File not open for writing
I'm following exactly (I hope) what is here.
The same occurs when I try to append the new line. How can I fix that?
getNewNumfunction should just be' '.join(newLine).