By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,548 Members | 1,396 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,548 IT Pros & Developers. It's quick & easy.

Passing items of a lsit as arguments

P: n/a
Hi!

I want to call a function that was defined with *args in the header, e.g.
the Tkinter.Canvas.create_polygon function. I got the coordinates in a
long list but how can I achieve that every item in this list is passed as
a single parameter?

Example:
bla = [(1,2), (3,4), (5,6), ...]
has to become
create_polygon((1,2), (3,4), (5,6), ..., fill=blue)

Thanks in Advance

Bye
Tobias

--
please send any mail to botedesschattens(at)web(dot)de
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 26 Mar 2004, Tobias Pfeiffer <- me@privacy.net wrote:
the Tkinter.Canvas.create_polygon function. I got the coordinates in a
long list but how can I achieve that every item in this list is passed as
a single parameter? Example:
bla = [(1,2), (3,4), (5,6), ...]
has to become
create_polygon((1,2), (3,4), (5,6), ..., fill=blue)


Either:
apply(create_polygon, bla)
or:
create_polygon(* bla)
KP

--
You know you've been sitting in front of your Lisp machine too long
when you go out to the junk food machine and start wondering how to
make it give you the CADR of Item H so you can get that yummie
chocolate cupcake that's stuck behind the disgusting vanilla one.
Jul 18 '05 #2

P: n/a
On Fri, Mar 26, 2004 at 09:31:47PM +0000, Tobias Pfeiffer wrote:
Hi!

I want to call a function that was defined with *args in the header, e.g.
the Tkinter.Canvas.create_polygon function. I got the coordinates in a
long list but how can I achieve that every item in this list is passed as
a single parameter?

Example:
bla = [(1,2), (3,4), (5,6), ...]
has to become
create_polygon((1,2), (3,4), (5,6), ..., fill=blue)


You can call the functions with the arguments you want this way:
create_polygon(*bla + (...,), **{'fill'=blue})

However, Tkinter.Canvas is forgiving in the way it accepts arguments.
For instance, this works just fine:
c.create_polygon([(10, 10), (10, 30), (30, 30), (30, 10)], fill="blue") or even c.create_polygon([40, 40, 60, 40, 60, 60, 40, 60], fill="green")

so just write '...create_polygon(bla, ..., fill=blue)'.

Jeff

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.