> I wrote a little script (pythonify.py) to be run between SWIG
> compilation and the install, which removes the extra "comedi_"
> bits. So now the commands would be:
>
> import comedi
> dev = comedi.open ('/dev/comedi0')
Ooh, nice :). This had always bugged me, but not enough to do
anything about it ;).
However, I ran into this:
$ python pythonify.py
Traceback (most recent call last):
File "pythonify.py", line 24, in <module>
comedi_new.write( "{1} = _comedi.{0}_{1}\n".format( match.group(1),
AttributeError: 'str' object has no attribute 'format'
$ python --version
Python 2.5.2
From
http://docs.python.org/library/stdtypes.html
str.format is new in Python 2.6.
Work around with this patch on your pythonify.py:
--- pythonify.py-orig 2009-07-05 11:09:05.000000000 -0400
+++ pythonify.py 2009-07-05 11:11:21.000000000 -0400
@@ -21,8 +21,14 @@
comedi_new.write( line )
match = pattern.search( line )
if match is not None and 'swig' not in match.group( 0 ):
- comedi_new.write( "{1} = _comedi.{0}_{1}\n".format( match.group(1),
- match.group(2) ) )
+ try:
+ new_string = "{1} = _comedi.{0}_{1}\n".format( match.group(1),
+ match.group(2) )
+ except AttributeError: # for compatability with python < 2.6
+ new_string = "%s = _comedi.%s_%s\n" % ( match.group(2),
+ match.group(1),
+ match.group(2) )
+ comedi_new.write(new_string)
comedi_new.close()
comedi_py.close()
> I don't know how to speak Makefile, so I'm not sure how to integrate
> it into the existing codebase. At the moment, if you're running 'make'
> in the swig/python directory, you can run 'make && python pythonify.py
> && sudo make install' and it works perfectly. Presumably there's some
> easy way to set up an installation hook to make it run as part of the
> make process.
All you need to change in swig/python/Makefile.am is:
--- Makefile.am-orig 2009-07-05 10:34:34.000000000 -0400
+++ Makefile.am 2009-07-05 10:35:40.000000000 -0400
@@ -14,8 +14,7 @@
pyexec_SCRIPTS = comedi.py
-EXTRA_DIST = README.txt setup.py test_comedi.py
+EXTRA_DIST = README.txt setup.py test_comedi.py pythonify.py
comedi_python_wrap.c comedi.py: $(srcdir)/../comedi.i
$(SWIG) -python -o comedi_python_wrap.c -I$(top_srcdir)/include $(srcdir)/../comedi.i
+ python pythonify.py
For other comedi-python people out there, I've written some python
wrappers to make digitial and analog IO simpler for my lab. I'm not
sure how well the simultaneous analog IO will transfer onto non
NI-DAQ-STC-based cards, but feel free to take a look:
http://www.physics.drexel.edu/~wking/rsrch/code/#pycomedi
Cheers,
Trevor/labrat
--
This email may be signed or encrypted with GPG (http://www.gnupg.org).
The GPG signature (if present) will be attached as 'signature.asc'.
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy
My public key is at http://www.physics.drexel.edu/~wking/pubkey.txt
Sounds good! Can your script be placed under the LGPL so it can be
incorporated into the Comedilib CVS repository?
> I don't know how to speak Makefile, so I'm not sure how to integrate
> it into the existing codebase. At the moment, if you're running 'make'
> in the swig/python directory, you can run 'make && python pythonify.py
> && sudo make install' and it works perfectly. Presumably there's some
> easy way to set up an installation hook to make it run as part of the
> make process.
>
> Hopefully somebody can put in a little effort to make this available
> to the whole community; otherwise, I hope it's at least useful to a
> few individuals out there. I will upload pythonify.py to the "Files"
> section of this discussion group.
It looks like Trevor/labrat is on the case there.
--
-=( Ian Abbott @ MEV Ltd. E-mail: <abb...@mev.co.uk> )=-
-=( Tel: +44 (0)161 477 1898 FAX: +44 (0)161 718 3587 )=-