address a port

Erik Heneryd erik at
Wed Mar 24 10:14:04 CET 2004

John Howard wrote:
> Basic has the inp() statement for accepting data from a port accessed
> from a memory location. Does python have a similar instruction?

No.  On Linux, you could either use the ioperm()/inb()/related macros 
(see for a simple Python 
wrapper) or read from /dev/port if you got that device compiled in - 
this function reads a byte (you'll need read access to /dev/port):

def inb(port):
     f = file("/dev/port")
     value = ord(
     return value

spam = inb(0x378) # get byte from LPT1

More (general) info can be found in the Linux I/O port mini-HOWTO:


Erik Heneryd

More information about the Python-list mailing list