| | |
python can't pass arguements from a function to another function?
![]() |
Hi all. I'm working on a python file that will be included in a project I am working on. Unfortunately, I ran into some problems when it came to passing arguments from a function, to another function. Let me explain; I have two functions: dist and return_mouse_angle. dist returns the distance between two points, and return_mouse_angle returns the slope of two points...
for example, when I run
I get this error:
I'm not able to pass mouse_pos[0] and object_pos[1] to the dist function. Is python not able to pass arguments (in this case, a list) from a function to another function?
python Syntax (Toggle Plain Text)
def dist(p1,p2): # a^2 + b^2 = c^2 return math.sqrt( (p2[0]-p1[0])^2+(p2[1]-p1[1])^2 ) def return_mouse_angle(mouse_pos,object_pos): radians = math.asin( dist(mouse_pos,object_pos)/ dist(mouse_pos,[mouse_pos[0],object_pos[1]]) ) degress = math.degrees( radians ) print degrees
for example, when I run
python Syntax (Toggle Plain Text)
return_mouse_slope( [100,100],[154,129])
I get this error:
Python Syntax (Toggle Plain Text)
Traceback (most recent call last): File "<pyshell#59>", line 1, in <module> return_mouse_slope( [100,100],[154,129]) File "C:/Documents and Settings/Owner/Desktop/rewrite project warp/lib/maths.py", line 15, in return_mouse_slope dist(mouse_pos,[mouse_pos[0],object_pos[1]]) ) ValueError: math domain error
I'm not able to pass mouse_pos[0] and object_pos[1] to the dist function. Is python not able to pass arguments (in this case, a list) from a function to another function?
•
•
•
•
I'm not able to pass mouse_pos[0] and object_pos[1] to the dist function. Is python not able to pass arguments (in this case, a list) from a function to another function?Python Syntax (Toggle Plain Text)
Traceback (most recent call last): File "<pyshell#59>", line 1, in <module> return_mouse_slope( [100,100],[154,129]) File "C:/Documents and Settings/Owner/Desktop/rewrite project warp/lib/maths.py", line 15, in return_mouse_slope dist(mouse_pos,[mouse_pos[0],object_pos[1]]) ) ValueError: math domain error
but how do i do that? i tried putting the dist function in return_mouse_angle:
but I still got
python Syntax (Toggle Plain Text)
def return_mouse_slope(mouse_pos,object_pos): p1 = mouse_pos p2 = object_pos p3 = [mouse_pos[0],object_pos[1]] # sin^-1 and distance formula radians = math.asin( math.sqrt( (p2[0]-p1[0])^2+(p2[1]-p1[1])^2 )/ math.sqrt( (p3[0]-p1[0])^2+(p3[1]-p1[1])^2 ) ) degress = math.degrees( radians ) print degrees
but I still got
python Syntax (Toggle Plain Text)
Traceback (most recent call last): File "<pyshell#16>", line 1, in <module> return_mouse_slope([100,100],[50,150]) File "C:\Documents and Settings\Owner\Desktop\rewrite project warp\lib\maths.py", line 18, in return_mouse_slope radians = math.asin( math.sqrt( (p2[0]-p1[0])^2+(p2[1]-p1[1])^2 )/ ValueError: math domain error
![]() |
Similar Threads
- c language problm, how to pass pointer to a function (C)
- Calling the function using function pointer in the perl script. (Perl)
- How to pass reference of a 2-D matrix to a function in C (C)
- Tkinter Button Command (Python)
- Calling c function from python (Python)
Other Threads in the Python Forum
- Previous Thread: HIDE wxMediaCtrl Display Window
- Next Thread: tkFileDialog
| Thread Tools | Search this Thread |
abrupt alarm ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error examples exe file float format function gnu graphics gui halp heads homework http ideas import input java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite statistics string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia write wxpython xlib






