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 8443627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:11:22+00:00 2026-06-10T09:11:22+00:00

I am facing a peculiar problem. I will describe in brief bellow Suppose i

  • 0

I am facing a peculiar problem. I will describe in brief bellow
Suppose i have this piece of code –

class MyClass:

   __postBodies = []
    .
    .
    .
for the_file in os.listdir("/dir/path/to/file"):
      file_path = os.path.join(folder, the_file)
      params = self.__parseFileAsText(str(file_path)) #reads the file and gets some parsed data back
      dictData = {'file':str(file_path), 'body':params}
      self.__postBodies.append(dictData)
      print self.__postBodies
      dictData = None
      params = None

Problem is, when i print the params and the dictData everytime for different files it has different values (the right thing), but as soon as the append occurs, and I print __postBodies a strange thing happens. If there are thee files, suppose A,B,C, then

first time __postBodies has the content = [{‘body’:{A dict with some
data related to file A}, ‘file’:’path/of/A’}]

second time it becomes = [{‘body’:{A dict with some data relaed to
file B}, ‘file’:’path/of/A’}, {‘body’:{A dict with some data relaed to
file B}, ‘file’:’path/of/B’}]

AND third time = [{‘body’:{A dict with some data relaed to file C},
‘file’:’path/of/A’}, {‘body’:{A dict with some data relaed to file C},
‘file’:’path/of/B’}, {‘body’:{A dict with some data relaed to file C},
‘file’:’path/of/C’}]

So, you see the ‘file’ key is working very fine. Just strangely the ‘body’ key is getting overwritten for all the entries with the one last appended.

Am i making any mistake? is there something i have to? Please point me to a direction.

Sorry if I am not very clear.

EDIT ————————

The return from self.__parseFileAsText(str(file_path)) call is a dict that I am inserting as ‘body’ in the dictData.

EDIT2 —————————-

as you asked, this is the code, but i have checked that params = self.__parseFileAsText(str(file_path)) call is returning a diff dict everytime.

def __parseFileAsText(self, fileName):

        i = 0
        tempParam = StaticConfig.PASTE_PARAMS

        tempParam[StaticConfig.KEY_PASTE_PARAM_NAME] = ""
        tempParam[StaticConfig.KEY_PASTE_PARAM_PASTEFORMAT] = "text"
        tempParam[StaticConfig.KEY_PASTE_PARAM_EXPIREDATE] = "N"
        tempParam[StaticConfig.KEY_PASTE_PARAM_PRIVATE] = ""
        tempParam[StaticConfig.KEY_PASTE_PARAM_USER] = ""
        tempParam[StaticConfig.KEY_PASTE_PARAM_DEVKEY] = ""
        tempParam[StaticConfig.KEY_PASTE_FORMAT_PASTECODE] = ""

        for line in fileinput.input([fileName]):
            temp = str(line)
            temp2 = temp.strip()
            if i == 0:              
                postValues = temp2.split("|||")

                if int(postValues[(len(postValues) - 1)]) == 0 or int(postValues[(len(postValues) - 1)]) == 2:
                    tempParam[StaticConfig.KEY_PASTE_PARAM_NAME] = str(postValues[0])

                    if str(postValues[1]) == '':                                        
                        tempParam[StaticConfig.KEY_PASTE_PARAM_PASTEFORMAT] = 'text'
                    else:
                        tempParam[StaticConfig.KEY_PASTE_PARAM_PASTEFORMAT] = postValues[1]

                    if str(postValues[2]) != "N":
                        tempParam[StaticConfig.KEY_PASTE_PARAM_EXPIREDATE] = str(postValues[2])

                    tempParam[StaticConfig.KEY_PASTE_PARAM_PRIVATE] = str(postValues[3])
                    tempParam[StaticConfig.KEY_PASTE_PARAM_USER] = StaticConfig.API_USER_KEY
                    tempParam[StaticConfig.KEY_PASTE_PARAM_DEVKEY] = StaticConfig.API_KEY

                else:
                    tempParam[StaticConfig.KEY_PASTE_PARAM_USER] = StaticConfig.API_USER_KEY
                    tempParam[StaticConfig.KEY_PASTE_PARAM_DEVKEY] = StaticConfig.API_KEY
                i = i+1
            else:
                if tempParam[StaticConfig.KEY_PASTE_FORMAT_PASTECODE] != "" :           
                    tempParam[StaticConfig.KEY_PASTE_FORMAT_PASTECODE] = str(tempParam[StaticConfig.KEY_PASTE_FORMAT_PASTECODE])+"\n"+temp2
                else:
                    tempParam[StaticConfig.KEY_PASTE_FORMAT_PASTECODE] = temp2

        return tempParam
  • 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-06-10T09:11:24+00:00Added an answer on June 10, 2026 at 9:11 am

    You are likely returning the same dictionary with every call to MyClass.__parseFileAsText(), a couple of common ways this might be happening:

    • __parseFileAsText() accepts a mutable default argument (the dict that you eventually return)
    • You modify an attribute of the class or instance and return that instead of creating a new one each time

    Making sure that you are creating a new dictionary on each call to __parseFileAsText() should fix this problem.

    Edit: Based on your updated question with the code for __parseFileAsText(), your issue is that you are reusing the same dictionary on each call:

    tempParam = StaticConfig.PASTE_PARAMS
    ...
    return tempParam
    

    On each call you are modifying StaticConfig.PASTE_PARAMS, and the end result is that all of the body dictionaries in your list are actually references to StaticConfig.PASTE_PARAMS. Depending on what StaticConfig.PASTE_PARAMS is, you should change that top line to one of the following:

    # StaticConfig.PASTE_PARAMS is an empty dict
    tempParam = {}
    
    # All values in StaticConfig.PASTE_PARAMS are immutable
    tempParam = dict(StaticConfig.PASTE_PARAMS)
    

    If any values in StaticConfig.PASTE_PARAMS are mutable, you could use copy.deepcopy but it would be better to populate tempParam with those default values on your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing this peculiar problem in my silverlight app. I have a Canvas that
iam facing problem in passing array to view. this is my controller code.. function
I am facing a peculiar issue in my ADO.NET code. This is the table
Am facing this problem ever since i upgraded to XCODE 4.5. I have various
I´m facing this problem: I have a Button that works like a WrapPanel using
I'm facing a really peculiar problem with my code, I am unable to push
I am facing a peculiar issue in an iPhone program. This is my code
I am facing a peculiar problem. The problem is, my webapp is being installed
Iam facing problem in understanding and converting a matlab code into opencv. I want
i am using toplink as ORM tool, i am facing one peculiar problem. I

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.