I’m new on Python. I’m testing this code on Python 2.7 but gives me an error.
import statsout
def output(data, format="text"):
output_function = getattr(statsout, "output_%s" % format, statsout.output_text)
return output_function(data)
Error:
Traceback (most recent call last):
File "C:\Documents and Settings\anlopes\workspace\test\src\test.py", line 1, in <module>
import statsout
ImportError: No module named statsout
Can someone give me a clue on what is wrong?
Best Regards,
Your example is from Dive Into Python, and
statsoutis an imaginary module used as an example. To quote from http://diveintopython.net/power_of_introspection/getattr.html :“For example, let’s imagine” being the key words there 🙂 Actually, reading it again I can quite see that that paragraph is easy to misparse…