11 textStr =
'Text String: Hello!\n'
12 uniTextStr =
u'Unicode String: 女時代'
15 currentDir = os.getcwd()
21 tempDir = tempfile.gettempdir()
24 uniFile =
u'MàxPɭüѕ.txt'
27 fullPath = tempDir +
'\\' + uniDir
35 if os.path.exists(fullPath):
40 print 'Working Directory:\n ' + os.getcwd()
42 print '!FAIL! Could not set working directory!\n'
44 print 'Moved to Temp folder:\n ' + os.getcwd()
50 print 'FAIL! Could not create unicode directory:\n' + fullPath
52 print 'Created unicode directory:\n' + fullPath
57 if os.path.exists(fullPath):
61 print 'Working Directory:\n ' + os.getcwd()
63 print '!FAIL! Directory does not exist!\n'
67 print 'Removed unicode directory:\n' + fullPath
74 with codecs.open(fname, encoding=
'utf-8', mode=
'w+')
as f:
76 f.write(textStr + uniTextStr)
77 print 'Finished writing file to ' + fname
82 def openFileInUniDir():
86 with codecs.open(fname, encoding=
'utf-8', mode=
'w+')
as f:
88 f.write(textStr + uniTextStr)
89 print 'Finished writing file to ' + fullPath + fname
98 if os.path.exists(tempDir + fname):
99 print 'File ' + fname +
' exists and will be removed!'
102 os.remove(tempDir + fname)
104 print '!FAIL! - File not deleted'
106 print 'File Removed.'
109 stats = unicode(
'Setup:\n' +
'Current directory: ' + currentDir +
'\nOutput filename: ' + uniFile +
'\nFile contents: ' + textStr + uniTextStr)