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 -*- | |
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
>>> 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
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 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
# -*- coding: utf-8 -*- | |
import tweepy | |
consumer_token = '' | |
consumer_secret = '' | |
access_token = '' | |
access_secret = '' | |
def get_tweets(api, screen_name): |
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 gen1(): | |
count = 0 | |
while True: | |
count = count + 1 | |
print count | |
if count > 10: | |
return | |
if count == 5: | |
print 'raise!' | |
raise '5!!!' |
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 -*- | |
# simple generator function | |
def generator1(limit): | |
for count in range(limit): | |
yield count | |
# simple generator function with return | |
def generator2(limit, stop): | |
for count in range(limit): | |
if count > stop: |
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 AdminHandler(webapp.RequestHandler): | |
@util.login_required | |
def get(self): | |
csrf_key = self._generate_csrf_key() | |
# pass csrf key as template parameter | |
@util.login_required | |
def post(self): | |
if users.is_current_user_admin(): | |
if not self._check_csrf_key(self.request.get('csrf_key')): |
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
hash1 = {:a=> 1, :b=>2} | |
hash2 = {} | |
hash2[:b] = 3 | |
p hash2 | |
hash2.update(hash1) | |
p hash2 | |
#{:b=>3} |