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
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.
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:
#!/usr/bin/env python3
"""
This program prints only the content of the directories docs and images.
The images are opened with PIL and their size is printed to console.
The pathlib module has been used to demonstrate how easy it is,
to do object oriented path manipulation.
This can be very helpful, if your program has no fixed location in your system,
where the location of the program itself defines the location of ressources.
"""
import sys
from pathlib import Path
from PIL import Image
cwd = Path.cwd()
# current working directory could be any location in system path
exe = Path(sys.argv[0]).resolve().parent
# sys.argv[0] holds the scriptname as str, which is executing
# putting this in a Path() makes a Path object from it
# the method resolve removes the dots in the path
# and makes the path absolute.
# The parent attribute holds the parent part of the path
# If the path was before a file, the parent is it's directory
# If the path was a directory, then it's the directory above
# The benefit of pathlib is, that it works with Linux, MacOS and Windows.
# If you're using the API of this module, you're on the safe side.
# The abstraction and some os differences are handled by this module
images = exe.parent / 'images'
docs = exe.parent / 'docs'
# parent means the previous part of the path
# goes one directory up
print('Current working directory:', cwd)
print('Directory of executable:', exe)
print('Images:', images)
print('Docs:', docs)
print()
print('Listing content of docs')
for file in docs.glob('*.pdf'):
print(file)
print()
print('Listing content of images')
for file in images.glob('*.png'):
img = Image.open(file)
width, height = img.size
print(f'Found image {file} with size {width}x{height}')
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.