I have a class that helps import a particular type of file, and is a 'factory' class Which allows me to do this, uses factory class generator in batch so that the customer can be repeated through importers. My question is, do I use iterator properly? Is this acceptable? I have just started using Python.
class FileParser: "Batch Importer": def __init __ (self, files) uses an open file handle to "stuff": self.files = files Def porters ): For the file itself: Try: FH = Open (File, "RB") Parser = FilePaste (FH) yield Parser Finally: FH. Batch Importer (Filelist) for P in Define Definitions (DIF Cleansing (--- Importer = Batch Importerates): P. Smith 1 () ...
This is a method for you that is a generator, absolutely fine. I recommend making all my classes neat-style ( If you are on Python 2, either __MetaCLASS_ = at the beginning of your module, or (object) all your base-less class Add to the tetayment), because the heritage classes are "evil" ;-); And, for clarity and brevity, I repeat the generator differently as coding ...:
Def Parser (self): To file in self: files: FH as the open (Eiffel, "RB"): The output fileper (FH) But from these bits of advice The use of generator methods in any form is not condemned! -)
F Note Ail instead of using afile . : There is an underlying identifier later, and as a general rule, it is better to use no to hide the underlying identifiers with itself (it does not cut you here, but it does not cut here In the future, by many bad ways you will not come in the right habit!
Comments
Post a Comment