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 outer(): | |
... def inner(): | |
"Fails with SyntaxError" | |
... from numpy import * | |
... return array | |
... return inner() | |
... | |
<stdin>:2: SyntaxWarning: import * only allowed at module level | |
File "<stdin>", line 3 | |
SyntaxError: import * is not allowed in function 'inner' because it is a nested 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
In [2]: x = 3 | |
In [3]: def foo(): | |
...: global x | |
...: def x(): | |
...: pass | |
...: | |
In [4]: x | |
Out[4]: 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
>>> AssertionError = ValueError | |
>>> assert False, "Assert Failed!" | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
ValueError: Assert Failed! | |
>>> AssertionError = None | |
>>> assert False, "Assert Failed!" | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: 'NoneType' object is not callable |
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 [2]: e = 3 | |
In [3]: x = {} | |
In [4]: try: | |
...: x['a'] | |
...: except Exception as e: | |
...: pass | |
...: |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
# td is a TemporaryDirectory that's being deleted earlier than | |
# expected somewhere in my test suite. | |
import shutil | |
old_rmtree = shutil.rmtree | |
def rmtree(path, *args, **kwargs): | |
if path == td.name: | |
import nose.tools; nose.tools.set_trace() | |
return old_rmtree(path, *args, **kwargs) |
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 os | |
from unittest import TestCase | |
import psutil | |
import humanize | |
pid = os.getpid() | |
proc = psutil.Process(pid) | |
real_doCleanups = TestCase.doCleanups | |
OUTPUT_FILE = open('/home/ssanderson/pandas16_memory_usage.txt', 'w') |
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 | |
import requests | |
import pandas as pd | |
from six.moves.urllib_parse import urlencode | |
def download_avocado_data(dest, start_date, end_date): | |
base_url = 'https://www.marketnews.usda.gov/mnp/fv-report-retail' |
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 codetransformer.transformers.switchcase import switch | |
def foo(x): | |
print("Start: x={}".format(x)) | |
with switch(x) as case: | |
@case(1) | |
def _1(): | |
# Read and write x. |
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 | |
from contextlib import contextmanager | |
@contextmanager | |
def some_context_manager(x): | |
print("Entering", x) | |
yield | |
print("Exiting", x) |