By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

printing to a file problems

P: 54
Gang....

I'm writing the results of a function to a file. Just a text file and here's what i've done

>>> fn = open("c:/Python25/debt.txt", 'w')
>>> fn.write(debtcheck())
['"$ 8 , 8 1 5 , 7 3 6 , 9 1 3 , 5 9 2 . 8 0 ">']
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
TypeError: argument 1 must be string or read-only character buffer, not None

If it makes a difference... when I do just print debtcheck() I get both a numerica response and then on the next line it says "none", as seen below

>>> print debtcheck()
['"$ 8 , 8 1 5 , 7 4 4 , 1 2 5 , 6 4 2 . 1 5 ">']
None

What am I doing wrong for a the contents of debtcheck not being printing to the text file?

Thanks
PC
May 4 '07 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
Gang....

I'm writing the results of a function to a file. Just a text file and here's what i've done

>>> fn = open("c:/Python25/debt.txt", 'w')
>>> fn.write(debtcheck())
['"$ 8 , 8 1 5 , 7 3 6 , 9 1 3 , 5 9 2 . 8 0 ">']
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
TypeError: argument 1 must be string or read-only character buffer, not None

If it makes a difference... when I do just print debtcheck() I get both a numerica response and then on the next line it says "none", as seen below

>>> print debtcheck()
['"$ 8 , 8 1 5 , 7 4 4 , 1 2 5 , 6 4 2 . 1 5 ">']
None

What am I doing wrong for a the contents of debtcheck not being printing to the text file?

Thanks
PC
I am guessing that your function debtcheck() prints the string or list ['"$ 8 , 8 1 5 , 7 4 4 , 1 2 5 , 6 4 2 . 1 5 ">']. print always returns None. It will work if debtcheck() does this:
Expand|Select|Wrap|Line Numbers
  1. def debtcheck():
  2.  return str(['"$ 8 , 8 1 5 , 7 4 4 , 1 2 5 , 6 4 2 . 1 5 ">'])
May 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.