I had always assumed that a file would leak if it was opened without being closed, but I just verified that if I enter the following lines of code, the file will close:
>>> f = open('somefile.txt')
>>> del f
Just out of sheer curiosity, how does this work? I notice that file doesn't include a __del__ method.
...
link text
I got the concept of reference count
So when i do a "del astrd" ,reference count drops to zero and astrd gets collected by gc ?
This is the sample codes.These codes I developed after my yesterday's question:link text
one.py:
def abc():
print "Hello"
print "123"
print '345'
two.py:
import one
#reload(one)
#def defg():
...
Trying to run this file in eclipse
class Try:
def __init__(self):
pass
def __del__(self):
print 1
a=Try()
raw_input('waiting to finish')
and pressing the stop button without letting the program finish doesn't print "1", i.e the del method is never called. If i try to run the script from the shell and do ctrl-c\sys....
Hello,
I am new to python and have been working through the examples in Swaroop CH's "A Byte of Python". I am seeing some behavior with the __del__ method that is puzzling me.
Basically, if I run the following script (in Python 2.6.2)
class Person4:
'''Represents a person'''
population = 0
def __init__(self, name):
...
Hello,
class A:
def __get(self):
return self._x
def __set(self, y):
self._x = y
def __delete_x(self):
print('DELETING')
del self._x
x = property(__get,__set,__delete_x)
b = A()
# Here, when b is deleted, i'd like b.x to be deleted, i.e __delete_x()
# called (and for immediate consequence, "DELETING" printed)
del b
Tha...
Hi,
I have one problem let assume A and B are 2 view controller from A user push to B view controller,In B user starts some download by creating object C(which is NSObject class) and sets B as delegate to C(assign),now user want go back to A then dealloc of B calls object releases, C delegate fails to give call back(crashes).I want to ...
When making use of del in a Python function, I'm getting false positives from PyFlakes telling me that the variable is undefined.
def foo(bar):
# what if it's ham? eww
if bar == 'ham':
del bar
return
# otherwise yummy!
print bar
The above function will return the following error:
C:\temp\test.py:7: und...