创建文件夹并解决解决unicode和ASCII码转换的问题

时间:2021-11-13 06:56:58

# -*- coding: UTF-8 -*-
import sys
import time
import os #解决unicode和ASCII码转换的问题
reload(sys) #解决unicode和ASCII码转换的问题
sys.setdefaultencoding('utf8') #解决unicode和ASCII码转换的问题

context = '''hello world'''
f = open("hello.txt", 'a+')
f.write(context)
f.close()
date1 = time.strftime("%Y%m%d", time.localtime())
date2 = "第"+time.strftime("%U", time.localtime())+"周"
date3 = "星期"+ time.strftime("%w", time.localtime())

print date1
print date2
print date3
date1 = str(date1)+str(date2)+str(date3)
# date1 = date1.encode(unicode)

path = ur"D:\工作目录\"
# print date1
# path = path + path1 + date1
path = str(path) + str(date1)
# print path
os.mkdir(path.encode('gbk'))
#os.mkdir(path.encode('gbk'))
# print path.decode('gb2312')
#path.decode('gb2312')
# path = path + date1
# print path
# os.mkdir(r'd:\工作目录\temp')
# lll = r'd:\Hello\Time'+date1
# print lll
# os.mkdir(lll)
# print path
# os.mkdir(path)