filename = os.path.abspath(sys.argv[1])
dirname = os.path.split(os.path.dirname(filename))[1]
my_file = open(filename, 'r')
lines = my_file.readlines()
my_file.close()
output_lines = [(dirname + ' ' + line) for line in lines]
my_file = open(filename, 'w')
my_file.write('\n'.join(output_lines))
my_file.close()
Use the folder name as a column in a text file