python

How to get pyodbc.connect to prompt?

In my C++ programs, I'm used to the connection process prompting for a missing password or letting you select your own connection. Whe I use pyodbc.connect(), an exception is generated instead. Traceback (most recent call last): File "<pyshell#41>", line 1, in <module> c=pyodbc.connect('') Error: ('IM002', '[IM002] [Microsoft][OD...

Is there a LGPL/Apache/BSD Python library for rendering modern HTML and Flash with a transparent background on Windows,Mac,Linux?

I'm looking for a Python library that's suitable, with DOM access too. I don't mind if the flash transparency doesn't carry over. PyQT's license isn't compatible with the project, and PySide isn't compiled cross-platform yet. Any thoughts? ...

Python what does it mean "AttributeError: 'unicode' object has no attribute 'has_key' "

Hello, I would like to ask what does it mean "AttributeError: 'unicode' object has no attribute 'has_key'" Here is the full stack trace: Traceback (most recent call last): File "D:\Projects\GoogleAppEngine\google_appengine\google\appengine\ext\webapp\__init__.py", line 509, in __call__ handler.post(*groups) File "D:\Projects...

Cannot connect to server externally using Twisted library in Python

I am trying to get a simple TCP server running on my server. I am using echoserv.py and echoclient.py on the Twisted examples page. When I run echoserv.py on the server, I can connect fine using the following in echoclient.py: reactor.connectTCP('localhost', 8000, factory) <- for a localhost connection reactor.connectTCP('192.168.0.250'...

Efficient way to verify that records are unique in Python/PyTables

I have a table in PyTables with ~50 million records. The combination of two fields (specifically userID and date) should be unique (i.e. a user should have at most one record per day), but I need to verify that this is indeed the case. Illustratively, my table looks like this: userID | date A | 1 A | 2 B | 1 ...

app-engine-patch with pyamf = No module named encoding

I'm trying to use app-engine-patch with pyamf by following this: http://pyamf.org/wiki/GoogleAppEngine because I want to migrate my Django <-> pyamf application to app-engine-patch <-> pyamf. What I have now is that I created my gateway.py with only one line of code: import pyamf just to test can I use pyamf and I get blank page whe...

Python, find a file in the same directory.

Let's say I have the files a.py and b.txt in the same directory. I can't garuntee where that directory is, but I know b.txt will be in the same directory as a.py. a.py needs to access b.txt, how would I go about finding the path to b.txt? Something like "./b.txt" won't work if the user runs the program from a directory other than the ...

dictionary of object

hi all, I have a sorted dict { 1L: '<'New_Config (type: 'String') (id: 1L) (value: 4L) (name: 'account_receivable')'>', 2L: '<'New_Config (type: 'string') (id: 2L) (value: 5L) (name: 'account_payable')'>', 3L: '<'New_Config (type: 'String') (id: 3L) (value: 8L) (name: 'account_cogs ')'>', 4L: '<'New_Config (type: 'String') (id: 4L)(...

How can I specify that some command line arguments are mandatory in Python?

I'm writing a program in Python that accepts command line arguments. I am parsing them with getopt (though my choice of getopt is no Catholic marriage. I'm more than willing to use any other library). Is there any way to specify that certain arguments must be given, or do I have to manually make sure that all the arguments were given?...

What do you make of this Python error?

Here's the error. Traceback (most recent call last): File "_ctypes/callbacks.c", line 295, in 'calling callback function' File "USB2.py", line 454, in ff self.drv_locked = False SystemError: Objects/cellobject.c:24: bad argument to internal function Here's the Python code involved. def drv_send(self, data, size): if not s...

How to migrate packages to a new Python installation?

How can i quickly migrate/copy my python packages that i have installed over time to a new machine? This is my scenario; Am upgrading from an old laptop running python2.5 & Django1.0, to a new laptop which i intend to install python 2.6.2 & Django 1.1. In time i have downloaded and installed many python packages in my old machine(e.f p...

How good is startswith?

Is text.startswith('a') better than text[0]=='a' ? Knowing text is not empty and we are only interested in the first character of it. ...

Amazon S3 Python Bulk File Transfer through Python

I want to tranfer files in around 1000 directories to an Amazon S3 bucket using Pythons S3 package. How could I do it ? ...

Is there an way to programatically read a file from a TrueCrypt disk into memory?

I need to load a file from an umounted TrueCrypt disk into memory. Is there any way to do this programatically? Does TrueCrypt offer an API? The way I believe is best for attempting this would be to mount the volume (prompting the user for a password, of course), open the file, and then unmount the volume. Is there a way to do this a...

when is it necessary to add an `else` clause to a try..except in Python?

When I write code in Python with exception handling I can write code like: try: some_code_that_can_cause_an_exception() except: some_code_to_handle_exceptions() else: code_that_needs_to_run_when_there_are_no_exceptions() How does this differ from: try: some_code_that_can_cause_an_exception() except: some_code_to_h...

Pythonic way of iterating over 3D array

I have a 3D array in Python and I need to iterate over all the cubes in the array. That is, for all (x,y,z) in the array's dimensions I need to access the cube: array[(x + 0, y + 0, z + 0)] array[(x + 1, y + 0, z + 0)] array[(x + 0, y + 1, z + 0)] array[(x + 1, y + 1, z + 0)] array[(x + 0, y + 0, z + 1)] array[(x + 1, y + 0, z + 1)] ar...

Transforming nested list in Python

Assuming I have a structure like this: a = [ ('A', ['D', 'E', 'F', 'G']), ('B', ['H']), ('C', ['I']) ] How can I transform it into: a = [ ('A', 'D'), ('A', 'E'), ('A', 'F'), ('A', 'G'), ('B', 'H'), ('C', 'I'), ] Thanks for your time! ...

pylint not recognizing some of the standard library

I'm using pylint + pydev, with python 2.6. I have a module with just this line of code from email import Message Now when I try to run this module it runs fine. But pylint reports an error: ID: E0611 No name 'Message' in module 'email' Although it exists... Any idea why? ...

zlib decompression in python

Okay so I have some data streams compressed by python's (2.6) zlib.compress() function. When I try to decompress them, some of them won't decompress (zlib error -5, which seems to be a "buffer error", no idea what to make of that). At first, I thought I was done, but I realized that all the ones I couldn't decompress started with 0x78DA ...

Translating human languages in Python

Is there a Python module for the translation of texts from one human language to another? I'm planning to work with texts that are to be pre and post processed with Python scripts. What other Python-integrated approaches can be used? ...