Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to read a continuously updable file

Status
Not open for further replies.

bhavanasi

Programmer
Jan 6, 2011
11
IN
By pressing a button i have to read a file which is dynamic file,,and displaying the file to user in a text box..If again user press the same button he has get the same out put..
 
Hi

See the [tt]file.tell()[/tt] and [tt]file.seek()[/tt] methods :
Code:
[b]def[/b] [COLOR=darkgoldenrod]readnext[/color][teal]([/teal]filename[teal],[/teal]lastseen[teal]=[/teal][purple]0[/purple][teal]):[/teal]
  with [COLOR=darkgoldenrod]open[/color][teal]([/teal]filename[teal])[/teal] as fil[teal]:[/teal]
    fil[teal].[/teal][COLOR=darkgoldenrod]seek[/color][teal]([/teal]lastseen[teal])[/teal]

    [b]for[/b] line [b]in[/b] fil[teal]:[/teal]
      [b]print[/b] line[teal].[/teal][COLOR=darkgoldenrod]rstrip[/color][teal]()[/teal]

    [b]return[/b] fil[teal].[/teal][COLOR=darkgoldenrod]tell[/color][teal]()[/teal]
Then store the position in a variable and pass it back when calling the next time : [tt]last[teal]=[/teal]readnext[teal]([/teal][green]'whatever'[/green][teal],[/teal]last[teal])[/teal][/tt] .

( This implementation is just a generic example. Rewrite it to fit your context. )


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top