converting infix to prefix in python
<p>I am trying to write an Infix to Prefix Converter where e.g. I would like to convert this:</p>

<pre><code>1 + ((C + A ) * (B - F))
</code></pre>

<p>to something like:</p>

<pre><code>add(1, multiply(add(C, A), subtract(B, F)))
</code></pre>

<p>but I get this instead :</p>

<pre><code>multiply(add(1, add(C, A), subtract(B, F)))
</code></pre>

<p>This is the code I have so far</p>

<pre><code>postfix = []
temp = []
newTemp = []

def textOperator(s):
    if s is '+':
        return 'add('
    elif s is '-':
        return 'subtract('
    elif s is '*':
        return 'multiply('
    else:
        return ""

def typeof(s):
    if s is '(':
        return leftparentheses
    elif s is ')':
        return rightparentheses
    elif s is '+' or s is '-' or s is '*' or s is '%' or s is '/':
        return operator
    elif s is ' ':
        return empty    
    else :
        return operand                          

infix = "1 + ((C + A ) * (B - F))"

for i in infix :
    type = typeof(i)
    if type is operand:
        newTemp.append(i)
    elif type is operator:
        postfix.append(textOperator(i))
        postfix.append(newTemp.pop())
        postfix.append(', ')
    elif type is leftparentheses :
        newTemp.append(i)
    elif type is rightparentheses :
        next = newTemp.pop()
        while next is not '(':
            postfix.append(next)
            next = newTemp.pop()
            postfix.append(')')
            newTemp.append(''.join(postfix))
            while len(postfix) &gt; 0 :
                postfix.pop()
    elif type is empty:
        continue
    print("newTemp = ", newTemp)
    print("postfix = ", postfix)

while len(newTemp) &gt; 0 :
    postfix.append(newTemp.pop())
postfix.append(')')

print(''.join(postfix)) 
</code></pre>

<p>Can someone please help me figure out how I would fix this. </p>