Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'column': 0.07; 'reason,': 0.07; 'subject:file': 0.07; '#print': 0.09; '[];': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'jan': 0.12; 'suggest': 0.14; 'dhananjay': 0.16; 'files:': 0.16; 'opened.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'advance.': 0.19; 'everyone,': 0.19; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'skip:e 30': 0.24; 'script': 0.25; 'header:X-Complaints-To:1': 0.27; 'header :In-Reply-To:1': 0.27; 'am,': 0.29; 'subject:list': 0.30; "skip:' 10": 0.31; 'anyone': 0.31; 'file': 0.32; 'could': 0.34; 'message.': 0.35; 'list': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'follows:': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; '2nd': 0.60; 'skip:o 30': 0.61; 'received:173': 0.61; 'received:fios.verizon.net': 0.84; 'thanking': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: how to write list in a file Date: Wed, 23 Apr 2014 19:50:41 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1398297087 news.xs4all.nl 2891 [2001:888:2000:d::a6]:40258 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70556 On 4/23/2014 3:53 AM, Dhananjay wrote: > Hello everyone, > > I am trying hard to write a list to a file as follows: > > > def average_ELECT(pwd): > os.chdir(pwd) I would 'print pwd' to make sure where files are being opened. > files = filter(os.path.isfile, os.listdir('./')) > folders = filter(os.path.isdir, os.listdir('./')) > eelec = 0.0; evdw = 0.0; EELEC = []; elecutoff = []; > g = Gnuplot.Gnuplot() > for f1 in files: > # if f1[21:23]=='12': > if f1[27:29]==sys.argv[1]: # vdw cutoff remains constant; see > 2nd column of output > fl1 = open(f1,'r').readlines() > # print len(fl1) > > for i in range(1, len(fl1)): > fl1[i]=fl1[i].split() > eelec = eelec + float(fl1[i][1]) > evdw = evdw + float(fl1[i][2]) > #print fl1[i][1], fl1[i][2] > avg_eelec = eelec/40 > avg_evdw = evdw/40 > # print eelec, evdw > # print f1[21:23], f1[27:29], avg_eelec, avg_evdw > print f1[21:23], f1[27:29], avg_eelec > # EELEC.append(avg_eelec); elecutoff.append(float(f1[21:23])) > eelec=0.0; evde=0.0; > a = f1[21:23]+' '+f1[27:29]+' '+str(avg_eelec) > EELEC.append(a) > print sorted(EELEC) > with open('EElect_elec12-40_vdwxxx.dat','w') as wr: > for i in EELEC: > print i > wr.write("%s\n" % i) > wr.close() > > > The script is printing "print sorted(EELEC)" as well as "print > f1[21:23], f1[27:29], avg_eelec" very well. > However, for some reason, I neither see any file (expected to see > EElect_elec12-40_vdwxxx.dat as per the script) generated nor any error > message. > > Could anyone suggest me correction here. > > Thanking you in advance. > > -- DJ > > > > -- Terry Jan Reedy