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

  • Home
  • SEARCH
  • 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 111359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:22:21+00:00 2026-05-11T02:22:21+00:00

i have a module (a single .py file, actually), with a class called HashedDir.

  • 0

i have a module (a single .py file, actually), with a class called HashedDir.

when i import the file and instanciate 2 instances of that class, when i check the object’s fields they’re always the same, even if the two objects should be different.

Eg:

 h1 = HashedDir('/path/to/dir')  print h1.getList()['files'] # /path/to/dir  h2 = HashedDir('some/other/path')  print h1.getList()['files'] # some/other/path  print h2.getList()['files'] # some/other/path 

Any idea?

This is the class:

from os  import walk from os import path from hashlib import md5 import re  class HashedDir:     '''     A list of files with associated md5 hashes generated retrieving thou     a recursive walk in the directory tree starting from a provided root     directory. Also stores the dirs in each dir     '''      #  {'files': [     #    ('/path/to/file1', '52bc309e11259af15e4623c7a0abc28c'),     #    ('/path/to/file2', '52bc309e11259af15e4623c7a0abc28c'),     #    ('/path/to/dir/file3', '52bc309e11259af15e4623c7a0abc28c')     #   ],     #   'dirs': ['/path/to/dir1', '/path/to/dir2']     #  }     fileList = {'files': [], 'dirs': []}     ignoreList = []      def __init__(self, rootDir, ignoreList=[]):         '''         ignoreList is a list of regular expressions. If a file or a dir matches         that regular expression, don't count it         '''         self.ignoreList = ignoreList          for dirpath, dirnames, filenames in walk(rootDir):             for fileName in filenames:                 completeName = path.join(dirpath,fileName)                 hash = md5(open(completeName).read()).hexdigest()                 relativePath = self._relativePath(completeName, rootDir)                 if not self._toBeIgnored(relativePath):                     self.fileList['files'].append((relativePath, hash))             for dirName in dirnames:                 completeName = path.join(dirpath, dirName)                 relativePath = self._relativePath(completeName, rootDir)                 if not self._toBeIgnored(relativePath):                     self.fileList['dirs'].append(relativePath)      def _relativePath(self, path, base):         return path.replace(base, '')      def _toBeIgnored(self, path):         for regex in self.ignoreList:             if re.compile(regex).search(path) != None:                 return True         return False      def getList(self):         return self.fileList 

Thanks in advance

  • 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. 2026-05-11T02:22:22+00:00Added an answer on May 11, 2026 at 2:22 am

    There are two kinds of variables in a class:

    • class variables, defined at the class level, and common to all instances

    • instance variables, defined within a class method (usually __init__) and qualified by the instance (usually self.).

    Example

    class SomeClass( object ):     classVariable = 0     def __init__( self ):         self.instanceVariable= 0 

    The variable named classVariable is part of the class, common to all instances. Because of the way Python does search, it’s available as a member of self.classVariable, as well as SomeClass.classVariable.

    The variable named instanceVariable is part of the instance (self.) and is unique to each instance.

    Note. There’s a third kind, global, but that’s not what you’re asking about.

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

Sidebar

Ask A Question

Stats

  • Questions 86k
  • Answers 86k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In addition to ashcatch's answer, qmake allows you to query… May 11, 2026 at 5:24 pm
  • Editorial Team
    Editorial Team added an answer The concept of a user's "full" name is OS dependent… May 11, 2026 at 5:24 pm
  • Editorial Team
    Editorial Team added an answer Try ghc -ddump-parsed. May 11, 2026 at 5:24 pm

Related Questions

I'm working on a Python package named lehmer that includes a bunch of extension
I am working on a desktop application in PyGTK and seem to be bumping
I'm a Linux n00b, and I want to install SciPy to help me on
I have a module that I want to keep up to date, and I'm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.