I've written a small program that, in part, reads in a file and parses
it. Sometimes, the file is gzipped. The code that I use to get the
file object is like so:
if filename.endswi th(".gz"):
file = GzipFile(filena me)
else:
file = open(filename)
Then I parse the contents of the file in the usual way (for line in
file:...)
The equivalent Java code goes like this:
if (isZipped(aFile )) {
input = new BufferedReader( new InputStreamRead er(new
GZIPInputStream (new FileInputStream (aFile)));
} else {
input = new BufferedReader( new FileReader(aFil e));
}
Then I parse the contents similarly to the Python version (while
nextLine = input.readLine. ..)
The Java version of this code is roughly 2x-3x faster than the Python
version. I can get around this problem by replacing the Python
GzipFile object with a os.popen call to gzcat, but then I sacrifice
portability. Is there something that can be improved in the Python
version?
Thanks -- Bill.
it. Sometimes, the file is gzipped. The code that I use to get the
file object is like so:
if filename.endswi th(".gz"):
file = GzipFile(filena me)
else:
file = open(filename)
Then I parse the contents of the file in the usual way (for line in
file:...)
The equivalent Java code goes like this:
if (isZipped(aFile )) {
input = new BufferedReader( new InputStreamRead er(new
GZIPInputStream (new FileInputStream (aFile)));
} else {
input = new BufferedReader( new FileReader(aFil e));
}
Then I parse the contents similarly to the Python version (while
nextLine = input.readLine. ..)
The Java version of this code is roughly 2x-3x faster than the Python
version. I can get around this problem by replacing the Python
GzipFile object with a os.popen call to gzcat, but then I sacrifice
portability. Is there something that can be improved in the Python
version?
Thanks -- Bill.
Comment