├── modules ├── mod4.1.json │ ├── json_basics │ │ ├── ob.json │ │ ├── multi_line.json │ │ └── json_basics.py │ ├── json_objects_manip_class │ │ ├── ob.json │ │ ├── __pycache__ │ │ │ └── timeclass.cpython-39.pyc │ │ ├── main.py │ │ └── timeclass.py │ ├── json_objects_manip_func │ │ ├── ob.json │ │ ├── __pycache__ │ │ │ └── timeclass.cpython-39.pyc │ │ ├── main.py │ │ └── timeclass.py │ ├── json_datatypes │ │ ├── ob.json │ │ └── json_datatypes.py │ ├── json_args │ │ ├── ob.json │ │ ├── beautify.py │ │ ├── json_dumb_args.py │ │ └── read.py │ ├── python.modules4.1.json.pdf │ ├── json_many_objects_same_type │ │ ├── __pycache__ │ │ │ └── timeclass.cpython-39.pyc │ │ ├── ob.json │ │ ├── main.py │ │ └── timeclass.py │ └── json_many_objects_different_types │ │ ├── __pycache__ │ │ └── timeclass.cpython-39.pyc │ │ ├── main.py │ │ ├── ob.json │ │ └── timeclass.py ├── mod1.1.math │ ├── exercise10.py │ ├── exercise04.py │ ├── exercise09.py │ ├── exercise01.py │ ├── exercise02.py │ ├── exercise08.py │ ├── exercise03.py │ ├── floor.ceil.py │ ├── exercise07.py │ ├── exercise05.py │ ├── isclose.py │ ├── python.modules1.1.math.pdf │ ├── logarithms.py │ ├── exercise06.py │ └── trig.py ├── mod1.3.decimal │ ├── exercise01.py │ ├── context.py │ ├── log.syntax.py │ ├── log.py │ ├── python.modules1.3.decimal.pdf │ ├── augmented.assignment.py │ ├── method.py │ ├── methods.py │ ├── with.py │ ├── operators.py │ ├── precision.py │ ├── quantize.py │ ├── logical.py │ ├── relational.operators.py │ ├── constructor.py │ └── opc.money.py ├── mod7.1.csv │ ├── excel.xls │ ├── python.modules7.1.csv.pdf │ ├── read_csv.py │ ├── read_csv_dictionary.py │ ├── dialect.py │ ├── delimiter.py │ ├── write_csv.py │ ├── script.sql │ ├── quotechar.py │ ├── sniffer.py │ ├── write_csv_dictionary.py │ ├── countries_new3.csv │ └── excel.csv ├── mod1.2.random │ ├── getrandbits.py │ ├── python.modules1.2.random.pdf │ ├── exercise01.py │ ├── exercise05.py │ ├── choices.py │ ├── exercise02.py │ ├── exercise03.py │ ├── exercise04.py │ ├── opc.dice.py │ └── opc.resampling.py ├── mod5.2.shelve │ ├── data.shelf.bak │ ├── data.shelf.dir │ ├── data.shelf.dat │ ├── python.modules5.2.shelve.pdf │ └── shelf_example.py ├── mod2.1.copy │ ├── python.modules2.1.copy.pdf │ └── exercise01.py ├── mod2.4.enum │ ├── python.modules2.4.enum.pdf │ ├── callable.py │ ├── unique_values.py │ ├── int_flag_enum.py │ ├── flag_enum.py │ ├── auto_values.py │ ├── int_enum.py │ ├── simple_enum.py │ ├── comparable.py │ ├── methods.py │ └── functionality.py ├── mod8.1.re(a) │ ├── python.modules8.1.re.pdf │ ├── groups2.py │ ├── groups.py │ ├── boundary.py │ ├── PatternMatcher.py │ ├── boundary_word.py │ ├── or.py │ ├── quantifiers2.py │ ├── quantifiers.py │ ├── dot.py │ ├── predefined_character_classes.py │ ├── character_classes.py │ ├── special_characters.py │ ├── escaping.py │ ├── star.py │ └── pies.html ├── mod2.3.heapq │ ├── python.modules2.3.heapq.pdf │ ├── creation.py │ ├── merging.py │ └── smallest.py ├── mod2.6.array │ ├── python.modules2.6.array.pdf │ ├── array_init.py │ ├── as_list.py │ ├── array_to_file.py │ ├── searching.py │ └── conversions.py ├── mod8.2.re(b) │ ├── python.modules8.2.re(b).pdf │ ├── splitting.py │ ├── subn.py │ ├── match_fullmatch.py │ ├── search.py │ ├── groups3.py │ ├── sub.py │ ├── flags.py │ ├── findall.py │ ├── pies.html │ └── pies2.html ├── mod2.5.bisect │ ├── python.modules2.5.bisect.pdf │ ├── key_sorted_problem.py │ ├── bisect_example.py │ ├── insert_keep_sorted.py │ ├── key_sorted_solution.py │ └── typical_search_examples(docs).py ├── mod5.1.pickle │ ├── python.modules5.1.pickle.pdf │ ├── pickle_load.py │ ├── ser.py │ └── pickle_loads.py ├── mod8.3.string │ ├── python.modules8.3.string.pdf │ ├── format_spec.py │ ├── template_init.py │ ├── str.format.py │ ├── format_spec2.py │ ├── template_substitute.py │ ├── template_safe_substitute.py │ ├── constants.py │ ├── replacement_indexing.py │ └── format_replacement.py ├── mod2.7.graphlib │ ├── python.modules2.7.graphlib.pdf │ ├── calculate_ts.py │ ├── prepare_for_ts.py │ └── dynamic.py ├── mod3.1.datetime │ ├── python.modules3.1.datetime.pdf │ ├── format │ │ ├── strftime.py │ │ └── locale_info.py │ ├── time │ │ ├── construct_time.py │ │ └── methods.py │ ├── timedelta │ │ ├── diff.py │ │ └── operations.py │ ├── date │ │ ├── methods.py │ │ └── construct_date.py │ └── datetime │ │ ├── datetime_ops.py │ │ └── methods.py ├── mod6.3.operator │ ├── python.modules6.3.operator.pdf │ ├── sort_by_indices.py │ ├── operators.py │ ├── getters.py │ └── method_caller.py ├── mod1.4.fraction │ ├── python.modules1.4.fractions.pdf │ └── frac.py ├── mod6.1.itertools │ ├── python.modules6.1.itertools.pdf │ ├── accumulate_example.py │ ├── starmap_example.py │ ├── split.py │ ├── merging.py │ ├── produce_values.py │ ├── filter.py │ ├── combinatorial_iterators.py │ └── groupby_example.py ├── mod6.2.functools │ ├── python.modules6.2.functools.pdf │ ├── partial.py │ ├── cache2.py │ ├── caching.py │ ├── cache3.py │ ├── polymorphic_function.py │ ├── wraps.py │ ├── polymorphic_method.py │ ├── ordering.py │ └── partialmethod.py └── mod2.2.collections │ ├── python.modules2.2.collections.pdf │ ├── named_tuple │ ├── construct.py │ ├── query │ │ ├── __pycache__ │ │ │ └── connect.cpython-39.pyc │ │ ├── connect.py │ │ └── main.py │ └── methods.py │ ├── doubleEndedQueue │ ├── __pycache__ │ │ └── queue.cpython-39.pyc │ ├── queue.py │ ├── methods.py │ └── exercise12_lesson17.py │ ├── counter │ ├── counter_init.py │ └── counter_methods.py │ ├── chain_map │ ├── constructor.py │ └── members.py │ └── dict_variations │ ├── ordered_dict.py │ ├── ordered_dict_fifo.py │ └── default_dict.py ├── advanced ├── advanced03.generators │ ├── gen.expression1.py │ ├── gen.expression2.py │ ├── gen.expression3.py │ ├── sample.xlsx │ ├── generator.py │ ├── sample.csv │ ├── python.advanced03.generators.pdf │ ├── close.py │ ├── throw.py │ ├── generator2.py │ ├── opc.csv.py │ ├── send.py │ ├── opc.file.py │ ├── exercise01.py │ └── opc.binary.tree.py ├── advanced06.lambda │ ├── lambda_arg_in_function.py │ ├── python.advanced06.lambda.functional.pdf │ ├── exercise01.py │ ├── map_examples.py │ ├── lambda_definition.py │ ├── filter_examples.py │ ├── map_examples3.py │ ├── closure.py │ ├── closure2.py │ ├── reduce_examples.py │ ├── filter_examples2.py │ ├── map_examples2.py │ ├── inner_lambda.py │ └── reduce_examples2.py ├── advanced02.iterators │ ├── read.data.fail.py │ ├── python.advanced02.iterator.pdf │ ├── for.implementation.py │ ├── iterator.list.dict.py │ ├── iterator.py │ ├── exercise01.py │ ├── enumerate2.py │ ├── enumerate1.py │ ├── iterator.for.py │ ├── iterator.conversions.py │ ├── read.data.success.py │ ├── zip.py │ ├── iterator.builtin1.py │ ├── opc.primes.py │ └── opc.fibonacci.py ├── advanced01.pip │ ├── python.advanced01.pip.pdf │ └── surface3d_demo3.py ├── advanced05.decorators(classes) │ ├── python.advanced05.decorators.classes.pdf │ ├── property_getter.py │ ├── class_decorator.py │ ├── example_timer.py │ ├── example_debug.py │ ├── property_setter.py │ ├── class_as_decorator.py │ ├── example_memoization.py │ ├── with_state.py │ ├── classmethod_and_staticmethod.py │ ├── property_deleter.py │ ├── with_arguments.py │ └── multiple_decorators.py └── advanced04.decorators(functions) │ ├── python.advanced04.decorators.functions.pdf │ ├── factory.power.py │ ├── decorator.syntax.py │ ├── decorator.arbitrary.args.py │ ├── decorator.py │ ├── closure.py │ ├── higher.order.func.py │ ├── decorator.func.with.params.py │ ├── exercise01.py │ ├── exercise02.py │ ├── opc.html.decorating.py │ └── opc.timing.py └── packages └── 01.MySQL ├── lesson02 ├── blobs │ ├── bs.png │ ├── copy.png │ ├── mysql.png │ ├── main.py │ └── dbtools.py ├── python.pac01.mysql.lesson02.crud.blob.date.ext.pdf ├── scripts │ ├── create_table_images.sql │ ├── dates.sql │ └── stored.sql ├── stored_proc │ ├── main.py │ └── dbtools.py ├── insert │ ├── main.py │ └── dbtools.py ├── upd_del │ ├── main.py │ └── dbtools.py ├── dates │ ├── main.py │ └── dbtools.py └── exercise1 │ ├── main.py │ └── dbtools.py └── lesson01 ├── python.pac01.mysql.lesson01.pdf ├── exercise04 ├── main.py └── dbtools.py ├── connection.py ├── exercise05 ├── main.py └── dbtools.py ├── query ├── main.py └── connect.py ├── exercise01 ├── connect.py └── main.py ├── exercise02 ├── connect.py └── main.py ├── dictionary_manip ├── connect.py └── main.py ├── fetchone ├── main.py └── dbtools.py ├── fetchmany ├── main.py └── dbtools.py ├── exercise03 ├── main.py └── dbtools.py └── exercise06 ├── dbtools.py └── main.py /modules/mod4.1.json/json_basics/ob.json: -------------------------------------------------------------------------------- 1 | [[1, 2], [2, 3]] -------------------------------------------------------------------------------- /modules/mod1.1.math/exercise10.py: -------------------------------------------------------------------------------- 1 | from math import nan 2 | 3 | print(nan==nan) -------------------------------------------------------------------------------- /modules/mod1.1.math/exercise04.py: -------------------------------------------------------------------------------- 1 | from math import pi, modf 2 | 3 | print(modf(pi)) -------------------------------------------------------------------------------- /modules/mod4.1.json/json_objects_manip_class/ob.json: -------------------------------------------------------------------------------- 1 | {"hour": 10, "minute": 22, "second": 24} -------------------------------------------------------------------------------- /modules/mod4.1.json/json_objects_manip_func/ob.json: -------------------------------------------------------------------------------- 1 | {"hour": 10, "minute": 22, "second": 24} -------------------------------------------------------------------------------- /modules/mod4.1.json/json_basics/multi_line.json: -------------------------------------------------------------------------------- 1 | [1, 2, 3] 2 | 4 3 | [1, 2, 3] 4 | [1, 2, 3] 5 | -------------------------------------------------------------------------------- /modules/mod1.1.math/exercise09.py: -------------------------------------------------------------------------------- 1 | from math import prod 2 | 3 | 4 | print(prod(list(range(1,101)))) -------------------------------------------------------------------------------- /modules/mod1.3.decimal/exercise01.py: -------------------------------------------------------------------------------- 1 | from decimal import Decimal 2 | D=Decimal 3 | 4 | print(D(1)+D(0.1)) -------------------------------------------------------------------------------- /modules/mod1.3.decimal/context.py: -------------------------------------------------------------------------------- 1 | #context.py 2 | from decimal import getcontext 3 | 4 | print(getcontext()) 5 | -------------------------------------------------------------------------------- /modules/mod4.1.json/json_datatypes/ob.json: -------------------------------------------------------------------------------- 1 | 1 2 | 1.1 3 | "string" 4 | [1, 2] 5 | [1, 2] 6 | {"1": 1, "2": 2} 7 | -------------------------------------------------------------------------------- /advanced/advanced03.generators/gen.expression1.py: -------------------------------------------------------------------------------- 1 | g = (i for i in range(4)) 2 | 3 | for i in g: 4 | print(i) -------------------------------------------------------------------------------- /advanced/advanced06.lambda/lambda_arg_in_function.py: -------------------------------------------------------------------------------- 1 | def f(x, y): 2 | return x(y) 3 | print(f(lambda x: x*x, 6)) -------------------------------------------------------------------------------- /modules/mod4.1.json/json_args/ob.json: -------------------------------------------------------------------------------- 1 | { 2 | "age": 25, 3 | "first_name": "John", 4 | "last_name": "Doe" 5 | } -------------------------------------------------------------------------------- /modules/mod7.1.csv/excel.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod7.1.csv/excel.xls -------------------------------------------------------------------------------- /modules/mod1.1.math/exercise01.py: -------------------------------------------------------------------------------- 1 | from math import dist, hypot 2 | 3 | print(dist((0,0,0),(1,2,1))) 4 | print(hypot(1,2,1)) -------------------------------------------------------------------------------- /modules/mod1.1.math/exercise02.py: -------------------------------------------------------------------------------- 1 | from math import frexp 2 | 3 | 4 | for x in range(100+1): 5 | print(x, frexp(x)) -------------------------------------------------------------------------------- /modules/mod1.1.math/exercise08.py: -------------------------------------------------------------------------------- 1 | from math import fsum 2 | 3 | myl = list(range(10)) 4 | 5 | print(sum(myl), fsum(myl)) -------------------------------------------------------------------------------- /advanced/advanced02.iterators/read.data.fail.py: -------------------------------------------------------------------------------- 1 | # read.data.fail.py 2 | for data in list(range(100000000)): 3 | print(data) -------------------------------------------------------------------------------- /advanced/advanced03.generators/gen.expression2.py: -------------------------------------------------------------------------------- 1 | g = (i for i in range(4) if i%2==0) 2 | 3 | for i in g: 4 | print(i) -------------------------------------------------------------------------------- /modules/mod1.2.random/getrandbits.py: -------------------------------------------------------------------------------- 1 | from random import getrandbits 2 | 3 | for i in range(100): 4 | print(getrandbits(2)) -------------------------------------------------------------------------------- /modules/mod5.2.shelve/data.shelf.bak: -------------------------------------------------------------------------------- 1 | 'int', (0, 5) 2 | 'dict', (512, 28) 3 | 'set', (1024, 22) 4 | 'object', (1536, 110) 5 | -------------------------------------------------------------------------------- /modules/mod5.2.shelve/data.shelf.dir: -------------------------------------------------------------------------------- 1 | 'int', (0, 5) 2 | 'dict', (512, 28) 3 | 'set', (1024, 22) 4 | 'object', (1536, 110) 5 | -------------------------------------------------------------------------------- /modules/mod1.1.math/exercise03.py: -------------------------------------------------------------------------------- 1 | from math import exp 2 | 3 | 4 | def f(x): 5 | return 1/(1+exp(-x)) 6 | 7 | 8 | print(f(0)) -------------------------------------------------------------------------------- /modules/mod1.1.math/floor.ceil.py: -------------------------------------------------------------------------------- 1 | from math import floor, ceil 2 | 3 | print(floor(5.1), floor(5)) 4 | print(ceil(-3.4), ceil(-3)) -------------------------------------------------------------------------------- /modules/mod5.2.shelve/data.shelf.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod5.2.shelve/data.shelf.dat -------------------------------------------------------------------------------- /advanced/advanced03.generators/gen.expression3.py: -------------------------------------------------------------------------------- 1 | g = (i if i%2==0 else i*i for i in range(4)) 2 | 3 | for i in g: 4 | print(i) -------------------------------------------------------------------------------- /modules/mod1.1.math/exercise07.py: -------------------------------------------------------------------------------- 1 | from math import gamma,factorial 2 | 3 | for i in range(2,11): 4 | print(gamma(i), factorial(i-1)) -------------------------------------------------------------------------------- /modules/mod1.3.decimal/log.syntax.py: -------------------------------------------------------------------------------- 1 | from decimal import Decimal 2 | 3 | D=Decimal 4 | d=D("0.1") 5 | print(d.ln(), type(d.ln())) 6 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/blobs/bs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/packages/01.MySQL/lesson02/blobs/bs.png -------------------------------------------------------------------------------- /advanced/advanced03.generators/sample.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/advanced/advanced03.generators/sample.xlsx -------------------------------------------------------------------------------- /modules/mod1.1.math/exercise05.py: -------------------------------------------------------------------------------- 1 | from math import fabs 2 | 3 | print(abs(5), fabs(5)) 4 | print(abs(0), fabs(0)) 5 | print(abs(-5), fabs(-5)) -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/blobs/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/packages/01.MySQL/lesson02/blobs/copy.png -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/blobs/mysql.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/packages/01.MySQL/lesson02/blobs/mysql.png -------------------------------------------------------------------------------- /modules/mod7.1.csv/python.modules7.1.csv.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod7.1.csv/python.modules7.1.csv.pdf -------------------------------------------------------------------------------- /modules/mod1.1.math/isclose.py: -------------------------------------------------------------------------------- 1 | from math import isclose 2 | 3 | print(isclose(0.001,0.005,abs_tol=1e-3)) 4 | print(isclose(0.0001,0.0005,abs_tol=1e-3)) -------------------------------------------------------------------------------- /modules/mod1.1.math/python.modules1.1.math.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod1.1.math/python.modules1.1.math.pdf -------------------------------------------------------------------------------- /modules/mod1.3.decimal/log.py: -------------------------------------------------------------------------------- 1 | # log.py 2 | from decimal import Decimal 3 | from math import log 4 | D=Decimal 5 | 6 | print(type(log(D("12.0")))) 7 | -------------------------------------------------------------------------------- /modules/mod2.1.copy/python.modules2.1.copy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod2.1.copy/python.modules2.1.copy.pdf -------------------------------------------------------------------------------- /modules/mod2.4.enum/python.modules2.4.enum.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod2.4.enum/python.modules2.4.enum.pdf -------------------------------------------------------------------------------- /modules/mod4.1.json/python.modules4.1.json.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod4.1.json/python.modules4.1.json.pdf -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/python.modules8.1.re.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod8.1.re(a)/python.modules8.1.re.pdf -------------------------------------------------------------------------------- /advanced/advanced01.pip/python.advanced01.pip.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/advanced/advanced01.pip/python.advanced01.pip.pdf -------------------------------------------------------------------------------- /modules/mod2.3.heapq/python.modules2.3.heapq.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod2.3.heapq/python.modules2.3.heapq.pdf -------------------------------------------------------------------------------- /modules/mod2.6.array/python.modules2.6.array.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod2.6.array/python.modules2.6.array.pdf -------------------------------------------------------------------------------- /modules/mod8.2.re(b)/python.modules8.2.re(b).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod8.2.re(b)/python.modules8.2.re(b).pdf -------------------------------------------------------------------------------- /modules/mod1.1.math/logarithms.py: -------------------------------------------------------------------------------- 1 | from math import e, log, log10 2 | 3 | print(log(e)) 4 | 5 | for x in [1,10,100,1000]: 6 | print(f"log({x}) = {log10(x)}") -------------------------------------------------------------------------------- /modules/mod1.2.random/python.modules1.2.random.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod1.2.random/python.modules1.2.random.pdf -------------------------------------------------------------------------------- /modules/mod1.3.decimal/python.modules1.3.decimal.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod1.3.decimal/python.modules1.3.decimal.pdf -------------------------------------------------------------------------------- /modules/mod2.5.bisect/python.modules2.5.bisect.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod2.5.bisect/python.modules2.5.bisect.pdf -------------------------------------------------------------------------------- /modules/mod5.1.pickle/python.modules5.1.pickle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod5.1.pickle/python.modules5.1.pickle.pdf -------------------------------------------------------------------------------- /modules/mod5.2.shelve/python.modules5.2.shelve.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod5.2.shelve/python.modules5.2.shelve.pdf -------------------------------------------------------------------------------- /modules/mod8.3.string/python.modules8.3.string.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod8.3.string/python.modules8.3.string.pdf -------------------------------------------------------------------------------- /modules/mod2.7.graphlib/python.modules2.7.graphlib.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod2.7.graphlib/python.modules2.7.graphlib.pdf -------------------------------------------------------------------------------- /modules/mod3.1.datetime/python.modules3.1.datetime.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod3.1.datetime/python.modules3.1.datetime.pdf -------------------------------------------------------------------------------- /modules/mod6.3.operator/python.modules6.3.operator.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod6.3.operator/python.modules6.3.operator.pdf -------------------------------------------------------------------------------- /modules/mod1.3.decimal/augmented.assignment.py: -------------------------------------------------------------------------------- 1 | # augmented.assigment.py 2 | from decimal import Decimal 3 | D=Decimal 4 | 5 | x=D("0.4") 6 | x**=D("0.1") 7 | print(x) 8 | -------------------------------------------------------------------------------- /modules/mod1.3.decimal/method.py: -------------------------------------------------------------------------------- 1 | from decimal import Decimal 2 | D=Decimal 3 | 4 | x=D(100) 5 | print(x.exp()) 6 | print(x.ln()) 7 | print(x.log10()) 8 | print(x.sqrt()) -------------------------------------------------------------------------------- /modules/mod1.3.decimal/methods.py: -------------------------------------------------------------------------------- 1 | from decimal import Decimal 2 | D=Decimal 3 | 4 | x=D(100) 5 | print(x.exp()) 6 | print(x.ln()) 7 | print(x.log10()) 8 | print(x.sqrt()) -------------------------------------------------------------------------------- /modules/mod1.4.fraction/python.modules1.4.fractions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod1.4.fraction/python.modules1.4.fractions.pdf -------------------------------------------------------------------------------- /modules/mod3.1.datetime/format/strftime.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | d = datetime.now() 4 | print(d.strftime("%A %B %y")) 5 | print(d.strftime("%I.%M.%S %p")) -------------------------------------------------------------------------------- /modules/mod6.1.itertools/python.modules6.1.itertools.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod6.1.itertools/python.modules6.1.itertools.pdf -------------------------------------------------------------------------------- /modules/mod6.2.functools/python.modules6.2.functools.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod6.2.functools/python.modules6.2.functools.pdf -------------------------------------------------------------------------------- /advanced/advanced03.generators/generator.py: -------------------------------------------------------------------------------- 1 | def f(): 2 | yield 1 3 | yield 2 4 | yield 3 5 | 6 | it = f() 7 | for _ in range(3): 8 | print(next(it)) 9 | -------------------------------------------------------------------------------- /advanced/advanced03.generators/sample.csv: -------------------------------------------------------------------------------- 1 | 1,A,100 2 | 2,B,90 3 | 3,A,80 4 | 4,B,70 5 | 5,A,60 6 | 6,B,50 7 | 7,A,40 8 | 8,B,30 9 | 9,A,20 10 | 10,B,10 11 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/python.pac01.mysql.lesson01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/packages/01.MySQL/lesson01/python.pac01.mysql.lesson01.pdf -------------------------------------------------------------------------------- /advanced/advanced02.iterators/python.advanced02.iterator.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/advanced/advanced02.iterators/python.advanced02.iterator.pdf -------------------------------------------------------------------------------- /modules/mod2.2.collections/python.modules2.2.collections.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod2.2.collections/python.modules2.2.collections.pdf -------------------------------------------------------------------------------- /modules/mod8.3.string/format_spec.py: -------------------------------------------------------------------------------- 1 | print("|{:3}|".format(1)) 2 | print("|{:6.2}|".format(1.1234)) 3 | print("|{:>10.2}|".format(1.1234)) 4 | print("|{:_^6.3}|".format(1.1234)) 5 | -------------------------------------------------------------------------------- /advanced/advanced03.generators/python.advanced03.generators.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/advanced/advanced03.generators/python.advanced03.generators.pdf -------------------------------------------------------------------------------- /advanced/advanced06.lambda/python.advanced06.lambda.functional.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/advanced/advanced06.lambda/python.advanced06.lambda.functional.pdf -------------------------------------------------------------------------------- /modules/mod1.3.decimal/with.py: -------------------------------------------------------------------------------- 1 | from decimal import Decimal, localcontext 2 | D=Decimal 3 | 4 | with localcontext() as ctx: 5 | ctx.prec = 500 6 | res = D(10) / D(3) 7 | print(res) -------------------------------------------------------------------------------- /advanced/advanced06.lambda/exercise01.py: -------------------------------------------------------------------------------- 1 | print([x for x in ["aba","anna","baba","aa","baa"] if x == x[::-1]]) 2 | 3 | print(list(filter(lambda x: x==x[::-1], ["aba","anna","baba","aa","baa"]))) 4 | -------------------------------------------------------------------------------- /advanced/advanced06.lambda/map_examples.py: -------------------------------------------------------------------------------- 1 | def square(x): 2 | return x*x 3 | 4 | print(list(map(square, [1,2,3]))) 5 | 6 | # with lambda: 7 | 8 | print(list(map(lambda x: x*x*x, [1,2,3]))) -------------------------------------------------------------------------------- /modules/mod6.3.operator/sort_by_indices.py: -------------------------------------------------------------------------------- 1 | from operator import itemgetter 2 | 3 | A = [(1,19,29), (5, 14, 24), (9, 11, 27)] 4 | 5 | for i in range(3): 6 | print(sorted(A, key=itemgetter(i))) -------------------------------------------------------------------------------- /modules/mod8.3.string/template_init.py: -------------------------------------------------------------------------------- 1 | from string import Template 2 | 3 | template1 = Template("$name lives in $place") 4 | template2 = Template("$name makes $salary $$") # $$ escapes $ 5 | 6 | -------------------------------------------------------------------------------- /modules/mod2.2.collections/named_tuple/construct.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | 3 | Point = namedtuple("Point", "x y") 4 | 5 | p = Point(1.4, 2.8) 6 | print(p[0], p[1]) 7 | print(p.x, p.y) -------------------------------------------------------------------------------- /modules/mod1.3.decimal/operators.py: -------------------------------------------------------------------------------- 1 | from decimal import Decimal 2 | D=Decimal 3 | 4 | x=D("2.2") 5 | y=D("1.1") 6 | print(x+y) 7 | print(x-y) 8 | print(x*y) 9 | print(x/y) 10 | print(x%y) 11 | print(x//y) -------------------------------------------------------------------------------- /modules/mod2.2.collections/doubleEndedQueue/__pycache__/queue.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod2.2.collections/doubleEndedQueue/__pycache__/queue.cpython-39.pyc -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/python.pac01.mysql.lesson02.crud.blob.date.ext.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/packages/01.MySQL/lesson02/python.pac01.mysql.lesson02.crud.blob.date.ext.pdf -------------------------------------------------------------------------------- /advanced/advanced06.lambda/lambda_definition.py: -------------------------------------------------------------------------------- 1 | addtwo = lambda x: x+2 2 | print(addtwo(5)) 3 | print(addtwo(addtwo(1))) 4 | 5 | # IIFE (Immediately Invoked Function Expression) 6 | y = (lambda x: x*x)(3) 7 | print(y) -------------------------------------------------------------------------------- /modules/mod2.2.collections/named_tuple/query/__pycache__/connect.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod2.2.collections/named_tuple/query/__pycache__/connect.cpython-39.pyc -------------------------------------------------------------------------------- /modules/mod6.1.itertools/accumulate_example.py: -------------------------------------------------------------------------------- 1 | from itertools import accumulate 2 | 3 | numbers = [1,2,3,4,5] 4 | print(list(accumulate(numbers))) 5 | 6 | it = accumulate(numbers, lambda x,y: x*y) 7 | print(list(it)) -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/python.advanced05.decorators.classes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/advanced/advanced05.decorators(classes)/python.advanced05.decorators.classes.pdf -------------------------------------------------------------------------------- /modules/mod3.1.datetime/time/construct_time.py: -------------------------------------------------------------------------------- 1 | from datetime import time 2 | 3 | time1 = time(11, 14, 24) 4 | print(time1) 5 | 6 | time2 = time.fromisoformat('11:14:12') 7 | print(time2.hour, time2.minute, time2.second) -------------------------------------------------------------------------------- /modules/mod3.1.datetime/time/methods.py: -------------------------------------------------------------------------------- 1 | from datetime import time, timedelta 2 | 3 | t1 = time.fromisoformat('11:12:13') 4 | t2 = t1.replace(hour=23, second=11) 5 | print(t1, t2) 6 | print(t1 < t2) 7 | print(t1 > t2) 8 | -------------------------------------------------------------------------------- /modules/mod3.1.datetime/timedelta/diff.py: -------------------------------------------------------------------------------- 1 | from datetime import timedelta 2 | 3 | t1 = timedelta(hours=5) 4 | t2 = timedelta(days=10, hours=25, seconds=100) 5 | print(t1+t2) 6 | print(t1/5, t1/100000) 7 | print(-t2) 8 | -------------------------------------------------------------------------------- /modules/mod4.1.json/json_objects_manip_class/__pycache__/timeclass.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod4.1.json/json_objects_manip_class/__pycache__/timeclass.cpython-39.pyc -------------------------------------------------------------------------------- /modules/mod4.1.json/json_objects_manip_func/__pycache__/timeclass.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod4.1.json/json_objects_manip_func/__pycache__/timeclass.cpython-39.pyc -------------------------------------------------------------------------------- /modules/mod5.1.pickle/pickle_load.py: -------------------------------------------------------------------------------- 1 | from pickle import dumps, loads 2 | 3 | d = [(1,3),{1,2},dumps] 4 | 5 | serialized = dumps(d) 6 | print(serialized) 7 | 8 | deserialized = loads(serialized) 9 | print(deserialized) -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/python.advanced04.decorators.functions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/advanced/advanced04.decorators(functions)/python.advanced04.decorators.functions.pdf -------------------------------------------------------------------------------- /modules/mod1.2.random/exercise01.py: -------------------------------------------------------------------------------- 1 | from random import randrange 2 | 3 | print([randrange(100,200+1) for i in range(10)]) 4 | print([randrange(0,9,2) for i in range(10)]) 5 | print([randrange(102,200+1,3) for i in range(10)]) -------------------------------------------------------------------------------- /modules/mod4.1.json/json_many_objects_same_type/__pycache__/timeclass.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod4.1.json/json_many_objects_same_type/__pycache__/timeclass.cpython-39.pyc -------------------------------------------------------------------------------- /modules/mod1.3.decimal/precision.py: -------------------------------------------------------------------------------- 1 | from decimal import Decimal, getcontext 2 | D=Decimal 3 | 4 | getcontext().prec = 3 5 | a=Decimal("0.4391") 6 | b=Decimal("12.939") 7 | print(a,b,b/a) 8 | 9 | print(getcontext()) 10 | -------------------------------------------------------------------------------- /modules/mod1.3.decimal/quantize.py: -------------------------------------------------------------------------------- 1 | #quantize.py 2 | from decimal import Decimal 3 | D=Decimal 4 | fpacc=Decimal(10) ** -2 5 | 6 | a=Decimal("0.43") 7 | b=Decimal("12.93") 8 | print(a*b) 9 | print((a*b).quantize(fpacc)) 10 | -------------------------------------------------------------------------------- /modules/mod2.4.enum/callable.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | 3 | Days = Enum("Days", "MONDAY TUESDAY WEDNESDAY THURSDAY " + 4 | "FRIDAY SATURDAY SUNDAY") 5 | 6 | for day in Days: 7 | print(day.name, day.value) -------------------------------------------------------------------------------- /modules/mod1.1.math/exercise06.py: -------------------------------------------------------------------------------- 1 | from math import comb 2 | 3 | try: 4 | print(comb(11.1,6)) 5 | except ValueError: 6 | print("Error: Must be non-negative") 7 | except TypeError: 8 | print("Error: Must be an integer") 9 | -------------------------------------------------------------------------------- /advanced/advanced02.iterators/for.implementation.py: -------------------------------------------------------------------------------- 1 | iter_obj = iter([1,2,3]) 2 | while True: 3 | try: 4 | element = next(iter_obj) 5 | #.. do something with element 6 | except StopIteration: 7 | break 8 | -------------------------------------------------------------------------------- /modules/mod1.1.math/trig.py: -------------------------------------------------------------------------------- 1 | from math import pi, sin, cos, tan 2 | 3 | for i in range(4): 4 | v = i*pi/2 5 | print(f"sin({i}*PI/2)={sin(v):.2f}") 6 | print(f"cos({i}*PI/2)={cos(v):.2f}") 7 | print(f"tan({i}*PI/2)={tan(v):.2f}") -------------------------------------------------------------------------------- /modules/mod3.1.datetime/timedelta/operations.py: -------------------------------------------------------------------------------- 1 | from datetime import date, timedelta 2 | 3 | d = date(2021, 12, 31) 4 | t = timedelta(days=10) 5 | print(d+t) 6 | d2 = d-t 7 | print(repr(d2-d)) 8 | print(date.today()+timedelta(days=10000)) 9 | -------------------------------------------------------------------------------- /modules/mod4.1.json/json_many_objects_different_types/__pycache__/timeclass.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/psounis/python_advanced/HEAD/modules/mod4.1.json/json_many_objects_different_types/__pycache__/timeclass.cpython-39.pyc -------------------------------------------------------------------------------- /modules/mod7.1.csv/read_csv.py: -------------------------------------------------------------------------------- 1 | from csv import reader 2 | 3 | with open("countries.csv", "r", encoding="utf-8") as file: 4 | csv_reader = reader(file) 5 | print(type(csv_reader)) 6 | for row in csv_reader: 7 | print(row) -------------------------------------------------------------------------------- /advanced/advanced03.generators/close.py: -------------------------------------------------------------------------------- 1 | def f(): 2 | i=1 3 | while True: 4 | yield i 5 | i+=2 6 | 7 | 8 | it = f() 9 | for i in it: 10 | print(i) 11 | if i==101: 12 | it.close() 13 | -------------------------------------------------------------------------------- /modules/mod4.1.json/json_args/beautify.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | a_person = { 4 | "first_name": "John", 5 | "last_name": "Doe", 6 | "age": 25 7 | } 8 | with open("ob.json", "w") as f: 9 | json.dump(a_person, f, indent=2, sort_keys=True) -------------------------------------------------------------------------------- /modules/mod4.1.json/json_args/json_dumb_args.py: -------------------------------------------------------------------------------- 1 | import decimal 2 | import json 3 | 4 | with open("ob.json", "r") as f: 5 | person = json.load(f, parse_int=decimal.Decimal, 6 | parse_float=decimal.Decimal) 7 | print(person) -------------------------------------------------------------------------------- /advanced/advanced03.generators/throw.py: -------------------------------------------------------------------------------- 1 | def f(): 2 | i=1 3 | while True: 4 | yield i 5 | i+=2 6 | 7 | 8 | it = f() 9 | for i in it: 10 | print(i) 11 | if i==101: 12 | it.throw(Exception) 13 | -------------------------------------------------------------------------------- /advanced/advanced06.lambda/filter_examples.py: -------------------------------------------------------------------------------- 1 | def is_odd(x): 2 | return x%2 == 1 3 | 4 | print(list(filter(is_odd, [1,2,3,4,5]))) 5 | print(filter(is_odd, [1,2,3,4,5])) 6 | 7 | # with lambda: 8 | 9 | print(list(filter(lambda x: x%2==0, [1,2,3,4,5]))) -------------------------------------------------------------------------------- /advanced/advanced06.lambda/map_examples3.py: -------------------------------------------------------------------------------- 1 | print(list(map(lambda x: x*x*x, [1,2,3]))) 2 | print([x*x*x for x in [1,2,3]]) 3 | 4 | A=[1,2,3] 5 | B=[4,5,6] 6 | print(list(map(lambda x,y: x+y, [1,2,3], [4,5,6]))) 7 | print([A[i]+B[i] for i in range(len(A))]) -------------------------------------------------------------------------------- /modules/mod3.1.datetime/date/methods.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | 3 | d = date(1990,11,1) 4 | print(d.isoformat(), d) 5 | 6 | d2 = d.replace(day=12) 7 | print(d2) 8 | print(f"Weekday: {d2.weekday()}") 9 | 10 | print(d < d2) 11 | print(d > d2) -------------------------------------------------------------------------------- /modules/mod6.2.functools/partial.py: -------------------------------------------------------------------------------- 1 | from functools import partial 2 | 3 | 4 | def power_func(x, y, a=1, b=0): 5 | return a*x**y + b 6 | 7 | 8 | new_func = partial(power_func, 2, a=4) 9 | 10 | print(new_func(4, b=1)) 11 | print(new_func(1)) 12 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/scripts/create_table_images.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS images; 2 | 3 | CREATE TABLE images ( 4 | image_id INT PRIMARY KEY AUTO_INCREMENT, 5 | image BLOB, 6 | descr VARCHAR(100) 7 | ); 8 | 9 | select * from images; 10 | -------------------------------------------------------------------------------- /modules/mod1.3.decimal/logical.py: -------------------------------------------------------------------------------- 1 | from decimal import Decimal, getcontext 2 | D=Decimal 3 | 4 | x=D(1) 5 | y=D(110) 6 | 7 | print(x.logical_and(y)) 8 | print(x.logical_or(y)) 9 | print(x.logical_xor(y)) 10 | getcontext().prec=8 11 | print(x.logical_invert()) -------------------------------------------------------------------------------- /modules/mod2.4.enum/unique_values.py: -------------------------------------------------------------------------------- 1 | from enum import Enum, unique 2 | 3 | @unique 4 | class Days(Enum): 5 | MONDAY = 1 6 | TUESDAY = 2 7 | WEDNESDAY = 3 8 | THURSDAY = 4 9 | FRIDAY = 5 10 | SATURDAY = 1 11 | SUNDAY = 7 12 | 13 | -------------------------------------------------------------------------------- /modules/mod2.2.collections/named_tuple/methods.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | 3 | Point = namedtuple("Point", "x y") 4 | 5 | p = Point(1.1, 2.8) 6 | print(p._make([1, 1])) 7 | print(p._asdict()) 8 | print(p._replace(x=3.3)) 9 | print(p._fields) 10 | -------------------------------------------------------------------------------- /advanced/advanced06.lambda/closure.py: -------------------------------------------------------------------------------- 1 | def f(x): 2 | return lambda y: x ** y 3 | 4 | 5 | g = f(2) 6 | 7 | print(g(10)) 8 | print(g.__closure__) 9 | print(g.__code__.co_freevars) 10 | for item in g.__closure__: 11 | print(item.cell_contents) 12 | 13 | 14 | -------------------------------------------------------------------------------- /modules/mod8.2.re(b)/splitting.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = "Computer Science is no more about computers, " + \ 4 | "than astronomy is about telescope." 5 | 6 | print(re.split(r" ", text)) 7 | print(re.split(r"\W? \W?", text)) 8 | print(re.split(r"\W? +\W?|\W", text)) -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/property_getter.py: -------------------------------------------------------------------------------- 1 | class Salary: 2 | def __init__(self, amount): 3 | self._amount = amount 4 | 5 | @property 6 | def amount(self): 7 | return self._amount 8 | 9 | 10 | s = Salary(500) 11 | print(s.amount) -------------------------------------------------------------------------------- /modules/mod1.2.random/exercise05.py: -------------------------------------------------------------------------------- 1 | from random import getrandbits 2 | 3 | x = getrandbits(8) 4 | 5 | print(f"x={x}=",end="") 6 | bits=[] 7 | for i in range(8): 8 | bits = [x%2] + bits 9 | x = x//2 10 | 11 | for i in range(8): 12 | print(bits[i], end="") 13 | -------------------------------------------------------------------------------- /advanced/advanced02.iterators/iterator.list.dict.py: -------------------------------------------------------------------------------- 1 | my_list = [1,2,3,4] 2 | it = iter(my_list) 3 | print(next(it)) 4 | print(next(it)) 5 | print(next(it)) 6 | 7 | my_dict = {"a":1, "b":2 } 8 | it = iter(my_dict) 9 | print(next(it)) 10 | print(next(it)) 11 | print(next(it)) -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/groups2.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | text = "Computer Science is no more about computers " + \ 5 | "than astronomy is about telescope" 6 | 7 | m = re.match(r".* (?P\w+?) is (?P\w+?) .*", text) 8 | print(m["previous"], m["next"]) 9 | 10 | -------------------------------------------------------------------------------- /advanced/advanced06.lambda/closure2.py: -------------------------------------------------------------------------------- 1 | l = [] 2 | for i in range(3): 3 | l.append(lambda: i) 4 | 5 | for it in l: 6 | print(it()) 7 | 8 | 9 | # solution: 10 | 11 | l = [] 12 | for i in range(3): 13 | l.append(lambda n=i: n) 14 | 15 | for it in l: 16 | print(it()) 17 | -------------------------------------------------------------------------------- /advanced/advanced06.lambda/reduce_examples.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | 3 | # sum 4 | print(reduce(lambda x, y: x+y, [1,2,3,4])) 5 | 6 | # max 7 | print(reduce(lambda x, y: x if x>y else y, [1,2,3,4])) 8 | 9 | # sum of squares 10 | print(reduce(lambda x, y: x + y*y, [1,2,3,4], 0)) -------------------------------------------------------------------------------- /modules/mod2.5.bisect/key_sorted_problem.py: -------------------------------------------------------------------------------- 1 | from random import randrange 2 | from bisect import insort 3 | 4 | numbers = [randrange(100) for _ in range(20)] 5 | print(numbers) 6 | 7 | numbers.sort(key=lambda x: x//10+x%10) 8 | print(numbers) 9 | 10 | insort(numbers, 45) 11 | print(numbers) -------------------------------------------------------------------------------- /modules/mod2.6.array/array_init.py: -------------------------------------------------------------------------------- 1 | from array import array 2 | 3 | a = array('i', [1, 2, 3]) 4 | a.fromlist([4,5,6]) 5 | print(a) 6 | 7 | a = array('d', [1, 2, 3]) 8 | a.fromlist([4,5,6]) 9 | print(a) 10 | 11 | # deprecated 12 | a = array('u', "abc") 13 | a.fromunicode("αβγ") 14 | print(a) -------------------------------------------------------------------------------- /modules/mod4.1.json/json_args/read.py: -------------------------------------------------------------------------------- 1 | import decimal 2 | import json 3 | 4 | with open("ob.json", "w") as f: 5 | json.dump([1,2,3,4.0,5.0], f, indent=2) 6 | 7 | with open("ob.json", "r") as f: 8 | x = json.load(f, parse_int=decimal.Decimal, 9 | parse_float=decimal.Decimal) -------------------------------------------------------------------------------- /modules/mod2.5.bisect/bisect_example.py: -------------------------------------------------------------------------------- 1 | from random import randrange 2 | from bisect import bisect 3 | 4 | numbers = [0] 5 | for i in range(1, 30): 6 | numbers.append(numbers[i-1] + randrange(2)) 7 | print(numbers) 8 | 9 | 10 | print(bisect(numbers, 10)) 11 | print(bisect(numbers, 10, 5, 10)) -------------------------------------------------------------------------------- /modules/mod6.1.itertools/starmap_example.py: -------------------------------------------------------------------------------- 1 | from itertools import starmap, product 2 | 3 | def func(a,b,c,d): 4 | return abs(a-b)+abs(b-c)+abs(c-d) 5 | print(list(product([1,2,3],[1,2,4],[3,5,2],[4,1,2]))) 6 | iterator = starmap(func, product([1,2,3],[1,2,4],[3,5,2],[4,1,2])) 7 | print(min(iterator)) -------------------------------------------------------------------------------- /advanced/advanced03.generators/generator2.py: -------------------------------------------------------------------------------- 1 | def f(): 2 | for i in range(10): 3 | yield i 4 | 5 | 6 | it = f() 7 | for i in it: 8 | print(i) 9 | 10 | it = f() 11 | while True: 12 | try: 13 | print(next(it)) 14 | except StopIteration: 15 | break -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/factory.power.py: -------------------------------------------------------------------------------- 1 | def factory_power(power): 2 | def nth_power(number): 3 | return number ** power 4 | 5 | return nth_power 6 | 7 | square = factory_power(2) 8 | print(square(4)) 9 | 10 | cube = factory_power(3) 11 | print(cube(4)) 12 | -------------------------------------------------------------------------------- /modules/mod3.1.datetime/date/construct_date.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | 3 | date1 = date(2021, 11, 21) 4 | print(date1) 5 | 6 | date2 = date.today() 7 | print(date2) 8 | print(f"{date2.day}/{date2.month}/{date2.year}") 9 | 10 | date3 = date.fromisoformat('2021-11-21') 11 | print(date3) 12 | 13 | -------------------------------------------------------------------------------- /modules/mod3.1.datetime/datetime/datetime_ops.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime, timedelta 2 | 3 | d = datetime(2021, 11, 1, 13, 11, 39) 4 | print(d.isoformat(sep=" ")) 5 | print(d, d + timedelta(hours=48)) 6 | print(d.replace(hour=23)) 7 | 8 | print(d < datetime(2022, 1, 1)) 9 | print(d == datetime(2021, 11, 1)) -------------------------------------------------------------------------------- /modules/mod6.2.functools/cache2.py: -------------------------------------------------------------------------------- 1 | from functools import cache 2 | 3 | 4 | @cache 5 | def fib(n): 6 | if n==0 or n==1: 7 | return 1 8 | else: 9 | return fib(n-1)+fib(n-2) 10 | 11 | 12 | print(fib(100)) 13 | print(fib.cache_info()) # cache stats 14 | fib.cache_clear() # clears cache -------------------------------------------------------------------------------- /advanced/advanced06.lambda/filter_examples2.py: -------------------------------------------------------------------------------- 1 | def is_even(x): 2 | return x%2 == 0 3 | 4 | my_list = [1,2,3,4,5] 5 | print(list(filter(is_even, my_list))) 6 | print([x for x in my_list if x%2==0]) 7 | print([x for x in my_list if is_even(x)]) 8 | print([x for x in my_list if (lambda x: x%2==0)(x)]) 9 | 10 | -------------------------------------------------------------------------------- /modules/mod2.5.bisect/insert_keep_sorted.py: -------------------------------------------------------------------------------- 1 | from random import randrange 2 | from bisect import insort 3 | 4 | numbers = [0] 5 | for i in range(1, 30): 6 | numbers.append(numbers[i-1] + randrange(2)) 7 | print(numbers) 8 | 9 | insort(numbers, 5) 10 | print(numbers) 11 | insort(numbers, 7) 12 | print(numbers) -------------------------------------------------------------------------------- /modules/mod1.3.decimal/relational.operators.py: -------------------------------------------------------------------------------- 1 | # relational.operators.py 2 | from decimal import Decimal 3 | D=Decimal 4 | 5 | print(D("12.0") == D("12")) 6 | print(D("3.0") != D("3.000")) 7 | print(D("1.1") < D("1.11")) 8 | print(D("1.1") <= D("1.11")) 9 | print(D("1.1") > D("1.11")) 10 | print(D("1.1") >= D("1.11")) -------------------------------------------------------------------------------- /modules/mod2.4.enum/int_flag_enum.py: -------------------------------------------------------------------------------- 1 | from enum import IntFlag 2 | 3 | 4 | class Perm(IntFlag): 5 | READ = 1 6 | WRITE = 2 7 | EXECUTE = 4 8 | 9 | RW = Perm.READ | Perm.WRITE 10 | print(Perm.READ in RW) 11 | 12 | RWX = RW | Perm.EXECUTE 13 | print(RWX) 14 | 15 | RX = RWX & ~ Perm.WRITE 16 | print(RX) -------------------------------------------------------------------------------- /modules/mod2.2.collections/counter/counter_init.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | l = [1, 2, 3, 2] 4 | cl = Counter(l) 5 | print(cl) 6 | 7 | phrase = "Winter is coming" 8 | cphrase = Counter(phrase) 9 | print(cphrase, cphrase["i"]) 10 | 11 | t = [[1, 2], [1]] 12 | ct = Counter(t) # error: elems=>unhashable 13 | -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/groups.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | text = "Computer Science is no more about computers " + \ 5 | "than astronomy is about telescope" 6 | 7 | m = re.match(r".* (\w+?) is (\w+?) .*", text) 8 | print(m.group(0) + "|" + m.group(1) + "|" + m.group(2)) 9 | print(m[0] + "|" + m[1] + "|" + m[2]) 10 | -------------------------------------------------------------------------------- /modules/mod6.2.functools/caching.py: -------------------------------------------------------------------------------- 1 | from functools import lru_cache 2 | 3 | 4 | @lru_cache(maxsize=3) 5 | def fib(n): 6 | if n==0 or n==1: 7 | return 1 8 | else: 9 | return fib(n-1)+fib(n-2) 10 | 11 | 12 | print(fib(100)) 13 | print(fib.cache_info()) # cache stats 14 | fib.cache_clear() # clears cache -------------------------------------------------------------------------------- /advanced/advanced03.generators/opc.csv.py: -------------------------------------------------------------------------------- 1 | # source: https://www.dataquest.io/blog/python-generators-tutorial/ 2 | data = "sample.csv" 3 | lines = (line for line in open(data, encoding="ISO-8859-1")) 4 | for line in lines: 5 | cells = line.split(",") 6 | for c in cells: 7 | print(c.strip(), end="\t") 8 | print("") -------------------------------------------------------------------------------- /modules/mod2.4.enum/flag_enum.py: -------------------------------------------------------------------------------- 1 | # official docs example: https://docs.python.org/3/library/enum.html 2 | from enum import Flag, auto 3 | 4 | 5 | class Color(Flag): 6 | RED = auto() 7 | BLUE = auto() 8 | GREEN = auto() 9 | WHITE = RED|GREEN|BLUE 10 | 11 | 12 | for item in Color: 13 | print(item, item.value) -------------------------------------------------------------------------------- /modules/mod7.1.csv/read_csv_dictionary.py: -------------------------------------------------------------------------------- 1 | from csv import DictReader 2 | 3 | with open("countries.csv", "r", encoding="utf-8") as file: 4 | csv_reader = DictReader(file) 5 | data = list(csv_reader) 6 | print(data) 7 | 8 | print("="*25) 9 | row = data[0] 10 | print(row) 11 | print(row["Name"], row["Continent"]) 12 | -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/boundary.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | with open("pies.html", encoding="utf-8") as f: 4 | text = f.read() 5 | print(text) 6 | 7 | 8 | res = re.findall(r"^\s*?<(.+?)>", text, re.MULTILINE) 9 | print(res) 10 | 11 | res2 = re.findall(r"^\s*?<(.+?)>.*<(/.+?)>$", text, re.MULTILINE) 12 | print(res2) 13 | 14 | -------------------------------------------------------------------------------- /modules/mod8.3.string/str.format.py: -------------------------------------------------------------------------------- 1 | print("int value: {} {}".format(1, 5+1)) 2 | print("int width(right align): {:>10d} ".format(1)) 3 | print("int width(left align): {:<10d} ".format(1)) 4 | print("float: {}".format(1/3)) 5 | print("float: decimals: {:.4f} {:.2f}".format(1/3, 1/8)) 6 | print("string: {}".format("Hello there! ")) 7 | 8 | -------------------------------------------------------------------------------- /modules/mod2.4.enum/auto_values.py: -------------------------------------------------------------------------------- 1 | from enum import Enum, auto 2 | 3 | class Days(Enum): 4 | MONDAY = auto() 5 | TUESDAY = auto() 6 | WEDNESDAY = auto() 7 | THURSDAY = auto() 8 | FRIDAY = auto() 9 | SATURDAY = auto() 10 | SUNDAY = auto() 11 | 12 | 13 | for day in Days: 14 | print(day.name, day.value) -------------------------------------------------------------------------------- /modules/mod1.3.decimal/constructor.py: -------------------------------------------------------------------------------- 1 | from decimal import Decimal 2 | 3 | D = Decimal 4 | 5 | print(D(1)) 6 | print(D('3.14')) 7 | print(D(3.14)) 8 | print(D('3.1400000000000001243449787580175325274467468261718751123123')) 9 | print(D((1,(1,4,1,5),-1))) 10 | print(D("NaN")) 11 | print(D("infinity")) 12 | print(D("-infinity")) 13 | 14 | -------------------------------------------------------------------------------- /modules/mod2.6.array/as_list.py: -------------------------------------------------------------------------------- 1 | from array import array 2 | from random import randrange 3 | 4 | arr = array('i', (randrange(100) for _ in range(10))) 5 | 6 | print(arr) 7 | arr.append(12) 8 | print(arr) 9 | arr.remove(12) 10 | print(arr) 11 | elem = arr.pop() 12 | print(elem, arr) 13 | # arr.clear() doesn't work 14 | print(arr) 15 | 16 | -------------------------------------------------------------------------------- /advanced/advanced02.iterators/iterator.py: -------------------------------------------------------------------------------- 1 | class MyIterator: 2 | def __iter__(self): 3 | self.n = 0 4 | return self 5 | 6 | def __next__(self): 7 | self.n += 1 8 | return self.n 9 | 10 | 11 | obj = MyIterator() 12 | it = iter(obj) 13 | print(next(it)) 14 | print(next(it)) 15 | print(next(it)) -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/decorator.syntax.py: -------------------------------------------------------------------------------- 1 | def decorate_with_lines(func): 2 | def dec(): 3 | print("=" * 20) 4 | func() 5 | print("=" * 20) 6 | 7 | return dec 8 | 9 | @decorate_with_lines 10 | def some_func(): 11 | print("I did many things.. ") 12 | 13 | 14 | some_func() 15 | -------------------------------------------------------------------------------- /modules/mod6.1.itertools/split.py: -------------------------------------------------------------------------------- 1 | from itertools import tee, islice 2 | 3 | iterator = (i for i in range(20)) 4 | 5 | it1, it2, it3, it4, it5, it6 = tee(iterator, 6) 6 | print(list(it1)) 7 | print(list(it2)) 8 | print(list(it3)) 9 | 10 | print(list(islice(it4, 10))) 11 | print(list(islice(it5, 5, 10))) 12 | print(list(islice(it6, 5, 10, 2))) -------------------------------------------------------------------------------- /modules/mod8.3.string/format_spec2.py: -------------------------------------------------------------------------------- 1 | print("|{:b}|".format(4)) 2 | print("|{:x}|".format(1000)) 3 | print("|{:<6.2f}|".format(1)) 4 | print("|{:>-10_.4f}|".format(5432.12)) 5 | print("|{:.2%}|".format(.3015)) 6 | print("|{1:_^-100_.2f}|{0}|".format(1000.1234, 2000.2468)) 7 | 8 | d = {"a": 5, "b": 10.123} 9 | print("|{d[a]:_^-100_.2f}|{d[b]}|".format(d=d)) -------------------------------------------------------------------------------- /modules/mod4.1.json/json_objects_manip_class/main.py: -------------------------------------------------------------------------------- 1 | from timeclass import Time, TimeEncoder, TimeDecoder 2 | import json 3 | 4 | t = Time(10, 22, 24) 5 | print(t) 6 | 7 | with open("ob.json", "w") as f: 8 | json.dump(t, f, cls=TimeEncoder) 9 | 10 | with open("ob.json", "r") as f: 11 | t2 = json.load(f, cls=TimeDecoder) 12 | print(t2) -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/PatternMatcher.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def matches(text, regexp): 5 | pattern = re.compile(regexp) 6 | matcher = pattern.fullmatch(text) 7 | if matcher is None: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | print(matches("abba", r"abba")) 14 | print(matches("abba", r"baba")) 15 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/stored_proc/main.py: -------------------------------------------------------------------------------- 1 | from dbtools import * 2 | 3 | connector = open_connection() 4 | 5 | try: 6 | results = call_stored(connector, 'country_cities', ['Greece']) 7 | 8 | for result in results: 9 | print(result) 10 | 11 | except MYSQL.Error as e: 12 | print(e) 13 | 14 | close_connection(connector) 15 | -------------------------------------------------------------------------------- /modules/mod2.2.collections/chain_map/constructor.py: -------------------------------------------------------------------------------- 1 | from collections import ChainMap 2 | 3 | dict1 = {"a": 1, "b": 2} 4 | dict2 = {"c": 3, "d": 4} 5 | dict3 = {"e": 5, "a": 6} 6 | 7 | cm = ChainMap(dict1, dict2, dict3) 8 | print(cm) 9 | 10 | print(cm["b"]) 11 | print(cm["a"]) 12 | 13 | pylookup = ChainMap(locals(), globals()) 14 | print(pylookup) 15 | -------------------------------------------------------------------------------- /modules/mod6.1.itertools/merging.py: -------------------------------------------------------------------------------- 1 | from itertools import chain, zip_longest 2 | 3 | a = (i for i in range(10)) 4 | b = (i for i in range(10,15)) 5 | c = (i for i in range(20,25)) 6 | for i in chain(a,b,c): 7 | print(i, end=" ") 8 | 9 | print() 10 | print(list(zip([1,2,3],[3,4],[5]))) 11 | print(list(zip_longest([1,2,3],[3,4],[5], fillvalue=0))) 12 | -------------------------------------------------------------------------------- /modules/mod6.1.itertools/produce_values.py: -------------------------------------------------------------------------------- 1 | from itertools import count, cycle, repeat 2 | 3 | it = (val for val in count(10,2)) 4 | print(next(it), next(it)) 5 | 6 | print("="*20) 7 | it = (val for val in cycle([1,2,3,4])) 8 | for i in range(10): 9 | print(next(it)) 10 | 11 | print("="*20) 12 | for i in repeat(10,3): 13 | print(i, end=" ") 14 | -------------------------------------------------------------------------------- /modules/mod7.1.csv/dialect.py: -------------------------------------------------------------------------------- 1 | from csv import reader, writer 2 | 3 | with open("excel.csv", "r") as file: 4 | csv_reader = reader(file, delimiter=";") 5 | dialect = csv_reader.dialect 6 | print("delimiter: " + dialect.delimiter) 7 | print("quotechar: " + dialect.quotechar) 8 | print("lineterminator: " + dialect.lineterminator) 9 | 10 | -------------------------------------------------------------------------------- /advanced/advanced02.iterators/exercise01.py: -------------------------------------------------------------------------------- 1 | class MyIterator: 2 | def __iter__(self): 3 | self.n = -1 4 | return self 5 | 6 | def __next__(self): 7 | self.n += 2 8 | if self.n<=100: 9 | return self.n 10 | else: 11 | raise StopIteration 12 | 13 | 14 | print(sum(MyIterator())) -------------------------------------------------------------------------------- /modules/mod1.2.random/choices.py: -------------------------------------------------------------------------------- 1 | from random import choice, choices 2 | 3 | my_list = list(range(5)) 4 | 5 | print(f"Random choice: {choice(my_list)}") 6 | print(f"3 Random choices: {choices(my_list, k=3)}") 7 | print(f"5 Weighted choices: {choices(my_list, [1,100,10,1,1], k=10)}") 8 | print(f"5 Cum.W. choices: {choices(my_list, cum_weights=[1,101,111,112,113], k=10)}") -------------------------------------------------------------------------------- /modules/mod2.2.collections/dict_variations/ordered_dict.py: -------------------------------------------------------------------------------- 1 | from collections import OrderedDict 2 | 3 | d = OrderedDict() 4 | 5 | d[1] = 11 6 | d[2] = 12 7 | d[3] = 13 8 | d[0] = 10 9 | 10 | for k,v in d.items(): 11 | print(f"{k}: {d[k]}") 12 | 13 | print(d.popitem()) 14 | 15 | print("="*25) 16 | for k,v in d.items(): 17 | print(f"{k}: {d[k]}") 18 | -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/boundary_word.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | with open("pies.html", encoding="utf-8") as f: 4 | text = f.read() 5 | print(text) 6 | 7 | 8 | res = re.findall(r"\bπίτες\b", text) 9 | print(res) 10 | 11 | res2 = re.findall(r"(\b\w*?)\Bπιτες\b", text) 12 | print(res2) 13 | 14 | res3 = re.findall(r"\ba.*?\b", text) 15 | print(res3) 16 | 17 | -------------------------------------------------------------------------------- /modules/mod4.1.json/json_objects_manip_func/main.py: -------------------------------------------------------------------------------- 1 | from timeclass import Time, time_encoder, time_decoder 2 | import json 3 | 4 | t1 = Time(10, 22, 24) 5 | print(t1) 6 | 7 | with open("ob.json", "w") as f: 8 | json.dump(t1, f, default=time_encoder) 9 | 10 | with open("ob.json", "r") as f: 11 | t2 = json.load(f, object_hook=time_decoder) 12 | print(t2) -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/exercise04/main.py: -------------------------------------------------------------------------------- 1 | from dbtools import * 2 | 3 | connector = open_connection() 4 | 5 | 6 | iter_query = query_iter_one(connector, "SELECT * FROM country") 7 | 8 | for item in iter_query: 9 | print(f"{item['Name']}({item['Continent']}). Next? Press Enter...", end="") 10 | input() 11 | 12 | 13 | close_connection(connector) 14 | -------------------------------------------------------------------------------- /modules/mod2.4.enum/int_enum.py: -------------------------------------------------------------------------------- 1 | from enum import IntEnum 2 | 3 | 4 | class Days(IntEnum): 5 | MONDAY = 1 6 | TUESDAY = 2 7 | WEDNESDAY = 3 8 | THURSDAY = 4 9 | FRIDAY = 5 10 | SATURDAY = 6 11 | SUNDAY = 7 12 | 13 | week_jobs = ["some", "more work", "much more work"] 14 | 15 | print(week_jobs[Days.MONDAY]) 16 | print(week_jobs[Days.TUESDAY]) -------------------------------------------------------------------------------- /modules/mod7.1.csv/delimiter.py: -------------------------------------------------------------------------------- 1 | from csv import reader, writer 2 | 3 | with open("excel.csv", "r") as file: 4 | csv_reader = reader(file, delimiter=";") 5 | data = list(csv_reader) 6 | 7 | with open("excel_new.csv", "w", newline="") as file: 8 | csv_writer = writer(file, delimiter=",") 9 | for row in data: 10 | csv_writer.writerow(row) 11 | 12 | -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/decorator.arbitrary.args.py: -------------------------------------------------------------------------------- 1 | def decorate_with_lines(func): 2 | def dec(*args, **kwargs): 3 | print("=" * 20) 4 | func(*args, **kwargs) 5 | print("=" * 20) 6 | 7 | return dec 8 | 9 | 10 | @decorate_with_lines 11 | def some_func(a,b): 12 | print(a*b) 13 | 14 | some_func(5,10) 15 | -------------------------------------------------------------------------------- /modules/mod2.2.collections/dict_variations/ordered_dict_fifo.py: -------------------------------------------------------------------------------- 1 | from collections import OrderedDict 2 | 3 | d = OrderedDict() 4 | 5 | d[1] = 11 6 | d[2] = 12 7 | d[3] = 13 8 | d[0] = 10 9 | 10 | for k,v in d.items(): 11 | print(f"{k}: {d[k]}") 12 | 13 | print(d.popitem(last=False)) 14 | 15 | print("="*25) 16 | for k,v in d.items(): 17 | print(f"{k}: {d[k]}") 18 | -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/decorator.py: -------------------------------------------------------------------------------- 1 | def decorate_with_lines(func): 2 | def dec(): 3 | print("=" * 20) 4 | func() 5 | print("=" * 20) 6 | 7 | return dec 8 | 9 | def some_func(): 10 | print("I did many things.. ") 11 | 12 | 13 | decorated_func = decorate_with_lines(some_func) 14 | 15 | decorated_func() 16 | -------------------------------------------------------------------------------- /modules/mod3.1.datetime/format/locale_info.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | import locale 3 | 4 | for loc in ['greek', 'french', 'german', 'italian']: 5 | print("Language: " + loc) 6 | locale.setlocale(locale.LC_TIME, loc) 7 | d=datetime.now() 8 | for i in range(1,8): 9 | print(d.replace(day=i).__format__(f"%A %d %B %Y")) 10 | print("="*10) 11 | -------------------------------------------------------------------------------- /modules/mod8.2.re(b)/subn.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = "Men occasionally stumble over the truth, but most of them " \ 4 | "pick themselves up and hurry off as if nothing had happened." 5 | 6 | 7 | def replace(match_object): 8 | length = len(match_object.group(0)) 9 | return "-" * length 10 | 11 | 12 | res = re.subn(r"the\w*", replace, text) 13 | print(res) 14 | -------------------------------------------------------------------------------- /modules/mod6.3.operator/operators.py: -------------------------------------------------------------------------------- 1 | from operator import add 2 | from functools import reduce 3 | from random import randrange 4 | 5 | my_list = [randrange(10) for _ in range(10)] 6 | print(my_list) 7 | 8 | 9 | def my_add(a, b): 10 | return a+b 11 | 12 | 13 | print(reduce(my_add, my_list, 0)) 14 | print(reduce(add, my_list, 0)) 15 | print(reduce(lambda x, y: x+y, my_list, 0)) -------------------------------------------------------------------------------- /modules/mod2.4.enum/simple_enum.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | 3 | 4 | class Days(Enum): 5 | MONDAY = 1 6 | TUESDAY = 2 7 | WEDNESDAY = 3 8 | THURSDAY = 4 9 | FRIDAY = 5 10 | SATURDAY = 6 11 | SUNDAY = 7 12 | 13 | 14 | today = Days.MONDAY 15 | print(today) 16 | print(today.name) 17 | print(today.value) 18 | print(type(today)) 19 | print(isinstance(today, Days)) -------------------------------------------------------------------------------- /modules/mod8.2.re(b)/match_fullmatch.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = "Computer Science is no more about computers " + \ 4 | "than astronomy is about telescope" 5 | 6 | print(re.match(r"Comp.", text)) 7 | print(re.match(r"Sci.", text)) 8 | print(re.compile(r"Sci.").match(text, 9)) 9 | 10 | print(re.fullmatch(r"Comp.*", text)) 11 | print(re.compile(r"Sci\w+").fullmatch(text, 9, 14)) 12 | -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/closure.py: -------------------------------------------------------------------------------- 1 | def factory_power(power): 2 | def nth_power(number): 3 | return number ** power 4 | 5 | return nth_power 6 | 7 | square = factory_power(2) 8 | print(square(4)) 9 | print(square.__closure__[0].cell_contents) 10 | 11 | cube = factory_power(3) 12 | print(cube(4)) 13 | print(cube.__closure__[0].cell_contents) 14 | -------------------------------------------------------------------------------- /modules/mod2.7.graphlib/calculate_ts.py: -------------------------------------------------------------------------------- 1 | from graphlib import TopologicalSorter 2 | 3 | graph = { 4 | "v1": {}, 5 | "v2": {"v1"}, 6 | "v3": {"v1", "v2"}, 7 | "v4": {"v3"}, 8 | "v5": {"v3"}, 9 | "v6": {"v2", "v4", "v5"}, 10 | "v7": {"v5", "v6"} 11 | } 12 | 13 | sorter = TopologicalSorter(graph) 14 | order = sorter.static_order() 15 | print(list(order)) 16 | 17 | 18 | -------------------------------------------------------------------------------- /modules/mod6.2.functools/cache3.py: -------------------------------------------------------------------------------- 1 | from functools import cached_property 2 | 3 | 4 | class Calcs: 5 | def __init__(self): 6 | self._val = 0 7 | 8 | @cached_property 9 | def val(self): 10 | print("some tedious calc...") 11 | self._val = 100 12 | return self._val 13 | 14 | 15 | calcs = Calcs() 16 | print(calcs.val) 17 | print(calcs.val) 18 | 19 | -------------------------------------------------------------------------------- /modules/mod8.3.string/template_substitute.py: -------------------------------------------------------------------------------- 1 | from string import Template 2 | 3 | template1 = Template("$name lives in $place") 4 | 5 | sub11 = template1.substitute({"name": "Bob", "place": "Athens"}) 6 | print(sub11) 7 | sub12 = template1.substitute(name="Bob", place="Athens") 8 | print(sub12) 9 | sub13 = template1.substitute({"name": "Bob"}, place="Athens") 10 | print(sub13) 11 | 12 | 13 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/scripts/dates.sql: -------------------------------------------------------------------------------- 1 | use pyworld; 2 | 3 | DROP TABLE IF EXISTS dates; 4 | 5 | CREATE TABLE dates ( 6 | vdate DATE, 7 | vtime TIME, 8 | vdatetime DATETIME, 9 | vtimestamp TIMESTAMP DEFAULT NOW() 10 | ); 11 | 12 | INSERT INTO dates (vdate, vtime, vdatetime) 13 | VALUES(CURRENT_DATE(), CURRENT_TIME(), NOW()); 14 | 15 | SELECT * 16 | FROM dates; 17 | 18 | -------------------------------------------------------------------------------- /modules/mod2.3.heapq/creation.py: -------------------------------------------------------------------------------- 1 | from heapq import heapify, heappush, heappop 2 | from random import randrange 3 | 4 | array = [randrange(20) for i in range(10)] 5 | print(array) 6 | heapify(array) 7 | print(array) 8 | 9 | heappush(array, randrange(20)) 10 | heappush(array, randrange(20)) 11 | print("="*40) 12 | while len(array)>0: 13 | item = heappop(array) 14 | print(f"{item}, {array}") 15 | -------------------------------------------------------------------------------- /modules/mod2.6.array/array_to_file.py: -------------------------------------------------------------------------------- 1 | from array import array 2 | from random import randrange 3 | 4 | arr = array('i', (randrange(100) for _ in range(10**6))) 5 | some_data = arr[:100] 6 | print(some_data) 7 | 8 | with open("data.bin", "wb") as f: 9 | arr.tofile(f) 10 | 11 | with open("data.bin", "rb") as f: 12 | arr.fromfile(f, 10**6) 13 | some_data = arr[:100] 14 | print(some_data) 15 | 16 | -------------------------------------------------------------------------------- /modules/mod2.7.graphlib/prepare_for_ts.py: -------------------------------------------------------------------------------- 1 | from graphlib import TopologicalSorter 2 | 3 | graph = { 4 | "v1": {}, 5 | "v2": {"v1"}, 6 | "v3": {"v1", "v2"}, 7 | "v4": {"v3"}, 8 | "v5": {"v3"}, 9 | "v6": {"v2", "v4", "v5"}, 10 | "v7": {"v5", "v6"} 11 | } 12 | 13 | sorter = TopologicalSorter(graph) 14 | # sorter.prepare() 15 | 16 | sorter.add("v1", "v5") 17 | sorter.prepare() 18 | -------------------------------------------------------------------------------- /modules/mod7.1.csv/write_csv.py: -------------------------------------------------------------------------------- 1 | from csv import reader, writer 2 | 3 | with open("countries.csv", "r", encoding="utf-8") as fread, \ 4 | open("countries_new.csv", "w", encoding="utf-8", newline="") as fwrite: 5 | csv_reader = reader(fread) 6 | csv_writer = writer(fwrite) 7 | for line in csv_reader: 8 | newline = line[:3]+[line[14]] 9 | csv_writer.writerow(newline) 10 | 11 | -------------------------------------------------------------------------------- /modules/mod2.2.collections/chain_map/members.py: -------------------------------------------------------------------------------- 1 | from collections import ChainMap 2 | 3 | dict1 = {"a": 1, "b": 2} 4 | dict2 = {"c": 3, "d": 4} 5 | dict3 = {"e": 5, "a": 6} 6 | 7 | cm = ChainMap(dict1, dict2, dict3) 8 | print(cm.maps) 9 | newcm = cm.parents 10 | print(newcm) 11 | 12 | ccm = cm.new_child({"f": 1}) 13 | print(ccm) 14 | ccm.maps[0], ccm.maps[1] = ccm.maps[1], ccm.maps[0] 15 | print(ccm) 16 | 17 | -------------------------------------------------------------------------------- /modules/mod7.1.csv/script.sql: -------------------------------------------------------------------------------- 1 | SELECT 'Code','Name','Continent','Region','SurfaceArea','IndepYear','Population','LifeExpectancy','GNP','GNPOld','LocalName','GovernmentForm','HeadOfState','Capital','Code2' 2 | UNION 3 | SELECT * 4 | FROM country 5 | INTO OUTFILE 'C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Uploads\\countries.csv' 6 | FIELDS TERMINATED BY ',' 7 | ENCLOSED BY '"' 8 | LINES TERMINATED BY '\n'; 9 | 10 | -------------------------------------------------------------------------------- /modules/mod2.6.array/searching.py: -------------------------------------------------------------------------------- 1 | from array import array 2 | from random import randrange 3 | 4 | arr = array('i', (randrange(100) for _ in range(1000))) 5 | 6 | print(arr) 7 | 8 | element = 12 9 | occurrences = arr.count(element) 10 | print("occurrences=" + str(occurrences)) 11 | pos = 0 12 | for _ in range(occurrences): 13 | pos = arr.index(element, pos) 14 | print("pos = " + str(pos)) 15 | pos = pos + 1 -------------------------------------------------------------------------------- /modules/mod7.1.csv/quotechar.py: -------------------------------------------------------------------------------- 1 | from csv import reader, writer 2 | 3 | with open("excel.csv", "r") as file: 4 | csv_reader = reader(file, delimiter=";") 5 | data = list(csv_reader) 6 | 7 | data[1][1] = "Bob,tom" 8 | 9 | with open("excel_new2.csv", "w", newline="") as file: 10 | csv_writer = writer(file, delimiter=",", quotechar="'") 11 | for row in data: 12 | csv_writer.writerow(row) 13 | 14 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/connection.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | try: 5 | with MYSQL.connect( 6 | host="localhost", 7 | user="pythonuser", 8 | password="pwd1234", 9 | database="pyworld" 10 | ) as connection: 11 | # program code goes here 12 | print(connection) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /advanced/advanced02.iterators/enumerate2.py: -------------------------------------------------------------------------------- 1 | class MyIterator: 2 | def __iter__(self): 3 | self.n = 0 4 | return self 5 | 6 | def __next__(self): 7 | self.n += 1 8 | if self.n<=10: 9 | return self.n 10 | else: 11 | raise StopIteration 12 | 13 | 14 | for index, iter_value in enumerate(MyIterator(),100): 15 | print(index, iter_value) 16 | -------------------------------------------------------------------------------- /advanced/advanced03.generators/send.py: -------------------------------------------------------------------------------- 1 | from random import randrange 2 | 3 | def f(): 4 | cnt=0 5 | for rounds in range(10): 6 | ret = yield cnt 7 | if ret is None: 8 | cnt+=1 9 | else: 10 | cnt+=1+ret 11 | 12 | 13 | it = f() 14 | for it_val in it: 15 | print(it_val) 16 | if randrange(2)==0: 17 | val = it.send(100) 18 | print(val) -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/higher.order.func.py: -------------------------------------------------------------------------------- 1 | def leibniz_term(n): 2 | return (-1)**n * 1/(2*(n+1)-1) 3 | 4 | 5 | def sum_func_terms(leibniz_term, n): 6 | sum=0 7 | for i in range(n): 8 | sum+=leibniz_term(i) 9 | 10 | return 4*sum 11 | 12 | 13 | for i in range(10,200,10): 14 | print(sum_func_terms(leibniz_term, i)) 15 | 16 | print(sum_func_terms(leibniz_term,100000)) -------------------------------------------------------------------------------- /modules/mod2.6.array/conversions.py: -------------------------------------------------------------------------------- 1 | from array import array 2 | from random import randrange 3 | 4 | arr = array('i', (randrange(100) for _ in range(50))) 5 | 6 | print("initial array: " + str(arr)) 7 | 8 | l = arr.tolist() 9 | print("as list: " + str(l)) 10 | 11 | bytes = arr.tobytes() 12 | print("as bytes: " + str(bytes)) 13 | 14 | reconstructed = array('i') 15 | arr.frombytes(bytes) 16 | print("reconstructed: " + str(arr)) -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/or.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def matches(text, regexp): 5 | pattern = re.compile(regexp) 6 | matcher = pattern.fullmatch(text) 7 | if matcher is None: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | text = "Computer Science is no more about computers " + \ 14 | "than astronomy is about telescope" 15 | 16 | print(re.findall(r"Sci.*? |ast.*? ", text)) 17 | -------------------------------------------------------------------------------- /modules/mod1.2.random/exercise02.py: -------------------------------------------------------------------------------- 1 | from random import triangular 2 | from math import floor 3 | 4 | stats={} 5 | 6 | for i in range(0,10): 7 | stats[(i/10,(i+1)/10)]=0 8 | 9 | for i in range(1000000): 10 | v=triangular(0, 1) 11 | s=floor(v*10)/10 12 | f=floor((v+0.1)*10)/10 13 | stats[(s,f)]+=1 14 | 15 | for i in range(0,10): 16 | print(f"stats[({i/10},{(i+1)/10})]={stats[(i/10,(i+1)/10)]/10000:.2f}%") 17 | -------------------------------------------------------------------------------- /modules/mod8.3.string/template_safe_substitute.py: -------------------------------------------------------------------------------- 1 | from string import Template 2 | 3 | template2 = Template("$name makes $salary$$") # $$ escapes $ 4 | 5 | sub21 = template2.safe_substitute({"name": "Bob", "salary": 1000}) 6 | print(sub21) 7 | try: 8 | sub22 = template2.substitute(name="Bob") 9 | print(sub22) 10 | except KeyError: 11 | print("KeyError") 12 | sub23 = template2.safe_substitute({"name": "Bob"}) 13 | print(sub23) -------------------------------------------------------------------------------- /modules/mod6.2.functools/polymorphic_function.py: -------------------------------------------------------------------------------- 1 | from functools import singledispatch 2 | 3 | 4 | @singledispatch 5 | def my_print(x): 6 | raise NotImplementedError("doesn't support this") 7 | 8 | 9 | @my_print.register 10 | def my_print_var(arg: int): 11 | print("int") 12 | 13 | @my_print.register 14 | def my_print_var(arg: float): 15 | print("float") 16 | 17 | 18 | my_print(54) 19 | my_print(2.1) 20 | my_print("str") 21 | -------------------------------------------------------------------------------- /modules/mod2.1.copy/exercise01.py: -------------------------------------------------------------------------------- 1 | from copy import copy, deepcopy 2 | 3 | ml = [[1,2,3],[4,5,6],[7,8,9]] 4 | 5 | ml2 = ml 6 | ml2[0][0]=10 7 | print(ml) 8 | 9 | ml = [[1,2,3],[4,5,6],[7,8,9]] 10 | ml2 = copy(ml) 11 | ml2[0]=[0] 12 | print(ml, ml2) 13 | 14 | ml = [[1,2,3],[4,5,6],[7,8,9]] 15 | ml2 = copy(ml) 16 | ml2[0][0]=0 17 | print(ml, ml2) 18 | 19 | ml = [[1,2,3],[4,5,6],[7,8,9]] 20 | ml2 = deepcopy(ml) 21 | ml2[0][0]=0 22 | print(ml, ml2) -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/scripts/stored.sql: -------------------------------------------------------------------------------- 1 | DROP PROCEDURE IF EXISTS country_cities; 2 | 3 | DELIMITER $$ 4 | CREATE PROCEDURE country_cities( 5 | IN in_country_name CHAR(52) 6 | ) 7 | BEGIN 8 | SELECT ct.name, ct.district, ct.population 9 | FROM country cn JOIN city ct 10 | ON cn.code = ct.countrycode 11 | WHERE cn.name = in_country_name; 12 | 13 | END$$ 14 | DELIMITER ; 15 | 16 | CALL country_cities('Greece'); 17 | 18 | -------------------------------------------------------------------------------- /modules/mod4.1.json/json_many_objects_same_type/ob.json: -------------------------------------------------------------------------------- 1 | [{"hour": 8, "minute": 50, "second": 32}, {"hour": 6, "minute": 34, "second": 41}, {"hour": 19, "minute": 11, "second": 19}, {"hour": 13, "minute": 10, "second": 13}, {"hour": 17, "minute": 3, "second": 8}, {"hour": 13, "minute": 17, "second": 56}, {"hour": 2, "minute": 18, "second": 0}, {"hour": 7, "minute": 0, "second": 57}, {"hour": 17, "minute": 7, "second": 30}, {"hour": 20, "minute": 48, "second": 21}] -------------------------------------------------------------------------------- /advanced/advanced02.iterators/enumerate1.py: -------------------------------------------------------------------------------- 1 | class MyIterator: 2 | def __iter__(self): 3 | self.n = 0 4 | return self 5 | 6 | def __next__(self): 7 | self.n += 1 8 | if self.n<=10: 9 | return self.n 10 | else: 11 | raise StopIteration 12 | 13 | 14 | print(enumerate(MyIterator())) 15 | print(list(enumerate(MyIterator()))) 16 | print(list(enumerate(MyIterator(),100))) 17 | -------------------------------------------------------------------------------- /advanced/advanced02.iterators/iterator.for.py: -------------------------------------------------------------------------------- 1 | class MyIterator: 2 | def __iter__(self): 3 | self.n = 0 4 | return self 5 | 6 | def __next__(self): 7 | self.n += 1 8 | if self.n<=10: 9 | return self.n 10 | else: 11 | raise StopIteration 12 | 13 | 14 | obj = MyIterator() 15 | it = iter(obj) 16 | for i in it: 17 | print(i) 18 | 19 | for i in obj: 20 | print(i) -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/class_decorator.py: -------------------------------------------------------------------------------- 1 | 2 | def decorate_with_lines(cls): 3 | def dec(): 4 | print("-"*20) 5 | ob = cls() 6 | print("-"*20) 7 | return ob 8 | return dec 9 | 10 | 11 | @decorate_with_lines 12 | class MyClass: 13 | def __init__(self): 14 | print("initializing...") 15 | 16 | def func(self): 17 | print("in func") 18 | 19 | 20 | c = MyClass() 21 | c.func() 22 | -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/example_timer.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | 4 | def timeit(func): 5 | def decorator(*args, **kwargs): 6 | t0 = time.time() 7 | ret = func(*args, **kwargs) 8 | t1 = time.time() 9 | print("Total time: " + str(t1-t0)) 10 | return ret 11 | 12 | return decorator 13 | 14 | 15 | @timeit 16 | def dummy(n): 17 | for i in range(n): 18 | pass 19 | 20 | dummy(100000000) 21 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/exercise05/main.py: -------------------------------------------------------------------------------- 1 | from dbtools import * 2 | 3 | connector = open_connection() 4 | 5 | 6 | iter_query = query_iter_many(connector, 10, "SELECT * FROM country LIMIT 42") 7 | 8 | for countries in iter_query: 9 | for country in countries: 10 | print(f"{country['Name']}({country['Continent']}). ") 11 | print("="*10 + ". Next? Press Enter...", end="") 12 | input() 13 | 14 | 15 | close_connection(connector) 16 | -------------------------------------------------------------------------------- /advanced/advanced06.lambda/map_examples2.py: -------------------------------------------------------------------------------- 1 | print(list(map(lambda x,y: x+y, [1,2,3], [4,5,6]))) 2 | 3 | print(dict(list(map(lambda x,y: 4 | (x,y), [1,2,3], 5 | ["one", "two", "three"])))) 6 | 7 | print(list(map(lambda x,y,z: 8 | {"id": x, "name": y, "grade": z}, 9 | (i for i in range(1000)), 10 | ["Bob", "Tom", "Pat"], 11 | [5,8,2]))) 12 | 13 | 14 | -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/decorator.func.with.params.py: -------------------------------------------------------------------------------- 1 | def decorate_gt_zero(func): 2 | def dec(a,b): 3 | if a<=0 or b<=0: 4 | print("Error: both args must be positive!") 5 | else: 6 | func(a,b) 7 | 8 | return dec 9 | 10 | def some_calc(a,b): 11 | print(a*b) 12 | 13 | 14 | @decorate_gt_zero 15 | def some_calc(a,b): 16 | print(a*b) 17 | 18 | 19 | some_calc(1,4) 20 | some_calc(-1,3) -------------------------------------------------------------------------------- /modules/mod6.1.itertools/filter.py: -------------------------------------------------------------------------------- 1 | from itertools import dropwhile, takewhile, compress, filterfalse 2 | 3 | elements = [1,2,3,4,5,1,2] 4 | pred = lambda x: x<3 5 | iterator = dropwhile(pred, elements) 6 | for item in iterator: 7 | print(item) 8 | 9 | print("="*20) 10 | print(list(takewhile(pred, elements))) 11 | 12 | print("="*20) 13 | print(list(compress(elements, [1,1,1,1,0,0,1]))) 14 | 15 | print("="*20) 16 | print(list(filterfalse(lambda x:x%2==0, elements))) -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/query/main.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | from connect import open_connection, close_connection 3 | MYSQL = mysql.connector 4 | 5 | conn = open_connection() 6 | 7 | try: 8 | cursor = conn.cursor() 9 | 10 | query = "SELECT * FROM country" 11 | cursor.execute(query) 12 | 13 | rows = cursor.fetchall() 14 | print(rows) 15 | cursor.close() 16 | except MYSQL.Error as e: 17 | print(e) 18 | 19 | close_connection(conn) 20 | -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/example_debug.py: -------------------------------------------------------------------------------- 1 | def debug_args(func): 2 | def decorator(*args): 3 | for arg in args: 4 | print(repr(arg), end=", ") 5 | return func(*args) 6 | 7 | return decorator 8 | 9 | class MyClass: 10 | def __init__(self): 11 | self.x = 5 12 | def __repr__(self): 13 | return f"MyClass({self.x})" 14 | 15 | @debug_args 16 | def dummy(n, ob): 17 | pass 18 | 19 | dummy(5, MyClass()) 20 | -------------------------------------------------------------------------------- /modules/mod3.1.datetime/datetime/methods.py: -------------------------------------------------------------------------------- 1 | # pip install pytz 2 | from pytz import timezone 3 | from datetime import datetime 4 | 5 | now = datetime.now() 6 | # tz names: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones 7 | us_now = datetime.now(timezone("America/New_York")) 8 | kt_now = datetime.now(timezone("Asia/Katmandu")) 9 | 10 | print("Greece time: " + str(now)) 11 | print("US/New York time: " + str(us_now)) 12 | print("Katmandu time: " + str(kt_now)) 13 | -------------------------------------------------------------------------------- /advanced/advanced02.iterators/iterator.conversions.py: -------------------------------------------------------------------------------- 1 | class MyIterator: 2 | def __iter__(self): 3 | self.n = 0 4 | return self 5 | 6 | def __next__(self): 7 | self.n += 1 8 | if self.n<=10: 9 | return self.n 10 | else: 11 | raise StopIteration 12 | 13 | it = iter(MyIterator()) 14 | print(list(it)) 15 | print(tuple(it)) 16 | print(set(it)) 17 | print(frozenset(it)) 18 | print(dict(enumerate(it))) -------------------------------------------------------------------------------- /advanced/advanced02.iterators/read.data.success.py: -------------------------------------------------------------------------------- 1 | # read.data.success.py 2 | class MyIterator: 3 | def __iter__(self): 4 | self.n = 0 5 | return self 6 | 7 | def __next__(self): 8 | self.n += 1000 9 | if self.n<=100000000: 10 | return list(range(self.n-1000, self.n)) 11 | else: 12 | raise StopIteration 13 | 14 | 15 | for next_data in MyIterator(): 16 | for data in next_data: 17 | print(data) -------------------------------------------------------------------------------- /advanced/advanced06.lambda/inner_lambda.py: -------------------------------------------------------------------------------- 1 | def factory_power(power): 2 | def nth_power(number): 3 | return number ** power 4 | 5 | return nth_power 6 | 7 | 8 | square = factory_power(2) 9 | print(square(4)) 10 | 11 | cube = factory_power(3) 12 | print(cube(4)) 13 | 14 | # using lambda 15 | 16 | def factory_power(power): 17 | return lambda n: n ** power 18 | 19 | 20 | square = factory_power(2) 21 | print(square(4)) 22 | 23 | cube = factory_power(3) 24 | print(cube(4)) -------------------------------------------------------------------------------- /modules/mod2.5.bisect/key_sorted_solution.py: -------------------------------------------------------------------------------- 1 | from random import randrange 2 | from bisect import bisect, insort 3 | 4 | numbers = [randrange(100) for _ in range(20)] 5 | numbers.sort(key=lambda x: x // 10 + x % 10) 6 | keys = [x // 10 + x % 10 for x in numbers] 7 | print(numbers) 8 | print(keys) 9 | 10 | new_value = 25 11 | key = new_value // 10 + new_value % 10 12 | pos = bisect(keys, key) 13 | insort(keys, key) 14 | numbers.insert(pos, new_value) 15 | print(numbers) 16 | print(keys) 17 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/insert/main.py: -------------------------------------------------------------------------------- 1 | from dbtools import * 2 | 3 | connector = open_connection() 4 | 5 | try: 6 | query = """INSERT INTO city (Name, countryCode, District, Population) 7 | VALUES('Chania','GRC', 'Crete', 100000)""" 8 | 9 | id = insert_query(connector,query) 10 | 11 | print("Row inserted with id: " + str(id)) 12 | 13 | connector.commit() 14 | 15 | except MYSQL.Error as e: 16 | print(e) 17 | 18 | close_connection(connector) 19 | -------------------------------------------------------------------------------- /modules/mod6.2.functools/wraps.py: -------------------------------------------------------------------------------- 1 | from functools import wraps 2 | 3 | 4 | def decorate_with_lines(func): 5 | @wraps(func) 6 | def dec(): 7 | """ inner docstring """ 8 | print("=" * 20) 9 | func() 10 | print("=" * 20) 11 | 12 | return dec 13 | 14 | 15 | @decorate_with_lines 16 | def some_func(): 17 | """ some_func docstring """ 18 | print("I did many things.. ") 19 | 20 | 21 | 22 | print(some_func.__name__) 23 | print(some_func.__doc__) 24 | -------------------------------------------------------------------------------- /modules/mod7.1.csv/sniffer.py: -------------------------------------------------------------------------------- 1 | from csv import reader, Sniffer 2 | 3 | with open("countries.csv", "r", encoding="utf-8") as file: 4 | sniff = Sniffer().sniff(file.read(1024)) 5 | file.seek(0) 6 | csv_reader = reader(file, dialect=sniff) 7 | dialect = csv_reader.dialect 8 | print("delimiter: " + dialect.delimiter) 9 | print("quotechar: " + dialect.quotechar) 10 | print("lineterminator: " + dialect.lineterminator) 11 | data = list(csv_reader) 12 | print(data) 13 | -------------------------------------------------------------------------------- /modules/mod8.2.re(b)/search.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = "Computer Science is no more about computers " + \ 4 | "than astronomy is about telescope" 5 | 6 | print(re.search(r"comp.", text)) 7 | print(re.search(r"Sci.", text)) 8 | 9 | print("="*20) 10 | pattern = re.compile(r"\ba\w*", re.IGNORECASE) 11 | pos = 0 12 | while True: 13 | m = pattern.search(text, pos) 14 | if m: 15 | print(m.group(), m.span()) 16 | pos = m.end() + 1 17 | else: 18 | break 19 | 20 | -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/property_setter.py: -------------------------------------------------------------------------------- 1 | class Salary: 2 | def __init__(self, amount): 3 | self._amount = amount 4 | 5 | @property 6 | def amount(self): 7 | return self._amount 8 | 9 | @amount.setter 10 | def amount(self, amount): 11 | if amount > 10000: 12 | raise ValueError("Too high salary") 13 | else: 14 | self._amount = amount 15 | 16 | s = Salary(500) 17 | print(s.amount) 18 | s.amount = 600 19 | print(s.amount) -------------------------------------------------------------------------------- /modules/mod4.1.json/json_many_objects_same_type/main.py: -------------------------------------------------------------------------------- 1 | from timeclass import Time, time_encoder, time_decoder 2 | from random import randrange 3 | import json 4 | 5 | arr = [] 6 | for i in range(10): 7 | t = Time(randrange(24), randrange(60), randrange(60)) 8 | arr.append(t) 9 | 10 | with open("ob.json", "w") as f: 11 | json.dump(arr, f, default=time_encoder) 12 | 13 | with open("ob.json", "r") as f: 14 | data = json.load(f, object_hook=time_decoder) 15 | for t in data: 16 | print(t) -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/quantifiers2.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def matches(text, regexp): 5 | pattern = re.compile(regexp) 6 | matcher = pattern.fullmatch(text) 7 | if matcher is None: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | text = "Men occasionally stumble over the truth, but most of them " \ 14 | "pick themselves up and hurry off as if nothing had happened." 15 | 16 | print(re.findall(r" o.* ", text)) 17 | print(re.findall(r" o.*? ", text)) 18 | 19 | -------------------------------------------------------------------------------- /modules/mod8.2.re(b)/groups3.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | text = "Computer Science is no more about computers " + \ 5 | "than astronomy is about telescope" 6 | 7 | m = re.match(r".* (?P\w+?) is (?P\w+?) .*", text) 8 | print(m[1], "|", m[2]) 9 | print(m["previous"], m["next"]) 10 | print(m.groupdict()) 11 | print(m.group(), m.group(0)) 12 | print(m.group(1), m.group(2), m.group(1, 2)) 13 | 14 | for i in range(m.lastindex+1): 15 | print(m.span(i), end=" ") 16 | print(m.group(i)) 17 | 18 | -------------------------------------------------------------------------------- /modules/mod2.7.graphlib/dynamic.py: -------------------------------------------------------------------------------- 1 | from graphlib import TopologicalSorter 2 | 3 | graph = { 4 | "v1": {}, 5 | "v2": {"v1"}, 6 | "v3": {"v1", "v2"}, 7 | "v4": {"v3"}, 8 | "v5": {"v3"}, 9 | "v6": {"v2", "v4", "v5"}, 10 | "v7": {"v5", "v6"} 11 | } 12 | 13 | sorter = TopologicalSorter(graph) 14 | sorter.prepare() 15 | 16 | while sorter.is_active(): 17 | ready = sorter.get_ready() 18 | # do something with these nodes 19 | print(ready) 20 | sorter.done(*ready) 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /modules/mod8.2.re(b)/sub.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = "Men occasionally stumble over the truth, but most of them " \ 4 | "pick themselves up and hurry off as if nothing had happened." 5 | 6 | res = re.sub(r"the\w*", "---", text) 7 | print(res) 8 | 9 | with open("pies.html", "r", encoding="utf-8") as f: 10 | text = f.read() 11 | s = re.sub(r"
    ", "
      ", text, 0, re.MULTILINE) 12 | s2 = re.sub(r"
