Binary or ascii file?

jurgen.defurne at philips.com jurgen.defurne at philips.com
Fri Sep 8 08:25:55 EDT 2000


anders.eriksson at morateknikutveckling.se@SMTP at python.org on 08/09/2000 11:44:54
Sent by:	python-list-admin at python.org
To:	python-list at python.org@SMTP
cc:	 
Subject:	Re: Binary or ascii file?
Classification:	Restricted
On Thu, 07 Sep 2000 17:50:46 GMT, ge at nowhere.none (Grant Edwards)
wrote:

>In article <imefrs4r6svcpk7rsa617ps45u3eepi2hb at 4ax.com>, Anders M Eriksson wrote:
>
>>Working on windows I need to know if the file I'm about to open is
>>binary or ascii.
>
>It's whichever you open it as.  "Binary vs. ASCII" mode is
>determined by the method the program uses to handle the data in
>the file. A file itself isn't either one, it's just a stream of
>bytes.
>

OK, I probably didn't make any sence in my original question ;-)

I'm creating an app that uses FTP to send files. If the ftp-server is
on a unix based computer then it will not work to send Windows ASCII
files as binary (.by not work I mean that it's looks funny reading the
file on the unix system.)

I would like to be able to automaticle select binary or ASCII mode.
Which then means that I need to find out if the file is an ASCII file
or not.

// Anders

--
http://www.python.org/mailman/listinfo/python-list


I presume that is (nearly) impossible. You could check in a file for the sequence \CR\LF, but how will you distinguish
that from an (executable, object, ...) in which the same binary sequence could be an instruction or a piece of data ?
You could try some applied statistics and measure the rate that \CR\LF appears in the file, but statistically you will
sometimes miss. This is bound to happen more for small files than for large files.

Jurgen




More information about the Python-list mailing list