Python Forum
Directory path - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Directory path (/thread-16474.html)



Directory path - gahhon - Mar-01-2019

I do have some issues regarding the directory path value.
Let's say my folder structure is like this
  • Python
    • config folder (containing several .ini files)
    • log folder (containing several .log files)
    • exe folder (containing several .exe files, these .exe files are compiled via pyinstaller)
    • Startup.exe

So the program is must be execute the Startup.exe then trigger the buttons.
Each buttons will handle different .exe files inside the exe folder.
So before I compile the Python scripts to executable files, I did declared the config and log path. For instance:
CONST_LOG_PATH = '..\log\common.log'
CONST_CONFIG_PATH = '..\config\common.config'
So based on this paths value, if I execute the .exe itself (inside exe folder), it will point to the correct as I declared.
But if I execute them via Startup.exe, it will point to the path before Startup.exe
So I modify those 2 paths to without ..\ and it work as expected.

So I wondering the path values should be declare where you are trigger from?

Thanks


RE: Directory path - gahhon - Mar-03-2019

Hello?


RE: Directory path - snippsat - Mar-03-2019

You most explain better,not possible to understand this.
When you say buttons is this a GUI or a web-app?
Handling other binary file .exe,you could use subprocess.

Can't except people know what you have done before when make a new Thread.
Is this also with Selenium as posted before,you most give info about that or link to Thread/posts with info.


RE: Directory path - DeaD_EyE - Mar-03-2019

As anchor you can use different locations or you work with absolute paths, which makes your program less flexible.

If you use the current working directory, you have to be in the right path, if you execute the program. This is not very usable, if the program lives somewhere on your path. When your program is somewhere in /usr/bin or C:\Windows\system32\, the working directory differs from Path, where the executable file is.

For myself I use the executable itself as anchor and define, all directories next to the executable. Here an example:

import sys
from pathlib import Path

cwd = Path.cwd()
exe = Path(sys.argv[0]).resolve().parent

print('Current working directory:', cwd)
print('Directory of executable:', exe)
print('Directory for images next to executable', exe / 'images')
If you have for example this structure:
Output:
|- project_test/ |- bin/ |- your_program |- docs/ |- Mastering_Natural_Language_Processing_with_Python.pdf |- learning_numpy_array.pdf |- images/ |- siemens_updates.jpg |- 11106-256x256x32.png |- x_vs_xor_vs_aes.png
The program:
If you plan to put your project into a zip file, together with resources, it's different.
But I guess you're not so far. First you should try pathlib, which helps a lot.

Edit: Instead of getting absolute paths of images, you can do it with the executable files. Another solution could be, to put the executable files in the system path, but this makes less fun.