Re: [Tutor] A recursion question

2011-11-18 Thread Kĩnũthia Mũchane
On 11/19/2011 06:03 AM, Asokan Pichai wrote: Another way to do that is to avoid any intermediate variables altogether That may be easier to understand YMMV def counter(mylist, val): if len(mylist == 0): return 0 if mylist[0] == val: return 1 + counter(mylist[1:]

Re: [Tutor] FW: urgent help!! THANKS EVERYONE!

2011-11-18 Thread Steven D'Aprano
Wayne Werner wrote: The chances of hitting the maximum recursion depth is pretty slim, unless your user manages to type in a wrong number about 1000 times ;) I've had to provide desktop support to people who have done that. Only-slightly-exaggerating-ly 'yrs, -- Steven ___

Re: [Tutor] A recursion question

2011-11-18 Thread Asokan Pichai
Another way to do that is to avoid any intermediate variables altogether That may be easier to understand YMMV def counter(mylist, val): if len(mylist == 0): return 0 if mylist[0] == val: return 1 + counter(mylist[1:], val) else: return counter(myl

Re: [Tutor] python telnet

2011-11-18 Thread Rayon
Thank you I think I understand now, thank you very much. -Original Message- From: tutor-bounces+evosweet=hotmail@python.org [mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of Steven D'Aprano Sent: 17 November 2011 19:52 To: tutor@python.org Subject: Re: [Tutor] python

Re: [Tutor] python telnet

2011-11-18 Thread Rayon
I installed the telnet client but still the same error. Traceback (most recent call last): File "C:\Users\Rayon\Documents\projects1\super_hia\main.py", line 6, in child = winspawn('telnet 192.168.0.55:210') File "C:\Python26\lib\site-packages\winpexpect-1.5-py2.6.egg\winpexpect.py", line

Re: [Tutor] urgent help!!!!!!!!!!!

2011-11-18 Thread Emile van Sebille
On 11/17/2011 3:26 PM ADRIAN KELLY said... i know i'm stupid but i have tried everything to get one line of text working, i have written out pseudo and read every website. now i am getting this error Traceback (most recent call last): File "F:\VTOS ATHLONE\PYTHON_VTOS\foreign exc

Re: [Tutor] Shorten Code.

2011-11-18 Thread Alexander Etter
On Nov 18, 2011, at 13:15, ALAN GAULD wrote: > > > > for var in [value,value_1]: > > >var = "green" > > > > Um, that won't work. You typed that example too quickly. > > Oops! Yes. You'd need to enumerate and access the variables > via an index. yuk. Don't do it folks! :-) > > Excuse: It w

Re: [Tutor] binary file query

2011-11-18 Thread Prasad, Ramit
>No *need* but, often convenient, regardless of whether the data was >written by a C struct or not.(*) It is a way to interpret binary data in >terms of fundamental data types such as ints, floats, strings etc. >Trying to convert raw bytes representing floats into a floating point >number witho

Re: [Tutor] A recursion question

2011-11-18 Thread Kĩnũthia Mũchane
On 11/18/2011 06:04 PM, Dave Angel wrote: On 11/18/2011 08:16 AM, Kĩnũthia Mũchane wrote: Well, it doesn't count the number of occurrences correctly if the list is empty. It should get zero, and it gets -1. But for any non-empty list, nothing ever looks at the -1 value, so it doesn't matte

Re: [Tutor] In a pickle over pickles….Python 3

2011-11-18 Thread Jerry Hill
On Fri, Nov 18, 2011 at 11:12 AM, Joe Batt wrote: > > pickledfile=open('///Users/joebatt/Desktop/python/pickledpuzzle5.txt','w') > pickle.dump(filecontents,pickledfile) > pickledfile.close() > > A pickle is a binary object, so you'll need to open your picklefile in binary mode: pickledfi

Re: [Tutor] Shorten Code.

2011-11-18 Thread ALAN GAULD
> > for var in [value,value_1]: > >var = "green" > > Um, that won't work. You typed that example too quickly. Oops! Yes. You'd need to enumerate and access the variables via an index. yuk. Don't do it folks! :-) Excuse: It was early morning and I hadn't had any coffee... Alan G.

Re: [Tutor] Encoding

2011-11-18 Thread Prasad, Ramit
On 11/17/2011 8:45 PM, Nidian Job-Smith wrote: Hi all, In my programme I am encoding what the user has in-putted.  What the user inputs will in a string, which might a mixture of letters and numbers. However I only want the letters to be encoded. 

Re: [Tutor] Saving read-only or encoded text files?

2011-11-18 Thread Wayne Werner
On Fri, Nov 18, 2011 at 11:17 AM, Max gmail wrote: > Thank you. This will work perfectly. > > On Nov 18, 2011, at 11:58 AM, Prasad, Ramit wrote: > > > > > Any file will eventually be able to be reverse engineered, but it > matters how much effort you care to obfuscate it. The way you can do it

Re: [Tutor] In a pickle over pickles….Python 3

2011-11-18 Thread Dave Angel
On 11/18/2011 11:12 AM, Joe Batt wrote: Hi All,Sorry to trouble you all again with more nooby problems! Only been programming a week so still all a haze especially since self taught….. I am opening a url and saving it to a file on my computer, then I am trying to pickle it. I have written the u

Re: [Tutor] Saving read-only or encoded text files?

2011-11-18 Thread Max gmail
Thank you. This will work perfectly. On Nov 18, 2011, at 11:58 AM, Prasad, Ramit wrote: > Hi. I've been using a lot of text files recently, and I'm starting to worry > about a user hacking some element by editing the text files. I know that I > can pickle my data instead, creating less easil

Re: [Tutor] Saving read-only or encoded text files?

2011-11-18 Thread Prasad, Ramit
Hi.  I've been using a lot of text files recently, and I'm starting to worry about a user hacking some element by editing the text files.  I know that I can pickle my data instead, creating less easily editable (try saying that five times fast) .dat files, but I'd rather store individual variabl

[Tutor] Saving read-only or encoded text files?

2011-11-18 Thread Max S.
Hi. I've been using a lot of text files recently, and I'm starting to worry about a user hacking some element by editing the text files. I know that I can pickle my data instead, creating less easily editable (try saying that five times fast) .dat files, but I'd rather store individual variables

[Tutor] In a pickle over pickles….Python 3

2011-11-18 Thread Joe Batt
Hi All,Sorry to trouble you all again with more nooby problems! Only been programming a week so still all a haze especially since self taught….. I am opening a url and saving it to a file on my computer, then I am trying to pickle it. I have written the url file to a file on my computer then ope

Re: [Tutor] FW: urgent help!! THANKS EVERYONE!

2011-11-18 Thread Wayne Werner
On Fri, Nov 18, 2011 at 9:26 AM, Prasad, Ramit wrote: > Forwarding to the list since I wasn't the only person who helped ;) > > From: ADRIAN KELLY [mailto:kellyadr...@hotmail.com] > Sent: Thursday, November 17, 2011 6:08 PM > To: Prasad, Ramit > Subject: RE: [Tutor] urgent help!! THANKS EVERYONE!

[Tutor] FW: urgent help!! THANKS EVERYONE!

2011-11-18 Thread Prasad, Ramit
Forwarding to the list since I wasn't the only person who helped ;) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- From: ADRIAN KELLY [mailto:kellyadr...@hotmail.com] Sent: Thursday, November 17,

Re: [Tutor] A recursion question

2011-11-18 Thread Dave Angel
On 11/18/2011 08:16 AM, Kĩnũthia Mũchane wrote: Hi, I am trying to do something which is really stupid :-) I would like to count the number of occurrences of a certain character in a list. This is more of an exercise in recursion rather than the underlying problem. I could have used a *for* l

Re: [Tutor] Shorten Code.

2011-11-18 Thread Dave Angel
On 11/18/2011 04:01 AM, Alan Gauld wrote: On 18/11/11 08:16, Mic wrote: What if I don’t write the same line of code more than once, but I write similiar lines more than once. Is that okay? Ler For example: value="green” value_1=”green” If you had a lot of these you could shorten it with a loo

Re: [Tutor] Encoding

2011-11-18 Thread Max S.
Well, I am assuming that by this you mean converting user input into a string, and then extracting the numerals (0-9) from it. Next time, please tell us your version of Python. I'll do my best to help with this. You might try the following: the_input = input("Insert string here: ") # change to

Re: [Tutor] A recursion question

2011-11-18 Thread Christian Witts
On 2011/11/18 03:16 PM, Kĩnũthia Mũchane wrote: Hi, I am trying to do something which is really stupid :-) I would like to count the number of occurrences of a certain character in a list. This is more of an exercise in recursion rather than the underlying problem. I could have used a *for* l

[Tutor] A recursion question

2011-11-18 Thread Kĩnũthia Mũchane
Hi, I am trying to do something which is really stupid :-) I would like to count the number of occurrences of a certain character in a list. This is more of an exercise in recursion rather than the underlying problem. I could have used a *for* loop or simply the list *count* method. Here is the

Re: [Tutor] Shorten Code.

2011-11-18 Thread Alan Gauld
On 18/11/11 08:16, Mic wrote: What if I don’t write the same line of code more than once, but I write similiar lines more than once. Is that okay? Ler For example: value="green” value_1=”green” If you had a lot of these you could shorten it with a loop (BTW the English term in programming ter

[Tutor] Shorten Code.

2011-11-18 Thread Mic
From: Wayne Werner Sent: Thursday, November 17, 2011 8:30 PM To: Mic Cc: tutor@python.org Subject: Re: [Tutor] Clock in tkinter? Say that I have a class and I want to make 100 objects. Then it could look like this: class Chairs(object): #Create the objects chair1=Chair