如何从Python [3.3]中找到正在运行的Python脚本的目录? 我尝试了什么建议在:How can I find script's directory with Python?,但我得到“无效的语法”,并指向“操作系统”(我没有进口操作系统)。如何从脚本中查找Python运行脚本的目录?
最接近我得到的答案是:sys.argv [0],但仍包含文件名,所以我不能使用它。有没有其他方法?
注意: 我对Python很新。
下面是一些代码,到目前为止我已经(在那里说rundir = sys.argv中[0],其中建议代码会去的部分):
import pygame
from pygame.locals import *
import os, sys
import time
pygame.init()
import statuscheck
print("Completed program status check.")
import mods.modlist
print("Loaded all mods..")
print("Completed loading")
sys.dont_write_bytecode = True
rundir = sys.argv[0]
print("Running from" + rundir)
您可以发布您确切的代码,你会得到确切的错误?你链接的答案听起来像它应该为你工作。 –