>>> os.path.join? Type: function String form: <function join at 0x7f8bb58a4f50> File: /usr/lib/python2.7/posixpath.py Definition: os.path.join(a, *p) Docstring: Join two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator. >>>
String form: <function join at 0x7f8bb58a4f50> File: /usr/lib/python2.7/posixpath.py Definition: os.path.join(a, *p) Source: def join(a, *p): """Join two or more pathname components, inserting '/' as needed. If any component is an absolute path, all previous path components will be discarded. An empty last part will result in a path that ends with a separator.""" path = a for b in p: <... resto do código omitido ...>
e a memória também =) c.TerminalInteractiveShell.cache_size = 0 A configuração acima desabilita _<NUMERO> _, __ e ___ continuarão funcionando Ref: https://ipython.org/ipython-doc/3/interactive/reference.html#output-caching-system
lista) 10000 loops, best of 3: 74.5 µs per loop >>> %timeit [str(l) for l in lista] 10000 loops, best of 3: 121 µs per loop >>> >>> import math >>> %time math.sqrt(3.456) CPU times: user 0 ns, sys: 0 ns, total: 0 ns Wall time: 13.1 µs 1.85903200617956 Ou, como vencer uma discussão inútil sobre otimização prematura %time roda só uma vez e mostra o resultado (igual o time do shell do sistema)
open(bashrc, 'w').write('echo muhaha') >>> %hist import os bashrc = os.path.expanduser('~/. bashrc') open(bashrc, 'w').write('echo muhaha') %hist >>> %hist -f arquivo.py >>> # ou ainda: >>> %save arquivo.py 1-3 Hm, na verdade eu queria criar um script pra isso que tô fazendo... (ou jogar para uns slides ;-)
as funções mágicas disponíveis • %quickref ◦ Mostra referência rápida de comandos do IPython • %edit ◦ Abre editor com arquivo temporário pra digitar o código e executar depois • %autoindent ◦ habilita/desabilita indentação automática • %run arquivo.py ◦ Roda comandos em arquivo.py
...: for e in collection: ...: print(e) ...: for e in collection: ...: print(e) ...: File "<ipython-input-8-17a426f52fc3>", line 4 for e in collection: ^ IndentationError: unindent does not match any outer indentation level If you want to paste code into IPython, try the %paste and %cpaste magic functions. >>>
%autoindent Automatic indentation is: OFF >>> def loop_duplo(collection): ....: for e in collection: ....: print(e) ....: for e in collection: ....: print(e) ....: >>>
%cpaste Pasting code; enter '--' alone on the line to stop or use Ctrl-D. :def loop_duplo(collection): : for e in collection: : print(e) : for e in collection: : print(e) : :<EOF> >>>
math >>> >>> for n in [9, 6, 25]: ....: ...: print(math.sqrt(n)) ....: ...: 3.0 2.44948974278 5.0 >>> Repare como ele ignorou a marcação extra gerada na outra sessão
(env)$ ipython WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv. (env)$ pip install ipython (env)$ ipython WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv. (env)$ hash -r (env)$ ipython >>> print "Yay!" Yay! Atualiza as referências aos programas conhecidos pelo shell.