Python – random bits I can never remember

Dates and times

make sure you ‘include’

import datetime
from datetime import datetime

usage syntax for producing ‘friendly’ date formats is;

your_date_string=datetime.now().strftime(‘%a, %H:%M’)

for details of strftime usage see strftime.org

emailing from gmail account 

look at Rpi forum thread – the working version is about 1/2 way through

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=32&t=31657

filename manipulation 

http://stackoverflow.com/questions/2759067/rename-files-in-python

Creating zip files

http://www.techrepublic.com/article/writing-and-appending-to-zip-archives-in-python/#.

 

basic motion detection with Python

http://www.raspberrypi.org/forum/viewtopic.php?f=43&t=45235&start=25#p394590

——————————————————————–

USB Support

The first line is generally not required as it is installed already, likewise the second only needs be done once.

The upgrade option can be important as earlier versions [below 1.x.x] of pyusb do not have ‘usb.core’ included which will often result in ‘no module named core’ errors where the python code is expecting it.

sudo apt-get install python libusb-1.0
sudo apt-get install python-pip
sudo pip install --upgrade pyusb

Colours in Pygame

http://www.discoveryplayground.com/computer-programming-for-kids/rgb-colors/