Last active
June 27, 2016 04:21
-
-
Save jiapengjun/423cb7e9d2bfab48465b72c6b1a0314c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import calendar | |
# print(calendar.calendar(2016, 3)) | |
# print(calendar.TextCalendar().formatmonth(2016,6, 3)) | |
# print(calendar.TextCalendar().formatmonth(2016,6)) | |
# print(calendar.TextCalendar().formatyear(2016, 3, 1, 4, 2)) | |
# print(calendar.HTMLCalendar().formatyear(2016)) | |
print(calendar.HTMLCalendar().formatyearpage(2016, 4, "./cal.css")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Open URL in chrome | |
import webbrowser | |
ctrl = webbrowser.get('open -a /Applications/Google\ Chrome.app %s') | |
ctrl.open('http://www.python.org') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#coding:utf-8 | |
""" test code for module: codecs """ | |
import codecs | |
text = u'中华人民共和国' | |
t1 = codecs.encode(text, "utf-8") | |
t2 = codecs.encode(text, "gb2312") | |
print str(type(text)) + str(type(t1)) + str(type(t2)) | |
with open("out1.txt", "w") as o1, open("out2.txt", "w") as o2: | |
o1.write(t1) | |
o2.write(t2) | |
with open("out1.txt") as o1, open("out2.txt") as o2: | |
t1 = o1.read() | |
print "orig t1: " + t1 | |
tn1 = codecs.decode(t1, "utf-8") | |
print "orig tn1: " + tn1 | |
print str(type(t1)) + str(type(tn1)) | |
t2 = o2.read() | |
print "orig t2: " + t2 | |
tn2 = codecs.decode(t2, "gb2312") | |
print "orig tn2: " + tn2 | |
if tn1 == tn2: | |
print "tn1 & tn2 is equal" | |
with codecs.open("out1.txt", encoding="utf-8") as oo1, \ | |
codecs.open("out2.txt", encoding="gb2312") as oo2: | |
t1 = oo1.read() | |
print "t1: " + t1 | |
t2 = oo2.read() | |
print "t2: " + t2 | |
print str(type(t1)) + str(type(t2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#coding:utf-8 | |
import codecs | |
text = '中华人民共和国' | |
with codecs.open("out1.txt", "w") as o1, \ | |
codecs.open("out2.txt", "w", encoding="gb2312") as o2: | |
o1.write(text) | |
o2.write(text) | |
with codecs.open("out1.txt") as o1, \ | |
codecs.open("out2.txt", encoding="gb2312") as o2: | |
t1 = o1.read() | |
t2 = o2.read() | |
print(str(type(t1)) + str(type(t2))) | |
if t1 == t2: | |
print("equal") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fibonacci number in one line. | |
#from functools import reduce | |
fib=lambda n:reduce(lambda x,y:(x[0]+x[1],x[0]),[(1,1)]*(n-2))[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment