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
>>> loader = machinery.SourceFileLoader('plugin_base', '/tmp/test.py') | |
>>> loader.create_module() | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
AttributeError: 'SourceFileLoader' object has no attribute 'create_module' | |
>>> isinstance(loader, importlib.abc.Loader) | |
True | |
>>> importlib.abc.Loader.create_module | |
<function Loader.create_module at 0x10b84de18> |
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 importlib.machinery import ModuleSpec, SourceFileLoader | |
from _frozen_importlib import _SpecMethods | |
path = '/tmp/test.py' | |
loader = SourceFileLoader('plugin_base', path) | |
spec = ModuleSpec(name='plugin_base', loader=loader) | |
mod = _SpecMethods(spec).create() |
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 sys | |
>>> sys.stdin = sys.stdin.detach() | |
>>> | |
>>> input('foo') | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
AttributeError: '_io.BufferedReader' object has no attribute 'errors' |
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 io | |
>>> stdin = sys.stdin | |
>>> correct_stdin = io.TextIOWrapper(stdin.buffer, 'iso-8859-15') | |
>>> correct_stdin.readline() | |
foobar | |
'foobar\n' | |
>>> del correct_stdin | |
>>> stdin.readline() | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> |
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 io | |
>>> sys.stdin.encoding | |
'ANSI_X3.4-1968' | |
>>> stdin = sys.stdin | |
>>> correct_stdin = io.TextIOWrapper(stdin.buffer, 'utf-8') | |
>>> correct_stdin.readline() | |
foobar | |
'foobar\n' | |
>>> del correct_stdin | |
>>> stdin.readline() |
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
$ python3 wtf.py | |
foo | |
bar | |
b'' |
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
mitsuhiko at atherton in /tmp/test | |
$ python3 | |
Python 3.4.0 (v3.4.0:04f714765c13, Apr 15 2014, 15:41:42) | |
[GCC 4.2.1 Compatible Clang 3.2 (tags/RELEASE_32/final)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import os | |
>>> letter = '\xf6' | |
>>> letter | |
'ö' | |
>>> open(letter, 'w').close() |
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
$ flask -a myapp | |
Usage: flask [OPTIONS] COMMAND [ARGS]... | |
This shell command acts as general utility script for Flask applications. | |
It loads the application configured (either through the FLASK_APP | |
environment variable or the --app parameter) and then provides commands | |
either provided by the application or Flask itself. | |
The most useful commands are the "run" and "shell" command. |
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 click | |
@click.command() | |
@click.argument('input', type=click.File('rb'), nargs=-1) | |
@click.argument('output', type=click.File('wb')) | |
def cli(input, output): | |
for f in input: | |
while True: | |
chunk = f.read(1024) | |
if not chunk: |
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 | |
debug = True | |
if os.environ.get('APP_NO_DEBUG'): | |
dеbug = False |
OlderNewer