I need advice. I'm writing a calculator; I've got the basic functionality of it down, and have finally moved to having it process functions. In this regard, I find the standard library of mathematical functions provided by Python unsatisfactory. While the more commonly used functions are defined, some of the more obscure functions lack proper mention. Examples of this include the arc hyperbolic cotangent, arc hyperbolic cosecant, hyperbolic cosecant, secant, etc. While some of these are just manipulations of the functions provided, it seems the better alternative would be to provide our definitions and refer the program to those when it encounters them. This is where my question lies. Should I just define these functions in the main script, or should I use a separate file? If I the latter, how do I make reference to the separate file? I am relatively new to Python, so if I'm missing a common technique or something, please do let me know. Thanks in advance.

You could first install the numpy and scipy modules which contain many special functions.

To answer tour second question, you want to write a separate module containing your own special functions. For example write a mymathfuncs.py file containing

# mymathfuncs.py
import numpy

def arccoth(z):
    """Arc hyperbolic cotangent"""
    return numpy.arctanh(1.0/z)

Then store this file in the same directory as your main program, or store it in a directory on your python path and write this in your main program

from mymathfuncs import arccoth
# etc

Also read the part of the python tutorial about modules http://docs.python.org/tutorial/modules.html

Edited 4 Years Ago by Gribouillis: n/a

Small example showing your current level could be usefull to give you correct advice. What books, tutorials have you learned? You have experimented with example code in Python interpreter to really learn the things, have you not? What you think of the code in the code snippet section of Python forum?

You could first install the numpy and scipy modules which contain many special functions.

To answer tour second question, you want to write a separate module containing your own special functions. For example write a mymathfuncs.py file containing

# mymathfuncs.py
import numpy

def arccoth(z):
    """Arc hyperbolic cotangent"""
    return numpy.arctanh(1.0/z)

Then store this file in the same directory as your main program, or store it in a directory on your python path and write this in your main program

from mymathfuncs import arccoth
# etc

Also read the part of the python tutorial about modules http://docs.python.org/tutorial/modules.html

Thanks Gribouillis

Small example showing your current level could be usefull to give you correct advice. What books, tutorials have you learned? You have experimented with example code in Python interpreter to really learn the things, have you not? What you think of the code in the code snippet section of Python forum?

thanks pyTony

This article has been dead for over six months. Start a new discussion instead.