• python 正则匹配汉字、简单读写、打开txt文件


    win10环境,假设:

        py脚本所在的当前目录下有index.html文件,现在,

        要将index.html 中的汉字提取出来,保存为当前目录下的temp.txt,然后用notepad.txt打开查看。代码:

    #coding=utf8
    import os,re
    
    with open('index.html', mode='r', encoding='UTF-8') as f:  # 打开文件
        data = f.read()  # 读取文件
        s = re.findall('[u4e00-u9fa5]', data)# 匹配所有汉字
        kw = ("".join(s))
        with open('temp.txt', mode='w', encoding='UTF-8') as fw:  # 打开文件
            fw.write(kw)  #写文件
            
    path = 'temp.txt'
    win32api.ShellExecute(0, 'open', 'notepad.exe', path, '', 1)
            

     其中,mode参数为:r 表示 读, w表示 写, a表示 追加写入

    打开文档也可用

    import webbrowser as web
    web.open('filepath or url')
  • 相关阅读:
    Weblogic(CVE-2018-2894)
    WebLogic (CVE-2018-2628)
    WebLogic(CVE-2017-10271)
    DC-5靶机渗透
    DC-4靶机渗透
    DC-3靶机渗透
    DC-2靶机渗透
    时间戳倒计时
    服务器的一些Linux命令
    CCF试题清单
  • 原文地址:https://www.cnblogs.com/pu369/p/12641828.html
Copyright © 2020-2023  润新知