Re: why writing list to file puts each item from list on seperate line?
- From: limodou <limodou@xxxxxxxxx>
- Date: Sat, 31 Dec 2005 12:30:47 +0800
30 Dec 2005 20:22:52 -0800, homepricemaps@xxxxxxxxx <homepricemaps@xxxxxxxxx>:
> if i use the code below to write a list to a file
>
> list = (food, price, store)
> data.append(list)
> f = open(r"test.txt", 'a')
> f.write ( os.linesep.join( list ) )
>
>
> it outputs to a file like this
>
> apple
> .49
> star market
>
> and i want it to do
>
> apple, .49. star market
>
> any ideas
>
my box is windows xp, so :
>>> print repr(os.linesep)
'\r\n'
If you want to seperate them with space, you should:
f.write ( ''.join( list ) )
and list = (food, price, store)
the list is not called "list", but "tuple", a real list should be
aList = [food, price, store]
--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit
.
- Follow-Ups:
- Re: why writing list to file puts each item from list on seperate line?
- From: homepricemaps
- Re: why writing list to file puts each item from list on seperate line?
- From: homepricemaps
- Re: why writing list to file puts each item from list on seperate line?
- References:
- why writing list to file puts each item from list on seperate line?
- From: homepricemaps
- why writing list to file puts each item from list on seperate line?
- Prev by Date: Memoization and encapsulation
- Next by Date: Re: why writing list to file puts each item from list on seperate line?
- Previous by thread: why writing list to file puts each item from list on seperate line?
- Next by thread: Re: why writing list to file puts each item from list on seperate line?
- Index(es):
Relevant Pages
|