Newbie Question

Andrew Robert andrew.arobert at gmail.com
Mon Jun 19 17:18:26 EDT 2006


Saint Malo wrote:
> I am new to programming, and I've chosen python to start with. I wrote
> a simple program that asks several questions and assings each one of
> them a variable via raw_input command.  I then combined all the
> variables into one like this a = b + c + d.  After this I wrote these
> values to a file.  What I want to do now is be able to search through
> the file for any data in there.  Is this possible?
> 
Most certainly.

It depends on how you want to treat the read data.

for example


# Open a file for read
file=open(r'test.txt','r')

# Read each line in file
for line in file

   #Search each line
   if "A" in line:

        print "I found A"

file.close()



More information about the Python-list mailing list