-1

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

hannes101
  • 2,410
  • 1
  • 17
  • 40
  • what is the problem ? That is very unclear what you expect – azro Oct 23 '22 at 18:57
  • What is in `data`? I'm surprised that `"D:\"` parsed, but if `data` is a fully qualified path name, the join won't change it. – tdelaney Oct 23 '22 at 19:02
  • Instead of opening a file we don't have access to, just initialize `data` to something that we can test. The code you post will raise a syntax error and I don't see any way that it could produce the output shown. – tdelaney Oct 23 '22 at 19:11
  • The variable data is not important i just need to group them without space – Kafası Güzel Penguen Oct 23 '22 at 19:25

1 Answers1

2

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))
mlokos
  • 359
  • 2
  • 10