SlideShare uma empresa Scribd logo
1 de 9
Baixar para ler offline
Slide 1
------------
Python - why settle for snake oil when you can have the whole snake?

Slide 2
------------
* This is a workshop, not a talk.
* You are expected to code along.
* So pull out your laptops, and
* Install python, ipython and komodo edit. (Or editor of your choice.)

Slide 3
------------
* Assume that you know programming in any language.
* So we dont spend a lot of time explaining basics.
* BUT, stop and ask if something doesn't make sense.
* AND Definately Stop me if I am going too slow, too fast, or making no sense.

Slide 4
------------
* Python *

* Dynamically but strongly typed.
* Very object oriented - everything is an object.
* But pragmatic - Objects aren't everthing.
* Allows various paradigms of programming - OO, procedural, functional.
* Shallow learning curve, but powerful powerful capabilities avaialble, when you
need them.
* import this
* We will come back to this slide.

Slide 4.1
-----------
* Hello world *

>>> print "Hello World"

Slide 5
-------------
* Lets start *

*   The control structures.
*   for, while, if, else, break, continue
*   -Yeah they are available, surprised?
*   We will use them in a moment, but after we see the data structures available.


Slide 6
----------

* The data strcutures *

* List - Like ArrayList in Java
* Tuple - Like List, but immutable
* Dict - Like Hashmaps in Java

--Hid

In [1]: v1 = [1, 2, 3, 4, 5]

In [2]: v2 = (1, 2, 3, 4, 5)
In [3]: v3 = {1:'a', 2:'b'}

In [4]: type(v1)
Out[4]: <type 'list'>

In [5]: type(v2)
Out[5]: <type 'tuple'>

In [6]: type(v3)
Out[6]: <type 'dict'>

Slide 7
-----------
* The control structures. *

* For Loop
* for el in iterable:
    [block statement]
* the classic for loop
* for (int i; i < n; i++){}
* for i in range(n):
    #Work with i
* while condition:
    [block]
* break, continue. Normal operation - break out of current loop.


--Hidden--
In [10]: for el in v1:
   ....:     print el
   ....:
   ....:
1
2
3
4
5

In [11]: x = 5

In [12]: while x < 100:
   ....:     print x
   ....:     x = x * 2
   ....:
   ....:
5
10
20
40
80

Slide 8
--------------

Conditionals
--------------
*If: elif: else:*

*   if condition:
        [block]
    else:
        [block]
--Hidden--

       In [15]: if f == 10:
      ....:     print 'Ten'
      ....: else:
      ....:     print 'Not 10'
      ....:
      ....:
Ten

if f == 12:
    print 'Ten'
 else:
    print 'Not 10'

Slide 9
--------------

* The fizzbuzz test *
* You have enough information now to write a solution
* Problem statement
Write a program that prints the numbers from 1 to 100. But for multiples of
three print "Fizz" instead of the number and for the multiples of five print
"Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

--Hidden---
Give time here

[Wrong]
for i in range(1, 101):
    if i % 3 == 0:
        print 'fizz'
    elif i % 5 == 0:
        print 'buzz'
    elif i % 15 == 0:
        print 'fizzbuzz'
    else:
        print i

[One sol]

for i in range(1, 101):
    if i % 15 == 0:
        print 'fizzbuzz'
    elif i % 3 == 0:
        print 'fizz'
    elif i % 5 == 0:
        print 'buzz'

      else:
          print i

Slide 10
------------

* Functions *

def function_name(argument_list):
    [block]

* Functions can have default value.
def fizzbuzz(till=100, fizz='fizz', buzz='buzz'):
    #fizzbuzz code

* Functions can have variable length values.

ex multiply all values passed to a function.

* Functions are first class - They are objects too. They can be passed to other
functions, assigned to variables etc.

--Hidden--
In [33]: def func():
   ....:     pass
   ....:

In [34]: type(func)
Out[34]: <type 'function'>

In [35]: def mult_all(*args):
   ....:     i = 1
   ....:     for el in args:
   ....:         i = i * el
   ....:
   ....:     return i
   ....:

In [36]: mult_all(2, 3, 4, 5)
Out[36]: 120

Slide 11
-----------
* Classes *

class ClassName(base_classes):
    [block]

* Classes are first class too
* They can be passed to function, and assigned to variables.

---Hiden---

