使用Python,如果我想的话
A.使用argv读取中的文本文件
B.进行字符串替换(搜索和替换)
用新名字写一个新文件
我可以用一个open()函数来实现吗?这是我目前掌握的,是的,我知道它不会像现在这样运行。你知道吗
import sys, re
FarmFixer, farmfile = argv
print "What is the serial number of the site?",
_nnn = raw_input()
print "What is the brand, or product name?",
_brand = raw_input()
print "What is the (fqdn) ServerName?",
_server_name = raw_input()
print "What is the content path?",
_content_path = raw_input()
print "What is the DAM path?",
_dampath = raw_input()
print "Which environment is this for?",
_env = raw_input()
print "What is the cache document root?",
_cache_docroot = raw_input()
for line in file_open:
re.sub("NNN", "_nnn", line)
re.sub("BRAND", "_brand", line)
re.sub("CONTENT_PATH", "_content_path", line)
re.sub("DAMPATH", "_dampath", line)
re.sub("ENV", "_env", line)
re.sub("CACHE_DOCROOT", "_cache_docroot", line)
farmfile = _nnn + _brand + "farm.any"
outie = open(farmfile, 'w')
outie.close
print farmfile
当然了回复sub线路完全失灵。你知道吗
你说你有两个文件,一个你要读,另一个你要写。您需要打开每个文件。你知道吗
这个问题本质上与老问题相同:edit text file using Python。你需要打开一个文件,读取它,打开另一个文件,然后写入它。你知道吗
相关问题 更多 >
编程相关推荐