task.getNamePrefix() [SOLVED]

So, in a task which I have named “move_greenKid” I ran a print(task.getNamePrefix()).

According to the reference material, this is supposed to return the initial part of the name, up to but not including any trailing digits following a hyphen or underscore. The output I got was “move_greenKid”. It didn’t cut off at the underscore.

I tried again with a hyphen, using the name “move-greenKid” and I got “move-greenKid” as my output. So I’m getting the full name instead of the part before the special character.

What’s up with that?

digits != letters. If your task were named “move_0123123”, it would become “move”. This method exists for a very specific reason, which is that we have a habit of appending a string of digits onto the end of our task names (for instance, hash(self)) to uniquify the task names for each instance of a class. For PStats reporting, we’d like to see all of these tasks grouped together in one category, so PStats uses this method to find the name to report them under.

It’s a bit of a hack.


Okay, so it only works on numbers. Good to know, thanks David.