This file contains 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
#!/usr/bin/env python3.3 | |
# -*- coding: utf-8 -*- | |
"""A Simple Hangman Demo for Python3. | |
""" | |
#### | |
import random as rand |
This file contains 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
from __future__ import print_function |
This file contains 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
... | |
try: | |
getattr(myobject, 'a_method') | |
except AttributeError: | |
return 0 | |
else: | |
return callable(getattr(myobject, 'a_method')) | |
... |
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Stinky and Grunty reloaded. | |
(http://pyvideo.org/video/880/stop-writing-classes) | |
;-) | |
Works with Python2 + 3. |
This file contains 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
comment_buffer = [] | |
... | |
comment_buffer.append('my_comment') | |
... | |
def show_comments(comment_buffer): | |
'\n'.join(comment_buffer) | |
This file contains 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
In [41]: s = [str(i) for i in xrange(100)] | |
In [42]: timeit reduce(lambda x, y: x + y, s, '') | |
10000 loops, best of 3: 31.9 us per loop | |
In [43]: timeit "".join(s) | |
100000 loops, best of 3: 2.98 us per loop | |
In [44]: a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p = s[:16] |
This file contains 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 rename_team(team_number): | |
"""rename teamnames in the teamnamces dict and in the menu dict""" | |
# hier kommt nicht der neue name | |
new_name = input("please enter new name for team number {}: ".format( | |
team_number)) | |
if new_name == "": | |
print("nothing renamed") | |
return | |
team_names[team_number] = new_name |
This file contains 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 random as rand | |
#### | |
def reroll_rec(minval=1, maxval=6, accu=0, depth=99): | |
"""It's tailrecursion when a function don't have to go back the whole call stack. | |
Only for demonstration purpose. Not intended for production use. | |
""" | |
assert depth >= 0 |
This file contains 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
"""This is a docstring at module level.""" | |
print(__doc__) | |
"""This docstring is ignored""" | |
print(__doc__) | |
def my_func(): | |
"""This is a docstring in my_func.""" | |
print(my_func.__doc__) | |
my_func() |