from sys import argv
from os.path import exists
script, from_file, to_file = argv
print "Copying from %s to %s" % (from_file, to_file)
input = open(from_file)
indata = input.read()
print "The input file is %d bytes long" % len(indata)
print "Does the output file exist? %r" % exists(to_file)
print "Ready, hit RETURN to continue, CTRL-C to abort."
raw_input()
output = open(to_file, 'w')
output.write(indata)
print "Alright, all done."
output.close()
input.close()
作者说,他能用一行代码写出来。。。。
1
hahastudio 2015-08-04 21:36:19 +08:00 1
|
2
zyqf OP |
3
ytf4425 2015-08-04 21:44:06 +08:00
外行人来欣赏艺术来了
看来码农也有码神啊 |
5
hahastudio 2015-08-04 21:47:53 +08:00
@zyqf 不嫌难看的话,你总可以用 ; 分隔
功能上讲的话,那些答案都说明了 |
6
expkzb 2015-08-04 21:51:23 +08:00
we could do these two on one line too, how?
意思不是把特指的两行变一行么 |
7
minvacai 2015-08-04 21:54:31 +08:00
cp from_file to_file #你够
|
10
zyqf OP @hahastudio 我还以为有什么复杂的写法呢。。。。
|
12
bububut 2015-08-04 22:11:26 +08:00
楼主需提高阅读理解水平,没让你把所有代码变成一行
|
13
leavic 2015-08-04 22:11:30 +08:00
lambda(语句1 and 语句2 and 语句3)
|
16
gamexg 2015-08-04 22:40:14 +08:00 1
指的是这个?还是全部?
print 'Copying from %s to %s'%(__import__('sys').argv[1:]) |
17
zyqf OP |
18
zhuangzhuang1988 2015-08-06 11:12:51 +08:00
再怎么复杂的代码都能 exec "from sys import argv;open(argv[2], 'w').write(open(argv[1]).read())"
|
19
WKPlus 2015-08-06 13:53:03 +08:00
最后的写法,文件都没关闭。干嘛非要一行写呢,又不是越少越优雅
|
20
saber000 2015-08-06 17:29:08 +08:00
open(__import__("sys").argv[2], "wb").writelines(open(__import__("sys").argv[1]))
|
21
goldalan 2016-04-23 04:17:46 +08:00
from sys import argv;open(argv[2], 'w').write(open(argv[1]).read());print("Great")
|