【发布时间】:2021-11-16 12:41:16
【问题描述】:
我目前正在努力解决以下问题:
我的文件夹结构如下:
master
- resources
customFile.fmu
fileCallingFMU.py
在执行 fileCallingFMU.py 时,我传递了一个路径字符串,例如
path = "./resources/customFile.fmu"
我的脚本包含一个超级函数,我在其中传递路径变量。但是每次我执行脚本时都会出现异常:
Exception has occurred: FileNotFoundError
[Errno 2] No such file or directory: b'2021-11-16_./resources/customFile.fmu.txt'
File "[projectFolder]\fileCallingFMU.py", line 219, in __init__
super().__init__(path, config, log_level)
File "[projectFolder]\fileCallingFMU.py", line 86, in <module>
env = gym.make(env_name)
我现在迫切的问题如下:
python为什么以及如何操作带有日期前缀和.txt作为文件扩展名的路径变量?!
希望有人能在这方面启发我...
编辑
我正在尝试运行 ModelicaGym 的示例。
我的文件CallingFMU.py 包含以下代码:
path = "./resources/customFile.fmu"
env_entry_point = 'cart_pole_env:JModelicaCSCartPoleEnv'
config = {
'path': path,
'm_cart': m_cart,
'm_pole': m_pole,
'theta_0': theta_0,
'theta_dot_0': theta_dot_0,
'time_step': time_step,
'positive_reward': positive_reward,
'negative_reward': negative_reward,
'force': force,
'log_level': log_level
}
from gym.envs.registration import register
env_name = env_name
register(
id=env_name,
entry_point=env_entry_point,
kwargs=config
)
env = gym.make(env_name)
入口点的完整代码可以在here找到。
【问题讨论】:
-
操纵路径变量的不是基础 Python。相反,它看起来像是 ModelicaGym 在
ModelicaBaseEnv类的get_log_file_name()方法中所做的事情。看起来该方法在该类以某种方式初始化时运行。 -
这就是拯救我一天的提示!
标签: python string errno pyfmi filenotfounderror