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 do_something(some_list=[]): | |
some_list.append('some item') | |
print some_list |
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
>>> do_something() | |
['some item'] | |
>>> do_something() | |
['some item', 'some item'] | |
>>> do_something() | |
['some item', 'some item', 'some item'] | |
>>> do_something() | |
['some item', 'some item', 'some item', 'some item'] | |
>>> |
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
>>> do_something(['my item']) | |
['my item', 'some item'] | |
>>> do_something(['my item']) | |
['my item', 'some item'] | |
>>> do_something(['my item']) | |
['my item', 'some item'] | |
>>> |
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
>>> do_something.func_defaults | |
(['some item'],) | |
>>> |
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
>>> do_something.func_defaults = ([42],) | |
>>> do_something() | |
[42, 'some item'] | |
>>> |
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 contextlib import contextmanager | |
import sys, os | |
@contextmanager | |
def suppress_stdout(): | |
with open(os.devnull, "w") as devnull: | |
old_stdout = sys.stdout | |
sys.stdout = devnull | |
try: | |
yield |
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
print "You can see this" | |
with suppress_stdout(): | |
print "You cannot see this" | |
print "And you can see this again" |
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 itertools | |
for a, b, c, d, e, f in itertools.product(range(1, 10), range(1, 10), range(1, 10), range(1, 10), range(1, 10), range(1, 10)): | |
if (a + b + c == 18 and | |
d + e + f == 18 and | |
a + d == b + e and | |
b + e == c + f and | |
int(str(e) + str(f)) in [16, 25, 36, 49, 64, 81] and | |
len(set([a, b, c, d, e, f])) == 6): | |
print a, b, c, d, e, f |
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
scale 562949953421312 | |
bad at 1125899906842624 0x4000000000000 0b100000000000000000000000000000000000000000000000000 | |
scale 281474976710656 | |
bad at 562949953421312 0x2000000000000 0b10000000000000000000000000000000000000000000000000 | |
scale 140737488355328 | |
bad at 281474976710656 0x1000000000000 0b1000000000000000000000000000000000000000000000000 | |
scale 70368744177664 |
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
void my_function() { | |
char *data = malloc(1024); | |
return; // oops! memory leak | |
} |
OlderNewer