python

Building an interleaved buffer for pyopengl and numpy

I'm trying to batch up a bunch of vertices and texture coords in an interleaved array before sending it to pyOpengl's glInterleavedArrays/glDrawArrays. The only problem is that I'm unable to find a suitably fast enough way to append data into a numpy array. Is there a better way to do this? I would have thought it would be quicker t...

How do I print a line following a line containing certain text in a saved file in Python?

I have written a Python program to find the carrier of a cell phone given the number. It downloads the source of http://www.whitepages.com/carrier_lookup?carrier=other&number_0=1112223333&response=1 (where 1112223333 is the phone number to lookup) and saves this as carrier.html. In the source, the carrier is in the line after the...

pymongo: problem with findandmodify - "no such command" is returned

I believe there is a bug in pymongo (or, at least, the documentation) which makes it impossible to run a findandupdate query. Here's what happens. When I run: result = db.command({ 'findandmodify': 'my_collection', 'query': {'foo': 'bar'}, 'update': {'$set': {'status': 'queued'}}, }) The query that act...

Callback, observers, and asynch sockets in Python.

I'm still a neophyte Python programmer and I'm trying to do something that is a bit over my head. What I've done is create a simple IRC bot using asyncore (and asynchronous sockets module). The client runs in a continuous loop, listening to the conversation in the channel. What I would like to do (I think?) is implement an observer pa...

Python Eval executing enviroment

I do not understand what environment a eval or exec statement executes in. You can pass both global and local scopes to them but I don't quite understand what this means. Does python create an anonymous module for them, and if that is the case how do the global and local scope differ? Does it run it like it was an anonymous function? ...

Accessing a ServerFactory from the Service in Twisted.

Hello All, I've been trying to come up with a decent design for multiple factories access each others information. For example, I have the following services: 1 management web service, a VirtualHost instance (multiple domains) and a built in DNS service. Going through the finger tutorial was very helpful but it lacks some key points. It ...

Parsing XML in Python using Expat

Background: I'm coming from C#-land, so I'm looking for something like being able to handle nodes and values by selecting via Xpath. Here's my code, so far: import urllib import sys from xml.parsers import expat url = 'http://SomeWebService.SomeDomain.com' u = urllib.urlopen(url) Parser = expat.ParserCreate() data = u.read() try: ...

Date fields and Django's loaddata

Can a date be loaded into a DateField using Django's loaddata admin feature? I have a JSON file that I'm using to bulk load data into my app. When you dumpdata, date fields are outputted in the format yyyy-mm-dd. However, if you try loading data back in with the same format, the field is treated as a string and the load fails. For ex...

Django LowerCaseCharField

We implemented a LowerCaseCharField. We would be happy to hear better implementation suggestions. from django.db.models.fields import CharField class LowerCaseCharField(CharField): """ Defines a charfield which automatically converts all inputs to lowercase and saves. """ def pre_save(self, model_instance, add): ...

memory location of dictionary in python 2.6.4 only?

Is it possible to see a memory location/address of data dictionary in python 2.6.4 only?? ...

Dictionary-like object in Python that allows setting arbitrary attributes

What I want to do in my code: myobj = <SomeBuiltinClass>() myobj.randomattr = 1 print myobj.randomattr ... I can implement a custom SomeClass that implements __setattr__ __getattr__. But I wonder if there is already a built-in Python class or simple way to do this? ...

literal usage of % in batch

I have a batch file containing a python script using the Output template> %(NAME)s when I ran it, cmd thinks its a var and igoners the % so youtube-dl.py -b -o %(uploader)s-%(title)s-%(id)s.%(ext)s turns into youtube-dl.py -b -o (uploader)s-(title)s-(id)s.(ext)s how do i convince cmd to not process it and pass it as is to py...

When will Jython support Python 3?

According to Jython's documentation: Jython is an implementation of the Python language for the Java platform. Jython 2.5 implements the same language as CPython 2.5, and nearly all of the Core Python standard library modules. (CPython is the C implementation of the Python language.) Jython 2.5 uses the same regressio...

Socket shutdown and rebind - How to avoid long wait?

I'm working with socket in python, and being in development stage I need to kill and restart my program frequently. The issue is that once killed my python script, I've to wait long time to be able to rebind the listen socket. Here's a snippet to reproduce the problem: #!/usr/bin/env python3 ...

python switch by class name?

I am currently doing this, to do different things based on an object's type: actions = { SomeClass: lambda: obj.name AnotherClass: lambda: self.normalize(obj.identifier) ...[5 more of these]... } for a in actions.keys(): if isinstance(obj, a): return actions[a]() Is it possible ...

Controlling distutils from Scons

I have a C++ library that I build using Scons which is eventually linked into (among other things) a Python extension. Once I have built the library with scons, I have written a standard setup.py script which I call to build and install the extension. My main problem is that setup.py does not recognize when the library has been rebuilt...

What are the Difference between cElementtree and ElementTree?

I know a little of dom, and would like to learn about ElementTree. Python 2.6 has a somewhat older implementation of ElementTree, but still usable. However, it looks like it comes with two different classes: xml.etree.ElementTree and xml.etree.cElementTree. Would someone please be so kind to enlighten me with their differences? Thank you...

App Engine (Python) Datastore Precall API Hooks

Background So let's say I'm making app for GAE, and I want to use API Hooks. BIG EDIT: In the original version of this question, I described my use case, but some folks correctly pointed out that it was not really suited for API Hooks. Granted! Consider me helped. But now my issue is academic: I still don't know how to use hooks in ...

What should people new to Python know about its community and ecosystem?

I'm cobbling together some sort of an introduction to Python, but one that focuses on the community and the ecosystem around Python rather than just the language. With How to Think Like a Computer Scientist and other great tutorials, it's easy to get familiar with the language, but it took me a fair while before I knew what The Cheese Sh...

numpy.matrix manipulations

Hi everyone, I have a question about numpy.matrix class. How can I perform such basic manipulations with matrices as adding, deleting and replacing rows and columns? p.s. I apologize for the lame question.. ...