01-31-2023, 10:12 AM
(01-30-2023, 04:06 PM)BaconWizard17 Wrote: This generally makes sense. However, when I tested it outside of GIMP in regular Python, it gave me an error when I used the backslash but worked correctly when I used a forward slash, so that's why I coded it that way. Any idea why that might be the case? I'll try using the os function instead though.
Because when you wrote it into a string-literal like this:
Code:
filePath = "C:\Users\ethan\Desktop\Test.xcf"
The backslashes are treated as an "escape" sequence and it treats the following character as special if it's a known character, (\n = linefeed, \r = carriage-return, \t = tab etc) so what Python thinks you've assigned filePath to is C:UsersethanDesktopTest.xcf
To enter an actual backslash you have to escape it with a backslash!
Code:
filePath = "C:\\Users\\ethan\\Desktop\\Test.xcf"
This translation for special characters only takes place for the string literal, not when doing this:
Code:
filePath = pdb.gimp_image_get_filename(image)