[Tutor] A puzzle for you

2006-10-13 Thread John Fouhy
>From the python_dev LiveJournal community --- Predict the outcome of the following code: ## from random import * seed() [choice(dict((x+1,0) for x in range(1000))) for x in range(693)][0] ## -- John. ___ Tutor maillist - Tutor@python.org http://mai

Re: [Tutor] tkinter tutorials

2006-10-13 Thread Dick Moores
At 05:45 PM 10/12/2006, Danny Yoo wrote: >John Grayson's "Python and Tkinter Programming" is an excellent book on >learning the Tkinter toolkit: > > http://www.manning.com/grayson/ Danny, "Python and Tkinter Programming" is still in its first edition, which came out in 2000. Python has chang

Re: [Tutor] Zipfile and File manipulation questions.

2006-10-13 Thread Danny Yoo
> Is there a way to say : > for filename in zfile.namelist() contains '.txt, .exe': Hi Chris, Yes. It sounds like you want to filter zfile.namelist() and restrict the entries to those with particular extensions. Try a "list comprehension" to filter for those interesting filenames: for fil

[Tutor] Zipfile and File manipulation questions.

2006-10-13 Thread Chris Hengge
First question..This is the code that I have:for filename in zfile.namelist():    outfile = open(filename, 'w')    outfile.write(zfile.read(filename))    outfile.close()Is there a way to say : for filename in zfile.namelist() contains '.txt, .exe':    outfile = open(filename, 'w')  

Re: [Tutor] How to write strings with new line character in a file OOPS CORRECTION

2006-10-13 Thread Bob Gailer
Bob Gailer wrote: > Asrarahmed Kadri wrote: > >> Here is the complete code: >> fd is the file handle. >> >> import sys >> >> def check_dup(fd1): >> print fd1 >> fd1.seek(0,0) >> done = 0 >> list1 = [] >> while not done: >> x = fd1.readline() >> if x == "":

Re: [Tutor] How to write strings with new line character in a file

2006-10-13 Thread Bob Gailer
Asrarahmed Kadri wrote: > Here is the complete code: > fd is the file handle. > > import sys > > def check_dup(fd1): > print fd1 > fd1.seek(0,0) > done = 0 > list1 = [] > while not done: > x = fd1.readline() > if x == "": > done = 1 > else:

Re: [Tutor] executing with double click on linux

2006-10-13 Thread johnf
On Friday 13 October 2006 12:33, Alfonso wrote: Could be wrong but can't you use file associations? I do on my SUSE system. John ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] executing with double click on linux

2006-10-13 Thread Alfonso
Jonathon Sisson escribió: > Alfonso wrote: > >> Sorry for the too obvious question. I'm new to python and have no idea >> how can I make execute a compiled .pyc with a double click in linux, >> with gnome. Trying to double click in a .py gives allways the question >> wether I want to execute

Re: [Tutor] Code for checking whether an input string is a palindrome or not.

2006-10-13 Thread Danny Yoo
>> Yes, you are right; the code isnt working for 'abcdba'; >> So what should I do to rectify it. > > Try walking through the code by hand so you understand why it is > failing. Then maybe you can figure out how to fix it. It's important to > learn to find and fix errors yourself. Hi Asrar, On

Re: [Tutor] How to write strings with new line character in a file

2006-10-13 Thread Danny Yoo
> fname = raw_input("Enter the file name to write data to:\t") > > fd = open(fname,'a+') > print fd > done = 0 Ok, good, that helps a lot: that's exactly what we need to diagnose the problem. There appears to be something funky that happens with append-plus mode. This problem has come up befor

Re: [Tutor] Code for checking whether an input string is a palindrome or not.

2006-10-13 Thread Kent Johnson
Asrarahmed Kadri wrote: > Yes, you are right; the code isnt working for 'abcdba'; > So what should I do to rectify it. Try walking through the code by hand so you understand why it is failing. Then maybe you can figure out how to fix it. It's important to learn to find and fix errors yourself.

Re: [Tutor] Tutor Digest, Vol 32, Issue 51

2006-10-13 Thread Danny Yoo
>> What makes you think so? >> >> >>> s = 'l' >> >>> s += '\n' >> >>> s >> 'l\n' >> >>> >> >> Seems to work '\n' is just a character like any other. > > The issue was to have a newline or return character after every string, > Here it is just iterpreted as \n alphabet., but not as a return

Re: [Tutor] Tutor Digest, Vol 32, Issue 51

