Limited Period Offer - Upto 50% OFF | OFFER ENDING IN: 0 D 0 H 0 M 0 S

Log In to start Learning

Login via

Post By Admin Last Updated At 2020-06-15
Python Packages

Python Packages:

A package is a hierarchical file directory structure that defines the single python application environment. This package consists of a module, sub packages, and sub-sub packages and so on ..usually packages are the way of structuring the python module namespace using dotted module names. This python packages allows the uniform handling of files and data.

For example, A.B indicates, Package A contains a sub-module B.In order to treat the python directories as packages, __init__.py files are required. And there is no restriction for the __init__.py file w.r.t to the number of code line . (i.e it can be empty files (or) a file that contains some code). Besides this python interpreter allows the user to execute the individual modules of the package.

So, are you looking at the example code? If so don’t waste your time by scrolling your mouse up and down. Since this concept is common in other programming languages like Java, I would like to leave for you as an assignment. visit Python online education for support.

In the definition of the package, we have seen the package is a combination of several directories, functions, module so on. In some cases, we require only a few components of the package. And in some other cases, we require all the modules of the package. And there is no limit regarding the number of modules, files in the package. Its good to use import statement, if the package contains less than 5 modules, function. But what if the package contains 100’s of modules/ directories.Its a bad way of programming to use import statement for those 100 files/directories inclusion. In such cases, we need to use an alternative to the problem. * provides a good solution to the problem. Usually * is used to import all the package modules.

Also check the essential packages in Python and IOT

Note :

If the package imports the file name from the current module, usually dot notation is used. And the leading dot indicates the packages involved in the relative import.

Beside this Python interpreter also supports the special attribute __path__. Usually, this contains the directory name that contains the __init__.py.

So in python tutorial, we will next about

Python Regular expressions:

A regular expression is a character sequence that forms a search pattern. In a variety of ways, these expressions permit you to match various string values. These are essentially a tiny highly specialized programming language available inside the python and made available through re-module. With this language, you can specify the rules for the set of possible strings to match. And this possible string may be English sentence, e-mail address (or) any other Tex commands.

Additionally, this module re provides full support for Perl like the regular expression in python. At the compilation time, if an error occurs, the re-module raises re.error exception.

Without invoking the special meaning, regular expressions use the backslash (\) to indicate the special forms (or)special meaning.

Regular expression syntax :

It is a set of strings that match the required expression. Additionally, this regular expression allows the concatenation to form new strings. If A and B are the regular expression, then AB is also a regular expression.

Ex: if the string  P matches  A and the other string q matches B then the string pq will match AB. Now let  us have a look over the python regular expression characters

Regular Expression characters :
SymbolMeaning
.Except new line character matches any character
^It matches any string starting
$It matches any string ending
*In the given regular expression, it searches zero (or)more repetition
\Either a special character (or) a regular expression character (or) special regular expression sequences.
?It Matches one (or) more previous regular expressions
+In the One(or) more occurrences
|It is used in the cases of Either (or)
()Capture and gr
{}It is  used to specify the exact number of sequences
.Uses for any character (except newline character)
^It is used for starting of the regular expression
[]It is used for the  character set
[…]Matches any single line character in brackets
[^…]Matches  any single character but not in brackets

Get the real-time examples on regular expression characters at python course

Besides this regular expression match, Python interpreter also supports the match expressions.

Match expressions:

So now, let us have a look over the match expressions:

PatternDescriptions
re*It matches for the  zero (or) more occurrences of the preceding expression
re+It matches one (or) more occurrence of the preceding expression
re?It matches for the one (or) more occurrence of the preceding expression
re{ n}It matches for the exactly ‘n’occurances of the preceding expression
re{n, }It matches for n (or) more occurrences of the preceding expression
re{n,m}It matches for at least ‘n’ of the’ occurrences of the preceding expression
a|bIt matches for  either a (or) b
(re)It groups the regular expressions and remembers matches text

Like match expression, it supports the special sequences.Now let us have a look over those special sequences.

Special Sequences :
CharacterDescription
\AIt returns the match if the specified characters are the string beginning
\bIt returns the match where the specified characters are at the beginning (or) end of the word
\BReturns a match where the special characters are present. But not at the beginning (or) end of the word.
\dReturns the string that contains numbers  0-9
\DReturns the string that does not contain digits
\sIt returns the string that contains the special character
\SIt returns the string that does not contain the special character
\wIt Returns a match, where the string contains any words
\WIt Returns a match, but string does not contain any word characters
\ZIt Returns the match, if the specified characters are the string end

Besides this, it additionally supports some built-in functions. Now let us have a look over those.

Functions :
Function _nameDescription
search()It searches the string for the match. If there is a match, it returns the match object
split()The split() returns a list. Here the string has been split at each match.
sub()It replaces the text match with the text of your choice
group()It returns the string that was matched by the regular expression
start()It returns the starting position of the match
end()It returns the ending position of the match
span()It returns  the tuple that contains the staring position of the match
Match():

A match object is an object containing the information about the search and result

So likewise python supports  regular expressions. Since I have said the working of these functions I would like to leave the example code for you as an assignment. If you struck up anywhere feel  contact the experts at Python training