Int + Str 类型 python

Int + Str type python

所以我有这个代码

la = os.path.dirname(__file__)
with open(la, "/builds", "w") as python_script_file:
    python_script_file.write(other_python_script)

我的路径包含字母和数字:

storage/0/downloads...

我该怎么办?它说当我制作 int 时我需要 int 它说 str.

错误:

Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
    start(fakepyfile,mainpyfile)
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
    exec(open(mainpyfile).read(),  __main__.__dict__)
  File "<string>", line 52, in <module>
TypeError: an integer is required (got type str)

[Program finished]

所以这是一个循环,我什么也做不了 我试图搜索一些东西,但之前似乎没有人问过这个问题

看看documentation of open。您需要文件名作为 first 参数(不是第一个和第二个)。

使用os.path.join将路径段合并为一个:

la = os.path.dirname(__file__)
fName = os.path.join(la,"builds")
with open(fName, "w") as python_script_file:
    python_script_file.write(other_python_script)