Re: Question: "load"ing a shared object in python
On Jan 28, 2005, at 6:48 AM, Rick L. Ratzel wrote: Pro Grammer <[EMAIL PROTECTED]> writes: Hello, all, I am not sure if this is the right place to ask, but could you kindly tell me how to "load" a shared object (like libx.so) into python, so that the methods in the .so can be used? That too, given that the shared object was written in c++, compiled with g++ ? Thanks, Pro Grammer Will the dl standard library module help you? From the Python docs at: http://docs.python.org/lib/module-dl.html As Simon Brunning notes, ctypes (<http://starship.python.net/crew/theller/ctypes/>) is a robust alternative to the `dl' module. Example: import dl, time a=dl.open('/lib/libc.so.6') a.call('time'), time.time() (929723914, 929723914.498) A note about this example: the `dl' call returns an integer as that is what the C time function returns. time.time() in Python is implemented in terms of C's gettimeofday, ftime or time depending on the platform. I'm guessing that there might be some C++ issues, but maybe it's worth looking into. As far as I am aware, neither dl nor ctypes natively support C++. This is a tricky matter, due to the lack of standards for C++ ABI's covering name mangling and vtable layout etc. See the thread starting at <http://mail.python.org/pipermail/python-list/2004-November/ 249513.html> for more information. Regards, Mark Rowe <http://bdash.net.nz/> -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting the --options of configure on installed python
On 25/07/2005, at 09:56 , Thanos Tsouanas wrote: > Hello! > > Is there a way to get the --options with which python was > configured on > a system? > > Thanks in advance. Hi Thanos, Take a look at the distutils.sysconfig module (): >>> import distutils.sysconfig >>> distutils.sysconfig.get_config_var('CONFIG_ARGS') "'--prefix=/opt/local' '--enable-shared' '--mandir=/opt/local/share/ man' '--bindir=/opt/local/bin' '--with-readline' '--enable-framework' '--enable-ipv6' '--enable-tk'" >>> Kind Regards, Mark Rowe <http://bdash.net.nz/> -- http://mail.python.org/mailman/listinfo/python-list
Re: msnp, friends list
On Feb 18, 2005, at 7:31 AM, jr wrote: I'm currently using the msnp.py code from Manish Jethani's project. I havn't been able to get the friends list to update like it should. it works once out of about every 25 times the program loads. Has anyone been able to implement his code and get the friends list to actively update? Or have any suggestions? I just spent a few minutes experimenting, and it seems that the following code does what you would like: import msnp import time class MsnListener(msnp.SessionCallbacks): def friend_list_updated(self, friend_list): print 'Got friend list update:', friend_list.lists msn = msnp.Session(MsnListener()) msn.login('[EMAIL PROTECTED]', 'xxx') msn.sync_friend_list() while True: msn.process() time.sleep(1) Any info would be great. Thanks. Hope this helps, Mark Rowe <http://bdash.net.nz/> -- http://mail.python.org/mailman/listinfo/python-list
Re: msnp, friends list
On Feb 18, 2005, at 11:35 AM, jr wrote: Sorry, I guess what I meant to ask was the status of the friends in the friends list begin updated. Right now we have a friends list which is being populated with the correct users, but their status (online, offline) is never getting set. For some reason the events aren't being fired?? Ok, I've seen this problem before. Basically, the MSN servers do not send state changes for your buddies if you change your status from offline -> online before you have retrieved your entire buddy list. There doesn't appear to be a way around that with msnp as it always changes your state after sign-in, and it fails to group the buddy list state into a single transaction so that you can tell when the entire list has been retrieved... It should be relatively simple to adapt the code to fix the problem. Regards, Mark Rowe <http://bdash.net.nz/> -- http://mail.python.org/mailman/listinfo/python-list
Re: How to write python plug-ins for your own python program?
On Mar 3, 2005, at 9:33 PM, Simon Wittber wrote: You mean like 'import'? :) That's how I would do it. It's the simplest thing, that works. exec("import %s as plugin" % pluginName) plugin.someMethod() where pluginName is the name of the python file, minus the ".py" extension. A better method would be something along the lines of: plugin = __import__(pluginName) plugin.someMethod() This avoids the potential security problem that `exec' poses as well as the need to parse + interpret the string. Regards, Mark Rowe <http://bdash.net.nz/> -- http://mail.python.org/mailman/listinfo/python-list
Re: Version Number Comparison Function
On Mar 26, 2005, at 3:34 AM, Keith wrote: Is there a function for comparing version numbers? E.g. 0.1.0 < 0.1.2 1.876b < 1.876c 3.2.2 < 3.4 FWIW, >>> from distutils import version >>> version_list = "3.4 3.2.2 1.867c 1.867b 0.1.2 0.1.0".split() >>> version_list = map(version.LooseVersion, version_list) >>> version_list.sort() >>> print version_list [LooseVersion ('0.1.0'), LooseVersion ('0.1.2'), LooseVersion ('1.867b'), LooseVersion ('1.867c'), LooseVersion ('3.2.2'), LooseVersion ('3.4')] >>> print ' < '.join(map(str, version_list)) 0.1.0 < 0.1.2 < 1.867b < 1.867c < 3.2.2 < 3.4 >>> It should be noted that distutils.version provides a StrictVersion class that offers less flexible but more predictable ordering -- see the module docstrings for more details. Regards, Mark Rowe <http://bdash.net.nz/> -- http://mail.python.org/mailman/listinfo/python-list