1

I created a function to read in a csv file and then write some of the data from the csv file into another file. I had to manipulate some of the data in the original csv file before I write it. I will probably have to do that manipulation a lot during the next couple months so I wrote another function to just do that manipulation, but I am having trouble calling in the function in my other function.

this is the function I am trying to call in:

import sys
import math

def convLatLon(measurement): # should be in '##.####' format    
    tpoint=float(measurement)    
    point_deg=math.floor(measurement) # find the degree for lat and lon 
    dpoint=tpoint-point_deg #subtract the lat value from just the degs to get the                   decimal fraction
    pointmin=dpoint * 60 # find the degree mins

    npoint= str(point_deg) + str(pointmin)        
    print(npoint)

How do I call in this function in another function? They are currently in the same directory. I am used to Matlab and thought it would be a simple call in command but I can not seem to figure it out. Any help will be greatly apprectiated.

Shay

1
  • 1
    I think you mean to pass tpoint to math.floor() Commented Aug 3, 2010 at 18:05

4 Answers 4

3

You can import the file (same as you imported sys and math). If your function is in a file called util.py:

import util
util.convLatLon(37.76)

If the file is in another directory, the directory must be in your PYTHONPATH.

Sign up to request clarification or add additional context in comments.

Comments

0

Is:

from <filename> import convLatLon

What you're looking for?

Comments

0

Sounds like you need to import the file.

If your function is defined in file myfile.py and you wan`t to use it from myotherfile.py, you should import myfile.py, like this:

import myfile

and then you can use the function like this:

result = myfile.myfunc(myparms)

If you want to get rid of the myfile prefix, import it like this:

from myfile import myfunc

Comments

0

If you have this function saved in a file called myconv.py

from myconv.py import convLatLon
convLatLon("12.3456")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.