Linked Questions
75 questions linked to/from Relative paths in Python
603
votes
26
answers
638k
views
How to get the path and name of the Python file that is currently executing?
I have scripts calling other script files but I need to get the filepath of the file that is currently running within the process.
For example, let's say I have three files. Using execfile:
script_1....
0
votes
1
answer
3k
views
Python - Access the Temp-Folder [duplicate]
I ́m trying to write a file into the %temp%-Folder, but the username of every User is different.
Does Python have a function or some kind like that to join the folder?
I tried it like this, but I get ...
0
votes
0
answers
4k
views
How do I load a UI file into a python file? [duplicate]
I'm a new programmer, sorry If my question is too basic
I created a mybutton.ui file in Qt Designer, Then I want to run it through my python app.
the mybutton.ui file is next to Qt-Designer-GUI-Code....
3
votes
0
answers
3k
views
How to load Qt Designer UI file [duplicate]
import sys
from PyQt5.uic import loadUi
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication, QWidget
from PyQt5.QtGui import QPixmap
from PyQt5 import uic
class WelcomeScreen(...
-1
votes
1
answer
1k
views
file can't be found when using relative path [duplicate]
I am doing a vehicle license plate detection and recognition project. My code was working perfectly fine and then all of a sudden it stopped working. It seems as if opencv stopped working completely.
...
0
votes
1
answer
1k
views
How to go back 1 directory in Python [duplicate]
Im use this path to go back 1 directory (back to directory 'dsa')
with open('../file.txt','r',encoding='utf-8') as f:
print(f.read())
I get this error
Traceback (most recent call last):
File &...
0
votes
1
answer
1k
views
How to run an .exe from the same folder as my Python program [duplicate]
The title may not be the best description of what I'm trying to do. I made a few simple lines of code to run a .exe, in this case the adobe reader installer.
import os
os.system('"D:/Python ...
1
vote
0
answers
108
views
How to get the directory of a function? [duplicate]
For example:
in the file main/main.py
import core.fun as f
f.script()
and in the file main/core/fun.py:
def script():
f = open('test.txt','r')
where a file test.txt is present in the folder main/...
0
votes
0
answers
82
views
relative paths in python modules [duplicate]
I am writing a python library with the following file structure:
main_folder
|
main.py
|
module_subfolder/
| |
| module.py
|
resources/
|
...
0
votes
0
answers
66
views
How to use relative imports? [duplicate]
How can I read the /billy/var/text.txt into b.py
The directory structure is:
/billy/b.py
/billy/var/text.txt
/sally/s.py
s.py
import sys, os
sys.path.append('..')
from billy import b
print('s.py - ...
0
votes
0
answers
75
views
Best practices for giving a relative file path in python so that the program can be used in the most locations [duplicate]
I'm currently experiencing problems accessing files inside my python project depending on where I call the program from. I can't seem to find an appropriate answer using the search bar.
I have a ...
981
votes
19
answers
1.5m
views
open() in Python does not create a file if it doesn't exist
What is the best way to open a file as read/write if it exists, or if it does not, then create it and open it as read/write? From what I read, file = open('myfile.dat', 'rw') should do this, right?
It ...
806
votes
22
answers
952k
views
Import a module from a relative path
How do I import a Python module given its relative path?
For example, if dirFoo contains Foo.py and dirBar, and dirBar contains Bar.py, how do I import Bar.py into Foo.py?
Here's a visual ...
1081
votes
12
answers
1.6m
views
How to get an absolute file path in Python
Given a path such as "mydir/myfile.txt", how do I find the file's absolute path in Python? E.g. on Windows, I might end up with:
"C:/example/cwd/mydir/myfile.txt"
429
votes
16
answers
663k
views
Why doesn't os.path.join() work in this case?
The below code will not join, when debugged the command does not store the whole path but just the last entry.
os.path.join('/home/build/test/sandboxes/', todaystr, '/new_sandbox/')
When I test this ...
chrisg's user avatar
- 41.8k