Account 37 88 33 29 96 in Microsoft Office Development qr codes in Microsoft Office Account 37 88 33 29 96

Account 37 88 33 29 96 using microsoft office toinclude denso qr bar code for web,windows application Microsoft Office Official Website Last Name Barker Smith Dunn Brown Stone First Name Doug Dave Stacey Nancy Sam Balance 0.00 258.54 314.

QR Code 2d barcode for None 33 -24.54 34.98.

When a user selects opti on 2, the program calls function updateRecord (lines 57 80) to update an account. First, the function determines whether the record that the user specifies exists, because the function can update only existing records. If the record exists, it is read into variable tempRecord.

Lines 69 70 convert the string representation of the account balance to a floating-point value before manipulating its numerical value. Before updating a record in the shelve file, the program must delete the existing record for the specified account; keyword del (line 75) deletes the current record. Line 76 updates the record by assigning the new record values to the corresponding account number (record key).

The program then outputs the updated values. The following is a typical output for this option:. Page 483 Friday, December 14, 2001 2:06 PM 14 . File Processing and Serialization Enter account to update (1 - 100): 37 37 Barker Doug Enter charge (+) or payment (-): +87.99 37 Barker Doug 87.99 Portability Tip 14.1 Not all Python platforms Quick Response Code for None require the value of a record to be deleted from a shelve file before updating that record. However, using del to delete a record value before updating it, ensures that the update occurs properly across Python platforms..

Option 3 calls function newRecord to enable a user to add a new account. This function adds an account in the same manner as that of the program of Fig. 14.

9. If the user enters an account number for an existing account, newRecord displays a message that the account exists and the program allows the user to select the next operation to perform. A typical output for option 3 is as follows:.

Enter new account number (1 - 100): 22 Enter lastname, firstname, balance Johnston Sarah 247.45 Option 4 calls function deleteRecord to remove a record that is no longer needed. The program prompts the user to enter an account number. If the account number exists, the program uses keyword del to delete that record from the shelve file, then displays a message to inform the user that the record has been deleted.

However, if the account number does not exist, the program displays an error message. A typical output for option 4 is as follows:. Enter account to delete (1 - 100): 29 Account # 29 deleted. Option 5 terminates the program. The main portion of the program (lines 127 146) creates a list of functions that correspond to the user-menu options (line 127). The program then opens the shelve file for the bank accounts and gets the user s menu choice.

Line 144 calls a function that corresponds with a user option. Recall that parentheses (()) are Python operators. When used in conjunction with the function name (e.

g., textFile), the operator calls the function and passes any indicated arguments. Variable options holds a list of function names, so a statement such as.

options[ 0 ]( creditFile ). invokes function textFil e (the first function in the list) and passes creditFile as an argument. Statements like this avoid the need for long if/else statements that determine the user menu option and call the appropriate function.. Page 484 Friday, December 14, 2001 2:06 PM File Processing and Serialization 14 . 14.12 Object Serialization Serialization, or pickli qr codes for None ng, converts complex object types, such as user-defined classes, to sets of bytes for storage or for transmission over a network. Pickling also is referred to as flattening or marshalling. Python provides both modules pickle and cPickle to perform pickling.

In this text we use cPickle, a module written in C, instead of the Python module pickle. We choose to use cPickle, because modules written in compiled languages, such as C, execute faster than do interpreted languages such as Python. Figure 14.

12 demonstrates pickling and storing a list in a file. Performance Tip 14.2.

Module cPickle executes more efficiently than does module pickle, because cPickle is implemented in C and compiled into native machine language on each platform.. 1 2 3 4 5 6 7 8 9 10 11 Microsoft Office QRCode 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29. # Fig. 14.12: fig14_12.

p y # Opening and writing pickled object to file. import sys, cPickle # open file try: file = open( "users.dat", "w" ) # open file in write mode except IOError, message: # file open failed print >> sys.

stderr, "File could not be opened:", message sys.exit( 1 ) print "Enter the user name, name and date of birth." print "Enter end-of-file to end input.

" inputList = [] while 1: try: accountLine = raw_input( " " ) # get user entry except EOFError: break # user-entered EOF else: inputList.append( accountLine.split() ) # append entry cPickle.

dump( inputList, file ) file.close() # write pickled object to file. Enter the user name, nam QR-Code for None e and date of birth. Enter end-of-file to end input. mike Michael 4/3/60 joe Joseph 12/5/71 amy Amelia 7/10/80 jan Janice 8/18/74 ^Z Fig.

14.12 Pickled object written to a file..

Copyright © . All rights reserved.