Linked Questions
19 questions linked to/from python: Change the scripts working directory to the script's own directory
603
votes
26
answers
637k
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....
863
votes
15
answers
1.5m
views
How do I change the working directory in Python?
cd is the shell command to change the working directory.
What is the equivalent in Python?
0
votes
1
answer
1k
views
Cannot change directory to a script using bash - cron [duplicate]
I have a script that runs multiple instances of Python Scrapy crawlers, Crawlers are int /root/crawler/batchscript.py
and in /root/crawler/ I have that scrapy crawler.
Crawlers are working perfectly ...
-3
votes
1
answer
260
views
Why is the output of readline() blank in a non-empty text file? [duplicate]
I am running python 3.7 in Wing IDE as an administrator.
The python file is in the same folder (Documents) as the textdoc file.
This is the python code I have:
file = open("textdoc.txt", "r")
...
0
votes
1
answer
99
views
Make Python Think It's Being Executed in Another Folder [duplicate]
I have a python script saved in a directory. When I run it from its folder it works as expected. However, when I run it through an interface (Unraid's User Script plug-in's "Run Script" ...
413
votes
16
answers
200k
views
How do you properly determine the current script directory? [duplicate]
I would like to see what is the best way to determine the current script directory in Python.
I discovered that, due to the many ways of calling Python code, it is hard to find a good solution.
Here ...
26
votes
6
answers
88k
views
Set working directory in Python / Spyder so that it's reproducible
Coming from R, using setwd to change the directory is a big no-no against reproducibility because others do not have the same directory structure as mine. Hence, it's recommended to use relative path ...
11
votes
1
answer
15k
views
How do I make CMake run a python script before building, in order to generate files for my project to be used in the build?
I have a python script that parses all of the C++ source files in the project's directory, looks for some stuff in the files, and then generates a file. This python script works fine, but I want it ...
6
votes
2
answers
8k
views
Python : download as pdf all emails from a label (gmail)
I would like to download 100+ email from gmail as pdf. It would be too long to manually download all of them via the print option in gmail.
This python script retrieves the emails in the chosen label....
0
votes
1
answer
2k
views
How to Change directory to the python script directory [duplicate]
In batch there is a command %~dp0 which mean change the directory to the script directory, for example: Batch file is in desktop, if you use %~dp0 the directory instantly go to the C:\Users\Windows\...
2
votes
1
answer
6k
views
Supervisor - program's directory option not working
I want to execute python script by supervisor.
I set up the directory option in supervisord.conf
and I used relative path in command option like this.
[supervisord]
http_port=/var/tmp/supervisor....
4
votes
2
answers
2k
views
Python script from Cron
I have finished a program in Python and I intend for it to be run from my RPi every n hours. This will be my first time running such program/script in this way and I would like to know if there is ...
1
vote
2
answers
1k
views
Python importing only modules within package
I am creating a Python package with multiple modules. I want to make sure that when I import modules within the package that they are importing only from the package and not something outside the ...
1
vote
1
answer
2k
views
Python Error message when opening .txt file / change in working directory
I’m a new python user and have written a python script that prompts for the name of a text file (.txt) to be opened and read by the program.
name = raw_input("Enter file:")
if len(name) < 1:
...
0
votes
4
answers
939
views
How can I change the folder where a file is created in python?
I would like to change the folder where a file is created in my Python Script.
Just now I have the next line:
file = open("scraping.txt", "w")
but the problem is that scraping.txt is saved in the ...