In LISP-like languages all language constructs are first-class citizens.
Consider the following example in Dylan:
let x = if (c)
foo();
else
bar();
end;
and in LISP:
(setf x (if c (foo) (bar)))
In Python you would have to write:
if c:
x = foo();
else:
x = bar();
Because Python desting...
I have an XML document which I'm pretty-printing using lxml.etree.tostring
print etree.tostring(doc, pretty_print=True)
The default level of indentation is 2 spaces, and I'd like to change this to 4 spaces. There isn't any argument for this in the tostring function; is there a way to do this easily with lxml?
...
I was wondering if there's any library for asynchronous method calls in Python. It would be great if you could do something like
@async
def longComputation():
<code>
token = longComputation()
token.registerCallback(callback_function)
# alternative, polling
while not token.finished():
doSomethingElse()
if token.finished():
...
Hi folks,
I have django+python+apache2+mod_python installed hosted and working on ubuntu server/ linode VPS. php5 is installed and configured. We don't have a domain name as in example.com. Just IP address. So my apache .conf file looks like this
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Location "/">...
I have a model named Project which has a m2m field users. I have a task model with a FK project. And it has a field assigned_to. How can i limit the choices of assigned_to to only the users of the current project?
...
Hi,
From two unequal arrays, i need to compare & delete based on the last value of an array.
Example:
m[0] and n[0] are read form a text file & saved as a array, [0] - their column number in text file.
m[0] = [0.00, 1.15, 1.24, 1.35, 1.54, 2.32, 2.85, 3.10, 3.40, 3.80, 4.10, 4.21, 4.44]
n[0] = [0.00, 1.12, 1.34, 1.45, 2.54, 3.12, 3....
I've been trying to use suds for Python to call a SOAP WSDL. I just need to call the service programmatically and write the output XML document. However suds automatically parses this data into it's own pythonic data format. I've been looking through the examples and the documentation, but I can't seem to find a way to return the XML doc...
I'm working with a webservice which requires a valid username/password. From PyQt, I'm accessing the webservice using QNetworkAccessManager which emits the
authenticationRequired (QNetworkReply*, QAuthenticator*)
signal when (obviously),authentication is required. When I fill in the user and psswd for
QAuthenticator, everything wor...
For the sake of simplicity, let's say I have a Person class in Python. This class has fields for firstname, lastname, and dob.
class Person:
def __init__(self, firstname, lastname, dob):
self.firstname = firstname;
self.lastname = lastname;
self.dob = dob;
In some situations I want to sort lists of Persons by lastname f...
I'm teaching myself Python and I see the following in Dive into Python section 5.3:
By convention, the first argument of any Python class method (the reference to the current instance) is called self. This argument fills the role of the reserved word this in C++ or Java, but self is not a reserved word in Python, merely a naming conv...
How can a python script know the amount of system memory it's currently using? (assuming a unix-based OS)
...
I tried the following, yet the button still has a white background:
self.button = gtk.CheckButton()
self.button.modify_fg(gtk.STATE_NORMAL, gtk.gdk.Color(65535,0,0))
self.button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(65535,0,0))
self.button.modify_fg(gtk.STATE_ACTIVE, gtk.gdk.Color(65535,0,0))
self.button.modify_b...
How do I do it? A lot of sites say I can just call .modify_bg() on the button, but that doesn't do anything. I'm able to add an EventBox to the button, and add a label to that, and then change its colors, but it looks horrendous - there is a ton of gray space between the edge of the button that doesn't change. I just want something that ...
Hello,
Newbie question here, so please bear with me.
Let's say I have a dictionary looking like this:
a = {"2323232838": ("first/dir", "hello.txt"),
"2323221383": ("second/dir", "foo.txt"),
"3434221": ("first/dir", "hello.txt"),
"32232334": ("first/dir", "hello.txt"),
"324234324": ("third/dir", "dog.txt")}
I want...
Is there a copy constructor in python ? If not what would I do to achieve something similar ?
The situation is that I am using a library and I have extended one of the classes there with extra functionality and I want to be able to convert the objects I get from the library to instances of my own class.
...
I received the following error when trying to retrieve data using Google App Engine from a single entry to a single page e.g. foobar.com/page/1 would show all the data from id 1:
ValueError: invalid literal for int() with base 10
Here are the files:
Views.py
class One(webapp.RequestHandler):
def get(self, id):
id ...
Hi there !
Consider the following class :
class Token:
def __init__(self):
self.d_dict = {}
def __setattr__(self, s_name, value):
self.d_dict[s_name] = value
def __getattr__(self, s_name):
if s_name in self.d_dict.keys():
return self.d_dict[s_name]
else:
raise Attribu...
When specifying my script file in setup.py, e.g. "script": 'pythonturtle.py', how can I specify its relative position in the file system? In my case, I need to go down two folders and then go into the "src" folder and it's in there. How do I write this in a cross-platform way?
...
I'm developing an app that handle sets of financial series data (input as csv or open document), one set could be say 10's x 1000's up to double precision numbers (Simplifying, but thats what matters).
I plan to do operations on that data (eg. sum, difference, averages etc.) as well including generation of say another column based on co...
Taking speed as an issue it may be better to choose another language, but, what is your library/module/implementation of choice for doing 1D FFT in python?
...