linux 安装git
grep -i "error:" /var/log/messages | less
python
工作常用别人的代码
设计好 API
def print_if_true(thing,check):
'''
Print the first argument if the second argument is true.
The operation is:
1. check whther the second argument is true
2. If it is, print the first argument.
'''
if check:
print(thing)
# use help to get the docstring of a function
help(print_if_true)
print(print_if_true.__doc__) # call the help documentation
?print_if_true # docstring
---
# This will print a heart shape on the screen
#def print_heat(*args):
a='zhangyanjie'
def print_heat(in_str):
print('\n'.join([''.join([(in_str
[(x-y)%7]
if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<0
else' ')
for x in range(-30,30)])
for y in range(15,-15,-1)]))
# This will print a multiplication table
print('\n'.join([''.join(['%s*%s=%-2s' % (y,x,x*y) for y in range(1,x+1)]) for x in range(1,10)]))
---
# default parameters
def print_all_args(req1,option='hello',*args,**kwargs):
print('required arg1:',req1)
print('required opt:',option)
print('required args:',args)
print('required kwargs:',kwargs)
# The *args will give you all function parameters as tuple:
# The **kwargs will give you all keyword arguments except for those corrsponding to a formal parameter as a dictionary
---
# 把函数作为变量
def answer1():
print("I enjoy programing with Python")
def answer2():
print("I'm a sucker for Python")
# A Function that takes another function as argument
def run_something(func):
func() # callback functions
run_something(answer1)
run_something(answer2)
网友评论