Hello, I have a following module and in its end I want to initalize
collection of tables:
Module:
from sqlalchemy import *
metadata = MetaData()
calendars_table = Table('calendars', metadata,
Column('id', Integer, primary_key=True),
Column('title', Unicode(50)),
Column('color', Unicode(6)),
)
events_table = Table('events', metadata,
Column('id', Integer, primary_key=True),
Column('calendar', Integer, ForeignKey('calendars.id')),
Column('date', Date),
Column('title', Unicode(50)),
Column('description', Unicode(1000)),
Column('color', Unicode(6)),
)
tables_collection = {}
Here I want to get all Table instances of current module and put them
into dictionary by names, but I don't know how I can get all variables
of current module in the end of this module. Please, give me a hint.
--
Best regards, Alex Gusarov 3 5193
On Tue, 21 Oct 2008 11:56:30 +0700, Alex Gusarov wrote:
Here I want to get all Table instances of current module and put them
into dictionary by names, but I don't know how I can get all variables
of current module in the end of this module. Please, give me a hint.
>>import math dir(math)
['__doc__', '__file__', '__name__', 'acos', 'asin', 'atan', 'atan2',
'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod',
'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow',
'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh']
Note that dir() gives you a list of "interesting" names. You can also use
math.__dict__.keys() or the inspect module.
Once you have a key, you can get the actual object you want with getattr:
>>key = 'acos' getattr(math, key)
<built-in function acos>
--
Steven
Alex Gusarov wrote:
Hello, I have a following module and in its end I want to initalize
collection of tables:
Module:
from sqlalchemy import *
metadata = MetaData()
calendars_table = Table('calendars', metadata,
Column('id', Integer, primary_key=True),
Column('title', Unicode(50)),
Column('color', Unicode(6)),
)
events_table = Table('events', metadata,
Column('id', Integer, primary_key=True),
Column('calendar', Integer, ForeignKey('calendars.id')),
Column('date', Date),
Column('title', Unicode(50)),
Column('description', Unicode(1000)),
Column('color', Unicode(6)),
)
tables_collection = {}
Here I want to get all Table instances of current module and put them
into dictionary by names, but I don't know how I can get all variables
of current module in the end of this module. Please, give me a hint.
tables_collection = dict((k, v) for k, v in globals().iteritems()
if isinstance(v, Table))
Alternatively you may consider using metadata.tables. The keys will then
be "calendars" and "events" rather than the variable names.
Peter
Steven, Peter, thanks a lot from a Python newcomer. Problem solved
with you help.
Still, Python community is best I ever met :)
--
Best regards, Alex This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Larry L |
last post by:
I have a Module that declares several arrays as public, some string, some
integers. I then have 2 forms. Form A is the main form, that loads on
start-up, and has a command button to open Form B. On...
|
by: gabor |
last post by:
hi,
as far as i know in python there aren't any private (i mean not accessible
from the outside of the object) methods/fields.
why?
in java/c++ i can make a method private, this way...
|
by: Phil Grimpo |
last post by:
I have a very odd situation here. I have an administration page, where
based on a users permissions, a recordset is called from the SQL server
which has a list of paths to "Module Menus". Each of...
|
by: Ross A. Finlayson |
last post by:
Hi,
I'm scratching together an Access database. The development box is
Office 95, the deployment box Office 2003.
So anyways I am griping about forms and global variables. Say for
example...
|
by: Michael |
last post by:
Hi newsgroup,
as the subject indicates I am looking for an advice
using global variables. I am not if this problem is more
about style then C. If its wrong in thi group, sorry.
So I have a...
| |
by: Floris van Haaster |
last post by:
Hi All!
I have a question, i have a web application and I store some member
information in a variable i declared in a module like:
Public some_info_variable as string
in module1.vb
But...
|
by: Burton Samograd |
last post by:
Hi,
I'm writing an app that stores some user configuration variables in a
file ~/.program/config, which it then imports like so:
import sys
from posix import environ...
|
by: CDMAPoster |
last post by:
About a year ago there was a thread about the use of global variables
in A97:
http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157
Best Practices by Kang...
|
by: rshepard |
last post by:
I'm stymied by what should be a simple Python task: accessing the value of
a variable assigned in one module from within a second module. I wonder if
someone here can help clarify my thinking. I've...
|
by: Gary Herron |
last post by:
Jacob Davis wrote:
Yuck, YUCK, YUCK! You are breaking *so* many
good-programming-practices, I hardly know where to start.
First off: A python global is not what you think. There are *no*...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |