2929import pyparsing
3030import importlib
3131import zmq
32+ import pathlib
3233
3334
3435if sys .platform == 'darwin' :
@@ -700,7 +701,7 @@ def __init__(self, fileName=None, modelName=None, lmodel=None, commandLineOption
700701 self .xmlFile = None
701702 self .lmodel = lmodel # may be needed if model is derived from other model
702703 self .modelName = modelName # Model class name
703- self .fileName = fileName # Model file/package name
704+ self .fileName = pathlib . Path ( fileName ). resolve () if fileName is not None else None # Model file/package name
704705 self .inputFlag = False # for model with input quantity
705706 self .simulationFlag = False # if the model is simulated?
706707 self .outputFlag = False
@@ -710,8 +711,8 @@ def __init__(self, fileName=None, modelName=None, lmodel=None, commandLineOption
710711
711712 self ._raiseerrors = raiseerrors
712713
713- if fileName is not None and not os . path . exists ( self .fileName ): # if file does not exist
714- raise IOError ("File Error:" + os . path . abspath ( self .fileName ) + " does not exist!!!" )
714+ if fileName is not None and not self .fileName . is_file ( ): # if file does not exist
715+ raise IOError (f "File Error: { self .fileName } does not exist!!!" )
715716
716717 # set default command Line Options for linearization as
717718 # linearize() will use the simulation executable and runtime
@@ -741,8 +742,7 @@ def setCommandLineOptions(self, commandLineOptions: str):
741742
742743 def loadFile (self ):
743744 # load file
744- loadFileExp = "" .join (["loadFile(" , "\" " , self .fileName , "\" " , ")" ]).replace ("\\ " , "/" )
745- loadMsg = self .sendExpression (loadFileExp )
745+ loadMsg = self .sendExpression (f'loadFile("{ self .fileName .as_posix ()} ")' )
746746 # Show notification or warnings to the user when verbose=True OR if some error occurred i.e., not result
747747 if self ._verbose or not loadMsg :
748748 self ._check_error ()
0 commit comments