how can i get a path of the main script from the library in python?

Use the built-in package pathlib‘s getcwd method. It defaults to the root folder of the top package.

Will not work if you change the working directory. Although, an unprefixed path is common practice to be relative to the working directory.

import pathlib

>>> A:\Programming\Python\generalfile

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top