", "", s, 0, re.MULTILINE) 13 | with open("pies2.html", "w", encoding="utf-8") as f: 14 | f.write(s2) -------------------------------------------------------------------------------- /modules/mod2.4.enum/comparable.py: -------------------------------------------------------------------------------- 1 | import functools 2 | from enum import Enum 3 | 4 | 5 | @functools.total_ordering 6 | class Days(Enum): 7 | MONDAY = 1 8 | TUESDAY = 2 9 | WEDNESDAY = 3 10 | THURSDAY = 4 11 | FRIDAY = 5 12 | SATURDAY = 6 13 | SUNDAY = 7 14 | 15 | def __gt__(self,other): 16 | return self.value > other.value 17 | 18 | 19 | print(Days.MONDAY > Days.WEDNESDAY) 20 | print(Days.MONDAY >= Days.WEDNESDAY) 21 | print(Days.MONDAY < Days.WEDNESDAY) 22 | print(Days.MONDAY <= Days.WEDNESDAY) -------------------------------------------------------------------------------- /advanced/advanced02.iterators/zip.py: -------------------------------------------------------------------------------- 1 | class MyIterator: 2 | def __init__(self,n): 3 | self.n = n 4 | 5 | def __iter__(self): 6 | self.i = 0 7 | return self 8 | 9 | def __next__(self): 10 | self.i += 1 11 | if self.i<=10: 12 | return self.n + self.i 13 | else: 14 | raise StopIteration 15 | 16 | 17 | a = MyIterator(10) 18 | b = MyIterator(20) 19 | c = MyIterator(30) 20 | 21 | 22 | for x,y,z in zip(a,b,c): 23 | print(x,y,z) 24 | -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/class_as_decorator.py: -------------------------------------------------------------------------------- 1 | class decorate_with_lines: 2 | def __init__(self, decorated): 3 | self.decorated = decorated 4 | 5 | def __call__(self): 6 | print("-"*20) 7 | ob = self.decorated() 8 | print("-"*20) 9 | return ob 10 | 11 | 12 | @decorate_with_lines 13 | class MyClass: 14 | def __init__(self): 15 | print("initializing...") 16 | 17 | def func(self): 18 | print("in func") 19 | 20 | 21 | 22 | c = MyClass() 23 | c.func() 24 | -------------------------------------------------------------------------------- /modules/mod1.2.random/exercise03.py: -------------------------------------------------------------------------------- 1 | from random import paretovariate 2 | from math import floor,inf 3 | 4 | stats={} 5 | 6 | for i in range(0,3): 7 | stats[(i,i+1)]=0 8 | stats[(3,inf)]=0 9 | 10 | 11 | for i in range(1000000): 12 | v=paretovariate(3) 13 | s=floor(v) 14 | f=s+1 15 | if s<=2: 16 | stats[(s,f)]+=1 17 | else: 18 | stats[(3,inf)]+=1 19 | 20 | for i in range(0,3): 21 | print(f"stats[({i},{i+1})]={stats[(i,i+1)]/10000:.2f}%") 22 | print(f"stats[(3,inf)]={stats[(3,inf)]/10000:.2f}%") -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/query/connect.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/exercise01/connect.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/exercise02/connect.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/exercise01.py: -------------------------------------------------------------------------------- 1 | def decorate_with_lines(func): 2 | def dec(): 3 | print("=" * 20) 4 | func() 5 | print("=" * 20) 6 | 7 | return dec 8 | 9 | 10 | def decorate_with_stars(func): 11 | def dec(): 12 | print("*" * 20) 13 | func() 14 | print("*" * 20) 15 | 16 | return dec 17 | 18 | 19 | @decorate_with_stars 20 | @decorate_with_lines 21 | def some_func(): 22 | print("I did many things.. ") 23 | 24 | 25 | some_func() 26 | -------------------------------------------------------------------------------- /modules/mod6.2.functools/polymorphic_method.py: -------------------------------------------------------------------------------- 1 | from functools import singledispatchmethod 2 | 3 | 4 | class MyClass: 5 | @singledispatchmethod 6 | def my_print(self, x): 7 | raise NotImplementedError("doesn't support this") 8 | 9 | 10 | @my_print.register 11 | def my_print_var(self, arg: int): 12 | print("int") 13 | 14 | @my_print.register 15 | def my_print_var(self, arg: float): 16 | print("float") 17 | 18 | 19 | c = MyClass() 20 | c.my_print(54) 21 | c.my_print(2.1) 22 | c.my_print("str") 23 | -------------------------------------------------------------------------------- /modules/mod2.2.collections/doubleEndedQueue/queue.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | 4 | class Queue: 5 | def __init__(self): 6 | self.data = deque() 7 | 8 | def enqueue(self, elem): 9 | self.data.append(elem) 10 | 11 | def dequeue(self): 12 | if len(self.data) == 0: 13 | return None 14 | else: 15 | return self.data.popleft() 16 | 17 | def __str__(self): 18 | return ", ".join(self.data) 19 | 20 | def __len__(self): 21 | return len(self.data) 22 | 23 | -------------------------------------------------------------------------------- /modules/mod2.2.collections/named_tuple/query/connect.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | -------------------------------------------------------------------------------- /modules/mod4.1.json/json_datatypes/json_datatypes.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | with open("ob.json", "w") as f: 4 | json.dump(1, f) 5 | f.write("\n") 6 | json.dump(1.1, f) 7 | f.write("\n") 8 | json.dump("string", f) 9 | f.write("\n") 10 | json.dump([1, 2], f) 11 | f.write("\n") 12 | json.dump((1, 2), f) 13 | f.write("\n") 14 | # json.dump({1, 2}, f) 15 | json.dump({1: 1, 2: 2}, f) 16 | f.write("\n") 17 | 18 | with open("ob.json", "r") as f: 19 | for line in f: 20 | print(type(json.loads(line))) 21 | -------------------------------------------------------------------------------- /modules/mod8.3.string/constants.py: -------------------------------------------------------------------------------- 1 | import string 2 | 3 | # as they appear in string.py 4 | whitespace = ' \t\n\r\v\f' 5 | ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz' 6 | ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 7 | ascii_letters = ascii_lowercase + ascii_uppercase 8 | digits = '0123456789' 9 | hexdigits = digits + 'abcdef' + 'ABCDEF' 10 | octdigits = '01234567' 11 | punctuation = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~""" 12 | printable = digits + ascii_letters + punctuation + whitespace 13 | 14 | 15 | if 'a' in string.printable: 16 | print(True) -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/dictionary_manip/connect.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | -------------------------------------------------------------------------------- /advanced/advanced02.iterators/iterator.builtin1.py: -------------------------------------------------------------------------------- 1 | class MyIterator: 2 | def __iter__(self): 3 | self.n = 0 4 | return self 5 | 6 | def __next__(self): 7 | self.n += 1 8 | if self.n<=10: 9 | return self.n 10 | else: 11 | raise StopIteration 12 | 13 | 14 | print(list(MyIterator())) 15 | print(f"min={min(MyIterator())}") 16 | print(f"max={max(MyIterator())}") 17 | print(f"sum={sum(MyIterator())}") 18 | print(f"all={all(MyIterator())}") 19 | print(f"any={any(MyIterator())}") -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/dictionary_manip/main.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | from connect import open_connection, close_connection 3 | MYSQL = mysql.connector 4 | 5 | 6 | connector = open_connection() 7 | 8 | try: 9 | cursor = connector.cursor(dictionary=True) 10 | 11 | query = "SELECT * FROM country" 12 | cursor.execute(query) 13 | 14 | rows = cursor.fetchall() 15 | for row in rows: 16 | print(f"{row['Name']}({row['Continent']})") 17 | 18 | except MYSQL.Error as e: 19 | print(e) 20 | 21 | close_connection(connector) 22 | -------------------------------------------------------------------------------- /advanced/advanced03.generators/opc.file.py: -------------------------------------------------------------------------------- 1 | # source: https://stackoverflow.com/questions/519633/lazy-method-for-reading-big-file-in-python 2 | 3 | def read_in_chunks(file_object, chunk_size=1024): 4 | """Lazy function (generator) to read a file piece by piece. 5 | Default chunk size: 1k.""" 6 | while True: 7 | data = file_object.read(chunk_size) 8 | if not data: 9 | break 10 | yield data 11 | 12 | 13 | with open('romeonjuliet.txt') as f: 14 | for piece in read_in_chunks(f): 15 | print(piece) 16 | -------------------------------------------------------------------------------- /modules/mod1.2.random/exercise04.py: -------------------------------------------------------------------------------- 1 | from random import randrange,shuffle 2 | 3 | def print_seq_cities(cities, seq): 4 | for i in range(len(cities)): 5 | print(cities[seq[i]], end=" ") 6 | 7 | cities=["A","B","C","D","E"] 8 | 9 | distances=[[randrange(100) for j in range(5)] for i in range(5)] 10 | 11 | ml = list(range(5)) 12 | 13 | for _ in range(5): 14 | shuffle(ml) 15 | print_seq_cities(cities, ml) 16 | distance=0 17 | for i in range(5-1): 18 | distance+=distances[ml[i]][ml[i+1]] 19 | print(" Total Distance: " + str(distance)) -------------------------------------------------------------------------------- /modules/mod2.4.enum/methods.py: -------------------------------------------------------------------------------- 1 | import functools 2 | from enum import Enum 3 | 4 | 5 | class Days(Enum): 6 | MONDAY = 1 7 | TUESDAY = 2 8 | WEDNESDAY = 3 9 | THURSDAY = 4 10 | FRIDAY = 5 11 | SATURDAY = 6 12 | SUNDAY = 7 13 | 14 | def mood(self): 15 | if self.value <= 5: 16 | return "bad" 17 | else: 18 | return "good" 19 | 20 | @classmethod 21 | def best_day(cls): 22 | return cls.SUNDAY 23 | 24 | 25 | for day in Days: 26 | print(day, day.mood()) 27 | 28 | print(Days.best_day()) -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/fetchone/main.py: -------------------------------------------------------------------------------- 1 | from dbtools import * 2 | 3 | connector = open_connection() 4 | 5 | try: 6 | cursor = connector.cursor(dictionary=True) 7 | 8 | query = "SELECT * FROM country" 9 | cursor.execute(query) 10 | 11 | country = cursor.fetchone() 12 | while country is not None: 13 | print(f"{country['Name']}({country['Continent']}). Next? Press Enter...", end="") 14 | input() 15 | country = cursor.fetchone() 16 | 17 | except MYSQL.Error as e: 18 | print(e) 19 | 20 | close_connection(connector) 21 | -------------------------------------------------------------------------------- /modules/mod7.1.csv/write_csv_dictionary.py: -------------------------------------------------------------------------------- 1 | from csv import DictReader, DictWriter 2 | 3 | with open("countries.csv", "r", encoding="utf-8") as file: 4 | csv_reader = DictReader(file) 5 | data = list(csv_reader) 6 | 7 | with open("countries_new3.csv", "w", encoding="utf-8", newline="") as file: 8 | csv_writer = DictWriter(file, fieldnames=["Name", "Continent"]) 9 | csv_writer.writeheader() 10 | for row in data: 11 | new_row = {"Name": row["Name"], 12 | "Continent": row["Continent"]} 13 | csv_writer.writerow(new_row) 14 | -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/quantifiers.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def matches(text, regexp): 5 | pattern = re.compile(regexp) 6 | matcher = pattern.fullmatch(text) 7 | if matcher is None: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | print(matches("abb", r"ab+")) 14 | print(matches("abb", r"ab{3,}")) 15 | print(matches("abab", r"(ab){2}")) 16 | print(matches("abab", r"(ab+){2}")) 17 | 18 | print("=" * 10) 19 | 20 | print(matches("aaaa", r"aa(aa)?")) 21 | print(matches("aaaa", r"(..)+")) 22 | print(matches("aaaa", r".(..)*")) 23 | 24 | -------------------------------------------------------------------------------- /modules/mod6.1.itertools/combinatorial_iterators.py: -------------------------------------------------------------------------------- 1 | from itertools import product, permutations, combinations, \ 2 | combinations_with_replacement 3 | 4 | it_prod = product(["a","b","c"],[1,2,3]) 5 | print([x for x in it_prod]) 6 | 7 | print("="*30) 8 | it_perm = permutations([1,2,3],3) 9 | for perm in it_perm: 10 | print(perm) 11 | 12 | print("="*30) 13 | it_comb = combinations([1,2,3,4],2) 14 | for comb in it_comb: 15 | print(comb) 16 | 17 | print("="*30) 18 | it_comb = combinations_with_replacement([1,2,3,4],2) 19 | for comb in it_comb: 20 | print(comb) 21 | -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/example_memoization.py: -------------------------------------------------------------------------------- 1 | def memoize(func): 2 | def decorator(arg): 3 | 4 | if arg in results_memory: 5 | return results_memory[arg] 6 | else: 7 | results_memory[arg] = func(arg) 8 | return results_memory[arg] 9 | 10 | results_memory = {} 11 | return decorator 12 | 13 | 14 | 15 | @memoize 16 | def fib(n): 17 | if n == 0: 18 | return 0 19 | elif n == 1: 20 | return 1 21 | else: 22 | return fib(n-1)+fib(n-2) 23 | 24 | 25 | 26 | print(fib(10)) 27 | -------------------------------------------------------------------------------- /modules/mod5.1.pickle/ser.py: -------------------------------------------------------------------------------- 1 | from pickle import dump, dumps 2 | 3 | 4 | class Data: 5 | def __init__(self, alist, adict, anint, aset, adata): 6 | self.alist = alist 7 | self.adict = adict 8 | self.anint = anint 9 | self.aset = aset 10 | self.adata = adata 11 | 12 | 13 | l = [1, 2, 3] 14 | print(dumps(l)) 15 | 16 | with open("data.pkl", "wb") as f: 17 | d1 = Data([1, 2], {1: 1, 2: 2}, 1, {1, 2}, None) 18 | dump(d1, f) 19 | d2 = Data([3], {3: 3}, 3, {3}, d1) 20 | dump(d2, f) 21 | d3 = Data([], {}, 0, set(), d2) 22 | dump(d3, f) 23 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/blobs/main.py: -------------------------------------------------------------------------------- 1 | from dbtools import * 2 | 3 | connector = open_connection() 4 | 5 | try: 6 | mod = 2 7 | if mod == 1: # store to db 8 | insert_with_blob(connector, "bs.png", "beautiful soup logo") 9 | connector.commit() 10 | insert_with_blob(connector, "mysql.png", "mysql logo") 11 | connector.commit() 12 | else: # read from db 13 | res = read_blob(connector,1) 14 | with open("copy.png", "wb") as f: 15 | f.write(res) 16 | 17 | except MYSQL.Error as e: 18 | print(e) 19 | 20 | close_connection(connector) 21 | -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/dot.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def matches(text, regexp): 5 | pattern = re.compile(regexp) 6 | matcher = pattern.fullmatch(text) 7 | if matcher is None: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | r = r"a.b." 14 | print(matches("abba", r)) 15 | print(matches("baba", r)) 16 | print(matches("abbaa", r)) 17 | print(matches("acbz", r)) 18 | print(matches("aaabba", r)) 19 | 20 | print("=" * 20) 21 | print(matches("abc", r"...")) 22 | print(matches("abcde", r"..c..")) 23 | print(matches("aa\nbb", r"..")) 24 | print(matches("\n\n", r"..")) 25 | 26 | -------------------------------------------------------------------------------- /modules/mod2.3.heapq/merging.py: -------------------------------------------------------------------------------- 1 | from heapq import merge 2 | from random import randrange 3 | 4 | 5 | data1 = [randrange(20) for _ in range(10)] 6 | data2 = [randrange(20) for _ in range(10)] 7 | data3 = [randrange(20) for _ in range(10)] 8 | 9 | data1.sort() 10 | data2.sort() 11 | data3.sort() 12 | 13 | print(data1) 14 | print(data2) 15 | print(data3) 16 | print(list(merge(data1, data2, data3))) 17 | 18 | data1.sort(key=lambda x:x%3) 19 | data2.sort(key=lambda x:x%3) 20 | data3.sort(key=lambda x:x%3) 21 | 22 | print(data1) 23 | print(data2) 24 | print(data3) 25 | print(list(merge(data1, data2, data3, key=lambda x:x%3))) 26 | -------------------------------------------------------------------------------- /advanced/advanced03.generators/exercise01.py: -------------------------------------------------------------------------------- 1 | class MyIterator: 2 | def __iter__(self): 3 | self.i = 9 4 | return self 5 | 6 | def __next__(self): 7 | self.i += 1 8 | if self.i <= 20: 9 | return self.i ** 2 10 | else: 11 | raise StopIteration 12 | 13 | 14 | for i in MyIterator(): 15 | print(i) 16 | 17 | 18 | def MyGenerator(): 19 | for i in range(10,21): 20 | yield i*i 21 | 22 | for i in MyGenerator(): 23 | print(i) 24 | 25 | 26 | g = (i*i for i in range(10,21)) 27 | 28 | for i in g: 29 | print(i) 30 | -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/predefined_character_classes.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def matches(text, regexp): 5 | pattern = re.compile(regexp) 6 | matcher = pattern.fullmatch(text) 7 | if matcher is None: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | regexp = r"[0-2][0-3]:[0-5]\d" 14 | print(matches("01:49", regexp)) 15 | print(matches("11:01", regexp)) 16 | print(matches("25:11", regexp)) 17 | 18 | print("=" * 10) 19 | regexp = r"[0-2][0-3]:[0-5]\d:[0-5]\d(.\d{1,4})?" 20 | print(matches("01:49:12", regexp)) 21 | print(matches("11:01:11.11", regexp)) 22 | print(matches("22:11:23.11213", regexp)) 23 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/upd_del/main.py: -------------------------------------------------------------------------------- 1 | from dbtools import * 2 | 3 | connector = open_connection() 4 | 5 | try: 6 | query = """UPDATE city 7 | SET name='Χανιά' 8 | WHERE name='Chania'""" 9 | 10 | update_query(connector, query) 11 | connector.commit() 12 | 13 | print("Check your db. Press Enter...") 14 | input("") 15 | 16 | query = """DELETE FROM city 17 | WHERE name='Χανιά'""" 18 | 19 | delete_query(connector, query) 20 | connector.commit() 21 | 22 | 23 | except MYSQL.Error as e: 24 | print(e) 25 | 26 | close_connection(connector) 27 | -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/with_state.py: -------------------------------------------------------------------------------- 1 | from math import sqrt 2 | 3 | def valid_int_gt_zero(func): 4 | def decorated(val): 5 | if not isinstance(val, int): 6 | raise TypeError("Not an integer") 7 | elif val < 0: 8 | raise ValueError("Negative value") 9 | else: 10 | decorated.calls += 1 11 | return func(val) 12 | 13 | decorated.calls = 0 14 | return decorated 15 | 16 | 17 | @valid_int_gt_zero 18 | def int_sqrt(val): 19 | return int(sqrt(val)) 20 | 21 | 22 | print(int_sqrt(2)) 23 | print(int_sqrt(4)) 24 | print("calls: " + str(int_sqrt.calls)) 25 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/fetchmany/main.py: -------------------------------------------------------------------------------- 1 | from dbtools import * 2 | 3 | connector = open_connection() 4 | 5 | try: 6 | cursor = connector.cursor(dictionary=True) 7 | 8 | query = "SELECT * FROM country LIMIT 42" 9 | cursor.execute(query) 10 | 11 | countries = cursor.fetchmany(10) 12 | while countries: 13 | for country in countries: 14 | print(f"{country['Name']}({country['Continent']}). ") 15 | print("="*10 + ". Next? Press Enter...", end="") 16 | input() 17 | countries = cursor.fetchmany(10) 18 | 19 | except MYSQL.Error as e: 20 | print(e) 21 | 22 | close_connection(connector) 23 | -------------------------------------------------------------------------------- /modules/mod8.2.re(b)/flags.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def matches(text, regexp): 5 | pattern = re.compile(regexp) 6 | matcher = pattern.fullmatch(text) 7 | if matcher is None: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | with open("pies.html", encoding="utf-8") as f: 14 | text = f.read() 15 | 16 | 17 | pattern = re.compile("A.*A", re.IGNORECASE) 18 | res = matches("abba", pattern) 19 | print(res) 20 | 21 | res2 = re.findall(r""" 22 | ^\s*? # start with some whitespace 23 | <(.+?)> # extract the first tag you find 24 | """, text, re.MULTILINE | re.VERBOSE) 25 | print(res2) 26 | 27 | 28 | -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/classmethod_and_staticmethod.py: -------------------------------------------------------------------------------- 1 | class MyClass: 2 | objects_initiated = 0 3 | 4 | def __init__(self, x, y): 5 | MyClass.objects_initiated += 1 6 | self.x = x 7 | self.y = y 8 | 9 | @staticmethod 10 | def print_cnt_objects(): 11 | print(MyClass.objects_initiated) 12 | 13 | @classmethod 14 | def constructJustX(cls, x): 15 | print(cls.__name__) 16 | print(cls.__dict__) 17 | return cls(x, 0) 18 | 19 | 20 | ob1 = MyClass(1, 1) 21 | ob2 = MyClass(2, 1) 22 | MyClass.print_cnt_objects() 23 | 24 | ob3 = MyClass.constructJustX(3) 25 | MyClass.print_cnt_objects() -------------------------------------------------------------------------------- /modules/mod2.3.heapq/smallest.py: -------------------------------------------------------------------------------- 1 | from heapq import heapify, nsmallest 2 | from random import randrange 3 | 4 | 5 | class Person: 6 | def __init__(self, name, age): 7 | self.name = name 8 | self.age = age 9 | 10 | def __lt__(self, other): 11 | return self.age < other.age 12 | 13 | def __str__(self): 14 | return self.name + "(" + str(self.age) + ")" 15 | 16 | 17 | array = [Person("name", randrange(20)) for i in range(10)] 18 | print(*array) 19 | heapify(array) 20 | print(*array) 21 | 22 | ml = nsmallest(4, array) 23 | print(*ml) 24 | 25 | ml = nsmallest(4, array, lambda person: 20-person.age) 26 | print(*ml) 27 | 28 | print(*array) -------------------------------------------------------------------------------- /modules/mod4.1.json/json_many_objects_different_types/main.py: -------------------------------------------------------------------------------- 1 | from timeclass import Time, ZonedTime, time_encoder, time_decoder 2 | from random import randrange 3 | import json 4 | 5 | arr = [] 6 | for i in range(10): 7 | if randrange(2)==0: 8 | t = Time(randrange(24), randrange(60), randrange(60)) 9 | else: 10 | t = ZonedTime(randrange(24), randrange(60), randrange(60), "UTC+" + str(randrange(10))) 11 | arr.append(t) 12 | 13 | with open("ob.json", "w") as f: 14 | json.dump(arr, f, default=time_encoder) 15 | 16 | with open("ob.json", "r") as f: 17 | data = json.load(f, object_hook=time_decoder) 18 | for t in data: 19 | print(t) -------------------------------------------------------------------------------- /modules/mod5.2.shelve/shelf_example.py: -------------------------------------------------------------------------------- 1 | from shelve import open 2 | 3 | class Data: 4 | def __init__(self, alist, adict, anint, aset, adata): 5 | self.alist = alist 6 | self.adict = adict 7 | self.anint = anint 8 | self.aset = aset 9 | self.adata = adata 10 | 11 | shelf = open("data.shelf", writeback=True) 12 | 13 | shelf["int"] = 1 14 | shelf["dict"] = {"a": 1, "b": 2} 15 | shelf["set"] = {1, 2, 3} 16 | shelf["object"] = Data([1, 2], {1: 1, 2: 2}, 1, {1, 2}, None) 17 | 18 | shelf.close() 19 | 20 | with open("data.shelf", writeback=True) as shelf: 21 | shelf["int"] = 2 22 | for k, v in shelf.items(): 23 | print(k, v) -------------------------------------------------------------------------------- /modules/mod4.1.json/json_basics/json_basics.py: -------------------------------------------------------------------------------- 1 | import json 2 | from random import randrange 3 | 4 | with open("ob.json", "w") as f: 5 | json.dump([(1,2),(2,3)], f) 6 | with open("ob.json", "r") as f: 7 | ob = json.load(f) 8 | print(ob) 9 | 10 | with open("multi_line.json", "w") as f: 11 | for _ in range(4): 12 | v = randrange(3) 13 | if v == 0: 14 | json.dump([1,2,3], f) 15 | elif v == 1: 16 | json.dump({"a":1, "b":2, "c":3}, f) 17 | else: 18 | json.dump(4, f) 19 | f.write("\n") 20 | 21 | with open("multi_line.json", "r") as f: 22 | for lineObj in f: 23 | print(json.loads(lineObj)) -------------------------------------------------------------------------------- /modules/mod6.1.itertools/groupby_example.py: -------------------------------------------------------------------------------- 1 | from random import randrange 2 | from itertools import groupby 3 | 4 | numbers = [randrange(2) for i in range(10)] 5 | print(numbers) 6 | print(list(groupby(numbers))) 7 | for k, items in groupby(numbers): 8 | print("Key: " + str(k), end=". Items: ") 9 | for item in items: 10 | print(item, end=" ") 11 | print() 12 | 13 | print("="*30) 14 | numbers = [randrange(10) for i in range(20)] 15 | print(numbers) 16 | for k, items in groupby(numbers, lambda x: "even" if x%2==0 else "odd"): 17 | print("Key: " + str(k), end=". Items: ") 18 | for item in items: 19 | print(item, end=" ") 20 | print() 21 | 22 | -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/exercise02.py: -------------------------------------------------------------------------------- 1 | def decorate_arg_int_not_zero(func): 2 | def dec(*args): 3 | for arg in args: 4 | if not isinstance(arg,int): 5 | print("Error: Must be integer!") 6 | return None 7 | if arg==0: 8 | print("Error: Must not be zero!") 9 | return None 10 | 11 | func(*args) 12 | 13 | return dec 14 | 15 | 16 | @decorate_arg_int_not_zero 17 | def some_func(a,b): 18 | print(a*b) 19 | 20 | @decorate_arg_int_not_zero 21 | def some_func1(a,b,c): 22 | print(a*b*c) 23 | 24 | some_func(0,10) 25 | some_func1(-8,10,20) 26 | -------------------------------------------------------------------------------- /modules/mod2.2.collections/named_tuple/query/main.py: -------------------------------------------------------------------------------- 1 | from collections import namedtuple 2 | import mysql.connector 3 | from connect import open_connection, close_connection 4 | MYSQL = mysql.connector 5 | 6 | conn = open_connection() 7 | 8 | try: 9 | cursor = conn.cursor() 10 | 11 | query = "SELECT Code, Name, Population FROM country" 12 | cursor.execute(query) 13 | 14 | rows = cursor.fetchall() 15 | print(rows) 16 | 17 | Country = namedtuple("Country", "Code Name Population") 18 | c = Country(*rows[0]) 19 | print(c.Code, c.Name, c.Population) 20 | 21 | 22 | cursor.close() 23 | except MYSQL.Error as e: 24 | print(e) 25 | 26 | close_connection(conn) 27 | -------------------------------------------------------------------------------- /modules/mod8.3.string/replacement_indexing.py: -------------------------------------------------------------------------------- 1 | class Time: 2 | def __init__(self, hour, minute, second): 3 | self.hour = hour 4 | self.minute = minute 5 | self.second = second 6 | 7 | def __str__(self): 8 | return f"{str(self.hour).zfill(2)}:" \ 9 | f"{str(self.minute).zfill(2)}:" \ 10 | f"{str(self.second).zfill(2)}" 11 | 12 | def __repr__(self): 13 | return f"Time({self.hour},{self.minute},{self.second})" 14 | 15 | 16 | t = Time(4, 48, 0) 17 | print("minutes = {0.minute}".format(t)) 18 | l = [1, 2, 3] 19 | print("second = {0[1]}".format(l)) 20 | d = {"a": 1, "b": 2} 21 | print("val = {arg[a]}".format(arg=d)) 22 | -------------------------------------------------------------------------------- /modules/mod1.4.fraction/frac.py: -------------------------------------------------------------------------------- 1 | import math 2 | from fractions import Fraction 3 | from decimal import Decimal 4 | 5 | f1 = Fraction(1/3) 6 | f2 = Fraction("1/3") 7 | f3 = Fraction(Decimal(1.2)) 8 | f4 = Fraction(-1, 5) 9 | print(f1, f2, f3, f4, f4.numerator, f4.denominator) 10 | 11 | print(f3.limit_denominator(100)) 12 | print(f3.limit_denominator()) 13 | print(f3.limit_denominator().as_integer_ratio()) 14 | 15 | print((f1*f4).limit_denominator()) 16 | print(f1/f2) 17 | print((f1+f2+f3).limit_denominator()) 18 | 19 | print(Fraction(math.sqrt(Fraction("1/9"))).limit_denominator()) 20 | print(round(Fraction("529/3"),1)) 21 | print(Fraction(math.pow(Fraction(1/3), Fraction(1/3))).limit_denominator()) 22 | -------------------------------------------------------------------------------- /modules/mod2.2.collections/dict_variations/default_dict.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | 4 | def func(): 5 | return "no value" 6 | 7 | d1 = defaultdict(func) 8 | 9 | print(d1["a"]) 10 | print(d1) 11 | 12 | 13 | print("="*25) 14 | 15 | d2 = defaultdict(list) 16 | 17 | d2["a"].append(1) 18 | d2["b"].append(2) 19 | print(d2) 20 | 21 | 22 | print("="*25) 23 | 24 | d3 = defaultdict(str) 25 | 26 | d3["a"] += "bb" 27 | d3["a"] += "aa" 28 | d3["c"] += "2" 29 | print(d3) 30 | 31 | 32 | print("="*25) # from the docs 33 | 34 | s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)] 35 | d4 = defaultdict(list) 36 | for k, v in s: 37 | d4[k].append(v) 38 | print(d4) 39 | -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/property_deleter.py: -------------------------------------------------------------------------------- 1 | class Salary: 2 | def __init__(self, amount): 3 | self._amount = amount 4 | 5 | @property 6 | def amount(self): 7 | return self._amount 8 | 9 | @amount.setter 10 | def amount(self, amount): 11 | if amount > 10000: 12 | raise ValueError("Too high salary") 13 | else: 14 | self._amount = amount 15 | 16 | @amount.deleter 17 | def amount(self): 18 | del self._amount 19 | 20 | s = Salary(500) 21 | print(s.amount) 22 | s.amount = 600 23 | print(s.amount) 24 | del s.amount 25 | try: 26 | print(s.amount) 27 | except AttributeError: 28 | print("property doesn't exist") 29 | -------------------------------------------------------------------------------- /modules/mod2.2.collections/doubleEndedQueue/methods.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | class Stack: 4 | def __init__(self): 5 | self.stack = deque() 6 | 7 | def push(self, element): 8 | self.stack.append(element) 9 | 10 | def pop(self): 11 | if len(self.stack) == 0: 12 | return None 13 | else: 14 | return self.stack.pop() 15 | 16 | 17 | contracts = Stack() 18 | contracts.push("A") 19 | contracts.push("B") 20 | contracts.push("C") 21 | print(contracts.pop()) 22 | 23 | print(contracts.stack) 24 | contracts.stack.rotate() 25 | print(contracts.stack) 26 | contracts.stack.remove("A") 27 | print(contracts.stack) 28 | print(contracts.stack.count("A")) 29 | -------------------------------------------------------------------------------- /modules/mod4.1.json/json_objects_manip_func/timeclass.py: -------------------------------------------------------------------------------- 1 | class Time: 2 | def __init__(self, hour, minute, second): 3 | self.hour = hour 4 | self.minute = minute 5 | self.second = second 6 | 7 | def __str__(self): 8 | return f"{str(self.hour).zfill(2)}:" \ 9 | f"{str(self.minute).zfill(2)}:" \ 10 | f"{str(self.second).zfill(2)}" 11 | 12 | 13 | def time_encoder(time): 14 | if isinstance(time, Time): 15 | return {"hour": time.hour, "minute": time.minute, "second": time.second} 16 | else: 17 | raise TypeError("Type should be Time") 18 | 19 | 20 | def time_decoder(time): 21 | return Time(time["hour"], time["minute"], time["second"]) 22 | -------------------------------------------------------------------------------- /modules/mod4.1.json/json_many_objects_same_type/timeclass.py: -------------------------------------------------------------------------------- 1 | class Time: 2 | def __init__(self, hour, minute, second): 3 | self.hour = hour 4 | self.minute = minute 5 | self.second = second 6 | 7 | def __str__(self): 8 | return f"{str(self.hour).zfill(2)}:" \ 9 | f"{str(self.minute).zfill(2)}:" \ 10 | f"{str(self.second).zfill(2)}" 11 | 12 | 13 | def time_encoder(time): 14 | if isinstance(time, Time): 15 | return {"hour": time.hour, "minute": time.minute, "second": time.second} 16 | else: 17 | raise TypeError("Type should be Time") 18 | 19 | 20 | def time_decoder(time): 21 | return Time(time["hour"], time["minute"], time["second"]) 22 | -------------------------------------------------------------------------------- /advanced/advanced06.lambda/reduce_examples2.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | 3 | students = [ 4 | { 5 | "name": "Bob", 6 | "grade": 5, 7 | }, 8 | { 9 | "name": "Pat", 10 | "grade": 7 11 | }, 12 | { 13 | "name": "Tom", 14 | "grade": 2 15 | } 16 | ] 17 | 18 | 19 | 20 | # students that passed 21 | print(reduce(lambda x, y: x+[y["name"]] if y["grade"]>=5 else x, students, [])) 22 | 23 | # get the entries with just the names of students that passed 24 | print(reduce(lambda x, y: x+[{"name": y["name"]}] if y["grade"]>=5 else x, students, [])) 25 | 26 | # student with lowest grade 27 | print(reduce(lambda x, y: x if x["grade"] < y["grade"] else y,students, (students[0]))) -------------------------------------------------------------------------------- /modules/mod5.1.pickle/pickle_loads.py: -------------------------------------------------------------------------------- 1 | from pickle import load 2 | 3 | 4 | class Data: 5 | def __init__(self, alist, adict, anint, aset, adata): 6 | self.alist = alist 7 | self.adict = adict 8 | self.anint = anint 9 | self.aset = aset 10 | self.adata = adata 11 | 12 | def __str__(self): 13 | return str(self.alist) + ", " + str(self.adict) + ", " + \ 14 | str(self.anint) + ", " + str(self.aset) + \ 15 | ", Data(" + str(self.adata) + ")" 16 | 17 | 18 | with open("data.pkl", "rb") as f: 19 | try: 20 | ob = load(f) 21 | while ob is not None: 22 | print(ob) 23 | ob = load(f) 24 | except EOFError: 25 | pass 26 | -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/character_classes.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def matches(text, regexp): 5 | pattern = re.compile(regexp) 6 | matcher = pattern.fullmatch(text) 7 | if matcher is None: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | print(matches("abb", r"[abc]*")) 14 | print(matches("abZ", r"[a-z]*")) 15 | print(matches("abdm", r"[a-dm-p]*")) 16 | print(matches("ffxm", r"[^a-d]*")) 17 | 18 | print("=" * 10) 19 | 20 | print(matches("psounis21@gmail.com", 21 | r"[a-zA-Z1-9]{8,12}@gmail.com")) 22 | print(matches("1.psounis@gmail.com", 23 | r"[a-zA-Z1-9]{8,12}@gmail.com")) 24 | print(matches("psounis-21@gmail.com", 25 | r"[a-zA-Z0-9_-]+@[a-zA-Z]+\.com")) 26 | -------------------------------------------------------------------------------- /modules/mod4.1.json/json_many_objects_different_types/ob.json: -------------------------------------------------------------------------------- 1 | [{"__ZonedTime__": true, "hour": 6, "minute": 52, "second": 28, "zone": "UTC+1"}, {"__Time__": true, "hour": 17, "minute": 54, "second": 31}, {"__Time__": true, "hour": 0, "minute": 9, "second": 16}, {"__ZonedTime__": true, "hour": 3, "minute": 23, "second": 49, "zone": "UTC+4"}, {"__ZonedTime__": true, "hour": 12, "minute": 45, "second": 46, "zone": "UTC+3"}, {"__ZonedTime__": true, "hour": 2, "minute": 7, "second": 27, "zone": "UTC+9"}, {"__ZonedTime__": true, "hour": 4, "minute": 51, "second": 51, "zone": "UTC+9"}, {"__Time__": true, "hour": 7, "minute": 2, "second": 52}, {"__Time__": true, "hour": 8, "minute": 57, "second": 32}, {"__ZonedTime__": true, "hour": 3, "minute": 10, "second": 3, "zone": "UTC+6"}] -------------------------------------------------------------------------------- /modules/mod6.3.operator/getters.py: -------------------------------------------------------------------------------- 1 | from operator import itemgetter, attrgetter 2 | 3 | class A: 4 | def __init__(self): 5 | self.x = 1 6 | self.y = 2 7 | 8 | def __getitem__(self, item): 9 | if item == 0: 10 | return self.x 11 | else: 12 | return self.y 13 | 14 | 15 | class B: 16 | def __init__(self): 17 | self.x = 11 18 | self.y = 21 19 | 20 | def __getitem__(self, item): 21 | if item == 0: 22 | return self.x 23 | else: 24 | return self.y 25 | 26 | 27 | a = A() 28 | b = B() 29 | 30 | attr_x = attrgetter("x") 31 | print(attr_x(a)) 32 | print(attr_x(b)) 33 | 34 | item = itemgetter(1) 35 | print(item(a)) 36 | print(item(b)) 37 | -------------------------------------------------------------------------------- /advanced/advanced02.iterators/opc.primes.py: -------------------------------------------------------------------------------- 1 | # modification on 2 | # https://school.geekwall.in/p/r1halvojG/what-can-you-use-python-generator-functions-for 3 | 4 | def check_prime(number): 5 | for divisor in range(2, int(number ** 0.5) + 1): 6 | if number % divisor == 0: 7 | return False 8 | return True 9 | 10 | class Primes: 11 | def __init__(self): 12 | self.number = 1 13 | def __iter__(self): 14 | return self 15 | def __next__(self): 16 | self.number += 1 17 | if check_prime(self.number): 18 | return self.number 19 | else: 20 | return self.__next__() 21 | 22 | primes = Primes() 23 | print(primes) 24 | for x in primes: 25 | print(x) -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/special_characters.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def matches(text, regexp): 5 | pattern = re.compile(regexp) 6 | matcher = pattern.fullmatch(text) 7 | if matcher is None: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | print(matches("\\\\", r"\\{2,}")) 14 | 15 | print("=" * 10) 16 | 17 | text = "Everything about me is a contradiction, " + \ 18 | "and so is everything about everybody else.\n " + \ 19 | "We are made out of oppositions; we live between two poles.\n " + \ 20 | "There's a philistine and an aesthete in all of us, " + \ 21 | "and a murderer and a saint.\n You don't reconcile the poles.\n " + \ 22 | "You just recognize them." 23 | 24 | print(re.split(r"\n *", text)) 25 | -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/opc.html.decorating.py: -------------------------------------------------------------------------------- 1 | # opc.html.decorating.py 2 | # source (mod): https://gist.github.com/Zearin/2f40b7b9cfc51132851a 3 | 4 | 5 | # The decorator to make it bold 6 | def makebold(fn): 7 | # The new function the decorator returns 8 | def wrapper(): 9 | # Insertion of some code before and after 10 | return '' + fn() + '' 11 | return wrapper 12 | 13 | # The decorator to make it italic 14 | def makeitalic(fn): 15 | # The new function the decorator returns 16 | def wrapper(): 17 | # Insertion of some code before and after 18 | return '' + fn() + '' 19 | return wrapper 20 | 21 | @makebold 22 | @makeitalic 23 | def say(): 24 | return 'hello' 25 | 26 | print(say()) 27 | -------------------------------------------------------------------------------- /modules/mod8.2.re(b)/findall.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | text = "Computer Science is no more about computers, " + \ 4 | "than astronomy is about telescope." 5 | 6 | print(re.findall(r"\w+", text)) 7 | print(re.findall(r"(\w+) about (\w+)", text)) 8 | print(re.findall(r"((\w+) about (\w+))", text)) 9 | 10 | print("="*20) 11 | 12 | text = "Everything about me is a contradiction, " + \ 13 | "and so is everything about everybody else.\n " + \ 14 | "We are made out of oppositions; we live between two poles.\n " + \ 15 | "There's a philistine and an aesthete in all of us, " + \ 16 | "and a murderer and a saint.\nYou don't reconcile the poles.\n" + \ 17 | "You just recognize them." 18 | 19 | pattern = re.compile(r"^(Y\w+) ([\w']+) (\w+)", re.MULTILINE) 20 | print(pattern.findall(text)) 21 | -------------------------------------------------------------------------------- /modules/mod6.3.operator/method_caller.py: -------------------------------------------------------------------------------- 1 | from operator import methodcaller 2 | 3 | class A: 4 | def __init__(self): 5 | self.x = 1 6 | self.y = 2 7 | 8 | def __getitem__(self, item): 9 | if item == 0: 10 | return self.x 11 | else: 12 | return self.y 13 | 14 | def f(self, arg): 15 | return self.x + arg 16 | 17 | 18 | class B: 19 | def __init__(self): 20 | self.x = 11 21 | self.y = 21 22 | 23 | def __getitem__(self, item): 24 | if item == 0: 25 | return self.x 26 | else: 27 | return self.y 28 | 29 | def f(self, arg): 30 | return self.x + arg 31 | 32 | 33 | a = A() 34 | b = B() 35 | 36 | method_f = methodcaller("f", 100) 37 | print(method_f(a)) 38 | print(method_f(b)) 39 | -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/escaping.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def matches(text, regexp): 5 | pattern = re.compile(regexp) 6 | matcher = pattern.fullmatch(text) 7 | if matcher is None: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | print(matches("a+aa", r"a+aa")) 14 | print(matches("a+aa", r"a\+aa")) 15 | print(matches("a+aa", "a\\+aa")) 16 | 17 | print("=" * 10) 18 | 19 | text = "Everything about me is a contradiction, " + \ 20 | "and so is everything about everybody else. " + \ 21 | "We are made out of oppositions; we live between two poles. " + \ 22 | "There's a philistine and an aesthete in all of us, " + \ 23 | "and a murderer and a saint. You don't reconcile the poles. " + \ 24 | "You just recognize them." 25 | 26 | print(re.split(r"\. *", text)) 27 | -------------------------------------------------------------------------------- /advanced/advanced04.decorators(functions)/opc.timing.py: -------------------------------------------------------------------------------- 1 | # source (mod): https://realpython.com/primer-on-python-decorators/ 2 | 3 | import time 4 | 5 | def timer(func): 6 | """Print the runtime of the decorated function""" 7 | def wrapper_timer(*args, **kwargs): 8 | start_time = time.perf_counter() # 1 9 | value = func(*args, **kwargs) 10 | end_time = time.perf_counter() # 2 11 | run_time = end_time - start_time # 3 12 | print(f"Finished {func.__name__!r} in {run_time:.4f} secs") 13 | return value 14 | return wrapper_timer 15 | 16 | @timer 17 | def waste_some_time(num_times): 18 | for _ in range(num_times): 19 | sum([i**2 for i in range(10000)]) 20 | 21 | for i in range(0,200,20): 22 | print(i) 23 | waste_some_time(i) 24 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/exercise03/main.py: -------------------------------------------------------------------------------- 1 | from dbtools import * 2 | 3 | 4 | def continent_cities_countries(continent): 5 | query_cnt = "SELECT name, code FROM country WHERE continent='" + continent + "'" 6 | rows_countries = query_full_results(connector, query_cnt) 7 | 8 | if len(rows_countries) > 0: 9 | for row_country in rows_countries: 10 | query_cit = "SELECT name FROM city WHERE countryCode='" + row_country["code"] + "'" 11 | row_cities = query_full_results(connector, query_cit) 12 | print(row_country["name"] + "(" + ", ".join([cityd["name"] for cityd in row_cities]) + ")") 13 | else: 14 | print("No such continent (" + continent + ")") 15 | 16 | 17 | connector = open_connection() 18 | 19 | continent_cities_countries('Europe') 20 | 21 | close_connection(connector) 22 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/exercise03/dbtools.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | 23 | 24 | def query_full_results(connection, query): 25 | try: 26 | cursor = connection.cursor(dictionary=True) 27 | cursor.execute(query) 28 | rows = cursor.fetchall() 29 | cursor.close() 30 | return rows 31 | except MYSQL.Error as e: 32 | print(e) 33 | -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/star.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def matches(text, regexp): 5 | pattern = re.compile(regexp) 6 | matcher = pattern.fullmatch(text) 7 | if matcher is None: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | print(matches("", r"a*")) 14 | print(matches("a", r"a*")) 15 | print(matches("aa", r"a*")) 16 | print(matches("aab", r"a*")) 17 | 18 | print("=" * 10) 19 | print(matches("Niger", r".*er")) 20 | print(matches("Niger", r".*em")) 21 | print(matches("Mexico", r"Me.*")) 22 | print(matches("Nexico", r"Me.*")) 23 | print(matches("Nicaragua", r".*ar.*")) 24 | print(matches("Nicaaagua", r".*ar.*")) 25 | print(matches("Morocco", r"M.*ro.*o")) 26 | 27 | print("=" * 10) 28 | print(matches("Mexico", r"(..)*")) 29 | print(matches("USA", r"(..)*")) 30 | print(matches("Burundi", r"B(u.)*di")) 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/fetchone/dbtools.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | 23 | 24 | def query_full_results(connection, query): 25 | try: 26 | cursor = connection.cursor(dictionary=True) 27 | cursor.execute(query) 28 | rows = cursor.fetchall() 29 | cursor.close() 30 | return rows 31 | except MYSQL.Error as e: 32 | print(e) 33 | 34 | 35 | -------------------------------------------------------------------------------- /modules/mod8.3.string/format_replacement.py: -------------------------------------------------------------------------------- 1 | 2 | print("{}, {}, {}".format(0, 1.1, "str")) 3 | print("{0}, {1}, {2}".format(0, 1.1, "str")) 4 | print("{1}, {2}, {0}".format(0, 1.1, "str")) 5 | print("{arg1} {arg2}".format(arg1=0, arg2=1)) 6 | print("{arg2}, {arg1}, {1}, {0}".format(0, 1, arg1=0, arg2=1)) 7 | 8 | 9 | class Time: 10 | def __init__(self, hour, minute, second): 11 | self.hour = hour 12 | self.minute = minute 13 | self.second = second 14 | 15 | def __str__(self): 16 | return f"{str(self.hour).zfill(2)}:" \ 17 | f"{str(self.minute).zfill(2)}:" \ 18 | f"{str(self.second).zfill(2)}" 19 | 20 | def __repr__(self): 21 | return f"Time({self.hour},{self.minute},{self.second})" 22 | 23 | 24 | t = Time(4, 48, 0) 25 | print("str={0!s}\nrepr={now!r}\nascii={now}".format(t, now=t)) 26 | -------------------------------------------------------------------------------- /modules/mod2.4.enum/functionality.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | 3 | class Days(Enum): 4 | MONDAY = 1 5 | TUESDAY = 2 6 | WEDNESDAY = 3 7 | THURSDAY = 4 8 | FRIDAY = 5 9 | SATURDAY = 6 10 | SUNDAY = 7 11 | 12 | 13 | print("="*30) 14 | # iterable 15 | for day in Days: 16 | print(day) 17 | 18 | print("="*30) 19 | # hashable 20 | workload = {Days.MONDAY: "a lot", 21 | Days.TUESDAY: "a little", 22 | Days.SUNDAY: "nothing"} 23 | print(workload) 24 | 25 | print("="*30) 26 | # get an enum member 27 | print(Days.WEDNESDAY) # usual way 28 | print(Days["WEDNESDAY"]) # by member name 29 | print(Days(3)) # by member value 30 | 31 | print("="*30) 32 | # comparisons 33 | print(Days.MONDAY==Days.MONDAY) 34 | print(Days.MONDAY!=Days.TUESDAY) 35 | try: 36 | print(Days.MONDAY other.hour: 18 | return True 19 | elif self.hour == other.hour: 20 | if self.minute > other.minute: 21 | return True 22 | elif self.minute == other.minute: 23 | if self.second > other.second: 24 | return True 25 | return False 26 | 27 | def __eq__(self, other): 28 | if self.hour == other.hour and self.minute == other.minute and self.second == other.second: 29 | return True 30 | return False 31 | 32 | 33 | t = Time(11,1,2) 34 | t2 = Time(11,1,1) 35 | print(f"{t} > {t2}: {t>t2}") 36 | print(f"{t} < {t2}: {t= {t2}: {t>=t2}") 38 | print(f"{t} <= {t2}: {t<=t2}") 39 | print(f"{t} == {t2}: {t==t2}") 40 | print(f"{t} != {t2}: {t!=t2}") -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/exercise1/main.py: -------------------------------------------------------------------------------- 1 | from dbtools import * 2 | from country import Country 3 | 4 | connector = open_connection() 5 | 6 | try: 7 | c = Country(connector) 8 | while True: 9 | print("="*20) 10 | print("Menu (Current country: " + str(c.name) + ")") 11 | print("="*20) 12 | print("1-Load Country") 13 | print("2-Insert New Country") 14 | print("3-Update Country") 15 | print("4-Delete Country") 16 | print("5-Print Country") 17 | print("6-Save Country") 18 | print("7-Exit") 19 | choice = int(input("Your choice: ")) 20 | if choice == 1: 21 | code = input("Give country code: ") 22 | c.load_country(code) 23 | if c.name is not None: 24 | c.print_country() 25 | elif choice == 2: 26 | c.insert_country() 27 | elif choice == 3: 28 | c.update_country() 29 | elif choice == 4: 30 | c.delete_country() 31 | c = Country(connector) 32 | elif choice == 5: 33 | c.print_country() 34 | elif choice == 6: 35 | c.save_country() 36 | else: 37 | break 38 | 39 | except MYSQL.Error as e: 40 | print(e) 41 | 42 | close_connection(connector) 43 | -------------------------------------------------------------------------------- /advanced/advanced01.pip/surface3d_demo3.py: -------------------------------------------------------------------------------- 1 | ''' 2 | ========================= 3 | 3D surface (checkerboard) 4 | ========================= 5 | 6 | Demonstrates plotting a 3D surface colored in a checkerboard pattern. 7 | ''' 8 | 9 | from mpl_toolkits.mplot3d import Axes3D 10 | import matplotlib.pyplot as plt 11 | from matplotlib import cm 12 | from matplotlib.ticker import LinearLocator 13 | import numpy as np 14 | 15 | 16 | fig = plt.figure() 17 | ax = fig.gca(projection='3d') 18 | 19 | # Make data. 20 | X = np.arange(-5, 5, 0.25) 21 | xlen = len(X) 22 | Y = np.arange(-5, 5, 0.25) 23 | ylen = len(Y) 24 | X, Y = np.meshgrid(X, Y) 25 | R = np.sqrt(X**2 + Y**2) 26 | Z = np.sin(R) 27 | 28 | # Create an empty array of strings with the same shape as the meshgrid, and 29 | # populate it with two colors in a checkerboard pattern. 30 | colortuple = ('y', 'b') 31 | colors = np.empty(X.shape, dtype=str) 32 | for y in range(ylen): 33 | for x in range(xlen): 34 | colors[x, y] = colortuple[(x + y) % len(colortuple)] 35 | 36 | # Plot the surface with face colors taken from the array we made. 37 | surf = ax.plot_surface(X, Y, Z, facecolors=colors, linewidth=0) 38 | 39 | # Customize the z axis. 40 | ax.set_zlim(-1, 1) 41 | ax.w_zaxis.set_major_locator(LinearLocator(6)) 42 | 43 | plt.show() 44 | -------------------------------------------------------------------------------- /modules/mod2.5.bisect/typical_search_examples(docs).py: -------------------------------------------------------------------------------- 1 | # functions from the official docs: https://docs.python.org/3/library/bisect.html 2 | from random import randrange 3 | from bisect import bisect_left, bisect_right 4 | 5 | def index(a, x): 6 | 'Locate the leftmost value exactly equal to x' 7 | i = bisect_left(a, x) 8 | if i != len(a) and a[i] == x: 9 | return i 10 | raise ValueError 11 | 12 | def find_lt(a, x): 13 | 'Find rightmost value less than x' 14 | i = bisect_left(a, x) 15 | if i: 16 | return a[i-1] 17 | raise ValueError 18 | 19 | def find_le(a, x): 20 | 'Find rightmost value less than or equal to x' 21 | i = bisect_right(a, x) 22 | if i: 23 | return a[i-1] 24 | raise ValueError 25 | 26 | def find_gt(a, x): 27 | 'Find leftmost value greater than x' 28 | i = bisect_right(a, x) 29 | if i != len(a): 30 | return a[i] 31 | raise ValueError 32 | 33 | def find_ge(a, x): 34 | 'Find leftmost item greater than or equal to x' 35 | i = bisect_left(a, x) 36 | if i != len(a): 37 | return a[i] 38 | raise ValueError 39 | 40 | 41 | numbers = [randrange(10) for _ in range(10)] + [5, 5] 42 | numbers.sort() 43 | 44 | print(numbers) 45 | print(index(numbers, 5)) 46 | print(find_lt(numbers, 5)) 47 | print(find_le(numbers, 5)) 48 | print(find_gt(numbers, 5)) 49 | print(find_ge(numbers, 5)) -------------------------------------------------------------------------------- /modules/mod6.2.functools/partialmethod.py: -------------------------------------------------------------------------------- 1 | from functools import partialmethod 2 | 3 | 4 | class Time: 5 | def __init__(self, hour, minute, second): 6 | self.hour = hour 7 | self.minute = minute 8 | self.second = second 9 | 10 | def __str__(self): 11 | return f"{str(self.hour).zfill(2)}:" \ 12 | f"{str(self.minute).zfill(2)}:" \ 13 | f"{str(self.second).zfill(2)}" 14 | 15 | def __gt__(self, other): 16 | if self.hour > other.hour: 17 | return True 18 | elif self.hour == other.hour: 19 | if self.minute > other.minute: 20 | return True 21 | elif self.minute == other.minute: 22 | if self.second > other.second: 23 | return True 24 | return False 25 | 26 | def __eq__(self, other): 27 | if self.hour == other.hour and self.minute == other.minute and self.second == other.second: 28 | return True 29 | return False 30 | 31 | def set_hour(self, hour=0, minute=0, second=0): 32 | self.hour = hour 33 | self.minute = minute 34 | self.second = second 35 | 36 | set_midnight = partialmethod(set_hour, 0, 0, 0) 37 | set_half = partialmethod(set_hour, minute=30, second=0) 38 | 39 | 40 | t = Time(11, 1, 2) 41 | print(t) 42 | t.set_midnight() 43 | print(t) 44 | t.set_half(22) 45 | print(t) 46 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/exercise06/dbtools.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | 23 | 24 | # returns result set 25 | def query_full_results(connection, query): 26 | cursor = connection.cursor(dictionary=True) 27 | cursor.execute(query) 28 | rows = cursor.fetchall() 29 | cursor.close() 30 | return rows 31 | 32 | 33 | # iterator 34 | def query_iter_one(connection, query): 35 | try: 36 | cursor = connection.cursor(dictionary=True) 37 | cursor.execute(query) 38 | row = cursor.fetchone() 39 | while row is not None: 40 | yield row 41 | row = cursor.fetchone() 42 | cursor.close() 43 | except MYSQL.Error as e: 44 | print(e) 45 | 46 | 47 | # iterator 48 | def query_iter_many(connection, n, query): 49 | cursor = connection.cursor(dictionary=True) 50 | cursor.execute(query) 51 | rows = cursor.fetchmany(n) 52 | while rows: 53 | yield rows 54 | rows = cursor.fetchmany(n) 55 | cursor.close() -------------------------------------------------------------------------------- /modules/mod4.1.json/json_many_objects_different_types/timeclass.py: -------------------------------------------------------------------------------- 1 | class Time: 2 | def __init__(self, hour, minute, second): 3 | self.hour = hour 4 | self.minute = minute 5 | self.second = second 6 | 7 | def __str__(self): 8 | return f"{str(self.hour).zfill(2)}:" \ 9 | f"{str(self.minute).zfill(2)}:" \ 10 | f"{str(self.second).zfill(2)}" 11 | 12 | 13 | class ZonedTime(Time): 14 | def __init__(self, hour, minute, second, zone): 15 | super().__init__(hour, minute, second) 16 | self.zone = zone 17 | 18 | def __str__(self): 19 | return f"{str(self.hour).zfill(2)}:" \ 20 | f"{str(self.minute).zfill(2)}:" \ 21 | f"{str(self.second).zfill(2)} " + self.zone 22 | 23 | 24 | def time_encoder(time): 25 | if isinstance(time, ZonedTime): 26 | return {"__ZonedTime__": True, "hour": time.hour, "minute": time.minute, 27 | "second": time.second, "zone": time.zone} 28 | elif isinstance(time, Time): 29 | return {"__Time__": True, "hour": time.hour, "minute": time.minute, 30 | "second": time.second} 31 | else: 32 | raise TypeError("Type should be Time") 33 | 34 | 35 | def time_decoder(time): 36 | if "__Time__" in time: 37 | return Time(time["hour"], time["minute"], time["second"]) 38 | elif "__ZonedTime__" in time: 39 | return ZonedTime(time["hour"], time["minute"], time["second"], time["zone"]) 40 | -------------------------------------------------------------------------------- /advanced/advanced03.generators/opc.binary.tree.py: -------------------------------------------------------------------------------- 1 | # A binary tree class. 2 | # source (mod): https://www.python.org/dev/peps/pep-0255/ 3 | class Tree: 4 | 5 | def __init__(self, label, left=None, right=None): 6 | self.label = label 7 | self.left = left 8 | self.right = right 9 | 10 | def __repr__(self, level=0, indent=" "): 11 | s = level*indent + str(self.label) 12 | if self.left: 13 | s = s + "\n" + self.left.__repr__(level+1, indent) 14 | if self.right: 15 | s = s + "\n" + self.right.__repr__(level+1, indent) 16 | return s 17 | 18 | def __iter__(self): 19 | return inorder(self) 20 | 21 | # Create a Tree from a list. 22 | def tree(list): 23 | n = len(list) 24 | if n == 0: 25 | return [] 26 | i = n // 2 27 | return Tree(list[i], tree(list[:i]), tree(list[i+1:])) 28 | 29 | 30 | 31 | # A non-recursive generator. 32 | def inorder(node): 33 | stack = [] 34 | while node: 35 | while node.left: 36 | stack.append(node) 37 | node = node.left 38 | yield node.label 39 | while not node.right: 40 | try: 41 | node = stack.pop() 42 | except IndexError: 43 | return 44 | yield node.label 45 | node = node.right 46 | 47 | # Exercise the non-recursive generator. 48 | t = tree("ABCDEFGHIJKLMNOPQRSTUVWXYZ") 49 | for x in t: 50 | print(x, end="") 51 | -------------------------------------------------------------------------------- /advanced/advanced05.decorators(classes)/multiple_decorators.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | 4 | def decorate_with_lines(func): 5 | def dec(arg): 6 | print("-"*20) 7 | res = func(arg) 8 | print("-"*20) 9 | return res 10 | return dec 11 | 12 | def timeit(func): 13 | def decorator(*args, **kwargs): 14 | t0 = time.time() 15 | ret = func(*args, **kwargs) 16 | t1 = time.time() 17 | print("Total time: " + str(t1-t0)) 18 | return ret 19 | 20 | return decorator 21 | 22 | def memoize(func): 23 | def decorator(arg): 24 | 25 | if arg in results_memory: 26 | return results_memory[arg] 27 | else: 28 | results_memory[arg] = func(arg) 29 | return results_memory[arg] 30 | 31 | results_memory = {} 32 | return decorator 33 | 34 | def valid_int_gt_zero(func): 35 | def decorated(val): 36 | if not isinstance(val, int): 37 | raise TypeError("Not an integer") 38 | elif val < 0: 39 | raise ValueError("Negative value") 40 | else: 41 | return func(val) 42 | 43 | return decorated 44 | 45 | 46 | @timeit 47 | @decorate_with_lines 48 | @valid_int_gt_zero 49 | def fib(n): 50 | @memoize 51 | def recursive(n): 52 | if n == 0: 53 | return 0 54 | elif n == 1: 55 | return 1 56 | else: 57 | return recursive(n - 1) + recursive(n - 2) 58 | 59 | print(f"fib({n})={recursive(n)}") 60 | 61 | fib(68) 62 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/exercise05/dbtools.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | 23 | 24 | # returns result set 25 | def query_full_results(connection, query): 26 | try: 27 | cursor = connection.cursor(dictionary=True) 28 | cursor.execute(query) 29 | rows = cursor.fetchall() 30 | cursor.close() 31 | return rows 32 | except MYSQL.Error as e: 33 | print(e) 34 | 35 | 36 | # iterator 37 | def query_iter_one(connection, query): 38 | try: 39 | cursor = connection.cursor(dictionary=True) 40 | cursor.execute(query) 41 | row = cursor.fetchone() 42 | while row is not None: 43 | yield row 44 | row = cursor.fetchone() 45 | cursor.close() 46 | except MYSQL.Error as e: 47 | print(e) 48 | 49 | 50 | # iterator 51 | def query_iter_many(connection, n, query): 52 | cursor = connection.cursor(dictionary=True) 53 | cursor.execute(query) 54 | rows = cursor.fetchmany(n) 55 | while rows: 56 | yield rows 57 | rows = cursor.fetchmany(n) 58 | cursor.close() 59 | -------------------------------------------------------------------------------- /modules/mod2.2.collections/doubleEndedQueue/exercise12_lesson17.py: -------------------------------------------------------------------------------- 1 | 2 | from queue import Queue 3 | from random import randrange 4 | 5 | class Bank: 6 | def __init__(self, N): 7 | self.N = N 8 | self.cash_desks = [Queue() for i in range(N)] 9 | 10 | def customer_enters(self, full_name): 11 | cash_desk = randrange(self.N) 12 | self.cash_desks[cash_desk].enqueue(full_name) 13 | print(full_name + " entered! To be served by cash desk: " + str(cash_desk)) 14 | 15 | def customer_served(self): 16 | not_empty_cash_desks = [i for i in range(self.N) if len(self.cash_desks[i]) > 0] 17 | 18 | if len(not_empty_cash_desks) > 0: 19 | cash_desk = not_empty_cash_desks[randrange(len(not_empty_cash_desks))] 20 | customer = self.cash_desks[cash_desk].dequeue() 21 | print(f"{customer} served by cash desk {cash_desk}") 22 | else: 23 | print("No customers.") 24 | 25 | def __str__(self): 26 | st = "\n" + "=" * 20 27 | for i in range(self.N): 28 | st += "\nCash Desk " + str(i) +": " 29 | st += str(self.cash_desks[i]) 30 | st += "\n" + "=" * 20 31 | return st 32 | 33 | 34 | def main(): 35 | bank = Bank(3) 36 | 37 | for i in range(100): 38 | num = randrange(100) 39 | if num <=29: 40 | bank.customer_served() 41 | else: 42 | bank.customer_enters("Cust" + str(randrange(1000))) 43 | 44 | if i % 10 == 0: 45 | print(bank) 46 | 47 | print("BANK CLOSED") 48 | 49 | main() -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/insert/dbtools.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | 23 | 24 | # returns result set 25 | def query_full_results(connection, query): 26 | cursor = connection.cursor(dictionary=True) 27 | cursor.execute(query) 28 | rows = cursor.fetchall() 29 | cursor.close() 30 | return rows 31 | 32 | 33 | # iterator 34 | def query_iter_one(connection, query): 35 | try: 36 | cursor = connection.cursor(dictionary=True) 37 | cursor.execute(query) 38 | row = cursor.fetchone() 39 | while row is not None: 40 | yield row 41 | row = cursor.fetchone() 42 | cursor.close() 43 | except MYSQL.Error as e: 44 | print(e) 45 | 46 | 47 | # iterator 48 | def query_iter_many(connection, n, query): 49 | cursor = connection.cursor(dictionary=True) 50 | cursor.execute(query) 51 | rows = cursor.fetchmany(n) 52 | while rows: 53 | yield rows 54 | rows = cursor.fetchmany(n) 55 | cursor.close() 56 | 57 | 58 | def insert_query(connection, query): 59 | cursor = connection.cursor() 60 | cursor.execute(query) 61 | 62 | lastrowid = None 63 | if cursor.lastrowid: 64 | lastrowid = cursor.lastrowid 65 | 66 | cursor.close() 67 | 68 | return lastrowid 69 | -------------------------------------------------------------------------------- /modules/mod1.3.decimal/opc.money.py: -------------------------------------------------------------------------------- 1 | # source(mod): https://docs.python.org/3/library/decimal.html 2 | 3 | from decimal import Decimal 4 | D=Decimal 5 | 6 | def moneyfmt(value, places=2, curr='', sep=',', dp='.', 7 | pos='', neg='-', trailneg=''): 8 | """Convert Decimal to a money formatted string. 9 | 10 | places: required number of places after the decimal point 11 | curr: optional currency symbol before the sign (may be blank) 12 | sep: optional grouping separator (comma, period, space, or blank) 13 | dp: decimal point indicator (comma or period) 14 | only specify as blank when places is zero 15 | pos: optional sign for positive numbers: '+', space or blank 16 | neg: optional sign for negative numbers: '-', '(', space or blank 17 | trailneg:optional trailing minus indicator: '-', ')', space or blank 18 | """ 19 | q = Decimal(10) ** -places # 2 places --> '0.01' 20 | sign, digits, exp = value.quantize(q).as_tuple() 21 | result = [] 22 | digits = list(map(str, digits)) 23 | build, next = result.append, digits.pop 24 | if sign: 25 | build(trailneg) 26 | for i in range(places): 27 | build(next() if digits else '0') 28 | if places: 29 | build(dp) 30 | if not digits: 31 | build('0') 32 | i = 0 33 | while digits: 34 | build(next()) 35 | i += 1 36 | if i == 3 and digits: 37 | i = 0 38 | build(sep) 39 | build(curr) 40 | build(neg if sign else pos) 41 | return ''.join(reversed(result)) 42 | 43 | d = D('-1234567.8901') 44 | print(moneyfmt(d, curr='$')) 45 | print(moneyfmt(d, places=0, sep='.', dp='', neg='', trailneg='-')) 46 | print(moneyfmt(d, curr='$', neg='(', trailneg=')')) 47 | print(moneyfmt(Decimal(123456789), sep=' ')) 48 | print(moneyfmt(Decimal('-0.02'), neg='<', trailneg='>')) 49 | 50 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/upd_del/dbtools.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | 23 | 24 | # returns result set 25 | def query_full_results(connection, query): 26 | cursor = connection.cursor(dictionary=True) 27 | cursor.execute(query) 28 | rows = cursor.fetchall() 29 | cursor.close() 30 | return rows 31 | 32 | 33 | # iterator 34 | def query_iter_one(connection, query): 35 | try: 36 | cursor = connection.cursor(dictionary=True) 37 | cursor.execute(query) 38 | row = cursor.fetchone() 39 | while row is not None: 40 | yield row 41 | row = cursor.fetchone() 42 | cursor.close() 43 | except MYSQL.Error as e: 44 | print(e) 45 | 46 | 47 | # iterator 48 | def query_iter_many(connection, n, query): 49 | cursor = connection.cursor(dictionary=True) 50 | cursor.execute(query) 51 | rows = cursor.fetchmany(n) 52 | while rows: 53 | yield rows 54 | rows = cursor.fetchmany(n) 55 | cursor.close() 56 | 57 | 58 | def insert_query(connection, query): 59 | cursor = connection.cursor() 60 | cursor.execute(query) 61 | 62 | lastrowid = None 63 | if cursor.lastrowid: 64 | lastrowid = cursor.lastrowid 65 | 66 | cursor.close() 67 | return lastrowid 68 | 69 | 70 | def update_query(connection, query): 71 | cursor = connection.cursor() 72 | cursor.execute(query) 73 | cursor.close() 74 | 75 | 76 | def delete_query(connection, query): 77 | cursor = connection.cursor() 78 | cursor.execute(query) 79 | cursor.close() 80 | 81 | -------------------------------------------------------------------------------- /modules/mod1.2.random/opc.dice.py: -------------------------------------------------------------------------------- 1 | """ 2 | game: dice 3 | source: http://hplgit.github.io/primer.html/doc/pub/random/._random-readable004.html#sec:random:twodicesumguess 4 | """ 5 | 6 | import random, sys 7 | 8 | class Dice: 9 | def __init__(self, n=1): 10 | self.n = n # no of dice 11 | 12 | def throw(self): 13 | return [random.randint(1,6) for i in range(self.n)] 14 | 15 | class Player(object): 16 | def __init__(self, name, capital, guess_function, ndice): 17 | self.name = name 18 | self.capital = capital 19 | self.guess_function = guess_function 20 | self.dice = Dice(ndice) 21 | 22 | def play_one_round(self): 23 | self.guess = self.guess_function(self.dice.n) 24 | self.throw = sum(self.dice.throw()) 25 | if self.guess == self.throw: 26 | self.capital += self.guess 27 | else: 28 | self.capital -= 1 29 | self.message() 30 | self.broke() 31 | 32 | def message(self): 33 | print('%s guessed %d, got %d' % (self.name, self.guess, self.throw)) 34 | 35 | def broke(self): 36 | if self.capital == 0: 37 | print('%s lost!' % self.name) 38 | sys.exit(0) # end the program 39 | 40 | def computer_guess(ndice): 41 | # All guesses have the same probability 42 | return random.randint(ndice, 6*ndice) 43 | 44 | def player_guess(ndice): 45 | return int(input('Guess the sum of the no of eyes in the next throw: ')) 46 | 47 | def play(nrounds, ndice=2): 48 | player = Player('YOU', nrounds, player_guess, ndice) 49 | computer = Player('Computer', nrounds, computer_guess, ndice) 50 | 51 | for i in range(nrounds): 52 | player.play_one_round() 53 | computer.play_one_round() 54 | print('Status: user has %d euro, machine has %d euro\n' % (player.capital, computer.capital)) 55 | 56 | if computer.capital > player.capital: 57 | winner = 'Machine' 58 | else: 59 | winner = 'You' 60 | print(winner, 'won!') 61 | 62 | 63 | play(8, 1) -------------------------------------------------------------------------------- /modules/mod1.2.random/opc.resampling.py: -------------------------------------------------------------------------------- 1 | """ 2 | game: two dice 3 | source: http://hplgit.github.io/primer.html/doc/pub/random/._random-readable004.html#sec:random:twodicesumguess 4 | """ 5 | 6 | import random, sys 7 | 8 | class Dice: 9 | def __init__(self, n=1): 10 | self.n = n # no of dice 11 | 12 | def throw(self): 13 | return [random.randint(1,6) for i in range(self.n)] 14 | 15 | class Player(object): 16 | def __init__(self, name, capital, guess_function, ndice): 17 | self.name = name 18 | self.capital = capital 19 | self.guess_function = guess_function 20 | self.dice = Dice(ndice) 21 | 22 | def play_one_round(self): 23 | self.guess = self.guess_function(self.dice.n) 24 | self.throw = sum(self.dice.throw()) 25 | if self.guess == self.throw: 26 | self.capital += self.guess 27 | else: 28 | self.capital -= 1 29 | self.message() 30 | self.broke() 31 | 32 | def message(self): 33 | print('%s guessed %d, got %d' % (self.name, self.guess, self.throw)) 34 | 35 | def broke(self): 36 | if self.capital == 0: 37 | print('%s lost!' % self.name) 38 | sys.exit(0) # end the program 39 | 40 | def computer_guess(ndice): 41 | # All guesses have the same probability 42 | return random.randint(ndice, 6*ndice) 43 | 44 | def player_guess(ndice): 45 | return int(input('Guess the sum of the no of eyes in the next throw: ')) 46 | 47 | def play(nrounds, ndice=2): 48 | player = Player('YOU', nrounds, player_guess, ndice) 49 | computer = Player('Computer', nrounds, computer_guess, ndice) 50 | 51 | for i in range(nrounds): 52 | player.play_one_round() 53 | computer.play_one_round() 54 | print('Status: user has %d euro, machine has %d euro\n' % (player.capital, computer.capital)) 55 | 56 | if computer.capital > player.capital: 57 | winner = 'Machine' 58 | else: 59 | winner = 'You' 60 | print(winner, 'won!') 61 | 62 | 63 | play(8, 1) -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/stored_proc/dbtools.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | 23 | 24 | # returns result set 25 | def query_full_results(connection, query): 26 | cursor = connection.cursor(dictionary=True) 27 | cursor.execute(query) 28 | rows = cursor.fetchall() 29 | cursor.close() 30 | return rows 31 | 32 | 33 | # iterator 34 | def query_iter_one(connection, query): 35 | try: 36 | cursor = connection.cursor(dictionary=True) 37 | cursor.execute(query) 38 | row = cursor.fetchone() 39 | while row is not None: 40 | yield row 41 | row = cursor.fetchone() 42 | cursor.close() 43 | except MYSQL.Error as e: 44 | print(e) 45 | 46 | 47 | # iterator 48 | def query_iter_many(connection, n, query): 49 | cursor = connection.cursor(dictionary=True) 50 | cursor.execute(query) 51 | rows = cursor.fetchmany(n) 52 | while rows: 53 | yield rows 54 | rows = cursor.fetchmany(n) 55 | cursor.close() 56 | 57 | 58 | def insert_query(connection, query): 59 | cursor = connection.cursor() 60 | cursor.execute(query) 61 | 62 | lastrowid = None 63 | if cursor.lastrowid: 64 | lastrowid = cursor.lastrowid 65 | cursor.close() 66 | 67 | return lastrowid 68 | 69 | 70 | def update_query(connection, query): 71 | cursor = connection.cursor() 72 | cursor.execute(query) 73 | cursor.close() 74 | 75 | 76 | def delete_query(connection, query): 77 | cursor = connection.cursor() 78 | cursor.execute(query) 79 | cursor.close() 80 | 81 | 82 | def call_stored(connection, stored_proc_name, list_args): 83 | cursor = connection.cursor(dictionary=True) 84 | cursor.callproc(stored_proc_name, list_args) 85 | 86 | results = [] 87 | for result in cursor.stored_results(): 88 | results += result.fetchall() 89 | 90 | cursor.close() 91 | return results 92 | 93 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson01/exercise06/main.py: -------------------------------------------------------------------------------- 1 | from dbtools import * 2 | 3 | 4 | def print_country(country): 5 | print("="*35) 6 | print(f"Code: {country['Code']}") 7 | print(f"Name: {country['Name']}") 8 | print(f"Continent: {country['Continent']}") 9 | print(f"Region: {country['Region']}") 10 | print(f"Surface Area: {country['SurfaceArea']}") 11 | print(f"Independence Year: {country['IndepYear']}") 12 | print(f"Population: {country['Population']}") 13 | print(f"Life Expectancy: {country['LifeExpectancy']}") 14 | print(f"GNP: {country['GNP']}") 15 | print(f"GNPold: {country['GNPOld']}") 16 | print(f"Local Name: {country['LocalName']}") 17 | print(f"Government Form: {country['GovernmentForm']}") 18 | print(f"Head of State: {country['HeadOfState']}") 19 | print(f"Capital: {country['Capital']}") 20 | print(f"Code2: {country['Code2']}") 21 | 22 | 23 | connector = open_connection() 24 | 25 | try: 26 | # build query 27 | where_continent = "" 28 | print("Criterion 1: Continent") 29 | print("1-Specify continent") 30 | print("2-Don't specify continent") 31 | choice = int(input("Your choice: ")) 32 | if choice == 1: 33 | continent = input("Give continent: ") 34 | where_continent = " Continent='" + continent + "' " 35 | 36 | where_indep_year = "" 37 | print("Criterion 2: Independence Year") 38 | print("1-Specify independence year") 39 | print("2-Don't specify independence year") 40 | choice = int(input("Your choice: ")) 41 | if choice == 1: 42 | year_from = int(input("From Year: ")) 43 | year_to = int(input("To Year: ")) 44 | where_indep_year = " IndepYear BETWEEN " + str(year_from) + " AND " + str(year_to) + " " 45 | 46 | where_head_of_state = "" 47 | print("Criterion 3: Head of State") 48 | print("1-Specify head of state") 49 | print("2-Don't specify head of state") 50 | choice = int(input("Your choice: ")) 51 | if choice == 1: 52 | governor = input("Give part(or whole)name of head of state: ") 53 | where_head_of_state = " HeadOfState LIKE '%" + str(governor) + "%' " 54 | 55 | list_clauses = [] 56 | if len(where_continent) > 0: 57 | list_clauses.append(where_continent) 58 | if len(where_indep_year) > 0: 59 | list_clauses.append(where_indep_year) 60 | if len(where_head_of_state) > 0: 61 | list_clauses.append(where_head_of_state) 62 | where_clause = " AND ".join(list_clauses) 63 | if len(where_clause) > 0: 64 | where_clause = "WHERE " + where_clause 65 | 66 | query = "SELECT * FROM country " + where_clause 67 | 68 | iter_query = query_iter_many(connector, 5, query) 69 | 70 | for countries in iter_query: 71 | for country in countries: 72 | print_country(country) 73 | print("="*10 + ". Next? Press Enter...", end="") 74 | input() 75 | 76 | except MYSQL.Error as e: 77 | print(e) 78 | 79 | close_connection(connector) 80 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/blobs/dbtools.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | 23 | 24 | # returns result set 25 | def query_full_results(connection, query): 26 | cursor = connection.cursor(dictionary=True) 27 | cursor.execute(query) 28 | rows = cursor.fetchall() 29 | cursor.close() 30 | return rows 31 | 32 | 33 | # iterator 34 | def query_iter_one(connection, query): 35 | try: 36 | cursor = connection.cursor(dictionary=True) 37 | cursor.execute(query) 38 | row = cursor.fetchone() 39 | while row is not None: 40 | yield row 41 | row = cursor.fetchone() 42 | cursor.close() 43 | except MYSQL.Error as e: 44 | print(e) 45 | 46 | 47 | # iterator 48 | def query_iter_many(connection, n, query): 49 | cursor = connection.cursor(dictionary=True) 50 | cursor.execute(query) 51 | rows = cursor.fetchmany(n) 52 | while rows: 53 | yield rows 54 | rows = cursor.fetchmany(n) 55 | cursor.close() 56 | 57 | 58 | def insert_query(connection, query): 59 | cursor = connection.cursor() 60 | cursor.execute(query) 61 | 62 | lastrowid = None 63 | if cursor.lastrowid: 64 | lastrowid = cursor.lastrowid 65 | cursor.close() 66 | 67 | return lastrowid 68 | 69 | 70 | def update_query(connection, query): 71 | cursor = connection.cursor() 72 | cursor.execute(query) 73 | cursor.close() 74 | 75 | 76 | def delete_query(connection, query): 77 | cursor = connection.cursor() 78 | cursor.execute(query) 79 | cursor.close() 80 | 81 | 82 | def call_stored(connection, stored_proc_name, list_args): 83 | cursor = connection.cursor(dictionary=True) 84 | cursor.callproc(stored_proc_name, list_args) 85 | 86 | results = [] 87 | for result in cursor.stored_results(): 88 | results += result.fetchall() 89 | 90 | cursor.close() 91 | return results 92 | 93 | 94 | def insert_with_blob(connection, filename, descr): 95 | 96 | with open(filename, "rb") as f: 97 | contents = f.read() 98 | 99 | query = "INSERT INTO images (image, descr) VALUES(%s, %s)" 100 | insert_tuple = (contents, descr) 101 | 102 | cursor = connection.cursor() 103 | cursor.execute(query, insert_tuple) 104 | 105 | cursor.close() 106 | 107 | 108 | def read_blob(connection, id): 109 | results = query_full_results(connection, "SELECT * FROM images WHERE image_id=" + str(id)) 110 | print(results) 111 | return results[0]["image"] 112 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/dates/dbtools.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | 23 | 24 | # returns result set 25 | def query_full_results(connection, query): 26 | cursor = connection.cursor(dictionary=True) 27 | cursor.execute(query) 28 | rows = cursor.fetchall() 29 | cursor.close() 30 | return rows 31 | 32 | 33 | # iterator 34 | def query_iter_one(connection, query): 35 | try: 36 | cursor = connection.cursor(dictionary=True) 37 | cursor.execute(query) 38 | row = cursor.fetchone() 39 | while row is not None: 40 | yield row 41 | row = cursor.fetchone() 42 | cursor.close() 43 | except MYSQL.Error as e: 44 | print(e) 45 | 46 | 47 | # iterator 48 | def query_iter_many(connection, n, query): 49 | cursor = connection.cursor(dictionary=True) 50 | cursor.execute(query) 51 | rows = cursor.fetchmany(n) 52 | while rows: 53 | yield rows 54 | rows = cursor.fetchmany(n) 55 | cursor.close() 56 | 57 | 58 | def insert_query(connection, query): 59 | cursor = connection.cursor() 60 | cursor.execute(query) 61 | 62 | lastrowid = None 63 | if cursor.lastrowid: 64 | lastrowid = cursor.lastrowid 65 | cursor.close() 66 | 67 | return lastrowid 68 | 69 | 70 | def update_query(connection, query): 71 | cursor = connection.cursor() 72 | cursor.execute(query) 73 | cursor.close() 74 | 75 | 76 | def delete_query(connection, query): 77 | cursor = connection.cursor() 78 | cursor.execute(query) 79 | cursor.close() 80 | 81 | 82 | def call_stored(connection, stored_proc_name, list_args): 83 | cursor = connection.cursor(dictionary=True) 84 | cursor.callproc(stored_proc_name, list_args) 85 | 86 | results = [] 87 | for result in cursor.stored_results(): 88 | results += result.fetchall() 89 | 90 | cursor.close() 91 | return results 92 | 93 | 94 | def insert_with_blob(connection, filename, descr): 95 | 96 | with open(filename, "rb") as f: 97 | contents = f.read() 98 | 99 | query = "INSERT INTO images (image, descr) VALUES(%s, %s)" 100 | insert_tuple = (contents, descr) 101 | 102 | cursor = connection.cursor() 103 | cursor.execute(query, insert_tuple) 104 | 105 | cursor.close() 106 | 107 | 108 | def read_blob(connection, id): 109 | results = query_full_results(connection, "SELECT * FROM images WHERE image_id=" + str(id)) 110 | print(results) 111 | return results[0]["image"] 112 | 113 | 114 | def insert_with_tuple(connection, query, insert_tuple): 115 | cursor = connection.cursor() 116 | cursor.execute(query, insert_tuple) 117 | cursor.close() 118 | 119 | -------------------------------------------------------------------------------- /packages/01.MySQL/lesson02/exercise1/dbtools.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | MYSQL = mysql.connector 3 | 4 | 5 | def open_connection(): 6 | try: 7 | return MYSQL.connect( 8 | host="localhost", 9 | user="pythonuser", 10 | password="pwd1234", 11 | database="pyworld" 12 | ) 13 | except MYSQL.Error as e: 14 | print(e) 15 | 16 | 17 | def close_connection(connection): 18 | try: 19 | connection.close() 20 | except MYSQL.Error as e: 21 | print(e) 22 | 23 | 24 | # returns result set 25 | def query_full_results(connection, query): 26 | cursor = connection.cursor(dictionary=True) 27 | cursor.execute(query) 28 | rows = cursor.fetchall() 29 | cursor.close() 30 | return rows 31 | 32 | 33 | # iterator 34 | def query_iter_one(connection, query): 35 | try: 36 | cursor = connection.cursor(dictionary=True) 37 | cursor.execute(query) 38 | row = cursor.fetchone() 39 | while row is not None: 40 | yield row 41 | row = cursor.fetchone() 42 | cursor.close() 43 | except MYSQL.Error as e: 44 | print(e) 45 | 46 | 47 | # iterator 48 | def query_iter_many(connection, n, query): 49 | cursor = connection.cursor(dictionary=True) 50 | cursor.execute(query) 51 | rows = cursor.fetchmany(n) 52 | while rows: 53 | yield rows 54 | rows = cursor.fetchmany(n) 55 | cursor.close() 56 | 57 | 58 | def insert_query(connection, query): 59 | cursor = connection.cursor() 60 | cursor.execute(query) 61 | 62 | lastrowid = None 63 | if cursor.lastrowid: 64 | lastrowid = cursor.lastrowid 65 | cursor.close() 66 | 67 | return lastrowid 68 | 69 | 70 | def update_query(connection, query): 71 | cursor = connection.cursor() 72 | cursor.execute(query) 73 | cursor.close() 74 | 75 | 76 | def delete_query(connection, query): 77 | cursor = connection.cursor() 78 | cursor.execute(query) 79 | cursor.close() 80 | 81 | 82 | def call_stored(connection, stored_proc_name, list_args): 83 | cursor = connection.cursor(dictionary=True) 84 | cursor.callproc(stored_proc_name, list_args) 85 | 86 | results = [] 87 | for result in cursor.stored_results(): 88 | results += result.fetchall() 89 | 90 | cursor.close() 91 | return results 92 | 93 | 94 | def insert_with_blob(connection, filename, descr): 95 | 96 | with open(filename, "rb") as f: 97 | contents = f.read() 98 | 99 | query = "INSERT INTO images (image, descr) VALUES(%s, %s)" 100 | insert_tuple = (contents, descr) 101 | 102 | cursor = connection.cursor() 103 | cursor.execute(query, insert_tuple) 104 | 105 | cursor.close() 106 | 107 | 108 | def read_blob(connection, id): 109 | results = query_full_results(connection, "SELECT * FROM images WHERE image_id=" + str(id)) 110 | print(results) 111 | return results[0]["image"] 112 | 113 | 114 | def insert_with_tuple(connection, query, insert_tuple): 115 | cursor = connection.cursor() 116 | cursor.execute(query, insert_tuple) 117 | cursor.close() 118 | 119 | -------------------------------------------------------------------------------- /modules/mod8.1.re(a)/pies.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Οι Πίτες του Πίτου - Οι Πίτες 7 | 8 | 9 | 10 |
11 |

