Path: csiph.com!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: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'output': 0.04; 'method,': 0.07; 'parsing': 0.07; 'python': 0.09; "'w')": 0.09; 'name):': 0.09; 'neighborhood': 0.09; 'looked': 0.10; 'file,': 0.15; '...,': 0.16; '2.7.3': 0.16; 'received:mac.com': 0.16; 'certainly': 0.17; 'received:10.0.1': 0.17; 'thanks,': 0.18; 'input': 0.18; 'to:name :python-list@python.org': 0.20; 'written': 0.20; 'fraction': 0.22; "i'd": 0.22; 'cc:2**0': 0.23; 'values': 0.26; 'lines': 0.28; 'cat': 0.29; 'decimal': 0.29; 'overhead': 0.29; "i'm": 0.29; 'lists': 0.31; 'point': 0.31; 'file': 0.32; 'received:10.0': 0.33; 'to:addr:python-list': 0.33; 'typically': 0.33; 'list': 0.35; 'received:17': 0.35; 'something': 0.35; 'but': 0.36; 'charset:us- ascii': 0.36; 'correctly': 0.37; 'moment': 0.37; 'data': 0.37; 'received:10': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'qualified': 0.60; 'skip:w 30': 0.61; 'further': 0.61; 'save': 0.61; 'telling': 0.61; 'day.': 0.63; 'decided': 0.65; 'middle': 0.66; 'analysis': 0.70; 'day': 0.73; '160': 0.84 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.7.7855,1.0.260,0.0.0000 definitions=2012-08-22_03:2012-08-22, 2012-08-22, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1203120001 definitions=main-1208220140 From: "William R. Wing (Bill Wing)" Subject: writelines puzzle Date: Wed, 22 Aug 2012 11:38:55 -0400 To: "python-list@python.org" X-Mailer: Apple Mail (2.1485) Cc: "William R. Wing \(Bill Wing\)" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345653547 news.xs4all.nl 6938 [2001:888:2000:d::a6]:59724 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27653 In the middle of a longer program that reads and plots data from a log file, I have added the following five lines (rtt_data is fully qualified file name): wd = open(rtt_data, 'w') stat = wd.write(str(i)) stat = wd.writelines(str(x_dates[:i])) stat = wd.writelines(str(y_rtt[:i])) wd.close() The value of i is unknown before I have read through the input log file, but is typically in the neighborhood of 2500. x_dates is a list of time stamps from the date2num method, that is values of the form 734716.72445602, day number plus decimal fraction of a day. y_rtt is a list of three- or four-digit floating point numbers. The x_dates and y_rtt lists are complete and plot correctly using matplotlib. Reading and parsing the input log file and extracting the data I need is time consuming, so I decided to save the data for further analysis without the overhead of reading and parsing it every time. Much to my surprise, when I looked at the output file, it only contained 160 characters. Catting produces: StraylightPro:Logs wrw$ cat RTT_monitor.dat 2354[ 734716.72185185 734716.72233796 734716.72445602 ..., 734737.4440162 734737.45097222 734737.45766204][ 240. 28.5 73.3 ..., 28.4 27.4 26.4] Clearly I'm missing something fundamental about using the writelines method, and I'm sure it will be a DUH moment for me, but I'd sure appreciate someone telling me how to get that data all written out. I certainly don't insist on writelines, but I would like the file to be human-readable. Python 2.7.3 OS-X 10.8 Thanks, Bill