#!/usr/local/bin/python3.4
# coding:utf-8
print("Content-Type: text/html; charset=UTF-8\r\n")
text = "Test File"
fname = "TEST"
fpath = "./"+fname+".txt"
try:
# FileOpen成功・失敗で分岐
f = open(fpath, 'w' ,encoding='utf-8')
except IOError:
# 失敗の場合
print("Could not open file!")
with f:
# 成功後
f.write(text)
f.close()
print(text)