EASTER - 2009 "He is no more in the grave, He is risen" Do you enjoy His presence in your Heart?... Let us reach multitudes with this message. Please involve in our Good Shephered Ministries. Pray and plane to visit and witness to share the greatest mirical of our Lord. Praise Him Hallelujah. With Love and regards, Rev. Billa. Lazarus Good Shepherd Ministries, A.T.Agraharam, Gunatur - 522 004. Andhra Pradesh - South India. [email protected] Phone: +91 9948189975.
--- On Mon, 4/6/09, [email protected] <[email protected]> wrote: From: [email protected] <[email protected]> Subject: Tutor Digest, Vol 62, Issue 15 To: [email protected] Date: Monday, April 6, 2009, 7:56 AM Send Tutor mailing list submissions to [email protected] 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 [email protected] You can reach the person managing the list at [email protected] When replying, please edit your Subject line so it is more specific than "Re: Contents of Tutor digest..." Today's Topics: 1. Re: Checking for string in a list strangeness (Kent Johnson) 2. Re: base n fractional (Dave Angel) 3. Re: Checking for string in a list strangeness (Kent Johnson) 4. problem in replacing regex (Kumar) 5. Please use plain text. (bob gailer) 6. Re: Checking for string in a list strangeness (bob gailer) ---------------------------------------------------------------------- Message: 1 Date: Mon, 6 Apr 2009 06:30:44 -0400 From: Kent Johnson <[email protected]> Subject: Re: [Tutor] Checking for string in a list strangeness To: AdamC <[email protected]> Cc: Python Tutor <[email protected]> Message-ID: <[email protected]> Content-Type: text/plain; charset=ISO-8859-1 On Mon, Apr 6, 2009 at 3:30 AM, AdamC <[email protected]> wrote: > I'm writing a small cgi application for children to use and I want to > check that the name they enter isn't a swear word. > #for i in swearlist: ? ? ? # shows swear list OK > # ? ?print i; Perhaps the words in swearlist include some whitespace? Try for i in swearlist: print repr(i) and look for leading and trailing spaces, tabs, etc. Kent ------------------------------ Message: 2 Date: Mon, 06 Apr 2009 08:53:28 -0400 From: Dave Angel <[email protected]> Subject: Re: [Tutor] base n fractional To: [email protected] Message-ID: <[email protected]> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Chris Castillo wrote: > Message: 1 > Date: Sun, 5 Apr 2009 15:36:09 -0500 > From: Chris Castillo <[email protected]> > Subject: [Tutor] base n fractional > To: [email protected] > Message-ID: > <[email protected]> > Content-Type: text/plain; charset="iso-8859-1" > > I need some help converting the fractional (right side of the decimal) to > base 10. > I have this but it doesn't work > > mynum = raw_input("Please enter a number: ") > myint, myfrac = mynum.split(".") > base = raw_input("Please enter the base you would like to convert to: ") > base = int(base) > mydecfrac = 0 > fraclen = len(myfrac) - 1 > > for digit in range(len(myfrac) -1, -1, -1): > mydecfrac = mydecfrac + int(myfrac[digit]) > mydecfrac = mydecfrac / base > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: <http://mail.python.org/pipermail/tutor/attachments/20090405/612ca99f/attachment-0001.htm> > First we need a clear statement (with examples) of your goal. Your prompts to the user indicate you want to convert from decimal to some other base. But your comments here and elsewhere on the thread indicate the exact opposite. The two problems are related, but mixing them will just confuse everybody. > so when I say that to myself i see: > number = 234 > mysum = 0 > for digit in range(len(number) -1, -1, -1): > mysum = (mysum) * (1/base) + int(number[digit]) This just isn't valid python. You can't subscript an integer. You probably need a string here. That is what raw_input() would produce. So let's get a specific example, and try to work with it. Perhaps you want base = 5 myfrac = "234" and you want to figure the value that .234 would mean if it's interpreted as base 5. First, let's do it by hand. The two is in the first digit to the right of the decimal place, and therefore represents 2/5 The three is in the next place, and represents 3/25 And the four is in the next place and represents 4/125 Result is 0.552 decimal There are two ways to work a base conversion. One is to do the arithmetic in the source base, and do successive multiplies of the destination base. That would mean working in base 5 in this case, which is probably more work in Python. The other is to work in the result base, and do the multiplies of the source base. That's the approach you were taking, and it works great if the precision of a float is acceptable. Your code is fine, although a bit convoluted. Only problem is that you're working in integers, when you need float. So just change mydecfrac to 0.0 and it'll work. ------------------------------ Message: 3 Date: Mon, 6 Apr 2009 08:54:17 -0400 From: Kent Johnson <[email protected]> Subject: Re: [Tutor] Checking for string in a list strangeness To: AdamC <[email protected]> Cc: *tutor python <[email protected]> Message-ID: <[email protected]> Content-Type: text/plain; charset=ISO-8859-1 On Mon, Apr 6, 2009 at 8:26 AM, AdamC <[email protected]> wrote: > 2009/4/6 Kent Johnson <[email protected]>: >> On Mon, Apr 6, 2009 at 3:30 AM, AdamC <[email protected]> wrote: >>> I'm writing a small cgi application for children to use and I want to >>> check that the name they enter isn't a swear word. >> >>> #for i in swearlist: ? ? ? # shows swear list OK >>> # ? ?print i; >> >> Perhaps the words in swearlist include some ?whitespace? Try >> for i in swearlist: >> ?print repr(i) >> >> and look for leading and trailing spaces, tabs, etc. >> >> Kent > > I think you're on to something here Kent. Thanks. There doesn't appear > to be any whitespaces in the words but an entry in the list appears > like this: > > print swearlist[0] > returns > ('xxxx',) > > where xxxx is the expletive in the database. Ah, yes, the result of mycursor.fetchone() is a tuple containing the fetched elements. Even though you are only reading one field, it is still returned in a tuple. That is what the parentheses and comma signify. Try this: swearlist = [] for i in range (0, myrowcount): myrow = mycursor.fetchone() swearlist.append(myrow[0]) Kent ------------------------------ Message: 4 Date: Mon, 6 Apr 2009 19:53:25 +0530 From: Kumar <[email protected]> Subject: [Tutor] problem in replacing regex To: [email protected] Message-ID: <[email protected]> Content-Type: text/plain; charset="iso-8859-1" Hello everyone, I have one account number. I want to replace all this account numbers and convert them as URLS. but I don't want to convert existing urls which has account numbers. e.g. 1234-4578 first i convert any existing url into <a> and then I check that if any above number exist then I convert them to my site's url . i am already having regex to check and replace this number. And I can replace all occurrences of this number and convert them into url using re.sub() but problem is that if the value is http://sadfsdf.com/1234-4578 then it first converts http://sadfsdf.com/1234-4578 into <a href=" http://sadfsdf.com/1234-4578">http://sadfsdf.com/1234-4578</a> and then again it converts last number into url so the complete url gets broken. can anybody help me how can I omit the searching existing urls with above number? I have already tried many examples but none of them seems working. Although I can use re.sub('[^/](myregex)','<desirect replacement>',value) but it won't be a permenant solution as if somebody enters /1234-4578 then also it won't convert it. Thanks, Kumar -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/tutor/attachments/20090406/8612a1b7/attachment-0001.htm> ------------------------------ Message: 5 Date: Mon, 06 Apr 2009 10:41:12 -0400 From: bob gailer <[email protected]> Subject: [Tutor] Please use plain text. To: [email protected] Message-ID: <[email protected]> Content-Type: text/plain; charset="us-ascii" An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/tutor/attachments/20090406/df82d404/attachment-0001.htm> ------------------------------ Message: 6 Date: Mon, 06 Apr 2009 10:56:44 -0400 From: bob gailer <[email protected]> Subject: Re: [Tutor] Checking for string in a list strangeness To: AdamC <[email protected]> Cc: Python Tutor <[email protected]> Message-ID: <[email protected]> Content-Type: text/plain; charset="us-ascii" An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/tutor/attachments/20090406/64de3c75/attachment.htm> ------------------------------ _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor End of Tutor Digest, Vol 62, Issue 15 *************************************
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
