timestamp

July 29, 2008

to get an actual time stamp, also insertable in sql database as date type


import datetime, time

stamp=datetime.datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")


compute checksum

July 23, 2008

To identify content..


import md5
#file = open("someFile")
#contentstr = file.read()
checksum = md5.new(contentstr).hexdigest()


get absolute path of a script

July 21, 2008

if you need the absolute path of the script you are running at the moment:

absPath=`echo -n \`pwd\` ;( [ \`dirname \$0\` == '.' ] && echo ) || echo "/\`dirname \$0\`"`

for example useful to build up libary paths in project folders.


actual time

July 20, 2008

to get actual time:

from datetime import datetime
now = datetime.datetime.now()

this will give you a datetime object which is often used by other methods. For string formatting use:

now.strftime(format_string)

* %a – Wochentagsname kurz
* %A – Wochentagsname
* %b – Monatsname kurz
* %B – Monatsname
* %c – Zeit und Datum
* %d – Monatstag 1-31
* %H – Stundenzahl 0-23
* %I – Stundenzahl 1-12
* %j – Kalendertag 1-366
* %m – Monatszahl 1-12
* %M – Minutenzahl 0-59
* %p – AM oder PM
* %S – Sekundenzahl 0-61
* %U – Wochenzahl 0-53 (Sonntag 0)
* %w – Wochentag 0-6
* %W – Wochenzahl 0-53 (Montag 0)
* %x – Datumsangabe
* %X – Zeitangabe
* %y – Jahr 0-99
* %Y – Jahr
* %Z – Zeitzone


Hello!

July 20, 2008

This is my first blog.

It shall serve as code repository and help blog for coding problems i often have to face up.

Hope it works and helps me a lot..