File holes in Linux

2010-09-29 Thread Tom Potts
Hi, all.  I'm not sure if this is a bug report, a feature request or what,
so I'm posting it here first to see what people make of it.  I was copying
over a large number of files using shutil, and I noticed that the final
files were taking up a lot more space than the originals; a bit more
investigation showed that files with a positive nominal filesize which
originally took up 0 blocks were now taking up the full amount.  It seems
that Python does not write back file holes as it should; here is a simple
program to illustrate:
  data = '\0' * 100
  file = open('filehole.test', 'wb')
  file.write(data)
  file.close()
A quick `ls -sl filehole.test' will show that the created file actually
takes up about 980k, rather than the 0 bytes expected.

If anyone can let me know if this is indeed a bug or feature request, how to
get around it, or where to take it next, I'd really appreciate it.

Thanks a lot,
Tom
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: if the else short form

2010-09-29 Thread Tom Potts
This is just a sneaky shorthand, which is fine if that's what you want, but
it makes it harder to read.  The reason it works is that 'fill==True' is a
boolean expression, which evaluates to True or False, but if you force a
True into being an integer, it will be 1, and a False will become 0.  Try
writing 'True == 1' on the Python interpreter to see what I mean.  So this
code snippet is creating a tuple with two elements, and then selecting the
first if 'fill==True' is False, or 0, and selecting the second if
'fill==True' is True, or 1.

As I say, this kind of coding is absolutely fine, but it makes things harder
to read and doesn't really save much space.  I wouldn't recommend using this
kind of style yourself, at least until you're more familiar with programming
in Python.

Tom

On 29 September 2010 11:42, Tracubik  wrote:

> Hi all,
> I'm studying PyGTK tutorial and i've found this strange form:
>
> button = gtk.Button(("False,", "True,")[fill==True])
>
> the label of button is True if fill==True, is False otherwise.
>
> i have googled for this form but i haven't found nothing, so can any of
> you pass me any reference/link to this particular if/then/else form?
>
> thanks
> Nico
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list