Python Forum
Problem with absolute path to file (Mr.Stickman Problems)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with absolute path to file (Mr.Stickman Problems)
#4
Sometimes when you start a program from another directory, or call a subprogram, the working directory mat not be what you thing it is.
This can be a problem is you assume it starts with the python file directory.
You can assure a starting location with the following snippet:
import os

path = os.path.dirname(__file__)
os.chdir(path)
you can then get the absolute path to your 'Background.gif.xcf' (is that really the file name?) file by using a relative
path as argument to os.path.abspath(relative_path) (of course replacing relative path with something like 'images/Background.gif.xcf')
Reply


Messages In This Thread
RE: Mr.Stickman Problems - by woooee - Jun-26-2018, 05:13 AM
RE: Mr.Stickman Problems - by buran - Jun-26-2018, 06:21 AM
RE: Problem with absolute path to file (Mr.Stickman Problems) - by Larz60+ - Jun-26-2018, 10:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Absolute paths in subprocess - file not found kittyticker 4 530 Jan-28-2024, 10:37 PM
Last Post: kittyticker
Sad problems with reading csv file. MassiJames 3 673 Nov-16-2023, 03:41 PM
Last Post: snippsat
  File path by adding various variables Mishal0488 2 1,064 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  Script File Failure-Path Error? jerryf 13 3,502 Nov-30-2022, 09:58 AM
Last Post: jerryf
  Upgrading from 2 to 3 and having file write problems KenHorse 2 1,515 May-08-2022, 09:47 PM
Last Post: KenHorse
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,235 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  (Path?)Problems with dockerizing a python app sgofferj 0 1,639 Jul-19-2021, 10:02 AM
Last Post: sgofferj
Exclamation Path sacn problem lucky511 10 3,940 Jun-24-2021, 12:09 PM
Last Post: Axel_Erfurt
  Problems with inserting images into an Excel File FightingFarmer 2 3,435 May-12-2021, 10:03 PM
Last Post: FightingFarmer
  Subprocess.Popen() not working when reading file path from csv file herwin 13 15,204 May-07-2021, 03:26 PM
Last Post: herwin

Forum Jump:

User Panel Messages

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