How to get current directory and file path in Python, find ...
www.iditect.com › guide › python1. To get the executing file path, use os module. The __file__ attribute can help you find out where the file you are executing is located. import os full_path = os. path. realpath(__file__) file_path = os. path. dirname(full_path) print (file_path) Output: D:\Python_projects\demo\scripts\1.py 2. In Python 3.4+, you can use pathlib module to get the executing file path. import pathlib print (pathlib.
Find a file in python - Stack Overflow
https://stackoverflow.com/questions/172469312.11.2009 · If you are using Python on Ubuntu and you only want it to work on Ubuntu a substantially faster way is the use the terminal's locate program like this.. import subprocess def find_files(file_name): command = ['locate', file_name] output = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0] output = output.decode() search_results = …