1 / 28

Lecture # 27 Python I

Lecture # 27 Python I. Python. “ Interpretive ” language (vs. compiled) So is HTML, JavaScript. Python supports file I/O. JavaScript doesn ’ t Python is a serious web programming language used by Google, ILM, etc. Jython. Jython is a “ dialect ” of Python Python is implemented in C

Download Presentation

Lecture # 27 Python I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture # 27 Python I

  2. Python • “Interpretive” language (vs. compiled) So is HTML, JavaScript. • Python supports file I/O. JavaScript doesn’t • Python is a seriousweb programming language used by Google, ILM, etc.

  3. Jython • Jython is a “dialect” of Python • Python is implemented in C Jython is implemented in Java • We use JES JES = Jython Environment for Students

  4. Downloading Jython • http://code.google.com/p/mediacomp-jes/ • http://code.google.com/p/mediacomp-jes/downloads/list

  5. Using Jython • Select JES from “Programs” • Click on the black part of the UI after the command prompt >>>

  6. Jython DEMO • print 5 + 9 • print “Hello” • x = 5 + 9 • print x • message = “Hello There” • print message

  7. Jython DEMO • print 5 + 9 • print “Hello” • x = 5 + 9 • print x • message = “Hello There” • print message • Note: Python is case sensitive. “Print” and “Message” won’t work.

  8. Jython DEMO Pictures • pickAFile()

  9. Jython DEMO Pictures • pickAFile() • print pickAFile()

  10. Jython DEMO Pictures • pickAFile() • print pickAFile() • file = pickAFile()

  11. Jython DEMO Pictures • pickAFile() • print pickAFile() • file = pickAFile() • print file

  12. Jython DEMO Pictures • pickAFile() • print pickAFile() • file = pickAFile() • print file • pict=makePicture(file) # interpret as picture

  13. Jython DEMO Pictures • pickAFile() • print pickAFile() • file = pickAFile() • print file • pict=makePicture(file) # interpret as picture • show(pict) # display as picture

  14. How could we do this all at once?

  15. How could we do this all at once? show(makePicture(pickAFile()))

  16. How could we do this all at once? show(makePicture(pickAFile())) Now lets save it as a Python Program: displayPict.py

  17. How could we do this all at once? show(makePicture(pickAFile())) Now lets save it as a Python Program: displayPict.py And run it: open it and load it

  18. How could we do this all at once? show(makePicture(pickAFile())) Now lets save it as a Python Program: displayPict.py And run it: open it and load it King of the “1-liners”

  19. Jython DEMO Sound • file = pickAFile() • print file • sound=makeSound(file) # interpret as sound • play(sound) # lets listen to it All together: play(makeSound(pickAFile())) • Save as a Python program and run it

  20. Jython Functions def myFunction(): colon

  21. Jython Functions def myFunction(): colon parentheses

  22. Jython Functions def myFunction(): colon parentheses function name

  23. Jython Functions def myFunction(): colon parentheses function name “def” instead of “function()”

  24. Jython Functions def myFunction(): colon parentheses function name “def” instead of “function()” The function must be called somewhere

  25. Jython Functions def myFunction(): block of commands

  26. Jython Functions def myFunction(): block of commands Note indentation!

  27. Jython Functions: Indentation • Indentation is critical in Python • Indentation associates these commands with this function • Indentation separates commands from other functions

  28. Jython Function: Example defpickAndShow(): file = pickAFile() myPict = makePicture(file) show(myPict) pickAndShow() # somewhere we have to call the function

More Related