Python Forum
How to Print Function Prototype ?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Print Function Prototype ?
#1
i want print function prototype. 

example
def foo(arg, kwarg = "py3.6", os = "Fedora"):
    pass

get_func_prototype(foo)

# output => '(arg, kwarg = "py3.6", os = "Fedora")'
Reply
#2
How does this look? https://docs.python.org/3/library/inspec...getargspec
Reply
#3
Thanks.

sorry. I actually want to how to make same func prototype of other func prototype

example. (This is More important to me. I don't think there is no solution.)

def foo(script, lang = "Python", os = "Fedora"):
    pass

def bar( get_func_prototype(foo) ): # for same prototype with foo
    pass
Reply
#4
That should be doable as well. Could you elaborate more on your use case? Like, are you just trying to wrap a function?
Reply
#5
class myd( dict ):
    def __init__( get_func_prototype(dict.__init__)  ): # for the same prototype because i don't know what dict.__init__ prototype is. and i don't want to rewrite same prototype.
Reply
#6
You're still talking too much implementation rather than goal. Is your goal to generate at runtime a class which shares a signature with a function? Are you trying not to duplicate code at write-time? Or do you just want to support dynamic calls to the class? If you just need to support calls, you don't need to do anything fancy, just use *args and **kwdwargs. Also, is dict important in your example? I can't make sense of it.
Reply
#7
(May-10-2017, 08:10 PM)micseydel Wrote: You're still talking too much implementation rather than goal. Is your goal to generate at runtime a class which shares a signature with a function? Are you trying not to duplicate code at write-time? Or do you just want to support dynamic calls to the class? If you just need to support calls, you don't need to do anything fancy, just use *args and **kwdwargs. Also, is dict important in your example? I can't make sense of it.

sometimes we have to write same prototype many times. why does someone prefer long way rather than short way?

Edit:
Why do I use *args, **kwargs .Is this a right way for all funcs for all owerwriting ?
Reply
#8
I'm not sure what you're writing that you're using the same function signature to the point where you don't want to keep writing it. I can't think of any solution, nor do I see this as a real problem. I don't think the *args or **kwargs will solve your problem (just shift the boiler plate).

I'd still like to see more context for what you're talking about. Like, if what you want those extra parameters for is just logging, then maybe a decorator would help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 315 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  How to print variables in function? samuelbachorik 3 920 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  How to print the output of a defined function bshoushtarian 4 1,323 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  Why does absence of print command outputs quotes in function? Mark17 2 1,395 Jan-04-2022, 07:08 PM
Last Post: ndc85430
  return vs. print in nested function example Mark17 4 1,758 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  output correction using print() function afefDXCTN 3 11,119 Sep-18-2021, 06:57 PM
Last Post: Sky_Mx
  print function output wrong with strings. mposwal 5 3,142 Feb-12-2021, 09:04 AM
Last Post: DPaul
  Output with none, print(x) in function Vidar567 3 2,527 Nov-24-2020, 05:40 PM
Last Post: deanhystad
  print function help percentage and slash (multiple variables) leodavinci1990 3 2,500 Aug-10-2020, 02:51 AM
Last Post: bowlofred
  Invalid syntax on print function DoctorSmiles 2 2,829 Jul-12-2020, 07:39 PM
Last Post: DoctorSmiles

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020