+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 4 people (50%) answered Yes
Recently 2 of 4 people (50%) answered Yes


In Python, I want to write computed values to a file

Jan 31st, 2010 17:09
forum net tr, Hindusthan Jobs, john mart, i can do it, Crick Dougles, Kelly India, Buddy Damm, http://www.hindusthanjobs.com/

Reading, writing, and Python
In the previous articles in the "Discover Python" series, you learned
about the basic Python data types and some of the container data types,
such as the tuple, string, and list. Other articles discussed the
conditional and looping features of the Python language and how they
work together with the container data types to simplify programming
tasks. The last basic step involved in writing programs is to read data
from and write data to a file. After reading this article, you'll be
able to check learning this skill off your to-do list.
Simple output
Throughout this series, you've written (output) data using the print
statement, which by default writes the expression as a string to the
screen (or console window). This is demonstrated in Listing 1, which
repeats your first "Hello, World!" Python program with some minor tweaks.
Listing 1. Simple output
>>> print "Hello World!"
Hello World!
>>> print "The total value is = $", 40.0*45.50
The total value is = $ 1820.0
>>> print "The total value = $%6.2f" % (40.0*45.50)
The total value = $1820.00
>>> myfile = file("testit.txt", 'w')
>>> print >> myfile, "Hello World!"
>>> print >> myfile, "The total value = $%6.2f" % (40.0*45.50)
>>> myfile.close()
As this example shows, writing data is easy with the print statement.
First, the example outputs a simple string. Then it creates and outputs
a compound string, created using the string formatting technique.
derlenmis turk video sitesi http://www.videoturk.gen.tr Video secilmis
youtube videolari http://www.youtubevideolari.net/ youtube videos online
video izle tr tube http://www.videotrtube.com/
firmalar sirketler rehberi http://www.sirketfirmarehberi.com/ firma
sirket rehberi adres telefon bilgileri
full program full oyun http://www.forumnettr.com/ download