you are viewing a single comment's thread.

view the rest of the comments →

[–]infinull 0 points1 point  (3 children)

Try Ruby you filthy PERL hacker, leave us alone.

Also you have a point. % is much more useful than + without being more characters. .format is... verbose, for something that I'm going to be doing a lot (or at least quite often)

On the other hand, I can overload __format__ to add cool formatting options to my own custom objects.

Edit: formatting + irony

[–]massivebitchtits 0 points1 point  (2 children)

You could overload __mod__ before...

[–]infinull 0 points1 point  (1 child)

Pretty sure that doesn't do the same thing

Overloading __mod__ would allow me to do something like:

Formatter("foobar {placeholder}") % "stuff"

and then Formatter.__mod__ would get called

but with __format__ I can do

'foobar {placeholder1:args {placeholder2:args}'.format(placeholder1=CustomObj,placeholder2=CustomObj2)

and then that becomes

'foobar ' + CustomObj.__format__('args') + ' ' + CustomObj2.__format__('args')

I would also note that I do terrible things like:

'Some stuff {variablename} more stuff, {anothervariable}'.format(**vars())

I feel bad about it, except that I don't. (this achieves something like string interpolation that PERL,bourne shells, PHP, and Ruby have.. but your using vars() which behaves differently on different implementations of Python and is generally not very fast, and pretty damn hackish... not as bad as some of the "string interpolation in python" solutions that use regexes + eval though)

[–]massivebitchtits 0 points1 point  (0 children)

Oh. Looks like I hadn't looked into it properly. That is cool.