298 lines
5.8 KiB
Plaintext
298 lines
5.8 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"source": [
|
|
"# Python: część 3\n",
|
|
"\n",
|
|
"## Tomasz Dwojak\n",
|
|
"\n",
|
|
"### 16 grudnia 2017"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"source": [
|
|
"## Co już było?\n",
|
|
" * podstawowe typy i struktury danych\n",
|
|
" * funkcje\n",
|
|
" * biblioteki\n",
|
|
" * klasy\n",
|
|
" * praca z plikami\n",
|
|
" * wyjątki"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"source": [
|
|
"# Co na dziś?\n",
|
|
" * Dzielenie kodu na pliki\n",
|
|
" * Podstawy analizy danych: Pandas"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"source": [
|
|
"## Dzielenie kodu\n",
|
|
"\n",
|
|
" * Zwiększenie jakości kodu\n",
|
|
" * Napisz raz i korzystaj w wielu sytuacjach\n",
|
|
" * Tworzenie własnej biblioteki"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"source": [
|
|
"## Dzielenie kodu - podsumowanie\n",
|
|
" * import\n",
|
|
" * ``if __name__ == '__main__'``\n",
|
|
" * Pakiety i pliki ``__init__.py``\n",
|
|
" * zmienna PYTHONPATH i ``sys.path``"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"source": [
|
|
"# Interpreter Pythona"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"source": [
|
|
"# Jupyter notebook"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"source": [
|
|
"## Argumenty do programu\n",
|
|
"\n",
|
|
" * czy potrzebujemy pyCharm żeby uruchomić prosty skrypt?"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"source": [
|
|
"### sys.argv\n",
|
|
" * zawiera liste wszystkich argumentów\n",
|
|
" * pierwszy element zawiera nazwe pliku"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "fragment"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"['/usr/lib/python2.7/site-packages/ipykernel/__main__.py', '-f', '/run/user/1000/jupyter/kernel-7efdb6ca-75d5-474e-90c4-fda3dadc3282.json']\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import sys\n",
|
|
"print(sys.argv)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"source": [
|
|
"### Biblioteka argparse"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "fragment"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import argparse\n",
|
|
"parser = argparse.ArgumentParser()\n",
|
|
"parser.parse_args()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"parser = argparse.ArgumentParser()\n",
|
|
"parser.add_argument(\"number\", help=\"Opis\")\n",
|
|
"args = parser.parse_args()\n",
|
|
"print(args.number)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"parser = argparse.ArgumentParser()\n",
|
|
"parser.add_argument(\"number\", help=\"Opis\", nargs=\"+\")\n",
|
|
"args = parser.parse_args()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"parser = argparse.ArgumentParser()\n",
|
|
"parser.add_argument(\"--verbosity\", help=\"increase output verbosity\")\n",
|
|
"args = parser.parse_args()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"parser = argparse.ArgumentParser()\n",
|
|
"parser.add_argument(\"--verbose\", help=\"increase output verbosity\",\n",
|
|
" action=\"store_true\")\n",
|
|
"args = parser.parse_args()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"parser = argparse.ArgumentParser()\n",
|
|
"parser.add_argument(\"-v\", \"--verbose\", help=\"increase output verbosity\",\n",
|
|
" action=\"store_true\")\n",
|
|
"args = parser.parse_args()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"slideshow": {
|
|
"slide_type": "slide"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"parser = argparse.ArgumentParser()\n",
|
|
"parser.add_argument(\"-v\", \"--verbose\", help=\"increase output verbosity\",\n",
|
|
" action=\"store_true\")\n",
|
|
"parser.add_argument(\"number\", help=\"Opis\", nargs=\"+\")\n",
|
|
"args = parser.parse_args()"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"celltoolbar": "Slideshow",
|
|
"kernelspec": {
|
|
"display_name": "Python 2",
|
|
"language": "python2",
|
|
"name": "python2"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.14"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|