Python 3, primeros pasos

Miguel González @migonzalvar

19 Febrero 2015

Instalación

Linux

  • Ya está!

    vagrant@vagrant-ubuntu-trusty-64:~$ python3
    Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
    [GCC 4.8.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    vagrant@vagrant-ubuntu-trusty-64:~$ which python3
    /usr/bin/python3

Windows

  • Instalador MSI

    Más info en https://www.python.org/downloads/windows/

Mac OS X

Intérpretes

Estándar

$ python
>>>

bpython

  • Instalación

    $ sudo apt-get install bpython3

    Más info

  • Demo

Escribir programas

Primero

  • Cabecera para hacer un archivo ejecutable. Funciona en Windows!

    #!/bin/env python3
    ...
  • chmod +x

  • Alternativamente python nombre.py

tabs 4 espacios

Vim

set shiftwidth=4  " operation >> indents 4 columns; << unindents 4 columns
set tabstop=4     " a hard TAB displays as 4 columns
set expandtab     " insert spaces when hitting TABs
set softtabstop=4 " insert/delete 4 spaces when hitting a TAB/BACKSPACE
set shiftround    " round indent to multiple of 'shiftwidth'
set autoindent    " align the new line indent with the previous line

Sublime

  • Preferences > Settings - User

    {
        ...,
        "translate_tabs_to_spaces": true
    }

PyCharm

Continuar

Recursos

  • https://docs.python.org/3/tutorial/
  • https://docs.python.org/3/library/
  • http://docs.python-guide.org/en/latest/
  • http://migonzalvar.eu/curso-python3/

Bonus track

pip

  • Gestor de paquetes

  • Incluida en Python 3 salvo Ubuntu

    $ python3 -m pip
  • Instalación en Ubuntu

    $ sudo apt-get install python3-pip
    $ curl https://bootstrap.pypa.io/get-pip.py | python3
  • Uso

    $ pip3 install youtube-dl
    ...
    $ pip3 install --upgrade youtube-dl
    ...
    $ pip3 uninstall youtube-dl

pyenv

  • Era una herramienta independiente virtualenv ahora incluida en la librería estándar como pyvenv o python3 -m venv

  • Uso

    $ python3 -m venv /path/to/venv
    $ source /path/to/venv/bin/activate
    (venv)$ 
  • Workaround en Ubuntu trusty 14.04

    $ python3 -m venv --without-pip /path/to/venv
    $ curl https://bootstrap.pypa.io/get-pip.py | /path/to/venv/bin/python

Gracias!

Python 3, primeros pasos

By migonzalvar

Python 3, primeros pasos

  • 1,349