0

I am having some problems working with the tell method when working with a file. Basically what I am trying to do is use the tell method to find where I currently am within a paragraph and to only display the characters up to a certain tell count. For example:

quote.txt="You will not apply my precept he said shaking his head How often have I said to you that when you have eliminated the impossible whatever remains however improbable must be the truth We know that he did not come through the door the window or the chimney We also know that he could not have been concealed in the room as there is no concealment possible When then did he come The Sign of the Four"

myfile=open("quote.txt","r")
mylist1=[]
myfile.tell()
while myfile.tell() < 50:
    read=myfile.readline()
    print read
    print myfile.tell()
    mylist1.append(read)

I know I could simply put myfile.read(50) and it would display what I needed however I will be using an if statement later to specify and read sections based on the tell.

Any help would be greatly appreciated. I can also provide more information if needed. Thanks again!

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by pyTony
0

What is your problem and what you are trying to do?

I do not undetstand reference to read(50) as it has nothing to do with your code which reads lines.

Line 3 does nothing. Your example input is only one line, so not very good test input for the loop.

Edited by pyTony

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.