Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 20th, 2002, 08:25 AM
nickname nickname is offline
inexperienced and useless
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: Stevenage, uk
Posts: 10 nickname User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
writing a list to a file

How do I write a list to a file, becuase I seem to not be able to do it?

Reply With Quote
  #2  
Old May 21st, 2002, 11:18 PM
moxie moxie is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: Atlanta, Ga
Posts: 1 moxie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to moxie
Lightbulb

NOTE: Be sure that the data in the list are strings, or make sure that you are writing strings to the file at least.

Here's an example:
============================

# Create a file object and open file
# create an empty list
# populate the list with numbers ranging 1..10
# convert number in list to strings
# write the list to a file
# close the file

#!/usr/bin/env python

myfile = open('myfile', 'w')
mylist = []
for x in range(1,11): mylist.append(x)
mylist = map(lambda(x): str(x), mylist)
myfile.writelines(mylist)
myfile.close()

=================================

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > writing a list to a file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway