A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/340445.html below:

using % operator to print possibly unitialized data attributes

using % operator to print possibly unitialized data attributes using % operator to print possibly unitialized data attributesAdam Monsen haircut at gmail.com
Fri Sep 9 14:19:10 EDT 2005
The following code uses the % operator to print possibly unitialized
data attributes:
------------------------8<------------------------
class J:
    name = ''
    value = ''
    def __str__(self):
        vals = self.__class__.__dict__
        vals.update(self.__dict__)
        return 'name="%(name)s" value="%(value)s' % vals

j = J()
j.name = "j object"
print j
------------------------>8------------------------

A couple of questions:
* is there a simpler or more elegant way to do this?
* how can I get this to work for new-style classes?

Thank you,
-Adam

-- 
Adam Monsen <haircut at gmail.com>
http://adammonsen.com/


More information about the Python-list 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