Windows中的Python文件路径
我正在使用Windows10。 我有这个密码Windows中的Python文件路径,python,windows,Python,Windows,我正在使用Windows10。 我有这个密码 script_dir = os.path.dirname(__file__) temp = cs(os.path.join(script_dir+"first.txt"), os.path.join(script_dir+"second.text"), os.path.join(script_dir+"third.txt")) 它在git bash中执行,但在powershell和cmd中抛出一个错误。 如何修复此代码,以便在任
script_dir = os.path.dirname(__file__)
temp = cs(os.path.join(script_dir+"first.txt"),
os.path.join(script_dir+"second.text"),
os.path.join(script_dir+"third.txt"))
它在git bash中执行,但在powershell和cmd中抛出一个错误。
如何修复此代码,以便在任何地方执行此代码
===============================================================================编辑:
它说,它找不到
.first.txt
和以下文件。
它也抛出了这个错误,
DLL加载失败:找不到指定的模块。
===============================================================================
编辑2:
cs
是我创建的一个类
class cs:
info = {}
result = {}
def __init__(self, first, second, third, output=None):
self.output = ""
self.first = first
self.second = second
self.third = third
def decrypt(self):
pass
我不知道为什么它在git bash中工作,但在powershell和cmd中却不工作正确的代码是
script_dir = os.path.dirname(__file__)
temp = cs(os.path.join(script_dir, "first.txt"),
os.path.join(script_dir, "second.text"),
os.path.join(script_dir, "third.txt"))
您所做的错误是将
“first.txt”
等添加到script\u dir
,并将其传递到os.path.join
<但是,code>os.path.join接受多个参数(任意数量的参数)并以正确的方式将它们连接在一起。您的代码所做的是将这些字符串添加到一起,生成:script\u dirfirst.txt
,这将解释它找不到文件的原因。它会抛出什么错误?您正在使用的cs
函数是什么?这并没有提供足够的信息。请添加所有相关代码和收到的错误消息。@MarcusWeinberger我已添加。