Rafał Kot
Rafał Kot

Reputation: 1084

python class in string

I have name of class in string like:

conf[0] = 'smtp_config'

and i want to run method like:

self.ui.smtp_config.setText("....")

How can i do this in python? :)

Upvotes: 2

Views: 163

Answers (2)

ChristopheD
ChristopheD

Reputation: 116307

func = getattr(self.ui, conf[0])
func.setText("....")

Upvotes: 2

Alexander Gessler
Alexander Gessler

Reputation: 46657

Try getattr(self.ui,conf[0]).setText(...)

Upvotes: 3

Related Questions