├── .gitignore ├── 1-podstawy.py ├── 2-zaawansowany.py ├── 3-jakosc-kodu.py ├── Python Has Power 2016 - prezentacja.pdf ├── Python Has Power 2017 - prezentacja - Łódź.pdf └── linki.md /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | -------------------------------------------------------------------------------- /1-podstawy.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ''' OGÓLNY POGLĄD NA SYNTAX ''' 3 | 4 | 5 | print("Witamy w Pythonie!") 6 | num_var = 5 7 | limit_var = 10 8 | 9 | def first_function(): 10 | print("Iteracja po " + str(limit_var) + " liczbach") # komentarz! 11 | for x in range(limit_var): 12 | if x == num_var: 13 | print("x równe {}".format(x)) 14 | else: 15 | print("") 16 | 17 | 18 | 19 | ''' DEFINICJE FUNKCJI''' 20 | 21 | 22 | def print_word(word): 23 | print(word) 24 | 25 | 26 | def print_args(*args): 27 | for index, value in enumerate(args): 28 | print('{0}. {1}'.format(index, value)) 29 | 30 | print_args('apple', 'banana', 'carrot') 31 | 32 | 33 | def print_kwargs(**kwargs): 34 | for name, value in kwargs.items(): 35 | print('{0} is {1}'.format(name, value)) 36 | 37 | print_kwargs(fruit='apple', vegetable='carrot') 38 | 39 | 40 | def print_default_value(fruit, vegetable='carrot', **kwargs): 41 | print('Fruit is {}'.format(fruit)) 42 | print('Vegetable is {}'.format(vegetable)) 43 | for name, value in kwargs.items(): 44 | print('{0} is {1}'.format(name, value)) 45 | 46 | print_default_value('apple') 47 | # or 48 | print_default_value(fruit='apple') 49 | 50 | print_default_value('apple', 'carrot', meat='bacon') 51 | # or 52 | print_default_value('apple', meat='bacon') 53 | 54 | 55 | ''' IMPORTOWANIE''' 56 | 57 | 58 | import math 59 | import sys 60 | 61 | from django.forms import * 62 | 63 | import our_application.module 64 | 65 | 66 | 67 | 68 | '''CZESTE OPERACJE NA TYPACH DANYCH''' 69 | 70 | 71 | # program losuje zbiór 6 unikatowych liczb od 1 do 49 72 | from random import choice 73 | 74 | results = set() 75 | 76 | while len(results) < 6: 77 | results.add(choice(range(1,50))) 78 | 79 | for x in results: 80 | print(x) 81 | 82 | 83 | # przykład iteracji po słownikach 84 | dishes = {'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500} 85 | 86 | for val in dishes.values(): 87 | print(val) 88 | 89 | for key in dishes.keys(): 90 | print(key) 91 | 92 | for key, val in dishes.items(): 93 | print(key, val) 94 | 95 | 96 | 97 | # Lista Ocen Studentów przy wykorzystaniu klas 98 | class Student: 99 | name = "" 100 | surname = "" 101 | mark = 0.0 102 | 103 | students = [] 104 | 105 | print('Podanie pustej wartosci konczy wpisywanie') 106 | while True: 107 | surname = input('Podaj nazwisko studenta > ') 108 | name = input('Podaj imie studenta > ') 109 | mark = input('Podaj ocene studenta > ') 110 | 111 | if not(surname and name and mark): 112 | break 113 | 114 | student = Student() 115 | student.surname = surname 116 | student.name = name 117 | student.mark = float(mark) 118 | students.append(student) 119 | 120 | for idx, student in enumerate(students): 121 | print('{}. {} {} {}'.format(idx+1, student.surname, student.name, student.mark)) 122 | 123 | 124 | # DEBUGOWANIE 125 | 126 | import pdb; pdb.set_trace() 127 | -------------------------------------------------------------------------------- /2-zaawansowany.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ''' COMPREHENSIONS ''' 3 | 4 | [ EXPRESSION for VARIABLE in SEQUENCE if CONDITION ] 5 | 6 | [ n**2 for n in range(10) if n % 2==0 ] 7 | 8 | [ n for n in range(10) ] 9 | 10 | {key: value for key, value in enumerate('abcde')} 11 | 12 | 13 | 14 | 15 | ''' LAMBDA ''' 16 | 17 | lambda VARIABLES: EXPRESSION 18 | lambda x: x**2 19 | lambda x, y, z: (x**2 + y) / z 20 | 21 | 22 | data = [{ 23 | 'name': 'Book', 24 | 'price': '10', 25 | }, { 26 | 'name': 'Phone', 27 | 'price': '20', 28 | }] 29 | 30 | sorted(data, key=lambda x: x['price']) 31 | 32 | 33 | 34 | 35 | ''' GENERATORY - YIELD ''' 36 | 37 | def squares(): 38 | x = 1 39 | while True: 40 | yield x 41 | yield x**2 42 | x = x + 1 43 | 44 | sq = squares() 45 | for x in range(100): 46 | import pdb; pdb.set_trace() # put PDB here and step into functions 47 | print("number %s" % next(sq)) 48 | print("square %s" % next(sq)) 49 | -------------------------------------------------------------------------------- /3-jakosc-kodu.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ''' PYLINT, PEP ''' 3 | 4 | # correct 5 | def long_function_name( 6 | var_one, var_two, var_three, 7 | var_four): 8 | print(var_one) 9 | 10 | foo = long_function_name(var_one, var_two, 11 | var_three, var_four) 12 | # or 13 | foo = long_function_name( 14 | var_one, var_two, var_three, var_four) 15 | 16 | # incorrect 17 | def long_function_name( 18 | var_one, var_two, 19 | var_three, var_four): 20 | print(var_one) 21 | 22 | foo = long_function_name(var_one, var_two, 23 | var_three, var_four) 24 | 25 | 26 | 27 | ''' TESTY JEDNOSTKOWE ''' 28 | 29 | import unittest 30 | 31 | class MathTest(unittest.TestCase): 32 | 33 | def test_add(self): 34 | self.assertEqual(2 + 3, 5) 35 | 36 | def test_sub(self): 37 | self.assertEqual(5 - 3, 3) 38 | 39 | if __name__ == '__main__': 40 | unittest.main() 41 | 42 | # python python/tests/test.py 43 | 44 | # Asercje w testach 45 | 46 | self.assertEqual(2 + 3, 5) 47 | self.assertAlmostEqual(0.1 + 0.2, 0.3, delta=1e-6) 48 | self.assertNotEqual('żółw', u'Żółw') 49 | self.assertTrue([0]) 50 | self.assertFalse([]) 51 | x = [] 52 | y = x 53 | self.assertIs(x, y) 54 | self.assertIn('x', ['x']) 55 | self.assertIsInstance([], list) 56 | self.assertIsNone(None) 57 | self.assertItemsEqual((2, 3), [2, 3]) 58 | 59 | 60 | # Code coverage 61 | 62 | # sudo pip install coverage 63 | # coverage run python/hello.py 64 | # coverage report -m 65 | # coverage html 66 | -------------------------------------------------------------------------------- /Python Has Power 2016 - prezentacja.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stxnext/php-sources/c64245a59da72b75a643087546ffb389c5c010ee/Python Has Power 2016 - prezentacja.pdf -------------------------------------------------------------------------------- /Python Has Power 2017 - prezentacja - Łódź.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stxnext/php-sources/c64245a59da72b75a643087546ffb389c5c010ee/Python Has Power 2017 - prezentacja - Łódź.pdf -------------------------------------------------------------------------------- /linki.md: -------------------------------------------------------------------------------- 1 | # Przydatne linki 2 | 3 | ## Nauka - podstawy 4 | * [Learn Python The Hard Way](http://learnpythonthehardway.org/book/) 5 | * [The Python Tutorial](https://docs.python.org/2/tutorial/index.html) 6 | * [learnpython.org](http://www.learnpython.org/) 7 | * [MITx: 6.00.1x](https://www.edx.org/course/introduction-computer-science-mitx-6-00-1x-6#.U1wSF_lf9LM) 8 | * [Hyperpolyglot](http://hyperpolyglot.org/scripting) - Poglądowe zestawienie php z pythonem 9 | * [PySchool](http://www.pyschools.com/) - Zestaw prostych zadań ćwiczących składnię 10 | * [PyCharm Edu Edition](https://www.jetbrains.com/pycharm-edu/) - Darmowa dystrybucja PyCharm IDE z wbudowanym kursem Pythona 11 | 12 | ## Nauka - następny krok 13 | * [Python Module of the Week](http://pymotw.com/2/) 14 | * [Hidden features of Python](http://stackoverflow.com/questions/101268/hidden-features-of-python) 15 | * Dokumentacja frameworka (eg. Django, Flask, Pyramid) 16 | * [Favorite Django Tips & Features](http://stackoverflow.com/questions/550632/favorite-django-tips-features) 17 | * książka [Python Network Programming Cookbook](http://www.amazon.com/Python-Network-Programming-Cookbook-Faruque/dp/1849513465) 18 | * książka [Python in Practice](http://www.amazon.com/Python-Practice-Concurrency-Libraries-Developers/dp/0321905636) 19 | * książka [Python Testing Cookbook](http://www.amazon.com/Python-Testing-Cookbook-Greg-Turnquist/dp/1849514666) 20 | 21 | ## Nauka - doszkalanie 22 | * [Python Weekly](http://www.pythonweekly.com/) - newsletter 23 | * [importpython](http://importpython.com/newsletter/) - newsletter 24 | * [Planet Python](http://planetpython.org/) - feed blogów o Pythonie 25 | * [pyvideo.org](http://www.pyvideo.org/) - wideo z prezentacji na konferencjach 26 | * [PyCon](http://www.pycon.org/) - największa konferencja Pythonowa 27 | * [EuroPython](https://europython.eu/) - największa konferencja Pythonowa w Europie 28 | * [PyCon PL](http://pl.pycon.org/) - największa konferencja Pythonowa w Polsce 29 | * [PyPila](http://pypila.stxnext.pl/) - spotkania lokalnego community w Pile 30 | * [PyRa](https://plus.google.com/u/0/communities/113848425473260356105) - spotkania lokalnego community w Poznaniu 31 | * [wroc.py](http://www.meetup.com/wrocpy/) - spotkania lokalnego community we Wrocławiu 32 | * [PyLadies](https://www.facebook.com/pyladiespl) 33 | 34 | ## Narzędzia 35 | * [php2python.com](http://www.php2python.com/) - Ułatwia znalezienie pythonowego odpowiednika phpowej funkcji 36 | * [repl.it](https://repl.it/languages/python) - Interaktywna konsola Pythona w przeglądarce 37 | * [Cloud9](https://c9.io/) - IDE + środowisko 38 | * [quantifiedcode](https://www.quantifiedcode.com/) - automatyczne code review 39 | 40 | ### IDE 41 | * [Sublime Text 3](http://www.sublimetext.com/) 42 | * [PyCharm](https://www.jetbrains.com/pycharm/) 43 | * [Eclipse + PyDev](https://eclipse.org/) 44 | * [Vim](http://www.vim.org/) 45 | 46 | ## Zagadki, wyzwania, ćwiczenia 47 | * [CheckIO](http://www.checkio.org/) 48 | * [CodinGame](https://www.codingame.com/) 49 | * [GROT](http://grot.hackathons.stxnext.pl/), [GROT server](http://grot-server.games.stxnext.pl/) 50 | * [CodeCombat](https://codecombat.com) 51 | * [CodeWars](http://www.codewars.com) 52 | 53 | ## Ciekawostki, artykuły 54 | * [Artykuły Python Has Power](http://pythonhaspower.com/artykuly.html) 55 | * [Pythonpedia](https://pythonpedia.com/) 56 | * [Full Stack Python](https://www.fullstackpython.com/) 57 | * [Awesome Python](http://awesome-python.com/) 58 | * [Python: faster way](http://pythonfasterway.cf/) 59 | 60 | --------------------------------------------------------------------------------