Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What did I do wrongly?
#2
(Aug-07-2022, 07:25 AM)Tomi Wrote: The icon.ico is in the same folder as the script im trying to run.
Python will use the path relative to the current working directory, not the directory containing the script. Two solutions:
  1. Hard code the full path to the file, such as "/spam/eggs/icon.ico"
  2. Have the code compute the full path like in the below example
from pathlib import Path
this_dir = Path(__file__).resolve().parent
icon_ico = str(this_dir / 'icon.ico')
If you want to distribute the program as a Python module, another option is to use package data files.
Reply


Messages In This Thread
What did I do wrongly? - by Tomi - Aug-07-2022, 07:25 AM
RE: What did I do wrongly? - by Gribouillis - Aug-07-2022, 08:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python reading variable in another py file wrongly _vertig0 2 2,091 Nov-21-2020, 07:19 AM
Last Post: _vertig0

Forum Jump:

User Panel Messages

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