python 参数及简单文件操作

来源:互联网 发布:linux 网络编程本地ip 编辑:程序博客网 时间:2024/05/16 14:39

将变量传入脚本(所写的.py文件),命令中的****.py部分就是所谓参数.


from sys import argv             //  sys为模块也有人叫库,argv为参数变量,由软件包提供特性

from os.path import exists    //   这个命令将文件名字符串作为参数,存在文件就返回True,否则Flase

script,from_file,to_file = argv

in_file = open(from_file)

indata = in_file.read()


out_file = open(to_file,'w')

out_file.write(indata)


out_file.close()

in_file.close()


这个代码运行不了就是大致的文件操作步骤。。。。。。。。。

原创粉丝点击