Find the current directory and file’s directory [duplicate]

To get the full path to the directory a Python file is contained in, write this in that file: import os dir_path = os.path.dirname(os.path.realpath(__file__)) (Note that the incantation above won’t work if you’ve already used os.chdir() to change your current working directory, since the value of the __file__ constant is relative to the current working … Read more

How do I list all files of a directory?

os.listdir() returns everything inside a directory — including both files and directories. os.path‘s isfile() can be used to only list files: from os import listdir from os.path import isfile, join onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] Alternatively, os.walk() yields two lists for each directory it visits — one for files and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)