python

python+win32: detect window drag

Is there a way to detect when a window that doesn't belong to my application is being dragged in windows using python/pywin32? I want to set it up so that when I drag a window whose title matches a pattern near the desktop edge, it snaps to the edge when the mouse is let go. I could write code to snap all windows with that title to the d...

Python: tree structure and numerical codes?

I'm using Python and I have some data that I want to put into a tree format and assign codes to. Here's some example data: Africa North Africa Algeria Africa North Africa Morocco Africa West Africa Ghana Africa West Africa Sierra Leone What would be an appropriate tree structure for this data? Also, is there...

Help converting Python app to C#

Everyone, here is a link to a small python app: http://en.wikipedia.org/wiki/File:Beta-skeleton.svg I think I've correctly converted it. (Source at bottom of post) But, the Math.Acos always returns NaN. Is there a difference between the python version of acos and Math.Acos? private Random rnd = new Random(); private double ...

shopify xml request from GAE python

I'm trying to make requests to the shopify.com API over GAE python the url i have to request is not formed in the usual format. it is composed like http://apikey:password@hostname/admin/resource.xml with urllib I can request it but i cant set the headers for an xml request so it doesn't work. urllib2, httplib... are having problems wi...

Scheduling a time in the future to send an email in Java or Python

I'm writing an application and I'd like it to somehow schedule an email to be sent at a later date (likely an hour after it is run). The programming language will be Python or Java. Any open-source tools available for that purpose? EDIT: I forgot to mention it's to be run after a test run, so the application will already be down and I ...

Python or SQL Logistic Regression

Given time-series data, I want to find the best fitting logarithmic curve. What are good libraries for doing this in either Python or SQL? Edit: Specifically, what I'm looking for is a library that can fit data resembling a sigmoid function, with upper and lower horizontal asymptotes. ...

'from sqlite3 import dbapi2 as sqlite3' vs 'import sqlite3'?

When I see the examples for pysqlite, there are two use cases for the SQLite library. from sqlite3 import dbapi2 as sqlite3 and import sqlite3 Why there are two ways to support the sqlite3 api? What's the difference between the two? Are they the same? In normal use, which would be preferred. ADDED I knew that they are different ...

The open/close function of SQLite implementation

I'm trying to come up with SQLiteDB object, and following is the open/close code for it. Does this work without problem? Am I missing something important? For close(), I use con.close() and cursor.close(), but I'm wondering if cursor.close() is necessary. class SQLiteDB(object): def __init__(self, dbFile, connect = True): ...

Declare function at end of file in Python.

Greetings StackOverflow, Is it possible to call a function without first fully defining it? When attempting, i get the error: "*function_name* is not defined". I am coming from a c++ background so this issue stumps me. Declaring the function before works: def Kerma(): return "energy / mass" print Kerma() However, atte...

Need code to return directory name only

I am a python newbie and have obtained a script that lets the user input a directory where shapefiles are located (ex., c:\programfiles\shapefiles). It then creates a field within each shapefile and adds the directory path that was input and the shapefile name (ex., c:\programfiles\shapefiles\name.shp). I would like to populate the field...

Ruby To Python Syntax Confusion

I'm trying to convert someone's Ruby code into my Python code. The originally developer is no longer with us and I don't know Ruby. Most of his code is easy enough to follow, but some of the following syntax is tripping me up. Example: myTable = '' myTable << [ 0, 1, 0, 0, 0, 300].pack('vvvvvv') ...

running PIL on 64bit

Is there any way of running PIL(Python Imaging Library) on a 64bit OS? it is windows 7 64bit ...

a basic question about "while true"

level: beginner def play_game(word_list): hand = deal_hand(HAND_SIZE) # random init while True: cmd = raw_input('Enter n to deal a new hand, r to replay the last hand, or e to end game: ') if cmd == 'n': hand = deal_hand(HAND_SIZE) play_hand(hand.copy(), word_list) print ...

Multithreaded repeater in Python

I have small repeater Below that keeps ending, How can fix so more stable from crashes, and not stop running.... I would I add a heartbeat to the gui to see that its still running. In Wxpthon, my menu bar goes blank or white. def TimerSetup(): import threading, time invl = 300 def dothis(): try: ...

How to copy directory permissions

Hey, I'm curious how to copy the permission from directory to another. Any idea? Thanks ...

How to wrap a c++ vector of vector with SWIG.

Hi, I'm using SWIG to wrap C++ code to Python code. I'm trying to wrap a vector of vectors. The method is: std::vector<std::vector<MyClass*>*> GetMyClassVectorOfVectors(); I'm able to wrap the first vector without adding lines to the file "MyAplication.i": The method is std::vector<MyClass*> GetMyClassVector(); And this is working...

Saving a StackedInline foreign keyed model before primary model in Django Admin

I have four models with the relationships Model PagetTemplate(models.Model): pass Model TextKey(models.Model): page_template = models.ForeignKey(PageTemplate, related_name='text_keys') Model Page(models.Model): page_template = models.ForeignKey(Pagetemplate, related_name='pages') Model Text(models.Model): key = model...

Pythonic way to check if a list is sorted or not

Is there a pythonic way to check if a list is already sorted in AESC or DESC. listtimestamps=[1,2,3,5,6,7] something like listtimestamps.isSorted() that returns True or False. EDIT: I want to input a list of timestamps for some messages and check if the the transactions appeared in the correct order. and I can write a custom function...

Django newbie question regarding defining an object with subobjects from models for use in templates

I am somewhat new to Django and have searched for some simple examples of creating objects with subobjects in views so that in templates I can have nested for loops. Here is my models.py for this application... from django.db import models from django import forms class Market(models.Model): name = models.CharField('Market name'...

How to use a generator to iterate over a tree's leafs

The problem: I have a trie and I want to return the information stored in it. Some leaves have information (set as value > 0) and some leaves do not. I would like to return only those leaves that have a value. As in all trie's number of leaves on each node is variable, and the key to each value is actually made up of the path necessary...