python按每行讀取文件后,會在每行末尾帶上換行符,這樣非常不方便后續業務處理邏輯,需要去掉每行的換行符,怎么去掉呢?看下面的案例:
>>> a = "hello world\n" >>> print a #可以看到hello world下面空了一格 hello world >>> a.split() #通過split方法將字符轉換成列表 ['hello', 'world'] #從列表中取第一個字符 >>> a.split()[0] 'hello' >>>
http://www.cnblogs.com/rayong/p/7141507.html