Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 18 Online
OpenStudy (anonymous):

Assignment 3: IDLE stopped recognizing my functions. It worked for quite a while, now it is saying that they are undefined. Anyone have any ideas?

OpenStudy (anonymous):

BTW: The saved code is this (not sure if it will work yet since I cant execute it to test): from string import * def countSubStringMatchRecursive(string,key): if find(string,key) != -1: return 1 + countSubStringMatchRecursive(string[1:len(string)-1]) else: return 0 The error message I get in the shell is this: Traceback (most recent call last): File "<pyshell#15>", line 1, in <module> countSubStringMatchRecursive("abcd","d") NameError: name 'countSubStringMatchRecursive' is not defined I have saved the .py file I am working in. I am not sure why it would work sometimes and not others. Do I need to import the function into the shell somehow?

OpenStudy (anonymous):

in the function definition, you call countSubStringMatchRecursive with only 1 parameter, when it expects 2.

OpenStudy (anonymous):

It's missing the key.

OpenStudy (anonymous):

you are totally right about that; thanks for pointing it out. That doesn't seem to be the cause of my issue though. The shell is still only sporadically recognizing my functions. Do I need to put a separator other than a carraige return between two function defs in the same py file?

OpenStudy (anonymous):

No its even okay to have something like def printMyName(name): print "my name is", name def enterMyName(): name = raw_input("what is your name?") return name with no carriage return in between. in python indentation matters more.

OpenStudy (anonymous):

OK thats good to know, thanks. I think i figured my problem out. I think you have to execute your saved file after any restart of the shell for the functions to be recognized.

OpenStudy (anonymous):

Yes. It helps to keep the source file open if you frequently tinker with your code, and then simply 'start module' or something (I simply hit the f5 key) while the source code is opened to restart the shell and run your code.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!