티스토리 뷰

Python

File

techbard 2016.06.13 09:50




# file write, read


import random


with open('my_file.txt', 'w') as f:

for _ in range(10):

f.write('a' * random.randint(0, 100))

f.write('\n')


value = [len(x) for x in open('my_file.txt')]

print(value)


# 결과

[33, 5, 11, 78, 11, 28, 47, 76, 20, 77]


댓글
댓글쓰기 폼
공지사항
Total
409,074
Today
3
Yesterday
40
«   2019/10   »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
글 보관함