Sean,
You need a keyword argument list as well, so that the effective PyMOL
class instance (_self) can be passed in by keyword (actual use of _self
is only strictly required when you have multiple PyMOLs active in a
single Python interpreter).
# pml input:
python
def my_fn(*arg, **kwd):
print arg
cmd.extend("my_fn", my_fn)
python end
my_fn my_arg_1, my_arg_2
# PyMOL output:
('my_arg_1', 'my_arg_2')
Cheers,
Warren
________________________________
From: Sean Law [mailto:[email protected]]
Sent: Sunday, August 02, 2009 10:56 AM
To: [email protected]
Subject: [PyMOL] Python Function with Unlimited Positional
Arguments
Hi PyMOLers,
I am trying to write a python script that will allow a user to
provide an unlimited number of positional arguments for a function. I
am use to the following scheme for defining a function and its
arguments:
def some_function ( x, y, z, file="false"):
#DO SOMETHING
return
Where x, y, and z are required arguments and "file=false" is an
optional argument. I came across the following page pertaining to
Python:
http://www.linuxtopia.org/online_books/programming_books/python_programm
ing/python_ch15s09.html
See "Unlimited Number of Positional Arguments Values"
There it explains that one could use the following syntax:
def some_function ( *args):
print arg[0]
return
Now, when put this in a script and call the function in PyMOL it
spits out the following error:
Traceback (most recent call last):
File "/pymol/./modules/pymol/parser.py", line 254, in parse
self.result=apply(layer.kw[0],layer.args,layer.kw_args)
TypeError: some_function() got an unexpected keyword argument
'_self'
Is the "*args" method simply not possible in PyMOL? I tried
using "**args" which worked nicely for keyword arguments.
Any help would be greatly appreciated. Thank you for your time.
Sean
________________________________
Stay on top of things, check email from other accounts! Check it
out. <http://go.microsoft.com/?linkid=9671350>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
PyMOL-users mailing list ([email protected])
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/[email protected]