Computer Science Canada

Python running error

Author:  Panphobia [ Thu Nov 15, 2012 8:07 pm ]
Post subject:  Python running error

I started learning python, and as practise I started re-doing all the questions for dwite in python, I ran into a problem with this question http://dwite.org/questions/arablish_numbers.html, here is my code that should work
code:
import sys

sys.stdin = open('DATA1.txt')
sys.stdout = open('OUT1.txt', 'w')

for y in range(0,5):
    temp = ""
    newString=""
    size=[]
    size = input().split()
    for i in range(0,len(size)):
        temp = size[i]
        if temp.isdigit():
            newString = temp +newString
        else:
            for x in range(0,len(temp)):
                newString = temp[x]+newString
    newString+=" "
    print(newString.strip())
               

here is my data1.txt contents
code:
tsetnoc siht ni snoitseuq 5 era ereht
ABC 123 abc123
aosdfi12345akjufd
mama hey mama 123 easy as bca i say
amam lol tahw pu ym reggin

and here is the error
code:
Traceback (most recent call last):
  File "C:\Users\DANIEL\Desktop\Python\de.vogella.python.first1\src\FirstMod.py", line 15, in <module>
    size = input().split()
  File "C:\Users\DANIEL\Desktop\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydev_sitecustomize\sitecustomize.py", line 210, in input
    return eval(raw_input(prompt))
  File "<string>", line 1
    tsetnoc siht ni snoitseuq 5 era ereht
               ^
SyntaxError: invalid syntax

Author:  btiffin [ Fri Nov 16, 2012 1:58 am ]
Post subject:  Re: Python running error

Yeah, see http://docs.python.org/2/library/functions.html#input then see http://docs.python.org/2/library/functions.html#raw_input which skips the evaluator.

Cheers

Author:  Panphobia [ Fri Nov 16, 2012 1:20 pm ]
Post subject:  RE:Python running error

got it, Thanks Very Happy


: