In Python, how can I make a function accept a sequence of variables embedded in a string?
<p>In Python:</p>

<pre><code>a = "l[0], l[1], l[2], l[3]"
# l[0] etc. have their own value

my_function(a) #doesn't work


#but this does work
my_function(l[0], l[1], l[2], l[3])
</code></pre>

<p>Can the string a be 'transformed' so that the function sees the variables?
Thank you.</p>

<p>Later update: Thank you for answering my question.
I am including the bigger problem and why I had to resort to the eval function (not desired according to your answers).
The function:</p>

<pre><code>class Line(object):
def __init__(self, pt1, pt2, *pt):
    pt1 = Point(pt1[0],pt1[1])
    pt2 = Point(pt2[0],pt2[1])
    self.vertices = [pt1, pt2]
    for i in pt:
        self.vertices.append(Point(i[0],i[1]))

def __getitem__(self, key):
    pt = self.vertices[key]
    p = Point(p[0],p[1])
    return p

#Here is the part with the issue:

def move(self, dx, dy):
    pts = len(self.vertices)
    l = self.vertices

    pt1 = Point(Point(l[0].x, l[0].y).move(dx, dy).x, Point(l[0].x, l[0].y).move(dx, dy).y)
    pt2 = Point(Point(l[1].x, l[1].y).move(dx, dy).x, Point(l[1].x, l[1].y).move(dx, dy).y)
    if pts == 2:
        mv = LineString(p1, p2)
    if pts &gt; 2:
        bla = ''
        for i in [2,pts]:
            px = Point(l[i].x, l[i].y).move(dx, dy).x
            py = Point(l[i].x, l[i].y).move(dx, dy).y
            l[i] = Point(px,py)
            bla += 'l[' + str(i) + '], '
            arguments = bla[:-2]
            mv = LineString(pt1, pt2, *eval(arguments))
    return mv
</code></pre>

<p>According to your answers, there are better ways of solving this..</p>
