$ ./a.py b.xml
This is ok. a.py reads files and prints something.
a.py reads arguments as in
# Each argument is a file
args = sys.argv[1:]
# Loop on files
for filename in args :
# Open the file
file = open(filename)
I want to pipe the out to other scripts.
$ ./a.py b.xml | grep '1)'
This gives python error.
This also fails
$ x=$(./a.py b.xml); echo $x...
How to tell python not to interpret shell script syntax such as | $() `` ?
The error is
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)
The python script is from Python recipes.
And | cat works and it is so easy, requiring no .encode or any changes in the python script. – Ksthawma Oct 03 '13 at 20:27