Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82012
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'string': 0.09; 'method:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:string': 0.09; '"test"': 0.16; 'dict': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'stats': 0.16; 'str.format()': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'trying': 0.19; '>>>': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'skip:{ 20': 0.24; 'header:X-Complaints-To:1': 0.27; 'correct': 0.29; 'getting': 0.31; 'that.': 0.31; '"",': 0.31; 'file': 0.32; '(most': 0.33; 'test': 0.35; 'error.': 0.37; 'mapping': 0.38; 'to:addr:python- list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'email addr:gmail.com': 0.63; 'statement,': 0.68; 'shah': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: concat string and dict in print statement |
| Date | Fri, 05 Dec 2014 19:11:21 +0100 |
| Organization | None |
| References | <14b86f3a-7284-4e83-b5c0-1d41c86d80a7@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bda6b5.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16633.1417803096.18130.python-list@python.org> (permalink) |
| Lines | 24 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1417803096 news.xs4all.nl 2970 [2001:888:2000:d::a6]:33076 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:82012 |
Show key headers only | View raw
gaurangnshah@gmail.com wrote:
> I am trying to combine string and dict in the print statement, however
> getting an error. Would someone let me know what will be correct way to do
> that.
>
> stats={'lname': 'shah', 'fname': 'gaurang'}
> a=test
>
> print "%s %(fname)s %(lname)s" %(a,stats)
>
> Following is the error I am getting
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: format requires a mapping
Try the str.format() method:
>>> stats = {'lname': 'shah', 'fname': 'gaurang'}
>>> a = "test"
>>> print "{0} {1[fname]} {1[lname]}".format(a, stats)
test gaurang shah
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
concat string and dict in print statement gaurangnshah@gmail.com - 2014-12-05 09:31 -0800 Re: concat string and dict in print statement Peter Otten <__peter__@web.de> - 2014-12-05 19:11 +0100 Re: concat string and dict in print statement Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-05 11:14 -0700
csiph-web