Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19842

Re: Help writelines

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <markus.rother@web.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python': 0.08; 'alot': 0.09; 'message-id:@web.de': 0.09; 'newline': 0.09; 'lambda': 0.16; 'received:217.72.192.243': 0.16; 'received:fmmailgate05.web.de': 0.16; 'works...': 0.16; 'wrote:': 0.16; 'subject:Help': 0.17; 'trying': 0.20; 'header:In-Reply-To:1': 0.22; 'figure': 0.23; 'from:addr:web.de': 0.23; 'pm,': 0.26; 'skip:[ 10': 0.27; 'tried': 0.27; 'object.': 0.30; 'everyone,': 0.32; 'list': 0.32; 'thanks': 0.32; 'header:User-Agent:1': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.34; 'function.': 0.34; 'file': 0.35; 'url:python': 0.36; 'received:kundenserver.de': 0.36; 'but': 0.37; 'could': 0.37; 'received:192': 0.38; 'received:de': 0.39; 'url:org': 0.39; 'either': 0.39; 'help': 0.39; 'received:192.168.1': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40
Date Fri, 03 Feb 2012 21:41:54 +0100
From Markus Rother <markus.rother@web.de>
User-Agent Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.24) Gecko/20111108 Thunderbird/3.1.16
MIME-Version 1.0
To python-list@python.org
Subject Re: Help writelines
References <CAKhY55OeHanpWC=WfzMo1nzujsrVC2oAD89R6So3ZG3mobBphg@mail.gmail.com>
In-Reply-To <CAKhY55OeHanpWC=WfzMo1nzujsrVC2oAD89R6So3ZG3mobBphg@mail.gmail.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:2gE0DmT4ic6bPNr7AdyDEuDkw4qtftXdqlE/AW6MiD5 OAPNPQhdZZyBy/HC4D/g23Ayw5w+M8doyTl2WgUlbJNQZQ4i4G l31ZrKjoCK4tgs3zQCGoxRqfLXSVbmCtqW6iKYNrSNsbZzirHy vS/2GsVLyMT5DMrz7wDx3C3rUDdYj9fk3keADAk1HIVrMn4CTW VGoWOB7nKk9Xlup44tLIA==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5418.1328301725.27778.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1328301725 news.xs4all.nl 6940 [2001:888:2000:d::a6]:47510
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19842

Show key headers only | View raw


Hi,

You have to iterate.
Either with

for u in users:
     fob.write( u + '\n' )

or with a lambda function.

always a good call: http://python.org/

greets,
M.

On 02/03/2012 09:27 PM, Anatoli Hristov wrote:
> Hi everyone,
>
> I`m totaly new in python and trying to figure out - how to write a 
> list to a file with a newline at the end of each object.
> I tried alot of combinations :) like:
> users = ['toli','didi']
> fob=open('c:/Python27/Toli/username','w')
> fob.writelines(users) + '%s\N'
> fob.close()
>  or fob.writelines('\N' % users)
> or fob.writelines('%s\N' % users)
> but nothing of dose works...
>
> Could you help me find out the right syntaxes?
>
> Thanks
>
>
>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Help writelines Markus Rother <markus.rother@web.de> - 2012-02-03 21:41 +0100

csiph-web