[Tutor] read_help
Rick Pasotto
rick@niof.net
Sun, 18 Nov 2001 18:12:13 -0500
On Sun, Nov 18, 2001 at 05:45:38PM -0500, Karshi wrote:
>
> Hi all,
>
> I have a question about the "read()" method. For example, if I wanna
> read the file which has size=200bytes. I want to read only 100bytes
> by skipping 2 bytes. How do I do it in Python?
>
> ---In Matlab it will look like this:
> ---file=fopen(somefile, 'rb')
> ---read=fread(file, 100, 2)
>>> f = open('filename','rb')
>>> f.seek(2)
>>> data = f.read(100)
If you're on unix you don't need the 'rb'.
--
When under the pretext of fraternity, the legal code imposes
mutual sacrifices on the citizens, human nature is not thereby
abrogated. Everyone will then direct his efforts toward
contributing little to, and taking much from, the common fund of
sacrifices. Now, is it the most unfortunate who gains from this
struggle? Certainly not, but rather the most influential and
calculating.
-- Frédéric Bastiat (1801-1850)
Rick Pasotto rickp@telocity.com http://www.niof.net