0

Assume the Python function def my_function() that is part of the class class MyClass(), which itself is part of the module mymodule.py, which is part of the package mypackage.

mypackage/
mypackage/mymodule.py
user$ cat mypackage/mymodule.py
#class MyClass(object):
#     def my_function(self):
#         ...

In a scientific manuscript, I would like to refer to the function my_function in the shortest and most precise way possible and simultaneously provide the info in which package, module and class this function is located.

Hence, would it be advisable to refer to it as: mypackage.mymodule.MyClass.my_function()?

(In comparison, in R it is common to refer to a specific function as myRpackage::my_R_function.)

Michael Gruenstaeudl
  • 1,609
  • 1
  • 17
  • 31
  • 3
    Yes, probably without the `()` – DeepSpace May 11 '16 at 15:37
  • 1
    I actually prefer to have the () because without them, the variable could be any type. – zondo May 11 '16 at 15:43
  • 1
    In the context, do you mention it's a function? Then you can probably leave the `()` off. Note that the official Python documentation does use `()` as part of the name when referring to a function. –  May 11 '16 at 15:45
  • If this manuscript is going to a publisher, you should ask the publisher (or editor, or whoever). If it's for e.g. a thesis, check if the university/institution has a policy. –  May 11 '16 at 15:46
  • @Evert I already communicated with the editor and was asked to "consult with the pertinent style guide for the language in question". Unfortunately, https://www.python.org/dev/peps/pep-0008/ is not clear on how to display such a concatenation. – Michael Gruenstaeudl May 11 '16 at 15:53
  • PEP 8 is about coding, not about documenting a function. It's the latter you're interested in. I'd go with the Python documentation style. For example, the [logging documentation](https://docs.python.org/3/library/logging.html#logging.Logger.debug) refers to `sys.exc_info()`: "otherwise, sys.exc_info() is called to get the exception information." –  May 11 '16 at 15:59
  • Strictly speaking that's a method not a function. You might think that is being pedantic but in Python they have different attributes. See https://docs.python.org/3/library/inspect.html. For what its worth, my vote goes for the `()`. – cdarke May 11 '16 at 16:03

0 Answers0