Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77321 > unrolled thread

I have tried and errored a reasonable amount of times

Started bySeymore4Head <Seymore4Head@Hotmail.invalid>
First post2014-08-30 14:27 -0400
Last post2014-08-31 19:05 +1000
Articles 8 on this page of 28 — 12 participants

Back to article view | Back to comp.lang.python


Contents

  I have tried and errored a reasonable amount of times Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-30 14:27 -0400
    Re: I have tried and errored a reasonable amount of times Tim Chase <python.list@tim.thechases.com> - 2014-08-30 13:48 -0500
      Re: I have tried and errored a reasonable amount of times Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-30 14:50 -0400
        Re: I have tried and errored a reasonable amount of times Ned Batchelder <ned@nedbatchelder.com> - 2014-08-30 16:20 -0400
          Re: I have tried and errored a reasonable amount of times Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-30 16:32 -0400
        Re: I have tried and errored a reasonable amount of times Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-31 18:37 +1000
          Re: I have tried and errored a reasonable amount of times Chris Angelico <rosuav@gmail.com> - 2014-08-31 19:16 +1000
      Re: I have tried and errored a reasonable amount of times Grant Edwards <invalid@invalid.invalid> - 2014-09-02 16:43 +0000
        Re: I have tried and errored a reasonable amount of times Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-02 12:59 -0400
        Re: I have tried and errored a reasonable amount of times Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-03 11:44 +1000
          Re: I have tried and errored a reasonable amount of times Rustom Mody <rustompmody@gmail.com> - 2014-09-02 20:14 -0700
            Re: I have tried and errored a reasonable amount of times Steven D'Aprano <steve@pearwood.info> - 2014-09-03 07:16 +0000
              Re: I have tried and errored a reasonable amount of times Marko Rauhamaa <marko@pacujo.net> - 2014-09-03 10:44 +0300
                Re: I have tried and errored a reasonable amount of times Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-04 11:54 +1000
                  Re: I have tried and errored a reasonable amount of times Chris Angelico <rosuav@gmail.com> - 2014-09-04 12:03 +1000
                  Re: I have tried and errored a reasonable amount of times Rustom Mody <rustompmody@gmail.com> - 2014-09-03 19:23 -0700
                  Re: I have tried and errored a reasonable amount of times Marko Rauhamaa <marko@pacujo.net> - 2014-09-04 08:36 +0300
              Re: I have tried and errored a reasonable amount of times Denis McMahon <denismfmcmahon@gmail.com> - 2014-09-04 11:17 +0000
                Re: I have tried and errored a reasonable amount of times Chris Angelico <rosuav@gmail.com> - 2014-09-04 21:42 +1000
                  Re: I have tried and errored a reasonable amount of times Denis McMahon <denismfmcmahon@gmail.com> - 2014-09-05 02:53 +0000
                    Re: I have tried and errored a reasonable amount of times Chris Angelico <rosuav@gmail.com> - 2014-09-05 13:02 +1000
                    Re: I have tried and errored a reasonable amount of times Grant Edwards <invalid@invalid.invalid> - 2014-09-05 14:54 +0000
                      Re: I have tried and errored a reasonable amount of times Marko Rauhamaa <marko@pacujo.net> - 2014-09-05 19:45 +0300
    Re: I have tried and errored a reasonable amount of times Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-30 22:21 +0100
      Re: I have tried and errored a reasonable amount of times Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-30 17:48 -0400
        Re: I have tried and errored a reasonable amount of times Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-30 23:32 +0100
        Re: I have tried and errored a reasonable amount of times Cameron Simpson <cs@zip.com.au> - 2014-08-31 15:30 +1000
        Re: I have tried and errored a reasonable amount of times Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-31 19:05 +1000

Page 2 of 2 — ← Prev page 1 [2]


#77573

