2. 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
4. 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!
5. 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/
6. PYTHON for Visual Studio Code
Python can be run also in Visual Studio Code (as Python
Extension).. Nice for Business Central Developers…
7. About Python
Python is:
• Programming language
• Scripting language
• Interpreted language (called AS IS)
• Open Source (by Design)
• Born between 1980-1990
8. 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
10. 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
12. 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
13. 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 use ‘, ‘’, ‘’’ quote to define strings
if Condition:
Statement = ‘test’
else:
OtherStatement = ‘test2’
14. 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
15. Strings
Strings
String: a contiguous set of chars in quotation marks.
Subset string: taken using slice operator ([], [:])
+ = concatenation operator
* = repetition operator
16. 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
21. 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 by 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()
22. Functions
Functions - return value & recursion
def tri_recursion(k):
if(k>0):
result = k+tri_recursion(k-1)
print(result)
else:
result = 0
return result
print("nnRecursion Example Results")
tri_recursion(6)
def my_function(x):
return 5 * x
print(my_function(3))
print(my_function(5))
print(my_function(9))
23. Function with Description
Function with Descriptions
cmp(listA, listB) compare elements
len(list) total length
max(list) max & Min
min(list)
list(seq) convert a tuple into a list
24. 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”
25. 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()
26. 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")
27. 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)
29. 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)
30. 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/
31. 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/
32. 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/
33. 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/
34. 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/
35. 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!
36. 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
37. 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
39. EXAMPLE: CONSUMING a Dynamics 365
Business Central APIs from PYTHON
https://robertostefanettinavblog.com/2019/03/09/cons
uming-business-central-apis-from-python/
41. Python & Flask – Best Links
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/