Re: Just remember that Python is sexy

2005-05-24 Thread Fuzzyman

Scott Kirkwood wrote:
> I often can't remember that to remove spaces from a string whether
it's
> strip() or trim(), and when finding patterns with the re library
> whether it's find() or search() and when iterating over key, values
of
> a dictionary whether it's items() or entries().
> But then I remember that Python is "sexy".
> It is sexier to strip() than to trim().
> You do a strip search() not a find() search.
> And you remove items() of clothing and not entries() of clothing.

Thats very silly.

Regards,

Fuzzy
http://www.voidspace.org.uk/python

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just remember that Python is sexy

2005-05-24 Thread Scott Kirkwood
Silly but true. It started with trying to figure how to remember it's
strip() and not trim(). 
Then it went downhill from there.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just remember that Python is sexy

2005-05-24 Thread Do Re Mi chel La Si Do
:-)



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just remember that Python is sexy

2005-05-25 Thread Sion Arrowsmith
Scott Kirkwood <[EMAIL PROTECTED]> wrote:
>I often can't remember that to remove spaces from a string whether it's
>strip() or trim(), and when finding patterns with the re library
>whether it's find() or search() and when iterating over key, values of
>a dictionary whether it's items() or entries().
>But then I remember that Python is "sexy".
>It is sexier to strip() than to trim().
>You do a strip search() not a find() search.
>And you remove items() of clothing and not entries() of clothing.

But can you come up with a method for remembering which way
round str.find() and str.index() are?

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Just remember that Python is sexy

2005-05-25 Thread Peter Hansen
Sion Arrowsmith wrote:
> But can you come up with a method for remembering which way
> round str.find() and str.index() are?

Don't use "str" and you won't have anything to remember:

'foo bar baz'.find('spam')
'spanish inquisition'.index('parrot')

-Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just remember that Python is sexy

2005-05-26 Thread Ville Vainio
> "Peter" == Peter Hansen <[EMAIL PROTECTED]> writes:

Peter> Sion Arrowsmith wrote:
>> But can you come up with a method for remembering which way
>> round str.find() and str.index() are?

Peter> Don't use "str" and you won't have anything to remember:

Peter> 'foo bar baz'.find('spam')
Peter> 'spanish inquisition'.index('parrot')

But which one raises an exception, and which one returns -1?

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just remember that Python is sexy

2005-05-26 Thread Duncan Booth
Ville Vainio wrote:

>> "Peter" == Peter Hansen <[EMAIL PROTECTED]> writes:
> 
> Peter> Sion Arrowsmith wrote:
> >> But can you come up with a method for remembering which way
> >> round str.find() and str.index() are?
> 
> Peter> Don't use "str" and you won't have anything to remember:
> 
> Peter> 'foo bar baz'.find('spam')
> Peter> 'spanish inquisition'.index('parrot')
> 
> But which one raises an exception, and which one returns -1?
> 
The name index implies it returns something you can use as an index to get 
at the substring.

In other words you can always assume that the following expression is True 
(if it has any value at all) when you use the result of index as an index:

s[s.index(t):].startswith(t)

The name 'find' doesn't really imply anything about the result, so it can 
return pretty much any crud such as -1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just remember that Python is sexy

2005-05-26 Thread Peter Hansen
Ville Vainio wrote:
>>"Peter" == Peter Hansen <[EMAIL PROTECTED]> writes:
> Peter> Sion Arrowsmith wrote:
> >> But can you come up with a method for remembering which way
> >> round str.find() and str.index() are?
> 
> Peter> Don't use "str" and you won't have anything to remember:
> 
> Peter> 'foo bar baz'.find('spam')
> Peter> 'spanish inquisition'.index('parrot')
> 
> But which one raises an exception, and which one returns -1?

Ah, is that what Sion meant by "which way around"?  Obviously that was 
an ambiguous question, since I thought he was referring to the order of 
the arguments.

My answer to the other question, unfortunately, is "I just type one of 
them at an interpreter prompt and see which result I get".  Much faster 
than checking the docs...;-)

-Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just remember that Python is sexy

2005-05-26 Thread Sion Arrowsmith
Duncan Booth  <[EMAIL PROTECTED]> wrote:
>Ville Vainio wrote:
>>> "Peter" == Peter Hansen <[EMAIL PROTECTED]> writes:
>> Peter> Sion Arrowsmith wrote:
>> >> But can you come up with a method for remembering which way
>> >> round str.find() and str.index() are?
>> 
>> Peter> Don't use "str" and you won't have anything to remember:
>> 
>> Peter> 'foo bar baz'.find('spam')
>> Peter> 'spanish inquisition'.index('parrot')
>> But which one raises an exception, and which one returns -1?

That's what I meant (and why I wrote "str." not "string.").

>The name index implies it returns something you can use as an index to get 
>at the substring.

Unfortunately, -1 can of course be used as an index. Mind you, it
would be perverse to expect to find the substring at it.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Just remember that Python is sexy

2005-05-26 Thread Duncan Booth
Sion Arrowsmith wrote:

>>The name index implies it returns something you can use as an index to
>>get at the substring.
> 
> Unfortunately, -1 can of course be used as an index. Mind you, it
> would be perverse to expect to find the substring at it.
> 
That was my point. The returned index always points at the substring, 
therefore the function which returns a -1 isn't returning an index. 
Therefore index must be the one which raises an exception.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just remember that Python is sexy

2005-05-26 Thread Greg Ewing
Duncan Booth wrote:

> The name index implies it returns something you can use as an index to get 
> at the substring.

But that's no fun -- it doesn't involve sex!

How about this: "index" and "sex" both end with "ex", which
is short for "exception".

(Of course, you could get straight from "index" to "exception"
that way too, but then there wouldn't be any excuse for
mentioning sex. :-)

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,   
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just remember that Python is sexy

2005-05-26 Thread Ville Vainio
> "Greg" == Greg Ewing <[EMAIL PROTECTED]> writes:

>> The name index implies it returns something you can use as an index
>> to get at the substring.

Greg> But that's no fun -- it doesn't involve sex!

Greg> How about this: "index" and "sex" both end with "ex", which
Greg> is short for "exception".

Or something about the use of index finger being an exception from the
conventional strategy...

-- 
Ville Vainio   http://tinyurl.com/2prnb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just remember that Python is sexy

2005-05-30 Thread Eric Pederson
> I often can't remember that to remove spaces from a string whether it's
> strip() or trim(), and when finding patterns with the re library
> whether it's find() or search() and when iterating over key, values of
> a dictionary whether it's items() or entries().
> But then I remember that Python is "sexy".
> It is sexier to strip() than to trim().
> You do a strip search() not a find() search.
> And you remove items() of clothing and not entries() of clothing.


Genius!  I will never perplex myself with string_foo.trim() again. (I do forget)

I recommend this be adopted as a naming standard for Python methods:

"The method name should have a sexy connotation"












Eric Pederson
http://www.songzilla.blogspot.com
:::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:::

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just remember that Python is sexy

2005-06-03 Thread Scott Kirkwood
Yes, 
but we don't want it to get out of hand, like calling it orgy() instead of join().
Or condom() instead of secure().
Or onClimax() instead of onFinished()
:-)On 5/31/05, Eric Pederson <[EMAIL PROTECTED]> wrote:
> I often can't remember that to remove spaces from a string whether it's> strip() or trim(), and when finding patterns with the re library> whether it's find() or search() and when iterating over key, values of
> a dictionary whether it's items() or entries().> But then I remember that Python is "sexy".> It is sexier to strip() than to trim().> You do a strip search() not a find() search.
> And you remove items() of clothing and not entries() of clothing.Genius!  I will never perplex myself with string_foo.trim() again. (I do forget)I recommend this be adopted as a naming standard for Python methods:
"The method name should have a sexy connotation"Eric Pedersonhttp://www.songzilla.blogspot.com
:::domainNot="@something.com"domainIs=domainNot.replace("s","z")ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs:::
-- 
http://mail.python.org/mailman/listinfo/python-list