Home  >  Article  >  Backend Development  >  What should I do if python cannot enter a new line?

What should I do if python cannot enter a new line?

coldplay.xixi
coldplay.xixiOriginal
2020-10-22 10:29:565830browse

The solution to the problem that python carriage return cannot wrap the line: first create a writing method; then write the selenium script running results into the [test_result.log] file; finally add [\n] after writing the parameter str. It will automatically wrap to the next line after each completion of writing.

What should I do if python cannot enter a new line?

Solution to the problem that python carriage return cannot wrap the line:

Now we need a file writing method to use the selenium script The running results are written into the test_result.log file

First create a writing method

def write_result(str):
    writeresult=file(r'D:\eclipse4.4.1 script\my_selenium\model\test_result.log','a+')
    str1=writeresult.write(str+'\n')
    writeresult.close()
    return str

As above, the file written in str1=writeresult.write(str '\n') is displayed on one line by default. When this method is called,

will be written in the first line of the file every time. Adding "\n" after writing the parameter str will automatically wrap to the next line after each completion of writing. The next time you write,

will be written on the next line. Free learning recommendation: python video tutorial

The above is the detailed content of What should I do if python cannot enter a new line?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn