Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Fu - mkdir not working
#7
(01-31-2023, 10:12 AM)Kevin Wrote:
(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)

Thanks for clarifying! I remember learning this now.
Modder/Skinner at MarvelMods.com using GIMP to create, edit, and export textures and previews more efficiently.

My GIMP scripts hosted on GitHub
Reply


Messages In This Thread
Python Fu - mkdir not working - by BaconWizard17 - 01-27-2023, 03:52 AM
RE: Python Fu - mkdir not working - by gasMask - 01-27-2023, 07:50 AM
RE: Python Fu - mkdir not working - by Kevin - 01-27-2023, 09:17 AM
RE: Python Fu - mkdir not working - by Ofnuts - 01-27-2023, 10:06 AM
RE: Python Fu - mkdir not working - by Kevin - 01-31-2023, 10:12 AM
RE: Python Fu - mkdir not working - by BaconWizard17 - 02-01-2023, 12:20 AM

Forum Jump: