[Python-ideas] Quick idea: defining variables from functions that take the variable name

M.-A. Lemburg mal at egenix.com
Wed Jun 1 11:53:26 EDT 2016


On 01.06.2016 17:17, Sven R. Kunze wrote:
> ...
> I hope that's not the only way to optimize it. :(

Well, if you restrict yourself to functions and objects,
you can implement the assigning from within the code:

Instead of writing:

    x = func('x')

you'd write

    func('x')

and have func register itself with the globals under the given
name:

    def func(bindto):
        value = 'Hello World !'
        globals()[bindto] = value
        return value

    func(bindto='x')

    >>> x
    'Hello World !'

> I am not that deep into CPython development in order to find a better
> solution but I think it should be possible for the compiler to find out
> whether a callee actually USES that information or not without any
> special decoration or something.

I don't see how that could work without being more explicit
about the intention.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Jun 01 2016)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> Python Database Interfaces ...           http://products.egenix.com/
>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
                      http://www.malemburg.com/



More information about the Python-ideas mailing list