Re: Pipe in the return statement

2011-07-28 Thread Thomas 'PointedEars' Lahn
Ethan Furman wrote:

 Billy Mays wrote:
 On 07/25/2011 10:16 AM, Archard Lias wrote:
 On Jul 25, 2:03 pm, Ian Collinsian-n...@hotmail.com  wrote:
 On 07/26/11 12:00 AM, Archard Lias wrote:
 Still I dont get how I am supposed to understand the pipe and its
 task/ idea/influece on control flow, of:
 returnstatement|statement
 ??

 It's simply a bitwise OR.

 Yes, but how does it get determined, which one actually gets returned?
 The return statement returns a single value from a function context. The
 pipe operator takes 2 values and bitwise ORs* them together.  That
 result is then returned to the caller.
 Just for completeness, if the actual line had been
 
 return statement1 or statement2
 
 then Python would compute statement1, and if its boolean value was
 True would return the computation of statement1, otherwise it would
 compute statement2 and return that.  When 'or' is used, the first
 truthy* item is return, or the last falsey* item if none evaluate to True.

Hence *bitwise* OR (as Billy wrote), _not_ logical OR (as you wrote), 
probably.
 
-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Pipe in the return statement

2011-07-25 Thread Archard Lias
Hi,

I have come across something I don't really understand and would be
grateful if someone could shed some light into my understanding of it.

In the documentation of the Qt4 libs in the page regarding the
QAbstractTableModel you find, to make the table editable, the
following:

Qt::ItemFlags StringListModel::flags(const QModelIndex index) const
{
if (!index.isValid())
return Qt::ItemIsEnabled;

 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
}

Now I'm working with PySide, the Python bindings from Nokia and I
figured the
return in the function to be related with a parent
(QAbstractItemModel)
followed by the actual Flag that says: yes the item, the index is
pointing
at, is actually editable. So translation of the C++ to Python would
be, and
it actually worked:

def flags(self, index):
if not index.isValid():
return Qt.ItemIsEnabled

return super(self.__class__, self).flags(index) |
Qt.ItemIsEditable

Still I dont get how I am supposed to understand the pipe and its task/
idea/influece on control flow, of:
return statement | statement
??

Thankful if you could help me with this.

Kind regards,
Archard Lias
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pipe in the return statement

2011-07-25 Thread Ian Collins

On 07/26/11 12:00 AM, Archard Lias wrote:

Hi,

Still I dont get how I am supposed to understand the pipe and its task/
idea/influece on control flow, of:
returnstatement  |statement
??


It's simply a bitwise OR.

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


Re: Pipe in the return statement

2011-07-25 Thread Christian Heimes
Am 25.07.2011 14:00, schrieb Archard Lias:
 def flags(self, index):
 if not index.isValid():
 return Qt.ItemIsEnabled
 
 return super(self.__class__, self).flags(index) |

Your use of super() is incorrect and will not work as you might expect.
You *must* use the class here, never self.__class__.

Christian

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


Re: Pipe in the return statement

2011-07-25 Thread TonyO
 Still I dont get how I am supposed to understand the pipe and its task/
 idea/influece on control flow, of:
 return statement | statement

In the words of René Magritte,

return statement | statement
   ^
Ceci n'est pas une pipe.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pipe in the return statement

2011-07-25 Thread gwowen
On Jul 25, 1:52 pm, TonyO guinness.t...@gmail.com wrote:

 return statement | statement

 In the words of René Magritte,

 return statement | statement
                    ^
 Ceci n'est pas une pipe.

*golf clap*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pipe in the return statement

2011-07-25 Thread Archard Lias
On Jul 25, 2:03 pm, Ian Collins ian-n...@hotmail.com wrote:
 On 07/26/11 12:00 AM, Archard Lias wrote:

  Hi,

  Still I dont get how I am supposed to understand the pipe and its task/
  idea/influece on control flow, of:
  returnstatement  |statement
  ??

 It's simply a bitwise OR.

 --
 Ian Collins

Yes, but how does it get determined, which one actually gets returned?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pipe in the return statement

2011-07-25 Thread Billy Mays

On 07/25/2011 10:16 AM, Archard Lias wrote:

On Jul 25, 2:03 pm, Ian Collinsian-n...@hotmail.com  wrote:

On 07/26/11 12:00 AM, Archard Lias wrote:


