removing a char at the end line of a page in python -
the following code seems work fine adds period(.) @ end of page. how can remove dot , coming from? thank help! code
with open("strings.txt") inf: line in inf: line = line.rstrip() if line.isalnum(): print("{} ok".format(line)) else: print("{} invalid".format(line))
the following output should have been generated:
5345m34534l invalid. no2no123non4 ok. noq234n5ioqw#% invalid. %#""sgmsgser invalid. doghdp5234 ok. sg,dermoepm invalid. 43453-frgsd invalid. hsth())) invalid. bmepm35wae ok. vmopaem2234+0+ invalid. gsdm12313 ok. gswrgsrdgrsgsig45 ok. )/(/)(#=%#)%/ invalid. ++-+-+--+--+-+>-<+-<<_<-+>>++ invalid.
your program generated following output:
5345m34534l invalid. no2no123non4 ok. noq234n5ioqw#% invalid. %#""sgmsgser invalid. doghdp5234 ok. sg,dermoepm invalid. 43453-frgsd invalid. hsth())) invalid. bmepm35wae ok. vmopaem2234+0+ invalid. gsdm12313 ok. gswrgsrdgrsgsig45 ok. )/(/)(#=%#)%/ invalid. ++-+-+--+--+-+>-<+-<<_<-+>>++. invalid.
i don't understand exact question related period(.) @ end of page. can tell if want remove character don't want i.e. trimming. need use rstrip() function takes argument "the character want trim right side". e.g. rstrip('.'). if want else let know.
and expected , actual output looks same don't understand want say.
[edited]after comment understood want say:
with open("strings.txt") inf: line in inf: line = line.rstrip(" .") #added space , .(period) strip if line.isalnum(): print("{} ok".format(line)) else: print("{} invalid".format(line))
Comments
Post a Comment