SlideShare uma empresa Scribd logo
1 de 36
Python Certification Training https://www.edureka.co/python
Agenda
Advanced Python Tutorial
Python Certification Training https://www.edureka.co/python
Agenda
Advanced Python Tutorial
Python Certification Training https://www.edureka.co/python
Agenda
Introduction 01
Introduction to
Advanced Python
Getting Started 02
Concepts 03
Practical Approach 04
Python and Shell
Looking at code to
understand theory
Key Concepts in Python
Python Certification Training https://www.edureka.co/python
Introduction to Advanced Python
Advanced Python Tutorial
Python Certification Training https://www.edureka.co/python
Introduction To Advanced Python
Python is an interpreted, high-level, general-purpose
programming language.
What is Python?
Advanced: Other
Languages
Learning
Advanced Python
Python Certification Training https://www.edureka.co/python
What Is Advanced Python
Computer Science5
Numerical Compute6
Databases7
Sys Programming 1
Graph Theory 2
Mathematics 3
Python spreading its wings across multiple dimensions and
use-cases in many fields
What is “Advanced”?
Python Certification Training https://www.edureka.co/python
Introduction To System Programming
Advanced Python Tutorial
Python Certification Training https://www.edureka.co/python
System Programming
Sys - Module
Hello Advanced Python!
Import sys
Provides information about constants, functions
and methods of the Python interpreter.
Data streams
stdout stderrstdin
>>> import sys
>>> sys.version
'2.6.5 (r265:79063, Apr 16 2010,
13:57:41) n[GCC 4.4.3]'
>>> sys.version_info
(2, 6, 5, 'final', 0)
>>>
Python Certification Training https://www.edureka.co/python
Command – Line Arguments
Sys - Module
Command Line
argcargv
#!/usr/bin/python
import sys
# it's easy to print this list of course:
print sys.argv
# or it can be iterated via a for loop:
for i in range(len(sys.argv)):
if i == 0:
print "Function name: %s" % sys.argv[0]
else:
print "%d. argument: %s" % (i,sys.argv[i])
$ python arguments.py arg1 arg2
['arguments.py', 'arg1', 'arg2']
Function name: arguments.py
1. argument: arg1
2. argument: arg2
$
Python Certification Training https://www.edureka.co/python
Changing Output Behaviour
Sys - Module
Python
Interactive Mode
Get Output
Write expression
>>> import sys
>>> x = 42
>>> x
42
>>> import sys
>>> def my_display(x):
... print "out: ",
... print x
...
>>> sys.displayhook = my_display
>>> x
out: 42
>>>
>>> print x
42
Behaviour of print() not changed
Python Certification Training https://www.edureka.co/python
Standard Data Streams
Sys - Module
>>> import sys
>>> for i in (sys.stdin, sys.stdout, sys.stderr):
... print(i)
...
', mode 'w' at 0x7f3397a2c150>
', mode 'w' at 0x7f3397a2c1e0>
>>>
SHELLstdin stdout
stderr
>>> import sys
>>> print "Going via stdout"
Going via stdout
>>> sys.stdout.write("Another way to do it!n")
Another way to do it!
>>> x = raw_input("read value via stdin: ")
read value via stdin: 42
>>> print x
42
>>> print "type in value: ", ; sys.stdin.readline()[:-1]
type in value: 42
'42'
>>>
Python Certification Training https://www.edureka.co/python
Redirections
Sys - Module
import sys
print("Coming through stdout")
# stdout is saved
save_stdout = sys.stdout
fh = open("test.txt","w")
sys.stdout = fh
print("This line goes to test.txt")
# return to normal:
sys.stdout = save_stdout
fh.close()
SHELLstdin stdout
stderr
import sys
save_stderr = sys.stderr
fh = open("errors.txt","w")
sys.stderr = fh
x = 10 / 0
# return to normal:
sys.stderr = save_stderr
fh.close()
Python Certification Training https://www.edureka.co/python
Variables & Constants In Sys Module
Sys - Module
byteorder
executable
maxint
modules
path
platform
Variables Constants
Python Certification Training https://www.edureka.co/python
Python And Shell
Advanced Python Tutorial
Python Certification Training https://www.edureka.co/python
Python And Shell
A piece of software that provides an interface for a user to some
other software or the operating system
What is “Shell”?
SHELL
GUICUI
Bourne-Shell
C-Shell
Bash Shell
Python Certification Training https://www.edureka.co/python
System Programming
The activity of programming system components or system
software
What is “SP”?
“System focussed programming”
Modules
sys os
Simple and clear
Well structured
Highly flexible
Advantages
Python Certification Training https://www.edureka.co/python
The ‘os’ Module
The os module allows platform independent programming by
providing abstract methods
What is “os” module?
Executing Shell scripts with os.system()
import os
def getch():
os.system("bash -c "read -n 1"")
getch()
from msvcrt import getch
Python Certification Training https://www.edureka.co/python
The ‘os’ Module
Executing Shell scripts with os.system()
import os, platform
if platform.system() == "Windows":
import msvcrt
def getch():
if platform.system() == "Linux":
os.system("bash -c "read -n
1"")
else:
msvcrt.getch()
print("Type a key!")
getch()
print("Okay")
Subprocess Module
os.system
os.spawn*
os.popen*
Python Certification Training https://www.edureka.co/python
Forking In Python
Advanced Python Tutorial
Python Certification Training https://www.edureka.co/python
Fork In Python
What is Forking?
import os
def child():
print('nA new child ', os.getpid())
os._exit(0)
def parent():
while True:
newpid = os.fork()
if newpid == 0:
child()
else:
pids = (os.getpid(), newpid)
print("parent: %d, child: %dn"
% pids)
reply = input("q for quit / c for
new fork")
if reply == 'c':
continue
else:
break
parent()
Process
Copy of Process
Parent
Child
Starting independent processes with fork()
exec*() function
Python Certification Training https://www.edureka.co/python
The exec*() Functions
exec*() functions
• os.execl(path, arg0, arg1, ...)
• os.execle(path, arg0, arg1, ..., env)
• os.execlp(file, arg0, arg1, ...)
• os.execlpe(file, arg0, arg1, ..., env)
• os.execv(path, args)
• os.execve(path, args, env)
• os.execvp(file, args)
• os.execvpe(file, args, env)
Python Certification Training https://www.edureka.co/python
Threads In Python
Advanced Python Tutorial
Python Certification Training https://www.edureka.co/python
What Is A Thread?
The smallest unit that can be scheduled in an operating systemWhat is a thread?
How to create a thread?
By forking a computer program in
two or more parallel tasks
Types of threads
Kernel threads User threads
Implemented in kernel NOT implemented in kernel
Python Certification Training https://www.edureka.co/python
What Is A Thread?
Global Variables
Process
Local variables
Code
THREAD
Local variables
Code
THREAD
Local variables
Code
THREAD
Python Certification Training https://www.edureka.co/python
The Thread Module
from thread import start_new_thread
def heron(a):
"""Calculates the square root of a"""
eps = 0.0000001
old = 1
new = 1
while True:
old,new = new, (new + a/new) / 2.0
print old, new
if abs(new - old) < eps:
break
return new
start_new_thread(heron,(99,))
start_new_thread(heron,(999,))
start_new_thread(heron,(1733,))
c = raw_input("Type something to quit.")
Example
Python Certification Training https://www.edureka.co/python
The Thread Module
from thread import start_new_thread
num_threads = 0
def heron(a):
global num_threads
num_threads += 1
# code has been left out, see above
num_threads -= 1
return new
start_new_thread(heron,(99,))
start_new_thread(heron,(999,))
start_new_thread(heron,(1733,))
start_new_thread(heron,(17334,))
while num_threads > 0:
pass
Previous example with counters for the threads
• Reading the value of num_thread
• A new int instance will be incremented or
decremented by 1
• the new value has to be assigned to
num_threads
Python Certification Training https://www.edureka.co/python
The Thread Module
from thread import start_new_thread, allocate_lock
num_threads = 0
thread_started = False
lock = allocate_lock()
def heron(a):
global num_threads, thread_started
lock.acquire()
num_threads += 1
thread_started = True
lock.release()
...
lock.acquire()
num_threads -= 1
lock.release()
return new
start_new_thread(heron,(99,))
start_new_thread(heron,(999,))
start_new_thread(heron,(1733,))
while not thread_started:
pass
while num_threads > 0:
pass
The solution
Python Certification Training https://www.edureka.co/python
Threading Module
import time
from threading import Thread
def sleeper(i):
print "thread %d sleeps for 5 seconds" % i
time.sleep(5)
print "thread %d woke up" % i
for i in range(10):
t = Thread(target=sleeper, args=(i,))
t.start()
Example
The Thread of the example doesn't do a lot, essentially it just
sleeps for 5 seconds and then prints out a message:
Python Certification Training https://www.edureka.co/python
Threading Module
thread 0 sleeps for 5 seconds
thread 1 sleeps for 5 seconds
thread 2 sleeps for 5 seconds
thread 3 sleeps for 5 seconds
thread 4 sleeps for 5 seconds
thread 5 sleeps for 5 seconds
thread 6 sleeps for 5 seconds
thread 7 sleeps for 5 seconds
thread 8 sleeps for 5 seconds
thread 9 sleeps for 5 seconds
thread 1 woke up
thread 0 woke up
thread 3 woke up
thread 2 woke up
thread 5 woke up
thread 9 woke up
thread 8 woke up
thread 7 woke up
thread 6 woke up
thread 4 woke up
Python Certification Training https://www.edureka.co/python
Pipes In Python
Advanced Python Tutorial
Python Certification Training https://www.edureka.co/python
What Are Pipes
Introducing modularity in the program to serve one instance output as
the input to another instance and so on till solution is achieved
What are pipes?
Two kinds of pipes
Named PipesAnonymous Pipes
Exist solely within processes and are usually
used in combination with forks
P1
P2
P3
P4
Python Certification Training https://www.edureka.co/python
Pipes – A Classic Example
99 Bottles of Beer
Drinking is injurious to health
Ninety-nine bottles of beer on the wall, Ninety-nine bottles of beer.
Take one down, pass it around, Ninety-eight bottles of beer on the wall.
Lyrics of the song:
Python Certification Training https://www.edureka.co/python
Named Pipes
Called FIFOs – Creating pipes which are implemented as files.What are named pipes?
First In – First Out
A process reads from and writes to such a pipe as if it
were a regular file. Sometimes more than one process
write to such a pipe but only one process reads from it.
Python Certification Training https://www.edureka.co/python
Conclusion
Advanced Python Tutorial
Python Certification Training https://www.edureka.co/python
Conclusion
Advanced Python, yay!
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programming Training | Edureka

Mais conteúdo relacionado

Mais procurados

Python Collections Tutorial | Edureka
Python Collections Tutorial | EdurekaPython Collections Tutorial | Edureka
Python Collections Tutorial | EdurekaEdureka!
 
What is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | EdurekaWhat is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | EdurekaEdureka!
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksEueung Mulyana
 
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Edureka!
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced pythonCharles-Axel Dein
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
 
How to use Map() Filter() and Reduce() functions in Python | Edureka
How to use Map() Filter() and Reduce() functions in Python | EdurekaHow to use Map() Filter() and Reduce() functions in Python | Edureka
How to use Map() Filter() and Reduce() functions in Python | EdurekaEdureka!
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Edureka!
 
What is Python? | Edureka
What is Python? | EdurekaWhat is Python? | Edureka
What is Python? | EdurekaEdureka!
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionARVIND PANDE
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaEdureka!
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for KidsAimee Maree Forsstrom
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in javaAhsan Raja
 

Mais procurados (20)

Python Collections Tutorial | Edureka
Python Collections Tutorial | EdurekaPython Collections Tutorial | Edureka
Python Collections Tutorial | Edureka
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
 
What is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | EdurekaWhat is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | Edureka
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced python
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Python programming
Python  programmingPython  programming
Python programming
 
How to use Map() Filter() and Reduce() functions in Python | Edureka
How to use Map() Filter() and Reduce() functions in Python | EdurekaHow to use Map() Filter() and Reduce() functions in Python | Edureka
How to use Map() Filter() and Reduce() functions in Python | Edureka
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
 
What is Python? | Edureka
What is Python? | EdurekaWhat is Python? | Edureka
What is Python? | Edureka
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
 
Python programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphismPython programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphism
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for Kids
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 

Semelhante a Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programming Training | Edureka

Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administrationvceder
 
First look on python
First look on pythonFirst look on python
First look on pythonsenthil0809
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk PemulaOon Arfiandwi
 
Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suiteericholscher
 
PyCon Taiwan 2013 Tutorial
PyCon Taiwan 2013 TutorialPyCon Taiwan 2013 Tutorial
PyCon Taiwan 2013 TutorialJustin Lin
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MoreMatt Harrison
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Edureka!
 
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsSystem Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsashukiller7
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using SwiftDiego Freniche Brito
 
AI Machine Learning Complete Course: for PHP & Python Devs
AI Machine Learning Complete Course: for PHP & Python DevsAI Machine Learning Complete Course: for PHP & Python Devs
AI Machine Learning Complete Course: for PHP & Python DevsAmr Shawqy
 
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat Pôle Systematic Paris-Region
 

Semelhante a Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programming Training | Edureka (20)

Python for Linux System Administration
Python for Linux System AdministrationPython for Linux System Administration
Python for Linux System Administration
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
First look on python
First look on pythonFirst look on python
First look on python
 
Pythonpresent
PythonpresentPythonpresent
Pythonpresent
 
Mufix Network Programming Lecture
Mufix Network Programming LectureMufix Network Programming Lecture
Mufix Network Programming Lecture
 
Pemrograman Python untuk Pemula
Pemrograman Python untuk PemulaPemrograman Python untuk Pemula
Pemrograman Python untuk Pemula
 
Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suite
 
Python_intro.ppt
Python_intro.pptPython_intro.ppt
Python_intro.ppt
 
Python1
Python1Python1
Python1
 
PyCon Taiwan 2013 Tutorial
PyCon Taiwan 2013 TutorialPyCon Taiwan 2013 Tutorial
PyCon Taiwan 2013 Tutorial
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
 
Wait, IPython can do that?
Wait, IPython can do that?Wait, IPython can do that?
Wait, IPython can do that?
 
Python lec1
Python lec1Python lec1
Python lec1
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
 
Python para equipos de ciberseguridad
Python para equipos de ciberseguridad Python para equipos de ciberseguridad
Python para equipos de ciberseguridad
 
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsSystem Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
AI Machine Learning Complete Course: for PHP & Python Devs
AI Machine Learning Complete Course: for PHP & Python DevsAI Machine Learning Complete Course: for PHP & Python Devs
AI Machine Learning Complete Course: for PHP & Python Devs
 
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
 
Os lab final
Os lab finalOs lab final
Os lab final
 

Mais de Edureka!

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaEdureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaEdureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaEdureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaEdureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaEdureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaEdureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaEdureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaEdureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaEdureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaEdureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | EdurekaEdureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEdureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEdureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaEdureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaEdureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaEdureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaEdureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaEdureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | EdurekaEdureka!
 

Mais de Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Último

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 

Último (20)

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 

Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programming Training | Edureka

  • 1. Python Certification Training https://www.edureka.co/python Agenda Advanced Python Tutorial
  • 2. Python Certification Training https://www.edureka.co/python Agenda Advanced Python Tutorial
  • 3. Python Certification Training https://www.edureka.co/python Agenda Introduction 01 Introduction to Advanced Python Getting Started 02 Concepts 03 Practical Approach 04 Python and Shell Looking at code to understand theory Key Concepts in Python
  • 4. Python Certification Training https://www.edureka.co/python Introduction to Advanced Python Advanced Python Tutorial
  • 5. Python Certification Training https://www.edureka.co/python Introduction To Advanced Python Python is an interpreted, high-level, general-purpose programming language. What is Python? Advanced: Other Languages Learning Advanced Python
  • 6. Python Certification Training https://www.edureka.co/python What Is Advanced Python Computer Science5 Numerical Compute6 Databases7 Sys Programming 1 Graph Theory 2 Mathematics 3 Python spreading its wings across multiple dimensions and use-cases in many fields What is “Advanced”?
  • 7. Python Certification Training https://www.edureka.co/python Introduction To System Programming Advanced Python Tutorial
  • 8. Python Certification Training https://www.edureka.co/python System Programming Sys - Module Hello Advanced Python! Import sys Provides information about constants, functions and methods of the Python interpreter. Data streams stdout stderrstdin >>> import sys >>> sys.version '2.6.5 (r265:79063, Apr 16 2010, 13:57:41) n[GCC 4.4.3]' >>> sys.version_info (2, 6, 5, 'final', 0) >>>
  • 9. Python Certification Training https://www.edureka.co/python Command – Line Arguments Sys - Module Command Line argcargv #!/usr/bin/python import sys # it's easy to print this list of course: print sys.argv # or it can be iterated via a for loop: for i in range(len(sys.argv)): if i == 0: print "Function name: %s" % sys.argv[0] else: print "%d. argument: %s" % (i,sys.argv[i]) $ python arguments.py arg1 arg2 ['arguments.py', 'arg1', 'arg2'] Function name: arguments.py 1. argument: arg1 2. argument: arg2 $
  • 10. Python Certification Training https://www.edureka.co/python Changing Output Behaviour Sys - Module Python Interactive Mode Get Output Write expression >>> import sys >>> x = 42 >>> x 42 >>> import sys >>> def my_display(x): ... print "out: ", ... print x ... >>> sys.displayhook = my_display >>> x out: 42 >>> >>> print x 42 Behaviour of print() not changed
  • 11. Python Certification Training https://www.edureka.co/python Standard Data Streams Sys - Module >>> import sys >>> for i in (sys.stdin, sys.stdout, sys.stderr): ... print(i) ... ', mode 'w' at 0x7f3397a2c150> ', mode 'w' at 0x7f3397a2c1e0> >>> SHELLstdin stdout stderr >>> import sys >>> print "Going via stdout" Going via stdout >>> sys.stdout.write("Another way to do it!n") Another way to do it! >>> x = raw_input("read value via stdin: ") read value via stdin: 42 >>> print x 42 >>> print "type in value: ", ; sys.stdin.readline()[:-1] type in value: 42 '42' >>>
  • 12. Python Certification Training https://www.edureka.co/python Redirections Sys - Module import sys print("Coming through stdout") # stdout is saved save_stdout = sys.stdout fh = open("test.txt","w") sys.stdout = fh print("This line goes to test.txt") # return to normal: sys.stdout = save_stdout fh.close() SHELLstdin stdout stderr import sys save_stderr = sys.stderr fh = open("errors.txt","w") sys.stderr = fh x = 10 / 0 # return to normal: sys.stderr = save_stderr fh.close()
  • 13. Python Certification Training https://www.edureka.co/python Variables & Constants In Sys Module Sys - Module byteorder executable maxint modules path platform Variables Constants
  • 14. Python Certification Training https://www.edureka.co/python Python And Shell Advanced Python Tutorial
  • 15. Python Certification Training https://www.edureka.co/python Python And Shell A piece of software that provides an interface for a user to some other software or the operating system What is “Shell”? SHELL GUICUI Bourne-Shell C-Shell Bash Shell
  • 16. Python Certification Training https://www.edureka.co/python System Programming The activity of programming system components or system software What is “SP”? “System focussed programming” Modules sys os Simple and clear Well structured Highly flexible Advantages
  • 17. Python Certification Training https://www.edureka.co/python The ‘os’ Module The os module allows platform independent programming by providing abstract methods What is “os” module? Executing Shell scripts with os.system() import os def getch(): os.system("bash -c "read -n 1"") getch() from msvcrt import getch
  • 18. Python Certification Training https://www.edureka.co/python The ‘os’ Module Executing Shell scripts with os.system() import os, platform if platform.system() == "Windows": import msvcrt def getch(): if platform.system() == "Linux": os.system("bash -c "read -n 1"") else: msvcrt.getch() print("Type a key!") getch() print("Okay") Subprocess Module os.system os.spawn* os.popen*
  • 19. Python Certification Training https://www.edureka.co/python Forking In Python Advanced Python Tutorial
  • 20. Python Certification Training https://www.edureka.co/python Fork In Python What is Forking? import os def child(): print('nA new child ', os.getpid()) os._exit(0) def parent(): while True: newpid = os.fork() if newpid == 0: child() else: pids = (os.getpid(), newpid) print("parent: %d, child: %dn" % pids) reply = input("q for quit / c for new fork") if reply == 'c': continue else: break parent() Process Copy of Process Parent Child Starting independent processes with fork() exec*() function
  • 21. Python Certification Training https://www.edureka.co/python The exec*() Functions exec*() functions • os.execl(path, arg0, arg1, ...) • os.execle(path, arg0, arg1, ..., env) • os.execlp(file, arg0, arg1, ...) • os.execlpe(file, arg0, arg1, ..., env) • os.execv(path, args) • os.execve(path, args, env) • os.execvp(file, args) • os.execvpe(file, args, env)
  • 22. Python Certification Training https://www.edureka.co/python Threads In Python Advanced Python Tutorial
  • 23. Python Certification Training https://www.edureka.co/python What Is A Thread? The smallest unit that can be scheduled in an operating systemWhat is a thread? How to create a thread? By forking a computer program in two or more parallel tasks Types of threads Kernel threads User threads Implemented in kernel NOT implemented in kernel
  • 24. Python Certification Training https://www.edureka.co/python What Is A Thread? Global Variables Process Local variables Code THREAD Local variables Code THREAD Local variables Code THREAD
  • 25. Python Certification Training https://www.edureka.co/python The Thread Module from thread import start_new_thread def heron(a): """Calculates the square root of a""" eps = 0.0000001 old = 1 new = 1 while True: old,new = new, (new + a/new) / 2.0 print old, new if abs(new - old) < eps: break return new start_new_thread(heron,(99,)) start_new_thread(heron,(999,)) start_new_thread(heron,(1733,)) c = raw_input("Type something to quit.") Example
  • 26. Python Certification Training https://www.edureka.co/python The Thread Module from thread import start_new_thread num_threads = 0 def heron(a): global num_threads num_threads += 1 # code has been left out, see above num_threads -= 1 return new start_new_thread(heron,(99,)) start_new_thread(heron,(999,)) start_new_thread(heron,(1733,)) start_new_thread(heron,(17334,)) while num_threads > 0: pass Previous example with counters for the threads • Reading the value of num_thread • A new int instance will be incremented or decremented by 1 • the new value has to be assigned to num_threads
  • 27. Python Certification Training https://www.edureka.co/python The Thread Module from thread import start_new_thread, allocate_lock num_threads = 0 thread_started = False lock = allocate_lock() def heron(a): global num_threads, thread_started lock.acquire() num_threads += 1 thread_started = True lock.release() ... lock.acquire() num_threads -= 1 lock.release() return new start_new_thread(heron,(99,)) start_new_thread(heron,(999,)) start_new_thread(heron,(1733,)) while not thread_started: pass while num_threads > 0: pass The solution
  • 28. Python Certification Training https://www.edureka.co/python Threading Module import time from threading import Thread def sleeper(i): print "thread %d sleeps for 5 seconds" % i time.sleep(5) print "thread %d woke up" % i for i in range(10): t = Thread(target=sleeper, args=(i,)) t.start() Example The Thread of the example doesn't do a lot, essentially it just sleeps for 5 seconds and then prints out a message:
  • 29. Python Certification Training https://www.edureka.co/python Threading Module thread 0 sleeps for 5 seconds thread 1 sleeps for 5 seconds thread 2 sleeps for 5 seconds thread 3 sleeps for 5 seconds thread 4 sleeps for 5 seconds thread 5 sleeps for 5 seconds thread 6 sleeps for 5 seconds thread 7 sleeps for 5 seconds thread 8 sleeps for 5 seconds thread 9 sleeps for 5 seconds thread 1 woke up thread 0 woke up thread 3 woke up thread 2 woke up thread 5 woke up thread 9 woke up thread 8 woke up thread 7 woke up thread 6 woke up thread 4 woke up
  • 30. Python Certification Training https://www.edureka.co/python Pipes In Python Advanced Python Tutorial
  • 31. Python Certification Training https://www.edureka.co/python What Are Pipes Introducing modularity in the program to serve one instance output as the input to another instance and so on till solution is achieved What are pipes? Two kinds of pipes Named PipesAnonymous Pipes Exist solely within processes and are usually used in combination with forks P1 P2 P3 P4
  • 32. Python Certification Training https://www.edureka.co/python Pipes – A Classic Example 99 Bottles of Beer Drinking is injurious to health Ninety-nine bottles of beer on the wall, Ninety-nine bottles of beer. Take one down, pass it around, Ninety-eight bottles of beer on the wall. Lyrics of the song:
  • 33. Python Certification Training https://www.edureka.co/python Named Pipes Called FIFOs – Creating pipes which are implemented as files.What are named pipes? First In – First Out A process reads from and writes to such a pipe as if it were a regular file. Sometimes more than one process write to such a pipe but only one process reads from it.
  • 34. Python Certification Training https://www.edureka.co/python Conclusion Advanced Python Tutorial
  • 35. Python Certification Training https://www.edureka.co/python Conclusion Advanced Python, yay!