使用 Python 内置的 defaultdict
,我们可以很容易的定义一个树形数据结构:
def tree(): return defaultdict(tree)
就是这样!
$ sudo dmidecode | |
# dmidecode 2.12 | |
# SMBIOS entry point at 0x000f0000 | |
SMBIOS 2.8 present. | |
<SNIP> | |
Handle 0x0000, DMI type 0, 24 bytes | |
BIOS Information |
使用 Python 内置的 defaultdict
,我们可以很容易的定义一个树形数据结构:
def tree(): return defaultdict(tree)
就是这样!
function smoothScroll(el, to, duration) { | |
if (duration < 0) { | |
return; | |
} | |
var difference = to - $(window).scrollTop(); | |
var perTick = difference / duration * 10; | |
this.scrollToTimerCache = setTimeout(function() { | |
if (!isNaN(parseInt(perTick, 10))) { | |
window.scrollTo(0, $(window).scrollTop() + perTick); | |
smoothScroll(el, to, duration - 10); |
Python Cheatsheet | |
================= | |
################################ Input & Output ############################### | |
name = input('please enter your name: ') | |
print('hello,', name) | |
ageStr = input('please enter your age: ') | |
age = int(ageStr) |
import jinja2 | |
from flask import Flask, render_template, request, redirect, url_for | |
from flask.ext.sqlalchemy import SQLAlchemy | |
from . import formatting | |
from .config import get_config | |
db = SQLAlchemy() |
# coding: utf-8 | |
import json | |
import re | |
import requests | |
# 替换成你自己的经纬度数据 | |
# 查询方式 打开饿了么官网 -> 开发者模式 -> 输入送餐地址 -> 观察请求 -> 找到经纬度数据 | |
latitude = 31.23978 | |
longitude = 121.49968 |
In your Python package, you have:
__init__.py
that designates this as a Python packagemodule_a.py
, containing a function action_a()
that references an attribute (like a function or variable) in module_b.py
, andmodule_b.py
, containing a function action_b()
that references an attribute (like a function or variable) in module_a.py
.This situation can introduce a circular import error: module_a
attempts to import module_b
, but can't, because module_b
needs to import module_a
, which is in the process of being interpreted.
But, sometimes Python is magic, and code that looks like it should cause this circular import error works just fine!
class MyResource | |
include HTTParty | |
debug_output $stdout # <= will spit out all request details to the console | |
#... | |
end |
# | |
# This first version should work on Mac OS X and Linux, but it spawns a process | |
# | |
# http://stackoverflow.com/questions/7220896/ | |
# https://github.com/rdp/os/blob/master/lib/os.rb#L127 | |
# http://www.ruby-doc.org/core-2.0/Process.html | |
# | |
# the real memory (resident set) size of the process (in 1_024 byte units). | |
def Process.rss() `ps -o rss= -p #{Process.pid}`.chomp.to_i ; end |