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
nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

ATLbeer posted:

This might warrant it's own thread but, I'm having problems with both Python24 and 25 installed on my Mac.

I don't particularly remember installing 25 but, I guess it might have come from my Leopard upgrade. I don't honestly care much which version I am using but, my problem comes from the fact that any type of library or module install I am doing is defaulting into the 2.5 installation directory but, all my scripts are executed by 2.4.4.

Can anyone help me sort out this all?

Should I remove one installation (24 or 25) or how can I at least just get easy_install etc, to use one installation (preferably 24, since I already have a bunch of packages installed there) or migrate my packages over?

No need to remove one or the other - they can co-exist nicely. And some software *cough*Zope*cough* can't use 2.5.

It's odd about the install and execution going to different pythons. Type in "which python" at the terminal to see what your default Python is. (I'm guessing 2.5.) Do you have any execution line at the top of your scripts like "#/usr/bin/python24"? Finally, is there an alias or symbolic link to python anywhere that you might have made?

nonathlon fucked around with this message at 12:59 on Feb 12, 2008

Adbot
ADBOT LOVES YOU

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

ATLbeer posted:

Thanks for the reply. I figured out the problem. I had installed MacPorts and it had put an ugly 2.4.4 version on top of 2.4 and 2.5 and injected itself into my profile. Took MacPorts out and it went back to normal again

Same thing happened to me, except with fink. One of the reasons I stopped using fink.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

porkface posted:

You guys know you can safely run multiple versions of Python on the same machine? You just have to set them up right, and choose which version you want to be your generic system-wide install.

I'm aware, thanks. It wasn't the Python alone (once I knew about that I could work it out) but dealing with similar problems with other apps and libraries, and making sure that things that relied upon the fink versions could find the fink versions and those that wanted non-fink ...

One reason to be grateful for the framework builds under OSX - it keeps everything nice and separated and easy to find. I've got 3 versions of Python installed currently with no problems.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
On to other topics: web development in Python. I've got a couple of web-applications (or rather, applications and databases that need a web front-end). It makes sense for all the logic to be in Python, rather than mix-and-matching languages and models. So what are people's experiences with Python webwork?

My own (limited) experience:

* Zope / Plone: I've done a lot of work with these and would advise anyone think strongly before before getting into them. You get a lot with Zope / Plone (default content presentation, ubiquitous and finely grained security, administrative tools, combining multiple applications / tools / products in the one web front). But they're tools that are a way of life - you have to dedicate a lot of time to get the framework to do anything, and I commonly spend more time wondering how to get Zope to do what I want, rather than solving the domain problems. And arguably Zope-Plone gets in the way of the development process, making it difficult be Pythonic and bang out some quick code to see how things work.

* Pylons: The Pylons philosophy looks good (use anything you want with our framework), but I've seen argued that this actually means that Pylons provides you with drat-all. Nonetheless, it seemed to work okay and I've been thinking about this for a dedicated web-service (as opposed to a general CMS).

* Django is the officially blessed framework. My one (and major) quibble is that it's using it's own database layer and ORM, which defeats the point if you have your own database layer already laid out (as I do). And Django's efforts at integrating SQLALchemy appear to have gone nowhere in 2 years.

* Webware has finally tottered out from it's coma and looks cool.

* I worked through the Turbogears book and it all seemed simple but (1) can it go beyond simple things, (2) with Turbogears 2 being mooted, this may not be a good time to commit.

Opinions?

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

dwayne_dibbley posted:

Any idea how I can get python to read and show umlaut characters from a file properly?

Not Vista's fault, not Python's fault. You're got a non-ascii file.

Open the file with `codecs.open()`, while specifying the encoding you want and then treat it like a normal file. You'll get unicode strings back. Arguably, the issue is that unicode and normal string interoperate in Python so much that the fact you have to use a different call here is anomalous. See http://www.jorendorff.com/articles/unicode/python.html

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Milde posted:

Pylons being a "collection" of separate components is a load of poo poo. It's all tightly coupled together and about the only place you really get any freedom is in OR mapping. It touts being WSGI-based but it abstracts away WSGI to the point of it being irrelevant. You see other projects writing "adapters" just for Pylons compatibility.

And not to mention it's poorly documented, and just poorly designed all around. It's like they went out of their way to make their framework as complicated as possible.

