Re: [Tutor] Importing classes

2017-01-11 Thread Alan Gauld via Tutor
On 11/01/17 02:53, kay Cee wrote: > Is there a proper way to import a class from a module? If so, please tell. The most common way is probably: >>> from mymodule import Myclass >>> myobject = Myclass() but its just as good to do >>> import mymodule >>> myobject = mymodule.Myclass() -- Al

[Tutor] Importing classes

2017-01-11 Thread kay Cee
Is there a proper way to import a class from a module? If so, please tell. Thank You, Unee0x ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Alexandre Conrad
2011/5/30 Marilyn Davis : > If we are coding via a vote, I'd be with Alan. > > If Timo adds non-parser modules, and they get through his glob filter, > then surely his code will break with a nice error statement and that would > remind him of his convention. Sure. From my point of view, I prefer a

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Steven D'Aprano
Timo wrote: Hello all, I have a question about how this is done the best way. In my project I have a folder with multiple file parsers, like this: - src -- main.py -- parsers --- __init__.py --- parser1.py --- parser2.py This gives you a stand-alone module called "main.py", and a sepa

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Marilyn Davis
If we are coding via a vote, I'd be with Alan. If Timo adds non-parser modules, and they get through his glob filter, then surely his code will break with a nice error statement and that would remind him of his convention. Or maybe it would just give a verbose report and go on to the next file.

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Alan Gauld
"Alexandre Conrad" wrote Why not use the os functions to read the file names dynamically and build the list that way? Provided the files use a standard naming scheme you don't need to change the init code. I wouldn't do that. If Timo adds non-parser modules in that directory (say some util

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Alexandre Conrad
2011/5/30 Alexandre Conrad : > selected_parser = "parser1" > parser = parsers[selected_parser] > parser = Parser() > ... I meant to have a capital P on the second line of course: selected_parser = "parser1" Parser = parsers[selected_parser] parser = Parser() or just (less readable though): pars

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Alexandre Conrad
2011/5/30 Alan Gauld : > But this means having to maintain the list in init.py. > Why not use the os functions to read the file names > dynamically and build the list that way? Provided > the files use a standard naming scheme you don't > need to change the init code. I wouldn't do that. If Timo a

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Alexandre Conrad
2011/5/30 Timo : > When the user clicks a button, I want to show all available parsers and use > the choosen one when the user clicks "ok". > Is it ok to place the following code in the __init__.py? > from parser1 import Parser1 > from parser2 import Parser2 > def get_parsers(): >    return [Parser

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Peter Otten
Timo wrote: > Hello all, > > I have a question about how this is done the best way. > > In my project I have a folder with multiple file parsers, like this: > - src > -- main.py > -- parsers >--- __init__.py >--- parser1.py >--- parser2.py > > The parsers just contain a class wh

Re: [Tutor] Importing classes when needed

2011-05-30 Thread Alan Gauld
"Timo" wrote When the user clicks a button, I want to show all available parsers and use the choosen one when the user clicks "ok". Is it ok to place the following code in the __init__.py? from parser1 import Parser1 from parser2 import Parser2 def get_parsers(): return [Parser1(), Parser

[Tutor] Importing classes when needed

2011-05-30 Thread Timo
Hello all, I have a question about how this is done the best way. In my project I have a folder with multiple file parsers, like this: - src -- main.py -- parsers --- __init__.py --- parser1.py --- parser2.py The parsers just contain a class which do the work. When the user clicks a bu