RobertoStefanetti
997 views
42 slides
Mar 18, 2019
Slide 1 of 42
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
About This Presentation
Python for dummies
Size: 2.35 MB
Language: en
Added: Mar 18, 2019
Slides: 42 pages
Slide Content
Roberto Stefanetti, MVP Business Applications Microsoft Education Influencer https :// robertostefanettinavblog.com Python for Dummies 1969-2019 “Fortran with Apollo 11 and Python for Mission to Mars” Roberto Stefanetti
WHAT IS PYTHON ? PYTHON ? https://www.python.org Python is an open source programming language that was made to be easy-to-read and powerful . A Dutch programmer named Guido van Rossum made Python in 1991. He named it after the television show Monty Python's Flying Circus
Python Diffusion
PYTHON IS USED IN.. Python is used in... a lot of institutions ! NASA, Facebook, Google, Mozilla, Yahoo, Dropbox, IBM, Youtube, iRobot, Maya, Paint apps etc. etc. … these “ Giants ” use Python in their “ CORE products ” and services!
DOWNLOAD PYTHON Python can be run on Apache ( Linux ) and IIS ( Windows ) and in Visual Studio Code (as Python Extension) Python for Windows Download from https ://www.python.org/downloads/windows/
PYTHON for Visual Studio Code Python can be run also in Visual Studio Code (as Python Extension).. Nice for Business Central Developers…
About Python Python is: Programming language Scripting language Interpreted language (called AS IS) Open Source (by Design) Born between 1980-1990
Python is for Python is for: “A lot of implementations” Desktop App, Mobile App, Web App AI & ML Data Science IoT (Internet of Things) Interfaces…. ..and many other things
Python can manage Python can manage: UI Databases Calculations Graphics Scripting & Programming Authentications & protocols
Phyton Technology Python Technology Object oriented language (polymorph, inheritance, overriding etc.) Interpreted (copy and run fast!…) Clear and simple code Language is expandable with other sub languages (ex: Flask module) Extensible (libraries) #import…. modules
Python Editor Python Editor SHELL
Source Code “.py” and “.pyc” Python Source Code Extension code is “ .py ” Python Code Translated to byte code (complied to “ .pyc ”) Compiled Python On Virtual Machine Written and compiled but interpreted
Syntax Syntax Python Identifier : a name used to identify a variable, function, class, module or other objects. An Identifier start with a letter A..Z or a..z or an _ ( underscore ) NO punctuation chars : @, $, % etc., is CASE SENSITIVE NO Braches for blocks (only indentation) # is a comment Python u se ‘, ‘’, ‘’’ quote to define strings if Condition: Statement = ‘test’ e lse: OtherStatement = ‘test2’
Data Types Data Types Major Python data types: String - ‘’ & “” List - [1,2,’aa’,True] Tuple - (34, 3.4, ‘aa’, True) immutable Set/frozenset - set(1,2, ‘aa’,True) Hash Dictionary - {‘k1’:1, ‘k2’:False} Groups of Keys and values
Strings Strings String: a contiguous set of chars in quotation marks. Subset string : taken using slice operator ([], [:]) + = concatenation operator * = repetition operator
Lists Lists Lists: separate by commas and enclosed in brackets [] (like C,C# arrays) Data Values : you can access to lists data values using with slice operators + = concatenation operator * = repetition operator
Conditionals Conditionals Statements If statement (boolean expression) If else statement (with optional else) Nested if statements (if nested in other if..)
Loops Types of loops While loop For loop
Functions Functions A function is an organized and “ reusable ” block of code. Many Built-in Functions are already available (ex: print ) You can create your “user functions” A Function block start with def followed b y name and () def my_function( fname ): print (fname + " Refsnes" ) my_function( "Emil" ) my_function( "Tobias" ) my_function( "Linus" ) def my_function(): print ( "Hello from a function" ) my_function()
Functions Functions - return value & recursion def tri_recursion(k): if (k> ): result = k+tri_recursion(k- 1 ) print(result) else : result = return result print( "\n\nRecursion Example Results" ) tri_recursion( 6 ) def my_function(x): return 5 * x print (my_function( 3 )) print (my_function( 5 )) print (my_function( 9 ))
Function with Description Function with Descriptions cmp (listA, listB ) compare elements len(list) total length max(list) max & Min m in(list) list(seq) convert a tuple into a list
Modules Python Module? file containing python statements (DLL like) “Divide and impera” with modules Module is a object with a lot of functions (like a function server or function package) You can “ Import Modules ”
Inheritance Inheritance ? > Sure, you can create a parent class and a child class class Person : def __init__(self, fname, lname): self.firstname = fname self.lastname = lname def printname(self): print(self.firstname, self.lastname) #Use the Person class to create an object, and then execute the printname method: x = Person( "John" , "Doe" ) x.printname() class Student (Person): pass x = Student( "Mike" , "Olsen" ) x.printname()
Try-Except Try-Except The try block lets you test a block of code for errors The except block lets you handle the error The finally block lets you execute code, regardless of the result of the try- and except blocks try : print (x) except : print ( "An exception occurred" )
Json ( Convert from JSON to Python & Vice-versa ) Json import json # some JSON: x = '{ "name":"John", "age":30, "city":"New York"}' # parse x: y = json.loads(x) # the result is a Python dictionary: print (y[ "age" ]) Convert from JSON to Python: Convert from Python to JSON: import json # a Python object (dict): x = { "name" : "John" , "age" : 30 , "city" : "New York" } # convert into JSON: y = json.dumps(x) # the result is a JSON string: print (y)
Import modules Import modules normal import (import entire module with ALL properties) from import (import required properties from a module.. ..not all module’s features are available ..example: only a function from a module)
PYTHON LIMITATIONS PYTHON LIMITATIONS Performance (interpreted) Not Mobile: not available in mobile applications! NO, not true to date …now you can have! https://www.ongraph.com/a-list-of-top-10-python-frameworks-for-app-development /
PYTHON BEST MODULES WE CAN HAVE PYTHON MODULES OF ANY TYPES Below a short list: Mongo SQLAlchemy Wx Phyton Twisted Mathplotlib Requests Beautiful Soap Pygame Fabric http://blog.stoneriverelearning.com/20-great-python-libraries-you-must-know /
PYTHON BEST FRAMEWORKS BEST FRAMEWORS Below a short list: Django Flask Web2py Pandas Bottle Falcon TurboGears NumPy https ://www.ongraph.com/a-list-of-top-10-python-frameworks-for-app-development /
FLASK (for Python) FLASK Flask is a micro-web framework , thus does not need particular tools or libraries. It built-in with development server and support for unit testing. This Unicode based platform supports RESTFUL ask for dispatching and is broadly reported for application developers to begin . Course: Great Free Course @Harvard.edu https:// online-learning.harvard.edu/course/cs50s-web-programming-python-and-javascript?delta=0 http://flask.pocoo.org/
FLASK (for Python) Dev Environment FLASK Dev Environment - Install Install Windows Flask Dev Env 4 Steps: - Install Python -Install Pip -Install VirtualEnv -Install VirtualEnvWrapper-win http ://timmyreilly.azurewebsites.net/python-flask-windows-development-environment-setup /
FLASK (for Python) Dev Environment FLASK Dev Environment USAGE 7 Steps: -Make a Virtual Environment -Connect our project with our Environment -Set Project Directory -Deactivate -Workon -Pip Install -Flask !
FLASK IS FUN! FLASK IS FUN! http ://flask.pocoo.org / https://realpython.com/flask-by-example-part-1-project-setup / http://timmyreilly.azurewebsites.net/python-flask-windows-development-environment-setup / https:// medium.freecodecamp.org/how-to-build-a-web-application-using-flask-and-deploy-it-to-the-cloud-3551c985e492
FLASK DEMO: TIC-TAC-TOC FLASK TIC-TAC-TOC Tic Tac Toe using Flask framework and Angular. AI uses the minimax algorithm to calculate moves . https :// github.com/Buuntu/minimax-algorithm Angular + Python + Flask — Full stack https ://medium.com/@ balramchavan/angular-python-flask-full-stack-demo-27192b8de1a3
FLASK DEMO: TIC-TAC-TOC FLASK TIC-TAC-TOC – PART OF CODE
EXAMPLE: CONSUMING a Dynamics 365 Business Central APIs from PYTHON https://robertostefanettinavblog.com/2019/03/09/consuming-business-central-apis-from-python /
EXAMPLE: CONSUMING a Dynamics 365 Business Central APIs from PYTHON
Python & Flask – Best L inks Python.org https ://www.python.org / Python Tutorial https://www.w3schools.com/python / Flask Tutorial (best Web micro-framework) https:// github.com/rstefanetti/SPGISummer2018-FlaskTutorial https:// medium.freecodecamp.org/how-to-build-a-web-application-using-flask-and-deploy-it-to-the-cloud-3551c985e492 https:// www.linkedin.com/learning/building-web-apis-with-flask?trk=search-cluster_flagship_learning http://timmyreilly.azurewebsites.net/python-flask-windows-development-environment-setup / Example of System Integrations with Python https://robertostefanettinavblog.com/2019/03/09/consuming-business-central-apis-from-python /
THANKS FOR WATCHING ! Roberto Stefanetti, MVP Business Applications Microsoft Education Influencer https :// robertostefanettinavblog.com