python3のhello world cgi

最小限のpython cgi

-----
#!/usr/bin/python
# -*- coding: utf-8 -*-

my_title = 'greeting from python'
my_message = 'hello, world'

###

def print_head(title):
    print('Content-type: text/html')
    print()
    print('<html><head>')
    print('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">')
    print('<title>'+title+'</title>')
    print('</head>')

def print_body(message):
    print('<body>')
    print(message)
    print('</body>')

def print_tail():
    print('</html>')

###

print_head(my_title)

print_body(my_message)

print_tail()
-----


3系はprintにカッコをつけてつかう

インデントでスペースとタブを混在させてはいけない