Turn a tuple into a list of numbers??

This is the place for queries that don't fit in any of the other categories.

Turn a tuple into a list of numbers??

Postby mrotsliah » Thu Mar 27, 2014 4:54 pm

I am working with a class someone else wrote. To define a new object, I need to enter non-negative integers. For example,

Code: Select all
new_object=Class_object.New_Object(1,2,3,4)


There is no limit on the number of integer entries for this new object.

My problems is that I have my non-negative integers stored as tuples (1,2,3,4). I need to somehow turn the tuple into a list of numbers so I can then define a new class object:

Code: Select all
new_object=Class_object.New_Object(change_to_list_of_numbers(1,2,3,4))


Is there a way to do this?

Another question: Would inheritance with object-oriented things help me bypass this little inconvenience? It's open source code in Sage; I just can't call the protected functions.

Thanks
mrotsliah
 
Posts: 4
Joined: Wed Dec 11, 2013 8:49 pm

Re: Turn a tuple into a list of numbers??

Postby micseydel » Thu Mar 27, 2014 8:24 pm

I think you want
Code: Select all
new_object=Class_object.New_Object(*the_tuple)


I don't think you need inheritance to do this, if I understand you correctly.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1391
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Turn a tuple into a list of numbers??

Postby XndrK » Thu Mar 27, 2014 8:31 pm

By the way, the *arguments idiom is called splat arguments, in case you were wondering.
Proverbs 26:14 describes me a bit too well.

Version: Python 2.7.5

https://github.com/4of92000
https://github.com/PythonForum/
User avatar
XndrK
 
Posts: 172
Joined: Sat Jun 15, 2013 7:57 pm

Re: Turn a tuple into a list of numbers??

Postby micseydel » Fri Mar 28, 2014 5:36 pm

The term "splat" seems to be used in Ruby and Perl, but not so much in Python, which calls it unpacking argument lists.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1391
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Turn a tuple into a list of numbers??

Postby mrotsliah » Fri Mar 28, 2014 6:29 pm

Thank you so much. This helps me out a lot.
mrotsliah
 
Posts: 4
Joined: Wed Dec 11, 2013 8:49 pm


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], micseydel and 4 guests