Re: language war

Поиск
Список
Период
Сортировка
От Jay O'Connor
Тема Re: language war
Дата
Msg-id 3FCCC19B.7080802@cybermesa.com
обсуждение исходный текст
Ответ на language war  (Jonathan Bartlett <johnnyb@eskimo.com>)
Ответы Re: language war
Список pgsql-general
 >>My favorite feature is the fact that I can include
 > >arbitrary files, using a line of code:
 > >include "$next_file.php";

 >Dynamically importing modules based on variables like you show above is
 >certainly possible in Python.

Here's an elaborate example:  I have two modules (A.py and B.py) that
both define the function test().  My main driver prompts the user for
input and based on the input will import the module and call test() in
the imported module, which will print either "module A" or "module B"
depending on what was imported, or an error message if the input didn't
matcha  module.  This illustrates a complete example, but you can
simplify it really to "mymodule = __import__ (next_file)" where
next_file is a variable name

====================
--A.py
def test ():
        print "module A"


--B.py
def test ():
        print "module B"
--dynamicimport.py
print "Test Dynamic Import"

request = raw_input ("enter 'a' or 'b'")
modName = request.upper()
mod = None

try:
    mod = __import__(modName)
except:
    print "unable to import %s" % modName

if mod:
    mod.test()
else:
    print "Sorry, no appropriate module"
====================


В списке pgsql-general по дате отправления:

Предыдущее
От: "Jay O'Connor"
Дата:
Сообщение: Re: language war
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: how many quotes?