[PyQt] PyQt documentation where PyQt function is not same as Qt C++ function

Kyle Altendorf sda at fstab.net
Wed Nov 29 18:51:55 GMT 2017


On 2017-11-28 04:01, J Barchan wrote:
> I now understand why PyQt has to use these "tuple" returns in places.  
> I may not be a fan of the way Python has to do this, but at least I now 
> know what to look for in function declarations (non-const & references) 
> which will make me need to check the signature, instead of it appearing 
> simply "random" to me!

Perhaps your distaste for Python's approach is mostly based on being 
used to something else like C++?

Python passes everything by reference.  Further, every name is a 
reference.  The difference is that some objects are immutable (strings, 
tuples, ints, and more) and so even though the receiving function 
references the original object it would be unable to change it in those 
cases.

Perhaps if you explain why you prefer passing in variables to receive 
the results of multiple return values (as C++ requires) we could help 
you understand better.

   int cplusplusFunc(int anInput, int &secondOutput, int &thirdOutput);

   int first, second, third;
   first = cplusplusFUnc(second, third)

vs.

   def pythonFunc(anInput):
       return 1, anInput + 2, 3

   first, second, third = pythonFunc(42)

Looking at that, do you still feel that the C++ approach is more clear?  
Seems to me that Python nicely distinguishes inputs from output (and 
yes, technically there is a single return value, a tuple, but it is so 
easily packed and unpacked that that fact is not an issue).

This may also be relevant to understanding Python:
   https://nedbatchelder.com/text/names1.html

Cheers,
-kyle


More information about the PyQt mailing list