From 5a4f9743f7631f3873c890f51cc7f183cab50926 Mon Sep 17 00:00:00 2001 From: Jonathan Dayton Date: Sat, 19 Oct 2019 10:54:19 -0500 Subject: [PATCH 01/27] Add missing period (#199) --- decorators.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decorators.rst b/decorators.rst index 1b83032..40f53ac 100644 --- a/decorators.rst +++ b/decorators.rst @@ -329,7 +329,7 @@ Come to think of it, isn't ``@wraps`` also a decorator? But, it takes an argument like any normal function can do. So, why can't we do that too? This is because when you use the ``@my_decorator`` syntax, you are -applying a wrapper function with a single function as a parameter +applying a wrapper function with a single function as a parameter. Remember, everything in Python is an object, and this includes functions! With that in mind, we can write a function that returns a wrapper function. From f2159f79981d5831a6f24eb26d7ac9abae94e296 Mon Sep 17 00:00:00 2001 From: Floris Lambrechts Date: Sat, 19 Oct 2019 17:56:38 +0200 Subject: [PATCH 02/27] Improve wording in paragraph about StopIteration (#196) "wondering that why" does not sound fluid. Also, using the word 'while' in a sentence about a `for` loop may be confusing. --- generators.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/generators.rst b/generators.rst index dd983c3..23cd1b0 100644 --- a/generators.rst +++ b/generators.rst @@ -134,10 +134,10 @@ element of a sequence. So let's test out our understanding: As we can see that after yielding all the values ``next()`` caused a ``StopIteration`` error. Basically this error informs us that all the -values have been yielded. You might be wondering that why don't we get -this error while using a ``for`` loop? Well the answer is simple. The +values have been yielded. You might be wondering why we don't get +this error when using a ``for`` loop? Well the answer is simple. The ``for`` loop automatically catches this error and stops calling -``next``. Do you know that a few built-in data types in Python also +``next``. Did you know that a few built-in data types in Python also support iteration? Let's check it out: .. code:: python From a8834dec1ec4d8602cd94bfb4e32fce236a471c9 Mon Sep 17 00:00:00 2001 From: Libbey Date: Sat, 19 Oct 2019 09:58:05 -0600 Subject: [PATCH 03/27] Add func call to Nesting a Decorator Within a Function (#192) 'Nesting a Decorator Within a Function' code does not ever actually call the func, so this commit adds execution and returns the wrapped function result when tagged with decorator. --- decorators.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/decorators.rst b/decorators.rst index 40f53ac..3389728 100644 --- a/decorators.rst +++ b/decorators.rst @@ -354,6 +354,7 @@ us specify a logfile to output to. with open(logfile, 'a') as opened_file: # Now we log to the specified logfile opened_file.write(log_string + '\n') + return func(*args, **kwargs) return wrapped_function return logging_decorator From a61e0c9b80acde5a83f3165ffac8d8ae42827a16 Mon Sep 17 00:00:00 2001 From: Chandler Zuo Date: Sat, 19 Oct 2019 11:58:51 -0400 Subject: [PATCH 04/27] Fix the contextmanager example (#190) See https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager --- context_managers.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/context_managers.rst b/context_managers.rst index 79d944f..fcff411 100644 --- a/context_managers.rst +++ b/context_managers.rst @@ -153,8 +153,10 @@ Let's see a basic, useless example: @contextmanager def open_file(name): f = open(name, 'w') - yield f - f.close() + try: + yield f + finally: + f.close() Okay! This way of implementing Context Managers appear to be more intuitive and easy. However, this method requires some knowledge about From 4a7296b6cc8a6b6387191ec84a2565a7ac6e0b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2EYasoob=20Ullah=20Khalid=20=E2=98=BA?= Date: Sat, 19 Oct 2019 18:06:46 +0200 Subject: [PATCH 05/27] added breakpoint. closes #195 (#200) --- debugging.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/debugging.rst b/debugging.rst index 58af25a..678d690 100644 --- a/debugging.rst +++ b/debugging.rst @@ -58,3 +58,7 @@ function. These are just a few commands. ``pdb`` also supports post mortem. It is also a really handy function. I would highly suggest you to look at the official documentation and learn more about it. + +**Note:** + +It might seem unintuitive to use `pdb.set_trace()` if you are new to this. Fortunately, if you are using Python 3.7+ then you can simply use the `breakpoint()` [built-in function](https://docs.python.org/3/library/functions.html#breakpoint). It automatically imports `pdb` and calls `pdb.set_trace()`. \ No newline at end of file From e5fbf503b75c0881a309bd26dc7e40a3ed77c2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2EYasoob=20Ullah=20Khalid=20=E2=98=BA?= Date: Tue, 19 May 2020 17:48:13 -0400 Subject: [PATCH 06/27] Got the internship <3 --- _templates/breadcrumbs.html | 5 ----- 1 file changed, 5 deletions(-) diff --git a/_templates/breadcrumbs.html b/_templates/breadcrumbs.html index 952fb30..a988ecd 100644 --- a/_templates/breadcrumbs.html +++ b/_templates/breadcrumbs.html @@ -26,11 +26,6 @@
-
-

Note

-

Hi! My name is Yasoob. I am the author of this book. Last year you guys helped me find an internship. I am asking for your help again to find an amazing internship for summer 2020. If you work at an amazing company and can help me, please read this article to find the details. Thanks!

-
-
    {% block breadcrumbs %}
  • {{ _('Docs') }} »
  • From 42577eec02e7a356bb923c6980f819248526660a Mon Sep 17 00:00:00 2001 From: Kasonnara Date: Wed, 20 May 2020 08:25:36 +0200 Subject: [PATCH 07/27] Add additional example to ShortHand Ternary (#205) Add a more common use case (in my experience) of 'None or something' --- ternary_operators.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ternary_operators.rst b/ternary_operators.rst index 7e7dec2..18b35c6 100644 --- a/ternary_operators.rst +++ b/ternary_operators.rst @@ -100,4 +100,14 @@ This is helpful in case where you quickly want to check for the output of a func >>> print(msg) No data returned +Or as a simple way to define function parameters with dynamic default values: +.. code:: python + + >>> def my_function(real_name, optional_display_name=None): + >>> optional_display_name = optional_display_name or real_name + >>> print(optional_display_name) + >>> my_function("John") + John + >>> my_function("Mike", "anonymous123") + anonymous123 From 69d90864f9080e8771abe56874886bde2dfd2cd0 Mon Sep 17 00:00:00 2001 From: Mike Morearty Date: Tue, 19 May 2020 23:25:58 -0700 Subject: [PATCH 08/27] Grammar: Change "it's" to "its" in some places (#203) * Use "it's" for "it is" * Use "its" for the possessive --- classes.rst | 2 +- context_managers.rst | 2 +- python_c_extension.rst | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/classes.rst b/classes.rst index 4d45cf2..9485307 100644 --- a/classes.rst +++ b/classes.rst @@ -159,7 +159,7 @@ its ``__init__`` method is called. For example: # called You can see that ``__init__`` is called immediately after an instance is -created. You can also pass arguments to the class during it's +created. You can also pass arguments to the class during its initialization. Like this: .. code:: python diff --git a/context_managers.rst b/context_managers.rst index fcff411..5a0f9d0 100644 --- a/context_managers.rst +++ b/context_managers.rst @@ -169,7 +169,7 @@ Let's dissect this method a little. 1. Python encounters the ``yield`` keyword. Due to this it creates a generator instead of a normal function. 2. Due to the decoration, contextmanager is called with the function - name (``open_file``) as it's argument. + name (``open_file``) as its argument. 3. The ``contextmanager`` decorator returns the generator wrapped by the ``GeneratorContextManager`` object. 4. The ``GeneratorContextManager`` is assigned to the ``open_file`` diff --git a/python_c_extension.rst b/python_c_extension.rst index 368d60b..5f49c3b 100644 --- a/python_c_extension.rst +++ b/python_c_extension.rst @@ -6,7 +6,7 @@ implementation is the ease of interfacing C code to Python. There are three key methods developers use to call C functions from their python code - ``ctypes``, ``SWIG`` and ``Python/C API``. Each -method comes with it's own merits and demerits. +method comes with its own merits and demerits. Firstly, why would you want to interface C with Python? @@ -194,7 +194,7 @@ Python/C API --------------- The `C/Python API `__ is probably the -most widely used method - not for it's simplicity but for the fact that +most widely used method - not for its simplicity but for the fact that you can manipulate python objects in your C code. This method requires your C code to be specifically written for @@ -229,7 +229,7 @@ the addList module is not written in Python at all, but rather in C. Next we'll have a look at the C code that get's built into the ``addList`` Python module. This may seem a bit daunting at first, but once you understand the various components that go into writing the C -file, it's pretty straight forward. +file, it's pretty straightforward. *adder.c* From d26d4b5dc7886cfa0715de9bf0ec8be567f7860e Mon Sep 17 00:00:00 2001 From: Alex Loftus Date: Wed, 20 May 2020 02:26:46 -0400 Subject: [PATCH 09/27] Update debugging.rst (#201) grammar fixes --- debugging.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/debugging.rst b/debugging.rst index 678d690..5e591f8 100644 --- a/debugging.rst +++ b/debugging.rst @@ -2,14 +2,14 @@ Debugging --------- Debugging is also something which once mastered can greatly enhance your -bug hunting skills. Most of the newcomers neglect the importance of the +bug hunting skills. Most newcomers neglect the importance of the Python debugger (``pdb``). In this section I am going to tell you only a few important commands. You can learn more about it from the official documentation. -**Running from commandline** +**Running from the command line** -You can run a script from the commandline using the Python debugger. +You can run a script from the command line using the Python debugger. Here is an example: .. code:: python @@ -61,4 +61,4 @@ official documentation and learn more about it. **Note:** -It might seem unintuitive to use `pdb.set_trace()` if you are new to this. Fortunately, if you are using Python 3.7+ then you can simply use the `breakpoint()` [built-in function](https://docs.python.org/3/library/functions.html#breakpoint). It automatically imports `pdb` and calls `pdb.set_trace()`. \ No newline at end of file +It might seem unintuitive to use `pdb.set_trace()` if you are new to this. Fortunately, if you are using Python 3.7+ then you can simply use the `breakpoint()` [built-in function](https://docs.python.org/3/library/functions.html#breakpoint). It automatically imports `pdb` and calls `pdb.set_trace()`. From 490477d93df85fbd5b3c739bc00d09a6e432f51e Mon Sep 17 00:00:00 2001 From: Jason Chen <33189757+LeChn@users.noreply.github.com> Date: Mon, 1 Jun 2020 14:10:11 -0400 Subject: [PATCH 10/27] capitalization correction for Counter title (#206) * Update collections.rst * parallel sorting bug fix Python 3 zip object no longer supports .sort() AttributeError: 'zip' object has no attribute 'sort' Changed to sorted to be forward compatible --- collections.rst | 4 ++-- lambdas.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/collections.rst b/collections.rst index af0aa5c..f668ca6 100644 --- a/collections.rst +++ b/collections.rst @@ -9,7 +9,7 @@ The ones which we will talk about are: - ``defaultdict`` - ``OrderedDict`` -- ``counter`` +- ``Counter`` - ``deque`` - ``namedtuple`` - ``enum.Enum`` (outside of the module; Python 3.4+) @@ -119,7 +119,7 @@ the end of the dictionary. # Blue 160 # Insertion order is preserved -``counter`` +``Counter`` ^^^^^^^^^^^^^^^ Counter allows us to count the occurrences of a particular item. For diff --git a/lambdas.rst b/lambdas.rst index 73328b8..756e260 100644 --- a/lambdas.rst +++ b/lambdas.rst @@ -39,5 +39,5 @@ they are used in the wild: .. code:: python data = zip(list1, list2) - data.sort() + data = sorted(data) list1, list2 = map(lambda t: list(t), zip(*data)) From 05af1fb7b09d978b9ef96e0e1e01a24ad75e4b34 Mon Sep 17 00:00:00 2001 From: "cursospython.com" <65613862+cursospython@users.noreply.github.com> Date: Thu, 4 Jun 2020 20:36:21 +0200 Subject: [PATCH 11/27] Added link to Spanish translation (#207) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 043cba4..b4205fe 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ If you want to translate this book in any other language then kindly let [me kno - [Russian](https://github.com/lancelote/interpy-ru) - [Korean](https://github.com/DDanggle/interpy-kr) - [Portuguese](https://github.com/joanasouza/intermediatePython) +- [Spanish](https://github.com/cursospython/LibroPython) License: ------- From 5360f3327b7e3998bd27586e58a2534618acef8e Mon Sep 17 00:00:00 2001 From: yasoob Date: Sat, 6 Jun 2020 08:30:52 -0400 Subject: [PATCH 12/27] setting up custom privacy conscious analytics service --- _templates/breadcrumbs.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/_templates/breadcrumbs.html b/_templates/breadcrumbs.html index a988ecd..a110d90 100644 --- a/_templates/breadcrumbs.html +++ b/_templates/breadcrumbs.html @@ -80,3 +80,5 @@ {% endif %}
+ + From 6d28d4f4e5d02811f29f6ae99a6d2d71d4e3874e Mon Sep 17 00:00:00 2001 From: Pablo Navarro Date: Tue, 9 Jun 2020 15:06:12 -0700 Subject: [PATCH 13/27] Update ternary_operators.rst (#208) Fix the blueprint for the ternary operator --- ternary_operators.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ternary_operators.rst b/ternary_operators.rst index 18b35c6..6f9cbbc 100644 --- a/ternary_operators.rst +++ b/ternary_operators.rst @@ -12,7 +12,7 @@ expressions. .. code:: python - condition_if_true if condition else condition_if_false + value_if_true if condition else value_if_false **Example:** From 6ed9f4542e2ec28343ac21932132c322f3af400a Mon Sep 17 00:00:00 2001 From: Yasoob Date: Thu, 11 Jun 2020 16:14:39 -0400 Subject: [PATCH 14/27] removed shynet. Too many fake views --- _templates/breadcrumbs.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/_templates/breadcrumbs.html b/_templates/breadcrumbs.html index a110d90..a988ecd 100644 --- a/_templates/breadcrumbs.html +++ b/_templates/breadcrumbs.html @@ -80,5 +80,3 @@ {% endif %}
- - From 23f165f7fcb0c28c8dffc94b18b79a9611b122bc Mon Sep 17 00:00:00 2001 From: Yasoob Date: Thu, 11 Jun 2020 16:26:20 -0400 Subject: [PATCH 15/27] maybe plausible analytics works better? --- _templates/breadcrumbs.html | 1 + 1 file changed, 1 insertion(+) diff --git a/_templates/breadcrumbs.html b/_templates/breadcrumbs.html index a988ecd..247493d 100644 --- a/_templates/breadcrumbs.html +++ b/_templates/breadcrumbs.html @@ -79,4 +79,5 @@ {% endif %}
+ From e7bbb9bbe26cc9076bdb5201c1c5c5f338b70479 Mon Sep 17 00:00:00 2001 From: Steven Xu <30362574+stevestar888@users.noreply.github.com> Date: Tue, 16 Jun 2020 23:51:48 -0400 Subject: [PATCH 16/27] grammar: add an apostrophe (#209) --- args_and_kwargs.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/args_and_kwargs.rst b/args_and_kwargs.rst index 544742e..34b4758 100644 --- a/args_and_kwargs.rst +++ b/args_and_kwargs.rst @@ -6,7 +6,7 @@ figuring out the \*args and \*\*kwargs magic variables. So what are they ? First of all let me tell you that it is not necessary to write \*args or \*\*kwargs. Only the ``*`` (asterisk) is necessary. You could have also written \*var and \*\*vars. Writing \*args and \*\*kwargs is just a -convention. So now lets take a look at \*args first. +convention. So now let's take a look at \*args first. Usage of \*args ^^^^^^^^^^^^^^^ From a4d1ec1b1a2c979ca71fdff9ab50cb4fb48d1bfc Mon Sep 17 00:00:00 2001 From: Steven Xu <30362574+stevestar888@users.noreply.github.com> Date: Sat, 4 Jul 2020 20:08:37 -0400 Subject: [PATCH 17/27] add output for first example (#211) --- enumerate.rst | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/enumerate.rst b/enumerate.rst index 277b679..e765ed5 100644 --- a/enumerate.rst +++ b/enumerate.rst @@ -7,12 +7,19 @@ advanced programmers are unaware of it. It allows us to loop over something and have an automatic counter. Here is an example: .. code:: python + + my_list = ['apple', 'banana', 'grapes', 'pear'] + for counter, value in enumerate(my_list): + print counter, value - for counter, value in enumerate(some_list): - print(counter, value) + # Output: + # 0 apple + # 1 banana + # 2 grapes + # 3 pear -And there is more! ``enumerate`` also accepts an optional argument which -makes it even more useful. +And there is more! ``enumerate`` also accepts an optional argument that +allows us to specify the starting index of the counter. .. code:: python @@ -26,9 +33,9 @@ makes it even more useful. # 3 grapes # 4 pear -The optional argument allows us to tell ``enumerate`` from where to -start the index. You can also create tuples containing the index and -list item using a list. Here is an example: +An example of where the optional argument of ``enumerate``comes in handy +is creating tuples containing the index and list item using a list. Here +is an example: .. code:: python From 1593256bcd5b4d0f7ced67460b2906475a2fc31f Mon Sep 17 00:00:00 2001 From: Steven Xu <30362574+stevestar888@users.noreply.github.com> Date: Fri, 10 Jul 2020 13:55:59 -0400 Subject: [PATCH 18/27] make exception execution more specific (#212) --- exceptions.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exceptions.rst b/exceptions.rst index d6fae82..abdb571 100644 --- a/exceptions.rst +++ b/exceptions.rst @@ -5,9 +5,11 @@ Exception handling is an art which once you master grants you immense powers. I am going to show you some of the ways in which we can handle exceptions. -In basic terminology we are aware of ``try/except`` clause. The code -which can cause an exception to occur is put in the ``try`` block and +In basic terminology we are aware of the ``try/except`` structure. The code +that can cause an exception to occur is put in the ``try`` block and the handling of the exception is implemented in the ``except`` block. +The code in the ``except`` block will only execute if the ``try`` block +runs into an exception. Here is a simple example: .. code:: python From 7ca139de480aaee0fedb8df3e3a533b7ded37eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2EYasoob=20Ullah=20Khalid=20=E2=98=BA?= Date: Sat, 11 Jul 2020 14:24:46 -0400 Subject: [PATCH 19/27] Removed Plausible --- _templates/breadcrumbs.html | 1 - 1 file changed, 1 deletion(-) diff --git a/_templates/breadcrumbs.html b/_templates/breadcrumbs.html index 247493d..a988ecd 100644 --- a/_templates/breadcrumbs.html +++ b/_templates/breadcrumbs.html @@ -79,5 +79,4 @@ {% endif %}
- From 2002172addd3cdf3be5b39514783b3a617b2de50 Mon Sep 17 00:00:00 2001 From: oliverkoo Date: Wed, 15 Jul 2020 14:40:21 -0400 Subject: [PATCH 20/27] Update enumerate.rst (#214) add missing space --- enumerate.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enumerate.rst b/enumerate.rst index e765ed5..3bcd2f6 100644 --- a/enumerate.rst +++ b/enumerate.rst @@ -33,7 +33,7 @@ allows us to specify the starting index of the counter. # 3 grapes # 4 pear -An example of where the optional argument of ``enumerate``comes in handy +An example of where the optional argument of ``enumerate`` comes in handy is creating tuples containing the index and list item using a list. Here is an example: From 42fec672382bc4e05d81559f6031671b1e617dee Mon Sep 17 00:00:00 2001 From: Steven Xu <30362574+stevestar888@users.noreply.github.com> Date: Mon, 20 Jul 2020 19:43:13 -0400 Subject: [PATCH 21/27] changed wording on *args (#210) * changed wording * Update args_and_kwargs.rst --- args_and_kwargs.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/args_and_kwargs.rst b/args_and_kwargs.rst index 34b4758..85ed174 100644 --- a/args_and_kwargs.rst +++ b/args_and_kwargs.rst @@ -3,7 +3,7 @@ I have come to see that most new python programmers have a hard time figuring out the \*args and \*\*kwargs magic variables. So what are they -? First of all let me tell you that it is not necessary to write \*args +? First of all, let me tell you that it is not necessary to write \*args or \*\*kwargs. Only the ``*`` (asterisk) is necessary. You could have also written \*var and \*\*vars. Writing \*args and \*\*kwargs is just a convention. So now let's take a look at \*args first. @@ -12,12 +12,11 @@ Usage of \*args ^^^^^^^^^^^^^^^ \*args and \*\*kwargs are mostly used in function definitions. \*args -and \*\*kwargs allow you to pass a variable number of arguments to a -function. What variable means here is that you do not know beforehand -how many arguments can be passed to your function by the user -so in this case you use these two keywords. \*args is used to send a -**non-keyworded** variable length argument list to the function. Here's -an example to help you get a clear idea: +and \*\*kwargs allow you to pass an unspecified number of arguments to a +function, so when writing the function definition, you do not need to +know how many arguments will be passed to your function. \*args is used to +send a **non-keyworded** variable length argument list to the function. +Here's an example to help you get a clear idea: .. code:: python From 219193a04c9d3fa52a5926467776c4ec47a5e204 Mon Sep 17 00:00:00 2001 From: Steven Xu <30362574+stevestar888@users.noreply.github.com> Date: Mon, 20 Jul 2020 19:44:07 -0400 Subject: [PATCH 22/27] add details about catching all exceptions (#213) * add details about catching all exceptions * Small grammar/wording changes --- exceptions.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/exceptions.rst b/exceptions.rst index abdb571..ebeb0d5 100644 --- a/exceptions.rst +++ b/exceptions.rst @@ -62,8 +62,16 @@ trapping ALL exceptions: # Some logging if you want raise e -This can be helpful when you have no idea about the exceptions which may -be thrown by your program. +This can be helpful when you have no idea about the exceptions that may +be thrown by your program. If you are just looking to catch all execptions, +but don't actually care about what they are, you can even exclude the +``Exception as e`` part. + +Note:: catching all exceptions may have unintended consequences because catching +all exceptions may also catch the ones you want to occur; for example, in +many command-line based programs, pressing control+c will terminate the program, +but if you catch all excepts, the ``KeyboardInterrupt`` will be caught as an +exception, so pressing control+c will NOT terminate the program. ``finally`` clause ~~~~~~~~~~~~~~~~~~ From a5c450968b100561d3ce411463161f101982af61 Mon Sep 17 00:00:00 2001 From: Jordan Bonecutter <34787245+jordan-bonecutter@users.noreply.github.com> Date: Sun, 16 Aug 2020 20:33:46 -0700 Subject: [PATCH 23/27] Unnecessary #include statement (#216) No stdio functions were used in this file. --- python_c_extension.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/python_c_extension.rst b/python_c_extension.rst index 5f49c3b..f4cf5d4 100644 --- a/python_c_extension.rst +++ b/python_c_extension.rst @@ -36,8 +36,6 @@ Simple C code to add two numbers, save it as ``add.c`` //sample C file to add 2 numbers - int and floats - #include - int add_int(int, int); float add_float(float, float); From 13764ad2b2e848495b567910770e7a25dd72ea92 Mon Sep 17 00:00:00 2001 From: Yasoob Khalid Date: Thu, 20 Aug 2020 01:11:21 -0400 Subject: [PATCH 24/27] new book released --- _templates/breadcrumbs.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/_templates/breadcrumbs.html b/_templates/breadcrumbs.html index a988ecd..f3f3b94 100644 --- a/_templates/breadcrumbs.html +++ b/_templates/breadcrumbs.html @@ -25,7 +25,14 @@ {% endif %}
- +
+

New book released!

+

Hi! I just released the alpha version of my new book; Practical Python Projects. + Learn more about it + on my blog. In 325+ pages, I will teach you how to implement 12 end-to-end projects. + You can buy it from Feldroy.com. +

+
    {% block breadcrumbs %}
  • {{ _('Docs') }} »
  • From 0bc5da8d01ddfc766297e82dd106ff3549eac67c Mon Sep 17 00:00:00 2001 From: John <66183716+just-linux@users.noreply.github.com> Date: Mon, 14 Sep 2020 15:40:24 -0500 Subject: [PATCH 25/27] Correct minor underline build complaints (#219) * Correct minor underline build complaints * Correct minor underline build complaints, additional file --- context_managers.rst | 2 +- decorators.rst | 4 ++-- for_-_else.rst | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/context_managers.rst b/context_managers.rst index 5a0f9d0..261ebd6 100644 --- a/context_managers.rst +++ b/context_managers.rst @@ -36,7 +36,7 @@ Let's see how we can implement our own Context Manager. This should allow us to understand exactly what's going on behind the scenes. Implementing a Context Manager as a Class: -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ At the very least a context manager has an ``__enter__`` and ``__exit__`` method defined. Let's make our own file-opening Context diff --git a/decorators.rst b/decorators.rst index 3389728..30509fe 100644 --- a/decorators.rst +++ b/decorators.rst @@ -273,7 +273,7 @@ Now let's take a look at the areas where decorators really shine and their usage makes something really easy to manage. Authorization -~~~~~~~~~~~~ +~~~~~~~~~~~~~ Decorators can help to check whether someone is authorized to use an endpoint in a web application. They are extensively used in Flask web @@ -296,7 +296,7 @@ authentication: return decorated Logging -~~~~~~~~~~~~ +~~~~~~~ Logging is another area where the decorators shine. Here is an example: diff --git a/for_-_else.rst b/for_-_else.rst index 9a68363..f7fbe82 100644 --- a/for_-_else.rst +++ b/for_-_else.rst @@ -1,5 +1,5 @@ ``for/else`` ----------- +------------ Loops are an integral part of any language. Likewise ``for`` loops are an important part of Python. However there are a few things which most @@ -22,7 +22,7 @@ That is the very basic structure of a ``for`` loop. Now let's move on to some of the lesser known features of ``for`` loops in Python. ``else`` Clause -^^^^^^^^^^^^^^^^^^^^ +^^^^^^^^^^^^^^^ ``for`` loops also have an ``else`` clause which most of us are unfamiliar with. The ``else`` clause executes after the loop completes normally. From 9b6262eed638dd2f5960fb959def6fe981b0b40c Mon Sep 17 00:00:00 2001 From: Keith Kong Hei Lok <70051933+LittleBigKeith@users.noreply.github.com> Date: Mon, 21 Sep 2020 01:31:31 +0800 Subject: [PATCH 26/27] Create zip.md (#218) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create zip.md Create new file for 'zip' function * Converted to reStructured * added zip to the index Co-authored-by: M.Yasoob Ullah Khalid ☺ Co-authored-by: Yasoob Khalid --- index.rst | 1 + zip.rst | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 zip.rst diff --git a/index.rst b/index.rst index 224ae75..b45de64 100644 --- a/index.rst +++ b/index.rst @@ -50,6 +50,7 @@ Table of Contents virtual_environment collections enumerate + zip object_introspection comprehensions exceptions diff --git a/zip.rst b/zip.rst new file mode 100644 index 0000000..947fe2a --- /dev/null +++ b/zip.rst @@ -0,0 +1,71 @@ +Zip and unzip +------------- + +**Zip** + +Zip is a useful function that allows you to combine two lists easily. + +After calling zip, an iterator is returned. In order to see the content wrapped inside, we need to first convert it to a list. + +Example: + +.. code:: python + + first_name = ['Joe','Earnst','Thomas','Martin','Charles'] + + last_name = ['Schmoe','Ehlmann','Fischer','Walter','Rogan','Green'] + + age = [23, 65, 11, 36, 83] + + print(list(zip(first_name,last_name, age))) + + # Output + # + # [('Joe', 'Schmoe', 23), ('Earnst', 'Ehlmann', 65), ('Thomas', 'Fischer', 11), ('Martin', 'Walter', 36), ('Charles', 'Rogan', 83)] + +One advantage of zip is that it improves readability of for loops. + +For example, instead of needing multiple inputs, you only need one zipped list for the following for loop: + +.. code:: python + + first_name = ['Joe','Earnst','Thomas','Martin','Charles'] + last_name = ['Schmoe','Ehlmann','Fischer','Walter','Rogan','Green'] + age = [23, 65, 11, 36, 83] + + for first_name, last_name, age in zip(first_name, last_name, age): + print(f"{first_name} {last_name} is {age} years old") + + # Output + # + # Joe Schmoe is 23 years old + # Earnst Ehlmann is 65 years old + # Thomas Fischer is 11 years old + # Martin Walter is 36 years old + # Charles Rogan is 83 years old + +**Unzip** + +We can use the `zip` function to unzip a list as well. This time, we need an input of a list with an asterisk before it. + +The outputs are the separated lists. + +Example: + +.. code:: python + + full_name_list = [('Joe', 'Schmoe', 23), + ('Earnst', 'Ehlmann', 65), + ('Thomas', 'Fischer', 11), + ('Martin', 'Walter', 36), + ('Charles', 'Rogan', 83)] + + first_name, last_name, age = list(zip(*full_name_list)) + print(f"first name: {first_name}\nlast name: {last_name} \nage: {age}") + + # Output + + # first name: ('Joe', 'Earnst', 'Thomas', 'Martin', 'Charles') + # last name: ('Schmoe', 'Ehlmann', 'Fischer', 'Walter', 'Rogan') + # age: (23, 65, 11, 36, 83) + From 257709f4acb61539bf654fc6a5b72ac5e2c86ba0 Mon Sep 17 00:00:00 2001 From: absara <105458799+Abidi-S@users.noreply.github.com> Date: Fri, 18 Nov 2022 07:42:25 +0000 Subject: [PATCH 27/27] Global and Return edits (#232) * replaced "&" with "and" in article heading * fixed minor typos --- global_&_return.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/global_&_return.rst b/global_&_return.rst index 39a75d4..0661752 100644 --- a/global_&_return.rst +++ b/global_&_return.rst @@ -1,9 +1,9 @@ -Global & Return +Global and Return --------------- -You might have encountered some functions written in python which have a +You might have encountered some functions written in Python which have a ``return`` keyword in the end of the function. Do you know what it does? It -is similar to return in other languages. Lets examine this little +is similar to return in other languages. Let's examine this little function: .. code:: python @@ -15,7 +15,7 @@ function: print(result) # Output: 8 -The function above takes two values as input and then output their +The function above takes two values as input and then outputs their addition. We could have also done: .. code:: python @@ -28,11 +28,11 @@ addition. We could have also done: print(result) # Output: 8 -So first lets talk about the first bit of code which involves the +So first let's talk about the first bit of code which involves the ``return`` keyword. What that function is doing is that it is assigning the value to the variable which is calling that function which in our -case is ``result``. In most cases and you won't need to use the -``global`` keyword. However lets examine the other bit of code as well +case is ``result``. In most cases you won't need to use the +``global`` keyword. However, let's examine the other bit of code as well which includes the ``global`` keyword. So what that function is doing is that it is making a global variable ``result``. What does global mean here? Global variable means that we can access that variable outside the @@ -125,11 +125,11 @@ Or by more common convention: print(profile_age) # Output: 30 -Keep in mind that even in the above example we are returning a tuple (despite the lack of paranthesis) and not separate multiple values. If you want to take it one step further, you can also make use of `namedtuple `_. Here is an example: +Keep in mind that even in the above example we are returning a tuple (despite the lack of parenthesis) and not separate multiple values. If you want to take it one step further, you can also make use of `namedtuple `_. Here is an example: .. code:: python - from collections import namedtuple + from collections import namedtuple def profile(): Person = namedtuple('Person', 'name age') return Person(name="Danny", age=31) @@ -157,4 +157,4 @@ Keep in mind that even in the above example we are returning a tuple (despite th print(age) #31 -This is a better way to do it along with returning ``lists`` and ``dicts``. Don't use ``global`` keyword unless you know what you are doing. ``global`` might be a better option in a few cases but is not in most of them. +This is a better way to do it, along with returning ``list`` and ``dict``. Don't use ``global`` keyword unless you know what you are doing. ``global`` might be a better option in a few cases but is not in most of them.