Capitalisation is important. You want
serial.Serial() instead of
You've also not put the correct path to the serial device -
dev/ttyAMA0 would be relative to the place the user runs the script from (so would only work if you run it from
Your code should be:
import serial ser = serial.Serial("/dev/ttyAMA0", baudrate=9600) ser.write("code") ser.close()
See http://www.elinux.org/Serial_port_programming for more examples.