python

How do I apply a patch from gist to the Django source?

I want to try out a patch on gist that modifies the source code of Django: gist: 550436 How do I do it? I have never used git so a step by step instruction would be greatly appreciated. Thanks ...

Python: Error --> setting an array element with a sequence

The data-element is a float-number and no sequence (I think). But I get the error "setting an array element with a sequence". folder = r"C:\Dokumente und Einstellungen\ssc" contents=os.listdir(folder) ar = zeros((81,81,256),int) filenumber = 0 for d in contents: if str(".bin") in d: filename = os.path.join("C:\\Dokumente u...

error while trying to connect with a cisco 2600 router through python in windows

The code i have given is import telnetlib HOST="X" user ="X" password="X" en_password="x" tn=telnetlib.Telnet(HOST) Traceback (most recent call last): File "<pyshell#15>", line 1, in <module> tn=telnetlib.Telnet(HOST) File "C:\Python27\lib\telnetlib.py", line 209, in __init__ self.open(host, port, ti...

How to pass a variable from the url to a view in django?

Hi there, Simple question. How can I pass a variable from the URL to the view? I'm following the Date Example. My view needs to arguments: def hours_ahead(request, offset): My url.py has this" (r'^plus/\d{1,2}/$', hours_ahead), I know I need to pass another argument through but I don't know how to get the number from the URL st...

Compare result from hexdigest() to a string

I've got a generated MD5-hash, which I would like to compare to another MD5-hash from a string. The statement below is false, even though they look the same when you print them and should be true. hashlib.md5("foo").hexdigest() == "acbd18db4cc2f85cedef654fccc4a4d8" Google told me that I should encode the result from hexdigest(), since...

how to check list is none in python

l=[None,None] i want to know is there any function to check list l is None or not..... ...

How to properly add quotes to a string using python?

I want to add a set of (double) quotes to a python string if they are missing but the string can also contain quotes. The purpose of this is to quote all command that are not already quoted because Windows API requires you to quote the entire command line when you execute a process using _popen(). Here are some strings that should be q...

Overriding __new__ and __init__ in Python

Possible Duplicate: Python's use of new and init ? The way I understand it, __init__ is different from a constructor in Java, because __init__ only initializes an object that has already been constructed implicitly (because __init__ is called after __new__). However, everything that I have ever needed to define has used this l...

time series forecasting (eventually with python)

which algorithms exist for time series forecasting/regression ? what about using neural networks ? (best docs about this topic ?) are there python libraries/code snippets that can help ? ...

Python: get the position of the biggest item in an numpy array

How can I get get the position of the biggest item in an numpy array? ...

Python Web Programming Steps to that and this and yeah and oh?

Hi guys, I'm really interested in being a good programmer. So far what I've been doing is just reading a whole bunch of my friend's dad's programming books. I've been just kind of stumbling through and no help can be gotten from my friend's dad because he's kind of gone... for a long time. haha. Anyway, I think I'm getting nowhere jus...

Large web projects created in Python

Please list large projects that are made using Python that you know. Please give urls of sites. ...

Can I make a program reading from a piped stdin AND keyboard?

Can I write a python program that read from a piped stdin and keyboard? What I mean? I want to be able to use it in this way: tail -f LOGFILE | myscript.py see the log lines appearing in the screen and type commands with the keyboard? This sounds like 2 stdin and that confuse me. Is it possible or is it conceptually wrong? Thanks! ...

non-technical benefits of having string-type immutable

Hi, I am wondering about the benefits of having the string-type immutable from the programmers point-of-view. Technical benefits (on the compiler/language side) can be summarized mostly that it is easier to do optimisations if the type is immutable. Read here for a related question. Also, in a mutable string type, either you have thre...

Create a python function at runtime to match a variable number of dictionary entries

I'm making a program to calculate latency from a tcpdump/pcap file and I want to be able to specify rules on the command line to correlate packets -- i.e. find the time taken between sending a packet matching rule A to receiving a packet matching rule B (concrete example would be a FIX NewOrderSingle being sent and a corresponding FIX Ex...

PIL ImageGrab fails on 2nd virtual monitor of VirtualBox

I set up a VirtualBox to use two monitors. I tried taking a screenshot of a window on the second monitor: import ImageGrab im = ImageGrab.grab(windowrect) im.save("img.png") windowrect I verified to be the correct rect of the window, in this case, (1616, 2, 2594, 732). However, img.png is just a big black box. Any ideas how to fix thi...

Programmatically managing a 'balance' of time (sick/vacation)

I'm using Python/Django, but this is more about the "data model" and how I interact with the information - I really just want to know if I'm crazy here. I'm working on a small app at my company (~55 employees) that will keep track of available Vacation/Sick time. Part of the purpose is to integrate "self-service" into our intranet, so ...

How to use less than and equal to in an assert statement in python.

When I run the following: growthRates = [3, 4, 5, 0, 3] for each in growthRates: print each assert growthRates >= 0, 'Growth Rate is not between 0 and 100' assert growthRates <= 100, 'Growth Rate is not between 0 and 100' I get: 3 Traceback (most recent call last): File "ps4.py", line 132, in <module> testNestEggVar...

Removing Tags from HTML Parsed with BeautifulSoup

I'm new to python and I'm using BeautifulSoup to parse a website and then extract data. I have the following code: for line in raw_data: #raw_data is the parsed html separated into smaller blocks d = {} d['name'] = line.find('div', {'class':'torrentname'}).find('a') print d['name'] <a href="/ubuntu-9-10-desktop-i386-t314421...

Merits of Bash Script v. Python Script for Shell-Command-Heavy Utility

I need to write a script to do the following: Monitor a queuing system, which is accessible by shell commands. Create directories from templates using a mix of inline text editing, cp/mv, command line scripts, and compiled c++ programs. Check for error conditions. Write files on error conditions. Note: 2D arrays would be mildly usefu...