Re: Python language problem
- From: "ripley" <ripleyfu@xxxxxxxxx>
- Date: 7 Jun 2006 04:37:54 -0700
Laszlo Nagy wrote:
You must undestand that 'a' and 'b' are names. You can only delete
names, not objects. Objects are freed by the garbage collector,
automatically. Probably you used to write programs in C or Pascal or
other languages with pointers. In Python, there are no pointers, just
references and you cannot free an object. You can only delete the
references to it. The good question is: why would you like to free an
object manually? The garbage collector will do it for you automatically,
when the object has no more references. (Well, cyclic references are
also garbage collected but not immediately.)
If you need to handle resources, you can still use the try-finally
statement. Like in:
f = file('example.txt','r')
try:
s = f.read()
finally:
f.close() # The resource is freed. But the object that was used to
access the resource, may not be freed here....
Regards,
Laszlo
Thanks for your so detailed explain, I think I know you, But my Engish
is not enough
to explain.
I create same object in Tree, I want to update Tree, when I need to
delete subtree.
If where no references, I can't do that. some thing like blow:
for i in list:
del i
From that code, I can't update list anymore.
.
- Follow-Ups:
- Re: Python language problem
- From: Diez B. Roggisch
- Re: Python language problem
- References:
- Python language problem
- From: ripleyfu
- Re: Python language problem
- From: Laszlo Nagy
- Python language problem
- Prev by Date: CENSORSHIP - Django Project (Schema Evolution Support)
- Next by Date: Re: Bug in list comprehensions?
- Previous by thread: Re: Python language problem
- Next by thread: Re: Python language problem
- Index(es):
Relevant Pages
|