[IronPython] array.fromfile

J. Merrill jvm_cop at spamcop.net
Thu Feb 22 17:19:12 CET 2007

Where did you get the value for the <length> variable?   How large is the file (in bytes)?  What is the encoding of the file?  You might need to read the file into a unicode string (assuming that you need some unicode characters) in order to deal with the file's encoding.

I assume that fromfile's <length> parameter is supposed to be the number of (logical) characters in the file (that is, the number of items to end up in the array).  If the file is encoded with UTF-8, it likely is quite a bit smaller than 2-bytes-per-character; if the program is expecting a two-bytes-per-character file, it would whine unless the file is [at least] 2*length bytes.)  

At 01:15 AM 2/22/2007, JoeSox wrote
>IronPython Team,
>Thanks for the thanks.  The array.cs is a great addition to IronPython.
>I just completed some testing with my ConceptNet C# library, which was
>using its own array.py to get things done.
>Testing with the IP array, I am getting an exception thrown ("file not
>large enough") performing a .fromfile on a unicode file (I think it is
>a unicode. It is a .mdf file from MIT's montylingua).
>I am guessing this is the problem since it is not a str file.  Does
>this sound correct?
>The fileptr and length are the same values being passed (stepping thru
>a Python run and an IronPython run)
>array_ptr = array('L')
>file_ptr        {<open file 'C:\Documents and Settings\Joseph\My
>Projects\conceptnet2.1\montylingua\FASTLEXICON_3.MDF', mode 'rb' at
>0x0337843A>}    object {IronPython.Runtime.PythonFile}
>length  260759  object {int}
>Thanks again,

J. Merrill / Analytical Software Corp

More information about the Ironpython-users mailing list