python

Converting unix timestamp string to readable date in Python

I have a string representing a unix timestamp (i.e. "1284101485") in Python, and I'd like to convert it to a readable date. time.strftime returns me with a type error. Any help is appreciated! ...

Best small web app release plan?

Hi, We are using Apache and Python, but that doesn't really matter. Basically, we have a Production version of our software that is running with clients depending on it being stable. Meanwhile, we are coding up the never version. Does anyone have a simple release plan they'd care to share? I've done the following on past projects,...

Parameter names in Python functions that take single object or iterable.

I have some functions in my code that accept either an object or an iterable of objects as input. I was taught to use meaningful names for everything, but I am not sure how to comply here. What should I call a parameter that can a sinlge object or an iterable of objects? I have come up with two ideas, but I don't like either of them: F...

Cannot install pyenchant on OSX

Hi, I am trying to install python bindings for the enchant library (pyenchant), according to the readme, it should be as simple as running python setup.py install But when I try that, I get this error: OSError: [Errno 2] No such file or directory: './tools/pyenchant-bdist-osx-sources/build/lib' Can someone tell me what to do? I have t...

Using the Python random module with XCHAT IRC scripts

I'm trying to print random items from a list into my XCHAT channel messages. So far I've only been able to print the random items from my list alone, but not with any specific text. Example usage would be: "/ran blahblahblah" to produce the desired effect of a channel message such as "blahblahblah [random item]" __module_name__ = "ra...

How to serialize beautifulsoup access-paths?

i have code, which does something like this: item.previous.parent.parent.aTag['href'] now i would like to be able to add filters fast, so hardcoding is no longer an option. how can i access the same tags with a path coded in a string? of course i could invent some format like [('getattr', 'previous'), ('getattr', 'parent'), ..., ('ge...

How to display milliseconds instead of microseconds with Django

In Django template language I can display a time with microseconds using : {{ player.time_to_display|time:"i:s:u" }} I would like to display only milliseconds instead of the full microsecond value. I am not able to locate a way to do that in the documentation, is there a simple mean to do that ? ...

Urllib2- fetch and show any language page, encoding problem.

I'm using Python Google App Engine to simply fetch html pages and show it. My aim is to be able to fetch any page in any language. Now I have a problem with encoding: Simple result = urllib2.urlopen(url).read() leaves artifacts in place of special letters and urllib2.urlopen(url).read().decode('utf8') throws error: 'utf8' c...

Getting non-contiguous text with lxml / ElementTree

Suppose I have this sort of HTML from which I need to select "text2" using lxml / ElementTree: <div>text1<span>childtext1</span>text2<span>childtext2</span>text3</div> If I already have the div element as mydiv, then mydiv.text returns just "text1". Using itertext() seems problematic or cumbersome at best since it walks the entire tr...

Django - Multiple columns primary key

Hello, I would like to implement multicolumns primary keys in django. I've tried to implement an AutoSlugField() which concatenate my columns values(foreignkey/dates) ... models.py : class ProductProduction(models.Model): enterprise = models.ForeignKey('Enterprise') product = models.ForeignKey('Product') date = models.Dat...

When are the first Python objects 'object' and 'type' instances created ?

Reading: http://www.python.org/download/releases/2.2/descrintro/#metaclasses A class statement is executed and then the name, bases, and attributes dict are passed to a metaclass object. Since 'type' is an instance - isinstance(type, type), it is an object already. When/how is the very first instance created ? My guess is that the firs...

How hard is it to learn Python/Django for a JEE dev?

I was wondering is learning Python and Django a hard/time consuming process for someone who's already rather familiar with OO programming (C++/Java) and some web dev (JEE)? I'm starting to look for a technology to implement a part of my master's thesis and since it will be a web app I'm considering JEE (since I'm already familiar with it...

Is there a Python module for handling Python object addresses?

(When I say "object address", I mean the string that you type in Python to access an object. For example 'life.State.step'. Most of the time, all the objects before the last dot will be packages/modules, but in some cases they can be classes or other objects.) In my Python project I often have the need to play around with object address...

How to make Beautiful Soup output HTML entities?

I'm trying to sanitize and XSS-proof some HTML input from the client. I'm using Python 2.6 with Beautiful Soup. I parse the input, strip all tags and attributes not in a whitelist, and transform the tree back into a string. However... >>> unicode(BeautifulSoup('text < text')) u'text < text' That doesn't look like valid HTML to me. An...

Peak detection in a 2D array

I'm helping a veterinary clinic measuring pressure under a dogs paw. I use Python for my data analysis and now I'm stuck trying to divide the paws into (anatomical) subregions. I made a 2D array of each paw, that consists of the maximal values for each sensor that has been loaded by the paw over time. Here's an example of one paw, where...

pisa to generate a table of content via html convert

Dear, Does anyone have any idea how to use the tag so the table of content comes onto the 1st page and all text is coming behind. This is what i've got so far, it generates the table of content behind my text... pdf.html <htmL> <body> <div> <pdf:toc /> </div> <pdf:nextpage> <br/> <h1> test </h1> <h2> second </h2> some text...

tipfy on google app engine (gae) installing extensions

I'm trying to get tipfy working on google app engine (GAE). I'm using Windows XP. The "hello world" example is working fine. What I'm not understanding is how to correctly install extensions. I'm trying to use the "multi-auth" example without much success. I'm receiving the following error: ImportError: No module named wtforms.valid...

Execute external application and send some key events to it...

Hi! I wasn't able to find a solution for Python. I am abelt o launch the application (using subprocess.Popen or subprocess.call), but I can't find a way to do the other part: I want to send a serie of keys (kind of macro) to the application I just opened. Like: Tab Tab Enter Tab Tab Delete ... Is there a way to do this that is Mac a...

Is there good planning GUI component (widget) for python?

I'm working on a scheduling app and looking for a calendar, timeline or other planning related GUI component for Python. Are you aware of any ? ...

How to replace "\" with "\\"

Hi, I've a path from wx.FileDialog (getpath()) shows "c:\test.jpg" which doesn't works with opencv cv.LoadImage() which needs "\\" or "/" So, I've tried to use replace function for example: s.replace("\","\\"[0:2]),s.replace("\\","\\\"[0:2]) but none those works. And, this command s.replace("\\","/"[0:1]) returns the same path, I d...