Monday, June 30, 2008

Get Key Press in Python

Getting single key press without having user pres ENTER.


import msvcrt

def getkey():
return msvcrt.getch()


import termios, sys, os
TERMIOS = termios

def getkey():
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO
new[6][TERMIOS.VMIN] = 1
new[6][TERMIOS.VTIME] = 0
termios.tcsetattr(fd, TERMIOS.TCSANOW, new)
c = None
c =, 1)
termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old)
return c

Usefull links:

Friday, June 27, 2008

Simple SOCKS4 proxy in Python

If you need a SOCKS4 proxy for a custom port you can simply write it in a few python lines.

from twisted.internet import reactor
from twisted.protocols import socks

from twisted.internet.protocol import Factory

factory = Factory()
factory.protocol = socks.SOCKSv4

reactor.listenTCP(9999, factory)

Wednesday, June 11, 2008

Sending Email with Python

A quick way to send email with Python.

import smtplib

msg_from = ""
msg_to = ""
smtp_server = ""

msg_subject = "Hello"
msg_body = "This is message body."

msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n%s" % (msg_from, msg_to, msg_subject, msg_body))

server = smtplib.SMTP(smtp_server)
server.sendmail(msg_from, msg_to, msg)

Friday, November 9, 2007

Mobile Python Book

I found a great book about programming with python on S60.