Hi,



Still I dont get how I am supposed to understand the pipe and its task/
idea/influece on control flow, of:
returnstatement|statement
??


It's simply a bitwise OR.

--
Ian Collins


Yes, but how does it get determined, which one actually gets returned?



The return statement returns a single value from a function context. 
The pipe operator takes 2 values and bitwise ORs* them together.  That 
result is then returned to the caller.  The pipe character in this 
instance is not the same as in a shell.


* This is not exactly true, but don't worry about it.

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


Re: Pipe in the return statement

2011-07-25 Thread Oliver Bestwalter
Hello Archard,

On 25.07.2011, at 16:16, Archard Lias wrote:

 On Jul 25, 2:03 pm, Ian Collins ian-n...@hotmail.com wrote:
 On 07/26/11 12:00 AM, Archard Lias wrote:
 
 Hi,
 
 Still I dont get how I am supposed to understand the pipe and its task/
 idea/influece on control flow, of:
 returnstatement  |statement
 ??
 
 It's simply a bitwise OR.
 
 --
 Ian Collins
 
 Yes, but how does it get determined, which one actually gets returned?

You do a Bitwise OR with numbers. Your statements are both returning numbers 
and those are combined with a bitwise OR. Combining b0001 with b0010 results in 
0011 for example, you can see this very often done in C Code to set and check 
flags. Here is a gentle introduction:

http://www.codeproject.com/KB/tips/Binary_Guide.aspxhttp://www.codeproject.com/KB/tips/Binary_Guide.aspx

Cheers
Oliver

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


Re: Pipe in the return statement

2011-07-25 Thread John Gordon
In 1c175da2-79f4-40ed-803f-217dc935d...@m8g2000yqo.googlegroups.com Archard 
Lias archardl...@googlemail.com writes:

   return statement | statement
 
  It's simply a bitwise OR.

 Yes, but how does it get determined, which one actually gets returned?

Neither value is returned on its own; the bitwise OR of both values is
computed and that value is returned.

It seems that you don't understand what the term bitwise or means.
Perhaps a Google search might help.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

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


Re: Pipe in the return statement

2011-07-25 Thread gwowen
On Jul 25, 3:16 pm, Archard Lias archardl...@googlemail.com wrote:

 Yes, but how does it get determined, which one actually gets returned?


It's a bit-wise or, not a logical or so what get returns is a
combination of the two results.  The n-th bit of the return value is 1
if the n-th bit of either (or both) of the two statements

(Fixed width font)
a 1 1 0 0 0 1 1 1 0 0 1 0 1 ...
b 0 1 0 1 0 0 1 0 0 0 0 1 1 ...
a|b   1 1 0 1 0 1 1 0 0 0 1 1 1 ...
(/Fixed width font)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pipe in the return statement

2011-07-25 Thread Archard Lias
On Jul 25, 4:39 pm, John Gordon gor...@panix.com wrote:
 In 1c175da2-79f4-40ed-803f-217dc935d...@m8g2000yqo.googlegroups.com Archard 
 Lias archardl...@googlemail.com writes:

return statement | statement

   It's simply a bitwise OR.
  Yes, but how does it get determined, which one actually gets returned?

 Neither value is returned on its own; the bitwise OR of both values is
 computed and that value is returned.

 It seems that you don't understand what the term bitwise or means.
 Perhaps a Google search might help.

 --
 John Gordon                   A is for Amy, who fell down the stairs
 gor...@panix.com              B is for Basil, assaulted by bears
                                 -- Edward Gorey, The Gashlycrumb Tinies

It figures, that you are right :P.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pipe in the return statement

2011-07-25 Thread Archard Lias
On Jul 25, 4:35 pm, Oliver Bestwalter oli...@bestwalter.de wrote:
 Hello Archard,

 On 25.07.2011, at 16:16, Archard Lias wrote:









  On Jul 25, 2:03 pm, Ian Collins ian-n...@hotmail.com wrote:
  On 07/26/11 12:00 AM, Archard Lias wrote:

  Hi,

  Still I dont get how I am supposed to understand the pipe and its task/
  idea/influece on control flow, of:
  returnstatement  |statement
  ??

  It's simply a bitwise OR.

  --
  Ian Collins

  Yes, but how does it get determined, which one actually gets returned?

 You do a Bitwise OR with numbers. Your statements are both returning numbers 
 and those are combined with a bitwise OR. Combining b0001 with b0010 results 
 in 0011 for example, you can see this very often done in C Code to set and 
 check flags. Here is a gentle introduction:

 http://www.codeproject.com/KB/tips/Binary_Guide.aspxhttp://www.codepr...

 Cheers
 Oliver

