When
in doubt, turn the problem around 90 degrees.
stdio 's
fopen(): filename is the file name to be
opened, mode indicates how the file is to be opened: 'r'
for reading, 'w' for writing (truncating an existing file), and
'a' opens it for appending (which on some Unix systems means that all
writes append to the end of the file, regardless of the current seek position).
The
problem is that your file contains BINARY data....
So,
let's remove the binary data:
import sys import string def strip_binary ( filename, newname
):
test = open ( filename, 'rb') stripped = open (newname, 'wb') data =
""> while data <>
"":
data = "" (1) if data <> "": if data in string.printable: stripped.write (data) stripped.close
()
test.close () strip_binary ( sys.argv[1],
sys.argv[2])
This will remove all characters that are not contained in the string
modules PRINTABLE variable.
Then
you should be able to open the NEW file as a ASCII file, without any
issues.
You
could instead of creating a temporary file, write the data to a list, and then
use a SPLIT("\n") on the temporary list, and process that. That would be
the rough equivalent of READLINES....
- Ben
|
_______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32