- OS=$(uname -s) # Darwin
- ARCH=$(uname -m) # x86_64
- if是检测commad执行的返回情况,正常(exit code为0)则True
if command; #等价于 command;if [$? -eq 0]
then
....
else
| class Watcher: | |
| def __init__(self): | |
| self.child = os.fork() | |
| print 'child', self.child | |
| if self.child == 0: | |
| return | |
| self.watch() | |
| def watch(self): |
| import signal | |
| def handle_hup(sig, frame): | |
| print "get signal: %s"%sig | |
| signal.signal(signal.SIGHUP, handle_hup) | |
| if __name__ == '__main__': | |
| ign = signal.SIG_IGN |
| # coding=utf-8 | |
| import os, logging | |
| import random | |
| import signal | |
| import time | |
| import sys |
| _filename_gbk_strip_re = re.compile(u"^[\u4e00-\u9fa5A-Za-z0-9_.-]+$") | |
| def secure_filename(filename): | |
| if isinstance(filename, text_type): | |
| from unicodedata import normalize | |
| filename = normalize('NFKD', filename).encode('utf-8', 'ignore') | |
| if not PY2: | |
| filename = filename.decode('utf-8') | |
| for sep in os.path.sep, os.path.altsep: |
| from urllib import urlencode | |
| from urlparse import urlparse, urlunparse, parse_qsl | |
| url = 'https://www.baidu.com?fuxk=true&m=1' | |
| url_parts = list(urlparse(url)) | |
| query = dict(parse_qsl(url_parts[4])) | |
| query.update({'nimabi': 1111}) | |
| url_parts[4] = urlencode(query) | |
| print urlunparse(url_parts) |
| def full_permutation(arr, cursor): | |
| if cursor == len(arr) - 1: | |
| print arr | |
| return | |
| for i in range(cursor, len(arr)): | |
| arr[cursor], arr[i] = arr[i], arr[cursor] | |
| full_permutation(arr, cursor + 1) | |
| arr[cursor], arr[i] = arr[i], arr[cursor] |
| def ngetmprint(list, ans, m): | |
| if m == len(list): | |
| ans = ans + list | |
| print ans | |
| elif m == 0: | |
| print ans | |
| else: | |
| ngetmprint(list[1:], ans + list[0:1], m - 1) | |
| ngetmprint(list[1:], ans, m) |