I am new to Python and I'm working with some tar files. The following example works:
#!/usr/bin/python
import os, readline, tarfile, scipy.io, numpy as np, sys
year = 2012;
month = 12;
day = 10;
RS = 9;
hour = 00;
minute = 05;
seconds = 00;
UTC = 1355094300;
anArchive = '/Users/user/data/20121210.zip';
tar = tarfile.open(anArchive);
dynamicPath = './%4d%2d%2d/RS%02d/%02d%02d%02d_%10d/all.txt' %(year, month, day, RS, hour,minute, seconds, UTC);
print(dynamicPath);
memb = tar.getmember(dynamicPath);
file = tar.extractfile(memb.name);
print('loading file with measurements...\n');
contents = file.read();
destinationFile = open("extractedFile.txt", "w");
destinationFile.write(contents);
which gets a file from a tar, extracts it and writes it in a new file.
Now I want to define a function that does the exact same thing:
#!/usr/bin/python
import os, readline, tarfile, scipy.io, numpy as np, sys
def extractFile():
year = 2012;
month = 12;
day = 10;
RS = 9;
hour = 00;
minute = 05;
seconds = 00;
UTC = 1355094300;
anArchive = "/Users/user/data/20121210.zip";
tar = tarfile.open(anArchive);
dynamicPath = "./%4d%2d%2d/LOSS_RS%02d/%02d%02d%02d_%10d/all.txt" %(year, month, day, RS, hour,minute, seconds, UTC);
print(dynamicPath);
#memb = tar.getmember("./20121210/RS09/004501_1355096701/all.txt");
memb = tar.getmember(dynamicPath);
file = tar.extractfile(memb.name);
print('loading file with measurements...\n');
contents = file.read();
destinationFile = open("extractedFile.txt", "w");
destinationFile.write(contents);
return
After I save it and make sure that is executable, I execute it from the terminal checking also for Indentation errors:
python -t extractFile.py
and the result is nothing. No error, the execution "finishes" but with no result, like if I had executed empty code.
Any ideas why the same exact code doesn't work when used as a function ?