Posted by & filed under python.

# resize an image using the PIL image library
# free from:  http://www.pythonware.com/products/pil/index.htm
# tested with Python24        vegaseat     11oct2005
 
import Image
 
# open an image file (.bmp,.jpg,.png,.gif) you have in the working folder
imageFile = "zFlowers.jpg"
 
im1 = Image.open(imageFile)
 
# adjust width and height to your needs
width = 500
height = 420
# use one of these filter options to resize the image
im2 = im1.resize((width, height), Image.NEAREST)      # use nearest neighbour
im3 = im1.resize((width, height), Image.BILINEAR)     # linear interpolation in a 2x2 environment
im4 = im1.resize((width, height), Image.BICUBIC)      # cubic spline interpolation in a 4x4 environment
im5 = im1.resize((width, height), Image.ANTIALIAS)    # best down-sizing filter
 
ext = ".jpg"
im2.save("NEAREST" + ext)
im3.save("BILINEAR" + ext)
im4.save("BICUBIC" + ext)
im5.save("ANTIALIAS" + ext)
 
# optional image viewer ...
# image viewer  i_view32.exe   free download from:  http://www.irfanview.com/
# avoids the many huge bitmap files generated by PIL's show()

Posted by & filed under python.

d={}
if type(d)==type(dict()):
     print 'Its dict!'
else:
     print 'Its not dict'

2 способ (более лучший ИМХО):

d={}
if type(d) is dict:
     print 'Its dict!'
else:
     print 'Its not dict'

Posted by & filed under python.

Ошибка, которую я сразу и не заметил:

r=r2={}

Теперь если сделать так

r['hello'] ='world'

А потом  так:

print(r2['hello'] )

То получим «world» , так что будьте аккуратны. Определять словари нужно по одному:

r={}
r2={}

Posted by & filed under javascript.

Этот javascript код не работает в IE:

<html>
<head>
<script language="javascript" type="text/javascript>
function init()
	{	var first=document.getElementsByName("first")[0]
                first.innerHTML="<option>1</option>"
	}
</script>
</head>
<body onload="init()">
<div id="ie_wrap">
<select name="first">
</select>
</div>
</body>
</html>

Для него работает такое:

function init()
	{	var first=document.getElementsByName("first")[0];
		first.options[0]=new Option("hello","world")
	}

Posted by & filed under python.

Странно что Trace ошибки не включен в класс Exceprion и приходится отдельно подключать модуль.
Итак, trace ошибки выводится так:

import traceback
try:
        raise Exception('hi')
except Exception,e:
        print (traceback.format_exc())

Posted by & filed under javascript.

Получение элемента:

document.getElementByTagName()
document.getElementById()
document.getElementsByName()

Установка атрибута:

var headline = document.getElementById("headline");
headline.setAttribute("align", "center");

Posted by & filed under python.

Простейшая работа:

import libxml2
doc=libxml2.parseDoc(content)
a=doc.xpathEval('/kml/Response/name')
print ((a[0].content))

Работа с учётом namespace:

import libxml2
doc=libxml2.parseDoc(content)
xp = doc.xpathNewContext()
xp.xpathRegisterNs("kml2", "http://earth.google.com/kml/2.0")
a=xp.xpathEval('/kml2:kml/kml2:Response/kml2:name')
print ((a[0].content))

Данный пример работает для следующего xml-файла:

 <kml xmlns="http://earth.google.com/kml/2.0"><Response>
  <name>1600 pennsylvania ave washington dc</name>
  <Status>
    <code>200</code>
    <request>geocode</request>
  </Status>
  <Placemark id="p1">
    <address>1600 Pennsylvania Ave NW, Washington D.C., DC 20500, USA</address>
    <AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>DC</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>District of Columbia</SubAdministrativeAreaName><Locality><LocalityName>Washington D.C.</LocalityName><Thoroughfare><ThoroughfareName>1600 Pennsylvania Ave NW</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>20500</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
    <ExtendedData>
      <LatLonBox north="38.9002436" south="38.8939484" east="-77.0333974" west="-77.0396926" />
    </ExtendedData>
    <Point><coordinates>-77.0365191,38.8976964,0</coordinates></Point>
  </Placemark>
</Response></kml>