1 , generating test data
Import faker f = faker.Faker (locale = ' zh-CN ' ) # China Data Print (f.credit_card_number ()) # credit card number Print (f.email ()) # E-mail Print (f.phone_number ()) # phone number Print (f.ssn ()) # identification number Print (f.user_name ()) # random user name
2 , getattr () function
getattr () function returns the value of an object attribute.
getattr syntax:
getattr(object, name[, default])
ps: default can specify the default value, returns to the default value when the object attribute does not exist
class Stu: DEF eat (Self): Print ( ' eat !!!!!! ' ) nn = Stu () Result = getattr (nn, ' eat ' ) # objects to eat nn properties Result () # attribute method plus () can perform Print (Result) # <Method Stu.eat of bound <__ main __. Stu AT 0x01E6C030 >> Object # according to the second L = [l, 2,3 ] APD = getattr (L, ' the append ' ) # Get the append attribute list l Print ( ' APD ', APD) # APD <Built-in of the append Method AT 0x01E68738 Object List> APD ( ' Nana ' ) # corresponds l.append ( 'Nana') Print (L) # [. 1, 2,. 3, 'Nana'] Print (the hasattr (L, ' the append ' )) # determines that there are no objects to this method, returns True