ahhh , yes. That 's it. Thanks Marcus. At some point in my code I was storing data using the path using json.dumps(thePath), when I stored directly thePath everything went okey. Cheers El viernes, 9 de junio de 2023 a las 16:57:49 UTC+2, Marcus Ottosson escribió:
> Also copy/pasted the question into ChatGPT out of curiosity and got a > similar response. > ------------------------------ > > The issue you are encountering seems to be related to the formatting of > the file path string. It appears that the filePath parameter you are > passing to the saveTreeDataToFile function includes double quotes (“) > around the path, resulting in the error you’re experiencing. > > The error message you provided, OSError: [Errno 22] Invalid argument: > ‘“D:/CHIMERA STUDIO/CHIMERA CGI/workspace/cfg_data.json”‘, indicates that > the path is being treated as an invalid argument due to the presence of the > double quotes. > > To resolve this issue, you should pass the file path without the double > quotes. If you are calling the saveTreeDataToFile function with the > filePath parameter in quotes like this: > > saveTreeDataToFile('"D:/CHIMERA STUDIO/CHIMERA CGI/workspace/cfg_data.json"', > treeWidget) > > You can modify the function call to remove the quotes: > > saveTreeDataToFile("D:/CHIMERA STUDIO/CHIMERA CGI/workspace/cfg_data.json", > treeWidget) > > By removing the double quotes, the file path should be passed correctly, > and the function should work as expected. > > On Fri, 9 Jun 2023 at 15:54, Marcus Ottosson <konstr...@gmail.com> wrote: > >> 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 <rudih...@gmail.com> 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 python_inside_m...@googlegroups.com. >>> 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 python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/eb8e2700-a9da-4db2-92dd-c8cc04be98c8n%40googlegroups.com.