如何用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 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短