I have a module (a single .py file, in fact) with a class named HashedDir.
When I import a file and I install 2 instances of that class, when I check the field of the object, they are always the same, even if the two objects are different.
Example:
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 ideas?
This is the class:
from Hasiylti import MD5 import ray class OS HashedDir running OS import import path: "" "Related MD5 One of the files hash The list stores dirs in each dir "#" '#' 'files' in addition to the recursive walks in the tree starting from the root directory of a. Directory: [# (' / path / / file1 ',' 52bc309e11259af15e4623c7a0abc28c '), # (' / path / / 'to 2,' 52bc309e11259af15e4623c7a0abc28c '), # (' / path / / dir / file3 ',' 52bc309e11259af15e4623c7a0abc2 for 8c ') #], #' dirs': ['/ path / to / dir1', '/ path / to dir2'] #} fileList = {'files': [],' dirs': [] } ignoreList = [] def __init __ (self, rootDir, ignoreList = []): "" "ignore list is a list of regular expressions. a file or a directory that matches the regular expression, do not count it" "" self.ignoreList = ignoreList dirpath, dirnames, walk away (rootDir) for file names for the file name in the file name: completeName = path.join (dirpath, filename) hash = md5 (open (completeName ) .read ()) hexdigest () relativePath = self._relativePath (fullName, r OotDir) if not self._toBeIgnored (relativePath): .. self.fileList [ 'files'] engage ((relativePath, hash)) in dirnames for dirname: completeName = path.join (dirpath, dirname) relativePath = self._relativePath (completeName, rootDir) does not self._toBeIgnored, then (RelativePath) :. Self.fileList ['dirs'] Attached (relativePath) Def _relativePath (self, path, base): Return path. Location (base, '') def _to beagle (self, path): for regex in self.ignoreList: if recompile (regex). Search (path)! = None: return right return false def getlist (self): back self File
Thanks in advance
Variables are:
Example variable, a class method
__init __
) and is eligible by example (usually Self.
).
Example
class is a class (object): Clasviriybl = 0 Diaf __int __ (self): Self.instanceVariable = 0
Named variables self.classVariable
Available, as well as SomeClass.classVariable
.
is a part of the named variable example
example ( Self.
) and is unique for each example.
Note. The third type is global, but it is not what you are asking.
Comments
Post a Comment