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
# -*- coding: utf-8 -*- | |
a = '啦啦啦' | |
# an error will happen here | |
print '##### 1 #####' | |
try: | |
print unicode(a) | |
except Exception as e: | |
print 'error:' |
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 MySQLdb | |
conn = MySQLdb.connect(user='xxx',passwd='xxx',db = 'xxx') | |
cursor = conn.cursor() | |
n = cursor.execute( | |
'select * from xxx where `content` in %(content)s', | |
{ 'content': ('aa','bb','cc') } | |
) |
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
# -*- coding: utf-8 -*- | |
''' | |
Python在同一行输出内容。 | |
原理: | |
输出\r | |
在Linux中,\r的作用是回到一行的开头。 | |
这里不能使用print,因为print自带换行。而这里我们不能使用换行。 | |
但是如果禁用print的换行也不行。如果没有换行print就不会flush,导致什么也不输出。 |
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
$(a).foo() | |
id = $(a).attr 'id' | |
$('#' + id).bar() |
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
# coffee可以这样写 | |
foo() if 0 == a | |
# 也可以这样写 | |
if 0 == a then foo() else bar() | |
# 但是不能可以这样写,编译出来根本不是我想要的效果 | |
foo() if 0 == a else bar() | |
# 也不能这样写,会报语法错误 |
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
# 第一个例子 | |
name = 'elephant' | |
# 第一种代码风格 | |
if 'John' == name: | |
isJohn = True | |
else: | |
isJohn = False | |
# 第二种代码风格 |
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
-> sudo apt-get install wine | |
正在读取软件包列表... 完成 | |
正在分析软件包的依赖关系树 | |
正在读取状态信息... 完成 | |
将会安装下列额外的软件包: | |
binfmt-support fonts-droid fonts-horai-umefont fonts-unfonts-core gcc-4.6-base:i386 libasn1-8-heimdal:i386 libasound2:i386 libavahi-client3:i386 libavahi-common-data:i386 | |
libavahi-common3:i386 libc6:i386 libcapi20-3 libcapi20-3:i386 libcomerr2:i386 libcups2:i386 libdb5.1:i386 libdbus-1-3:i386 libdrm-intel1:i386 libdrm-nouveau1a:i386 libdrm-radeon1:i386 | |
libdrm2:i386 libexif12:i386 libexpat1:i386 libffi6:i386 libfontconfig1:i386 libfreetype6:i386 libgcc1:i386 libgcrypt11:i386 libgd2-xpm:i386 libgettextpo0 libgif4:i386 libgl1-mesa-dri:i386 | |
libgl1-mesa-glx:i386 libglapi-mesa:i386 libglib2.0-0:i386 libglu1-mesa:i386 libgnutls26:i386 libgpg-error0:i386 libgphoto2-2:i386 libgphoto2-port0:i386 libgpm2:i386 libgssapi-krb5-2:i386 | |
libgssapi3-heimdal:i386 libgstreamer-plugins-base0.10-0:i386 libgstreamer0.10-0:i386 libhcrypto4-heimdal:i386 libheimbase1-heimdal:i386 libheimntlm0-heimdal:i386 libhx509-5-heimdal: |
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
# 第一种风格 | |
def isMale(user): | |
if user['sex'] == 'm': | |
return True | |
else: | |
return False | |
# 第二种风格 | |
def isMale(user): | |
if user['sex'] == 'm': |
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
for i in range(10): | |
print 'hello world' | |
# 能不能不产生新的变量 (此例中的i) | |
# 来完成循环10次的任务 |
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
在.emacs.d/core/prelude-core.el最后添加函数 | |
(defun prelude-py-taglist (arg) | |
"简易版taglist" | |
(interactive "P") | |
(let ((buffer-other | |
(if arg | |
"*py-taglist*" | |
(format "*py-taglist from %s*" (buffer-name))))) | |
(occur-1 "class \\|def " nil |
OlderNewer