Οι Πίτες του Πίτου

12 |

Ποιοτικές πίτες - μόνο χειροποίητο φύλλο

13 | 20 |
21 | 22 |
23 |

Οι Πίτες

24 |
25 |

Οι πίτες μας

26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
ΣπανακόπιταΣπανακόπιτα4€
ΜανιταρόπιταΜανιταρόπιτα5.5€
ΠρασόπιταΠρασόπιτα3.5€
ΜπουρέκιΜπουρέκι4.5€
48 |
49 |
50 |

Οι πίτες μας στο χώρο σας!

51 |

52 | Ωράριο λήψης παραγγελιών (18:00-22:00) 53 |

54 |
55 |
56 | 57 | Πληροφορίες Παράδοσης: 58 | 59 | 60 | 61 | (*) 62 |
63 | 64 | 65 | (*) 66 |
67 | 68 | 74 |
75 | 76 | 77 |
78 | 79 | 80 | (*) 81 |
82 | 83 |
84 | 85 |
86 | (*) Τα πεδία είναι υποχρεωτικά 87 |
88 | 89 |
90 | 91 | Παραγγελία: 92 | 93 |
    94 |
  • 95 | 96 | 97 |
  • 98 |
  • 99 | 100 | 101 |
  • 102 |
  • 103 | 104 | 105 |
  • 106 |
  • 107 | 108 | 109 |
  • 110 |
