0

I have a project that will be used by a lot of developers, so I need to create a local file that specifies the path for each developer that runs the code.

How can I write a path that suites all devices? Is that possible?

I don't want to specify the root name, for example:

with open("/Users/myname/.ssh/pri.txt", "w") as f:   
    f.write(str(private_key.to_pem()))

This is what I mean, I don't want the Users/myname/ to specify and modify for each dev.

xihtyM
  • 240
  • 1
  • 2
  • 9
Starlight
  • 15
  • 3
  • 1
    Use [`Path.home()`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.home) and other Pathlib methods to specify the path relative to that. – Barmar Mar 08 '23 at 07:55
  • What have you tried ? What is your expected output ? This is a trivial task, as you could just use the interpreter context path. – Itération 122442 Mar 08 '23 at 07:55
  • @Barmar I will try this method.Thank you ,@Itération 122442 I update the question please check. – Starlight Mar 08 '23 at 07:59
  • 2
    Does this answer your question? [What is a cross-platform way to get the home directory?](https://stackoverflow.com/questions/4028904/what-is-a-cross-platform-way-to-get-the-home-directory) For your specific example `Path.home() / ".ssh" / "pri.txt"` or `Path.home().joinpath(".ssh", "pri.txt")` should be what you want. – Abdul Aziz Barkat Mar 08 '23 at 08:00

1 Answers1

0

Thank you all, you helped me a lot.

I found a solution that works:

from pathlib import Path


with open(Path.home().joinpath(".ssh", "pri.txt"), "w") as f:   
    f.write(private_key)

Using Path.home()

Starlight
  • 15
  • 3