467,915 Members | 1,267 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

printing to a file problems

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
  • viewed: 1103
Share:
1 Reply
bvdet
Expert Mod 2GB
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.

Similar topics

10 posts views Thread by Brian Hanson | last post: by
1 post views Thread by phil cunningham | last post: by
4 posts views Thread by Tom Leylan | last post: by
4 posts views Thread by Al Jones | last post: by
1 post views Thread by Gidi | last post: by
1 post views Thread by Dreamtime | last post: by
12 posts views Thread by Alex Clark | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.