On Tue, 2009-09-29 at 16:16 -0700, rich.al...@gmail.com wrote:
> I have the following I'm trying to optimize.
> 
> Input (from the web) is
> 
> sids = "1,2,3,5"  (a list of ids is posted, say they are article ids)
> 
> Now, to add them to a many to many, I'd like to just
> 
> try:
> authors.articles.add(ids).
> except:
> 
> I know the ids need to be ints, but tried a number of things to get
> them into the proper format but all fail with one exception or another
> 
> ids = map(int, sids.split(','))
> 
> but i konw that:  authors.articles.add(1,2,3,4) works....how do i get
> "1,2,3,4" into 1,2,3,4
> 
> probably a simple python thing or something.
> 
> thanks
> (disregard the need for validation above).

Yep, pretty straightforward:

authors.articles.add(*map(int, sids.split(',')))

See
http://docs.python.org/tutorial/controlflow.html#tut-unpacking-arguments

Cheers

Tom


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to