Python Tutorial ( PDFDrive )
Python Database Access ...................................................... 338 What is MySQLdb? ................................................................................ 339 How do I install the MySQLdb? .............................................................. 339 Database Connection: ............................................................................ 339 EXAMPLE: ........................................................................................... 340 Creating Database Table: ...................................................................... 340 EXAMPLE: ............................................................................................. 340 INSERT Operation: ................................................................................ 341 TUTORIALS POINT Simply Easy Learning EXAMPLE: ........................................................................................... 341 EXAMPLE: ........................................................................................... 342 READ Operation: ................................................................................... 342 EXAMPLE: ........................................................................................... 342 Update Operation: .................................................................................. 343 EXAMPLE: ............................................................................................. 343 DELETE Operation: ............................................................................... 344 EXAMPLE: ........................................................................................... 344 Performing Transactions: ....................................................................... 344 EXAMPLE: ............................................................................................. 344 COMMIT Operation: ............................................................................... 345 ROLLBACK Operation: .......................................................................... 345 Disconnecting Database: ....................................................................... 345 Handling Errors: ..................................................................................... 345 Python Networking ................................................................ 347 What are Sockets? ................................................................................. 347 The socket Module: ................................................................................ 348 Server Socket Methods: ......................................................................... 348 Client Socket Methods: .......................................................................... 348 General Socket Methods: ....................................................................... 348 A Simple Server: .................................................................................... 348 A Simple Client: ...................................................................................... 349 Python Internet modules ........................................................................ 349 Further Readings: .................................................................................. 350 Python Sending Email ........................................................... 351 Example: ................................................................................................ 351 Sending an HTML e-mail using Python: ................................................. 352 EXAMPLE: ........................................................................................... 352 Sending Attachments as an e-mail: ....................................................... 353 EXAMPLE: ............................................................................................. 353 Python Multithreading ............................................................ 355
Starting a New Thread: .......................................................................... 355 EXAMPLE: ............................................................................................. 355 The Threading Module: .......................................................................... 356 Creating Thread using Threading Module: ............................................. 356 EXAMPLE: ........................................................................................... 357 Synchronizing Threads: ......................................................................... 358 EXAMPLE: ........................................................................................... 358 Multithreaded Priority Queue: ................................................................ 359 EXAMPLE: ........................................................................................... 359 Python XML Processing ........................................................ 361 XML Parser Architectures and APIs: ...................................................... 361 Parsing XML with SAX APIs: ................................................................. 362 The make_parser Method: ..................................................................... 362 The parse Method: ................................................................................. 363 The parseString Method: ........................................................................ 363 EXAMPLE: ........................................................................................... 363 Parsing XML with DOM APIs: ................................................................ 365 Python GUI Programming ..................................................... 367 Tkinter Programming .............................................................................. 367 Example: ................................................................................................ 367 Tkinter Widgets ...................................................................................... 368 Methods: ................................................................................................ 370 Example: ................................................................................................ 370 Example: ................................................................................................ 372 Methods: ................................................................................................ 375 Example: ................................................................................................ 375 Syntax: ................................................................................................... 376 Parameters: ............................................................................................ 376 Methods: ................................................................................................ 377 Example: ................................................................................................ 377 Syntax: ................................................................................................... 378 Parameters: ............................................................................................ 378 Example: ................................................................................................ 379 Syntax: ................................................................................................... 379 Parameters: ............................................................................................ 379 Example: ................................................................................................ 380 Syntax: ................................................................................................... 381 Parameters: ............................................................................................ 381 Methods: ................................................................................................ 382 TUTORIALS POINT Simply Easy Learning
- Page 1 and 2: Python Tutorial
- Page 3 and 4: ABOUT THE TUTORIALPython TutorialPy
- Page 5 and 6: Example: ..........................
- Page 7 and 8: Return Value ......................
- Page 9 and 10: Description .......................
- Page 11 and 12: Syntax ............................
- Page 13 and 14: Example ...........................
- Page 15 and 16: Parameters ........................
- Page 17 and 18: Return Value ......................
- Page 19 and 20: Parameters ........................
- Page 21 and 22: Parameters ........................
- Page 23 and 24: Locating Modules: .................
- Page 25 and 26: Parameters ........................
- Page 27 and 28: Description .......................
- Page 29 and 30: Return Value ......................
- Page 31 and 32: Example ...........................
- Page 33 and 34: Parameters ........................
- Page 35: Regular-expression Modifiers - Opti
- Page 39 and 40: Example: ..........................
- Page 41 and 42: CHAPTER1Python OverviewPython is a
- Page 43 and 44: CHAPTER2Python EnvironmentBefore we
- Page 45 and 46: • To use this installer python-XY
- Page 47 and 48: -c cmd run Python script sent in as
- Page 49 and 50: This will produce the following res
- Page 51 and 52: file_name = raw_input("Enter filena
- Page 53 and 54: $ python -husage: python [option] .
- Page 55 and 56: print 'Input file is "', inputfilep
- Page 57 and 58: Here, an integer object is created
- Page 59 and 60: Python Lists: Lists are the most v
- Page 61 and 62: FunctionDescriptionint(x [,base])Co
- Page 63 and 64: CHAPTER5Python Basic OperatorsWhat
- Page 65 and 66: Line 4 - Value of c is 2Line 5 - Va
- Page 67 and 68: Line 5 - a is greater than bLine 6
- Page 69 and 70: | Binary OR Operator copies a bit i
- Page 71 and 72: else:print "Line 3 - a and b are tr
- Page 73 and 74: if ( id(a) == id(b) ):print "Line 2
- Page 75 and 76: When you execute the above program,
- Page 77 and 78: if statementsif...else statementsne
- Page 79 and 80: Example: #!/usr/bin/pythonvar1 = 10
- Page 81 and 82: else:print "Could not find true exp
- Page 83 and 84: Loop Typewhile loopfor loopDescript
- Page 85 and 86: num = raw_input("Enter a number :")
Starting a New Thread: .......................................................................... 355
EXAMPLE: ............................................................................................. 355
The Threading Module: .......................................................................... 356
Creating Thread using Threading Module: ............................................. 356
EXAMPLE: ........................................................................................... 357
Synchronizing Threads: ......................................................................... 358
EXAMPLE: ........................................................................................... 358
Multithreaded Priority Queue: ................................................................ 359
EXAMPLE: ........................................................................................... 359
Python XML Processing ........................................................ 361
XML Parser Architectures and APIs: ...................................................... 361
Parsing XML with SAX APIs: ................................................................. 362
The make_parser Method: ..................................................................... 362
The parse Method: ................................................................................. 363
The parseString Method: ........................................................................ 363
EXAMPLE: ........................................................................................... 363
Parsing XML with DOM APIs: ................................................................ 365
Python GUI Programming ..................................................... 367
Tkinter Programming .............................................................................. 367
Example: ................................................................................................ 367
Tkinter Widgets ...................................................................................... 368
Methods: ................................................................................................ 370
Example: ................................................................................................ 370
Example: ................................................................................................ 372
Methods: ................................................................................................ 375
Example: ................................................................................................ 375
Syntax: ................................................................................................... 376
Parameters: ............................................................................................ 376
Methods: ................................................................................................ 377
Example: ................................................................................................ 377
Syntax: ................................................................................................... 378
Parameters: ............................................................................................ 378
Example: ................................................................................................ 379
Syntax: ................................................................................................... 379
Parameters: ............................................................................................ 379
Example: ................................................................................................ 380
Syntax: ................................................................................................... 381
Parameters: ............................................................................................ 381
Methods: ................................................................................................ 382
TUTORIALS POINT
Simply Easy Learning