FromChris Angelico <rosuav@gmail.com>
Date2014-09-05 13:02 +1000
Message-ID<mailman.13781.1409886170.18130.python-list@python.org>
In reply to#77571
On Fri, Sep 5, 2014 at 12:53 PM, Denis McMahon <denismfmcmahon@gmail.com> wrote:
> On Thu, 04 Sep 2014 21:42:56 +1000, Chris Angelico wrote:
>
>> On Thu, Sep 4, 2014 at 9:17 PM, Denis McMahon <denismfmcmahon@gmail.com>
>> wrote:
>>> On Wed, 03 Sep 2014 07:16:34 +0000, Steven D'Aprano wrote:
>>>
>>>> Who uses + for disjunction (∨ OR) and concatenation for conjunction (∧
>>>> AND)? That's crazy notation.
>>>
>>> The way I was taught it in the mid 1980s, a.b === a and b, a+b === a or
>>> b.
>>
>> The middle dot is another notation for multiplication, as is abuttal
>> (not actually concatenation, in this context). So they're all saying the
>> same thing: boolean 'and' is multiplication, boolean 'or' is addition.
>
> Yes Chris, I know that. I was responding to Stephen's statement that
> using + for or was crazy notation, and pointing out that 30 years ago,
> that's what UK colleges were teaching!

Ah, okay. Wasn't sure if you meant to be agreeing with multiplication
or offering an alternative.

ChrisA

[toc] | [prev] | [next] | [standalone]


#77588

FromGrant Edwards <invalid@invalid.invalid>
Date2014-09-05 14:54 +0000
Message-ID<lucirc$4k2$1@reader1.panix.com>
In reply to#77571
On 2014-09-05, Denis McMahon <denismfmcmahon@gmail.com> wrote:
> On Thu, 04 Sep 2014 21:42:56 +1000, Chris Angelico wrote:
>> On Thu, Sep 4, 2014 at 9:17 PM, Denis McMahon <denismfmcmahon@gmail.com> wrote:
>>> On Wed, 03 Sep 2014 07:16:34 +0000, Steven D'Aprano wrote:
>>>
>>>> Who uses + for disjunction (∨ OR) and concatenation for conjunction
>>>> (∧ AND)? That's crazy notation.
>>>
>>> The way I was taught it in the mid 1980s, a.b === a and b, a+b === a
>>> or b.
>> 
>> The middle dot is another notation for multiplication, as is abuttal
>> (not actually concatenation, in this context). So they're all saying
>> the same thing: boolean 'and' is multiplication, boolean 'or' is
>> addition.
>
> Yes Chris, I know that. I was responding to Stephen's statement that 
> using + for or was crazy notation, and pointing out that 30 years
> ago, that's what UK colleges were teaching!

AFAIK, that's the standard notation in both CS and EE university
classes in the US also: + for 'or' and dot or abuttal for 'and'.

Well, it was 30 years ago...

-- 
Grant Edwards               grant.b.edwards        Yow! But was he mature
                                  at               enough last night at the
                              gmail.com            lesbian masquerade?

[toc] | [prev] | [next] | [standalone]


#77589

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-09-05 19:45 +0300
Message-ID<87lhpyj9rv.fsf@elektro.pacujo.net>
In reply to#77588
Grant Edwards <invalid@invalid.invalid>:

>>>>> Who uses + for disjunction (∨ OR) and concatenation for
>>>>> conjunction (∧ AND)? That's crazy notation.
>
> AFAIK, that's the standard notation in both CS and EE university
> classes in the US also: + for 'or' and dot or abuttal for 'and'.

Besides, it's no crazier for Boolean algebra than real algebra. For some
reason, mathematicians use + for addition and concatenation for
multiplication...


Marko

[toc] | [prev] | [next] | [standalone]


#77337

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-08-30 22:21 +0100
Message-ID<mailman.13655.1409433719.18130.python-list@python.org>
In reply to#77321
On 30/08/2014 19:48, Tim Chase wrote:
> On 2014-08-30 14:27, Seymore4Head wrote:
>> I really tried to get this without asking for help.
>>
>> mylist = ["The", "earth", "Revolves", "around", "Sun"]
>> print (mylist)
>> for e in mylist:
>>
>>   # one of these two choices should print something.  Since neither
>> does, I am missing something subtle.
>>
>>      if e[0].isupper == False:
>>          print ("False")
>>      if e[0].isupper == True:
>>          print ("True")
>>
>> I am sure in the first , third and fifth choices should be true.
>> Right now, I am just testing the first letter of each word.
>
> There's a difference between e[0].isupper which refers to the method
> itself, and e[0].isupper() which then calls that method.  Call the
> method, and you should be good to go.
>
> -tkc
>

For the OP use the interactive prompt to see for yourself.  Compare:-
 >>> 'no'.isupper
<built-in method isupper of str object at 0x0000000003D14FB8>
 >>> 'no'.isupper()
