[Tutor] Tutor Digest, Vol 62, Issue 15
Lazarus billa
billa_lazarus at yahoo.com
Tue Apr 7 17:32:59 CEST 2009
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.
bilas999 at yahoo.com
Phone: +91 9948189975.
--- On Mon, 4/6/09, tutor-request at python.org <tutor-request at python.org> wrote:
From: tutor-request at python.org <tutor-request at python.org>
Subject: Tutor Digest, Vol 62, Issue 15
To: tutor at python.org
Date: Monday, April 6, 2009, 7:56 AM
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: 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 <kent37 at tds.net>
Subject: Re: [Tutor] Checking for string in a list strangeness
To: AdamC <kabads at gmail.com>
Cc: Python Tutor <tutor at python.org>
Message-ID:
<1c2a2c590904060330n42d0132didb9cab2808a2b66 at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
On Mon, Apr 6, 2009 at 3:30 AM, AdamC <kabads at gmail.com> 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 <davea at ieee.org>
Subject: Re: [Tutor] base n fractional
To: tutor at python.org
Message-ID: <49D9FB48.3030603 at ieee.org>
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 <ctcast at gmail.com>
> Subject: [Tutor] base n fractional
> To: tutor at python.org
> Message-ID:
> <50e459210904051336v60dfc6ddt280d3c9c8f6e035b at mail.gmail.com>
> 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 <kent37 at tds.net>
Subject: Re: [Tutor] Checking for string in a list strangeness
To: AdamC <kabads at gmail.com>
Cc: *tutor python <tutor at python.org>
Message-ID:
<1c2a2c590904060554w176c7d7dnd0dff61f68383001 at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
On Mon, Apr 6, 2009 at 8:26 AM, AdamC <kabads at gmail.com> wrote:
> 2009/4/6 Kent Johnson <kent37 at tds.net>:
>> On Mon, Apr 6, 2009 at 3:30 AM, AdamC <kabads at gmail.com> 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 <hihiren1 at gmail.com>
Subject: [Tutor] problem in replacing regex
To: tutor at python.org
Message-ID:
<a4f7efa90904060723k43c12ec5k6b27950280102a7d at mail.gmail.com>
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 <bgailer at gmail.com>
Subject: [Tutor] Please use plain text.
To: tutor at python.org
Message-ID: <49DA1488.5030701 at gmail.com>
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 <bgailer at gmail.com>
Subject: Re: [Tutor] Checking for string in a list strangeness
To: AdamC <kabads at gmail.com>
Cc: Python Tutor <tutor at python.org>
Message-ID: <49DA182C.9070104 at gmail.com>
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 - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
End of Tutor Digest, Vol 62, Issue 15
*************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090407/747a9d23/attachment-0001.htm>
More information about the Tutor
mailing list