How to open a file, read from it, and retrieve information from it?

Eric @ Zomething eric at
Wed Mar 10 05:25:29 CET 2004

bugsyboy9 at described:

> >From a GUI interface, a user needs to request a string to be searched
> from a file and bring the string back, if it is in the file, and
> display it in a different field within the same GUI.  Basically, I
> need to be able to open a file, parse its contents, and bring the
> requested information back and display it in a GUI window.

The fun is in the doing, but here are some links you might want to explore:

File objects:
Tkinter GUI:
Regular expressions:

here's how easy it can be (to do something easy) in Python:

IDLE 1.0      
>>> from easygui import *
>>> fname=fileopenbox()  #opens a file dialog  and returns a selected file name
>>> fl=file(fname,'r') #opens the file for reading
>>> #reads the file into a string
>>> pos=fString.find("contract") #finds the first position of the string "contract" in the file string
>>> pos

If you start playing with it, you'll start enjoying it, I say.

Try, do, Google, repeat.

Eric Pederson
Pythonista since... February 2004!

More information about the Python-list mailing list