How to display the "%" in python.
I found so far two methods:
>>> print "See %d%%" % (0.77 * 100)
See 77%
>>> print "See {0:.0%}".format(0.77)
See 77%
>>>
Is a blog about python programming language. You can see my work with python programming language, tutorials and news.
>>> print "See %d%%" % (0.77 * 100)
See 77%
>>> print "See {0:.0%}".format(0.77)
See 77%
>>>
>>> import geo
>>> geo.adress("Santa Claus")
{'status': '200', 'latitude': '32.1715776', 'longitude': '-82.3315138', 'accuracy': '4'}
from xml.dom import minidom as dom import urllib def fetchPage(url): a = urllib.urlopen(url) return ''.join(a.readlines()) def extract(webpage): a = dom.parseString(webpage) item2 = a.getElementsByTagName('SendingDate')[0].firstChild.wholeText print "DATA ",item2 item = a.getElementsByTagName('Cube') for i in item: if i.hasChildNodes() == True: eur = i.getElementsByTagName('Rate')[10].firstChild.wholeText dol = i.getElementsByTagName('Rate')[26].firstChild.wholeText print "EURO ",eur print "DOLAR ",dol if __name__=='__main__': webpage = fetchPage("http://www.bnro.ro/nbrfxrates.xml") extract(webpage)The result is:
$python xmlparse.py DATA 2010-02-04 EURO 4.1214 DOLAR 2.9749With "urllib" package I read the url.
from PIL import Image
import glob, os
size_file = 300,300
for f in glob.glob("*.png"):
file, ext = os.path.splitext(f)
img = Image.open(f)
img.thumbnail(size_file, Image.ANTIALIAS)
img.save("thumb_" + file, "JPEG")
import glob
import PIL
from PIL import Image
for f in glob.glob("*.jpg"):
img = Image.open(f)
dim_percent=(100/float(img.size[0]))
dim_size=int((float(img.size[1])*float(dim_percent)))
img = img.resize((100,dim_size),PIL.Image.ANTIALIAS)
if f[0:2] != "trumb_":
img.save("thumb_" + f, "JPEG")
>>> import gtk >>> dgd=gtk.gdk.display_get_default() >>> gsd=dgd.get_default_screen() >>> height=gsd.get_height() >>> width=gsd.get_width() >>> print "height=",height,"width=",width height= 1024 width= 1280