[Tutor] trouble with stringio function in python 3.2

anupama srinivas murthy anupama.2312.bmsit at gmail.com
Mon May 4 09:29:36 CEST 2015


> On May 4, 2015 2:17 AM, "anupama srinivas murthy" <
> anupama.2312.bmsit at gmail.com> wrote:
>
>> Hello,
>>
>> My python code needs to run on versions 2.7 to 3.4. To use stringio
>> function as appropriate, the code i use is;
>>
>> if sys.version < '3':
>>             dictionary = io.StringIO(u"""\n""".join(english_words))
>>         else:
>>             dictionary = io.StringIO("""\n""".join(english_words))
>>
>> The code runs fine on all versions mentioned above except for 3.2 where i
>> get the error:
>> dictionary = io.StringIO(u"""\n""".join(english_words))
>>                                     ^
>> SyntaxError: invalid syntax
>>
>> How can I solve the issue?
>>
>> Thank you
>> Anupama
>>
>>
>


On 4 May 2015 at 12:48, Reuben <reuben.dlink at gmail.com> wrote:

Did you import correct library?


Thank you for asking

Yes. I made a new modification and the code now runs fine on python 3.2 as
well. I replaced;

dictionary = io.StringIO(u"""\n""".join(english_words))

with

dictionary = io.StringIO(unicode('\n').join(english_words))

However, i do not understand why it works fine now


More information about the Tutor mailing list