1. 程式人生 > >用python把一個txt文件中所有逗號,替換成空格?

用python把一個txt文件中所有逗號,替換成空格?

image split() 技術分享 pytho pre ron lines mark class

 1 string = "word  2     3  4    5 6     7"
 2 string = ",".join(string.split())
 3 
 4 
 5 
 6 import numpy as np
 7 import pandas as pd
 8 a = pd.read_csv(list_landmarks_align_celeba.txt)
 9 print(a)
10 f = open("list_landmarks_align_celeba.txt","r")
11 for line in f.readlines():
12     line = "
,".join(line.split()) 13 print(line) 14 print(line[3]) 15 # print(line[ :2]) 16 # print(line[::2])

技術分享圖片

 

用python把一個txt文件中所有逗號,替換成空格?