Wednesday, April 15, 2020

Learn programming in five steps

Get started with Python

Stefan Schwarzer

Whether you are just developing a small administration script or developing a large application - with Python you can do both easily.

Python is versatile. The programming language, whose development began in the early 1990s, is equally suitable for small and very large projects. Python is available for Linux, many Unix derivatives, Mac OS X, Windows and also for platforms such as OS / 2 or Nokia S60 cell phones.

The Python standard distribution (CPython), which can be downloaded from the Python website [1], contains around 350 modules, among other things for dealing with Posix signals and threads, regular expressions and for retrieving websites and parsing E Emails. A standard distribution includes a debugger for code analysis and a profiler for measuring execution speed. In addition to extensive, English-language documentation [2] there is also an excellent Python quick reference [3].

There are many other libraries on the Internet, for example for PDF generation [6], game programming [5] or for creating special parsers [4]. The Python Package Index (PyPI) [11] offers an extensive list. There are interfaces to various GUI toolkits such as Tk [7], GTK [8], wxWindows [9] and Qt [10]. Figure 1 shows the development environment Idle written in Python with Tk.

course Python training in Bangladesh

Illustration 1


Figure 1: IDLE, an integrated development environment programmed in Python with the Tk library. Depending on the Linux distribution, this IDE is installed together with Python or from a separate package.

Python is not only suitable for scripting, but it can also be used to write extensive programs. Gentoo Linux's package management tools are primarily Python scripts. Well-known Python applications are the file transfer program BitTorrent, the mailing list manager Mailman, the application server Zope, the vector graphics program Skencil and the online game Eve.

Python is easy to learn and encourages you to write easy-to-understand code. It gives priority to the speed of development over the speed of program execution. However, this does not mean that Python programs always work sluggishly: the structure of the language allows the implementation of optimal algorithms, and many internal Python functions are written in C.

installation


Many Linux distributions already set up Python during installation, almost all of them offer it as a package. To find out if your system already has Python, issue the command in the shell python -V. If Python is set up, it answers with the version number. The latest version for production use is number 2.4.3.

If you get an error message, reinstall Python from your distribution packages. Some Linux games require you to install additional packages to set up some Python extensions that python-dev,python-headers or something similar,

Gimmick


The Python interpreter in interactive mode is suitable for initial tests, but also for experimentation during development ( Listing 1 ). Enter the python code at the prompt >>>. The ...Python interpreter creates the ellipse as a continuation prompt, the “0” at the end of the listing is the return value of the function os.system().

TIP

If you find Python too spartan in interactive mode, take a look at the Python interpreter IPython [12].

Listing 1

$ python

Python 2.4.2 (# 1, Oct 4 2005, 21:25:43)

[GCC 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> print "Hallo Welt!"

Hello World!

>>> for i in range(5):

... print I, # Einrueckung ist wichtig

0 1 2 3 4

>>> import os

>>>os.system("ls -l")

totally 8

-rw-r - r-- 1 schwa 1927 Apr 7, 11:57 am structure.otl

-rw-r - r-- 1 schwa schwa 3667 Apr 12 10:04 pm part1.lmtxt

If you want, you can also write the Python code into a text file (usually with the extension .py) and python date. by executing it. Alternatively, enter the path to the interpreter in the first line of the file, make it chmod a+x datei.pyexecutable and start the script with Pfad/meine_datei.py.

If you use umlauts or other characters in the file outside of the ASCII character set, you will receive an error message. In such a case, also specify the encoding of the file:

#! / usr / bin / python

# encoding: iso-8859-1

Identifier


In Python, the names for variables, functions, classes, etc. can contain any number of upper and lower case letters, numbers and underscores, but do not start with a number. Uppercase/lowercase is significant, Halland hallotherefore denotes different objects. The Python Style Guide [13] gives advice on how to name your identifiers.