How to set relative path to executive script
Question: I want to set relative path to folder with my executive script that will works
from any machine without hardcoding absolute path to file. So far I have
following:

    
    
    import os
    path_to_folder = os.path.realpath('.')
    

When I run my script from `PyCharm` calling `print(path_to_folder)` return
correct path

`C:\Users\Me\Desktop\Project\Script\`

But if I try to call it from `cmd` like `python3.4
C:\Users\Me\Desktop\Project\Script\my_script.py` I get just

`C:\Users\Me\`

What is the more reliable way to set relative path?


Answer: I used to use [Pathlib](https://docs.python.org/3/library/pathlib.html)

    
    
    # get sibling file
    sib = Path(__file__).with_name(same_level_file)
    
    # get parent
    par = Path(__file__).parent
    
    # file in sibling parent
    sib2 = Path(__file__).parent.with_name(parent_folder).joinpath(file2)     
    