class Accounts(object):
    def __init__(self, account_holder, initial_deposit):
        self.account_holder = account_holder
        self.money_available = initial_deposit
        self.history = []

    def withdraw(self, amount):
        self.money_available = self.money_available - amount
        self.history.append('Withdrew %s'%amount)

    def deposit(self, amount):
        self.money_available = self.money_available + amount
        self.history.append('Deposited %s'%amount)

    def __str__(self):
        return "%s has %s available." % (self.account_holder,
self.money_available)

    def __repr__(self):
        return str(self)
Slide 12
-----------

* Time for another problem *

* Project euler: problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get
3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000

--hidden--
In [15]: sum = 0

In [16]: for i in range(1000):

Display all 213 possibilities? (y or n)

In [16]: for i in range(1000):

   ....:      if i % 3 == 0 or i % 5 == 0:
   ....:          sum += i
   ....:
   ....:

In [18]: print sum
-------> print(sum)
233168


Slide 13
-----------
* Here comes the list comprehensions *

* The last sulotion was needlessly verbose
* List comprehension: Take a list and transform it.
* Standard list comrehension syntax - [expr(i) for i in iterable if condition]
* List of all squares: [i*i for i in range(1,11)]
* List of all squares of even numbers: [i*i for i in range(1,11) if i%2 == 0]
* So solution to last problem is just
sum([i*i for i in range(1,1001) if i%3 == 0 or i%5==0])

--Hidden--
In [19]: [i*i for i in range(1,11)]
Out[19]: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
In [1]: sum([i*i for i in range(1,1001) if i%3 == 0 or i%5==0])
Out[1]: 156390386

Slide 14
-----------
*Some functional programming*

* List comprehensions are python way to do functional programming constructs
* [function(i) for i in iterable if condition] is filter(func2, map(func1,
iter))
* Lets see how this list comprehension maps to functional concepts
* Get the list of squares of even numbers

--Hidden--
In [5]: filter(lambda x: x%2==0, map(lambda x: x ** 2, range(1, 11)))
Out[5]: [4, 16, 36, 64, 100]

In [6]: [el*el for el in range(1, 11) if el%2 ==0]
Out[6]: [4, 16, 36, 64, 100]

Slide 15
--------------
*File Handling*

* Open a file with - open('location') or file('location')
* or give a mode - open('location', 'rw')
* iterate as
for line in open_file.readlines():
    print line#Or whatvere

or
string = open_file.read()


--Hidden--

In [8]: open_file = open('/home/shabda/python_talk/11.txt')

In [9]: for el in open_file.readlines():
   ...:     print el
   ...:     break
   ...:
   ...:
Project Gutenberg's Alice's Adventures in Wonderland, by Lewis Carroll


Slide 16
--------------

*Some actual work*

Find the most commonly used word in the Alice in wonderland text.

--Hidden--
Give time here

#!/usr/bin/env python
from operator import itemgetter

open_file = open('/home/shabda/python_talk/11.txt')
text = open_file.read()
words = text.split()
word_count = {}
for word in words:
    if word in word_count:
        word_count[word] += 1
    else:
        word_count[word] = 1

sorted_list = sorted(word_count.items(), key=itemgetter(1), reverse=True)
print sorted_list[0]


Slide 17
------------
* Problems *
* Ok, now you suggets some problems and lets solve them together.

Slide 18
-------------
* A tour of the standard library *

*   Batteries included
*   math
*   datetime
*   string
*   re
*   random
*   os
*   pickle
*   Do a dir and see for yourself.

And a lot, lot more
http://docs.python.org/library/

--hidden--
Spend time here

In [14]: math.cos(math.pi)
Out[14]: -1.0

In [9]: datetime.date.today() > datetime.date(2008, 9, 12)
Out[9]: True

In [18]: string.capitalize('python is a programming language.')
Out[18]: 'Python is a programming language.'




In [19]: import random

In [20]: random.choice(['ubuntu', 'redhat', 'xandros'])
Out[20]: 'xandros'

In [21]: random.choice(['ubuntu', 'redhat', 'xandros'])
Out[21]: 'ubuntu'

Slide 19
-------------

* Back to slide 4 *

* Dynamically but strongly typed.
* Very object oriented - everything is an object.
* But pragmatic - Objects aren't everthing.
* Allows various paradigms of programming - OO, procedural, functional.
* Shallow learning curve, but powerful powerful capabilities avaialble, when you
need them.
* import this

--Hidden--
Explain.

* Slide 20 *
---------------
* Decorators *
Syntacting sugar for
foo_func =docorator_func(foo_func)

