Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A silly question
#2
Can you have GS and crop at the same time and if so are you expecting a -crop-GS_xcf result?

Are GS and crop booleans?

Lambdas not a solution here. To avoid ifs your best weapon is an array or dictionary of postfixes, keyed by the option.

Something I sometimes do with booleans is take advantage of the fact that they are automatically converted to 0 or 1, so you can write things like:

Code:
value=[valueIfFalse,ValueIfTrue][boolean]

Otherwise your code is also a backwards walking mammoth, I would have used:

Code:
theName=name
if GS: theName+='-GS'
if crop: theName+='-crop'
theName+=postFix

Or using %-formatting and my boolean-indexed array trick

Code:
theName='%s%s%s_xcf.webp' % (name, ['','-crop'][crop],['','-GS'][GS])

Other people would build a list of name parts and use
Code:
theName=''.join(nameParts)
Reply


Messages In This Thread
A silly question - by carmen - 10-27-2019, 08:30 PM
RE: A silly question - by Ofnuts - 10-27-2019, 09:07 PM
RE: A silly question - by carmen - 10-27-2019, 10:29 PM
RE: A silly question - by Ofnuts - 10-27-2019, 11:33 PM

Forum Jump: