When you do a file.read (), it reads the entire file into memory. If you do not do a file.close(), data you have read from the file will still stick in the memory.
I suggest you try putting a file.close() after reading the file.
Something like
while(True):
try:
xml_file = xml_file_generator.next()
with open(xml_file, "r") as f:
xml_data = f.read()
soup = BeautifulSoup(xml_data)
tag_list = soup.findAll("tr")
for tag in tag_list:
#Get contents from tag object
#Add content to Mysql
f.close()
Cheers
Thinrhino
--
You received this message because you are subscribed to the Google Groups "Python Pune" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonpune+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On 06-Apr-2014 2:00 AM, "Thin Rhino" <thin...@gmail.com> wrote:
>
> When you do a file.read (), it reads the entire file into memory. If you do not do a file.close(), data you have read from the file will still stick in the memory.
>
> I suggest you try putting a file.close() after reading the file.
>
> Something like
>
> while(True):
> try:
> xml_file = xml_file_generator.next()
> with open(xml_file, "r") as f:
> xml_data = f.read()
> soup = BeautifulSoup(xml_data)
> tag_list = soup.findAll("tr")
> for tag in tag_list:
> #Get contents from tag object
> #Add content to Mysql
> f.close()
>
Using 'with' would ensure that the file is closed unless there's an exception.
--
You received this message because you are subscribed to the Google Groups "Python Pune" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonpune+unsubscribe@googlegroups.com.