i'm a school teacher writing an addition app using Python. It was going ok but i didn't like the editor so i found a new one(NetBean6.5). i copied/pasted my code but the NBeans editor is looking for a "main" module... i've done a little c++ so i understand what it's looking for but i don't know where to put it or what it should look like. Below i the code i copied from the python.org editor.

can some one tell/show how/where to setup "main"?

for i in range(2):

addString = input('What addition table do you want to use ')
addTable = int(addString)
tryAgain ='Try again'
correct = 'CORRECT!'
import random
add1 = random.randrange(1,10,1)
print (addString +' + '+ str(add1)+ ' = ' )
stuAnswer= input()
stuInt= int(stuAnswer)
answer = (addTable+add1)

while answer !=stuInt:
print (tryAgain)
print(addString+' + '+str(add1)+' = ')
stuAnswer= input()
stuInt = int(stuAnswer)
answer = (addTable+add1)

print (correct)

print (str(stuAnswer))
print( addTable+add1)

9 Years
Discussion Span
Last Post by vegaseat

Please use code tags when posting code in this forum. If you don't, your code is excruciatingly hard to read and makes it less likely that forum members will answer your question.

To use code tags:
[code=python] # Put your code inside here


Now regarding the 'main' module: there is no set way to do this in Python, as the language doesn't require you to use any specific structure; however the most common way that you'll see a 'main' function being represented is this:

import os

def main():
    """ This is the main function """

if __name__ == '__main__':

This convention is used most commonly to avoid certain code from running when importing from this module. Now, with that being said I'm not so convinced that an editor would force you to use that style (or any style for that matter). I think that your problem might be something entirely different.

Could you copy-paste the exact error that you're getting? Also, the subject of the thread mentions jython... Are you using jython or python?


i will surely use tags next time.

thank you for your reply.. i didn't get an error. i got a dialog box asking me to select main module.

thank you again,


Actually Snee left this note somewhere:

I found a mildly more sensible solution to running simple Python files on NetBeans 6.5 -->

Create a new project, save it in a recognizable location and run it. Now you can create individual Python files and save them in the new project source subdirectory, for instance

After that the 'Run File' option is activated, run and enjoy!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.