2

I am trying to call the python function elevation2 (the file is called elevation2.py and the function def elevation2) in the same folder as my current file.

     import numpy as np         
     import elevation2
     def callgoogle(latmin,latmax,samples1, lngmin,lngmax,samples2):
      elev=[]
    if samples1 <= samples2:
        i = 0
        while i<samples1: 
            i = i+1
            w = latmin + i*(latmax-latmin)/samples1 
            if i == 1:
                elev = elevation2(w, lngmin,w,lngmax,samples2)
            else:
                elevo = elevation2(w, lngmin,w,lngmax,samples2)
                elev = np.c_[elev, elevo]                 
    else :
        i=0
        while i<samples2:
            i = i+1
            w = lngmin + i*(lngmax-lngmin)/samples2 
            if i == 1:
                elev = elevation2(latmin, w,latmax,w,samples1)
            else:
                elevo = elevation2(w, lngmin,w,lngmax,samples2)
                elev = np.c_[elev, elevo]     
    return elev

and the error I get is

TypeError: 'module' object is not callable

I wonder what that means?

The code in the elevation2 file is

import json as simplejson
import json
import urllib
import ssl


 ssl._create_default_https_context = ssl._create_unverified_context


def elevation2(lat1, lng1,lat2,lng2,samples):
J.Doe
  • 181
  • 1
  • 8
  • 1
    `import elevation2` means `elevation2` is a module, but you're attempting to call it when you do `elevation2(latmin, w,latmax,w,samples1)`. I think you meant to reference a function inside of that module instead. – Carcigenicate Apr 05 '21 at 13:46
  • this may be relevant https://stackoverflow.com/a/42385016/13273054 – kiranr Apr 05 '21 at 13:48

2 Answers2

0

elevation2 file

class Elevation2:
   ........ your code
   def yourMethod():

end elevation1 file

from Elevation2 import elevation2 

e=Elevation2()
e.yourMethod()

try this

Salim Baskoy
  • 591
  • 5
  • 11
  • putting a class Elevation2: in front of the elevation2 file does not work. I added the code. It says then 'expected an intended block' – J.Doe Apr 05 '21 at 13:57
0

Now that you've added your elevation2 code, the question is possible to answer.

The issue is that elevation2 is a function within the elevation2 module.

Therefore, try calling elevation2.elevation2(...) instead of elevation2(...).

Asker
  • 1,299
  • 2
  • 14
  • 31