Search code examples
pythonstringint

Int + Str type python


So I have this code

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

My path contains letters and numbers:

storage/0/downloads...

And what should I do? It says I need int when I make int it says str.

Error:

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]

So it's a loop, I can't do anything I tried to search something, but it seems to be no one asked this before


Solution

  • Have a look at the documentation of open. you need the file name as the first argument (not first and second).

    Use os.path.join to join path segments to one:

    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)