[Tutor] Tutor Digest, Vol 61, Issue 32

WM. wferguson1 at socal.rr.com
Mon Mar 9 23:39:10 CET 2009


tutor-request at python.org wrote:
> Send Tutor mailing list submissions to
> 	tutor at python.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> 	tutor-request at python.org
> 
> You can reach the person managing the list at
> 	tutor-owner at python.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> 
> 
> Today's Topics:
> 
>    1. Re: probelm pyhton shell doesnt open help please (Martin Walsh)
>    2. Re: while loop problem (Lie Ryan)
>    3. problem with an anagram program (jessica cruz)
>    4. Re: UNSUBSCRIPTABLE? (Alan Gauld)
>    5. Re: problem with an anagram program (Andre Engels)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Sun, 08 Mar 2009 23:18:10 -0500
> From: Martin Walsh <mwalsh at mwalsh.org>
> Subject: Re: [Tutor] probelm pyhton shell doesnt open help please
> To: tutor at python.org
> Message-ID: <49B49882.2070901 at mwalsh.org>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> mustafa akkoc wrote:
>> it gives this message socket error 
>>
> <image text>
> IDLE's subprocess didn't make a connection. Either IDLE can't start a
> subprocess or personal firewall software is blocking the connection.
> </image text>
> 
> IIRC, this was once a known issue with IDLE when combined with the
> windows firewall service, or when running multiple instances of IDLE
> (perhaps inadvertently). But, I'm having difficulty tracking down the
> pertinent bug report(s) -- maybe these have been fixed? or I'm just
> tired, probably the latter.
> 
> A couple of suggestions from memory ...
> 1. Check the process/task list for errant pythonw.exe processes, and end
> them.
> 2. Launch IDLE with the -n flag from a terminal (command prompt).
> 3. Report back to the list with your results, and include the python and
> windows version info if you continue to have trouble.
> 
> HTH,
> Marty
> 
> PS. Keep in mind, some of us won't see images you post to the list so
> you should generally include a text version of error messages whenever
> possible. Or at least, note when you've included an image so that those
> with sufficient interest can make the extra effort to view it, if
> necessary.
> 
> 
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Mon, 09 Mar 2009 16:51:28 +1100
> From: Lie Ryan <lie.1296 at gmail.com>
> Subject: Re: [Tutor] while loop problem
> To: tutor at python.org
> Message-ID: <gp2ap6$j95$1 at ger.gmane.org>
> Content-Type: text/plain; charset=UTF-8; format=flowed
> 
> mustafa akkoc wrote:
>> hello i have syntax problem in this program 
>>
> <snip>
> 
> After correcting the indentations, and putting a missing parentheses in 
> line 24 (the last line), I don't see any Syntax Error.
> 
> #!/usr/bin/python
> # Filename: while.py
> number = 23
> running = True
> 
> while running :
>      guess= int(input('Enter an integer : '))  # it give a syntax error 
> this line can you me ?
> 
>      if guess == number:
>          print('Congratulations, you guessed it.')
>          running = False # this causes the while loop to stop
> 
>      elif guess < number:
>          print('No, it is a little higher than that.')
> 
>      else:
>          print('No, it is a little lower than that.')
> 
> else:
>      print('The while loop is over.')
> 
>      # Do anything else you want to do here
> print('Done')  # you missed a paren, probably CopyPasteError
> 
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Mon, 9 Mar 2009 01:28:38 -0700 (PDT)
> From: jessica cruz <jessica06cruz at yahoo.com>
> Subject: [Tutor] problem with an anagram program
> To: Tutor at python.org
> Message-ID: <823438.88941.qm at web43139.mail.sp1.yahoo.com>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> I just started learning python an I'm currently working on this program. The purpose of this program is to read a string of letters from user input and print out all the words which are anagrams of the input string. This is what I have and when I try to run the program it says that there is an error "invalid syntax" but I can't figure out where. 
> 
> 
> 
> 
> #this reads all of the words in the file into a list
> infile = open('/afs/cats/courses/cmps012a-cm/pa1/wordList.txt')
> wdcount = int(infile.readline()) #first item is count of all the words
> word_list = infile.readlines()
> wordList = []
> 
> # code that will be compared will be a histogram type code with frequency
> # characters
> def code(w):
> ??? hist = []
> ??? chars = list(w) 
> ??? chars.sort() 
> ??? for letter in chars: 
> ??????? if not letter in hist:? # when the letter is not already in hist, 
> ??????????? hist.extend([letter, str(w.count(letter))])? # its added to hist along with its freq.
> ??????? else: 
> ??????????? continue
> ??? coding = "".join(hist) # then they are joined as one string
> ??? return coding
> 
> 
> 
> 
> # new list is made with words in word_list followed by its code
> for word in? word_list:
> ??? wordList.append(word) 
> ??? wordList.append(code(word[:(len(word)-2)])) 
> 
> 
> while True:
> ??? word1 = raw_input('Enter word:') 
> ??? word = word1.lower() 
> ??? sig = code(word) 
> ??? i = 1 
> ??? if sig in wordList: 
> ??????? print "Anagrams:"
> ??????? while i <= len(wordList):? # when the sig of the inputed word is in the word list, 
> ??????????? if sig == wordList[i]
> ??????????? print wordList[i-1]? # the corresponding words are printed
> ??????????? i += 2 # then adds two because codes are every other entry
> ??? else:
> ??????? print "No anagrams"
> ??? choice = raw_input("Continue? (yes/no)")
> ??? if choice == 'y' or choice == 'yes':
> ??????? continue
> ??? else:
> ??????? break
> ??????????? 
> ??????? 
> ??????? 
> ??? 
> ??????? 
> ??? 
> 
> 
> 
> ????????????? 
> ??? 
> ??? 
> ??? 
> 
> 
> 
> 
> 
>       
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/tutor/attachments/20090309/54781b33/attachment-0001.htm>
> 
> ------------------------------
> 
> Message: 4
> Date: Mon, 9 Mar 2009 08:39:44 -0000
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] UNSUBSCRIPTABLE?
> To: tutor at python.org
> Message-ID: <gp2kkl$9p0$1 at ger.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> 	reply-type=response
> 
> "WM." <wferguson1 at socal.rr.com> wrote
> 
>> Well, Mr. Wilkins takes the biscuit. He found where I did not enter 
>> a pair of parens.()
> 
> But do you understand *why* you got the error and what it was telling 
> you?
> Pyton's error message told you exactly what you had done wrong
> although you may not have quite understood it. But do you now see
> what the error message was telling you when it said:
> 
> ------------------
>    File "C:\Python26\TicTacToeD.py", line 150, in main
>      DisplayBoard(board)
>    File "C:\Python26\TicTacToeD.py", line 68, in DisplayBoard
>      print "\n\t", board[1], "|", board[2], "|", board[3]
> TypeError: 'function' object is unsubscriptable
> ------------------
> 
> Can you understand it clearly enough that when a similar error
> comes up in future you will know what to look for and where?
> 
No, Mr. G., I cannot.
My approach has been to key in most of Dawson's programs, to get 
accustomed to the jargon and to get used to some keys that I didn't know 
were on the keyboard.  My long term memory seems to be pretty shot and 
the stuff is not soaking in. I have found your tutorial, and some others 
in the Python B/G file of interest, but not retainable. Two O'Reilly 
books are worthless to me. Dawson's book is very clear; being half way 
through it, I should know a great deal more than I do.  Oh, well, one 
should not bring a cap-pistol to a knife fight, nor a leaky brain to an 
academic task.


More information about the Tutor mailing list