Search code examples
pythonstringerrnopyfmifilenotfounderror

Python erronously adding file extension to path string


I'm currently struggling with the following problem:

My folder structer looks like:

master
 - resources
   customFile.fmu
fileCallingFMU.py

While executing the fileCallingFMU.py I pass a path string like

path = "./resources/customFile.fmu"

My script contains a super function where I pass the path variable. But everytime I execute the script it trips with an exception:

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)

My urging question now is the following:

Why and how does python manipulate the path variable with a date-prefix and .txt as file extension?!

Hope anyone can enlighten me on this one...

EDIT

I'm trying to get the example of ModelicaGym running.

My fileCallingFMU.py contains the following code:

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)

The full code for the entryPoint can be found here.


Solution

  • As jjramsey pointed out the problem was burried within the ModelicaGym library.

    The logger could not create a propper log file, because the model name was not properly stored in the self.model variable.

    Source of this error lied in the line

    self.model_name = model_path.split(os.path.sep)[-1]
    

    due to the fact that the os library was not able to separate my path string

    "./resources/customFile.fmu"
    

    After changing it to

    ".\\resources\\customFile.fmu"
    

    everythig works as expected.

    Thanks again!