0% found this document useful (0 votes)
54 views20 pages

UNIT 3 Developing IoTs-Control Flow

Control flow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views20 pages

UNIT 3 Developing IoTs-Control Flow

Control flow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

UNIT –III

DEVELOPING IOTs

IoT design methodology - Motivation for using Python- Logical

Design using Python - Control Flow – Packages - File Handling -

Classes - Python Packages of Interest for IoT - Case Study on IoT

System for Weather Monitoring


Control Flow
Control Flow

• Python program control flow is regulated by various types


of conditional statements, loops, and function calls.
Control Flow
 if statement
 for statement
 while statement
 range statement
 break/continue statement
 pass statement
Control Flow-if statement
• The if statement in Python is similar to the if statement in
other languages.
Control Flow-for statement
• The for statement in Python iterates over items of any sequence (list,
string, etc.) in the order in which they appear in the sequence.
• This behavior is different from the for statement in other languages
such as C in which an initialization, incrementing and stopping
criteria are provided.
Control Flow-while statement
• The while statement in Python executes the statements within the
while loop as long as the while condition is true.
Control Flow-range statement
• The range statement in Python generates a list of numbers in
arithmetic progression.
Control Flow- break/continue statement
• The break and continue statements in Python are similar to the
statements in C.
Control Flow- pass statement
• The pass statement in Python is a null operation.
• The pass statement is used when a statement is required
syntactically but you do not want any command or code to
execute.
File Handling
File Handling

• Python allows reading and writing to files using the file object.
• The open(filename, mode) function is used to get a file
object.
• The mode can be read (r), write (w), append (a), read and
write (r+ or w+), read-binary (rb), write-binary (wb), etc.
• After the file contents have been read the close function is
called which closes the file object.
File Handling - Examples
Ex: To use seek function to set the position of the file pointer within
a file
Data.txt file: PrepBytes is an Ed-Tech Company

file=open(“data.txt”,’r’)
file.seek(10)
data=file.read(5)
print(data)
file.close() Output: is an
Python Packages of Interest for IoT
Python Packages of Interest for IoT

• JSON
• XML
• HTTPLib & URLLib
• SMTPLib
• NumPy
• Scikit-learn
Python Packages of Interest for IoT
JSON
• Java Script Object Notation (JSON) is an easy to read and write data-
interchange format.
• It is an alternative to XML and is easy for machines to parse and generate.
• It is built on two structures- a collection of name-value pairs (eg:-a Python
dictionary) and ordered lists of values (eg:- a Python List)

XML
• XML (Extensible Markup Language) is a data format for structured document
interchange.
• The Python minidom library(accessing and modifying XML documents)
provides a minimal implementation of the document object model interface
and has API similar to that in other languages.
Python Packages of Interest for IoT

HTTPLib & URLLib


• HTTPLib2 and URLLib2 are Python libraries used in network/
internet programming.
• URLLib2 - handles opening and reading URLs.
• HTTPLib2 - handles http request
SMTPLib
• Simple Mail Transfer Protocol (SMTP) is a protocol which handles
sending email and routing e-mail between mail servers.
• The Python smtplib module provides an SMTP client session object
that can be used to send email.
Python Packages of Interest for IoT
NumPy
• NumPy is a package for scientific computing in Python.
• NumPy provides support for large multi-dimensional arrays and
matrices.
Scikit-learn
• It is an open source machine learning library for Python that
provides implementations of various machine learning algorithms
for classification, clustering, regression and dimension reduction
problems.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy