[Python-Dev] a suggestion ... Re: PEP 383 (again)
"Martin v. Löwis"
martin at v.loewis.de
Thu Apr 30 15:04:59 CEST 2009
>> Because in Python, we want to be able to access all files on disk.
>> Neither Java nor Mono are capable of doing that.
>
> Java is not capable of doing that. Mono, as I keep pointing out, is. It
> uses NULLs to escape invalid UNIX filenames. Please see:
>
> http://go-mono.com/docs/index.aspx?link=T%3AMono.Unix.UnixEncoding
>
> "The upshot to all this is that Mono.Unix and Mono.Unix.Native can list,
> access, and open all files on your filesystem, regardless of encoding."
I think this is misleading. With Mono 2.0.1, I get
** (/tmp/a.exe:30553): WARNING **: FindNextFile: Bad encoding for
'/home/martin/work/3k/t/\xff'
Consider using MONO_EXTERNAL_ENCODINGS
when running the program
using System.IO;
class X{
public static void Main(string[] args){
DirectoryInfo di = new DirectoryInfo(".");
foreach(FileInfo fi in di.GetFiles())
System.Console.WriteLine("Next:"+fi.Name);
}
}
On the other hand, when I write
using Mono.Unix;
class X{
public static void Main(string[] args){
UnixDirectoryInfo di = new UnixDirectoryInfo(".");
foreach(UnixFileSystemInfo fi in di.GetFileSystemEntries())
System.Console.WriteLine("Next:"+fi.Name);
}
}
I get indeed all files listed (and can also find out the other
stat results). Of course, the resulting application will be
mono-specific (it links with Mono.Posix), and not work on Microsoft
.NET anymore. IOW, IronPython likely won't use this API.
Python, of course, already has the equivalent of that: os.listdir,
with a byte parameter, will give you access to all files. If
you wanted to closely emulate the Mono API, you could set
the file system encoding to the mono-lookalike codec.
Regards,
Martin
More information about the Python-Dev
mailing list