如何用python在Selenium中编写文本文件?
通过首先创建一个txt文件并在其中包含内容,我们可以使用python在Selenium中编写文本文件。
首先,我们需要以写模式打开文件,并以文本文件的位置路径作为参数。有多种读取方法可以执行这些操作。
write()–将字符串写在一个文本文件中。
writelines()–它在一个文本文件中写入多个字符串。
示例
用.NET实现代码write()。
#open the file for write operation
f = open('hello.txt' , 'w')
#writes the new content
f.write('Nhooo')
#close the file
f.close()
# again open the file for read
f = open('hello.txt' , 'r')
#reads the file content and prints in console
print(f.read())
#close the file
f.close()代码实现writelines()
#open the file for write operation
f = open('hello.txt' , 'w')
lines = ["Nhooo", "Selenium"]
#writes the new content
f.writelines(lines)
#close the file
f.close()
# again open the file for read
f = open('hello.txt' , 'r')
#reads the file content and prints in console
print(f.read())
#close the file
f.close()热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短