Greetings ...

 Thanks Tim for your reply ...

>>   This post is a little off topic, but I believe with-in scope of
>> python and how pywin32 is used, if anybody is offended by this post,
>> just delete it ... ;-)
>
> Looks pretty much on-topic to me. At any rate, I'll bite...
 Mmm, I am asking for advice and any info can only help ...

>>   I'm currently write a util that is meant to sync Contacts with a
>> database, which can be found at ...
>> http://code.google.com/p/pycontactsync/ ... Please don't laugh at the
>> code, I'm still a very junior  python programmer and still working
>> through some of the basic OO ideas.
>
> I've pulled the current subversion trunk to look at. There appears to
> be only one directory: tests with a set of non-package subdirectories
> (ie without an __init__.py). This is just so you know what I'm referring
> to.
 Yes, the test folder is mainly going to be tests of each sub-system
or module, by themselves ... One, so that I can figure how this all
works and two, hoping other people might be able to pick up and use
the good bits ...

I'm not sure what " __init__.py" is or how that all works, as I said
still putting this all together and trying to find what works best and
how this all makes sense ...

> One very initial comment is that you're repeating the adoconstants.py
> in two different "packages" (not sure if they're meant to be packages
> or not). This is something of a code smell, but I assume that this is
> not your final structure so...
? Code smell? I'm not sure what you mean by this ... The access and
mysql folder, that have adoconstants.py in, is the beginning of my
tests or little programs that store data in access/mysql ... This was
copied and modified until it worked from
http://www.mayukhbose.com/python/ado/index.php ... If the code below
is better or faster, then I will rather use it then.

> A second point is that the ado constants can (probably) be pulled
> automatically when you dispatch the adodb connection:
>
> <code>
> import win32com.client
> constants = win32com.client.constants
>
> ado = win32com.client.gencache.EnsureDispatch ("ADODB.Connection")
> #
> # At this point, win32com.client.constants will contain a classalike
> # with a bunch of ad_... constants
> #
> print constants.adLongVarChar
> print constants.adMarshallAll
>
> </code>
I just cut and pasted the above example and I did get the following error ...

>>>
201
Traceback (most recent call last):
  File "C:\src\pyDBSync\subsystems\test\adCon.py", line 10, in <module>
    print constants.adMarshallAll
  File "C:\Python26\lib\site-packages\win32com\client\__init__.py",
line 170, in __getattr__
    raise AttributeError(a)
AttributeError: adMarshallAll
>>>

Did I miss type something or am I just a plank ... ;-)

>>   Looking to map the attribs in the Contacts, into a nice to read and
>> easy to use array of sorts ... Currently I'm writing alot of code and
>> looking plenty of things up ... I was reading into
>> lists/tuples/dictionaries, but can't come up with code that works or
>> makes sense.  Was thinking of multi-dimensional array, but I'm really
>> lost.
>
> It may be that my last answer solved part at least of your issues. However,
> you've got several options here, depending on exactly how you want to
> use things (and personal preference, of course). If all you want is a
> nice mapping to-and-from constant and constant name just use a dictionary,
> or two dictionaries:
>
> double_dict = {}
> double_dict['const1'] = 1
> double_dict[1] = 'const1'
>
> or
>
> dict1 = {}
> dict2 = {}
> dict1['const1'] = 1
> dict2[1] = 'const1'
>
> Obviously these fall down pretty quick when you've got the same value for 
> different
> names -- which will obviously happen. So you have to invent your own 
> namespaces
> (say, a list of dicts or a dict of dicts) at the risk of reinventing Python 
> :).
>
> Your example above talks of tracking a description and maybe other things. Two
> or three close choices here, depending on how you expect things to work:
>
> Dict of tuples:
>
> <code>
> stuff = [
>   ('adDouble', constants.adDouble, 'A double-width whatever in ad'),
>   ('adPropRequired', constants.adPropRequired, 'A property is required'),
> ]
> data_dictionary = dict ((s[0], s) for s in stuff)
> </code>
>
> This will give you a dictionary keyed by name with the value being the tuple.
> This works adequately for fixed-length tuples but doesn't scale. You could
> throw in the recently-added namedtuple for better effect, but it still 
> outgrows
> itself soonish.
>
>
> Classes:
>
> <code>
> class Stuff (object):
>   def __init__ (self, name, value, description):
>     self.name = name
>     self.value = value
>     self.description = description
>
> stuff = [
>   ('adDouble', constants.adDouble, 'A double-width whatever in ad'),
>   ('adPropRequired', constants.adPropRequired, 'A property is required'),
> ]
> data_dictionary = dict ((s[0], Stuff (*s)) for s in stuff)
>
> </code>
>
> This is a very slightly more scalable version of the last one. The class I've
> defined is very Noddy but it could be extended if that were required.
>
> You could do the same kind of thing with dictionaries, which is a sort of
> halfway house. (The class I've sketched above is little more than a dict
> in disguise).
>
> Hopefully that's food for thought. Do come back with clearer requirements of
> questions
Huh? That is some deep stuff ... Sorry, I don't understand much of
what you getting at here ... I really would like to make sure this
works as quick as possible, but I am at a lose here ...

