Wednesday, September 28, 2011

Read a file in Python

Hi, I'll teach you how to read a file in Python

Python is a hight level programming language, very powerful and clean syntax.
file = open("C:/myfile.txt",'r') # open myfile in read mode
mylist= ["Words"] # create a list
while True:
      myline = file.readline()
      mylist.append(myline) # add a new node
      if not myline: break # end of file
for elemento in myList:
      print elemento

print "Created By:  Christopher Jimenez"

No comments:

Post a Comment