当前位置: 首页>>代码示例>>Python>>正文


Python Person.Person类代码示例

本文整理汇总了Python中Person.Person的典型用法代码示例。如果您正苦于以下问题:Python Person类的具体用法?Python Person怎么用?Python Person使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Person类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: inheritance_two

def inheritance_two():
    car = {}

    driver = Passenger()
    driver.setName('Bob')
    driver.setAge(30)
    driver.setSeatPosition(0)
    driver.setIsDriver(True)

    passenger = Passenger()
    passenger.setName('Jim')
    passenger.setAge(40)
    passenger.setSeatPosition(1)

    person = Person()
    person.setName('Jack')
    person.setAge(25)

    car['driver'] = driver
    car['passenger'] = passenger
    car['otherpassenger'] = person

    for key in car:
        occupant = car[key]
        try:
            print('Occupant ' + occupant.getName() + (', driving' if occupant.getIsDriver() else ', passenger' ) )
        except AttributeError as ae:
            if isinstance(occupant, Human):
                print('Occupant ' + occupant.getName() )
            else:
                print( 'Error : ' + ae.message)
开发者ID:rikkouri,项目名称:project-a,代码行数:31,代码来源:Inheritance.py

示例2: Scene

class Scene(object):
    
    def __init__(self):
        self.person = Person()

    def enter(self):
        print "This scene is not yet configured. Subclass it amd implement enter()."
        exit(1)
        
    def get_action(self):
        action = raw_input("> ")
        if (action == "exit"):
            exit(0)
            self.get_action()
        elif (action == "read map" and self.person.has_item("map")):
            print " _~_     ___ "
            print "|_L_|---|_r_|"
            print " ___     _|_ "
            print "|_S_|---|_r_|"
            print "         _|_ "
            print "        |_x_|"
            return self.get_action()
        elif (action == "read paper" and self.person.has_item("paper")):
            print "*******"
            print "Hurry to the passage, the machines have"
            print "found us! If you encounter one then use the"
            print "trap we put in place by shouting the password" 
            print "*******" 
            return self.get_action()
        elif (action == "inventory"):
            print self.person.items
            return self.get_action()
        else:
            return action
开发者ID:chazp,项目名称:Scurminator,代码行数:34,代码来源:game.py

示例3: get_data

def get_data():
    url = next_urls.pop().replace('\n', '')
    if url in seen_urls:
        return
    print(url)
    person = Person(url, session)
    try:
        person.get_all_info()
    except:
        print('Get user data error!')
        return
    print(person.id, person.name, person.url, person.gender, person.location, person.business,
          person.employment, person.position, person.education, person.education_extra,
          person.description, person.hash_id,
          person.follower_num, person.followee_num, person.asks, person.answers, person.posts,
          person.collections, person.logs, person.agrees, person.thanks)

    data = (person.id, person.name, person.url, person.gender, person.location, person.business,
            person.employment, person.position, person.education, person.education_extra,
            person.description, person.hash_id,
            person.follower_num, person.followee_num, person.asks, person.answers, person.posts,
            person.collections, person.logs, person.agrees, person.thanks)
    try:
        db.insert_data(data)
    except pymysql.err.DataError as E:
        print(E)
        return
    next_urls.update(person.follow())
    seen_urls.add(url)
    print(len(next_urls))
    # 爬取一百人之后更新一次next_urls.txt文件,实时保存进度
    if len(next_urls) % 100 == 0:
        save_next_urls()
    save_seen_urls(url)
开发者ID:Vaayne,项目名称:zhihu-people,代码行数:34,代码来源:test.py

示例4: get_people

