scoping problem in recursive closure
why does this work: def function1(): a = 10 def function2(): print a function2() ...
why does this work: def function1(): a = 10 def function2(): print a function2() ...
Hello all, I have a python function that makes a subprocess call to a shell script that outputs 'true' or 'false'. I'm storing the output from subprocess.communicate() and trying to do return output == 'true' but it returns False every time. I'm not too familiar with python, but reading about string comparisons says you can compare st...
I was wondering how people deal with graph theory in python? How is a graph stored? Are there libraries for this? For example how would I input a graph and then find its Chromatic polynomial? Or its girth? Or the number of unique spanning trees? How about problems that involve edge weight like salesman problems? I don't need all of the...
Question: IS there and IDE like python's IDLE for other languages? specifically I'd like one for java, but any programing just feels so much nicer with a debug system like IDLE's. Info: The main feature I'm getting at is the ability to test programs. In IDLE I can have the editor for my class in one window, i save and run it then ID...
Hi, I have list of 200 rss feeds, which I have to downloading. It's continuous process - I have to download every post, nothing can be missing, but also no duplicates. So best practice should be remember last update of feed and control it for change in x-hour interval? And how to handle if downloader will be restarted? So downloader sho...
When I try to connect to an MS CRM web service using suds/python-ntlm, I am getting a timeout on requests. However, the code that I'm trying to replace -- which calls out to the cURL command line app to do the same call -- succeeds. Clearly something is different in the way that cURL is sending the command data, but I'll be damned if I...
I have a Python script that is running a few ls commands. This script runs under cron all day. I use awk to write out the column that the filename is in when ls -l is executed. When I run the script via command line the output looks like this -rw-rw---- 1 mysql adm 141 2010-03-25 08:56 mysql-bin.000485 -rw-rw---- 1 mysql adm ...
I would like to convert this string foo_utf = u'nästy chäräctörs with å and co.' # unicode into this foo_ascii = 'nästy chäräctörs with å and co.' # ASCII . Any idea how to do this in Python (2.6)? I found unicodedata module but I have no idea how to do the transformation. ...
Setup: Multiple sites on Django on the same set of servers, being served by the same group of Apache processes. Some sites are Eastern TZ; some are Central. Database is PSQL running on a separate server. When I started, I didn't put much thought into how the various sites would handle timezones; I guess I saw the TIMEZONE setting in Dja...
Hi, this is my first question, so sorry if the form is wrong! I'm trying to make thrift server (python) and client (c++). However I need to exchange messages in both direction. Client should register (call server's function and wait), and server should listen on same port for N (N-> 100k) incoming connections (clients). After some cond...
I have been search all over the net and couldn't find an appropriate solution for this issue OverflowError: mktime argument out of range The code that causes this exception t = (1956, 3, 2, 0, 0, 0, 0, 0, 0) ser = time.mktime(t) I would like to know the actual reason for this exception, some say that the date is not in a valid ...
Given two sets a = [5,3,4,1,2,6,7] b = [1,2,4,9] c = set(a) - set(b) # c -> [5,3,6,7] is it possible to count how many items were removed from set 'a' ? ...
I want to create a list containing the 3-D coords of a grid of regularly spaced points, each as a 3-element tuple. I'm looking for advice on the most efficient way to do this. In C++ for instance, I simply loop over three nested loops, one for each coordinate. In Matlab, I would probably use the meshgrid function (which would do it in ...
What is the best way to store the cards and suits in python so that I can hold a reference to these values in another variable? For example, if I have a list called hand (cards in players hand), how could I hold values that could refer to the names of suits and values of specific cards, and how would these names and values of suits and ...
When mapping an object using SQLAlchemy, is there a way to only map certain elements of a class to a database, or does it have to be a 1:1 mapping? Example: class User(object): def __init__(self, name, username, password, year_of_birth): self.name = name self.username = username self.password = password ...
I have a Python package mymodule with a sub-package utils (i.e. a subdirectory which contains modules each with a function). The functions have the same name as the file/module in which they live. I would like to be able to access the functions as follows, from mymodule.utils import a_function Strangely however, sometimes I can import...
I see that elmer makes it possible to run Python code from Tcl. But is it possible the other way around? Could anyone give an example in Python? Update: by this I mean, being able to access Tcl objects, invoke Tcl functions, etc instead of simply running some Tcl code. ...
Does Python have a pool of all strings and are they (strings) singletons there? More precise, in the following code one or two strings were created in memory: a = str(num) b = str(num) ? ...
HI, I have a device that exposes a telnet interface which you can log into using a username and password and then manipulate the working of the device. I have to write a C program that hides the telnet aspect from the client and instead provides an interface for the user to control the device. What would be a good way to proceed. I tr...
Hi, I looked and searched and couldn't find what I needed although I think it should be simple (if you have any Python experience, which I don't). Given a string, I want to verify, in Python, that it contains ONLY alphanumeric characters: a-zA-Z0-9 and . _ - examples: Accepted: bill-gates Steve_Jobs Micro.soft Rejected: Bill...