python

django templates

How can i split cases for None and False in django templates. {%if x %} True {%else%} None and False - how i can split this cases? {%endif%} ...

Why use lambda functions?

I can find lots of stuff showing me what a lambda function is, and how the syntax works and what not. But other than the "coolness factor" (I can make a function in middle a call to another function, neat!) I haven't seen something that's overwelmingly compelling to say why I really need/want to use them. It seems to be more of a styli...

SPSS Python Error

Getting the following error when trying to run SPSS from an external Python IDE. import spss yields the following error Traceback (most recent call last): File "C:\Documents and Settings\USER\workspace\SPSS\src\NE ASQ 2010.py", line 6, in <module> import spss File "C:\Python26\Lib\site-packages\spss180\spss\spss.py", line 16,...

strings with wildcards matching

Hi all I need to match two strings with simple wildcards: "oh.my.*" matches "*.my.life", "oh.my.goodness" and "*.*.*", but not "in.my.house" The only wildcard is *, which substitutes string of any character (minus .) I thought of using fnmatch, but it does not accept wildcards in file name. There is some code with regex which i am u...

How to match string with database fields in Django?

I have one database with column - where is datas like 'Very big News' 'News' 'something else' 'New Nes' 'Fresh News' 'Something else' I need match with my database.I Need go through every row in this database and find if i have string field which is inside of this string field. for example if i have field 'News' which is inside. I ...

Application is not working under raw system.

Hi, I've an python GUI application, I use pyQt4. I build binary with bbfreeze (before I was using py2exe but it didn't work with email module well). On system where I build this app, everything works properly, but when I install it on raw windows (without all those vc_redist and set of python libraries) binary does not work. Where sh...

Running a python script from ArcMap

Hello all - running a python script from within ESRI's ArcMap and it calls another python script (or at least attempts to call it) using the subprocess module. However, the system window that it executes in (DOS window) comes up only very briefly and enough for me to see there is an error but goes away too quickly for me to actually rea...

Run a C# application from python script

I've just about finished coding a decently sized disease transmission model in C#. However, I'm fairly new to .NET and am unsure how to proceed. Currently I just double-click on the .exe file and the model imports config setting from text files, does its thing, and outputs the results into a text file. What I would like to do next i...

how to check variable against 2 possible values python

I have a variable s which contains a one letter string s = 'a' Depending on the value of that variable, I want to return different things. So far I am doing something along the lines of this: if s == 'a' or s == 'b': return 1 elif s == 'c' or s == 'd': return 2 else: return 3 Is there a better way to write this? a more py...

What language should i learn after PHP/JS ?

i have about 5 years of work in PHP/JS/CSS and other web technologies , as web developer , i feel i should move to learn another languages , other things , but there is huge stack of languages and technologies today : JAVA/( Modern JAVA frameworks ) , C/C++ , Python , Ruby/ROR , Perl , Mobile development ...etc , and this make me confus...

Sort list by given order of indices -Python

I have a list of lines read from a file. I need to sort the list by time stamp (in UTC), however the time stamp is not always at the beginning of the string. I have parsed out the time stamp using regular expressions and place them into a separate list. The indices of the two lists will match. Once I sort the list of time stamps, I can g...

socket.getaddrinfo fails on one machine; works on another apparently-identical one. Why?

I've got a laptop and a desktop, both running Ubuntu 10.04, both running the stock Python 2.6.5 that comes with Ubuntu. On the laptop, the following program #!/usr/bin/env python import socket print(socket.getaddrinfo("localhost", 8025, 0, socket.SOCK_STREAM)) works -- i.e., it prints out some stuff without getting an error. The stu...

I'd like to know what's going on this Python program. I've included the code.

Here's the code: http://paste.pocoo.org/show/238093/ My main questions right now are: Is Line 37 mainly the gist of this program? And does it simply calculate this once and then print the result? Ex: self.start + key*self.step with start=1, key=4, step=2 [prints 9] where does the variable 'value' actually come into play here? Line 39....

How do to multiple imports in Python ?

In Ruby, instead of repeating the "require" (the "import" in Python) word lots of times, I do %w{lib1 lib2 lib3 lib4 lib5}.each { |x| require x } So it iterates over the set of "libs" and "require" (import) each one of them. Now I'm writing a Python script and I would like to do something like that. Is there a way to, or do I need to ...

Run a function each tick in Twisted

I'm using the twisted framework, and I need to keep track of how much time has passed since an event has started, and perform an action when a certain amount has passed. The best way to do that seems to me to be to check against a time-stamp each tick of the reactor. If it is the best way, how do I do it? If it isn't, what's a better w...

blocking socket client example

Hello, i need to connect to a blocking service using tcp ports (if someone here knows about it, it is a motorola digital wirelink protocol service) , i need a good starting point example, ideally in perl, python or php which are the languages i know better. So far i have tried this basic example with no luck. import socket import sys ...

Are there reasons to use get/put methods instead of item access?

I find that I have recently been implementing Mapping interfaces on classes which on the surface fit the model (they are essentially just key-value stores with no more meta-data), but underneath they are sometimes quite complex. Here are a couple examples of increasing severity: An object which wraps another mapping converting all obj...

python encryption

i have done the fallowing: key_one= int(raw_input("Enter key (0 <= key <= 127): "))#get the user to input the key number if key_one in range(128):# to see if the number that the user input is in the given range bin_key_one=bin(key_one)[2:]#change the number into binary and remove the 0b from it ...

Django Error: No module named engine

I'm trying to implement this code but getting Error: No module named engine http://github.com/robstyles/Massive-Coupon---Open-source-groupon-clone Any thoughts? ...

Any way to keep track of the last 5 data points in python

So I have an array that holds several numbers. As my script runs, more and more numbers are appended to this array. However, I am not interested in all the numbers but just want to keep track of the last 5 numbers. Currently, I just store all the numbers in the array. However, this array gets really big and it's full of unnecessary info...