You need use a raw string for the path variable, or escape the backslash:
path = r"D:\final"
You can see the difference here:
>>> "D:\final"
'D:\x0cinal'
>>> r"D:\final"
'D:\\final'
In the first case '\f
' is the form feed character 0x0c.
Also, use os.path.join() to construct pathnames:
import os.path
path = r"D:\final"
nameFile = "Res.mat"
result = os.path.join(path, nameFile)
>>> result
'D:\\final\\Res'
Since you explicitly append the string literal .mat
to nameFile
, why not simply define nameFile
with the .mat
extension? If this needs to be dynamic, just add it on like this:
extension = '.mat'
result = os.path.join(path, nameFile + extension)