Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Python basics modules classes Python Basics named after Monty Python interpreted dynamically typed object-oriented indentation based.

Similar presentations


Presentation on theme: "Introduction to Python basics modules classes Python Basics named after Monty Python interpreted dynamically typed object-oriented indentation based."— Presentation transcript:

1

2

3 Introduction to Python basics modules classes

4 Python Basics named after Monty Python interpreted dynamically typed object-oriented indentation based statement grouping (!)‏

5 def fib(n): # write Fibonacci series up to n """Print a Fibonacci series up to n.""" a, b = 0, 1 while b < n: print b, a, b = b, a+b

6 Python Modules a file containing class and function definitions and executable statements modules can be executed directly modules can be imported into other modules

7 import BaseHTTPServer class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):... def test(HandlerClass = SimpleHTTPRequestHandler, ServerClass = BaseHTTPServer.HTTPServer): BaseHTTPServer.test(HandlerClass, ServerClass)‏ if __name__ == '__main__': test()‏ SimpleHTTPServer.py

8 Executing Modules Directly e.g. H:\> python SimpleHTTPServer.py class and function definitions are entered into the ' __main__ ' symbol table executable statements are executed

9 Importing Modules e.g. import SimpleHTTPServer a new symbol table is created with the name of the module class and function definitions are entered into the newly created symbol table executable statements are executed only if this is the first time the module has been imported

10 Accessing Imported Symbols imported functions and classes are accessed by prefixing the function or class name with the name of the module e.g. import SimpleHTTPServer... SimpleHTTPServer.test

11 Python Classes all members (data and methods) are public all methods are virtual the first (explicit) argument of a method is the object itself; this argument is implied when the method is called special object initialization goes in the ' __init__ ' method classes are first class data types

12 import SocketServer class HTTPServer(SocketServer.TCPServer): def server_bind(self): """Override server_bind to store the server name.""" SocketServer.TCPServer.server_bind(self)‏ host, port = self.socket.getsockname()‏ self.server_name = socket.getfqdn(host)‏ self.server_port = port BaseHTTPServer.py

13 import socket class BaseServer:... class TCPServer(BaseServer): def __init__(self, server_address, RequestHandlerClass): """Constructor. May be extended, do not override.""" BaseServer.__init__(self, server_address, RequestHandlerClass)‏ self.socket = socket.socket(self.address_family, self.socket_type)‏ self.server_bind()‏ self.server_activate()‏ SocketServer.py

14 XHTML reformulation of HTML in XML XML (eXtensible Markup Language)‏  adds structure and meaning to content  hierarchy delineated by tags

15 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Foo foo


Download ppt "Introduction to Python basics modules classes Python Basics named after Monty Python interpreted dynamically typed object-oriented indentation based."

Similar presentations


Ads by Google