False
 >>>

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#77339

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-08-30 17:48 -0400
Message-ID<pgh40alno9vl8n8bpk5ogbnc1uhql76n2n@4ax.com>
In reply to#77337
On Sat, 30 Aug 2014 22:21:40 +0100, Mark Lawrence
<breamoreboy@yahoo.co.uk> wrote:

>On 30/08/2014 19:48, Tim Chase wrote:
>> On 2014-08-30 14:27, Seymore4Head wrote:
>>> I really tried to get this without asking for help.
>>>
>>> mylist = ["The", "earth", "Revolves", "around", "Sun"]
>>> print (mylist)
>>> for e in mylist:
>>>
>>>   # one of these two choices should print something.  Since neither
>>> does, I am missing something subtle.
>>>
>>>      if e[0].isupper == False:
>>>          print ("False")
>>>      if e[0].isupper == True:
>>>          print ("True")
>>>
>>> I am sure in the first , third and fifth choices should be true.
>>> Right now, I am just testing the first letter of each word.
>>
>> There's a difference between e[0].isupper which refers to the method
>> itself, and e[0].isupper() which then calls that method.  Call the
>> method, and you should be good to go.
>>
>> -tkc
>>
>
>For the OP use the interactive prompt to see for yourself.  Compare:-
> >>> 'no'.isupper
><built-in method isupper of str object at 0x0000000003D14FB8>
> >>> 'no'.isupper()
>False
> >>>
That would work now, but I didn't even know no.isupper() was command
until 15 min ago.  :)

I have been told that one is a method and the other calls a method.  I
still have to learn exactly what that means.  I'm getting there.

Thanks

[toc] | [prev] | [next] | [standalone]


#77340

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-08-30 23:32 +0100
Message-ID<mailman.13657.1409437993.18130.python-list@python.org>
In reply to#77339
On 30/08/2014 22:48, Seymore4Head wrote:
> On Sat, 30 Aug 2014 22:21:40 +0100, Mark Lawrence
> <breamoreboy@yahoo.co.uk> wrote:
>
>> On 30/08/2014 19:48, Tim Chase wrote:
>>> On 2014-08-30 14:27, Seymore4Head wrote:
>>>> I really tried to get this without asking for help.
>>>>
>>>> mylist = ["The", "earth", "Revolves", "around", "Sun"]
>>>> print (mylist)
>>>> for e in mylist:
>>>>
>>>>    # one of these two choices should print something.  Since neither
>>>> does, I am missing something subtle.
>>>>
>>>>       if e[0].isupper == False:
>>>>           print ("False")
>>>>       if e[0].isupper == True:
>>>>           print ("True")
>>>>
>>>> I am sure in the first , third and fifth choices should be true.
>>>> Right now, I am just testing the first letter of each word.
>>>
>>> There's a difference between e[0].isupper which refers to the method
>>> itself, and e[0].isupper() which then calls that method.  Call the
>>> method, and you should be good to go.
>>>
>>> -tkc
>>>
>>
>> For the OP use the interactive prompt to see for yourself.  Compare:-
>>>>> 'no'.isupper
>> <built-in method isupper of str object at 0x0000000003D14FB8>
>>>>> 'no'.isupper()
>> False
>>>>>
> That would work now, but I didn't even know no.isupper() was command
> until 15 min ago.  :)
>
> I have been told that one is a method and the other calls a method.  I
> still have to learn exactly what that means.  I'm getting there.
>
> Thanks
>

Slow down a little :) 'no' is a string, isupper is just one of many 
methods that any string has.  Try typing help('no') into the interactive 
prompt and see what you get.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#77341

FromCameron Simpson <cs@zip.com.au>
Date2014-08-31 15:30 +1000
Message-ID<mailman.13658.1409464347.18130.python-list@python.org>
In reply to#77339
On 30Aug2014 17:48, Seymore4Head <Seymore4Head@Hotmail.invalid> wrote:
>I have been told that one is a method and the other calls a method.  I
>still have to learn exactly what that means.  I'm getting there.

A method is, essentially, a function. Observe:

   def my_func(x):
     print(9)

my_func is just the name of the function, and .isupper is likewise just the 
name of the function that tests a string for uppercaseness.

Conversely, my_func() actually calls the function, and likewise .isupper() 
calls the test function, returning True or False depending on whether the 
string was uppercase or not.

