0

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

4
  • Please update your question with the full error traceback. Commented Jul 21, 2020 at 14:09
  • Edited, added traceback Commented Jul 21, 2020 at 14:13
  • 2
    Use open properly? Commented Jul 21, 2020 at 14:16
  • The error seems to be somewhere in your Pydroid IDE. You should check that you can correctly run a new python file with just print("Hello World") in it. Commented Jul 21, 2020 at 14:16

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.