import os
print(os.path.dirname(__file__))
print(os.path.dirname(os.path.dirname(__file__)))
print(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
print(os.name)
print(os.getcwd())
print(os.listdir(os.getcwd()))
print(__file__)
print(os.path.isfile(__file__))
print(os.path.isfile(os.getcwd()))
print(os.path.isdir(os.getcwd()))
print(os.path.exists(__file__))
print(os.path.split(__file__))
print(os.path.split(__file__+"/"))
print(os.getcwd())
print(os.system("calc"))
print(os.chdir(os.getcwd()))
print(os.path.getsize(__file__))
print(os.path.abspath(__file__))
print(os.path.join(os.path.dirname(__file__),"helloworld"))
print(os.path.join(os.path.dirname(__file__),"/helloworld"))
print(os.path.basename(__file__),"I am filename")
print(os.path.basename(os.path.dirname(__file__)))
import os
import sys
if __name__ == "__main__":
print(os.path.realpath(__file__))
print(os.path.split(os.path.realpath(__file__)))
print(os.path.split(os.path.realpath(__file__))[0])
print(os.path.getmtime(__file__))
import os
lists = os.listdir(os.path.dirname(__file__))
lists.sort(key = lambda fn:os.path.getmtime(os.path.dirname(__file__)+"\\"+fn))
lists.reverse()
print(lists)
print("最新文件为:"+lists[-1])
print()
file = os.path.join(os.path.dirname(__file__),lists[-1])
print(file)

参考:
https://www.cnblogs.com/breakcircle/p/6261566.html