Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ The output:

::

$ python3 code/lenexample.py
$ python3 code/lenexample.py
Length of the f object is 5

__contains__ method
Expand Down Expand Up @@ -587,7 +587,7 @@ Let us look at it in details in the following example.

def can_sudo(self):
return self.sudo

u = User("kdas", 1000, 1000, "/home/kdas", True)
pprint(u.__dict__)

Expand Down
10 changes: 5 additions & 5 deletions docs/click.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ is optional).

::

$ myhello
$ myhello
Hello World
$ myhello --help
Usage: myhello [OPTIONS]
Expand Down Expand Up @@ -160,7 +160,7 @@ option which will take a string as input.
--help Show this message and exit.
$ myhello
Hello World
Bye
Bye
$ myhello --name kushal
Hello World
Bye kushal
Expand Down Expand Up @@ -260,8 +260,8 @@ The output looks like below:
--password TEXT
--help Show this message and exit.
$ myhello
Password:
Repeat for confirmation:
Password:
Repeat for confirmation:
Hello World
We received hello as password.

Expand Down Expand Up @@ -305,4 +305,4 @@ The output looks like:

Click has many other useful features, like *yes parameter*, *file path input*.
I am not going to write about all of those here, but you can always from the
`upstream documentation <http://click.pocoo.org/>`_.
`upstream documentation <http://click.pocoo.org/>`_.
4 changes: 2 additions & 2 deletions docs/datastructure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ We can store anything in the list, so first we are going to add another list *b

.. index:: sort

Above you can see how we used the *a.extend()* method to extend the list. To sort any list we have *sort()* method. The *sort()* method will only work if elements in the list are comparable. We will remove the list b from the list and then sort.
Above you can see how we used the *a.extend()* method to extend the list. To sort any list we have *sort()* method. The *sort()* method will only work if elements in the list are comparable. We will remove the list b from the list and then sort.

::

Expand Down Expand Up @@ -525,7 +525,7 @@ changes the variable outside of the function.

def modify(numbers):
numbers.append(42)

modify(numbers)
print(numbers)
[1, 2, 4, 42]
Expand Down
4 changes: 2 additions & 2 deletions docs/flask.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ Put the following code in this file
filename='hello.css')}}" />
</head>
<body>

It works!

</body>
</html>

Expand Down
12 changes: 6 additions & 6 deletions docs/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ From Python3.8, we can also mark any function to have only positional arguments.

>>> def add(a, b, /):
... return a + b
...
...
>>> add(2, 3)
5
>>> add(a=2, b=3)
Expand Down Expand Up @@ -351,7 +351,7 @@ number, we can do it easily like this.

.. note:: To know more read `this link <http://docs.python.org/3/faq/programming.html#how-do-you-make-a-higher-order-function-in-python>`_.

map
map
====

`map` is a very useful class in python. It takes one function
Expand Down Expand Up @@ -388,7 +388,7 @@ In the above example, `name` and `age` are the parameters of the `hello`, and `k
the arguments passed to the function.


*args and **kwargs in function definition
*args and **kwargs in function definition
=========================================

There are times when we don't know the number of arguments before hand. There
Expand All @@ -406,12 +406,12 @@ This is where we use `*args` and `**kwargs` in the function.
print(f"We received {len(kwargs)} keyword arguments. And they are:")
for k, v in kwargs.items():
print(f"key={k} and value={v}")


unknown(30, 90, "kushal", lang="python", editor="vim")

We received 3 positional arguments. And they are:
30 90 kushal
30 90 kushal
We received 2 keyword arguments. And they are:
key=lang and value=python
key=editor and value=vim
Expand Down
2 changes: 1 addition & 1 deletion docs/hardwaresimulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Learning using hardware simulation
==================================

From this section and in the future chapters, there will be examples and problems
which is using a special device simulation in VS Code editor.
which is using a special device simulation in VS Code editor.

We will use the simulation to have a `Circuit Playground Express device <https://adafruit.com/product/3333>`_,
and learn to interact with the device. We will be able to turn on lights of different
Expand Down
4 changes: 2 additions & 2 deletions docs/ifelse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ The elegant way to test Truth values is like
pass

.. warning:: Don't do this

::

if x == True:
pass

Expand Down
2 changes: 1 addition & 1 deletion docs/loopingonhardware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ One NeoPixel at a time

.. figure:: img/oneneoatatime.gif

The `cpx.pixels` can be accessed by index numbers, from 0 to 9. This way, we can turn on
The `cpx.pixels` can be accessed by index numbers, from 0 to 9. This way, we can turn on
one NeoPixel at a time.

.. code-block:: python
Expand Down
12 changes: 6 additions & 6 deletions docs/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Now we are going to see how modules work. Create a file called bars.py. Content
Prints a bar with -

:arg num: Length of the bar

"""
print("-" * num)

Expand Down Expand Up @@ -136,7 +136,7 @@ a single function from the module. Look at the following updated `bars.py` examp
Prints a bar with -

:arg num: Length of the bar

"""
print("-" * num)

