在现实生活中我们往往需要一种算法,能够根据
This file contains hidden or 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
| # 开始是一段标准的 sql 语句,参见如下 | |
| select tt.* from | |
| ( | |
| select t.name,t.stu_id,t.realname,t.cur_grade, | |
| case when t.create_time>=c.send_time and t.phone is not null then t.phone else c.recipient_phone end as phone, | |
| case when t.create_time>=c.send_time and t.adds is not null then t.adds else c.recipient_adds end as add from | |
| ( | |
| select b.name,b.id as stu_id,b.realname,b.cur_grade,getsecret(a.recipient_phone,'bQQyVGStWD0=','2') as phone, | |
| concat(a.province_name,a.city_name,a.county_name,getsecret(a.recipient_adds,'bQQyVGStWD0=','2'))as adds,a.create_time from |
This file contains hidden or 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
| package com.company; | |
| public class Main { | |
| public static void main(String[] args) { | |
| // write your code here | |
| // 这种循环方法挺有意思的哈 | |
| char[] numbers={'a','b','c'}; | |
| for (char x:numbers){ | |
| System.out.println(x); |
This file contains hidden or 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
| script_write.py: | |
| import subprocess | |
| def write(): | |
| command="ping www.xueersi.com > ping_result.txt" | |
| subprocess.Popen(command,shell=True) | |
| if __name__=='__main__': | |
| write() |
This file contains hidden or 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
| Skip to content | |
| Search… | |
| All gists | |
| GitHub | |
| New gist @Allianzcortex | |
| Edit | |
| Delete | |
| Star 0 |
This file contains hidden or 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
| str2int=lambda s:sum(int(v)*10**i for i,v in enumerate(s[::-1])) | |
| str2int=lambda s:reduce((lambda x,y:x*10+y),map(int,s)) |
Part I
-
实现了 getitem 后就可以用 c[0] 这种 和 c[:2] 切片模式
-
在调用 in 这个方法时,如果没有 contains 方法,但它是 iterable 可迭代的,那么这也会起作用
-
class Vector:
def __repr__(self):
return 'Vector(%r, %r)' % (self.x, self.y)
This file contains hidden or 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 -*- | |
| import re | |
| RE_WORD=re.compile(r'\w+') | |
| class Sentence(object): | |
| def __init__(self,text): | |
| self.text=text | |
| self.words=RE_WORD.findall(text) |
附录1:
call 的使用:
可以帮忙创建良好的 API,举几个例子:
① Django 实现的 Validators
② june 里实现的 用户验资
如何写出 Pythnnic 的工程代码:
命令行工具和正则是最基本的工具
写出一个只有一个文件的 Pythonic 代码并不难,写出一堆代码只为完成任务也不难,难的就在于 如何非常优雅地实现一个整个 Pythonic 的工程代码。
下面是一个常有的 utils: