Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Jonnty
Aug 2, 2007

The enemy has become a flaming star!

tehk posted:

Is there a popular extension framework for python? Something like MEF/MonoAddins/JPF/Boost-Extension.

Currently I am using my own plug-in manager(__import__+ a lot of fluff), but I would much rather use something else if a good plug-in framework exist. This is mostly because I want to have extension information(author, version, and title info) files stored along side the module and I do not want to write a parser. Currently I am storing that information in the module and hoping that plugs keep their modifications inside the activate and deactivate methods.

What's wrong with just storing all that metadata in a dictionary?

Adbot
ADBOT LOVES YOU

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

tehk posted:

Is there a popular extension framework for python? Something like MEF/MonoAddins/JPF/Boost-Extension.

Currently I am using my own plug-in manager(__import__+ a lot of fluff), but I would much rather use something else if a good plug-in framework exist. This is mostly because I want to have extension information(author, version, and title info) files stored along side the module and I do not want to write a parser. Currently I am storing that information in the module and hoping that plugs keep their modifications inside the activate and deactivate methods.

A dictionary in the module would do fine. Also, metaclasses and plugin systems are made for each other, just in case you had not looked into them.

tehk
Mar 10, 2006

[-4] Flaw: Heart Broken - Tehk is extremely lonely. The Gay Empire's ultimate weapon finds it hard to have time for love.

deimos posted:

A dictionary in the module would do fine. Also, metaclasses and plugin systems are made for each other, just in case you had not looked into them.

The issue with that is I need to import the plug-in to get the dictionary, which brings me back to square one so it is not much different then what I am currently doing. Plugs could do bad things in whilst I am just importing them to get the metadata. I want to have that data available before I import the module. Most other projects which have python extensions use this approach as well.

I just remembered the configparser module which should solve my problems for now. However, I would still like to know if any of the frameworks out there are any good.

edit: vvv That is true I can't, but I would also prefer if a module was not loaded unless it was enabled for performance issues.

Err also if the plug-in is enabled then I do not care so much about it doing 'bad things'. I just don't want them doing them when the user is under the impression that they are disabled.

tehk fucked around with this message at 17:34 on May 27, 2010

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

tehk posted:

The issue with that is I need to import the plug-in to get the dictionary, which brings me back to square one so it is not much different then what I am currently doing. Plugs could do bad things in whilst I am just importing them to get the metadata. I want to have that data available before I import the module. Most other projects which have python extensions use this approach as well.

I just remembered the configparser module which should solve my problems for now. However, I would still like to know if any of the frameworks out there are any good.

Any problem with just doing something like __import__("plugin", fromlist=["metadata"])

e: whoops, yes, ignore me. But if you can't trust your plugins not to do 'bad things' in the main body, how can you trust them not to do 'bad things' in the correct methods?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



What's a good module for writing a parser in? I found this old blogpost which lists too many to test out and try individually: http://nedbatchelder.com/text/python-parsers.html

I basically have a structured text-format that I'll need to turn into Python objects. Each line is a record, and the lines following can be sub-records or new records themselves.

bitprophet
Jul 22, 2004
Taco Defender

Carthag posted:

What's a good module for writing a parser in? I found this old blogpost which lists too many to test out and try individually: http://nedbatchelder.com/text/python-parsers.html

I basically have a structured text-format that I'll need to turn into Python objects. Each line is a record, and the lines following can be sub-records or new records themselves.

The answer to this is usually, in order, PyParsing and then PLY. (Meaning, try PyParsing, if that doesn't seem like it can do it or you don't like it, then try PLY.)

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



bitprophet posted:

The answer to this is usually, in order, PyParsing and then PLY. (Meaning, try PyParsing, if that doesn't seem like it can do it or you don't like it, then try PLY.)

Thanks I'll check them out :)

Threep
Apr 1, 2006

It's kind of a long story.
What's a good way to strip out XML tags but not their content? I'm trying to convert Tomboy/Gnote notes to another format (iPhone notes.db) and I need to remove the tags from the text itself.

I can do it with regexes of course, but that seems so crude and volatile. lxml has strip_tags, but it's broken in the version in the Ubuntu repos.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Threep posted:

lxml has strip_tags, but it's broken in the version in the Ubuntu repos.

Then get a different version?

Threep
Apr 1, 2006

It's kind of a long story.

Avenging Dentist posted:

Then get a different version?
Would prefer a solution that works on Ubuntu without messing with custom packages (pip is also way out of date) since it would make support a pain otherwise.

I figured it was a common task and there'd be an easy solution.

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.

Threep posted:

Would prefer a solution that works on Ubuntu without messing with custom packages (pip is also way out of date) since it would make support a pain otherwise.

I figured it was a common task and there'd be an easy solution.

u''.join(your_lxml_etree.xpath('//text()'))

Benji the Blade
Jun 22, 2004
Plate of shrimp.
It's been a long time since I've worked with XML in any non-trivial way, but it sounds like it'd be pretty trivial to do with XSLT, and I believe lxml can process XSLT. The bonus here is that XSLT might be able to do a decent amount of the processing for you.

The downside is that you'd be writing XSLT code, though. And just to work around a bug in a library in Ubuntu.

Threep
Apr 1, 2006

It's kind of a long story.

Habnabit posted:

u''.join(your_lxml_etree.xpath('//text()'))
Fantastic, thanks.

ninjawtf
Mar 23, 2006
type fast for me
Is there any "easy" way to work with videos in Python? I'm trying to do some editing work on YouTube videos (watermarks, replace sections) and cant find a good library to do this. Pymedia doesn't support FLVs and even then the process is converting the whole vid to imgs and then putting it back together. Seems like there should be an easier way... Anyone know of one?

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

ninjawtf posted:

Is there any "easy" way to work with videos in Python? I'm trying to do some editing work on YouTube videos (watermarks, replace sections) and cant find a good library to do this. Pymedia doesn't support FLVs and even then the process is converting the whole vid to imgs and then putting it back together. Seems like there should be an easier way... Anyone know of one?

It looks like PyMedia hasn't been updated since 2006, which would explain why it doesn't support FLV. Check out pyffmpeg which is a Python wrapper for the ffmpeg libavcodec and libavformat libraries (which underpin VLC and ffdshow among others). It doesn't look very complete, but it looks like it can decode video frames and I assume you could manage the rest from there.

Also, if you're using Windows, you might want to consider Avisynth as an alternative to Python for this job. Avisynth is a scripting language specifically designed for manipulating video files. You could probably accomplish what you want with just a few lines of Avisynth code.

Farrok
May 29, 2006

So I've been using python for a while to do mostly scientific computing. It's been quite handy due to its increased flexibility over matlab and I've been able to make some pretty decent GUI so other people can utilize my code with minimal training, and its been great to work with basically just a text editor and the terminal on OSX.

However, I now have a need to use an external SDK. Specifically, I need to be able to write a program that will use Canon's "EDSDK" in order to remotely control and gather data from a camera. I have no idea at all how this works. The OSX version of the EDSDK I downloaded seems to have no actual method files. Instead it comes as a 'framework', which seems to mean its usable with XCode and I suppose written in Objective-C. Is it possible to access such a thing with Python? Would I be better off downloading their Windows version of the EDSDK which I think consists of .dll files. I have no more experience with those than I do with 'frameworks' but at least I've seen them in the directories of other programs.

The main thing is that I'd like to use the Python files I've already generated in an app that will control this camera. Is this possible?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Farrok posted:

The main thing is that I'd like to use the Python files I've already generated in an app that will control this camera. Is this possible?

You can do it (perhaps not well) with ctypes, which will let you talk with C and C-like libraries. There's also this but I don't know what the difference between EDSDK and CDSDK is: http://pypi.python.org/pypi/pycanon/0.9

Cpt.Wacky
Apr 17, 2005

Avenging Dentist posted:

You can do it (perhaps not well) with ctypes, which will let you talk with C and C-like libraries. There's also this but I don't know what the difference between EDSDK and CDSDK is: http://pypi.python.org/pypi/pycanon/0.9

Another option might be using gPhoto to control the camera. Either write your own bindings/wrapper or use the subprocess module to call the gphoto utility.

Yakattak
Dec 17, 2009

I am Grumpypuss
>:3