Expand Down Expand Up @@ -164,7 +164,7 @@ the module from there. All imported modules are of type `module`.
['ANSWER', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'hashbar', 'simplebar', 'starbar']
>>> type(bars)
<class 'module'>
>>> bars.__name__
>>> bars.__name__
'bars'
>>> bars.__file__
'/home/kdas/code/pym/code/bars.py'
Expand Down Expand Up @@ -317,7 +317,7 @@ Using the *view_dir* example.
::

>>> view_dir('/')
.readahead bin boot dev etc home junk lib lib64 lost+found media mnt opt
.readahead bin boot dev etc home junk lib lib64 lost+found media mnt opt
proc root run sbin srv sys tmp usr var


Expand Down Expand Up @@ -355,7 +355,7 @@ The *text* attribute holds the HTML returned by the server.
Using this knowledge, let us write a command which can download a given file (URL) from Internet.


.. code:: python
.. code:: python

#!/usr/bin/env python3
import os
Expand Down Expand Up @@ -383,7 +383,7 @@ Using this knowledge, let us write a command which can download a given file (UR


Here we used something new, when the module name is *__main__*, then only
ask for a user input and then download the given URL. This also prevents
ask for a user input and then download the given URL. This also prevents
the same when some other Python code imports this file as a Python module.

To learn more about requests module, go to their `wonderful documentation <http://docs.python-requests.org>`_.
Expand Down
2 changes: 1 addition & 1 deletion docs/mu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ working on actual projects. In this chapter we will learn about **mu editor**,
which is a very simple and beginner friendly editor for anyone starting with
Python. It is developed by Nicholas Tollervey.

If you already have an editor of your choice, you can skip this chapter.
If you already have an editor of your choice, you can skip this chapter.

Installation
=============
Expand Down
2 changes: 1 addition & 1 deletion docs/projectstructure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ First, we will have to install **twine** using **pip** (we are using a virtualen
$ twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Uploading distributions to https://test.pypi.org/legacy/
Enter your username: kushaldas
Enter your password:
Enter your password:
Uploading pymfactorial-0.1-py3-none-any.whl
100%|██████████████████████████████████████| 4.29k/4.29k [00:01<00:00, 3.77kB/s]
Uploading pymfactorial-0.1.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion docs/strings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ You can iterate over a string using simple `for` loop.

>>> for ch in "Python":
... print(ch)
...
...
P
y
t
Expand Down
12 changes: 6 additions & 6 deletions docs/thebeginning.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ can write the code in a file and then run the file. In this topic, we will
first write the code using the interpreter, after starting Python in the
command prompt (shell or terminal). If you are new to Linux command line,
you can read about Linux commands in `this
book <https://lym.readthedocs.io/en/latest/>`.
book <https://lym.readthedocs.io/en/latest/>`_.


The following is from Fedora 32 machine.

::


Python 3.8.2rc1 (default, Feb 12 2020, 00:00:00)
Python 3.8.2rc1 (default, Feb 12 2020, 00:00:00)
[GCC 10.0.1 20200130 (Red Hat 10.0.1-0.7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>


Using the Python interpreter
Expand All @@ -37,9 +37,9 @@ In our first code we are going to print "Hello World!" using the interpreter. To
Using a source file
=====================

As a serious programmer, you might want to write the above code into a source file. Use any text editor you like to create the file called helloworld.py. I used vi. You can even use GUI based tools like `Kate <https://kate-editor.org/get-it/>` or `gedit <https://wiki.gnome.org/Apps/Gedit>`.
As a serious programmer, you might want to write the above code into a source file. Use any text editor you like to create the file called helloworld.py. I used vi. You can even use GUI based tools like `Kate <https://kate-editor.org/get-it/>`_ or `gedit <https://wiki.gnome.org/Apps/Gedit>`_.

Open a shell or terinal and perform these steps.
Open a shell or terminal and perform these steps.

1. Enter the following text:

Expand Down Expand Up @@ -101,7 +101,7 @@ There are more places where you should be following the same type of whitespace

- Add a space after "," in dicts, lists, tuples, and argument lists and after ":" in dicts.

- Spaces around assignments and comparisons (except in argument list)
- Spaces around assignments and comparisons (except in argument list).

- No spaces just inside parentheses.

Expand Down
4 changes: 2 additions & 2 deletions docs/virtualenv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ So, now we will install a Python module called redis.
(virt1)$ python3 -m pip install redis
Collecting redis
Downloading redis-2.10.5-py2.py3-none-any.whl (60kB)
100% |████████████████████████████████| 61kB 607kB/s
100% |████████████████████████████████| 61kB 607kB/s
Installing collected packages: redis
Successfully installed redis-2.10.5

Expand Down Expand Up @@ -169,7 +169,7 @@ the following Python code in a file named *main.py*.
::

$ pipenv shell
$ $ python main.py
(myproject-dbBcpQ4l) $ python main.py
Your IP is 192.168.1.2

Exiting from the virtualenv
Expand Down