python - Excaption not including -


i have file @ /location/data.txt . in file have entry :

aaa:xxx:abc.com:1857:xxx1:rel5t2:y

ifa:yyy:xyz.com:1858:yyy1:rel5t2:y

i want access 'aaa' code either mention aaa while giving input in caps or small after running python code should return me aaa right item here want include 1 exception if give input -mc suffix (aaa-mc) either in small latters or in caps should ignore -mc. below code , output getting now.

def pitemname():

    global itemlist,fitemlist     pitemlist = []     fitemlist = []     itemlist = str(raw_input('enter pipe separated list of items : ')).upper().strip()     items = itemlist.split("|")     count = len(items)     print  'total distint item count : ',  count     pipelst = [i.split('-mc')[0] in itemlist.split('|')]     filepath = '/location/data.txt'     f = open(filepath, 'r')     lns in f:             split_pipe = lns.split(':', 1)             if split_pipe[0] in pipelst:                     index = pipelst.index(split_pipe[0])                     pitemlist=split_pipe[0]+"|"                     fitemlist.append(pitemlist)                     del pipelst[index]     lns in pipelst:         print bcolors.red + lns,' wrong item name' + bcolors.endc     f.close() 

when execute above code prompts me :

enter pipe separated list of items :

and if provide list :

enter pipe separated list of items : aaa-mc|ifa

it gives me result :

total distint item count : 2

aaa-mc wrong item name

items belonging other :

other center :

item count other center = 0

items belonging current centers :

active items in us1 :

^ifa$

active items in us2 :

^aaa$

ignored item count current center = 0

you have entered itemlist belonging center as: ^ifa$|^aaa$

active item count : 2

do want continue [yes|y|no|n] :

as must see in above result aaa coming valid count (active item count : 2) because available in /location/data.txt file. coming aaa-mc wrong item name (2nd line above result). want '-mc or -mc' ignore item present or non present in /location/data.txt file.

please let me know what's wrong above code achieving this.

the way constructing itemlist reading in string, capitalizing (with upper()), , stripping whitespace. therefore, 'aaa-mc' being converted 'aaa-mc'. you're later splitting uppercase string on token '-mc', impossible contain, so.

i'd reccommed either replacing upper() lower() when reading string in, or doing hard replace on types of '-mc', instead of

i.split('-mc')[0] 

try using

i.replace('-mc','').replace('-mc','') 

in list comprension.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -