Pythonのos.path.realpath(__ file __)、os.getcwd()、sys.path()の違い



Difference Between Pythons Os



os.getcwd()sys.pathは、実行中のスクリプトの絶対パスsys.pathを返し、os.path.realpath(__ file__)は絶対パス+ファイル名を返します。ただし、たとえば、firディレクトリのfir.pyからsecディレクトリのsec.pyを呼び出す場合、sec.pyにはパスを取得するための3つのモードがあります。 sec.pyのパス情報を取得する場合は、sys.path.realpathを使用する必要があります。図のように一目でわかります。