Below for you to share a python3 in the current absolute path of the two methods, with a good reference value, I hope to be helpful to everyone. Come and see it together.
Import Sysprint (SYS.ARGV)
Get a list of the file's current absolute path strings
[' d:/pycharm/practiceproject/clientservernetworking.py ']
Method 2:
Import Osprint (OS.GETCWD ()) print (Os.listdir ()) Print (Os.path.join (OS.GETCWD (), Os.listdir () [1]) D:\pycharm\ practiceproject['. Idea ', ' clientservernetworking.py ']d:\pycharm\practiceproject\clientservernetworking.py
os.getcwd () Gets the current working path, which does not include the current file name clientservernetworking.py,
Os.listdir () gets a list of the names of files and folders under the current path
The final step stitching the path to get the absolute path of the current file string
Note: Method 1 and method 21 slash slash a backslash