22
votes
2answers
8k views

Python: How to “perfectly” override a dict

How can I make as "perfect" a subclass of dict as possible? The end goal is to have a simple dict in which the keys are lowercase. It would seem that should be some tiny set of primitives I can ...
9
votes
3answers
11k views

Understanding .get() method in python

sentence = "The quick brown fox jumped over the lazy dog." characters = {} for character in sentence: characters[character] = characters.get(character,0) + 1 print(characters) I don't ...
8
votes
2answers
6k views

Python-Scapy or the like-How can I create an HTTP GET request at the packet level

I am a moderate programmer, just getting into network programming. As an attempt to improve my understanding of networks in general, I am trying to perform several basic HTTP actions from the packet ...
8
votes
2answers
5k views

Making HTTP requests via Python Requests module not working via proxy where curl does? Why?

Using this curl command I am able to get the response I am looking for from Bash curl -v -u z:secret_key --proxy http://proxy.net:80 \ -H "Content-Type: application/json" ...
6
votes
1answer
3k views

Getting HTTP GET arguments in Python

I'm trying to run an Icecast stream using a simple Python script to pick a random song from the list of songs on the server. I'm looking to add a voting/request interface, and my host allows use of ...
5
votes
4answers
488 views

PHP: get array value as in Python?

In Python I can use "get" method to get value from an dictionary without error. a = {1: "a", 2: "b"} a[3] # error a.get(3, "") # I got empty string. So I search for a common/base function that do ...
5
votes
2answers
349 views

I want to retrieve multiple logs from a server with minimum lines of code

I would like to retrieve multiple log files from an Ubuntu server (using Python 2.7 on win 7 machine) without having to write verbose, repetitive code. I'm sure I can use a loop to accomplish this, ...
4
votes
3answers
5k views

python dict: get vs setdefault

Please excuse if this has been asked before, I wasn't able to find it via the search. The following two expressions seem equivalent to me. Which one is preferable? data = [('a', 1), ('b', 1), ('b', ...
4
votes
3answers
2k views

python. how to get attribute value with libxml2

I was using MINIDOM but it does not provide xpath methods. I am now trying to use libxml2 but I am having trouble retrieving attribute values. An extract of my xml looks as follow: <Class ...
3
votes
1answer
932 views

Why does Python's urlparse.parse_qs() split arguments on semicolon

I'm writing a test script in Python to check the output of my PHP application and I've got a problem with Python's urlparse.parse_qs() function. GET string delimiter (AFAIK) is an ampersand. The ...
3
votes
3answers
207 views

GAE ValueError with GET parameters

I am trying to create a simple application to return the remainder given two inputs from GET parameters. These inputs will be taken from the url query. For example ...
3
votes
2answers
657 views

Specify request method with urllib2?

This code produces a POST request: urllib2.urlopen("http://somedomain.com/", data) I would like to produce a GET request - any ideas on how to do that? Thanks for the help!
3
votes
1answer
445 views

Python URL parameters

I'm trying to build a simple URL shortener in Python. Save the URLs is easy using a GET request (with the cgi.FieldStorage() method), something like: ...
2
votes
2answers
8k views

Python Web Crawlers and “getting” html source code

So my brother wanted me to write a web crawler in Python (self-taught) and I know C++, Java, and a bit of html. I'm using version 2.7 and reading the python library, but I have a few problems 1. ...
2
votes
3answers
4k views

What is the syntax for adding a GET parameter to a URL? python; google app engine

I need to get access to certain webpage by adding some elements to the url. What is the syntax for adding a get parameter to a url?

1 2 3 4 5 9
15 30 50 per page