faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 4 people (100%) answered Yes
Recently 2 of 2 people (100%) answered Yes

Entry

Printing % literally

Jul 5th, 2000 09:58
Nathan Wallace, Hans Nowak, Snippet 1, Fredrik Lundh


"""
Packages: basic_datatypes.strings
"""

''' 
>Trying to do something like:
>
>printer = "fasthp"
>
>print """
>%(printer)s: print command = lpr -r -s -h -b -P%p %s
>""" % vars()
>
>But the %p and %s entries cause errors.  How do I
>get these interpreted literally?  (They're not variables to
>Python, only to printcap)

try:
'''

printer = "fasthp"

print """
%(printer)s: print command = lpr -r -s -h -b -P%%p %%s
""" % vars()