algN/test/读写/demo.py

71 lines
2.3 KiB
Python
Raw Normal View History

2025-08-23 10:12:26 +08:00
# """
# 模式 描述
# r 以只读的形式打开文件,文件的指针在开头
# r+ 读写,文件指针在开头
# rb 以二进制的形式,只读文件指针在开头
# w 只写,文件不存在,则创建新的,存在则覆盖,指针在开头
# w+ 读写,文件不存在,则创建新的,存在则覆盖,指针在开头
# wb 只写,以二进制的形式
# a 追加模式,文件指针在结尾
# a+ 读写,不存在则创建,存在直接追加
# ab 以二进制形式追加
#
# 1. close(): 关闭文件---非常重要
# 2. read([count]): 读取文件中的内容 count字节数量
# 3. readlines(): 读取所有内容,打包成列表
# 4. readline(): 读取一行数据,追加读取,读取过的不能再次读取
# 5. seekoffset[from]: 修改指针的位置从from位置移动了offset个字节,
# from0则表示从起始位置1则表示从当前位置开始2则表示从末尾开始
# offset要移动的字节数
# 6. write(): 向文件中写入内容
# """
import json
import sys
import time
import traceback
from collections import namedtuple
from queue import Queue
import yaml
#
# import yaml
#
#
# # 写文件
# # with open("hello.txt", 'w') as f:
# # f.write("hello world")
# import pandas as pd
# # 读文件
ss = time.time()
# with open(r"D:\tuoheng\codenew\tuoheng_alg\config\dsp_dev_service.yml",'r', encoding='utf-8') as f:
# data = yaml.safe_load(f)
with open(r"D:\tuoheng\codenew\tuoheng_alg\test\读写\dsp_application.json", 'r', encoding='utf-8') as f:
a = json.loads(f.read())
print(a)
print(time.time()-ss)
# # try:
# # aa = Queue(1)
# # aa.put(1, timeout=2)
# # aa.put(2, block=True, timeout=5)
# # except Exception as e:
# # traceback_str = traceback.format_exc()
# # print("aaaaaaaaaaaaaa", traceback_str)
# import time
# class a():
# def __init__(self, value):
# self.value = value
#
# def test(self):
# num = 0
# aa = self.value
# while True:
# num += 1
# bb = aa
# if num > 10000000:
# break
# ss = time.time()
# a("1111").test()
# print(time.time()-ss)
envs = ('dev', 'test', 'prod')
print('dev1' in envs)