Author Topic: alias for function  (Read 1466 times)

Glauco

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
alias for function
« on: October 28, 2011, 09:08:27 AM »
Hi all, I'm using pyxll for extend excel with a lot of functions that i want to organize like excel "style".

Mi idea is to organize them using "." as a separator  ( like excel ).

For example:
=CUBE.SLICE()
=CUBE.LAYER()

=CHART.LINE()
=CHART.FANCHART()
=CHART.DOUBLEHIST()

Actually this is not possible because "." is not usable as function name in python.

How about an otional parameter in xl_funct like "alias"

pyxll.xl_func(....., alias="CHART.LINE")


Thank you
Glauco

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 584
  • Karma: +14/-1
    • View Profile
Re: alias for function
« Reply #1 on: November 01, 2011, 08:34:59 AM »
Hi Glauco,

yes that sounds like a nice idea. I'll have a look at that in a future version.

the xl_func decorator uses the 'func_name' property of the function so you could try changing that before applying the decorator and that should work, e.g.

def test():
    pass

test.func_name = "a.b"
test = xl_func(...)(test)

or with another decorator:

def rename(name):
    def rename_decorator(func):
        func.func_name = name
        return func
    return rename_decorator

@xl_func(...)
@rename("a.b")
def test():
   pass

I'm afraid I've not tried the above code, but I think it should work. Let me know how you get on.

Best regards,
Tony

Glauco

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: alias for function
« Reply #2 on: November 11, 2011, 09:19:26 AM »
Yezz!
It work, probably this is enough for my purpose, but i think this must be described in documentation.


Well done Tony
Thank you
Glauco

phrrngtn

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: alias for function
« Reply #3 on: August 14, 2015, 08:50:57 PM »
there is a now a 'name' parameter for xl_func in PyXLL 2.3.0 (2015-06-25)