[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

NameError: name 'main' is not defined

Jolly

12/19/2007 3:39:00 AM

hey guys,

When i try to run my code I get an error. NameError name 'main is not
defined'

[code]
if __name__ == "__main__":
main()

filename = "addbook.dat"

def main():
theMenu = '''
1) Add Entry
2) Remove Entry
3) Find Entry
4) Quit and Save
'''
theBook = {}
readBook(theBook)
choice = getChoice(theMenu)
while choice != 4:
if choice == 1:
addEntry(book)
elif choice == 2:
removeEntry(book)
elif choice == 3:
findEntry(book)
else:
print "Invalid choice, try again."
choice = getChoice(theMenu)
saveBook(theBook)


def readbook(book):
import os
if os.path.exists(filename):
store = open(filename,'r')
for line in store:
name = line.rstrip()
entry = store.net().rstrip
book[name] = entry
store.close()

def saveBook(book):
store = open(filename,'w')
for name,entry in book.items():
store.write(name + '\n')
store.write(entry + '\n')
store.close()

def getChoice(menu):
print menu
choice = int( raw_input("Select a choice(1-4): ") )
return choice

def addEntry(book):
name=raw_input("Enter a name: ")
entry = raw_input("Enter a street, town and phone number: ")
book[name] = entry

def removeEntry(book):
name=raw_input("Enter a name: ")
del(book[name])

def findEntry(book):
name = raw_input("Enter a name: ")
if name in book:
print name, book[name]
else: print "Sorry, no entry for: ",name


[/code]
11 Answers

Robert Kern

12/19/2007 4:11:00 AM

0

jolly wrote:
> hey guys,
>
> When i try to run my code I get an error. NameError name 'main is not
> defined'
>
> [code]
> if __name__ == "__main__":
> main()

Put this at the end of the file. Currently, it is getting executed before the
code that defines main().

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Jolly

12/19/2007 5:35:00 AM

0

thanks....

BobbyM

9/3/2013 6:20:00 AM

0

On 9/3/2013 2:33 PM, Jordy Chase wrote:
>
> Well, I beg to differ with you... It was one of the best TV offerings
> of the 80's, Imo... superb acting, well written plotlines, characters
> who were complex and flawed and 3 dimensional, and very *real*.... It
> was much better than the average, run of the mill mediocre tv show,
> Imo...

My, at the time, 11 year old daughter enjoyed it.


JD Chase

3/1/2014 4:48:00 AM

0


Still deciding...

The Bloomfield Bloviator

3/1/2014 6:08:00 AM

0

On Tuesday, September 3, 2013 1:33:49 AM UTC-4, Jordy Chase wrote:

> Well, I beg to differ with you... It was one of the best TV offerings of the 80's, Imo... superb acting, well written plotlines, characters who were complex and flawed and 3 dimensional, and very *real*.... It was much better than the average, run of the mill mediocre tv show, Imo...

Why are we not surprised that you watched a show that was on opposite Monday Night Football?

JD Chase

3/1/2014 6:20:00 AM

0


Labels, stereotypes, gender roles... what good are they? we all have masculine and feminine elements in us, Imo... some may be more masculine or more feminine, but so what? The point is to be a unique individual and ignore gender roles, as much as possible...

The Bloomfield Bloviator

3/1/2014 6:59:00 AM

0

On Saturday, March 1, 2014 1:19:35 AM UTC-5, JD Chase wrote:

> The point is to be a unique individual and ignore gender roles, as much as possible...

So we should intentionally go out of our way to ignore gender roles as much as possible?

I don't think that's how most of us want to live.

Would you have us do away with separate sports teams for females and make it so a girl can only play on the basketball team if she's good enough to play against the boys? I mean, having a separate sports team for the girls is saying that since they're not good enough to play on the boys teams, we need to let them play their inferior brand of the game anyway, because they are of a different gender.

There are a lot of differences between the genders. They even have found now that the recommended dosages of most drugs should be different for women than for men, and not just based on their body masses.

Gender roles developed for a reason, much to do with genetic predisposition..

The Impressions have a song on their "This Is My Country" album called "They Don't Know," that contains the lyrics "Every brother is a leader, every sister is a breeder."

I don't think Curtis Mayfield would have been for ignoring gender roles.

M. Rick

3/1/2014 12:23:00 PM

0

> Gender roles developed for a reason, much to do with genetic predisposition.

Were you genetically predisposed to be a toll collector on the NJ Turnpike?

Gotta pay the toll
If you wanna be a troll
And you know you don't pass E-Z

JD Chase

3/1/2014 1:31:00 PM

0


We don't have to *completly* ignore gender roles, but we can not be rigid about them either... like most things, identity is loose and fluid and on a continuum...

Will Dockery

3/1/2014 8:12:00 PM

0


"The Bloomfield Bloviator" <savoybg@verizon.net> wrote:
>
> Why are we not surprised that you watched a show

And why are we not surpriswed that you spend your days and nights with your
nose buried in the Glass Teat?

"Sometimes I wanna do like Elvis did and shhot the damned thing out." -Bob
Dylan, "Talking TV Blues"