및 공백으로 구분하여 각 열을 가져옵니다. 각 파티션의 크기와 여유 공간을 추출 할 수있는이 방법 :
contents = # here go the file contents
# split the text file into lines and ignore the first line
lines = contents.splitlines()[1:]
part_data = {}
for line in lines:
columns = line.split() # split the lines along the white space characters
if len(columns) != 3:
continue # incomplete lines
part_data[columns[0]] = (columns[1], columns[2])
당신에게 사전에있는 모든 파티션의 여유 공간과 크기를 제공 할 것입니다. 실제 결과를 얻으려면 그것은 것 : 거기 당신을
contents = # here go the file contents
second_line = contents.splitlines()[1]
second_column = second_line.split()[1]
: 당신은 드라이브 문자를 무시하고, 두 번째 열 및 두 번째 행을 원하는 경우에
part_data['C:'][0]
, 당신은 다음에 그것을 줄일 수 있습니다 가고 싶지만, 항상 똑같은 형식이어야합니다. 두 번째 줄에 세 개의 열이 없으면 실제로 작동하지 않고 IndexError
이됩니다.
a_string.split()
은 모든 공백을 자동으로 제거하고 a_string.split(' ')
은 공백을 자동으로 반환합니다.
이
#Open file in lines
file = open('path/to/txt','r').readlines()
#For each line
for disk in file:
fields = disk.split("\t")
#To check the total fields...
if(len(fields)>1):
print fields[1]
겠습니까 파일의 모든 데이터를 읽고에만 읽기 목록에서 필요한 데이터가 가능한 해결책이 될 추출? – Ashan
이미 시도한 것이 있습니까? 그리고 그것을 동적이거나 항상 두 번째 열의 두 번째 열이되기를 원합니 까? – xZise
@xZise 항상 두 번째 행의 두 번째 coloum –