Bottom Page

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
Quote
#2
Hello?
Quote
#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.
Quote
#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.
gahhon likes this post
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!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Help repeately prompting for directory name if it already exists. hikerguy62 3 252 Aug-05-2019, 01:43 PM
Last Post: ichabod801
  OS module and file/directory recovery hikerguy62 1 86 Aug-02-2019, 06:42 AM
Last Post: Gribouillis
  How do I set the path to my module one directory below my python 3.7.3 program? deac33 1 71 Jul-30-2019, 04:13 AM
Last Post: Larz60+
  File Path not recognised starzar 3 150 Jul-27-2019, 05:23 AM
Last Post: starzar
  FileNotFoundError...System cannot find the path specified alex9745 28 3,528 Jul-23-2019, 05:14 AM
Last Post: alex9745
  Help | How to make Dynamic Path/Address soothsayerpg 3 180 Jul-14-2019, 03:51 PM
Last Post: DeaD_EyE
  ImportError: cannot import name 'path' user123 2 216 Jul-14-2019, 10:08 AM
Last Post: Larz60+
  installation directory of modules in python3.7 srm 2 163 Jul-11-2019, 01:06 PM
Last Post: joe_momma
  Home Directory pgoosen 7 301 Jul-05-2019, 10:23 AM
Last Post: DeaD_EyE
  Writing the Path to a file properly dcw9996 2 189 Jul-01-2019, 11:26 PM
Last Post: dcw9996

Forum Jump:


Users browsing this thread: 1 Guest(s)