Oh!, never gave it a thought about the fact that what I was looking at
where flags... Thank you very much for the link, is a great
introduction to something I had not known before.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pipe in the return statement

2011-07-25 Thread Archard Lias
On Jul 25, 2:33 pm, Christian Heimes li...@cheimes.de wrote:
 Am 25.07.2011 14:00, schrieb Archard Lias:

  def flags(self, index):
      if not index.isValid():
          return Qt.ItemIsEnabled

      return super(self.__class__, self).flags(index) |

 Your use of super() is incorrect and will not work as you might expect.
 You *must* use the class here, never self.__class__.

 Christian

It would be great if you could elaborate a little more on that. Am I
not supposed to access the parent here?

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


Re: Pipe in the return statement

2011-07-25 Thread Christian Heimes
Am 25.07.2011 17:28, schrieb Archard Lias:
 It would be great if you could elaborate a little more on that. Am I
 not supposed to access the parent here?

You must spell out the parent explicitly, otherwise subclasses call
super() with themselves rather than the correct parent class.
self.__class__ is too dynamic here. Have a look at this example:

class A(object):
def method(self):
pass

class B(A):
def method(self):
super(self.__class__, self).method()

class C(B):
pass

In this example, C().method() results in super(C, self).method()
because self.__class__ is C. However that is wrong because you have to
call super() with the direct parent.

Christian

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


Re: Pipe in the return statement

2011-07-25 Thread Archard Lias
On 25 Jul., 18:11, Christian Heimes li...@cheimes.de wrote:
 Am 25.07.2011 17:28, schrieb Archard Lias:

  It would be great if you could elaborate a little more on that. Am I
  not supposed to access the parent here?

 You must spell out the parent explicitly, otherwise subclasses call
 super() with themselves rather than the correct parent class.
 self.__class__ is too dynamic here. Have a look at this example:

 class A(object):
     def method(self):
         pass

 class B(A):
     def method(self):
         super(self.__class__, self).method()

 class C(B):
     pass

 In this example, C().method() results in super(C, self).method()
 because self.__class__ is C. However that is wrong because you have to
 call super() with the direct parent.

 Christian

Oh! Get it, thanks a lot :P

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


Re: Pipe in the return statement

2011-07-25 Thread Ethan Furman

Billy Mays wrote:

On 07/25/2011 10:16 AM, Archard Lias wrote:

On Jul 25, 2:03 pm, Ian Collinsian-n...@hotmail.com  wrote:

On 07/26/11 12:00 AM, Archard Lias wrote:

Still I dont get how I am supposed to understand the pipe and its task/
idea/influece on control flow, of:
returnstatement|statement
??


It's simply a bitwise OR.


Yes, but how does it get determined, which one actually gets returned?


The return statement returns a single value from a function context. The 
pipe operator takes 2 values and bitwise ORs* them together.  That 
result is then returned to the caller.


Just for completeness, if the actual line had been

return statement1 or statement2

then Python would compute statement1, and if its boolean value was 
True would return the computation of statement1, otherwise it would 
compute statement2 and return that.  When 'or' is used, the first 
truthy* item is return, or the last falsey* item if none evaluate to True.


-- None or 2 or 0
2
-- None or 2 or 3
2
-- None or [] or 0
0

With 'and', the first falsey item is returned, unless all the items are 
  truthy in which case the last item is returned:


-- 2 and 3
3
-- 2 and 0 and 9
0

Hope this helps.

~Ethan~

* 'truthy' = bool(some expression or object) == True
* 'falsey' = bool(some expression or object) == False
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pipe in the return statement

2011-07-25 Thread red floyd
On Jul 25, 5:52 am, TonyO guinness.t...@gmail.com wrote:
  Still I dont get how I am supposed to understand the pipe and its task/
  idea/influece on control flow, of:
  return statement | statement

 In the words of René Magritte,

 return statement | statement
                    ^
 Ceci n'est pas une pipe.

We have a WINNER!!

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