Multiply lists together

Been working on a small class project to make a blackjack game. I realize that there are a billion how to's on this, but I'm trying to understand coding and build my own...that being said, I've messed up a lot. This conundrum is confusing to me thoug

Python regular expressions in parentheses

I'm having some trouble when trying to some get some data from within parenthesis. Here's some sample code: import re test_string = '123a (456b)' regex_a = re.match(r'(?P<a>\d+)a', test_string) regex_b = re.match(r'(?P<b>\d+)b', test_string) p

How to make a list of nested python dictionaries unique

I've got the following list of nested dictionaries: [{'permission': 'full', 'permission_type': 'allow', 'trustee': {'id': 'SID:S-1-5-32-545', 'name': 'Users', 'type': 'group'}}, {'permission': 'full', 'permission_type': 'allow', 'trustee': {'id': 'SI

Generator to generate gap tuples from zeros iterations

Let's say that I have an arbitrary number of iterables, all of which can be assumed to be sorted, and contain elements all of the same type (integers, for illustration's sake). a = (1, 2, 3, 4, 5) b = (2, 4, 5) c = (1, 2, 3, 5) I would like to write

How can I convert to tables of length 1?

I have opened a netCDF file that has two variables. Each variable has 4 dimensions: time, height, latitude, and longitude. I am using a script that is looping over every latitude(i) & longitude step(j) and delivers the data into a float format and ar

python set understanding made of different lists

expected = { 'l1': ['abc', 'def', 'ghi', 'jkl'], 'l2': ['abc', 'ghi', 'jkl', 'mno'] } I would like to get set(['abc', 'def', 'ghi', 'jkl', 'mno']) using python 2.6+ (so {x for x in ...} is not what I want). I've tried all_files = set(files for files

Python 2.6 ImportError: no module named argparse

I'm trying to run git-cola from Red Hat Enterprise Linux Server release 6.5 and receive: Traceback (most recent call last): File "....../bin/git-cola", line 24, in <module> from argparse import ArgumentParser ImportError: No module named a

Make Python 2.7 with Python 2.6

I have this simply python function that can extract a zip file (platform independent) def unzip(source, target): with zipfile.ZipFile(source , "r") as z: z.extractall(target) print "Extracted : " + source + " to: " + target T

The Python equivalence operator does not work as I expected

I have a Python script that assigns command-line arguments to different variables when the script is run from the command-line. I've done this before with little to no problems, but this time I'm getting hung up on what appears to be a little technic

Psycopg2 Full external join with Python 2.6

I am brand new to using psycopg2 to interact with a postgreSQL database. I am attempting to do a full outer join and cannot find any documentation to help me with the command. Here is what I am attempting in Python 2.6: cursor.execute(""" S

Can we read the mount player file in django apache?

I am writing one function to get file size in django application. Django application we are running through apache server. File is located in some other location. We are getting that file through mounted path. Code is as follows, import os filePath =

print results in the stdout file as well as the console

My requirement is to print the output of the file in the console as well as a log file. The following piece of code does it for me , exept for a minor hiccup. I am calling a perl script at the end of the file , whose output is getting displayed in th

Python 2.6 (Windows EXE) Keep the program running?

I'm trying to keep my python program running but it closes right away. I have tried raw_input() but I get this error: EOFError: EOF when reading a line I put raw_input() at the end. What should I use to have it running?I don't have access to Python r

Split long conditional expressions into lines

I have some if statements like: def is_valid(self): if (self.expires is None or datetime.now() < self.expires) and (self.remains is None or self.remains > 0): return True return False When I type this expressions my Vim automatically moves and to ne

Reading / Writing in a Subprocess Popen ()

I'm trying to talk to a child process using the python subprocess.Popen() call. In my real code, I'm implementing a type of IPC, so I want to write some data, read the response, write some more data, read the response, and so on. Because of this, I c

Python how to get the base instance of an instance?

In C# I would go: myObj.base I have a Date class which inherits from date.datetime. The Date class overrides __gt__() and __lt__() so when using the < and > operators they are called. I do not want to use these overrides - I want to use the date.dat

Python Multiprocessing: synchronizing a file-like object

I'm trying to make a file like object which is meant to be assigned to sys.stdout/sys.stderr during testing to provide deterministic output. It's not meant to be fast, just reliable. What I have so far almost works, but I need some help getting rid o

Python getattr is called twice?

I am using this simple example to understand Python's getattr function: In [25]: class Foo: ....: def __getattr__(self, name): ....: print name ....: ....: In [26]: f = Foo() In [27]: f.bar bar bar Why is bar printed twice? Using Python 2.6.5.I think

Python list comprehensions and other best practices

This relates to a project to convert a 2-way ANOVA program in SAS to Python. I pretty much started trying to learn the language Thursday, so I know I have a lot of room for improvement. If I'm missing something blatantly obvious, by all means, let me

Simple thread in Python 2.6 using thread.start_new_thread ()

I'm following a tutorial on simple threading. They give this example and when I try to use it I'm getting unintelligible errors from the interpreter. Can you please tell me why this isn't working? I'm on WinXP SP3 w/ Python 2.6 current import thread