python

problem when zooming pictures in wxpython

hello I need to draw over image (to comment over it) in a scrolled panel. I'm having troubles with it since it doesn't behave right when I zoom it in or out. it stops drawing , and then it shows it after a while in a wrong place. right in the upper left corner of the window. and doesn't draw lines correctly . below is the code for the (o...

Cancel query execution in pyscopg2

Hi, How would one go about cancelling execution of a query statement using pyscopg2 (the python Postgres driver)? As an example, let's say I have the following code: import psycopg2 cnx_string = "something_appropriate" conn = psycopg2.connect(cnx_string) cur = conn.cursor() cur.execute("long_running_query") Then I want to cancel th...

Python Sockets - Creating a message format

I have built a Python server to which various clients can connect, and I need to set a predefined series of messages from clients to the server - For example the client passes in a name to the server when it first connects. I was wondering what the best way to approach this is? How should I build a simple protocol for their communicati...

Django: information leakage problem when using @login_required and setting LOGIN_URL

Hi all, I found a form of information leakage when using the @login_required decorator and setting the LOGIN_URL variable. I have a site that requires a mandatory login for all content. The problem is that you get redirected to the login page with the next variable set when it's a existing page. So when not logged in and asking for: ...

Network Path and Variables in Python

I am new to Python, and thus I am just starting on the basics of the language. I have a question on how to copy a file from a network share to local disk with variables. If I use the following line: shutil.copyfile(r"\\mynetworkshare\myfile.txt","C:\TEMP\myfile.txt") everything works fine. However, what I can't seem to figure out i...

A more pythonic way of iterating a list while excluding an element each iteration

I have the following code: items = ["one", "two", "three"] for i in range(0, len(items)): for index, element in enumerate(items): if index != i: # do something with element Basically I want to exclude every element once and iterate the rest. So for the list I have above, I'd like the following iterations: "t...

compile python .py file without executing

Is there a way to compile a Python .py file from the command-line without executing it? I am working with an application that stores its python extensions in a non-standard path with limited permissions and I'd like to compile the files during installation. I don't need the overhead of Distutils. ...

Problem with embeding python code in html?

NOT SURE ABOUT THIS: I think we cannot embed python code in html like we do with PHP, JSP I have a piece of code I am trying to tamper with. PAGE = urllib.unquote_plus("%3C%21doctype+html+public+%22-%2F%2FW3C%2FDTD+HTML+4.01%2F%2FEN%22+%22http ........ When I view source in the html file, I can see it being neatly displayed. But I am...

DateTimeProperty has error being set to a datetime in Google App Engine

I'm having a weird error with some Google App Engine code I'm writing. My program contains some code like this: import datetime ... class Action(db.Model): visibleDate = db.DateTimeProperty() ... getActionQuery = Action.gql("WHERE user = :user AND __key__ = :key", user = user, key = self.request.get("key")) theAction = getActio...

Find sequences of digits in long integers efficiently

Is it possible to find a defined sequence in an integer without converting it to a string? That is, is it possible to do some form of pattern matching directly on integers. I have not thought of one but I keeping thinking there should be a mathematical way of doing this. That's not to say it is more efficient. (edit) I actually what num...

Traversing an unusual tree in Python

I have an unusual tree array like this: [[0, 1], [1, 2], [2, 3], [2, 4], [2, 5], [5, 6], [4, 6], [3, 6], [0, 7], [7, 6], [8, 9], [9, 6]] Each element of the array is a pair, which means second one is a follower of the first, e.g.: [0, 1] - 0 is followed by 1 [1, 2] - 1 is followed by 2 I am trying to extract array like this: 0 ...

Scripting HTTP more effeciently

Often times I want to automate http queries. I currently use Java(and commons http client), but would probably prefer a scripting based approach. Something really quick and simple. Where I can set a header, go to a page and not worry about setting up the entire OO lifecycle, setting each header, calling up an html parser... I am looking ...

Could not get cookie from another (parent) domain in Django

Hi All! I need to remove a cookie that was previously set for parent domain while browsing host at subdomain of the parent. I.e., a cookie "xyz" was set for example.com, and I am trying to remove it on subdomain.example.com, using Django backend. The request.COOKIES given to the view does not contain any cookies except those from subd...

How can I support * in user-defined search strings in python?

This question is related to this stack overflow question: http://stackoverflow.com/questions/238600/how-can-i-support-wildcards-in-user-defined-search-strings-in-python But I need to only support the wildcards and not the ? or the [seq] functionality that you get with fnmatch. Since there is no way to remove that functionality from fn...

Executing Python multi-line statements in the one-line command-line

I'm using python -c to execute a one-liner loop, i.e.: $ python -c "for r in range(10): print 'rob'" this works fine. However, if I import a module before the for loop, I get a syntax error: $ python -c "import sys; for r in range(10): print 'rob'" File "<string>", line 1 import sys; for r in range(10): print 'rob' ...

There's an example on how to use an API with Python and cURL. Is it feasable to just copy the code if I have IronPython installed and have it work?

Here's the code in question: #!/usr/bin/python import pycurl c = pycurl.Curl() values = [ ("key", "YOUR_API_KEY"), ("image", (c.FORM_FILE, "file.png"))] # OR: ("image", "http://example.com/example.jpg"))] c.setopt(c.URL, "http://imgur.com/api/upload.xml") c.setopt(c.HTTPPOST, values) c.perform() c.close() I...

Tracking system and real time stats analysis in Python

This question is related to an older question: http://stackoverflow.com/questions/2019096/mysql-tracking-system. In short: I have to implement a tracking system that will have high loads using Python. For the database part I've settled on mongoDB (which sounds like the right tool for this job). The development language will be Python. ...

Using win32com and/or active_directory, how can I access an email folder by name?

In python w/ Outlook 2007, using win32com and/or active_directory, how can I get a reference to a sub-folder so that I may move a MailItem to this sub-folder? I have an inbox structure like: Inbox | +-- test | `-- todo I can access the inbox folder like: import win32com.client import active_directory ses...

Using win32com and/or active_directory, how can I change the conversation of a MailItem?

In Python w/ Outlook 2007, using win32com and/or Active Directory, how can I change the conversation of an email? Is there a way to change the mapping of a ConversationIndex to a ConversationTopic? I can successfully change the subject of a MailItem by creating a new MailItem, but when I view the folder in "Conversation" view mode, the...

NetBeans and Python

When I run some python code in NetBeans, which raises an error, the output in NetBeans just gives an error message and no further information, such as line number. Is there any way to fix that? ...