Okaayyyy ...

Actually that's just the sort of information I was looking for. A lot of things look good from the outside, or have a good image due to the relentless promotion by the inner circle, but when you get to actually do something non-trivial, you run into problems.

(Cue, my grousing about Plone's form handling which was abysmal until recently. For every form you had to write the HTML by hand, supply two scripts for handling the form that had a very restricted range of python you could use in them, and another two files of metadata. As a consequence, changing a form was like turning an oil-tanker ... yet no one in the Plone community complained about this.)

bitprophet posted:

Yup. This is a major misunderstanding about Django; it is loosely coupled by design. Yes, you lose the contrib apps (admin, auth, etc) and generic views, but it still works perfectly fine in terms of URL dispatch, view functions and template rendering.

Also good to hear. I'd avoided Django because I didn't want to deal with its ORM (SQLAlchemy for ever!)- but the contrib stuff looks nice, as does encapsulating a site as a Python package.

On other matters, has anyone coded a plugin / extension using setuptools entry point schema? It seems to be simple (especially compared to zope.interface) but like a lot fo thinsg with setuptools, it's under explained and I can't find many examples.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Milde posted:

And the convention for naming non-class variables in Python is lowercase_with_underscores

Kind of. It's more of a convention than camelCaps but the whole style issue isn't as fixed as it is in (say) Java. l lowercase_with_underscores is what they use in the Python style sheet, but several communities have quite different styles (e.g. Zope). The major styles points would be to be consistent, use lowercase (no underscores) for module Names, CapsStyle for classes and *never* mix spaces and tabs for indentation.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
Here's something basic, but it might represent a gap in my Python-fu.

I have a bunch of floating point numbers of indeterminate size. Say, 3.02340, 0.8, 0.0051234. Now with the string formatting, it's fairly easy to specify the number of digits before the decimal points and the number of digits after:

'%2f' % x => ['3.023400', '0.800000', '0.005123']

'%0.2f' % x => ['3.02', '0.80', '0.01']

What I'd like to do is something a bit different, show 3 digits precision overall. So it would look like:

['3.02', '0.800', '0.00512']

Any ideas on the most robust way to do this?

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

SkyLander posted:

Anyway basically I have to do basic commands and one of them is to do a dir command which just lists what is in a directory. So I found listdirectory() in the OS module. So I basically just do input from the command line into a string and I just put that into listdirectory. Now does that just create a list of strings? Or how do I then output that? Sorry if that seems confusing.

You're on the right track. The call is 'os.listdir (path)', which returns a set of strings. Apart from looking at the standard library docs (which are all online), you might want to install ipython, which lets you introspect Python objects. For example

>>> import os
>>> os??
Type: module
Base Class: <type 'module'>
String Form: <module 'os' from ...

>>> os.listdir??
Type: builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form: <built-in function listdir>
Namespace: Interactive
Docstring [source file open failed]:
listdir(path) -> list_of_strings

Return a list containing the names of the entries in the directory.

...

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
A database security / access question, for which I want a Python solution:

So I have this small to medium sized database, for which I've written an access wrapper in SqlAlchemy. The wrapper handles searches, addition and deletion and so on, and lies between the actual database and the web services that will use it. So far so good.

The complexity comes in terms of different access levels. Not all rows should be accessible to all users, some users will have access to all of them, some to restricted sets: a fairly classic access control problem that I'd like to solve in the software layer. However, I haven't found a great deal of prior art in SqlAlchemy or Python. Any pointers? I'd hate to have to write a whole ACL library just for this.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Land Mime posted:

Does this really need to be solved at the software layer? Allowing certain users to view certain rows sounds perfectly suited for, well, views. Of course depending on your situation this may be a horrible idea, but its certainly the first thing that came to mind.

I had that idea too. Unfortunately, it's not going to work. Neither the groups / users, or the subsets of data they can see will be fixed, or identical across installations. It also causes run-on problems with the object-mapping in SqlAlchemy (e.g. "Country objects are mapped and retrieved from the country, the country_public_view table, the country_restricted_view table, the country_admin_view table ..."). You see my problem.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
While I'm throwing questions out to the masses: here's one about iterators and generators. There seems to be two styles when people are writing iterators for their own containers - having the yield within the class and having it in an external function.

A toy example - take a container class and give it an iterator to yield the contents:

code:
class L(list):
   def traverse (self):
      for i in self:
         yield i
Simple. But you commonly also see a style where this is done:

code:
class L(list):
   def traverse (self):
      return _traverse (self):

def _traverse (mylist):
      for i in mylist:
         yield i
What's the difference? It seems to me as if these are functionally different. I though that the second (independent) iterator might be thread-safe or allow against multiple simultaneous iterators. Quick experimentation says not. Any ideas?

nonathlon fucked around with this message at 15:06 on Apr 23, 2008

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Milde posted:

And in his specific example it's completely 100% useless. iter() for lists does exactly what that traverse function does.

That's why I called it a "toy example". There seemed little point in confusing the issue with the details of a custom class. Try and keep up boy.

The dichotomy in method / external iterators is a puzzle because of its presence in code that I've seen. In a way, it's a relief that no one else understands what the difference because I sure can't see it. Any method or function that yields should create an independent generator - with it's own state - when first called. So functionally the two should be identical. And - for tidier code - why not just put the whole iterator in a method.

(I have to go beyond __iter__ in my particular project because the container has to be iterated over in a number of different ways. It's a tree structure and need iteration over vertexes, arcs, in post-order, pre-order etc.)

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
What are people using for general HTML form generation? A lot of the more popular modules out there are tied to particular frameworks (e.g. zope.form, newforms). I really like formencode's validation and conversion but it doesn't generate forms (for good reasons) and has some oddities when handling arrays of fields. formbuild is supposed is okay, but again has a couple of odd design decisions.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

such a nice boy posted:

Help me out, y'all; I'm preparing for a job interview this afternoon and I'm trying to think of all the questions they could possibly ask. I know that "what feature would you most like added to language X" is a popular question, but I can't think of anything for Python. So...what feature would you most like added to Python?

One of the strange things about Python is that the things that used to bug me have mostly been fixed over the years. Still, here's some outstanding items:

* There's a bunch of ubiquitous and widely used 3rd party libraries that really should be in the standard library. I'm thinking of PIL, more advanced database interaction (something like JDBC), a better standard GUI than Tk and so on.

* Not everyone uses them, but it would be neat to have interfaces as part of the standard library (rather than the complex monolith that is zope.interface).

* Lot's of people hate using 'self' in objects. Personally, I'm indifferent.

* In-place increment and decrement (x++, x--) would be nice.

* Unicode as the standard string would be nice, and that's coming in Python3000.

* Multi-line and more sophisticated lambdas, oh yes.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

A Perturbed Parrot posted:

Quick Python question.
I'm presently working on a project which requires (and in fact is made much nicer by) the use of large databases.
After a quick look, I think I might use Python/MySQL mostly because it is free and rather easy to use, however, I'm open to any suggestion.
I don't really need a very elaborate database system just something robust, easy to use and manage. The application is not related to the web in any shape or form so "security" is not an issue at all.
Any good names to look up?
e:SQLite seems a solution I hadn't explored at first, any ideas about it?

The only problem I've found with Python and MySQL is getting the library (MySQLdb) to compile. If you can pass that hurdle, it's fine. The Python Postgres libraries are okay. SQLite, although supposedly a dumb and simple solution works absolutely fine, is easy to use and performance is okay.

You may want to think about a database wrapper or ORM like SQLObject or SQLalchemy. It takes a while to get the hang of them but it makes it easy to change your db and deal in objects instead of rows.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
I've just discovered the wonders of appscript, a way to call Applescript from Python. It's cool, and recommended as much better than using Applescript directly. I hacked up a quick script to import a list of todo items into an application without an explicit Applescript dictionary. You can see it here, including some notes on a few holes or oddities I found.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
A question about PDF libraries for Python: ReportLab allows you to *make* PDFs, PyPDF allows you to *edit* them (to the extent of adding and deleting pages), but is there any library that will allow you to interrogate or add to them?

I'm doing some work with PDF ebooks and I'd like to peek at the PDF metadata to rename the files accordingly, and then to merge some annotations (from an iLiad reader) into the main document. However current Python PDF libraries seem to neatly skirt this functionality. I guess what I'm looking for is the Python equivalent of iText. Options?

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Jo posted:

I'm going image processing beyond the capabilities of the Python Imaging Library. I'd use OpenCV with Python wrappers, but I'm hoping to get more familiar with the techniques and algorithms by writing my own versions. Near as I can tell, NumPy is the only real 'quick' solution for dealing with 2D arrays in Python. Before I continue onward with my project, NumPy is the 'official' or most common way of dealing with large 2D arrays, correct?

Yes. The history of arrays in Python is tangled, but originally there was "array" in the standard library, but that was broken. Then there was Numeric Python, which dissolved into infighting after a while and forked numarray. Then they all made up and we ended up with Numpy. And that's what everyone uses.

The only problems you may encounter (and this depend on what you are trying to do):

* You have to compile Numpy for your platform. (The install does this, but the point is it's not pure python)

* To a large extent, Numpy is all about fixed-size arrays. You can reshape an array, but (say) adding a column or row is an rear end.

* The documentation is a bit skimpy, but you can refer to the Numeric python docs for a lot of pointers.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

m0nk3yz posted:

Uh, my mac works great for me for installing python things - it's all I develop on. Also, if you're on leopard: You should not be installing any other python distribution other than the one it came with, unless it's to your home directory or some /opt location. Thou shalt not change the system python!

That's not true - there's no problem with compiling a framework build for OSX. I routinely maintain 3 different pythons on my Mac (2.3 for backwards, 2.4 for zope, 2.5 for work). And once you factor eggs in, installing packages is a snap. So your original point is true - python works great on the mac.

(With, admittedly, some exceptions. Over the years I've sometimes had problems with libraries like PIL and MySQLdb that have to be compiled, but always able to eventually hack around them. And I've had problems with these libraries under Redhat as well, so it's difficult to see OSX as deficit in this regard.)

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

m0nk3yz posted:

Let me correct myself: I don't compile additional framework builds unless I need to - which is almost never, simply due to the fact I can install a perfectly functional build in my home directory and keep it completely self-contained.

As for compiling packages - this is true pretty much everywhere. People get pretty hung up on having packages with pre-compiled everything, but what happens if you need version 2 and your upstream only provides version 1 (which happens to me with ubuntu all the time) - I'm going to need to compile the darn thing. I guess I just don't see what the big deal about compiling this stuff.

Point taken. I'd prefer to use a single build of Python myself, except for Zope's lunk-headed attitude to versions (i.e. only runs on Python 2.4 for obscure reasons, internal modules are incredibly picky about the versions of other modules they will work with). And granted, no package installer with help you with versioning in Python.

On a side note, when I started working with Python on Windows was when I was astonished how hard it was to develop with. What, I have to get a special installer for half the packages I want? What if the developer hasn't been arsed to compile one as yet? Now _that's_ difficult ...

nonathlon fucked around with this message at 18:55 on Sep 30, 2008

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

deimos posted:

While I agree, 2.5 does have basically one of the better things of 2.6 which is context managers.

OK, I surrender. What's a "context manager"?

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

nihilocrat posted:

Hey, that's one of the main reasons I avoid C/C++ these days. People think I'm a pussy, but at least I can get "Hello World" without having to find/compile/link to a zillion dependency libraries.

Actually I agree. I programmed in C++ for years and recently had to return to it. The whole library-link thing is ridiculous: compilers being unable to find a library you have on your disk, or compiling and then complaining about an "unresolved symbol". If nothing else, Java got all that stuff right.

m0nk3yz posted:

.. on context managers ...

Well, huh. Thanks for the explanation.That's actually useful - I actually constructs like that in C++ (set something up in the c'tor, clean it up in the d'tor) and recently tried to do something similar in Python. (It works but only 2 problems - you can't tell when the object will be deleted, and session termination disposes of objects in a weird way). This will be a lot easier.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

duck monster posted:

Anyone know a good way of getting mysqldb of some variety working on the mac. This is making me too angry working it out for myself :(

Getting MySQLdb to work can be a bitch. Sometimes it just works but other times I've spent days trying to get it installed (with occasional periods of it looking like it installed but it actually not working).

General advice: use of the precompiled packages out there. Or use Postgres instead. Or follow the tale of woe on my webpages as I encounter every problem under the sun.

I've also had problems with MySQLdb on Redhat as well, so it's not just Mac. DPAPI is okay, but by now Python really needs a saner and more standard set of db modules, like Java.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

GuyGizmo posted:

I think I finally got it. The key seems to be that python just doesn't like circular import statements ...

Late to the dance, but this is a point that needs underlining. As opposed to (say) C, where you pay great attention to where and in what order things are included, in Python this _largely_ disappears. I say largely, because circular imports can create all sorts of cryptic errors that are hard to diagnose. The moral: decompose your design properly, so you don't end up with modules calling each other.

As for you above problem, I once had to solve something similar and ended up with this: a file (e.g. thing1.py) finds out its own path. Use that to get it's parent directory. List and select the files in that directory. Import doesn't come into it.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

duck monster posted:

Trying to get Python Imaging Library working with python on Os/X has got me very loving close to just abandoning developing on macs :(

Adding to the list of "yeah, I had this problem too", you might wants to look at my notes on installing PIL, to see if there is any help there.

To be fair, it's not all Apple's fault, the PIL installer is a little odd. Again, image handling is something that should be in the standard library.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Sparta posted:

I want to learn Python (in fact, I'm going to have to learn it). I have a little programming background. I got through 3 quarters of Computer Science, in which I mainly mastered C, and struggled tremendously with Java.

I have worked with PHP, and although I'm not really a great coder, if I need to figure out a problem, I can most likely find myself a solution.

I love procedural programming, it makes sense to me, but I keep hearing about how great Python is (and about OOP). Is there a tutorial/book out there that is good at teaching me how to code Python when I do have some programming experience, but only on the procedural end?

I wouldn't get too hung up on OOP - you can program procedurally in Python until you get the idea of objects. And then you will wonder how you ever did without them. But if you think of objects as just smart structs, records with functions attached, that will get you a long way.

A good place to start learning is Dive Into Python and/or How to think like a Computer Scientist. Both are free on the web. I'd suggest doing a few different tutorials, to get different points of view on things.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

BlackDiamonds posted:

For those of you who are playing around with python editors I want to say that the dev branch for Python in NetBeans is fantastic. See http://wiki.netbeans.org/Python and http://blogs.sun.com/tor/ for more information. I'm just sad that it won't be in NetBeans 6.5.

Colour me disappointed. Netbeans is my editor of choice - I work in a number of languages and prefer to use the one editor for all - and the lack of Python/Jython support has chaffed. Have you been using nbpython with the 6.5 candidates?

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

m0nk3yz posted:

No. Do not jump into python 3000 - Python 3000 is not going to be widely adopted for some time - you're much better off focusing on python 2.6 and using that to build up your skills. Python 3000 is not "that big" of a change from 2.6 that it will make all of your 2.6 knowledge and skills worthless.

This. Python 3000 is cool but (a) it's unclear how long it will need to takeover from current Python (several years seems to be the general consensus), (b) in many ways it's just a tidying up of the language so you won;t be wasting your time with current Python, (c) virtually all the learning resources around are devoted to current Python, and (d) it's unclear to me if anyone is actually using it to build things "out in the wild" as yet.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

tef posted:

(elementtree api is not my friend)

Which parts don't you like? I ask because I've *coff* wrapped elementtree myself to compensate for some deficiencies.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
Anyone worked with validating XML parsers, or any form of XML validation? Python's always been weak in this area and most of the (half-hearted) attempts have faded and gone away over the last few years.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
A few odd questions starting from OSX and stretching beyond:

* What state is PyCocoa / Cocoa-Python in? I was thinking about a new project, went to XCode and created a Python application. Normally the boilerplate generated by XCode results in a minimal / trivial application that works (if it does nothing), but this errored out immediately with "uncaught exception". I went to the PyCocoa pages, and they're in a state of long neglect, with apologies for no progress. Is there another up-to-date resource for the Cocoa-Python bridge?

* Which leads to another question: PyCocoa obviously calls Cocoa and Foundation libraries from within Python. But I'd like to do that from within a commandline app. (Want to use PDFKit.) Buts there's a dearth of examples. Any pointers?

* Finally, what are people using for code documentation? I've used epydoc for a long time, but Sphinx is popular lately, although it seemed to me to be a documentation tool, more than a code documentation tool.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
I've been using paster / eggs / setuptools for building modules for a while now: generate a skeleton with "paster create", use "python setup.py develop" while I'm working on it, and "python setup.py install" for deployment. Once in a while something strange happens when the install stage installs an old version of the module. It looks to be that it pulls an old copy out of the "build" or "dist" directories and uses that to install, even if the module has been updated or has a later version number. Has anyone seen this? I haven't discerned a pattern to explain it yet.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
I'm having an odd problem with IPython: the colors that it uses to print up code (in error and introspection) are unreadable in my terminal. So at first I did the usual - edited my settings in .ipython/ipytonrc. This had no effect. After some investigation, I find that you're now supposed to use .ipython/ipy_user_conf.py. Fine, edit that. Still has no effect. I'm baffled at this point. Any idea where I can look for or change the setting?

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
I've been getting interested in Mono recently - I'm primarily OSX and Linux so the Windows-bound .Net just wasn't any good - and so I begane to wonder what the situation is with Python and Mono / etc. This means IronPython, yes? And can I run IronPython on a non-Windows platform? Their site didn't help me in answering this.

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
A general programming question in a specific Pythonic context:

I have a webpage with a form (on a Plone site for what it matters), that when submitted calls an external program to do some calculations, grabs the results and renders them on the page. Simple. (For interest, it's matching submitted biosequences to an established corpus via various specialised commandline programs.)

The problem has come about that sometimes the server is overloaded or the external program fails to complete, leaving my webserver waiting for an answer that never comes. So: what's the appropriate Pythonic idiom for handling this sort of situation? It seems reasonable to launch the external app, wait for x seconds and then conclude it has failed and return a "sorry" message to the user. Threads, job control, multiprocessing - what's the best way to it?

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...
I've been Doing The Right Thing and using setuptools to handle the installation of all the modules I write. But I recently wrote a few scripts, that I thought others might find useful. (They do conversion between various bioinformatic file formats.) When thinking about the best way to distribute it, I realised that setuptools would work fine. You can give it a version, that can be updated. It takes care of the prerequisites. It can copy a script to the right place.

It does install an egg in the site-packages dir, but the egg appears to be non-importable. So it seems to work fine. Can anyone think of any objections or potential problems?

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

outlier posted:

I have a webpage with a form (on a Plone site for what it matters), that when submitted calls an external program to do some calculations, grabs the results and renders them on the page. Simple. (For interest, it's matching submitted biosequences to an established corpus via various specialised commandline programs.)

The problem has come about that sometimes the server is overloaded or the external program fails to complete, leaving my webserver waiting for an answer that never comes. So: what's the appropriate Pythonic idiom for handling this sort of situation? It seems reasonable to launch the external app, wait for x seconds and then conclude it has failed and return a "sorry" message to the user. Threads, job control, multiprocessing - what's the best way to it?

Odd to follow myself up but ...

The situation is that I have some 3rd party code calling a commandline program, waiting for the results, then munging them in various ways before returning them to a webservice. And when the user gets bored and terminates the request, the called commandline process seems to hang around. Curious.

Dwelling through the code, I see they have called the commandline with the subprocess module. I would reason that when owning object (that calls subprocess and creates the Popen) gets deleted, then the Popen should get deleted and delete the process - yet it's still hanging around. What gives? How can I ensure that a called process is disposed of correctly?

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Sylink posted:

Can anyone explain XML parsing to me? I look at XML and think its pretty simple but all the modules and tutorials I read seem extremely esoteric.

I just want to grab values from certain tags which shouldn't seem this complicated with all kinds nodes and poo poo.

That's really a general programming question not a Python one but look: an XML document is a set of nested tags that can be represented as a tree. So you _have_ to think about nodes, because to get to the node you want, you need to walk to the right point in the tree. But that's no so hard, because you just start from the root and move to children, and their children as you need.

Additional free advice: use xml.etree (in Python 2.5+) or Elementtree (before that). It make handling XML easy.

Adbot
ADBOT LOVES YOU

nonathlon
Jul 9, 2004
And yet, somehow, now it's my fault ...

Centipeed posted:

I tried Project Euler when I was first getting into a programming language, but the problem is that most of the thinking you have to do (Or I had to do, at least) was mathematical rather than "How do I do this with the language I've got in front of me?". Did anyone else find this?

That's fair comment - a lot of the problems are mathematical or algorithmic in nature. It's a good source of exercises, but don't feel that you have to do every problem.

  • Locked thread