Answer the question
In order to leave comments, you need to log in
Open and Write to file?
Tell me what is the difference in the above code,
and is it required to close the file in both cases?
f = open(path, 'w')
f.write(req.text)
with open(path, 'w') as f:
f.write(req.text)
Answer the question
In order to leave comments, you need to log in
In the first version, the indents are superfluous. Will have to close the file after work.
In the second case, the context manager is used, the file will close itself after the end of the with ... as
block
The second option is considered more correct
In the first case, you will need to manually close the file f.close()
, and in the second, it closes after it is no longer used. More precisely, it will close after the execution of the last line of code in the block. Indents in the first option are not needed.
ReferenceError: submit is not defined
Look in the console and click to find out what error it gives.
no declaration function submit()
What are you trying to submit()? It is not announced what needs to be submitted.
If you want to do it with regular javascript, then give the form a name, for example name = "registrationForm" and write in the onClick event = "registrationForm.submit()"
You can also use $('#form').submit().
Better yet, assign IDs to your form and "link-button" and fire a jquery event when a specific button is clicked.
If you are already using jquery then why are you trying to use the good old dom.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question