python 3 - instantiating class from user input
Brad Bailey
computer_brad at yahoo.com
Thu Apr 7 00:04:44 EDT 2011
I dont understand why this is such a big deal. Nor do i understand why google can't find a reasonable answer. If one can't figure out from the title what I'm trying to do, then a look at code should firmly plant the intent. The general idea of the code is, in my opinion, very basic.
I notice, that when you are coding a class instance, it's in the format of:
newInstance = someClass()
OK, so we are calling someClass as if it's a function. Is there a way to do something to the effect of:
someClass(newInstance)
I've seen all kinds of hacks and workarounds that seem 10 times more complicated that this ought to be.
class inventoryItem:
itsDecrtiption = None
itsVendor = None
itsCost = None
itsMarkup = None
itsQuantity = None
newItem = input('enter the new item to add to inventory')
findItem = input('enter the item number to find')
def addItem(newItem):
pass
def lookupItem(findItem):
if findItem:
doSomething()
else:
complain()
addItem(findItem)
More information about the Python-list
mailing list