Hi I am trying to read and print lines from a text.
I can print ALL the lines by typing:
myfile = open("c:/test/buffet.txt","r")
for line in myfile:
... print line
Q1. How can I print the first 10 lines?
Q2. How can I print the every other line?
Also, How does Python define a line? How does it define a string?
I also used the following command, which seemed to work but gave me different results
myfile = open("c:/test/buffet.txt","r").readlines() [:10]
print myfile
For printing the first 10 lines, the result was different depending on how the text file was editted... That is, if I combined all the sentences together as a pragraph, it differred from the one that I wrote each sentence seperately as a line. That's why I asked how it defines lines.
Thank you.
I can print ALL the lines by typing:
myfile = open("c:/test/buffet.txt","r")
for line in myfile:
... print line
Q1. How can I print the first 10 lines?
Q2. How can I print the every other line?
Also, How does Python define a line? How does it define a string?
I also used the following command, which seemed to work but gave me different results
myfile = open("c:/test/buffet.txt","r").readlines() [:10]
print myfile
For printing the first 10 lines, the result was different depending on how the text file was editted... That is, if I combined all the sentences together as a pragraph, it differred from the one that I wrote each sentence seperately as a line. That's why I asked how it defines lines.
Thank you.