$ ./a.py b.xml
还行吧。a.py 读取文件并打印一些东西。
a.py 读取参数,如
# Each argument is a file
args = sys.argv[1:]
# Loop on files
for filename in args :
# Open the file
file = open(filename)
我想通过管道输出到其他脚本。
$ ./a.py b.xml | grep '1)'
这给出了python错误。
这也失败了
$ x=$(./a.py b.xml); echo $x...
如何告诉 python 不要解释 shell 脚本语法,例如 | $() `?
错误是
Traceback (most recent call last):
File "./flattenXml.py", line 135, in <module>
process(file, prefix)
File "./flattenXml.py", line 116, in process
linearize(root, prefix + "//" + removeNS(root.tag))
File "./flattenXml.py", line 104, in linearize
linearize(childEl, path + '/' + numberedTag)
File "./flattenXml.py", line 104, in linearize
linearize(childEl, path + '/' + numberedTag)
File "./flattenXml.py", line 104, in linearize
linearize(childEl, path + '/' + numberedTag)
File "./flattenXml.py", line 104, in linearize
linearize(childEl, path + '/' + numberedTag)
File "./flattenXml.py", line 104, in linearize
linearize(childEl, path + '/' + numberedTag)
File "./flattenXml.py", line 104, in linearize
linearize(childEl, path + '/' + numberedTag)
File "./flattenXml.py", line 83, in linearize
print path + "/@" + removeNS(name) + "=" + val
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 106: ordinal not in range(128)
python 脚本来自Python recipes。