--Hidden--

In [1]: def good_function():
   ...:     print 'I am a good function'
   ...:
   ...:

In [2]: def decorator(orig_func):
   ...:     def bad_func():
   ...:         print 'I am a bad function'
   ...:     return bad_func
   ...:

In [3]: good_function = decorator(good_function)

In [4]: good_function()
I am a bad function

In [5]: @decorator
   ....: def good_function2():
   ....:     print 'I am a good function'
   ....:
   ....:

In [6]: good_function2()
I am a bad function


#!/usr/bin/env python

def is_val_positive_deco(orig_func):
        def temp_func(val):
                if val < 0:
                         return 0
                else:
                         return orig_func(val)
        return temp_func

@is_val_positive_deco
def sqrt(val):
        import math
        return math.pow(val, (1.0/2))

print sqrt(-1)
print sqrt(4)

Slide 21
---------------
* Web development with Python *

* Many useful frameworks
* Django
* GAE
* Turbogears
* We recommend Django - Most actively developed and largest community
participation


Slide 22
----------
*If we have time*
* PIL - Image Manipulation
* Mechanize - Browser automation
* Beautiful Soup - Html extraction.

Slide 23
-------------
* Resources *
python.org
diveintopython.org
uswaretech.com/blog

Slide 24
----------
* Thank You. *
You can give feedback, ask questions at shabda@uswaretech.com

Mais conteúdo relacionado

Mais procurados

Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a ElixirSvet Ivantchev
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей КоваленкоFwdays
 
Dts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinDts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinAhmad Arif Faizin
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?Adam Dudczak
 
4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладкаDEVTYPE
 
Design Pattern Observations
Design Pattern ObservationsDesign Pattern Observations
Design Pattern ObservationsDmitri Nesteruk
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedSusan Potter
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScriptGarth Gilmour
 
The best language in the world
The best language in the worldThe best language in the world
The best language in the worldDavid Muñoz Díaz
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196Mahmoud Samir Fayed
 
T3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerT3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerDavid Muñoz Díaz
 
Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)David de Boer
 

Mais procurados (20)

Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
 
Dts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinDts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlin
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка
 
C++ L05-Functions
C++ L05-FunctionsC++ L05-Functions
C++ L05-Functions
 
Design Pattern Observations
Design Pattern ObservationsDesign Pattern Observations
Design Pattern Observations
 
PythonOOP
PythonOOPPythonOOP
PythonOOP
 
Collection Core Concept
Collection Core ConceptCollection Core Concept
Collection Core Concept
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
Python
PythonPython
Python
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
 
The best language in the world
The best language in the worldThe best language in the world
The best language in the world
 
Why Haskell
Why HaskellWhy Haskell
Why Haskell
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
 
T3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerT3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmer
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)
 

Semelhante a Talk Code

A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsMichael Pirnat
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnArnaud Joly
 
The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31Mahmoud Samir Fayed
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88Mahmoud Samir Fayed
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notesRajiv Gupta
 
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88Mahmoud Samir Fayed
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonakaptur
 
The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30Mahmoud Samir Fayed
 
Functional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonFunctional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonCarlos V.
 
Ansible for Beginners
Ansible for BeginnersAnsible for Beginners
Ansible for BeginnersArie Bregman
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docxjosies1
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...Yashpatel821746
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Yashpatel821746
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...Yashpatel821746
 

Semelhante a Talk Code (20)

Cc code cards
Cc code cardsCc code cards
Cc code cards
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
 
The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31The Ring programming language version 1.5 book - Part 5 of 31
The Ring programming language version 1.5 book - Part 5 of 31
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notes
 
Calvix python
Calvix pythonCalvix python
Calvix python
 
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189
 
Functional python
Functional pythonFunctional python
Functional python
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30
 
Boosting Developer Productivity with Clang
Boosting Developer Productivity with ClangBoosting Developer Productivity with Clang
Boosting Developer Productivity with Clang
 
Functional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonFunctional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with Python
 
Ansible for Beginners
Ansible for BeginnersAnsible for Beginners
Ansible for Beginners
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
 

Último

Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 

Último (20)

Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 