111 | 112 | 113 |
114 | 115 |
116 | 117 | Τρόπος Πληρωμής: 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 |
126 |
127 | 128 | 129 | 130 |
131 |
132 |
133 | 134 | 139 | 140 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /modules/mod8.2.re(b)/pies.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Οι Πίτες του Πίτου - Οι Πίτες 7 | 8 | 9 | 10 |
11 |

Οι Πίτες του Πίτου

12 |

Ποιοτικές πίτες - μόνο χειροποίητο φύλλο

13 | 20 |
21 | 22 |
23 |

Οι Πίτες

24 |
25 |

Οι πίτες μας

26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
ΣπανακόπιταΣπανακόπιτα4€
ΜανιταρόπιταΜανιταρόπιτα5.5€
ΠρασόπιταΠρασόπιτα3.5€
ΜπουρέκιΜπουρέκι4.5€
48 |
49 |
50 |

Οι πίτες μας στο χώρο σας!

51 |

52 | Ωράριο λήψης παραγγελιών (18:00-22:00) 53 |

54 |
55 |
56 | 57 | Πληροφορίες Παράδοσης: 58 | 59 | 60 | 61 | (*) 62 |
63 | 64 | 65 | (*) 66 |
67 | 68 | 74 |
75 | 76 | 77 |
78 | 79 | 80 | (*) 81 |
82 | 83 |
84 | 85 |
86 | (*) Τα πεδία είναι υποχρεωτικά 87 |
88 | 89 |
90 | 91 | Παραγγελία: 92 | 93 |
    94 |
  • 95 | 96 | 97 |
  • 98 |
  • 99 | 100 | 101 |
  • 102 |
  • 103 | 104 | 105 |
  • 106 |
  • 107 | 108 | 109 |
  • 110 |