I'm looking for a module that allows me to connect to a MySQL database. I've tried pymysql but it's bugged, so you can't SELECT more than one row (which sucks). Anyone have any good modules they wish to share?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Yakattak posted:

I'm looking for a module that allows me to connect to a MySQL database. I've tried pymysql but it's bugged, so you can't SELECT more than one row (which sucks). Anyone have any good modules they wish to share?

The standard answer is mysqldb. I've been needing something in pure python, so I've been using MySQL Connector/Python.

MaberMK
Feb 1, 2008

BFFs

Thermopyle posted:

The standard answer is mysqldb. I've been needing something in pure python, so I've been using MySQL Connector/Python.

If you're only working with a handful of tables, then that works. Otherwise, use SQLAlchemy.

Farrok
May 29, 2006

Avenging Dentist posted:

You can do it (perhaps not well) with ctypes, which will let you talk with C and C-like libraries. There's also this but I don't know what the difference between EDSDK and CDSDK is: http://pypi.python.org/pypi/pycanon/0.9

I had seen that, but unfortunately the difference in the two SDKs lies in which cameras are supported. Mine is not supported by CDSDK =/.

Cpt.Wacky posted:

Another option might be using gPhoto to control the camera. Either write your own bindings/wrapper or use the subprocess module to call the gphoto utility.

Tried this, too, but I don't know what to do with the error I'm getting. Running gphoto2 --auto-detect and it finds my camera. However, it can't seem to actually access it. Every time I try a command that actually tries to get through the usb connection to the camera returns the following error: Error (-53: 'Could not claim the USB device'). This appears to have a been a bug in previous versions specific to a linux kernel and I can't find any info about fixing it in OSX. Without being able to use lsusb in the terminal, I don't know how to approach debugging the issue as suggested from those folks that found it in linux. I thought maybe it was as simple as requiring root access, but sudo doesn't help either.

Yakattak
Dec 17, 2009

I am Grumpypuss
>:3

Thermopyle posted:

The standard answer is mysqldb. I've been needing something in pure python, so I've been using MySQL Connector/Python.

:psyduck:

When I do setup.py install, it keeps saying:
code:
error: package directory 'mysql' does not exist
And it's clearly in there, anyone else encounter this problem with the latest rev?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Yakattak posted:

:psyduck:

When I do setup.py install, it keeps saying:
code:
error: package directory 'mysql' does not exist
And it's clearly in there, anyone else encounter this problem with the latest rev?

I don't know the answer in any case, but you should probably specify which of the two packages I mentioned you're trying.

Yakattak
Dec 17, 2009

I am Grumpypuss
>:3

Thermopyle posted:

I don't know the answer in any case, but you should probably specify which of the two packages I mentioned you're trying.