2006-10-13 Thread Meher Kolli
On 10/13/06, [EMAIL PROTECTED] <[EMAIL PROTECTED] > wrote:Send Tutor mailing list submissions to tutor@python.orgTo subscribe or unsubscribe via the World Wide Web, visithttp://mail.python.org/mailman/listinfo/tutoror, via email, send a message with subject or body 'help' to    

Re: [Tutor] Code for checking whether an input string is a palindrome or not.

2006-10-13 Thread Kent Johnson
Asrarahmed Kadri wrote: > > Hi, > > Here is a code that reports whether the string is a palindrome or not. I > have posted it to help people new to programming ( i am also a newbie) > to understand the logic and comment on it. > > Share and expand your knowledge as well as understanding... >

Re: [Tutor] Code for checking whether an input string is a palindrome or not.

2006-10-13 Thread Simon Brunning
def pal(spam): return spam == spam[::-1] ;-) -- Cheers, Simon B [EMAIL PROTECTED] http://www.brunningonline.net/simon/blog/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Code for checking whether an input string is a palindromeor not.

2006-10-13 Thread Alan Gauld
"Asrarahmed Kadri" <[EMAIL PROTECTED]> wrote in message > Here is a code that reports whether the string is a palindrome or > not. I'd suggest a simpler approach is to use the string/list methods in Python: string1 = list(raw_input("enter a string\n")) #using a list is easier string2 = string

[Tutor] Code for checking whether an input string is a palindrome or not.

2006-10-13 Thread Asrarahmed Kadri
Hi,   Here is a code that reports whether the string is a palindrome or not. I have posted it to help people new to programming ( i am also a newbie) to understand the logic and comment on it.   Share and expand your knowledge as well as understanding...   Happy scripting   Regards, Asrar   Cod

Re: [Tutor] How to write string in a file, each one on new line???

2006-10-13 Thread Kent Johnson
Asrarahmed Kadri wrote: > Folks, > > I dont like to swamp your mailboxes with my trivial questions. We don't mind trivial questions, this is a list for beginners. But there is no need to swamp our mailboxes by asking the same question more than once, and if you include complete code and compl

Re: [Tutor] How to write strings with new line character in a file

2006-10-13 Thread Kent Johnson
Asrarahmed Kadri wrote: > Here is the complete code: > fd is the file handle. > > import sys > > def check_dup(fd1): > print fd1 > fd1.seek(0,0) > done = 0 > list1 = [] > while not done: > x = fd1.readline() > if x == "": > done = 1 > else

[Tutor] How to write string in a file, each one on new line???

2006-10-13 Thread Asrarahmed Kadri
Folks,   I dont like to swamp your mailboxes with my trivial questions. But please tell me why this isnt working??   str = str + '\n' fd.write(str)   # fd is teh file handle   the traceback is as under:   Traceback (most recent call last):  File "scrap.py", line 39, in ?    fd.write(str + '\n')IOE

Re: [Tutor] How to write strings with new line character in a file

2006-10-13 Thread Asrarahmed Kadri
Here is the complete code: fd is the file handle.  import sys  def check_dup(fd1):    print fd1    fd1.seek(0,0)    done = 0    list1 = []    while not done:    x = fd1.readline()    if x == "":    done = 1    else:     list1.append(x)    return list1     fname = raw_in

Re: [Tutor] Tutor Digest, Vol 32, Issue 49

2006-10-13 Thread Alan Gauld
"Meher Kolli" <[EMAIL PROTECTED]> wrote in message > You can't add \n to a string ..up have use something like this > > if str == 'q': > done = 1 > fd.close() > else: > fd.write("%s \n" %(str)) What makes you think so? >>> s = 'l' >>> s += '\n' >>> s 'l\n' >>> Seem

Re: [Tutor] Tutor Digest, Vol 32, Issue 49

2006-10-13 Thread Meher Kolli
Message: 8Date: Fri, 13 Oct 2006 02:03:49 +0100From: "Asrarahmed Kadri" < [EMAIL PROTECTED]>Subject: [Tutor] How to write strings with new line character in afileTo: pythontutor Message-ID:<[EMAIL PROTECTED]>Content-Type: text/plain; charset="iso-8859-1" Folks,I a

Re: [Tutor] Trying to understand sys.getrefcount()

2006-10-13 Thread Alan Gauld
> class junk(object): > ... pass > ... sys.getrefcount(junk) > 5 > I understand why j1 is 1 higher than I expect, based on the docs, > but why > does getrefcount(junk) return 5 before any instances of class junk > are made? Because Python s holding 4 references to the class object inte