简体   繁体   中英

To read from a certain text file and compare it to a string in python

it should be quite a simple answer but i was just wondering how to compare a string in python to a full row of a column in a text file. I have split each bit of data by using commas but i am not sure this is working.

At the moment i have:

if (username) in open('names.txt').read():

Obviously this will compare to the full text file and not one column but what i need to know is, how to modify this piece of text to read only from one column and any more text needed to be added to it if need be.

thanks for all the help guys! ill try them out now and read into it some more.

if username in map(lambda a: a.split(" ")[0], open('names.txt').readlines()):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM