Reputation: 864
I am asking a very basic question but I am confused about it.
filepath = os.path.join(dir_path, 'filename.txt')
f1 = open(r'E:/pjt/filename.txt', 'w+')
I am trying to pass the location of filename.txt to the second step. Can anybody teach me how to do it? I tried using +filepath+
but I could not.
Upvotes: 1
Views: 141
Reputation: 77
You can use the following code snippet to get the current directory of the file, then use it for join or other commands.
import os
_cur_dir = os.path.dirname(__file__)
Upvotes: 0
Reputation: 312289
filepath
is already a path to the file - just use it:
filepath = os.path.join(dir_path, 'filename.txt')
f1 = open(filepath, 'w+')
# Here ---^
Upvotes: 1