111 | 112 | 113 |
114 | 115 |
116 | 117 | Τρόπος Πληρωμής: 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 |
126 |
127 | 128 | 129 | 130 |
131 |
132 |
133 | 134 | 139 | 140 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /modules/mod8.2.re(b)/pies2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Οι Πίτες του Πίτου - Οι Πίτες 7 | 8 | 9 | 10 |
11 |

Οι Πίτες του Πίτου

12 |

Ποιοτικές πίτες - μόνο χειροποίητο φύλλο

13 | 20 |
21 | 22 |
23 |

Οι Πίτες

24 |
25 |

Οι πίτες μας

26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
ΣπανακόπιταΣπανακόπιτα4€
ΜανιταρόπιταΜανιταρόπιτα5.5€
ΠρασόπιταΠρασόπιτα3.5€
ΜπουρέκιΜπουρέκι4.5€
48 |
49 |
50 |

Οι πίτες μας στο χώρο σας!

51 |

52 | Ωράριο λήψης παραγγελιών (18:00-22:00) 53 |

54 |
55 |
56 | 57 | Πληροφορίες Παράδοσης: 58 | 59 | 60 | 61 | (*) 62 |
63 | 64 | 65 | (*) 66 |
67 | 68 | 74 |
75 | 76 | 77 |
78 | 79 | 80 | (*) 81 |
82 | 83 |
84 | 85 |
86 | (*) Τα πεδία είναι υποχρεωτικά 87 |
88 | 89 |
90 | 91 | Παραγγελία: 92 | 93 |
    94 |
  1. 95 | 96 | 97 |
  2. 98 |
  3. 99 | 100 | 101 |
  4. 102 |
  5. 103 | 104 | 105 |
  6. 106 |
  7. 107 | 108 | 109 |
  8. 110 |
