On Fri, Nov 7, 2008 at 2:23 PM, RyanN <[EMAIL PROTECTED]> wrote:
>
> to do this I tried:
>
> def addCountry(self,country_name):
> # create an instance of country
> exec(country_name + "= country('" + country_name + "')")
> # Add this new instance of a country to a list
> exec("self.countries.append(" + country_name + ")")
>
Don't use exec. It's quite dangerous, and in your case is making
things much more complex than necessary. A much simpler way to do
what you want:
def addCountry(self,country_name):
self.countries.append(country(country_name))
There is no need to bind the result of "country(country_name)" to a name at all.
--
http://mail.python.org/mailman/listinfo/python-list