2016-11-03 6 views

答えて

-2

を役に立てば幸いこの

file = open("myfile.txt", "r") 
lines = file.readlines() 
str = '' 

for i in range(len(lines)): 
    str += lines[i].rstrip('\n') + ' ' 

print str 

を試してみてください。

0

あなたがしようとしていることは不明です。 Pythonのイディオムでは(私はそれを理解していた場合)ここで

アウトラインです:

あなたのコード - コメント:

# file = file.open ("users.txt", r) NO! just use open' and don't use 'file' for a name 

# for user in users: What is 'users'? 
    # user = users.readline() # if this is a file, just do 'for user in users: ...' 
    ''' this is where I'd like to add something that creates user, user, until EOF ''' 
# file.close() # not necessary if you use `with` 

が修正:

with open("users.txt", r) as users: 
    for user in users: 
     # if each line of the file is a 'user' this gives you one user at a time 
関連する問題