Menu
The examples below will increase in number of lines of code and difficulty:
If considering extending this example for e.g. File transfers, keep in mind that UDP is not reliable. So you'll have to handle packets getting lost and packets arriving out of order. In effect, to get something reliable you'll need to implement something similar to TCP on top of UDP, and you might want to consider using TCP instead. Python-geoip is a library that provides access to GeoIP databases. Currently it only supports accessing MaxMind databases. It’s similar to other GeoIP libraries but comes under the very liberal BSD license and also provides an extra library that optionally ships a recent version of the Geolite2 database as provided by MaxMind.
1 line: Output
2 lines: Input, assignment
3 lines: For loop, built-in enumerate function, new style formatting
4 lines: Fibonacci, tuple assignment
5 lines: Functions
6 lines: Import, regular expressions
7 lines: Dictionaries, generator expressions
8 lines: Command line arguments, exception handling
9 lines: Opening files
10 lines: Time, conditionals, from..import, for..else
11 lines: Triple-quoted strings, while loop
12 lines: Classes
13 lines: Unit testing with unittest
14 lines: Doctest-based testing
15 lines: itertools
16 lines: csv module, tuple unpacking, cmp() built-in
18 lines: 8-Queens Problem (recursion)
20 lines: Prime numbers sieve w/fancy generators
21 lines: XML/HTML parsing
28 lines: 8-Queens Problem (define your own exceptions)
33 lines: 'Guess the Number' Game (edited) from http://inventwithpython.com
These all run under Python 3. If you are interested in differences between Python 2 and Python 3, please take a look at the previous version of this page.
CategoryDocumentation
- Python Basic Tutorial
- Python Advanced Tutorial
- Python Useful Resources
- Selected Reading
The standard library comes with a number of modules that can be used both as modules and as command-line utilities.
The dis Module
The dis module is the Python disassembler. It converts byte codes to a format that is slightly more appropriate for human consumption.
![Module Module](https://www.dataquest.io/wp-content/uploads/2019/01/fp-python.png)
![Python ip tools examples Python ip tools examples](/uploads/1/2/5/7/125737311/505262867.png)
You can run the disassembler from the command line. It compiles the given script and prints the disassembled byte codes to the STDOUT. You can also use dis as a module. The dis function takes a class, method, function or code object as its single argument.
Example
This would produce the following result −
The pdb Module
The pdb module is the standard Python debugger. It is based on the bdb debugger framework.
You can run the debugger from the command line (type n [or next] to go to the next line and help to get a list of available commands) −
Example
Before you try to run pdb.py, set your path properly to Python lib directory. So let us try with above example sum.py −
The profile Module
The profile module is the standard Python profiler. You can run the profiler from the command line −
Example
Let us try to profile the following program −
Now, try running cProfile.py over this file sum.py as follows −
The tabnanny Module
The tabnanny module checks Python source files for ambiguous indentation. If a file mixes tabs and spaces in a way that throws off indentation, no matter what tab size you're using, the nanny complains −
Example
Let us try to profile the following program −
If you would try a correct file with tabnanny.py, then it won't complain as follows −