python needs leaning stuff from other language

Gary Herron gherron at
Fri Apr 3 01:29:33 CEST 2009

online.service at wrote:
> python's list needs a thing  list.clear()  like c# arraylist
> and
> python needs a writeline() method
> --

(While you are correct that Python needs these things, a better 
attitude, as a newbie, would be to *ask* how Python supplies these 
features you want, because in fact, they have been included in the 
language for a very long time.)

    some_list[:] = []
    del some_list[:]
will clear the contents of a list, but will leave the identity of the 
list unchanged. 

That is
    A = [1,2,3]
    B = A
    del A[:]
will leave both A and B referencing the same empty list.

    A = [1,2,3]
    B = A
    A = []
will leave A referencing a new empty list,
but B will reference the original [1,2,3] list.

As for a writeline(), and guessing what it is you want, I'd say look at the
    print>>outfile, ...
form in Python 2.5.  In Python 3.X, the
function will get you the functionality (I think) you want.

Gary Herron

More information about the Python-list mailing list