MySQL Connector/Python, I tried both the zip and tar (I knew if one didn't work, the other wouldn't but I thought I'd try).

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.

Yakattak posted:

I'm looking for a module that allows me to connect to a MySQL database. I've tried pymysql but it's bugged, so you can't SELECT more than one row (which sucks). Anyone have any good modules they wish to share?

oursql is pretty much the best thing that's out there right now. The top of that link has a whole list of reasons why you should use it over mysqldb.

myconnpy is a bit of a mess. I've been considering rewriting it from scratch with support for twisted.

Stabby McDamage
Dec 11, 2005

Doctor Rope

Farrok posted:

I had seen that, but unfortunately the difference in the two SDKs lies in which cameras are supported. Mine is not supported by CDSDK =/.


Tried this, too, but I don't know what to do with the error I'm getting. Running gphoto2 --auto-detect and it finds my camera. However, it can't seem to actually access it. Every time I try a command that actually tries to get through the usb connection to the camera returns the following error: Error (-53: 'Could not claim the USB device'). This appears to have a been a bug in previous versions specific to a linux kernel and I can't find any info about fixing it in OSX. Without being able to use lsusb in the terminal, I don't know how to approach debugging the issue as suggested from those folks that found it in linux. I thought maybe it was as simple as requiring root access, but sudo doesn't help either.

Is there anything using the camera, either directly or in the background? That error sounds to me like it might mean "device in use".

king_kilr
May 25, 2007

MaberMK posted:

If you're only working with a handful of tables, then that works. Otherwise, use SQLAlchemy.

SQLAlchemy is totally distinct from a driver. SQLAlchemy is a framework/toolkit/whatever, it *uses* MySQLDb (and most other PEP249 compliant drivers).

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Habnabit posted:

oursql is pretty much the best thing that's out there right now. The top of that link has a whole list of reasons why you should use it over mysqldb.

myconnpy is a bit of a mess. I've been considering rewriting it from scratch with support for twisted.

I take it your a (the?) dev of oursql?

Is it pure python?

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.

king_kilr posted:

SQLAlchemy is totally distinct from a driver. SQLAlchemy is a framework/toolkit/whatever, it *uses* MySQLDb (and most other PEP249 compliant drivers).

And as of sqlalchemy 0.6, it supports oursql as well!

Thermopyle posted:

I take it your a (the?) dev of oursql?

Is it pure python?

The only dev. It's written almost entirely in cython, with a bit of C and some code generation stuff in python.

Yakattak
Dec 17, 2009

I am Grumpypuss
>:3

Habnabit posted:

And as of sqlalchemy 0.6, it supports oursql as well!


The only dev. It's written almost entirely in cython, with a bit of C and some code generation stuff in python.


Hmm hopefully you can answer this for me. When I try to install oursql it can't find mysql_config. Where should I be able to find this?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
How does oursql compare to MySQL Connector/Python?

king_kilr
May 25, 2007

MEAT TREAT posted:

How does oursql compare to MySQL Connector/Python?

I've never heard of ANYONE using MySQL Connector/Python.

HTH.

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.

Yakattak posted:

Hmm hopefully you can answer this for me. When I try to install oursql it can't find mysql_config. Where should I be able to find this?

It comes with the mysql development libraries. If you're on windows or ubuntu, there's binaries available. Otherwise, install your platform's version of libmysqlclient-dev.

MEAT TREAT posted:

How does oursql compare to MySQL Connector/Python?

myconnpy doesn't use libmysql at all; it's a total rewrite from scratch in pure python. AFAIK, it's not fully-functional yet, and still doesn't offer any options for asynchronous queries. The quality of the python code isn't really the best, either.

I don't know if myconnpy uses parameterized queries like oursql does, so it might not be able to do server-side cursors either.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Habnabit posted:

The only dev. It's written almost entirely in cython, with a bit of C and some code generation stuff in python.

Too bad. That makes it not usable with things like greenlet or eventlet. :(


king_kilr posted:

I've never heard of ANYONE using MySQL Connector/Python.

HTH.

Then you're not reading this thread since I mention using it several posts up. :D

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.

Thermopyle posted:

Too bad. That makes it not usable with things like greenlet or eventlet. :(

Eventlet? I'm so, so sorry.

But yeah, for you folks using real eventloops, I'm definitely considering rewriting myconnpy for usability with twisted. I think twisted recently got an async postgres driver, too.

Captain Capacitor
Jan 21, 2008

The code you say?

Habnabit posted:

Eventlet? I'm so, so sorry.

But yeah, for you folks using real eventloops, I'm definitely considering rewriting myconnpy for usability with twisted. I think twisted recently got an async postgres driver, too.

Twisted? I'm so, so sorry. :v:

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.

Captain Capacitor posted:

Twisted? I'm so, so sorry. :v:

Well, hey, at least my code is linear.

Yakattak
Dec 17, 2009

I am Grumpypuss
>:3

Habnabit posted:

It comes with the mysql development libraries. If you're on windows or ubuntu, there's binaries available. Otherwise, install your platform's version of libmysqlclient-dev.

I used MacPorts to install MySQL5 and I do infact have mysql_config in the MySQL dirs, yet pip doesn't seem to find it and it completely errors out. :negative:

Adbot
ADBOT LOVES YOU

Habnabit
Dec 30, 2007

lift your skinny fists like
antennas in germany.

Yakattak posted:

I used MacPorts to install MySQL5 and I do infact have mysql_config in the MySQL dirs, yet pip doesn't seem to find it and it completely errors out. :negative:

If you used macports, it's probably called mysql_config5 instead of mysql_config. There's a section in the oursql docs for what to do with a differently-named mysql_config.

  • Locked thread