Talk Code

  • 1. Slide 1 ------------ Python - why settle for snake oil when you can have the whole snake? Slide 2 ------------ * This is a workshop, not a talk. * You are expected to code along. * So pull out your laptops, and * Install python, ipython and komodo edit. (Or editor of your choice.) Slide 3 ------------ * Assume that you know programming in any language. * So we dont spend a lot of time explaining basics. * BUT, stop and ask if something doesn't make sense. * AND Definately Stop me if I am going too slow, too fast, or making no sense. Slide 4 ------------ * Python * * Dynamically but strongly typed. * Very object oriented - everything is an object. * But pragmatic - Objects aren't everthing. * Allows various paradigms of programming - OO, procedural, functional. * Shallow learning curve, but powerful powerful capabilities avaialble, when you need them. * import this * We will come back to this slide. Slide 4.1 ----------- * Hello world * >>> print "Hello World" Slide 5 ------------- * Lets start * * The control structures. * for, while, if, else, break, continue * -Yeah they are available, surprised? * We will use them in a moment, but after we see the data structures available. Slide 6 ---------- * The data strcutures * * List - Like ArrayList in Java * Tuple - Like List, but immutable * Dict - Like Hashmaps in Java --Hid In [1]: v1 = [1, 2, 3, 4, 5] In [2]: v2 = (1, 2, 3, 4, 5)
  • 2. In [3]: v3 = {1:'a', 2:'b'} In [4]: type(v1) Out[4]: <type 'list'> In [5]: type(v2) Out[5]: <type 'tuple'> In [6]: type(v3) Out[6]: <type 'dict'> Slide 7 ----------- * The control structures. * * For Loop * for el in iterable: [block statement] * the classic for loop * for (int i; i < n; i++){} * for i in range(n): #Work with i * while condition: [block] * break, continue. Normal operation - break out of current loop. --Hidden-- In [10]: for el in v1: ....: print el ....: ....: 1 2 3 4 5 In [11]: x = 5 In [12]: while x < 100: ....: print x ....: x = x * 2 ....: ....: 5 10 20 40 80 Slide 8 -------------- Conditionals -------------- *If: elif: else:* * if condition: [block] else: [block]
  • 3. --Hidden-- In [15]: if f == 10: ....: print 'Ten' ....: else: ....: print 'Not 10' ....: ....: Ten if f == 12: print 'Ten' else: print 'Not 10' Slide 9 -------------- * The fizzbuzz test * * You have enough information now to write a solution * Problem statement Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". --Hidden--- Give time here [Wrong] for i in range(1, 101): if i % 3 == 0: print 'fizz' elif i % 5 == 0: print 'buzz' elif i % 15 == 0: print 'fizzbuzz' else: print i [One sol] for i in range(1, 101): if i % 15 == 0: print 'fizzbuzz' elif i % 3 == 0: print 'fizz' elif i % 5 == 0: print 'buzz' else: print i Slide 10 ------------ * Functions * def function_name(argument_list): [block] * Functions can have default value.
  • 4. def fizzbuzz(till=100, fizz='fizz', buzz='buzz'): #fizzbuzz code * Functions can have variable length values. ex multiply all values passed to a function. * Functions are first class - They are objects too. They can be passed to other functions, assigned to variables etc. --Hidden-- In [33]: def func(): ....: pass ....: In [34]: type(func) Out[34]: <type 'function'> In [35]: def mult_all(*args): ....: i = 1 ....: for el in args: ....: i = i * el ....: ....: return i ....: In [36]: mult_all(2, 3, 4, 5) Out[36]: 120 Slide 11 ----------- * Classes * class ClassName(base_classes): [block] * Classes are first class too * They can be passed to function, and assigned to variables. ---Hiden--- class Accounts(object): def __init__(self, account_holder, initial_deposit): self.account_holder = account_holder self.money_available = initial_deposit self.history = [] def withdraw(self, amount): self.money_available = self.money_available - amount self.history.append('Withdrew %s'%amount) def deposit(self, amount): self.money_available = self.money_available + amount self.history.append('Deposited %s'%amount) def __str__(self): return "%s has %s available." % (self.account_holder, self.money_available) def __repr__(self): return str(self)
  • 5. Slide 12 ----------- * Time for another problem * * Project euler: problem 1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000 --hidden-- In [15]: sum = 0 In [16]: for i in range(1000): Display all 213 possibilities? (y or n) In [16]: for i in range(1000): ....: if i % 3 == 0 or i % 5 == 0: ....: sum += i ....: ....: In [18]: print sum -------> print(sum) 233168 Slide 13 ----------- * Here comes the list comprehensions * * The last sulotion was needlessly verbose * List comprehension: Take a list and transform it. * Standard list comrehension syntax - [expr(i) for i in iterable if condition] * List of all squares: [i*i for i in range(1,11)] * List of all squares of even numbers: [i*i for i in range(1,11) if i%2 == 0] * So solution to last problem is just sum([i*i for i in range(1,1001) if i%3 == 0 or i%5==0]) --Hidden-- In [19]: [i*i for i in range(1,11)] Out[19]: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] In [1]: sum([i*i for i in range(1,1001) if i%3 == 0 or i%5==0]) Out[1]: 156390386 Slide 14 ----------- *Some functional programming* * List comprehensions are python way to do functional programming constructs * [function(i) for i in iterable if condition] is filter(func2, map(func1, iter)) * Lets see how this list comprehension maps to functional concepts * Get the list of squares of even numbers --Hidden-- In [5]: filter(lambda x: x%2==0, map(lambda x: x ** 2, range(1, 11)))
  • 6. Out[5]: [4, 16, 36, 64, 100] In [6]: [el*el for el in range(1, 11) if el%2 ==0] Out[6]: [4, 16, 36, 64, 100] Slide 15 -------------- *File Handling* * Open a file with - open('location') or file('location') * or give a mode - open('location', 'rw') * iterate as for line in open_file.readlines(): print line#Or whatvere or string = open_file.read() --Hidden-- In [8]: open_file = open('/home/shabda/python_talk/11.txt') In [9]: for el in open_file.readlines(): ...: print el ...: break ...: ...: Project Gutenberg's Alice's Adventures in Wonderland, by Lewis Carroll Slide 16 -------------- *Some actual work* Find the most commonly used word in the Alice in wonderland text. --Hidden-- Give time here #!/usr/bin/env python from operator import itemgetter open_file = open('/home/shabda/python_talk/11.txt') text = open_file.read() words = text.split() word_count = {} for word in words: if word in word_count: word_count[word] += 1 else: word_count[word] = 1 sorted_list = sorted(word_count.items(), key=itemgetter(1), reverse=True) print sorted_list[0] Slide 17 ------------ * Problems *
  • 7. * Ok, now you suggets some problems and lets solve them together. Slide 18 ------------- * A tour of the standard library * * Batteries included * math * datetime * string * re * random * os * pickle * Do a dir and see for yourself. And a lot, lot more http://docs.python.org/library/ --hidden-- Spend time here In [14]: math.cos(math.pi) Out[14]: -1.0 In [9]: datetime.date.today() > datetime.date(2008, 9, 12) Out[9]: True In [18]: string.capitalize('python is a programming language.') Out[18]: 'Python is a programming language.' In [19]: import random In [20]: random.choice(['ubuntu', 'redhat', 'xandros']) Out[20]: 'xandros' In [21]: random.choice(['ubuntu', 'redhat', 'xandros']) Out[21]: 'ubuntu' Slide 19 ------------- * Back to slide 4 * * Dynamically but strongly typed. * Very object oriented - everything is an object. * But pragmatic - Objects aren't everthing. * Allows various paradigms of programming - OO, procedural, functional. * Shallow learning curve, but powerful powerful capabilities avaialble, when you need them. * import this --Hidden-- Explain. * Slide 20 * --------------- * Decorators *
  • 8. Syntacting sugar for foo_func =docorator_func(foo_func) --Hidden-- In [1]: def good_function(): ...: print 'I am a good function' ...: ...: In [2]: def decorator(orig_func): ...: def bad_func(): ...: print 'I am a bad function' ...: return bad_func ...: In [3]: good_function = decorator(good_function) In [4]: good_function() I am a bad function In [5]: @decorator ....: def good_function2(): ....: print 'I am a good function' ....: ....: In [6]: good_function2() I am a bad function #!/usr/bin/env python def is_val_positive_deco(orig_func): def temp_func(val): if val < 0: return 0 else: return orig_func(val) return temp_func @is_val_positive_deco def sqrt(val): import math return math.pow(val, (1.0/2)) print sqrt(-1) print sqrt(4) Slide 21 --------------- * Web development with Python * * Many useful frameworks * Django * GAE * Turbogears * We recommend Django - Most actively developed and largest community participation Slide 22
  • 9. ---------- *If we have time* * PIL - Image Manipulation * Mechanize - Browser automation * Beautiful Soup - Html extraction. Slide 23 ------------- * Resources * python.org diveintopython.org uswaretech.com/blog Slide 24 ---------- * Thank You. * You can give feedback, ask questions at shabda@uswaretech.com