View Single Post
Old Jun 15th, 2007, 8:59 AM   #4
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 641
Rep Power: 4 Jessehk is on a distinguished road
Something like this maybe?

class Person(object):
	def __init__(self, name, age):
		self.name = name
		self.age = age

def main():
	p = Person("Joe Smith", 38)
	attr = raw_input("Enter an attribute of a person: ")
	print "The person's %s is  %s." % (attr, getattr(p, attr))
	
if __name__ == "__main__":
	main()


EDIT: Ah, I think I misunderstood your question.
Too print the contents of a variable in a string, just use the "%s" specifier and follow it with an argument.

For example:
name = "Joe"
print "Hello, %s!" % name
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote