I have been trying to create a text file and code it in UTF-8. I have managed to do it using codecs
However, I am having trouble when I ask the user for input. Any ideas?

# -*- coding: cp1252 -*-
import codecs

fileName = "testing1"
textFile = codecs.open(fileName, "wt", encoding='utf-8')
variable = u"é "
foo=raw_input(u"what is your name: ")
textFile.write(u"héllo") #This works 
textFile.write(variable) #This works    
textFile.write(foo)# this fails
textFile.close()

Your code failed to execute with the strange "wt" mode, with "w" mode everything seemed to work in Python 2.7.3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.