Skip to main content

Thread: Python3.0 help


i've been reading byte of python (the python3.0 version) , examples in them myself. haven't had trouble until , wondering if me. typed out in book , tried execute , got error.

traceback (most recent call last):
file "objvar.py", line 42, in <module>
droid1 = robot('r2-d2')
file "objvar.py", line 14, in __init__
print('initializing {0}'.format(self.name))
attributeerror: 'str' object has no attribute 'format'
exception exceptions.attributeerror: "'str' object has no attribute 'format'" in <bound method robot.__del__ of <__main__.robot instance @ 0xb7dd2c0c>> ignored

copied , pasted example code book , got same results.


here's code typed out
code:
#!/usr/bin/python3.0  # filename : objvar.py    class robot:      '''represents robot name'''            # class variable, counting number of robots.      population = 0            def __init__(self, name):          '''initializes data.'''                    self.name = name          print('initializing {0}'.format(self.name))                  # when person created, robot          # adds population          robot.population += 1                def __del__(self):          '''i dying'''          print('{0} being destroyed'.format(self.name))                    robot.population -= 1                    if robot.population == 0:              print('{0} last one.'.format(self.name))          else:              print('there still {0:d} robots working'.format(robot.population))                    def sayhi(self):          '''greeting robot'''                    print('greetings, masters call me {0}.'.format(self.name))                def howmany():          '''prints current population'''                    print('we have {0:d} robots.'.format(robot.population))            howmany = staticmethod(howmany)        droid1 = robot('r2-d2')  droid1.sayhi()  robot.howmany()    droid2 = robot('c-3po')  droid2.sayhi()  robot.howmany    print('\nrobots can work here.\n')  print('robots have finished work. let\' destroy them.')    del droid1  del droid2    robot.howmany()
also, have other python tutorials at?

code:
-----@-------:~/desktop$ python3 objvar.py  initializing r2-d2 greetings, masters call me r2-d2. have 1 robots. initializing c-3po greetings, masters call me c-3po.  robots can work here.  robots have finished work. let' destroy them. r2-d2 being destroyed there still 1 robots working c-3po being destroyed c-3po last one. have 0 robots.
no problems here.


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Python3.0 help


Ubuntu

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums