Notebook
  • Study hard and make progress every day
  • Mouka
    • Windows Internal
      • Helper Functions(todo:)
      • Find Kernel Module Address
      • Patch Guard Oops
      • Hook SSDT(Shadow)
      • Restore SSDT(Shadow)
      • Misc
        • Volatile in C
    • AntiCheat
      • Inject Defense
      • Injection Method
    • DriverDevelopment
      • 20180625
      • 20180626-27
    • Python
      • Python Tricks
        • 内置 http 服务器
        • 函数作为变量
        • "is" vs "=="
        • 直接变量值交换
        • 计算代码执行时间
        • 函数参数分解
        • 打印Python字典
        • 命名元组代替class
        • get()方法访问字典
        • 字典排序
        • 一次检查多个标志
        • 合并两个字典
        • re.sub使用替换函数
    • Algorithms
      • Greedy
        • 使括号平衡的最小交换次数
        • 埃及分数
      • DynamicProgramming
        • 0-1 背包问题
      • LeetCode
        • Count Primes
  • Honey
    • Python笔记
      • lxml库
      • os库
      • json文件读写
      • Scrapy
        • Scrapy安装与开始项目
        • Scrapy-Xpath
Powered by GitBook
On this page
  1. Honey
  2. Python笔记

json文件读写

Previousos库NextScrapy

Last updated 6 years ago

读

with open("C:\\Users\\daiyifan\\pclady_wiki\\pclady_wiki\\answers1.json",
        "r",
        encoding="utf-8") as js1:
    url1=json.load(js1)

写

with open("C:\\Users\\daiyifan\\pclady_wiki\\pclady_wiki\\answers.json","w",encoding="utf-8") as js3:
    json.dump(url_sum,js3)#只能写入字典
    f.write('\n')#可以换行

replace

经过replace的字符串不改变本身的值,而作为值返回。

str=str.repalce(old,new[,max])#max指最多匹配次数

正则表达式

re模块正则表达式匹配的结果会返回为一个对象,可以通过group方法来查看该对象的值。group(0)为全部匹配的值,group(1)为第一次匹配()中的值如:

re模块的sub的替换结果可以用函数表示

详见

re.sub使用替换函数