import os
def paths(filename):
dirList = ['c:\\', 'y:\\', 'z:\\']
complete = [os.path.join(s, filename) for s in dirList]
return complete
def fileWrite():
for each_file in paths('c:\\peter.txt'):
text = 'Hello World'
file = open(each_file, 'w')
file.write(text)
file.close()
Или, как указывает Ipthnc ниже, функция paths может быть сокращена до:
def paths(filename):
return [os.path.join(s, filename) for s in ('c:\\', 'y:\\', 'z:\\')]