Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Directory path
#1
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
Reply
#2
Hello?
Reply
#3
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.
Reply
#4
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.
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I set the path to my module one directory below my python 3.7.3 program? deac33 1 532 Jul-30-2019, 04:13 AM
Last Post: Larz60+
  Directory path EOF Graham 8 1,408 Nov-28-2018, 10:13 PM
Last Post: Graham
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 2,062 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020