如何用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 新房祝福语简短10字
14 长辈新年祝福语大全简短
15 新年给大家简短祝福语
16 生日祝福语简短独特姑姑
17 芭比的婚礼祝福语简短
18 邀请新人祝福语简短英文