Possibly unicode related, try print(repr(filePath)) and print(type(filePath)). Strings coming out of Qt is often unicode.
Second possible cause is that there are “ included in the path, notice the triple ‘ on the invalid argument warning. On Fri, 9 Jun 2023 at 15:41, Rudi Hammad <[email protected]> wrote: > hi, > okey let me explain with an example which will be faster. It is a small > code so I'll just past it here. I have the function: > > def saveTreeDataToFile(filePath, treeWidget): > treeData = json.loads(serializeTree(treeWidget)) > print(filePath) # Result: "D:/CHIMERA STUDIO/CHIMERA > CGI/workspace/cfg_data.json" > > with open(filePath, mode="w") as f: > json.dump(treeData, f, indent=4) > > I printed the file path just to check which is "D:/CHIMERA STUDIO/CHIMERA > CGI/workspace/cfg_data.json". So there is no back slash issue or anything. > I get the following error: > > # OSError: [Errno 22] Invalid argument: '"D:/CHIMERA STUDIO/CHIMERA > CGI/workspace/cfg_data.json"' > > > however, if override manually filePath with the result that what was > printed like so: > > def saveTreeDataToFile(filePath, treeWidget): > treeData = json.loads(serializeTree(treeWidget)) > filePath = "D:/CHIMERA STUDIO/CHIMERA CGI/workspace/cfg_data.json" > with open(filePath, mode="w") as f: > json.dump(treeData, f, indent=4) > > ...everything works fine. How is this possible? If it is a formatting > issue I don't see it. > Any idea what is happening ? > > thanks, > R > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/4eae1d5e-791d-4afc-bea0-489ec135b057n%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/4eae1d5e-791d-4afc-bea0-489ec135b057n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD1tXib8Us%2BBddWn9OexyNOG%3D_JWqOabYw7k8kiVdUOeA%40mail.gmail.com.
