python

Python Virtualbox

how to list the names of available virtual machines in a virtualbox using pyvb modules. pls help. ...

Unable to get set intersection to work

Sorry for the double post, I will update this question if I can't get things to work :) I am trying to compare two files. I will list the two file content: File 1 File 2 "d.complex.1" "d.complex.1" 1 4 5 5 48 ...

Evaluating a mathematical expression in a string

stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 This returns the following error: Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: '2^4' I know that eval can work around this, but isn't there a better and - more importantly - safer method...

How to append EOF to file using Perl or Python?

I’m trying to bulk insert data to SQL server express database. When doing bcp from Windows XP command prompt, I get the following error: C:\temp>bcp in -T -f -S Starting copy... SQLState = S1000, NativeError = 0 Error = [Microsoft][SQL Native Client]Unexpected EOF encountered in BCP data-file 0 rows copied. Network packet size (by...

Importing bytea field into PostgreSQL database via psycopg2

I have a list of values as such: row = ['0x14', '0xb6', '0xa1', '0x0', '0xa1', '0x0'] I would like to insert these into a bytea field in my PostgreSQL database, using psycopg2, but I am unfamiliar with byte strings in python. What is the best way to achieve this? ...

More efficient solution to loop nesting required

I am trying to compare two files. I will list the two file content: File 1 File 2 "d.complex.1" "d.complex.1" 1 4 5 5 48 47 65 21 d.complex.10 ...

Python - functional "find"?

I need a function, which is capable of iterating over the collection, calling a supplied function with element of the collection as a parameter and returning the parameter or it's index when received "True" from supplied function. It is somethong like this: def find(f, seq, index_only=True, item_only=False): """Return first item i...

function not defined but really is defined...

I am writing a script and in my script I have this function: def insert_image(cursor, object_id, sku): product_obj = core.Object.get(object_id) string_sku = str(sku) folder = string_sku[0] + string_sku[1] + string_sku[2] found_url = False # KLUDGE This is ugly and redundant, however putting this in an if elif elif el...

Scrapy install: no acceptable C compiler found in $PATH

I am trying to install Scrapy on a a Mac OS X 10.6.2 machine... When i try to build one of the dependent modules ( libxml2 ) I am getting the following error: configure: error: no acceptable C compiler found in $PATH I assume I need the gcc...is that easy to install on 10.6? Is there some sort of package I should be installing, so ...

Imports in Python project with doctests

Hi. I have a Python project with following directory structure: /(some files) /model/(python files) /tools/(more python files) ... So, I have Python files in couple subdirectories and there are some dependencies between directories as well: tools are used by model, etc. Now my problem is that I want to make doctests for both models ...

Python XML to dictionary to iterate over items

I have the following XML example <?xml version="1.0"?> <test> <items> <item>item 1</item> <item>item 2</item> </items> </test> I need to iterate over each tag in a for loop in python. If tried many things but I just can't get it.. thanks for the help ...

Is there a Python version of CPAN?

So I've been using Perl for several years now and I'm starting to dabble a little in Python. Is there a sort of CPAN but for Python? What's the normal way to manage modules in Python? Any direction would be greatly appreciated. FWIW I use Linux so Windows-only solutions aren't really useful to me. ...

How do I remove whitespace from the end of a string in Python?

I need to remove whitespaces after the word in the string. Can this be done in one line of code? Example: string = " xyz " desired result : " xyz" ...

Error installing scrapy on Mac Os X 10.6

Trying to install Scrapy on Mac OSX 10.6 using this guide: When running these commands from Terminal: cd libxml2-2.7.3/python sudo make install I get the following error: Making install in . make[1]: *** No rule to make target `../libxslt/libxslt.la', needed by `libxsltmod.la'. Stop. make: *** [install-recursive] Error 1 Followin...

Any ready solution for basic asynchronous (non-blocking) HTTP clients with Stackless Python 3.1?

I am looking for a way to serve HTTP (and do HTTP requests) in an asynchronous, non-blocking fashion. This seems to be hard to do when you’ve decided on Stackless Python 3.1 (also see here for docs) as i did. There are some basic examples, like the pretty informative and detailed article How To Use Linux epoll with Python, and there is...

Python: Fast querying in a big dbf (xbase) file

Hi all, I have a big DBF file (~700MB). I'd like to select only a few lines from it using a python script. I've seen that dbfpy is a nice module that allows to open this type of database, but for now I haven't found any querying capability. Iterating through all the elements from python is simply too slow. Can I do what I want from py...

Flickr API automated login using Python library flickrapi

I have a web application that I want to sync with Flickr. I don't want the users to have to log into Flickr so I plan to use a single login. I believe I'll need to do something like this: import flickrapi flickr = flickrapi.FlickrAPI(myKey, mySecret) (token, frob) = flickr.get_token_part_one(perms='write', my_auth_callback) flickr.get_t...

Pythonic and efficient way of finding adjacent cells in grid

I am building a tile based app in Python using pyglet/openGL wherein I'll need to find the all of the adjacent cells for a given cell. I am working in one quadrant of a Cartesian grid. Each cell has an x and y value indicating it's position in the grid( x_coord and y_coord ). These are not pixel values, rather grid positions. I am lookin...

Django Form inheritance problem

Why can't I do this? from django import forms from django.forms import widgets class UserProfileConfig(forms.Form): def __init__(self,*args,**kwargs): super (UserProfileConfig,self).__init__(*args,**kwargs) self.tester = 'asdf' username = forms.CharField(label='Username',max_length=100,initial=self.tester) Mo...

any python socket server framework?

Hi, I'm looking for a python socket server framework - not to handle http, but to handle tcp sockets. I've done it myself, but adding all the features is tedious. This framework would handle thread pooling, socket setup, signal handling, etc. A big feature is code-reloading. If I use apache/mod_python, or django, or whatever, I don't h...