I'm trying to test run my program in C:\reader\compressed\ where I have created two test files 'test.gzip' and 'test.bz2' but when I go run the Reader class I get that the module reader has no attribute 'Reader'.
I'm opening python to "import reader" then "r = reader.Reader('test.bz2')"
Directory looks like:
I can import all the modules I've created.
import reader
import reader.compressed
import reader.compressed.gzipped
import reader.compressed.bzipped
Here is my reader.py:
import os
from reader.compressed import gzipped, bzipped
extension_map = {
'.bz2': bzipped.opener,
'.gz': gzipped.opener,
}
class Reader:
def __init__(self, filename):
extension = os.path.splitext(filename)[1]
opener = extension_map.get(extension, open)
self.f = opener(filename, 'rt')
def close(self):
self.f.close()
def read(self):
return self.f.read()
I've checked my modules to see that they are there along with the new files to test that are supposed to return the messages.
>>> import reader
>>> r= reader.reader.Reader('test.gz')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'reader' has no attribute 'reader'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Develop\Python\reader\__init__.py", line 13, in
__init__
self.f = opener(filename, 'rt')
File"C:\Python\Python36\lib\gzip.py", line 53, in open
binary_file = GzipFile(filename, gz_mode, compresslevel)
File
"C:\Programs\Python\Python36\lib\gzip.py", line 163, in
__init__
fileobj = self.myfileobj = builtins.open(filename, mode or
'rb')
FileNotFoundError: [Errno 2] No such file or directory:
'test.gz'