Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79891 > unrolled thread
| Started by | satishmlmlml@gmail.com |
|---|---|
| First post | 2014-10-28 23:02 -0700 |
| Last post | 2014-10-29 16:12 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
%%(%s)s mean in python satishmlmlml@gmail.com - 2014-10-28 23:02 -0700
Re: %%(%s)s mean in python satishmlmlml@gmail.com - 2014-10-28 23:12 -0700
Re: %%(%s)s mean in python Ned Batchelder <ned@nedbatchelder.com> - 2014-10-29 07:38 -0400
Re: %%(%s)s mean in python Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2014-10-29 16:12 +0100
| From | satishmlmlml@gmail.com |
|---|---|
| Date | 2014-10-28 23:02 -0700 |
| Subject | %%(%s)s mean in python |
| Message-ID | <76c6409c-5289-4cf2-b80a-6349325356c6@googlegroups.com> |
def fetchRecord(db, form): try: key = form['key'].value record = db[key] fields = record.__dict__ fields['key'] = key except: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing or invalid key!' return fields def updateRecord(db, form): if not 'key' in form: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing key input!' else: key = form['key'].value if key in db: record = db[key] else: from person import Person record = Person(name='?', age='?') for field in fieldnames: setattr(record, field, eval(form[field].value)) db[key] = record fields = record.__dict__ fields['key'] = key return fields db = shelve.open(shelvename) action = form['action'].value if 'action' in form else None if action == 'Fetch': fields = fetchRecord(db, form) elif action == 'Update': fields = updateRecord(db, form) else: fields = dict.fromkeys(fieldnames, '?') fields['key'] = 'Missing or invalid action!' db.close() print(replyhtml % htmlize(fields)) What does %%(%s)s mean in Python?
[toc] | [next] | [standalone]
| From | satishmlmlml@gmail.com |
|---|---|
| Date | 2014-10-28 23:12 -0700 |
| Message-ID | <362b93be-cb5e-4874-98f8-c27927e66166@googlegroups.com> |
| In reply to | #79891 |
also what does rowshtml += (rowhtml % ((fieldname,) * 3)) expand to?
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2014-10-29 07:38 -0400 |
| Message-ID | <mailman.15293.1414582749.18130.python-list@python.org> |
| In reply to | #79891 |
On 10/29/14 2:02 AM, satishmlmlml@gmail.com wrote: > def fetchRecord(db, form): > try: ... 34 lines deleted ... > db.close() > print(replyhtml % htmlize(fields)) Why did you paste all this code, it doesn't have the thing you are asking about. > > What does %%(%s)s mean in Python? > It depends entirely on context. You'll need to find a *small* example of what you are asking about so we can help. -- Ned Batchelder, http://nedbatchelder.com
[toc] | [prev] | [next] | [standalone]
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
|---|---|
| Date | 2014-10-29 16:12 +0100 |
| Message-ID | <m2r05g$5hm$1@r01.glglgl.de> |
| In reply to | #79891 |
Am 29.10.2014 07:02 schrieb satishmlmlml@gmail.com:
> What does %%(%s)s mean in Python?
Weird question, as this has nothing to do with the code you just posted.
In general, what comes up to my mind, is that it is a format string to
build another format string.
Example:
metafmt = '%%(%s)s'
fieldname = 'myfield'
fmt = metafmt % fieldname
# Now we have a fmt as if it was assigned with '%(myfield)s':
# %% -> %, %s -> myfield.
d = {fieldname: 'my content'}
print fmt % d
# this now prints the given field - which is noted in fieldname -
# from the given dict d.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web