Remove leading and trailing spaces?

后端 未结 4 1421
醉梦人生
醉梦人生 2020-12-07 19:57

I\'m having a hard time trying to use .strip with the following line of code.

Thanks for the help.

f.write(re.split(\"Tech ID:|Name:|Account #:\",li         


        
4条回答
  •  独厮守ぢ
    2020-12-07 20:15

    Expand your one liner into multiple lines. Then it becomes easy:

    f.write(re.split("Tech ID:|Name:|Account #:",line)[-1])
    
    parts = re.split("Tech ID:|Name:|Account #:",line)
    wanted_part = parts[-1]
    wanted_part_stripped = wanted_part.strip()
    f.write(wanted_part_stripped)
    

提交回复
热议问题