Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
English Grammar
#4
(Jan-05-2020, 08:32 AM)Gribouillis Wrote: I like the idea, but wouldn't it be a little lighter if instead of a Text class, you defined a special type of formatting strings, say fmtstr, so that you could write
s = fmtstr('{} had {:w}. The {:o} knight to enter the castle had {:w}').format(
              ['Arthur', 'Lancelot', 'Robin'], (2, 'monkey'), 1, (3, 'dog'))
The fmstr.format() method would select its behavior depending the types of its arguments: list, tuples, numbers etc.

I like the idea of moving it out front, and I think that makes it a little clearer. But then you are having to distinguish between lists and tuples, which I think is a problem. The code might have the knights in a tuple, and then it might be misinterpreted by the fmtstr.

Perhaps if there was no default behavior for lists or tuples, and everything had to have an explicit format type, that might work:

s = fmtstr('{:S} had {:w}. The {:o} knight to enter the castle had {:w}').format(
              ('Arthur', 'Lancelot', 'Robin'), [2, 'monkey'], 1, (3, 'dog'))
So here the knights are interpreted to be comma-separated because of the S format type rather than it being a list, and [2, 'monkey'] and (3, 'dog') can both be handled as numbers with plurals even though they have different types.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
English Grammar - by ichabod801 - Jan-05-2020, 04:14 AM
RE: English Grammar - by Gribouillis - Jan-05-2020, 08:32 AM
RE: English Grammar - by ichabod801 - Jan-05-2020, 03:39 PM
RE: English Grammar - by Larz60+ - Jan-05-2020, 09:41 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020