111 | 112 | 113 |
114 | 115 |
116 | 117 | Τρόπος Πληρωμής: 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 |
126 |
127 | 128 | 129 | 130 |
131 |
132 |
133 | 134 | 139 | 140 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /modules/mod7.1.csv/countries_new3.csv: -------------------------------------------------------------------------------- 1 | Name,Continent 2 | Aruba,North America 3 | Afghanistan,Asia 4 | Angola,Africa 5 | Anguilla,North America 6 | Albania,Europe 7 | Andorra,Europe 8 | Netherlands Antilles,North America 9 | United Arab Emirates,Asia 10 | Argentina,South America 11 | Armenia,Asia 12 | American Samoa,Oceania 13 | Antarctica,Antarctica 14 | French Southern territories,Antarctica 15 | Antigua and Barbuda,North America 16 | Australia,Oceania 17 | Austria,Europe 18 | Azerbaijan,Asia 19 | Burundi,Africa 20 | Belgium,Europe 21 | Benin,Africa 22 | Burkina Faso,Africa 23 | Bangladesh,Asia 24 | Bulgaria,Europe 25 | Bahrain,Asia 26 | Bahamas,North America 27 | Bosnia and Herzegovina,Europe 28 | Belarus,Europe 29 | Belize,North America 30 | Bermuda,North America 31 | Bolivia,South America 32 | Brazil,South America 33 | Barbados,North America 34 | Brunei,Asia 35 | Bhutan,Asia 36 | Bouvet Island,Antarctica 37 | Botswana,Africa 38 | Central African Republic,Africa 39 | Canada,North America 40 | Cocos (Keeling) Islands,Oceania 41 | Switzerland,Europe 42 | Chile,South America 43 | China,Asia 44 | Côte d’Ivoire,Africa 45 | Cameroon,Africa 46 | "Congo, The Democratic Republic of the",Africa 47 | Congo,Africa 48 | Cook Islands,Oceania 49 | Colombia,South America 50 | Comoros,Africa 51 | Cape Verde,Africa 52 | Costa Rica,North America 53 | Cuba,North America 54 | Christmas Island,Oceania 55 | Cayman Islands,North America 56 | Cyprus,Asia 57 | Czech Republic,Europe 58 | Germany,Europe 59 | Djibouti,Africa 60 | Dominica,North America 61 | Denmark,Europe 62 | Dominican Republic,North America 63 | Algeria,Africa 64 | Ecuador,South America 65 | Egypt,Africa 66 | Eritrea,Africa 67 | Western Sahara,Africa 68 | Spain,Europe 69 | Estonia,Europe 70 | Ethiopia,Africa 71 | Finland,Europe 72 | Fiji Islands,Oceania 73 | Falkland Islands,South America 74 | France,Europe 75 | Faroe Islands,Europe 76 | "Micronesia, Federated States of",Oceania 77 | Gabon,Africa 78 | United Kingdom,Europe 79 | Georgia,Asia 80 | Ghana,Africa 81 | Gibraltar,Europe 82 | Guinea,Africa 83 | Guadeloupe,North America 84 | Gambia,Africa 85 | Guinea-Bissau,Africa 86 | Equatorial Guinea,Africa 87 | Greece,Europe 88 | Grenada,North America 89 | Greenland,North America 90 | Guatemala,North America 91 | French Guiana,South America 92 | Guam,Oceania 93 | Guyana,South America 94 | Hong Kong,Asia 95 | Heard Island and McDonald Islands,Antarctica 96 | Honduras,North America 97 | Croatia,Europe 98 | Haiti,North America 99 | Hungary,Europe 100 | Indonesia,Asia 101 | India,Asia 102 | British Indian Ocean Territory,Africa 103 | Ireland,Europe 104 | Iran,Asia 105 | Iraq,Asia 106 | Iceland,Europe 107 | Israel,Asia 108 | Italy,Europe 109 | Jamaica,North America 110 | Jordan,Asia 111 | Japan,Asia 112 | Kazakstan,Asia 113 | Kenya,Africa 114 | Kyrgyzstan,Asia 115 | Cambodia,Asia 116 | Kiribati,Oceania 117 | Saint Kitts and Nevis,North America 118 | South Korea,Asia 119 | Kuwait,Asia 120 | Laos,Asia 121 | Lebanon,Asia 122 | Liberia,Africa 123 | Libyan Arab Jamahiriya,Africa 124 | Saint Lucia,North America 125 | Liechtenstein,Europe 126 | Sri Lanka,Asia 127 | Lesotho,Africa 128 | Lithuania,Europe 129 | Luxembourg,Europe 130 | Latvia,Europe 131 | Macao,Asia 132 | Morocco,Africa 133 | Monaco,Europe 134 | Moldova,Europe 135 | Madagascar,Africa 136 | Maldives,Asia 137 | Mexico,North America 138 | Marshall Islands,Oceania 139 | Macedonia,Europe 140 | Mali,Africa 141 | Malta,Europe 142 | Myanmar,Asia 143 | Mongolia,Asia 144 | Northern Mariana Islands,Oceania 145 | Mozambique,Africa 146 | Mauritania,Africa 147 | Montserrat,North America 148 | Martinique,North America 149 | Mauritius,Africa 150 | Malawi,Africa 151 | Malaysia,Asia 152 | Mayotte,Africa 153 | Namibia,Africa 154 | New Caledonia,Oceania 155 | Niger,Africa 156 | Norfolk Island,Oceania 157 | Nigeria,Africa 158 | Nicaragua,North America 159 | Niue,Oceania 160 | Netherlands,Europe 161 | Norway,Europe 162 | Nepal,Asia 163 | Nauru,Oceania 164 | New Zealand,Oceania 165 | Oman,Asia 166 | Pakistan,Asia 167 | Panama,North America 168 | Pitcairn,Oceania 169 | Peru,South America 170 | Philippines,Asia 171 | Palau,Oceania 172 | Papua New Guinea,Oceania 173 | Poland,Europe 174 | Puerto Rico,North America 175 | North Korea,Asia 176 | Portugal,Europe 177 | Paraguay,South America 178 | Palestine,Asia 179 | French Polynesia,Oceania 180 | Qatar,Asia 181 | Réunion,Africa 182 | Romania,Europe 183 | Russian Federation,Europe 184 | Rwanda,Africa 185 | Saudi Arabia,Asia 186 | Sudan,Africa 187 | Senegal,Africa 188 | Singapore,Asia 189 | South Georgia and the South Sandwich Islands,Antarctica 190 | Saint Helena,Africa 191 | Svalbard and Jan Mayen,Europe 192 | Solomon Islands,Oceania 193 | Sierra Leone,Africa 194 | El Salvador,North America 195 | San Marino,Europe 196 | Somalia,Africa 197 | Saint Pierre and Miquelon,North America 198 | Sao Tome and Principe,Africa 199 | Suriname,South America 200 | Slovakia,Europe 201 | Slovenia,Europe 202 | Sweden,Europe 203 | Swaziland,Africa 204 | Seychelles,Africa 205 | Syria,Asia 206 | Turks and Caicos Islands,North America 207 | Chad,Africa 208 | Togo,Africa 209 | Thailand,Asia 210 | Tajikistan,Asia 211 | Tokelau,Oceania 212 | Turkmenistan,Asia 213 | East Timor,Asia 214 | Tonga,Oceania 215 | Trinidad and Tobago,North America 216 | Tunisia,Africa 217 | Turkey,Asia 218 | Tuvalu,Oceania 219 | Taiwan,Asia 220 | Tanzania,Africa 221 | Uganda,Africa 222 | Ukraine,Europe 223 | United States Minor Outlying Islands,Oceania 224 | Uruguay,South America 225 | United States,North America 226 | Uzbekistan,Asia 227 | Holy See (Vatican City State),Europe 228 | Saint Vincent and the Grenadines,North America 229 | Venezuela,South America 230 | "Virgin Islands, British",North America 231 | "Virgin Islands, U.S.",North America 232 | Vietnam,Asia 233 | Vanuatu,Oceania 234 | Wallis and Futuna,Oceania 235 | Samoa,Oceania 236 | Yemen,Asia 237 | Yugoslavia,Europe 238 | South Africa,Africa 239 | Zambia,Africa 240 | Zimbabwe,Africa 241 | -------------------------------------------------------------------------------- /modules/mod7.1.csv/excel.csv: -------------------------------------------------------------------------------- 1 | 0;First Name;Last Name;Gender;Country;Age;Date;Id 2 | 1;Dulce;Abril;Female;United States;32;15/10/2017;1562 3 | 2;Mara;Hashimoto;Female;Great Britain;25;16/08/2016;1582 4 | 3;Philip;Gent;Male;France;36;21/05/2015;2587 5 | 4;Kathleen;Hanner;Female;United States;25;15/10/2017;3549 6 | 5;Nereida;Magwood;Female;United States;58;16/08/2016;2468 7 | 6;Gaston;Brumm;Male;United States;24;21/05/2015;2554 8 | 7;Etta;Hurn;Female;Great Britain;56;15/10/2017;3598 9 | 8;Earlean;Melgar;Female;United States;27;16/08/2016;2456 10 | 9;Vincenza;Weiland;Female;United States;40;21/05/2015;6548 11 | 10;Fallon;Winward;Female;Great Britain;28;16/08/2016;5486 12 | 11;Arcelia;Bouska;Female;Great Britain;39;21/05/2015;1258 13 | 12;Franklyn;Unknow;Male;France;38;15/10/2017;2579 14 | 13;Sherron;Ascencio;Female;Great Britain;32;16/08/2016;3256 15 | 14;Marcel;Zabriskie;Male;Great Britain;26;21/05/2015;2587 16 | 15;Kina;Hazelton;Female;Great Britain;31;16/08/2016;3259 17 | 16;Shavonne;Pia;Female;France;24;21/05/2015;1546 18 | 17;Shavon;Benito;Female;France;39;15/10/2017;3579 19 | 18;Lauralee;Perrine;Female;Great Britain;28;16/08/2016;6597 20 | 19;Loreta;Curren;Female;France;26;21/05/2015;9654 21 | 20;Teresa;Strawn;Female;France;46;21/05/2015;3569 22 | 21;Belinda;Partain;Female;United States;37;15/10/2017;2564 23 | 22;Holly;Eudy;Female;United States;52;16/08/2016;8561 24 | 23;Many;Cuccia;Female;Great Britain;46;21/05/2015;5489 25 | 24;Libbie;Dalby;Female;France;42;21/05/2015;5489 26 | 25;Lester;Prothro;Male;France;21;15/10/2017;6574 27 | 26;Marvel;Hail;Female;Great Britain;28;16/08/2016;5555 28 | 27;Angelyn;Vong;Female;United States;29;21/05/2015;6125 29 | 28;Francesca;Beaudreau;Female;France;23;15/10/2017;5412 30 | 29;Garth;Gangi;Male;United States;41;16/08/2016;3256 31 | 30;Carla;Trumbull;Female;Great Britain;28;21/05/2015;3264 32 | 31;Veta;Muntz;Female;Great Britain;37;15/10/2017;4569 33 | 32;Stasia;Becker;Female;Great Britain;34;16/08/2016;7521 34 | 33;Jona;Grindle;Female;Great Britain;26;21/05/2015;6458 35 | 34;Judie;Claywell;Female;France;35;16/08/2016;7569 36 | 35;Dewitt;Borger;Male;United States;36;21/05/2015;8514 37 | 36;Nena;Hacker;Female;United States;29;15/10/2017;8563 38 | 37;Kelsie;Wachtel;Female;France;27;16/08/2016;8642 39 | 38;Sau;Pfau;Female;United States;25;21/05/2015;9536 40 | 39;Shanice;Mccrystal;Female;United States;36;21/05/2015;2567 41 | 40;Chase;Karner;Male;United States;37;15/10/2017;2154 42 | 41;Tommie;Underdahl;Male;United States;26;16/08/2016;3265 43 | 42;Dorcas;Darity;Female;United States;37;21/05/2015;8765 44 | 43;Angel;Sanor;Male;France;24;15/10/2017;3259 45 | 44;Willodean;Harn;Female;United States;39;16/08/2016;3567 46 | 45;Weston;Martina;Male;United States;26;21/05/2015;6540 47 | 46;Roma;Lafollette;Female;United States;34;15/10/2017;2654 48 | 47;Felisa;Cail;Female;United States;28;16/08/2016;6525 49 | 48;Demetria;Abbey;Female;United States;32;21/05/2015;3265 50 | 49;Jeromy;Danz;Male;United States;39;15/10/2017;3265 51 | 50;Rasheeda;Alkire;Female;United States;29;16/08/2016;6125 52 | 51;Dulce;Abril;Female;United States;32;15/10/2017;1562 53 | 52;Mara;Hashimoto;Female;Great Britain;25;16/08/2016;1582 54 | 53;Philip;Gent;Male;France;36;21/05/2015;2587 55 | 54;Kathleen;Hanner;Female;United States;25;15/10/2017;3549 56 | 55;Nereida;Magwood;Female;United States;58;16/08/2016;2468 57 | 56;Gaston;Brumm;Male;United States;24;21/05/2015;2554 58 | 57;Etta;Hurn;Female;Great Britain;56;15/10/2017;3598 59 | 58;Earlean;Melgar;Female;United States;27;16/08/2016;2456 60 | 59;Vincenza;Weiland;Female;United States;40;21/05/2015;6548 61 | 60;Fallon;Winward;Female;Great Britain;28;16/08/2016;5486 62 | 61;Arcelia;Bouska;Female;Great Britain;39;21/05/2015;1258 63 | 62;Franklyn;Unknow;Male;France;38;15/10/2017;2579 64 | 63;Sherron;Ascencio;Female;Great Britain;32;16/08/2016;3256 65 | 64;Marcel;Zabriskie;Male;Great Britain;26;21/05/2015;2587 66 | 65;Kina;Hazelton;Female;Great Britain;31;16/08/2016;3259 67 | 66;Shavonne;Pia;Female;France;24;21/05/2015;1546 68 | 67;Shavon;Benito;Female;France;39;15/10/2017;3579 69 | 68;Lauralee;Perrine;Female;Great Britain;28;16/08/2016;6597 70 | 69;Loreta;Curren;Female;France;26;21/05/2015;9654 71 | 70;Teresa;Strawn;Female;France;46;21/05/2015;3569 72 | 71;Belinda;Partain;Female;United States;37;15/10/2017;2564 73 | 72;Holly;Eudy;Female;United States;52;16/08/2016;8561 74 | 73;Many;Cuccia;Female;Great Britain;46;21/05/2015;5489 75 | 74;Libbie;Dalby;Female;France;42;21/05/2015;5489 76 | 75;Lester;Prothro;Male;France;21;15/10/2017;6574 77 | 76;Marvel;Hail;Female;Great Britain;28;16/08/2016;5555 78 | 77;Angelyn;Vong;Female;United States;29;21/05/2015;6125 79 | 78;Francesca;Beaudreau;Female;France;23;15/10/2017;5412 80 | 79;Garth;Gangi;Male;United States;41;16/08/2016;3256 81 | 80;Carla;Trumbull;Female;Great Britain;28;21/05/2015;3264 82 | 81;Veta;Muntz;Female;Great Britain;37;15/10/2017;4569 83 | 82;Stasia;Becker;Female;Great Britain;34;16/08/2016;7521 84 | 83;Jona;Grindle;Female;Great Britain;26;21/05/2015;6458 85 | 84;Judie;Claywell;Female;France;35;16/08/2016;7569 86 | 85;Dewitt;Borger;Male;United States;36;21/05/2015;8514 87 | 86;Nena;Hacker;Female;United States;29;15/10/2017;8563 88 | 87;Kelsie;Wachtel;Female;France;27;16/08/2016;8642 89 | 88;Sau;Pfau;Female;United States;25;21/05/2015;9536 90 | 89;Shanice;Mccrystal;Female;United States;36;21/05/2015;2567 91 | 90;Chase;Karner;Male;United States;37;15/10/2017;2154 92 | 91;Tommie;Underdahl;Male;United States;26;16/08/2016;3265 93 | 92;Dorcas;Darity;Female;United States;37;21/05/2015;8765 94 | 93;Angel;Sanor;Male;France;24;15/10/2017;3259 95 | 94;Willodean;Harn;Female;United States;39;16/08/2016;3567 96 | 95;Weston;Martina;Male;United States;26;21/05/2015;6540 97 | 96;Roma;Lafollette;Female;United States;34;15/10/2017;2654 98 | 97;Felisa;Cail;Female;United States;28;16/08/2016;6525 99 | 98;Demetria;Abbey;Female;United States;32;21/05/2015;3265 100 | 99;Jeromy;Danz;Male;United States;39;15/10/2017;3265 101 | 100;Rasheeda;Alkire;Female;United States;29;16/08/2016;6125 102 | --------------------------------------------------------------------------------