Find path of Python file run from Pyzo [duplicate]

1 week ago 15
ARTICLE AD BOX

What I want to get is "C:\Users\myname\Desktop\diodo_laser\grafici_diodo_laser.py", or the same without "grafici_laser_diodo.py"

Since you know the directory is under your home directory, you can find it using pathlib or os.path.

For example, using pathlib:

from pathlib import Path home = Path.home() mydir = home / "Desktop" / "diodo_laser"

mydir would a pathlib.Path object pointing to your directory.

or with os.path:

from os.path import expanduser home = expanduser("~") mydir = os.path.join(home, "Desktop", "diodo_laser")

mydir would a string containing the path to your directory.

Read Entire Article