1

I want to add with a function log100() to the math module:

def log100(number):
  ans = math.log(number,100)
  return ans

I can't see how I can do it without using "os" module to add directories.

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
  • Just fyi: [you don't need to add your question's topic to the title.](https://meta.stackexchange.com/a/130208/174780) – Pranav Hosangadi Sep 22 '20 at 17:39
  • 1
    Does this answer your question? [How do I extend a python module? Adding new functionality to the \`python-twitter\` package](https://stackoverflow.com/questions/2705964/how-do-i-extend-a-python-module-adding-new-functionality-to-the-python-twitter) – Pranav Hosangadi Sep 22 '20 at 17:40

1 Answers1

2

Although it isn't the best idea -- you risk confusing people who read your code later by messing with standard modules -- you could do something like

math.log100 = lambda x: math.log(x, 100)

or

def log100(x):
    return math.log(x, 100)

math.log100 = log100

, which then can be called as

math.log100(10) # Output 0.5
Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70