python

loop through list of dictionaries

hello! i have a list of dictionaries. there are several points inside the list, some are multiple. When there is a multiple entry i want to calculate the average of the x and the y of this point. My problem is, that i don't know how to loop through the list of dictionaries to compare the ids of the points! when i use something like tha...

TurboMail 3 with Pylons 1.0 - MailNotEnabledException

I am trying to setup TurboMail 3 with Pylons 1.0 Followed the docs here I have added this to the development.ini [DEFAULT] ... mail.on = true mail.manager = immediate mail.transport = smtp mail.smtp.server = localhost and my app_globals.py looks like: """The application's Globals object""" from beaker.cache import CacheManager f...

Multiple drag and drop in PyQt4

Hi, i can't find an example on dragging (and dropping) multiple elements with Qt/PyQt; In my case i need to drag elements from this QTableView: class DragTable(QTableView): def __init__(self, parent = None): super(DragTable, self).__init__(parent) self.setDragEnabled(True) def dragEnterEvent(self, event): ...

Using built-in type(,,) function to create a dynamic module

I'm trying to use the type(,,) function to dynamically build a module. The module creates classes representing templates, and I need a new class for every .tex file that lives in a particular folder. For instance, if I have a a4-page-template.tex file, I need to create a class called A4PageTemplate. I can create the type easily enough u...

cgal python exception

from CGAL.Kernel import * raises an exception as follows: File "C:/Python26/Lib/site-packages/cgal\CGAL\__init__.py", line 1, in <module> from Kernel import * ImportError: No module named Kernel What could the reasons be? thanks ...

python mysqldb timestamp/unix_timestamp issue

trying to understand the subtleties of inserting data into a mysql tbl when dealing with unix_timestamp, and the timestamp def within the tbl using python v2.6, using the mysqldb lib i'm consistently getting the err/warning: TypeError: not all arguments converted during string formatting the test tbl looks like: DROP TABLE IF EXISTS ...

Timed out after 30000ms

Hi everyone, When I use SeleniumRC,sometimes I meet a error, but sometimes not. I guess it's related to the time of wait_for_page_to_load(), but I don't know how long will it need? The error information: Exception: Timed out after 30000ms File "C:\Users\Herta\Desktop\test\newtest.py", line 9, in <module> sel.open(url) File "C:\Users...

python code problem

i have this code: class Check(webapp.RequestHandler): def get(self): user = users.get_current_user() be = "SELECT * FROM Benutzer ORDER BY date " c = db.GqlQuery(be) for x in c: if x.benutzer == user: s=1 break else: s=2 if s is 0: self.redirect('/') to check whether th...

paramiko SFTP hangs on get

I'm trying to use paramiko to get a file via SFTP. It connects, I can list directories and it even downloads the first megabyte or so of the file but then it just hangs. No exception, no error, nothing. It just hangs there indefinitely. Here's the code I'm working with: import paramiko t = paramiko.Transport( host ) t.connect( username...

Why does Cassandra act strange with byte keys (with Lazyboy) ?

Hello, I wrote a test program for testing Cassandra, and I had problems reading data. Seems like Cassandra sometimes takes one key for another. Here is my test program : from lazyboy import * from lazyboy.key import Key import uuid import random class TestItemKey(Key): def __init__(self, key=None): Key.__init__(self, "TestMX...

Create List of Single Item Repeated n Times in Python

I know a list comprehension will do this, but I was wondering if there is an even shorter (and more Pythonic?) approach. I want to create a series of lists, all of varying length. Each list will contain the same element e, repeated n times (where n = length of the list). How do I create the lists, without doing [e for number in xrange(...

ERROR:Couldn't find form element in any form int the page! Init aborted

Hi. I have a page written in python and I also have dynamic drop down lists (select form fields). When I run it I get the error: ERROR:Couldn't find form element in any form DEPT the page! Init aborted Anyone know what this means? Should I have the name of my form be DEPT? ...

I know I'm supposed to keep Python code to 79 cols, but how do I indent continuations of lines?

I am aware that the standard Python convention for line width is 79 characters. I know lines can be continued in a number of ways, such as automatic string concatenation, parentheses, and the backslash. What does not seem to be as clearly defined is how exactly the overflowing text should be formatted. Do I push it all the way back to co...

Django: Is there a way to set global views? For example enable data for a sidebar through all URLS

Hello I am building a Django application that is a pretty basic blog, so far it has been wonderful. I got comments, tags etc up. But one thing is bugging me: I cant get the sidebar i want to work. I use the django.views.generic.date_based generic view and this is my urls.py for the blog: urlpatterns = patterns('django.views.generi...

Converting (part of) a numpy recarray into a 2d array?

We've got a set of recarrays of data for individual days - the first attribute is a timestamp and the rest are values. Several of these: ts a b c 2010-08-06 08:00, 1.2, 3.4, 5.6 2010-08-06 08:05, 1.2, 3.4, 5.6 2010-08-06 08:10, 1.2, 3.4, 5.6 2010-08-06 08:15, 2.2, 3.3, 5.6 2010-08-06 08:20, 1.2, 3.4, 5.6 We'd l...

How to lock django command for single run. Django. Python.

How to lock django commands so it will not run twise in the same time? ...

Is it possible to make Python functions behave like instances?

I understand that functions can have attributes. So I can do the following: def myfunc(): myfunc.attribute += 1 print(myfunc.attribute) myfunc.attribute = 1 Is it possible by any means to make such a function behave as if it were an instance? For example, I'd like to be able to do something like this: x = clever_wrapper(myfu...

subprocess.Popen() has inconsistent behavior between Eclipse/PyCharm and terminal execution

The problem I'm having is with Eclipse/PyCharm interpreting the results of subprocess's Popen() differently from a standard terminal. All are using python2.6.1 on OSX. Here's a simple example script: import subprocess args = ["/usr/bin/which", "git"] print "Will execute %s" % " ".join(args) try: p = subprocess.Popen(["/usr/bin/which...

Django/Python resize image

Hello. I have a image from files = request.FILES['new_photo'].read() and i want to know it's size and possibly resize it. How i can do it? thanks. UPD before. i read() file and gave this string and some info? to SQL function. And she save it on ftp. how i can get data same as the data returned from read() method? i try to use ...

Remove Adjacent Duplicate Elements from a List

Google Python Class | List Exercise - Given a list of numbers, return a list where all adjacent == elements have been reduced to a single element, so [1, 2, 2, 3] returns [1, 2, 3]. You may create a new list or modify the passed in list. My solution using a new list is - def remove_adjacent(nums): a = [] for item in ...