python

Django index page best/most common practice.

I am working on a site currently (first one solo) and went to go make an index page. I have been attempting to follow django best practices as I go, so naturally I go search for this but couldn't a real standard in regards to this. I have seen folks creating apps to serve this purpose named various things (main, home, misc) and have see...

Syntax quirks or why is that valid python

In python 2.6, why is the following line valid? my_line = 'foo' 'bar' and if that is valid, why isn't the following: my_list = 1 2 The first example is string concatenation, however, the following isn't valid either (thanks god): foo = 'foo' bar = 'bar' foo_bar = foo bar ...

How does/should global data in modules across packages be managed in Python/other languages?

I am trying to design the package and module system for a programming language (Heron) which can be both compiled and interpreted, and from what I have seen I really like the Python approach. Python has a rich choice of modules, which seems to contribute largely to its success. What I don`t know is what happens in Python if a module is ...

howto scroll a gtk.scrolledwindow object from python code

I'm writing a python application that has a glade gui. Using subprocess to execute some shell commands in the background. Using a glade GUI which has a scrolledwindow widget and a textview widget inside the scrolledwindow widget. The textview gets populated as the subprocess.Popen object run and display their stdout and stderr to this t...

Upper limit in Python time.sleep()?

Is there an upper limit to how long you can specify a thread to sleep with time.sleep()? I have been having issues with sleeping my script for long periods (i.e., over 1k seconds). This issue has appeared on both Windows and Unix platforms. ...

Redirect with additional variables

Hello. I have view which in some cases redirects user to another addres. How can I redirect user, with additional variables (not GET, beacause that variable can be long text)? Currently I'm using HttpResponseRedirect. Cheers. ...

Is there a python hamcrest matcher library for performing XML document matching?

I'm interested in both xpath matching and full document comparisons: assert_that(mydoc, hasTextAtXPath('/foo/bar', 'text')) assert_that(mydoc, matchesStructurally('<some_xml/>')) Does any matcher library exist for this? If not, what is the best place to start with for this type of comparison, so that I can write one of my own? ...

Why does Django throw an exception whenever I enable admin.autodiscover()?

Here is my setup. I am using Django version 1.1.1 on Dreamhost, Python 2.4. The problem I am having is whenever I create a simple app and also have admin.autodiscover() enabled, Django will throw an exception. My setup: from django.conf.urls.defaults import * from testapp.views import HelloWorld from django.contrib import admin admin.a...

Python, Huge Iteration Performance Problem

Hi I'm doing an iteration through 3 words, each about 5 million characters long, and I want to find sequences of 20 characters that identifies each word. That is, I want to find all sequences of length 20 in one word that is unique for that word. My problem is that the code I've written takes an extremely long time to run. I've never ev...

How can I debug a problem calling Python's copy.deepcopy() against a custom type?

In my code I'm trying to take copies of instances a class using copy.deepcopy. The problem is that under some circumstances it is erroring with the following error: TypeError: 'object.__new__(NotImplementedType) is not safe, use NotImplementedType.__new__()' After much digging I have found that I am able to reproduce the error using ...

Creating a new virtualenv results in an error.

Hi, I'm trying to get virtualenv to work on my machine. I'm using python2.6, and after installing pip, and using pip to install virtualenv, running "virtualenv --no-site-packages cyclesg" results in the following: New python executable in cyclesg/bin/python Installing setuptools.... Complete output from command /home/nubela/Workspace...

Convert an RFC 3339 time to a standard Python timestamp

Is there an easy way to convert an RFC 3339 time into a regular Python timestamp? I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file. I notice from the ATOM spec, that ATOM dates include a time zone offset (Z<a number>) but, in ...

How to import constants from .h file into python module

Hello! What is a recommended way to import a bunch of constants defined in a c-style (not c++, just plain old c) .h file into python module so that it can be used in python's part of a project. In the project we use a mix of languages and in perl I can do this importing by using h2xs utility to generate .pm module. Constants definitio...

Python 3: create a list of possible ip addresses from a CIDR notation.

I have been handed the task of creating a function in python (3.1) that will take a CIDR notation and return the list of possible ip addresses. I have looked around python.org and found this: http://docs.python.org/dev/py3k/library/ipaddr.html but i haven't seen anything that will fill this need... I would be very grateful for any assi...

Recommended Schooling / Certification for an impoverished programmer

Hello, I am currently a high school senior who's been programming mainly in Python for about 4 years now (& some XHTML, CSS, Javacript). I have worked as a programmer/circuit designer for about 2 years at a local small business (paid almost nothing). However, I have no real certification or schooling in programming. So, the only educ...

String class internals - caching character offset to byte relationship if using UTF-8

When writing a custom string class that stores UTF-8 internally (to save memory) rather than UTF-16 from scratch is it feasible to some extent cache the relationship between byte offset and character offset to increase performance when applications use the class with random access? Does Perl do this kind of caching of character offset t...

how to properly destroy gtk.Dialog objects/widgets

Noob @ programming with python and pygtk. I'm creating an application which includes a couple of dialogs for user interaction. #!usr/bin/env python import gtk info = gtk.MessageDialog(type=gtk.DIALOG_INFO, buttons=gtk.BUTTONS_OK) info.set_property('title', 'Test info message') info.set_property('text', 'Message to be displayed in the m...

Wrapping a C library in Python: C, Cython or ctypes?

I want to call a C library from a Python application. I don't want to wrap the whole API, only the functions and datatypes that are relevant to my case. As I see it, I have three choices: Create an actual extension module in C. Probably overkill, and I'd also like to avoid the overhead of learning extension writing. Use Cython to expos...

anyone have example python code that sends mail using sendmail and subprocess?

I'm kind of confused about how subprocess.Popen works. If anyone has example code that sends email using the subprocess module and sendmail that'd be great. ...

ctypes WriteProcessMemory() fails, help!

I have been trying to get this function working for some time now with no luck. def write_memory(self, address, data): PROCESS_ALL_ACCESS = 0x001F0FFF count = c_ulong(0) length = len(data) c_data = c_char_p(data[count.value:]) null = c_int(0) windll.kernel32.SetLastError(10000) if not windll.kernel32.WritePro...