#Python 面试题
Python 装饰器
def log(func):
def wrapper(*args, **kw):
print('call %s():' % func.__name__)
return func(*args, **kw)
return wrapper
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import json | |
import urllib | |
from urllib.parse import urlencode | |
import urllib.request as ur | |
#---------------------------------- | |
# 天气预报调用示例代码 - 聚合数据 |
# webservice.py | |
from suds import WebFault | |
from suds.client import Client | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
logging.getLogger('suds.transport').setLevel(logging.DEBUG) | |
# url="http://ipatest.shenzhenair.com/sasis/services/PassengerInfoService?wsdl" | |
url = 'http://ipatest.shenzhenair.com/sasis/services/FlightStatusInfoService?wsdl' |
#Python 面试题
Python 装饰器
def log(func):
def wrapper(*args, **kw):
print('call %s():' % func.__name__)
return func(*args, **kw)
return wrapper
#-*- encoding=utf-8 -*- | |
print '----------------------方法1--------------------------' | |
#方法1,实现__new__方法 | |
#并在将一个类的实例绑定到类变量_instance上, | |
#如果cls._instance为None说明该类还没有实例化过,实例化该类,并返回 | |
#如果cls._instance不为None,直接返回cls._instance | |
class Singleton(object): | |
def __new__(cls, *args, **kw): | |
if not hasattr(cls, '_instance'): | |
orig = super(Singleton, cls) |
# find_common_root.py | |
class TreeNode(): | |
def __init__(self, left, right, val): | |
self.val = val | |
self.left = left | |
self.right = right | |
def getPath(self, root, decNode, array): |
def getresult(a=None, b=None, c=None, target=None): | |
for aitem in a: | |
for bitem in b: | |
if target - aitem - bitem in c: | |
return a.index(aitem), bitem, target - aitem - bitem | |
else: | |
return None | |
a = [1, 2, 3] |
# exchange_rate.py | |
import urllib2 | |
#https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22{from_currency}{to_currency}%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys | |
def get_exchange_rates(from_currency, to_currency): | |
url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22{from_currency}{to_currency}%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys".format( | |
from_currency=from_currency, to_currency=to_currency) | |
response = urllib2.urlopen(url, timeout=20).read() | |
json_html = eval(response) |
FROM phusion/baseimage:latest | |
MAINTAINER flurdy | |
ENV DEBIAN_FRONTEND noninteractive | |
# accept-java-license | |
RUN echo /usr/bin/debconf shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections | |
RUN apt-get update && \ |
#分布式搜索elasticsearch配置文件详解
配置文件位于%ES_HOME%/config/elasticsearch.yml文件中
所有的配置都可以使用环境变量,例如: node.rack: ${RACK_ENV_VAR} 表示环境变量中有一个RACK_ENV_VAR变量。
下面列举一下elasticsearch的可配置项:
# -*- coding: utf-8 -*- | |
# python elasticsearch_pulk_del.py --keep=31 --ip=10.140.65.12 保留31天index | |
# python elasticsearch_pulk_del.py --start_index=0 --end_index=10 --ip=10.140.65.12 删除最老的11个index | |
# python elasticsearch_pulk_del.py --om=true --ip=10.140.65.12 优化merge吞吐量 | |
import urllib2 | |
import json | |
import time | |
import datetime | |
from optparse import OptionParser |