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
#! /bin/bash | |
while getopts "i:o:" opt; do | |
case $opt in | |
i ) input="$OPTARG" ;; | |
o ) output="$OPTARG" ;; | |
esac | |
done | |
#字符串替换使用这样方式,可以方便的替换,也可以使用自带的${string/sub/replace} | |
#input=`echo "$input" | sed 's/\ /\\\ /g'` |
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=utf8 | |
import codecs | |
#正则表达式 | |
import re | |
import math | |
''' | |
python | |
将x±y替换成x±y/sqrt(n) | |
正则表达式操作 | |
文件操作 |
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
#The GUI interface is depend on python-tk package, so you should install it first | |
sudo apt-get install python-tk | |
#display the GUI interface | |
pydoc -g |
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
import __builtin__ | |
# list all the predefined names | |
print dir(__builtin__) |
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
y, z = 1, 2 | |
def all_global(): | |
#global declaration | |
global x | |
x = y+z | |
all_global() | |
#you can get x here | |
print 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
def maker(N): | |
''' | |
if you want to get different functions | |
when you pass different parameters into a maker, | |
you can use nested scope function, | |
it's also known as a factory function. | |
''' | |
def action(X): | |
return X**N | |
return action |
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
def makeActions(): | |
acts = [] | |
for i in range(5): | |
acts.append(lambda x : i ** x) # all remember same last i | |
return acts | |
acts = makeActions() | |
acts[0](2) # print 16 | |
acts[2](2) # print 16 |
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
L = [(lambda x: x**2),(lambda x: x**3),(lambda x: x**4)] | |
for f in L: | |
print f(2) | |
mydict = {'a':(lambda x: x**2),'b':(lambda x: x**3),'c':(lambda x: x**4) } |
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
import sys | |
#use sys.stdout.write(x) to print x in a lambda | |
showall = (lambda x: map(sys.stdout.write, x)) | |
# showall = lambda x:[sys.stdout.write(line) for line in x] | |
t = showall(['a\n', 'b\n', 'c\n']) # it will print a\nb\nc\n |
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
if a: | |
b | |
else: | |
c | |
# equivaltent expression | |
b if a else c |
OlderNewer