Linked Questions

576 votes
26 answers
619k views

How do I 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: ...
Ray's user avatar
  • 190k
3 votes
2 answers
5k views

Django FileNotFoundError in a view when returning HTML using codecs [duplicate]

I am creating a view in Django that returns a static HTML page, and my code for that view is as follows: from django.shortcuts import render from django.http import HttpResponse from django.shortcuts ...
Vinayak G.'s user avatar
-1 votes
1 answer
6k views

FileNotFoundError: [Errno 2] No such file or directory: 'greetings.txt' [duplicate]

I am stuck to this weirdly small problem for like 3 hours and i just can't find the fix of it. Here look at the problem I'm trying to read a .txt file(greetings.txt) which contains a simple message ...
Sunyog Lodhi's user avatar
-1 votes
2 answers
1k views

How to specify a directory in Python [duplicate]

I am making a simple game with pygame, and I want it to eventually be shareable with others. However, my code manually changes the directory of the python file each time, which uses a path. I thought ...
Luke Piasecki's user avatar
0 votes
2 answers
1k views

Python3 can't read or at least find file [duplicate]

I'm playing around with python3+ but yet can't get it to read a file thats local to the git repo output pyyaml version = 5.3.1 Whoops! Can't find config.yml file --- exiting Process finished with ...
Tony's user avatar
  • 9,131
0 votes
1 answer
107 views

What is going on? I am using Python to fetch a directory with os but it's not working [duplicate]

I am creating a decision tree and I give it a picture of either a cat or dog and it will decide whether it can detect if it is a cat or dog. I created a directory in my project called 'Images' and put ...
blackscratch22's user avatar
-2 votes
1 answer
93 views

CSV file unable to be found [duplicate]

I am trying to run this code to read csv file then take an item number in the csv and search for it in a website, then give me URL of the results. The issue is that it is unable to find the csv file. ...
Zainab Alkamal's user avatar
0 votes
2 answers
88 views

Exception occurring when trying to open a file with python [duplicate]

I am trying to open a file with python like this: m = open("e.txt", 'r') The text file I'm trying to open is in the same directory as my python file is. However I'm getting an error message....
gamer_294's user avatar
1 vote
0 answers
88 views

Set current directory when running a Python project [duplicate]

I have a Python project which I want to run, let's say the folder is called foo. The folder contains an __init__.py. If I run it like this: ~ $ ls foo/ __init__.py img.png # etc... ~ $ python -m foo ...
tleb's user avatar
  • 4,485
0 votes
2 answers
102 views

Using "Subprocess Call" to call a program at an unkown directory [duplicate]

I'm looking for a way to open another python file in the same folder, but it could be anywhere on a PC. (i.e when I send it to someone the program should be able to find it's way to the file (...
HarveyLlG's user avatar
0 votes
0 answers
55 views

What is the proper way to open a file in Python? [duplicate]

I'm using VSCode on a mac and I can't figure out why I'm getting FileNotFoundError: [Errno 2] No such file or directory: 'flying_circus_cast.txt' with the following snippet of code. The text file ...
CodeHappy's user avatar
0 votes
0 answers
49 views

Importing files from different folders with relative paths in the code [duplicate]

So, I have a following file structure: main.py ├── net └── src ├── file.py └── dataset └── image.jpg I use import net.src.file to import file.py into main.py, that ...
Laura's user avatar
  • 1
0 votes
0 answers
31 views

No such file or directory found [duplicate]

I'm having a problem opening .txt file in same directory, and file do exist there. No such file or directory: 'example.txt' f = open("example.txt", "r+") #vscode Both .py and ....
Shah's user avatar
  • 1
0 votes
0 answers
27 views

Can't read the text file in python [duplicate]

This python code right here should open a text file in the same directory where I put my ex15.py and read it but there seems to be a problem it always says there's a problem in line 5 and it can't the ...
Jon's user avatar
  • 17
0 votes
0 answers
20 views

Reading a file in python macOS [duplicate]

So basically, I'm new to coding and I'm trying to read the contents of a .txt file and I'm able to do that by hardcoding the file path of the .txt file but I'm trying to write lines of code where it ...
ayaanimrn's user avatar

15 30 50 per page