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

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

coldplay.xixi
Release: 2020-10-22 10:29:56
Original
5878 people have browsed it

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template