A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-January/059836.html below:

[Python-Dev] str with base

[Python-Dev] str with baseAdam Olsen rhamph at gmail.com
Tue Jan 17 18:04:35 CET 2006
On 1/17/06, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>   class Color:
>     msg = {'en':['red', 'green', 'blue'], 'de':['rot','grün','blau']}
>     def __str__(self, language='en'):
>       return self.msg[language][self.value]
>
>   red = Color(0)
>
> so you could say
>
>   print str(red, 'de')
>
> I don't think I like this direction.

I agree that *args makes the code non-obvious.  However, if **kwargs
is used instead:

  def str(obj, **kwargs):
    return obj.__str__(**kwargs)

  class Color:
    msg = {'en':['red', 'green', 'blue'], 'de':['rot','grün','blau']}
    def __str__(self, language='en'):
      return self.msg[language][self.value]

  red = Color(0)

  print str(red, language='de')

I find that quite readable.

--
Adam Olsen, aka Rhamphoryncus
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4