2016-11-01 3 views
0

모든 요소가 온라인 파일의 한 줄인 목록을 만들고 싶습니다. 그러나 목록을 분리하려면 EM을받습니다. "TypeError : 바이트와 같은 객체가 필요하며 'str'이 필요하지 않습니다. 나는 이미 decode ('utf8')로이 문제를 해결하려고 노력했지만 나는 할 수 없었다. 조언?목록 분할 : TypeError : 'str'이 아닌 바이트와 같은 객체가 필요합니다.

def collect_record(name): 
file = "http://www.uniprot.org/uniprot/%s.txt" %name 
u=urllib.request.urlopen(file) 
pdblines=u.readlines() 
for line in pdblines : 
    line = ligne.strip() 
    pdblines = line.split("b") 
u.close() 
return pdblines 
+0

당신은 당신의 게시물에 전체 역 추적을 추가해야합니다. 또한 코드에 오타가 있습니다. 'ligne.strip()'. [mcve]를 입력하십시오. –

답변

0

텍스트 파일이므로 특별히 수행 할 필요가 없습니다.

def collect_record(name): 
    file = "http://www.uniprot.org/uniprot/%s.txt" % name 
    lines = [i for i in urllib.request.urlopen(file)] 
    return lines 

좀 더 명시 할 경우

def collect_record(name): 
    file = "http://www.uniprot.org/uniprot/%s.txt" % name 
    lines = str(urllib.request.urlopen(file).read()).split('\n') 
    return lines 
+0

도움 주셔서 감사합니다. –

관련 문제