2015-02-04 5 views
-1
import re 

f= ('HelloHowAreYou') 
f = re.sub(r"([a-z\d])([A-Z])", r'\1 \2', f) 
# Makes the string space separated. You can use split to convert it to list 
f = f.split() 
print (f) 

텍스트 파일의 모든 문자열을 대문자로 구분하여 사용할 수 있지만 텍스트 파일을 읽을 때 코드를 변경하면 문제가 발생합니다. 누군가가 왜 어떤 빛을 비추 수 있습니까?텍스트 파일 읽기 및 스트라이핑

내가 사용하여 파일 읽기 :

f = open('words.txt','r') 

답변

1

는 내가 사용하고 파일 읽기 :

F = 개방 ('words.txt', 'R')를

그러나 코드는 파일을 읽지 않고 열뿐입니다. 시도 :

my_file = open('words.txt','r') 
f = file.read() 
my_file.close() 

또는

with open('words.txt','r') as my_file: 
    f = my_file.read()