Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 569211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:16:15+00:00 2026-05-13T13:16:15+00:00

Question: How do I kill an instantiation or insure i’m creating a new instantiation

  • 0

Question: How do I kill an instantiation or insure i’m creating a new instantiation of the python universal feedparser?


Info:

I’m working on a program right now that downloads and catalogs large numbers of blogs. It has worked well so for except for an unfortunate bug. My code is set up to take a list of blog urls and run them through a for loop. each run it picks a url and sends it down to a separate class which manages the downloading, extracting, and saving of the data to a file.

The first url works just fine. It downloads the entirety of the blog and saves it to a file. But the second blog it downloads will have all the data from the first one as well, I’m totally clueless as to why.


Code snippets:

class BlogHarvester:
  def __init__(self,folder):
    f = open(folder,'r')
    stop = folder[len(folder)-1]
    while stop != '/':
        folder = folder[0:len(folder)-1]
        stop = folder[len(folder)-1]
    blogs = []
    for line in f:
        blogs.append(line)

    for herf in blogs:
        blog = BlogParser(herf)
        sPath = ""
        uid = newguid()##returns random hash.
        sPath = uid
        sPath = sPath + " - " + blog.posts[0].author[1:5] + ".blog"
        print sPath
        blog.storeAsFile(sPath)

class BlogParser:
  def __init__(self, blogherf='null', path='null', posts = []):
    self.blogherf = blogherf

    self.blog = feedparser.parse(blogherf)
    self.path = path
    self.posts = posts
    if blogherf != 'null':
        self.makeList()
    elif path != 'null':
        self.loadFromFile()

class BlogPeices:
  def __init__(self,title,author,post,date,publisher,rights,comments):
    self.author = author
    self.title = title
    self.post = post
    self.date = date
    self.publisher = publisher
    self.rights = rights
    self.comments = comments

I included snippets I figured that would probably be useful. Sorry if there are any confusing artifacts. This program has been a pain in the butt.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:16:16+00:00Added an answer on May 13, 2026 at 1:16 pm

    As what Ignacio said, any mutations that happen to the default arguments in the function list will stay for the life of the class.

    From http://docs.python.org/reference/compound_stmts.html#function-definitions

    Default parameter values are evaluated
    when the function definition is
    executed. This means that the
    expression is evaluated once, when the
    function is defined, and that that
    same “pre-computed” value is used for
    each call. This is especially
    important to understand when a default
    parameter is a mutable object, such as
    a list or a dictionary: if the
    function modifies the object (e.g. by
    appending an item to a list), the
    default value is in effect modified.
    This is generally not what was
    intended. A way around this is to use
    None as the default, and explicitly
    test for it in the body of the
    function.

    But this brings up sort of a gotcha, you are modifying a reference… So you may be modifying a list that the consumer of the class that wasn’t expected to be modified:

    For example:

    class A:
      def foo(self, x = [] ):
        x.append(1)
        self.x = x
    
    a = A()
    a.foo()
    print a.x
    # prints: [1]
    a.foo()
    print a.x
    # prints: [1,1]   # !!!! Consumer would expect this to be [1]
    y = [1,2,3]
    a.foo(y)
    print a.x
    # prints: [1, 2, 3, 1]
    print y
    # prints: [1, 2, 3, 1]  #  !!!! My list was modified
    

    If you were to copy it instead: (See http://docs.python.org/library/copy.html )

    import copy
    class A:
      def foo(self, x = [] ):
        x = copy.copy(x)
        x.append(1)
        self.x = x
    
    a = A()
    a.foo()
    print a.x
    # prints: [1]
    a.foo()
    print a.x
    # prints: [1]   # !!! Much better =)
    y = [1,2,3]
    a.foo(y)
    print a.x
    # prints: [1, 2, 3, 1]
    print y
    # prints: [1, 2, 3]  #  !!!! My list is how I made it
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question: How can I determine all processes in the child's Process Tree to kill
The question is special because some keys, such as CTRL+Z, stopped working. I tried
Edited Question : I am working on a multithreaded JMS receiver and publisher code
You may think this question is stupid or something but as a new IT
Possible Duplicate: Is there any way to kill a Thread in Python? So this
(there is a follow up to this question here ) I am working on
Question as stated in the title.
Question is pretty self explanitory. I want to do a simple find and replace,
Question Alright, I'm confused by all the buzzwords and press release bingo going on.
Question in the title. And what happens when all 3 of $_GET[foo] , $_POST[foo]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.