Python Presentation

download Python Presentation

If you can't read please download the document

Transcript of Python Presentation

  • 1. Cosa dicono... "Python stata una parte importante in Google sin dall'inizio, e rimane tale mentre il sistema cresce e si evolve. Oggi dozzine di ingegneri di Google usano Python, e stiamo cercando sempre pi gente brava in questo linguaggio." dice Peter Norvig, direttore della qualit di ricerca presso Google, Inc.

2. Variabili Le variabili non hanno tipi, n si dichiarano. Appaiono quando le assegni, spariscono quando non le usi pi x,y,z = 1,2,3 first, second = second, first a = b = 123 3. Controlli di flusso if x < 5 or (x > 10 and x < 20): print "Il valore OK." for i in [1,2,3,4,5]: print "Iterazione numero", i 4. Liste Le liste sono delle strutture dati molto utili name = ["Cleese", "John"] print name[1], name[0] # Stampa "John Cleese" 5. Dizionari person = { 'first name': "Robin", 'last name': "Hood", 'occupation': "Scoundrel" } print person[first name] print person[last name] 6. Funzioni def square(x): return x*x print square(2) # Stampa 4 queeble = square print queeble(2) # Stampa 4 7. Oggetti class Person: def __init__(self, name): self.name = name me = Person(Nome) print me.name # Stampa Nome 8. Main.py #!/usr/bin/env python if __name__ == "__main__": print hello world $ python Main.py hello world $ chmod u+x Main.py $ ./Main.py hello world 9. Demo 10. Dicono di wxPtyhon... "Why the hell hasn't wxPython become the standard GUI for Python yet?" -- Eric S. Raymond wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard Python GUI toolkit is that Tkinter was there first. -- Guido van Rossum 11. What is wxPtyhon? wxPython un cross-platform GUI toolkit permette di creare facilmente interfacce grafiche implementato come modulo di Python wrappa wxWidgets cross platform libreria GUI 12. What is wxPtyhon? wxPython un GUI toolkit cross-platform basato sulla libreriawxWidgets Dove possibile usa elementi grafici nativi per rispettare il Look and Feel nativo Maturo wxWidgets 1992 wxPython 1996 13. What is wxPtyhon? 14. What is wxPtyhon? wxPython plain-text posso usare vim, emacs, nano IDE? Boa Constructor, WingIDE, SPE, SCiTE 15. wxPython GUI Le GUI composta da una collezione di widgets Alcuni widget sono finestre di alto livello gestite dal sistema altri sono widget contenuti da altri widget La GUI wx comeun albero di componenti grafici Prima di visualizzare una finesrta occorre: creare lalbero dei componenti associare degli eventi ad un oggetto particolare 16. wxPython GUI Le applicazioni GUI applications sonoevent driven Lapplicazione aspetta che accada qualcosa come pressione di un tasto, movimento del mouse, ecc. Quando accade un evento linformazione viene raccolta ed inviata ad un handler Gli eventi sono gestiti in modo asincrono 17. wxPython GUI Alcuni eventi sono il risultato di un azione umana: left-click su un pulsante selezione di un elemento di menu drag di un elemento da un pannel ad un altro. . . Altri eventi sono generati dal sistema timer countdown expires una parte nascosta della GUI viene mostrata . . . 18. wxPython GUI 19. wxPython GUI Hello world! import wx class App(wx.App): def OnInit(self): frame = wx.Frame(parent=None, title="Hello World!") frame.Show() return True app = App() app.MainLoop() 20. Demo 21. wxPython GUI Real world! 22. wxPython GUI Real world! 23. wxPython GUI Real world! 24. wxPython GUI Real world! 25. wxPython GUI Real world! 26. Riferimenti http://wxPython.org http://wiki.wxPython.org http://wxWidgets.org wxPython in Action