Skip to content

Instantly share code, notes, and snippets.

View douglarek's full-sized avatar

douglarek

View GitHub Profile
#! /usr/bin/env python
# coding: utf-8
import logging
from datetime import datetime
import time
if __name__ == '__main__':
logging.basicConfig(level = logging.DEBUG,
format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
https://python3wos.appspot.com/
#!/usr/bin/env python
import sys
try:
import urllib.request
except ImportError:
import urllib
urllib.request = None
class Foo(object):
_instance = None
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(Foo, cls).__new__(cls, *args, **kwargs)
return cls._instance
class Brog(object):
__shared_state = {}
#!/bin/bash
for name in $(sed -n 's/.* name="\([a-z|A-Z|_]*\)">.*/\1/p' $1)
do
if ! grep -q $name $2; then
sed -i "/$name/ d" $1
fi
done
local return_code="%(?..%{$fg[red]%}%? %{$reset_color%})"
PROMPT='%{$fg[green]%}%c \
$(git_prompt_info)\
%{$fg[red]%}%(!.#.->)%{$reset_color%} '
PROMPT2='%{$fg[red]%}\ %{$reset_color%}'
RPS1='%{$reset_color%} ${return_code} '
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}:: %{$fg[yellow]%}("
ZSH_THEME_GIT_PROMPT_SUFFIX=")%{$reset_color%} "
import warnings
def deprecated(func):
"""This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emmitted
when the function is used."""
def new_func(*args, **kwargs):
#warnings.warn("Call to deprecated function %s." % func.__name__,
# category=UserWarning, stacklevel=2)
warnings.warn("Call to deprecated function %s." % func.__name__,
Python闭包详解
1 快速预览
以下是一段简单的闭包代码示例:
def foo():
m=3
n=5
def bar():
a=4
return m+n+a
return bar
#! /usr/bin/env sh
cmd=$*
while [ true ];
do
eval $cmd
if [ $? -eq 0 ]; then