Dicts in Python have a very nice method get:
# m is some dict
m.get(k,v) # if m[k] exists, returns that, otherwise returns v
Is there some way to do this for any value? For example, in Perl I could do this:
return $some_var or "some_var doesn't exist."
...
Hi,
I have a Django application which sometimes needs to send some data through TCP and I want this connection to be persistant.
The way I wanted to do it was to create a simple Twisted TCP server (I'm the one who will be waiting for the initial connection) and somehow call it from a Django view whenever I would be needing it.
How s...
If I want get a list of filenames with a search pattern with wildcard. Like:
getFilenames.py c:\PathToFolder\*
getFilenames.py c:\PathToFolder\FileType*.txt
getFilenames.py c:\PathToFolder\FileTypeA.txt
How to do this? Thanks.
...
I'm trying to make the app read data from a socket, but it takes some time and locks the interface, how do I make it respond to tk events while waiting?
...
Hi, I am trying to round integers in python. I looked at the built-in round() function but it seems that that rounds floats.
My goal is to round integers to the closest multiple of 10. i.e.: 5-> 10, 4-> 0, 95->100, etc.
5 and higher should round up, 4 and lower should round down.
This is the code I have that does this:
round_int(x...
I have some small python apps that use cx_Oracle to connect to an Oracle database. I deploy these apps by compiling them with py2exe, which works fine in many cases.
The problem is, there is no standard Oracle Client version (9i and 10g for example) across the many people who need to install this, and it would be very frustrating to try...
I am trying to build a django service to which numerous clients will send data. Each client will represent an authenticated user, who might be connected to the internet or not, so the client will aggregate the data and send them when a connection is available. The data should also be persisted locally so that they are accessed quickly wi...
Automapper is a object-object mapper where we can use to project domain model to view model in asp.net mvc.
http://automapper.codeplex.com/
Is there equivalent implementation in Python for use in Django(Template)/Pylons ?
Or is there necessity for this in Python world?
...
I have a package that has several components in it that would benefit greatly from using logging and outputting useful information.
What I do not want to do is to 'setup' proper logging for every single file with somewhere along these lines:
import logging
logging.basicConfig(level=DEBUG)
my_function = logging.getLogger("my_function")
...
How are greenlets implemented? Python uses the C stack for the interpreter and it heap-allocates Python stack frames, but beyond that, how does it allocate/swap stacks, how does it hook into the interpreter and function call mechanisms, and how does this interact with C extensions? (Any quirks)?
There are some comments at the top of gre...
How do I calculate the intersection points of two circles. I would expect there to be either two, one or no intersection points in all cases.
I have the x and y coordinates of the centre-point, and the radius for each circle.
An answer in python would be preferred, but any working algorithm would be acceptable.
...
I'm using App Engine python to host an application and would love to use Appstats and a couple of other libraries that run as middleware. However, when I set up middleware through appengine_config.py (as shown below) it works on the dev server but not in production. Appstats AND gaesessions work like a charm in the dev server and don't...
I am looking for a command-line tool that removes all comments from an input
file and returns the stripped output. It'd be nice it supports popular
programming languages like c, c++, python, php, javascript, html, css, etc. It
has to be syntax-aware as opposed to regexp-based, since the latter will catch
the pattern in source code strin...
I am trying to pass the name of a function into another function as an argument but I get an error: "TypeError: 'str' object is not callable". Here is a simplified example of the problem:
def doIt(a, func, y, z):
result = z
result = func(a, y, result)
return result
def dork1(arg1, arg2, arg3):
thing = (arg1 + arg2) / ...
I am using a Windows machine with python, django, and pinax installed.
I can import modules from any normal location (even if it's not in the actuall installed directory). However, I cannot import these same modules when I am in a virtual environment that I built for Pinax.
What are possible causes of this? What are possible solutio...
I have some MySQL database server information that needs to be shared between a Python backend and a PHP frontend.
What is the best way to go about storing the information in a manner wherein it can be read easily by Python and PHP?
I can always brute force it with a bunch of str.replace() calls in Python and hope it works if nobody ha...
Hello,
I have a directed cyclic graph with more than one cycle in it and I need a way to detect (and list) each cycle present in the digraph.
The graph can be seen here: http://img412.imageshack.us/img412/3327/schematic.gif
This is a dummy graph put together for the sake of debugging my python script. It contains the cycles: [n13, n14...
So I have to learn python for an upcoming project at work. I know plenty of languages so I'm not too worried, but the project hasn't started yet so I can't learn python as I work on the project. Instead of just going through tutorials and programming random trivial stuff, is there someplace that maybe have open (but simple) problems to s...
Hello,
I am wondering what is a valuable program (or programs) that a prospective employer hiring in Java, Python, C# or any high level programming language would like to see in the candidates work history? This or these programs would be seen as valuable indicators for the persons knowledge of the language.
A list of useful apps woul...
hi - We are using a cluster of memcached servers for caching purpose, in a Django(Python) production, having tried both cmemcache and python-memcache as the API. The problem is under high concurrency, we started to have duplicate key-value pairs, that is to say we are having multi values for a single key. Is there anyone having had the s...