I have some code that I translated from python 2 to python 3 (there are no visible differences in my example, but it is changed). Basically, my code reads a binary audio file. The sizes of the same raw audio file are wildly different after they are read and I have no idea why. The main difference is that one of the programs is run in python 3.8 and the older one is 2.7.
Python 3 code:
def __read_file(self, file):
try:
a_dir = os.path.join(TestContext().accuracy_dir,self._accuracy,"Audio") if \
self._accuracy else TestContext().media_dir
if "http://" in file:
f = urllib.request.urlopen(file)
a_buffer = f.read()
else:
if False == os.path.isabs(file):
file = os.path.join(a_dir, file)
with open(file, mode='rb') as f:
a_buffer = f.read()
except IOError as e:
raise IOError('I/O error({0}): {1}'.format(e.errno, e.strerror))
print("AUDIO BUFFER LENGTH", len(a_buffer))
return a_buffer
Python 3 result:
AUDIO BUFFER LENGTH: 3977
Python 2 result:
AUDIO BUFFER LENGTH: 122400
My [python](advertisement redacted) 2 code is the exact same except with urllib2 instead of urllib.
Also, the python 2 way is the correct way. My audio file should be that big. I’m not sure why it suddenly smaller.
Any help is appreciated.