can anybody tell me why when I import the code from the module in Lecture 4 it tells me that 'findRoot' is not defined even though the code is not commented out? When I import 'lect4.py' the shell just moves to the next line without printing anything and if I write findRoot(x,y,z) for some numbers x,y,z it says that findRoot is not defined. No idea what's wrong...
Usually when I get that type of error, it's because I wrote findRoot instead of findroot.
try lect4.findRoot(x,y,z) when you import a module, its functions, methods, object are in its namespace so you have to specify the module that it is in. http://docs.python.org/tutorial/classes.html#a-word-about-names-and-objects http://docs.python.org/reference/simple_stmts.html#import
http://effbot.org/zone/import-confusion.htm http://docs.python.org/tutorial/modules.html#modules
Thank you bwCa. That makes all the difference. Any idea why he doesn't need to do that in the lecture example?
if you use from module import function/object - or from module import * you import those things directly into the importing modules namespace and you can call them like they are actually in the module you are editing - is that what he did in the lecture? http://docs.python.org/reference/simple_stmts.html#import i have read a lot saying that this is NOT the preferred method http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#importing
privyet, we do not have the book and the course hasn't started yet
@minimallinux this discussion group is for other ocw classes not just the edx class
Join our real-time social learning platform and learn together with your friends!