Python练习题(3)

1.使用requests模块获取这个json文件http://java-api.super-yx.com/html/hello.json
2.将获取到的json转为dict
3.将dict保存为hello.json文件
4.用文件流写一个copy(src,dst)函数,复制hello.json到C:\hello.json

import requests
import json

def copy(src, dst):
    read_file = open(src, "rb")
    write_file = open(dst, "wb")
    while True:
        data = read_file.read(1024)  # 每次读取 1024 字节
        if not data:  # 当读取到文件末尾时,data 为空
            break
        else:
            write_file.write(data)
    read_file.close()
    write_file.close()
# 1. 使用 requests 模块获取 json 文件
response = requests.get('http://java-api.super-yx.com/html/hello.json')

# 2. 将获取到的 json 转为 dict
data_dict = json.loads(response.text)

# 3. 将 dict 保存为 hello.json 文件
with open('hello.json', 'w') as f:
    json.dump(data_dict, f)

# 4. 复制 hello.json 到 D:\hello.json
copy('hello.json', 'D:\\hello.json')


相关推荐

  1. python 基础练习题3

    2024-07-13 06:10:01       32 阅读
  2. python练习3

    2024-07-13 06:10:01       32 阅读
  3. 网络工程师练习题3

    2024-07-13 06:10:01       44 阅读
  4. 练习题(2024/4/3

    2024-07-13 06:10:01       31 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-13 06:10:01       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-13 06:10:01       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-13 06:10:01       58 阅读
  4. Python语言-面向对象

    2024-07-13 06:10:01       69 阅读

热门阅读

  1. C语言排序之快速排序

    2024-07-13 06:10:01       27 阅读
  2. 基于Go1.19的站点模板爬虫详细介绍

    2024-07-13 06:10:01       24 阅读
  3. c++_文件解析_读取_每行用字符分割_去除两头空格

    2024-07-13 06:10:01       21 阅读
  4. 使用 OpenCV 的 inRange 函数进行颜色分割

    2024-07-13 06:10:01       22 阅读
  5. Web控件进阶交互

    2024-07-13 06:10:01       29 阅读
  6. iOS开发-Xcode

    2024-07-13 06:10:01       21 阅读
  7. Xcode依赖管理大师:精通项目依赖的艺术与实践

    2024-07-13 06:10:01       22 阅读
  8. 数据结构笔记之特殊矩阵压缩

    2024-07-13 06:10:01       26 阅读
  9. 交换机的二三层原理

    2024-07-13 06:10:01       25 阅读
  10. pdf工具

    pdf工具

    2024-07-13 06:10:01      24 阅读