How to pass ref values ​​in Python?

I mainly use the C ++ API for the application, but there are no links to its python access. One variable is passed through ref, for example:

GetPoint ( Point  &p, Object obj )

so how can i translate to python? Is there a pass through the ref character?

+3
source share
5 answers

In Python, there is no transfer character by reference.

Just change the passed point, your changes will be visible from the calling function.

>>> def change(obj):
...     obj.x = 10
...
>>> class Point(object): x,y = 0,0
...
>>> p = Point()
>>> p.x
0
>>> change(p)
>>> p.x
10

...

So, I have to pass this as: GetPoint (p, obj)?

Yes, although Iriimulia has a good moment. Links may have changed the call to return a point, rather than using the out parameter.

+4
source

, Python :

Point GetPoint(Object obj)

:

Point Object::GetPoint()

, .

+3

, Python . , .

+2

Python. , .

+1

python ref - - API. , , - , , ++ python. python, .

, boost.python http://www.boost.org/doc/libs/1_38_0/libs/python/doc/index.html

+1

Source: https://habr.com/ru/post/1703689/


All Articles