object oriented python 3 input error -
i'm working python 3.4 on debian 8.5 linux. i'm working "learn python 3 hard way" , i'm working section running test (via nosetests). have code (which include in full) , it's giving me error on statement should valid, i'm assuming it's not liking how i've set statement up. it's on "class prompt" section:
class prompt(object): prompt = input("> ")
the idea code prompt 1 time and: call later on easier coding, nose keeps responding :
typeerror: bad argument type built-in operation
i'll include full error test well.
i'm looking see if in fact, i'm calling prompt incorrectly , if so, i'd appreciate nudge in right direction, not full solution ( learn better way :) ) thanks!
====== begin engine.py ==============
# babylon 5 scorched earth # more advanced example of proof-of-concept worked on # few weeks ago. # time engine 1 file, rooms can # self contained , need include 1 file # have 1 room, room change # depending on race choose! in game # there total of 5 rooms: # earther - earth on surface # drakh - earth, underground! # marsie - mars, inside mars dome # minbari - minbar # centari - centari prime, in front of emperor's palace # stats part of model, are: # cha - charisma - how charming , persuasive # con - constitution - how damage can take # dex - how fast you, how minble finges # int - how smart # str - how strong # tech - not random - earthers start 5, else starts 10 # teep - 1 in 100 chance teep, cannot chosen!! # wis - how savy you, or how wise schemes # prompt defined in engine too, , called # throught game # first imports sys import exit # we'll call first room random import randint # randomizing stats # define names object, define invalid names class name(object): def name(self): invalid.name=("delenn", "kosh", "morden", "sheridan", "sinclair", "ivanova" "g'kar") # define races - have know races we're working # define valid races - other races excluded class race(object): def race(self): valid.race = ("centari", "drakh", "earther", "marsie", "minbari") # define stats - again tech , teep not random # tech 5 earthers , 10 else # teep random roll 1 100 , cannot elected # races valid teeps class stats(object): def stats(self): stats = [ " cha: " " con: " " dex: " " int: " " str: " " tech: " " teep: " " wis : " ] def cha(self): print(stats.cha.self[randint(0 - 20)]) def con(self): print(stats.con.self[randint(0 - 20)]) def dex(self): print(stats.dex.self[randint(0 - 20)]) def int(self): print(stats.int.self[randint(0 - 20)]) def str(self): print(stats.str.self[randint(0 - 20)]) def teep(self): print(stats.teep.self[randint(0 - 100)]) def wis(self): print(stats.wis.self[randint(0 - 20)]) def tech(self): if race(self)== "earther": print(stats.tech.self("5")) else: print(stats.tech.self("10")) # setting prompt class prompt(object): prompt = input("> ") # set room - generic code # tells program room # code generic, we're defining # word "room" , once engine we'll # telling room class room(object): def enter(self): print("there's no room here @ moment.") print("create room , show ") print("other ! ") exit(1) # if there no other rooms present # here's engine, tell # room exactly. basically, we're going tell go # current room , code move next room ! class engine(object): def __init__(self, room_map): self.room_map = room_map def play(self): # needs defined we'll use start current_room = self.room_map.opening_room() # program last_room = self.room_map.next_room('finished') while current_room !=last_room: next_room_name = current_room.enter() currrent_room = self.room.map.next_room(next_room_map) # print out thue room current_room.enter() # there no death coded in here. # next we'll try coding map class in here , see # engine can self-contained class map(object): # here's every room mapped out rooms = { # here th rooms officially named ' atr' : atr(), # first room @ rim ' centari_prime' : centariprime(), # centari ' earth_under' : earthunderground(), # drakh ' earth' : earth(), # earthers ' marsdome' : marsdome(), # marsies ' minbar ' : minbar(), # minbari ' finished' : finished(), # last room! } # defining map def __init__(self, start_map): self.start_room = start_rooms def next_room(self, room_name): val = map.room.get(room_name) return val def opening_room(self): return self.next_ room(self.start_room) # defining starting room a_room = rooms('atr') a_game = engine(a_room) a_game = play()
===== begin error log ========
====================================================================== error: failure: typeerror (bad argument type built-in operation) ---------------------------------------------------------------------- traceback (most recent call last): file "/usr/local/lib/python3.4/dist-packages/nose/failure.py", line 39, in runtest raise self.exc_val.with_traceback(self.tb) file "/usr/local/lib/python3.4/dist-packages/nose/loader.py", line 418, in loadtestsfromname addr.filename, addr.module) file "/usr/local/lib/python3.4/dist-packages/nose/importer.py", line 47, in importfrompath return self.importfromdir(dir_path, fqname) file "/usr/local/lib/python3.4/dist-packages/nose/importer.py", line 94, in importfromdir mod = load_module(part_fqname, fh, filename, desc) file "/usr/lib/python3.4/imp.py", line 235, in load_module return load_source(name, filename, file) file "/usr/lib/python3.4/imp.py", line 171, in load_source module = methods.load() file "<frozen importlib._bootstrap>", line 1220, in load file "<frozen importlib._bootstrap>", line 1200, in _load_unlocked file "<frozen importlib._bootstrap>", line 1129, in _exec file "<frozen importlib._bootstrap>", line 1471, in exec_module file "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed file "/home/phoenix/python3/b5_scorched/projects/skeleton/tests/engine_test.py", line 5, in <module> b5_scorched.engine import * # import classes file "/home/phoenix/python3/b5_scorched/projects/skeleton/b5_scorched/engine.py", line 88, in <module> class prompt(object): file "/home/phoenix/python3/b5_scorched/projects/skeleton/b5_scorched/engine.py", line 89, in prompt prompt = input("> ") typeerror: bad argument type built-in operation ---------------------------------------------------------------------- ran 1 test in 0.006s failed (errors=1)
thank again !
i can't reproduce error messages here's see:
this definition strange:
class prompt(object): prompt = input("> ")
when file run or imported, prompts input that's thrown away. since don't invoke feature, it's hard know how meant used. here's guess @ implementation:
class prompt(): @staticmethod def input(): return input("> ")
usage
>>> x = prompt.input() > goat >>> x 'goat' >>>
beyond that, there other problems program: function has unreachable code:
def opening_room(self): return self.next_ room(self.start_room)
anything after return
never executed. there's no import or code in file define atr()
is. additionally, there seem indentation issues (e.g. none of class map()
methods indented) , static/class methods defined instance methods.
you might want test smaller chucks of code build larger ones.
Comments
Post a Comment