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.
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!