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
37 if os.path.exists(fullPath):
42 print 'Working Directory:\n ' + os.getcwd()
44 print '!FAIL! Could not set working directory!\n'
46 print 'Moved to Temp folder:\n ' + os.getcwd()
52 print 'FAIL! Could not create unicode directory:\n' + fullPath
54 print 'Created unicode directory:\n' + fullPath
61 if os.path.exists(fullPath):
65 print 'Working Directory:\n ' + os.getcwd()
67 print '!FAIL! Directory does not exist!\n'
72 print 'Removed unicode directory:\n' + fullPath
81 with codecs.open(fname, encoding=
'utf-8', mode=
'w+')
as f:
83 f.write(textStr + uniTextStr)
84 print 'Finished writing file to ' + fname
91 def openFileInUniDir():
95 with codecs.open(fname, encoding=
'utf-8', mode=
'w+')
as f:
97 f.write(textStr + uniTextStr)
98 print 'Finished writing file to ' + fullPath + fname
109 if os.path.exists(tempDir + fname):
110 print 'File ' + fname +
' exists and will be removed!'
113 os.remove(tempDir + fname)
115 print '!FAIL! - File not deleted'
117 print 'File Removed.'
120 stats = unicode(
'Setup:\n' +
'Current directory: ' + currentDir +
121 '\nOutput filename: ' + uniFile +
'\nFile contents: ' + textStr + uniTextStr)