Hi!
I had to remove some fields from a dictionary, the keys of this fields are on a list. So I write this function:
def delete_keys_from_dict(dict_del, lst_keys):
"""
Delete the keys present in the lst_keys from the dictionary.
Loops recursively over nested dictionaries.
"""
dict_foo = dict_del.copy()#Used as iterat...
I wrote a simple script to solve a "logic puzzle", the type of puzzle from school where you are given a number of rules and then must be able to find the solution for problems like "There are five musicians named A, B, C, D, and E playing in a concert, each plays one after the other... if A goes before B, and D is not last ... what is th...
I need to use a thread pool in python, and I want to be able to know when at least 1 thead out or "maximum threads allowed" has finished, so I can start it again if I still need to do something.
I has been using something like this:
def doSomethingWith(dataforthread):
dostuff()
i = i-1 #thread has finished
i = 0
poolSize = 5
t...
Hi there
I wanna list a external webpage's ulr's content. like i wanna list the content of this website example.com/dir/dir/images/
currently i can download an image from a page with urllib.urlretrieve(page_url,save_url )
But I want to list all images in a directory, or anything ells for that matter
I wanna use python
...
My present task is to dissect tcpdump data that includes P2P messages and I am having trouble with the piece data I acquire and write to a file on my x86 machine. My suspicion is I have a simple endian-ness issue with the bytes I write to to file.
I have a list of bytes holding a piece of P2P video read and processed using python-pcapy...
In the code below how match the pattern after "answer" and "nonanswer" in the dictionary
opt_dict=(
{'answer1':1,
'answer14':1,
'answer13':12,
'answer11':6,
'answer5':5,
'nonanswer12':1,
'nonanswer11':1,
'nonanswer4':1,
'nonanswer5':1,})
And
if opt_dict:
for ii in opt_dict:
lo...
Hi folks,
I have a nice admin panel setup so users can manage the data within the site.
Problem is that I need to implement a workflow, so saved models can be approved from and to various stages, to then be finally published.
As the model in question is just one, I thougth of adding a boolean 'approved_for_publishing' field and a 'a...
I'm using xlwt in python to create a Excel spreadsheet. You could interchange this for almost anything else that generates a file; it's what I want to do with the file that's important.
from xlwt import *
w = Workbook()
#... do something
w.save('filename.xls')
I want to I have two use cases for the file: I stream it out to the user's...
How to understand this line?
>>> smtplib.SMTP.mock_returns = Mock('smtp_connection')?
What is smtp_connection? It
seems I can modify it to any name.
following is from minimock
Here's an example of something we might test, a simple email sender:: ...
I'm new to all of this but I've learned a few things about python not long time ago, could you help me specify the correct the XPath for selenium to click?
I've tried this way, but didn't work, obviously :(
self.selenium.click("xpath=//html/body/div/div/div/div[4]/ul/li[3]/a")
If you're wandering where did i get that ugly XPath, it's...
If I have two identical sets, meaning a == b gives me True, will they have the same iteration order? I tried it, and it works:
>>> foo = set("abc")
>>> bar = set("abc")
>>> zip(foo, bar)
[('a', 'a'), ('c', 'c'), ('b', 'b')]
My question is, was I lucky, or is this behavior guaranteed?
...
Having a problem with parsing Snort logs using the pyparsing module.
The problem is with separating the Snort log (which has multiline entries, separated by a blank line) and getting pyparsing to parse each entry as a whole chunk, rather than read in line by line and expecting the grammar to work with each line (obviously, it does not.)...
I find myself using python for a lot of file management scripts as the one below. While looking for examples on the net I am surprised about how little logging and exception handling is featured on the examples. Every time I write a new script my intention is not to end up as the one below but if it deals with files then no matter what m...
Update : For anyone wondering what I went with at the end -
I divided the result-set into 4 and ran 4 instances of the same program with one argument each indicating what set to process. It did the trick for me. I also consider PP module. Though it worked, it prefer the same program. Please pitch in if this is a horrible implementation! ...
I decided to improve my knowledge about python network programming and here is the deal: I have a simple server for Windows, which interacts with a client from a mobile device using wi-fi. Also I have a packet sniffer (Wireshark).
Now I want to ask, what do I need to write the Linux version of this server? How to determine the structure ...
For some reason, every time I attempt to install a new module using easy_install, I'm getting the error:
AttributeError: 'module' object has no attribute '__getstate__'
I'm using setuptools-0.6c11-py2.6
...
I'd like to delete all the files in a given directory on a remote server that I'm already connected to using paramiko. I cannot explicitly give the file names, though, because these will vary depending on which version of file I had previously put there.
Here's what I'm trying to do... the line below the #TODO is the call I'm trying wh...
I would like to parse a string to obtain a list including all words (hyphenated words, too). Current code is:
s = '-this is. A - sentence;one-word'
re.compile("\W+",re.UNICODE).split(s)
returns:
['', 'this', 'is', 'A', 'sentence', 'one', 'word']
and I would like it to return:
['', 'this', 'is', 'A', 'sentence', 'one-word']
...
Here is my code:
toBe =[]
#Check if there is any get request
if request.GET.items() != []:
for x in DB:
try:
#This is removing the PMT that is spcific to the name
if request.GET['pmtName'] != "None":
if not request.GET['pmtName'] in x['tags']:
print x['title'], x['...
I want to make a Django view that does the following:
Receive an HttpRequest on api/some/url/or/other
Passes this through to another server at some/url/or/other (rewrite the URL, basically)
Adding a cookie based on session data in Django
Using the same method, data, params, et al, that were in the original request
Returns verbatim th...