简体   繁体   中英

reading from a file and checking using if condition in python

i have a list of URL , and it should be checked with file if the URL is present in that file it should skip that and move to next

             file = open('url','r')
             read = file.readlines()
             lists_of_url = ['url','url','url','url']
              for urls in lists_of_url:
                    if urls!=read[0]:
                       print(urls)

You probably want:

if url not in read:
    print(url)

That would print each URL which is not present in read (ie the contents of each file).

It will print the items that are not in the file

    file1 = open('url','r')
    read = file1.readlines()
    a = []
    lists_of_url = ['url','url','url','url']
    for i in read:
     a.append(i.strip())

    for item in lists_of_url:
         if item not in a:
              print item

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