摘要: 1 import json 2 a = {'name':'alex','age':27} 3 b = json.dumps(a) 4 print(b,type(b)) 5 a = 8 6 print(json.dumps(a),type(json.dumps(a))) 7 f = open('new 阅读全文
posted @ 2020-03-02 22:31 竹石2020 阅读(139) 评论(0) 推荐(0)
摘要: 1 import time 2 import sys # 可以在运行文件的时候添加参数 3 # 使用sys.argv 来调用参数 4 print(sys.path) # 返回模块的搜索路径,初始化时使用pythonpath环境变量的值 5 print(sys.platform) # 返回平台的信息 阅读全文
posted @ 2020-03-02 20:31 竹石2020 阅读(110) 评论(0) 推荐(0)
摘要: 1 import os 2 print(os.getcwd()) # 获取当前工作目录 3 os.chdir('test') # 更改当前工作目录 4 print(os.getcwd()) 5 os.chdir('..') # 返回上一层 6 print(os.getcwd()) 7 os.make 阅读全文
posted @ 2020-03-02 17:32 竹石2020 阅读(151) 评论(0) 推荐(0)
摘要: 1 import os 2 import sys 3 print(__file__) 4 print(os.path.abspath(__file__)) 5 print(os.path.dirname(os.path.dirname(__file__))) 6 sys.path.append(os 阅读全文
posted @ 2020-03-02 14:20 竹石2020 阅读(174) 评论(0) 推荐(0)
摘要: 1 def v_code(): 2 code_str = '' 3 for i in range(5): 4 import random 5 num = random.randint(0,9) 6 str1 = chr(random.randint(65,90)) 7 str2 = chr(rand 阅读全文
posted @ 2020-03-02 13:39 竹石2020 阅读(151) 评论(0) 推荐(0)
摘要: time.asctime() 可以将结构化时间转换为一种标准形式的时间 time.ctime() 可以将时间戳转化为一种标准的时间格式 默认传递时间戳 1 import time 2 import datetime 3 print(time.strftime('%Y-%m-%d %X',time.l 阅读全文
posted @ 2020-03-02 10:20 竹石2020 阅读(181) 评论(0) 推荐(0)
摘要: time.time() 时间戳 从19070年开始 通常用来计算时间用的 格式化时间转换过程 从时间戳到结构化时间再到格式化时间Format string 结构化时间struct_time 可以由localtime()、gmtime() 传入时间戳(timestamp)进行转化 例如: 1 impo 阅读全文
posted @ 2020-03-01 23:01 竹石2020 阅读(164) 评论(0) 推荐(0)
摘要: 如果在本文件开始运行 __name__ 变量为__main__ 如果从外部调用本文件__name__变量就为 该文件的路径 作用,可以作为一个文件运行的开始,二是可以用来调试一个函数文件是否有bug,事后调用不用注释掉调试的代码,直接调用。 功能: 一:用于被调用文件的测试。 二:不想让该文件成为被 阅读全文
posted @ 2020-03-01 11:33 竹石2020 阅读(369) 评论(0) 推荐(0)
摘要: 1 def fetch(data): 2 print('这是查询功能') 3 tag = False 4 data = 'aaaa %s\n'%data 5 res_data = [] 6 with open('bbb','r',encoding='gbk') as file: 7 for i in 阅读全文
posted @ 2020-02-29 16:01 竹石2020 阅读(222) 评论(0) 推荐(0)
摘要: 1 tag = True 2 while tag: 3 print('第一层') 4 choice = input('请输入 》') 5 if choice == 'quit':break 6 if choice == 'quit_all': tag =False 7 while tag: 8 pr 阅读全文
posted @ 2020-02-28 22:41 竹石2020 阅读(233) 评论(0) 推荐(0)