[Tutor] Pulling items from a dict in a print command

Ben Sherman bensherman at gmail.com
Wed Jun 18 21:35:48 CEST 2014


Whats a more pythony way to do this?  I have a dict with a few dozen
elements, and I want to pull a few out.  I've already shortened it with
itemgetter, but it still seems redundant.  I feel like I can do something
like I've seen with *kwargs, but I'm not sure.

I'm using old style sprintf formatting, so feel free to show me a better
way to do this with the new way.

Thanks for the help!

Code:

    print(("overall_status=%s|" +
            "mon_count=%s," +
            "healthy_mons=%s," +
            "pg_count=%s," +
            "pg_clean_count=%s," +
            "osd_count=%s," +
            "osd_up=%s," +
            "osd_in=%s," +
            "bytes_avail=%s," +
            "bytes_used=%s," +
            "bytes_total=%s") %
            itemgetter("overall_status",
            "mon_count",
            "healthy_mons",
            "pg_count",
            "pg_clean_count",
            "osd_count",
            "osd_up",
            "osd_in",
            "bytes_avail",
            "bytes_used",
            "bytes_total")(parsed_json))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140618/e4dfb79b/attachment.html>


More information about the Tutor mailing list