python

Cookies and HTTP with Python

I wish to "retrieve" the cookies sent by the client in my subclass of BaseHTTPRequestHandler. Firstly I'm unsure of the exact sequence of sending of headers, in a typical HTTP request and response this is my understanding of the sequence of events: Client sends request (method, path, HTTP version, host, and ALL headers). The server re...

django error when i signup my site . why ?????

thanks this is the signup view: def signup(request, form_class=SignupForm, template_name="account/signup.html", success_url=None): if success_url is None: success_url = get_default_redirect(request) if request.method == "POST": form = form_class(request.POST) if form.is_valid(): use...

How do I generate coverage xml report for a single package?

I'm using nose and coverage to generate coverage reports. I only have one package right now, ae, so I specify to only cover that: nosetests -w tests/unit --with-xunit --with-coverage --cover-package=ae And here are the results, which look good: Name Stmts Exec Cover Missing -----------------------------------------...

[PyGTK] How can I show a widget and all its parent containers?

In my program, there is a point where all widgets are hidden. Is there a simple way to show a widget and all of its parent containers? I am not able to use show_all(), because that would show other widgets that I don't want shown. I could go down the containers and show them all, but I would prefer not to if there is a more concise solut...

PyQt4: Hide widget and resize window

Hi everyone: I'm working with several widgets but the solution just won't come out. What I have is a series of buttons in series of QHBoxLayouts. Some buttons are hidden by default, but they will appear when needed. To solve space issues, all buttons have a minimum and maximum size so they always look well packed. Also I have a QTextEdi...

How can I replace double and single quotations in a string efficiently ?

I'm parsing a xml file and inserting it into database. However since some text containes double or single quotation I'm having problem with insertion. Currently I'm using the code shown below. But it seems it's inefficient. s = s.replace('"', ' ') s = s.replace("'", ' ') Is there any way I can insert text without replacing these quota...

How do I define an array of custom types in WSDL?

I'm very new to WSDL, but what I'm trying to do is very simple. I have gotten a web service working with python's ZSI library, but am stuck defining a service which returns an array of a custom type. In my WSDL I have the following: <xsd:element name="ArtPiece"> <xsd:complexType> <xsd:sequence> <xsd:element name="tit...

Django: Using django.contrib.auth for SAAS ( Users, permissions, etc. )

I'm making a SAAS and I've been asking a slew of questions on here related to the Auth system built in. I'm having trouble understanding the "why" and "how". Primarily I don't understand how it fits in with my SAAS. I (do) know the following: You can do this: http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-informa...

How do I create a list or set object in a class in Python?

For my project, the role of the Lecturer (defined as a class) is to offer projects to students. Project itself is also a class. I have some global dictionaries, keyed by the unique numeric id's for lecturers and projects that map to objects. Thus for the "lecturers" dictionary (currently): lecturer[id] = Lecturer(lec_name, lec_id, ma...

Python Lambda behaviour

I'm trying to get my head around lambda expressions, closures and scoping in Python. Why does the program not crash on the first line here? >>> foo = lambda x: x + a >>> foo(2) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 1, in <lambda> NameError: global name 'a' is not defined >>> a = ...

Issue with python class hierarchy

I have a class hierarchy: class ParentClass: def do_something(self): pass # child classes have their own implementation of this class ChildClass1(ParentClass): def do_something(self): <implementation here> class ChildClass2(ParentClass): def do_something(self, argument_x): <implementation here> ...

Deferred evaluation in python

I have heard of deferred evaluation in python (for example here), is it just referring to how lambdas are evaluated by the interpreter only when they are used? Or is this the proper term for describing how, due to python's dynamic design, it will not catch many errors until runtime? Or am I missing something entirely? ...

Position of a character

Hi all, How can i get the position of a character in a string in python. regards Arun ...

'ASCII' to Unicode error in python when attempting to read a latin-1 encoded string

Hi All- I'm having a problem when trying to apply a regular expression to some strings encoded in latin-1 (ISO-8859-1). What I'm trying to do is send some data via HTTP POST from a page encoded in ISO-8859-1 to my python application and do some parsing on the data using regular expressions in my python script. The web page uses jQuer...

Python : How to plot 3d graphs using Python?

I am using matplotlib for doing this from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib import matplotlib.pyplot as plt fig = plt.figure() ax = Axes3D(fig) x = [6,3,6,9,12,24] y = [3,5,78,12,23,56] ax.plot(x, y, zs=0, zdir='z', label='zs=0, zdir=z') plt.show() Now this builds a graph that is horizontal in...

how do i get the username who login use openid ,i use django,pinax

1. 2 3. in this example,my username is zjm1126 ,and my email is [email protected], i want to get this. and this is my django-plug-in in this project: ...

how to write integer number in particular no of bytes in python ( file writing)

assume i have to store few integer numbers like 1024 or 512 or 10240 or 900000 in a file, but the condition is that i can consume only 4 bytes (not less nor max).but while writing a python file using write method it stored as "1024" or "512" or "10240" ie they written as ascii value but i want to store directly their binary value. Any h...

assign multiple instances of a class to variables

Python. I need to assign multiple class instances to number of variables. First i tried this: a = b = c = [] but they all refer to the same object, which is not what I need. This works better: (a, b, c) = [[] for i in range(3)] but it seems a bit too verbose. Is there a shorter way to do this? UPDATE: OK, so this is not really Pyt...

Replace a whole line in a file

Hi, I have a .txt file containing data like this: 0,Rent1,Expense,16/02/2010,1,4000,4000 0,Car Loan1,Expense,16/02/2010,2,4500,9000 0,Flat Loan1,Expense,16/02/2010,2,4000,8000 0,Rent2,Expense,16/02/2010,1,4000,4000 0,Car Loan2,Expense,16/02/2010,2,4500,9000 0,Flat Loan2,Expense,16/02/2010,2,4000,8000 Now i want to replace ...

Maintaining session in an Eventlet page scraper?

Hello, I'm trying to do some scraping of a site that requires authentication (not http auth). The script I'm using is based on this eventlet example. Basically, urls = ["https://mysecuresite.com/data.aspx?itemid=blah1", "https://mysecuresite.com/data.aspx?itemid=blah2", "https://mysecuresite.com/data.aspx?itemid=blah3"] impo...