python needs leaning stuff from other language

Gary Herron gherron at islandtraining.com
Thu Apr 2 19:29:33 EDT 2009


online.service at ymail.com wrote:
> python's list needs a thing  list.clear()  like c# arraylist
> and
> python needs a writeline() method
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>   

(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.)

Both
    some_list[:] = []
and
    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.

Alternatively
    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
    print(...)
function will get you the functionality (I think) you want.

Gary Herron






More information about the Python-list mailing list