Re: [Tutor] string rules for 'number'

2012-10-08 Thread Steven D'Aprano
On 08/10/12 11:51, Arnej Duranovic wrote: Alright guys, I appreciate all your help SO much. I know understand, as the gentleman above said A string is a string is a string doesn't matter what is in it and they are ordered the same way...BUT this is what was going through my head. Since letters

Re: [Tutor] Through a glass, darkly: the datetime module

2012-10-08 Thread Prasad, Ramit
Steven D'Aprano wrote: It is a little-known fact that Unix sys admins, and C programmers, can only type a fixed number of keys before their brains explode. Sad but true. Since nobody knows how many keys that will be, but only that it is fixed at birth, they have a horror of typing four

[Tutor] finding a number with str.find

2012-10-08 Thread Benjamin Fishbein
Is there a way to find the next character that is a digit (0-9) in a string? It seems that the str.find method can only find one particular character, rather than any character from among many. ___ Tutor maillist - Tutor@python.org To unsubscribe or

[Tutor] finding digit in string

2012-10-08 Thread Benjamin Fishbein
I figured out a solution for the question I asked on here. To find the next digit (0-9) in a string, I use: text.find(0 or 1 or 2, etc...) But is there a more elegant way to do this? The way I found uses a lot of typing. ___ Tutor maillist -

Re: [Tutor] finding a number with str.find

2012-10-08 Thread Alan Gauld
On 08/10/12 17:33, Benjamin Fishbein wrote: Is there a way to find the next character that is a digit (0-9) in a string? it seems that the str.find method can only find one particular character, When looking for patterns rather than literal values you need to use regular expressions. These

Re: [Tutor] finding digit in string

2012-10-08 Thread Mark Lawrence
On 08/10/2012 17:43, Benjamin Fishbein wrote: I figured out a solution for the question I asked on here. To find the next digit (0-9) in a string, I use: text.find(0 or 1 or 2, etc...) But is there a more elegant way to do this? The way I found uses a lot of typing.

Re: [Tutor] finding digit in string

2012-10-08 Thread Alan Gauld
On 08/10/12 17:43, Benjamin Fishbein wrote: I figured out a solution for the question I asked on here. To find the next digit (0-9) in a string, I use: text.find(0 or 1 or 2, etc...) Are you sure that worked? It doesn't for me on Python 2.7... s 'a string with 7 words in it' s.find('4'

Re: [Tutor] finding digit in string

2012-10-08 Thread Dave Angel
On 10/08/2012 12:43 PM, Benjamin Fishbein wrote: I figured out a solution for the question I asked on here. Why then did you start a new thread, instead of responding on the same one? You didn't even use the same subject string. To find the next digit (0-9) in a string, I use: text.find(0 or

Re: [Tutor] finding digit in string

2012-10-08 Thread bob gailer
On 10/8/2012 12:43 PM, Benjamin Fishbein wrote: I figured out a solution for the question I asked on here. To find the next digit (0-9) in a string, I use: text.find(0 or 1 or 2, etc...) But is there a more elegant way to do this? The way I found uses a lot of typing. My way is: import

Re: [Tutor] finding a number with str.find

2012-10-08 Thread Steven D'Aprano
On 09/10/12 03:33, Benjamin Fishbein wrote: Is there a way to find the next character that is a digit (0-9) in a string? It seems that the str.find method can only find one particular character, rather than any character from among many. Correct. For more complicated searching needs, either

Re: [Tutor] Through a glass, darkly: the datetime module

2012-10-08 Thread Roel Schroeven
Sander Sweers schreef: Roel Schroeven schreef op zo 07-10-2012 om 21:19 [+0200]: Sander Sweers schreef: Op 7 okt. 2012 04:29 schreef aklei...@sonic.net mailto:aklei...@sonic.net het volgende: I'm also not sure but I seem to remember that it is (SUNDAY, MONDAY, TUESDAY, WEDNESDAY,

Re: [Tutor] string rules for 'number'

2012-10-08 Thread Oscar Benjamin
On 8 October 2012 03:19, eryksun eryk...@gmail.com wrote: As a supplement to what's already been stated about string comparisons, here's a possible solution if you need a more 'natural' sort order such as '1', '5', '10', '50', '100'. You can use a regular expression to split the string into a

Re: [Tutor] finding digit in string

2012-10-08 Thread Prasad, Ramit
Mark Lawrence wrote: On 08/10/2012 17:43, Benjamin Fishbein wrote: I figured out a solution for the question I asked on here. To find the next digit (0-9) in a string, I use: text.find(0 or 1 or 2, etc...) But is there a more elegant way to do this? The way I found uses a lot of

Re: [Tutor] finding a number with str.find

2012-10-08 Thread Alan Gauld
On 08/10/12 19:31, Steven D'Aprano wrote: re.search(r'\d', 'I 8 sandwiches').start() # returns 2 I knew there was a better way that using index and group but I couldn't think what it was... start() so obvious once you see it :-) -- Alan G Author of the Learn to Program web site

Re: [Tutor] finding digit in string

2012-10-08 Thread eryksun
On Mon, Oct 8, 2012 at 4:11 PM, Prasad, Ramit ramit.pra...@jpmorgan.com wrote: for ch in text: if '0' = ch = '9': doSomething(ch) I am not sure that will work very well with Unicode numbers. I would assume (you know what they say about assuming) that str.isdigit() works

Re: [Tutor] Through a glass, darkly: the datetime module

2012-10-08 Thread Steven D'Aprano
On Mon, Oct 08, 2012 at 08:50:14PM +0200, Roel Schroeven wrote: Sander Sweers schreef: As far as I know also in Belgium Sunday is officially the first day of the week. Look at the calendar and check what is the leftmost day. My guess this is the same as your northern neighbor, Sunday ;-).

Re: [Tutor] Why difference between printing string typing its object reference at the prompt?

2012-10-08 Thread boB Stepp
Steve, On Thu, Oct 4, 2012 at 6:28 AM, Steven D'Aprano st...@pearwood.info wrote: snip Now, ask me about *raw strings*, and the difference between Unicode and byte strings :) How can I resist asking! I am not in chapter 2 of my study text yet, but looking ahead raw strings seem to be a method