加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Ball.py 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
Csy 提交于 2023-01-09 13:11 . first commit
'''
Author: caishuyang
Date: 2023-01-08 14:50:05
LastEditors: caishuyang
LastEditTime: 2023-01-08 16:48:56
Description:
'''
import yaml
class Ball():
def __init__(self, typename):
self.classname = 'Ball'
self.name = typename
self.r = 5e-3
self.m = 1e-3
self.num = 0
self.x = 0
self.y = 0
self.vx = 0
self.vy = 0
self.ax = 0
self.ay = 0
self.readParam()
def readParam(self):
yamlPath = 'config.yaml'
flag = True
try:
f = open(yamlPath, 'r', encoding='utf-8')
except:
print('无法打开', yamlPath)
flag = False
if flag:
cont = f.read()
param = yaml.load(cont, Loader=yaml.FullLoader)
dic = param[self.classname][self.name]
self.r = float(dic['r'])
self.num = float(dic['num'])
self.m = float(dic['m'])
def __str__(self):
return self.name
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化