[IronPython] Writing to a file with unicode name

abdalla ramadan abdollaramadan.dev at gmail.com
Fri Jul 9 10:48:36 PDT 2010


Vernon:

Thank you very much for your reply.
Since the unicode text is not hard coded and is read from file I thought
that writing
line = line[0:-1]
will get rid of the new line character but it seemed I have to write
line = line.replace("\r","").replace("\n","")
now the code works correctly.

Thanks again.

2010/7/9 Vernon Cole <vernondcole at gmail.com>

> Adballa:
>   One problem you may be having is with Python trying to escape the
> backslashes in your Windows file name.  I tried a very simple test using the
> Python "open" statement rather than any fancy .NET things. It created a file
> with a japenese name on my Windows Vista laptop. Note that I used forward
> (/) slashes where Windows users would expect a back (\) slash.
>
> <code>
> out = open(u"c:/temp/青山学院大学相模原キャンパス",'w')
> out.write('testing...\n')
> out.close()
> </code>
>
> The same code works in CPython, too.  If I remove the "u" unicode indicator
> as in
>  ...open("c:/temp...
> then the same code will work in IronPython and Python 3.1, since it is
> unnecessary in IPy and illegal in Python 3.
> --
> Vernon
>
> 2010/7/9 abdalla ramadan <abdollaramadan.dev at gmail.com>
>
>> Hello,
>>
>> I am trying to write to a file with the japanese name 青山学院大学相模原キャンパス
>> The relative path I am passing to the methods is
>> "output\url\c\青山学院大学相模原キャンパス"
>>
>> I used two methods
>> s = StreamWriter(filenamenew, True, Encoding.UTF8)
>> and
>> outputfile = codecs.open(filenamenew, "w",'utf_8_sig')
>>
>> which both throwed the following exception:
>> Unhandled Exception: System.ArgumentException: Illegal characters in path.
>>
>> Thanks very much for advance.
>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>>
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ironpython.com/pipermail/users-ironpython.com/attachments/20100709/939edeca/attachment.htm>


More information about the Users mailing list