0

I want to save some files generated by my program to "<drive_name>\Users\<computer_name>\Documents" folder.

I need the drive and computer name. What would be a neat way to achieve this. I usually get the current working directory and just split the string to get that info but there has to be a better way right?

2

1 Answer 1

0

pathlib is more pythonic.

ex)

In [1]: from pathlib import Path

In [2]: path = Path('~').resolve()

In [3]: path
Out[3]: PosixPath('/home/phi/git/python/etl/~')

just declare path = Path(__file__) in your script.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.