Bo Peng wrote:
> Is there a better way than doing
>
> try:
>import aModule
> except:
>has_aModule = False
> else:
>has_aModule = True
>
> The main concern here is that loading aModule is unnecessary (and may
> take time).
Yes. Specifically catch ImportError in your except clause.
Bo Peng wrote:
> def GUI():
>if options['cml']:
> cml()
>else:
> if imp.find_module('wx'):
>wxGUI()
> elif imp.find_module('Tkinter'):
>tkGUI()
> else:
>cml()
On the other hand, I don't see how this is superior to an exception-based
approach...
Bo Peng wrote:
> > here's an outline that matches your use case:
> >
> > if user wants command line:
> > command line only
> > else:
> > if wxPython is available:
> > prepare wx based GUI
> > elif Tkinter is available:
> > prepare tk based GU
> if the user happens to prefer the command line interface, why bother looking
> for a GUI ? sounds like you haven't really thought this through...
>
> here's an outline that matches your use case:
>
> if user wants command line:
> command line only
> else:
> if wxPython
Bo Peng wrote:
> > And if you aren't doing the above multiple times, then you *really*
> > shouldn't be worried about the time to load "aModule"
>
> This is used in a scenario like:
>
>if wxPython is available:
> prepare wx based GUI
>elif Tkinter is available:
> prepare tk bas
On Mon, 19 Dec 2005 08:33:18 -0600, Bo Peng wrote:
> This is used in a scenario like:
>
>if wxPython is available:
> prepare wx based GUI
>elif Tkinter is available:
> prepare tk based GUI
>else:
> command line only
>
> Since a user may prefer command line so wxPython/
Peter Hansen wrote:
> Bo Peng wrote:
>
>> Is there a better way than doing
>>
>> try:
>>import aModule
>> except:
>>has_aModule = False
>> else:
>>has_aModule = True
>>
>> The main concern here is that loading aModule is unnecessary (and may
>> take time).
> And if you aren't doing
Bo Peng wrote:
> Is there a better way than doing
>
> try:
>import aModule
> except:
>has_aModule = False
> else:
>has_aModule = True
>
> The main concern here is that loading aModule is unnecessary (and may
> take time).
Loading a module does *not* take time after the first time.
On Mon, 19 Dec 2005 02:52:08 -0600, Bo Peng wrote:
> Dear list,
>
> Is there a better way than doing
>
> try:
>import aModule
> except:
>has_aModule = False
> else:
>has_aModule = True
Do you mean to catch every possible exception when importing aModule?
If you replace "except:" wi
Gerhard Häring wrote:
> Bo Peng wrote:
>
>>Dear list,
>>
>>Is there a better way than doing
>>
>>try:
>> import aModule
>>except:
>> has_aModule = False
>>else:
>> has_aModule = True
>>
>>The main concern here is that loading aModule is unnecessary (and may
>>take time).
>
> No, there is n
Gerhard Häring <[EMAIL PROTECTED]> writes:
> Bo Peng wrote:
>> Dear list,
>> Is there a better way than doing
>> try:
>>import aModule
>> except:
>>has_aModule = False
>> else:
>>has_aModule = True
>> The main concern here is that loading aModule is unnecessary (and
>> may take time).
Bo Peng wrote:
> Dear list,
>
> Is there a better way than doing
>
> try:
>import aModule
> except:
>has_aModule = False
> else:
>has_aModule = True
>
> The main concern here is that loading aModule is unnecessary (and may
> take time).
No, there is not really a better way.
You *c
2005/12/19, Bo Peng <[EMAIL PROTECTED]>:
Dear list,Is there a better way than doingtry: import aModuleexcept: has_aModule = Falseelse: has_aModule = TrueThe main concern here is that loading aModule is unnecessary (and may
take time).If loading aModule is unnecessary, the best way is not load
13 matches
Mail list logo