python use os.path.join to take specific location

Question:

I need to save a folder called D:MyPc if the hostname is MyPc

name_file = open("D:/Others/name.txt" , "r")
data = name_file.readline()
name_file.close()
print(os.path.join("D:", data))

the output is D:
MyPc

Answers:

To check the hostname: How can I use Python to get the system hostname?

Also, there is an error in your code. Change the last line to have double backslash in string:

print(os.path.join("D:\", data))
Answered By: mlokos
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.