You are welcome! I did it so you can see that is not so complicated when you are doing it step by step. Tiny steps. As @Kebap said.
Look at
os.path.join(dir, subdir, filename)
You can use
Look at
os.path
module. os.path.join() takes a bunch of arguments and join them to create a properly formated path acording to the OS. os.path.join(dir, subdir, filename)
1 2 3 4 5 6 7 8 9 |
import os.path dir_ = some_dir # dir is reserved word in Python. root is more suitable variable name :-) subdir = subdir file_name = '{}.txt' . format (element[ 0 ]) path = os.path.join(dir_, subdir, file_name) with open (path, 'w' ) as out_file: # etc. |
os.path.abspath(dir)
on dir
to get the full path of the dir. As a precaution.