-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathmakeTextFile.py
More file actions
44 lines (38 loc) · 1.03 KB
/
makeTextFile.py
File metadata and controls
44 lines (38 loc) · 1.03 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# coding:utf-8
'''
欢迎参加黄哥python远程视频培训,
帮你完成从不会写代码到会写代码解决问题的过渡。
https://github.com/pythonpeixun/article/blob/master/index.md
咨询qq:1465376564
黄哥Python培训 黄哥改写
Python 3
'makeTextFile.py -- create text file'
P52页 中文版书上错误点
1、少一个变量fname = input('Enter file name: ')
2、书上11-14行(下面的代码22-26) 行代码没有缩进
'''
import os
ls = os.linesep
# get filename
while True:
fname = input('Enter file name: ')
if os.path.exists(fname):
print("ERROR: '%s' already exists" % fname)
else:
break
# get file content (text) lines
all = []
print("\nEnter lines ('.' by itself to quit).\n")
# loop until user terminates input
while True:
entry = input('> ')
if entry == '.':
break
else:
all.append(entry)
# write lines to file with proper line-ending
fobj = open(fname, 'w')
fobj.writelines(['%s%s' % (x, ls) for x in all])
fobj.close()
print('DONE!')