# 写一个函数,有2个功能,能读文件,也能写文件 # 读文件,只需要传文件名 # 写文件,需要传文件名,写入的内容 import json def op_file(file, content=None): if content: with open(file, ‘w‘, encoding=‘utf-8‘) as fw: json.dump(content, fw) else: with open(file, encoding=‘utf-8‘) as fw: result = json.load(fw) return result
# 2、判断一个数为float或者正数 价格def check_float(num): num = str(num) if num.isdigit() and int(right) > 0: return True elif num.count(‘.‘) == 1: left, right = num.split(‘.‘) if left.isdigit() and right.isdigit() and int(right) > 0: return True return False
原文地址:https://www.cnblogs.com/skyxiuli/p/10740391.html
时间: 2024-10-06 14:32:33