import os print("Path at terminal when executing this file") print(os.getcwd() + "\n") print("This file path, relative to os.getcwd()") print(__file__ + "\n") print("This file full path (following symlinks)") full_path = os.path.realpath(__file__) print(full_path + "\n") print("This file directory and name") path, filename = os.path.split(full_path) print(path + ' --> ' + filename + "\n") print("This file directory only") print(os.path.dirname(full_path)) print('get the root file path') import os.path print(os.path.abspath(os.path.join(os.getcwd(), os.pardir)))
Wednesday, October 12
How do I get the directory in Python?
by
AHK
on
12:36
in
Coding,
coding tricks,
Errors,
How-to,
information,
other,
Programming,
real hidden facts,
Technology,
tips-tricks
tips-tricks
Labels:
Coding,
coding tricks,
Errors,
How-to,
information,
other,
Programming,
real hidden facts,
Technology,
tips-tricks
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment