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 get_counter(): | |
print 'get_counter' | |
def counter(): | |
count[0] = count[0] + 1 | |
return count[0] | |
count = [0] | |
return counter |
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 get_counter(): | |
print 'get_counter' | |
def counter(): | |
counter.count = counter.count + 1 | |
return counter.count | |
counter.count = 0 | |
return counter |
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 temp(): | |
... print 'called' | |
... for lp in [1,2,3,4,5]: | |
... print 'called:' + str(lp) | |
... yield lp | |
... | |
>>> gen = temp() | |
>>> for index in gen: | |
... pass | |
... |
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: utf-8 -*- | |
class Klass1: | |
def __init__(self, param1, param2): | |
print 'param1: %s' % param1 | |
print 'param2: %s' % param2 | |
class Klass2: | |
def __init__(self, param1, param2, param3): | |
print 'param1: %s' % param1 |
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
for c in target_string: | |
print '%s: %s' % (hex(ord(c)), c.rstrip()) |
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: utf-8 -*- | |
import csv | |
import StringIO | |
s = StringIO.StringIO() | |
csv_writer = csv.writer(s) | |
list = [ | |
{'name': 'item1', 'value': 'foo string'}, | |
{'name': 'item2', 'value': 'bar "quoted" string'}, |
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
# 引数もリストで渡す | |
# 一行で | |
Popen(['ls','-l'],stdout=PIPE).stdout.read() | |
# 一行毎に | |
p = Popen(['ls','-l'],stdout=PIPE) | |
for line in p.stdout.read(): | |
print line | |
# popen2は書いたまま |
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: utf-8 -*- | |
import sys, csv, StringIO | |
import tweepy | |
def get_followers(api, screen_name): | |
followers_count = api.get_user(screen_name = screen_name).followers_count | |
cursor = tweepy.Cursor(api.followers, screen_name = screen_name) | |
followers = cursor.items() |
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
class Foo(): | |
message = "I'm Foo class" | |
def method(self, foo): | |
self.foo = foo | |
print self.message | |
@classmethod | |
def class_method(cls, foo): | |
cls.foo = foo |
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 asyncore | |
import socket | |
class EchoHandler(asyncore.dispatcher): | |
def __init__(self, sock): | |
asyncore.dispatcher.__init__(self, sock=sock) | |
self.send('welcome') | |
return |