Let me try and give and example of data and how it would be nice to
work it out ...

This is currently just the WAB interface, each contact has elements,
listed as they have be captured.

I was thinking of using a for loop, must like I do wab-dump.py

for oItem in oContU.Elements:
        oItemNum += 1
        print "Contact Name ", oItem.Name, " Number ", oItemNum, " ID
", oItem.Id
        print "Number of Elements", oItem.Properties.Count
        for oContP in oItem.Properties:
            print "Element ID 0x%08x Element Value %s " % (oContP.Id,
oContP.Value)

Contact Name  Andre E C  Number  2  ID  A4000000
Number of Elements 20
Element ID 0x0ffe0003 Element Value 6
Element ID 0x0fff0102 Element Value A4000000
Element ID 0x3001001f Element Value Andre E C
Element ID 0x3002001f Element Value SMTP
Element ID 0x3003001f Element Value l...@example.org
Element ID 0x3004001f Element Value This is a note.
Element ID 0x30080040 Element Value 04/10/10 23:16:55
Element ID 0x300b0102 Element Value 534D54503A4C454554404C45454E582E4F524700
Element ID 0x3a06001f Element Value Andre E
Element ID 0x3a11001f Element Value C
Element ID 0x3a17001f Element Value IT Tech
Element ID 0x3a1c001f Element Value +27834073090
Element ID 0x3a45001f Element Value Mr
Element ID 0x3a4d0002 Element Value 2
Element ID 0x3a50001f Element Value http://www.example.org
Element ID 0x3a51001f Element Value http://mail.google.com
Element ID 0x3a54101f Element Value (u'SMTP', u'SMTP')
Element ID 0x3a550003 Element Value 0
Element ID 0x3a56101f Element Value (u'l...@example.org',
u'clintonlee.tay...@gmail.com')
Element ID 0x3a710003 Element Value 0

Now if I could use an array so that I could print the Display Label,
map the attrib to a field name, instead of if/elif as follows ...

                      if colnum == 1:
                            ModifyContact(objSession, rownum +
NumberOfContacts, constants.wabPR_NICKNAME, col)
                        elif colnum == 2:
                            ModifyContact(objSession, rownum +
NumberOfContacts, constants.wabPR_EMAIL_ADDRESS, col)
                        elif colnum == 3:
                            ModifyContact(objSession, rownum +
NumberOfContacts, constants.wabPR_HOME_TELEPHONE_NUMBER, col)
                        elif colnum == 4:
                            ModifyContact(objSession, rownum +
NumberOfContacts, constants.wabPR_HOME_FAX_NUMBER, col)
                        elif colnum == 5:
                            ModifyContact(objSession, rownum +
NumberOfContacts, constants.wabPR_CELLULAR_TELEPHONE_NUMBER, col)
                        elif colnum == 6:
                            ModifyContact(objSession, rownum +
NumberOfContacts, constants.wabPR_HOME_FAX_NUMBER, col)
                        elif colnum == 7:
                            ModifyContact(objSession, rownum +
NumberOfContacts, constants.wabPR_BUSINESS_TELEPHONE_NUMBER, col)
                        elif colnum == 8:
                            ModifyContact(objSession, rownum +
NumberOfContacts, constants.wabPR_COMPANY_NAME, col)
                        elif colnum == 9:
                            ModifyContact(objSession, rownum +
NumberOfContacts, constants.wabPR_TITLE, col)


I was wondering if there is a way to print or list all the constants
in a com library, like http://wabaccess.sourceforge.net/Schema.htm

Or if there is a way to get to all the constants like
http://msdn.microsoft.com/en-us/library/ms879904.aspx, but I think
that is in an SDK or something ... Would be better if we could just
pull this info out of the system, instead of manually capturing,
removing human error and updates that might happen and have these
constants change.

I hope this make sense ... Seems a little dis-jointed ...

Thanks
Mailed
LeeT
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to