def get_people(path):
    import logging
    logging.basicConfig(filename='log.log', level=logging.DEBUG,
                        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    people = []

    with codecs.open(path, "r", "iso-8859-1") as f:
        assert isinstance(path, str)
        ind = path.rindex(sep)
        fi = path[ind:]
        year = re.search("[0-9]{4}", fi).group()
        year = int(year)
        d = {}
        first = True
        for line in f:
            fields = line.split("|")
            if first:
                for i in range(len(fields)):
                    field = fields[i]
                    d[i] = field.replace("\r\n", "")
                first = False
            else:
                p = Person(year)
                for i in range(len(fields)):
                    field = fields[i]
                    try:
                        r = d[i]
                        method = switcher.get(r, None)
                        if method is not None:
                            method(p, field)
                    except KeyError:
                        print(fields)
                        p.valid = False
                people.append(p)
    return people
开发者ID:zlepper,项目名称:sccPython,代码行数:35,代码来源:csv.py

示例5: end_choice

 def end_choice(self):
     John = Person('John','22','male','China','None','None','Basketball')
     #选择1的数量大于2,则和好,否则再也不见
     if gl.END1 > gl.END2:
         John.talk('好,我们重新开始!')
     if gl.END1 < gl.END2:
         John.talk('我们已经回不到过去了!再也不见!')
开发者ID:lizhanguo,项目名称:python_S09,代码行数:7,代码来源:Choice.py

示例6: _merge

	def _merge(pcMerge, pcMaster, pcSlave):
		Log.trace(__class__, "_merge() called")
		# add headerNames in pcNew
		for kMaster in pcMaster.getHeaderNames():
			pcMerge.addHeader(kMaster)
		# Merge attributes of pcMaster to pcNew
		for pMaster in pcMaster.getPersons():
			pMerge = Merge.getPerson(pcMerge, pMaster)
			if(pMerge == None):
				pMerge = Person()
				pcMerge.addPerson(pMerge)
			pSlave = Merge.getPerson(pcSlave, pMaster)
			if(pSlave == None):
				# do copy of pMaster
				pSlave = Person()
			for kMaster in pcMaster.getHeaderNames():
				aMaster = pMaster.getAttribute(kMaster)
				aSlave = pSlave.getAttribute(kMaster)
				aMerge = Person.ATTR_NOT_AVAILABLE
				# Attribute is empty
				if((aMaster != "" or aMaster != Person.ATTR_NOT_AVAILABLE) and (aSlave == "" or aSlave == Person.ATTR_NOT_AVAILABLE)):
					aMerge = aMaster
				elif((aSlave != "" or aSlave != Person.ATTR_NOT_AVAILABLE) and (aMaster == "" or aMaster == Person.ATTR_NOT_AVAILABLE)):
					aMerge = aSlave
				# Attributes are not empty
				elif(aMaster == aSlave):
					aMerge = aMaster
				else:
					Log.warn(__class__, "merge conflict:\nMaster=" + aMaster + "\n Slave=" + aSlave)
				pMerge.setAttribute(kMaster, aMerge)
		Log.trace(__class__, "_merge() finished")
开发者ID:cpieloth,项目名称:AdressbookConverter,代码行数:31,代码来源:Merge.py

示例7: read

	def read(fName):
		Log.trace(__class__, "read()")
		pCollection = PersonCollection()
		try:
			file = open(fName, 'r')
			isHeader = True
			#SEP = ',*'
			SEP = "[\,,\s]*"
			EMB = "\""
			regEx = re.compile(EMB + '([^' + EMB + ']*)' + EMB + SEP)
			for line in file:
				i = 0
				person = Person()
				for col in regEx.findall(line):
					if(isHeader):
						pCollection.addHeader(col)
						#self._headerNames.append(col)
					else:
						person.setAttribute(pCollection.getHeaderNames()[i], col)
						i += 1 
				if(isHeader):
					isHeader = False
				else:
					pCollection.addPerson(person)
					
			file.close()
			return pCollection
		except IOError:
			Log.error(__class__, "IOError with file > " + fName)
			return None
开发者ID:cpieloth,项目名称:AdressbookConverter,代码行数:30,代码来源:InOut.py

示例8: __init__

	def __init__(self, studentID, name = "Student X", gender = "m", leavingCertificate = 700):
		self.studentID = studentID
		Person.__init__(self, name, gender)
		self.modules = []
		self.moduleEnrollments = {}
		self.semester = 1
		self.leavingCertificate = leavingCertificate #TODO: check Irish system
		self.faculty = ""
开发者ID:bazilinskyy,项目名称:agent-based-uni,代码行数:8,代码来源:Student.py

示例9: main

def main():
    collection_old = 'activities'
    collection_new = 'activity'

    address_old = '192.168.37.128'
    port_old = 27017

    address_new = '192.168.6.254'
    port_new = 37017

    Person.convert_person(address_old, port_old, address_new, port_new)

    print("OK")
开发者ID:hezhensong,项目名称:MongoConvertor,代码行数:13,代码来源:main1.py

示例10: doMapping

	def doMapping(self, pcSrc):
		pcDest = PersonCollection()
		# add headerNames to destination personCollection
		for kDest in self._mapping.values():
			pcDest.addHeader(kDest)
		# add srcPersons to destPersons with new headerNames
		for pSrc in pcSrc.getPersons():
			pDest = Person()
			for kSrc, kDest in self._mapping.items():
				attr = pSrc.getAttribute(kSrc)
				if((attr == Person.ATTR_NOT_AVAILABLE  or attr == "") and self._defaultValues[kDest] != ""):
					attr = self._defaultValues[kDest]
				pDest.setAttribute(kDest, attr)
			pcDest.addPerson(pDest)
		return pcDest
开发者ID:cpieloth,项目名称:AdressbookConverter,代码行数:15,代码来源:Mapping.py

示例11: getMatches

    def getMatches(self):
        matchesURL = "https://api.gotinder.com/updates"
        result = self.session.post(matchesURL, headers=self.headers, proxies=None)
        result = result.json()
        matches = result["matches"]
        people = []
        for match in matches:
            if "person" in match:
                person = Person(match["person"])
                personInformationURL = "https://api.gotinder.com/user/" + person.personID
                personResult = self.session.get(personInformationURL, headers=self.headers, proxies=None).json()

                personResult = personResult["results"]
                person = Person(personResult)
                people.append(person)
                print(person.name + "\t" + person.getSchools())
开发者ID:dsouzarc,项目名称:tinderNNBot,代码行数:16,代码来源:Tinder.py

示例12: __init__

	def __init__(self):
		Person.__init__(self, '', '', '')
		BaseWidget.__init__(self,'Person window')
		self.parent = None

		#Definition of the forms fields
		self._firstnameField 	= ControlText('First name')
		self._middlenameField  	= ControlText('Middle name')
		self._lastnameField  	= ControlText('Lastname name')
		self._fullnameField  	= ControlText('Full name')
		self._buttonField  		= ControlButton('Press this button')

		#Define the button action
		self._buttonField.value = self.buttonAction

		self._formset = ['_firstnameField', '_middlenameField', '_lastnameField', 
			'_fullnameField', 
			(' ','_buttonField', ' '), ' ']
开发者ID:AlfiyaZi,项目名称:pyforms,代码行数:18,代码来源:PersonWindow.py

示例13: test_file_input

 def test_file_input(self):
     self.myModel = Model()
     self.myModel.data_handler.read_in("TestData.csv")
     self.expected = Person('D003', 'M', 12, 312, 'Normal', 123)
     self.assertEquals(self.myModel.data_handler.get_data()[0].get_id(), self.expected.get_id())
     self.assertEquals(self.myModel.data_handler.get_data()[0].get_weight(), self.expected.get_weight())
     self.assertEquals(self.myModel.data_handler.get_data()[0].get_age(), self.expected.get_age())
     self.assertEquals(self.myModel.data_handler.get_data()[0].get_sales(), self.expected.get_sales())
     self.assertEquals(self.myModel.data_handler.get_data()[0].get_income(), self.expected.get_income())
开发者ID:ZachChristensen,项目名称:PR301InterpreterPattern,代码行数:9,代码来源:UnitTests.py

示例14: begin

 def begin(self):
     John = Person('John',22,'M','China','None','None','Basketball')
     Liz = Person('Liz',22,'F','China','None','None','Dance')
     print '''
     ======故事开始======
     '''
     Liz.talk('亲爱的!我考上了北京城市学院了')
     s.wait(2)
     John.talk('我没考上。。。不过我决定打工赚钱供你上大学!')
     s.wait(2)
     Liz.talk('你对我真好,我太爱你了!')
开发者ID:lizhanguo,项目名称:python_S09,代码行数:11,代码来源:Story.py

示例15: modifier

def modifier(filename):
    """Modifies a file CSV. Adds a new column in the data structure"""
    try:
        assert os.path.exists(filename)
    except:
        raise ValueError('file "'+str(filename)+'" does not exist!')
    try:
        persons = {}
        csv_file = open(filename, 'rU')
        csv_reader = csv.DictReader(csv_file, delimiter=',')
        for line in csv_reader:
            person_id = int(line['id'])
            surname = line['surname']
            name = line['name']
            birth_date = line['birthdate']
            nickname = line['nickname']
            person = Person(surname, name, birth_date, nickname)
            persons[person_id] = person
        csv_file.close()

        csv_file = open(filename, 'w')
        fieldnames = ['id',
                      'surname',
                      'name',
                      'fullname',
                      'birthdate',
                      'nickname',
                      'age']
        csv_writer = csv.writer(csv_file, delimiter=',', lineterminator='\n')
        csv_writer.writerow(fieldnames)
        for person_id in persons.keys():
            person = persons[person_id]
            record = [person_id,
                      person.surname,
                      person.first_name,
                      person.get_fullname(),
                      person.birth_date,
                      person.nickname,
                      person.get_age()]
            csv_writer.writerow(record)
    finally:
        csv_file.close()
开发者ID:alexeymishkin,项目名称:homeworks,代码行数:42,代码来源:hw6_solution1.py


注:本文中的Person.Person类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。