I have seen many a projects use simplejson module than the in builtin Standard Library json.
Also there seem to be many different simplejson modules
What are the advantages of simplejson and which implementation is good?
Why not, just use the standard builtin json module?
...
I have the following function:
def my_func():
"""My docstring is both funny and informative"""
pass
How do I get access to the docstring?
...
Like in C and many other languages there are static variables which retain their value between function calls. Is there any equivalent in Python?
...
I'm trying to use SOAPpy to write a web service client. However after defining WSDL object, a call to a web-service method is wrapped in a
<v1> .. actual parameters .. </v1>
How can I disable this v1 tag?
...
I wonder if it possible to not have jython automagicaly transform java objects to python types when you put them in a Java ArrayList.
Example copied from a jython-console:
>>> b = java.lang.Boolean("True");
>>> type(b)
<type 'javainstance'>
>>> isinstance(b, java.lang.Boolean);
1
So far, everything is fine but if I put the object in ...
Hello,
To my shame, I can't figure out how to handle exception for python 'with' statement. If I have a code:
with open("a.txt") as f:
print f.readlines()
I really want to handle 'file not found exception' in order to do somehing. But I can't write
with open("a.txt") as f:
print f.readlines()
except:
print 'oops'
and c...
Is there a list somewhere of recommendations of different Python-based REST frameworks for use on the serverside to write your own RESTful APIs? Preferably with pros and cons.
Please feel free to add recommendations here. :)
...
I need a server-side script (PHP, Python) to capture a webpage to a PNG, JPG, Tiff, GIF image and resize them to a thumbnail.
What is the best way to accomplish this?
See also:
Web Page Screenshots with PHP?
How can I take a screenshot of a website with PHP and GD?
How might I obtain a Snapshot or Thumbnail of a web page usi...
I am running Python 2.5.
This is my folder tree:
ptdraft/
nib.py
simulations/
life/
life.py
(I also have __init__.py in each folder, omitted here for readability)
How do I import the nib module from inside the life module? I am hoping it is possible to do without tinkering with sys.path.
(Note: The main module being r...
What are your opinions and expectations on Google's Unladen Swallow? From their project plan:
We want to make Python faster, but we
also want to make it easy for large,
well-established applications to
switch to Unladen Swallow.
Produce a version of Python at least 5x faster than CPython.
Python application performanc...
I am building an application plugin in Python which allows users to arbitrarily extend the application with simple scripts (working under Mac OS X). Executing Python scripts is easy, but some users are more comfortable with languages like Ruby.
From what I've read, I can easily execute Ruby scripts (or other arbitrary shell scripts) us...
I'm trying to write a video application in PyQt4 and I've used Python ctypes to hook into an old legacy video decoder library. The library gives me 32-bit ARGB data and I need to turn that into a QImage. I've got it working as follows:
# Copy the rgb image data from the pointer into the buffer
memmove(self.rgb_buffer, self.rgb_buffer_p...
It's somewhat common knowledge that Python functions can have a maximum of 256 arguments. What I'm curious to know is if this limit applies to *args and **kwargs when they're unrolled in the following manner:
items = [1,2,3,4,5,6]
def do_something(*items):
pass
I ask because, hypothetically, there might be cases where a list lar...
I wrote a script to run a command-line program with different input arguments and grab a certain line from the output. I have the following running in a loop:
p1 = subprocess.Popen(["program", args], stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=False)
p2 = subprocess.Popen(["grep", phrase], stdin=p1.stdout, stdout=subprocess....
If you have a collection of methods in a file, is there a way to include those files in another file, but call them without any prefix (i.e. file prefix)?
So if I have:
[Math.py]
def Calculate ( num )
How do I call it like this:
[Tool.py]
using Math.py
for i in range ( 5 ) :
Calculate ( i )
...
Are there better alternatives to PIL (Python Imaging Library - http://is.gd/3OPI ) for basic image file I/O and processing in Python?
...
Is there any way to work around the limitations of WeakValueDictionary to allow it to hold weak references to built-in types like dict or list? Can something be done at the C level in an extension module? I really need a weakref container that can hold (nearly) any type of object.
...
Does python have any sort of built in functionality of notifying what dictionary elements changed upon dict update? For example I am looking for some functionality like this:
>>> a = {'a':'hamburger', 'b':'fries', 'c':'coke'}
>>> b = {'b':'fries', 'c':'pepsi', 'd':'ice cream'}
>>> a.diff(b)
{'c':'pepsi', 'd':'ice cream'}
>>> a.update(b...
I usually do this in Perl:
whatever.pl
while(<>) {
#do whatever;
}
then cat foo.txt | whatever.pl
Now, I want to do this in Python. I tried sys.stdin but I have no idea how to do as I have done in Perl. How can I read the input?
Thanks.
EDIT:
Thanks, I like every single solution.
...
Heyas
I'm using lxml and python to generate xml documents (just using etree.tostring(root) ) but at the moment the resulting xml displays html entities as with named entities ( < ; ) rather than their numeric values ( < ; ). How exactly do I go about changing this so that the result uses the numeric values instead of the names?
T...