dimanche 24 mars 2019

If statement using OR operator by reading a file

I am trying to fetch the filter from the text file using if conditon in Python. When I make an if statement with OR operator it gives a wrong result

My dummy file contains this text:

 -ads-management/'

 &adslots='

 +advertorial.

 .com/ad2/

 ://affiliate.$third-party'

 ://adv.$domain=~adv.cincsys.com

 =PAGE_AD_

 ?phpAds_

 120-600.gif|

 |data:text$popup$domain=~clker.com'

 ||qqc.co/Webservices/jsParseLinks.aspx$script,third-party
 ||pagead2.googlesyndication.com/pagead/js/r*/r*/show_ads_impl.js$script,domain=mrpiracy.xyz

 @@||cloudfront.net/ads/ads.js$script,domain=thesimsresource.com

> !example.com

    a=open('dummy.txt','r')
     text=a.read()
     line_withdomain=0
     line_withoutdomain=0
    for line in text.split("\n"):
      if line.startswith(":") or ("-") or ("=") or (".") or ("&") or("+") or("|")  
         if "domain=" in line:
            line_withdomain +=1
         else:
            line_withoutdomain += 1
     elif line.strip():
         print(f"these are remainin line '{line}'")
 print(line_withdomain)
 print(line_withoutdomain)

When I run this code, it gives me wrong output. It count last four lines also, but I don't want to include those line as well as comment line

Aucun commentaire:

Enregistrer un commentaire