Detecting the http request type (GET, HEAD, etc) from a python cgi
Hi, How can I find out the http request my python cgi received? I need different behaviors for HEAD and GET. Thanks! ...
Hi, How can I find out the http request my python cgi received? I need different behaviors for HEAD and GET. Thanks! ...
I have two django model classes: class A(models.Model): name = models.CharField(max_length = 128) #irrelevant class B(models.Model): a = models.ManyToManyField(A) name = models.CharField(max_length = 128) #irrelevant What I want to do is the following: a1 = A() a2 = A() b = B() b.a.add(a1) b.a.add(a1) #I wan...
I'm trying to access a SOAP API using Suds. The SOAP API documentation states that I have to provide three cookies with some login data. How can I accomplish this? ...
Hey, any idea about what is the timeout error which I am getting here: Error trace: File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/_cprequest.py", line 606, in respond cherrypy.response.body = self.handler() ...
My application creates custom URIs (or URLs?) to identify objects and resolve them. The problem is that Python's urlparse module refuses to parse unknown URL schemes like it parses http. If I do not adjust urlparse's uses_* lists I get this: >>> urlparse.urlparse("qqqq://base/id#hint") ('qqqq', '', '//base/id#hint', '', '', '') >>> url...
I am writing a screen scraper script in python with module 'mechanize' and I would like to use the mechanize.click_link() method on a link that has javascript:__doPostBack in href. I believe the page I am trying to parse is using AJAX. Note: mech is the mechanize.Browser() >>> next_link.__class__.__name__ 'Link' >>> next_link Link(bas...
I want to embed python in my C++ application. I'm using Boost library - great tool. But i have one problem. If python function throws an exception, i want to catch it and print error in my application or get some detailed information like line number in python script that caused error. How can i do it? I can't find any functions to ge...
Hi, i'm trying to write a very simple django app. I cant get it to show my form inside my template. <form ...> {{form.as_p}} </form> it shows absolutely nothing. If I add a submit button, it only shows that. Do I have to declare a form object that inherits from forms.Form ? Cant it be done with ModelForms? [UPDATE]Solved! (apologi...
Hey. I have a problem I'm trying to solve in Python and I can't think of a clever implementation. The input is a string of letters. Some of them represent variables, others represent operators, and I want to iterate over a large amount of values for the variables (different configurations). I think an equivalent question would be that y...
Can't figure this out. In Terminal, I import a module which instantiates a class, which I haven't figured out how to access. Of course, I can always instantiate in Terminal: Server=Data.ServerData() Then I can get a result: Server.Property().DefaultChart However, I want to skip that step getting the result directly from the insta...
I'm removing an item from an array if it exists. Two ways I can think of to do this Way #1 # x array, r item to remove if r in x : x.remove( r ) Way #2 try : x.remove( r ) except : pass Timing it shows the try/except way can be faster (some times i'm getting:) 1.16225508968e-06 8.80804972547e-07 1.14314196588e-06 8.73...
Sorry if this is on the wrong site ( maybe superuser ) but I'm trying to make my python.py file executable so I can click on it and it automatically does its thing, without me specifying it to open in the terminal by that default prompt, and I already have 'chmod +x' for its permissions. Clarification: I want to run it by clicking on ...
As the title states, how expensive are Python dictionaries to handle? Creation, insertion, updating, deletion, all of it. Asymptotic time complexities are interesting themselves, but also how they compare to e.g. tuples or normal lists. ...
Could someone please give me a complete list of those special methods that you can put in classes, e.g. a couple are __len__ and __add__, but what are the rest? Thanks. ...
I was having some trouble grokking the list comprehension syntax in Python, so I started thinking about how to achieve the same thing in Perl, which I'm more familiar with. I realized that the basic examples (taken from this page) can all be done in Perl with map or grep. E.g. (python) (perl) ...
A pretty silly trivial question. The canonical example is f = open('filename'), but f is not very descriptive. After not looking at code in a while, you can forget whether it means "file" or "function f(x)" or "fourier transform results" or something else. EIBTI. In Python, file is already taken by a function. What else do you use...
Could someone explain the differences to me? Aren't all arguments "keyword arguments"? They all have names, and can all be assigned by that name instead of the position. Do keyword arguments mean ones with default values? (Note: I'm talking about pure python, no C) Thanks. EDIT: I just realized there's two types of each: def func(*arg...
I am writing a python extension that seems to be leaking memory. I am trying to figure out the soure of the problem using valgrind. However, it seems that python itself is leaking memory according to valgrind. Using the following simple script: hello.py print "Hello World!" and doing > valgrind --tool=memcheck python ./hello.py...
I am using a library function called get_count_and_price which returns a 2-tuple (count,price). In many places I use both time and price. However, in some I only need time or price. So right now, if I only need count, I assign to (count,price) and leave the price unused. This works great and causes no trouble in and of itself. However....
I'm not sure what's going on, but on my own laptop, everything works okay. When I upload to my host with Python 2.3.5, my views.py can't find anything in my models.py. I have: from dtms.models import User from dtms.item_list import * where my models, item_list, and views files are in /mysite/dtms/ It ends up telling me it can't find ...