A method versus a function? A method is a particular type of function. It is 
normally defined in a class, eg:

   class MyClass:

       def method_name_here(self, arg1, arg2):
         ... do something with self and arg1 and arg2 ...

When you have an object which is an instance of the class (let us call it "o"), 
when you call:

   o.method_name_here(1,2)

it invokes the function MyClass.method_name_here(o,1,2). So because the string 
"no" is an instance of str, the code:

   "no".isupper()

runs the function str.isupper("no"), which examines its argument for 
uppercaseness.

Cheers,
Cameron Simpson <cs@zip.com.au>

Why is it so hard for people to simply leave people alone? But, the answer
comes to me: they are idiots and in a perfect world, I would be permitted to
kill them all.  - Julie Rhodes <jk.rhodes@asacomp.com>

[toc] | [prev] | [next] | [standalone]


#77344

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-08-31 19:05 +1000
Message-ID<5402e54c$0$29998$c3e8da3$5496439d@news.astraweb.com>
In reply to#77339
Seymore4Head wrote:

> That would work now, but I didn't even know no.isupper() was command
> until 15 min ago.  :)
> 
> I have been told that one is a method and the other calls a method.  I
> still have to learn exactly what that means.  I'm getting there.

Indeed you are :-)

"Command", in Python, doesn't really have any formal meaning. Sometimes we
use it informally, e.g. I might say that the `import` statement is a
command that loads a module.

What is the difference between "is a method" and "calls a method"? In
practice, there's not much difference between methods and functions, so I'm
going to talk about functions. Pretty much everything I say will apply to
methods too.

[Reminder: functions are "stand alone" objects that live inside a module,
but not a class. Methods are just like functions, but they live inside
classes. There are a few other differences, but conceptually they're the
same thing.]

Let's create a function. Copy and paste this into an interactive session:

def spam(n):
    return "spam"*n


This takes the indented body of the function (in this case, a single line of
source code), compiles it, shoves the compiled bytecode somewhere Python
can get to later, creates a function object which includes that compiled
bytecode, and assigns that function object to the variable called "spam".
spam is a variable like any other, and we can print it, put it inside a
list, assign it to another variable, and so forth:

py> print(spam)
<function spam at 0xb7d05344>
py> mylist = [None, 1, "two", spam]
py> print(mylist)
[None, 1, 'two', <function spam at 0xb7d05344>]
py> x = spam
py> print(x)
<function spam at 0xb7d05344>


Because functions are objects, they have attributes and methods like other
objects:

py> spam.__name__
'spam'
py> dir(spam)
['__annotations__', '__call__', '__class__', '__closure__', '__code__', 
'__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', 
'__format__', '__ge__', '__get__', '__getattribute__', '__globals__', 
'__gt__', '__hash__', '__init__', '__kwdefaults__', '__le__', '__lt__', 
'__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', 
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', 
'__subclasshook__']

See how all of those attributes start and end with double underscores?
These "dunder" (Double UNDERscore) attributes are reserved for use by
Python, and 99.9% of the time you don't need to pay any attention to them
in the least. But they are there, Python uses them, and on (rare) occasions
so will you.

(Feel free to look but not touch: you can print out the value of any dunder
attribute, but don't try changing them until you know what you're doing.)

So far, we've just been treating spam as an object. What sort of object?
It's a function object, like there are int objects, str objects, float
objects, list objects, and so on. Unlike all those other kinds of object,
function objects are callable: if you put round brackets (parentheses)
after the variable, the object assigned to that variable will be called:

py> spam
<function spam at 0xb7d05344>
py> spam(3)
'spamspamspam'


Remember how we assigned spam object to the variable "x"? That means that x
is another name for spam:

py> x(4)
'spamspamspamspam'


And since spam has been placed inside a list, we have a third way to refer
to it:

py> mylist[3]  # Retrieve the function.
<function spam at 0xb7d05344>
py> mylist[3](2)  # And call it.
'spamspam'


Note that this does NOT mean that we have three copies of the function. We
only have a single copy of the function. But we have three different ways
of referring to it:

* the canonical name, "spam", which is the name it knows itself by;
* the name "x";
* the list item mylist[3].

Any of those will give you the function object itself, but without calling
it. Only when you use round brackets (parentheses) will the function
actually be called.



-- 
Steven

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web