I was wondering what happens to methods declared on a metaclass. I expected that if you declare a method on a metaclass, it will end up being a classmethod, however, the behavior is different. Example
>>> class A(object):
... @classmethod
... def foo(cls):
... print "foo"
...
>>> a=A()
>>> a.foo()
foo
>>> A.foo()
foo
...
Hello ,
Thanking everybody before starting.
I have a serious issue with a GUI implemented in Qt,say,QGui. Through Python APIs,say,qpread etc. I accesses the hardware resources.
What i does is through Python script I calls these APIs according to my requirement.
This QGui mostly crashes while running the script whether it is for long...
I have a Django app. When logged in as an admin user, I want to be able to pass a secret parameter in the URL and have the whole site behave as if I were another user.
Let's say I have the URL /my-profile/ which shows the currently logged in user's profile. I want to be able to do something like /my-profile/?__user_id=123 and have the u...
How can this be that this error was raised? I entered this:
def json(self):
return json.dumps(
{
'items': self.items
}
)
and got that error (because self.items was an empty queryset (Django)
but then,
def json(self):
return json.dumps(
{
'items': [] # Pass in empty list to...
def getText(nodelist):
"""Extracts the text between XML tags
I took this directly from http://docs.python.org/library/xml.dom.minidom.html.
For example, if I have a tag <Tag>525</Tag> this method returns me '525'
"""
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + n...
What do you think about Python's new Set Literal (2.7a3+)?
>>> {1,1,2,3,3}
set([1, 2, 3])
Wouldn't it make some confusions with Array, If you came from different programming backgrounds like C/C++, C#, Java?
...
From the following HTML snippet:
<link rel="index" href="/index.php" />
<link rel="contents" href="/getdata.php" />
<link rel="copyright" href="/blabla.php" />
<link rel="shortcut icon" href="/img/all/favicon.ico" />
I'm trying to get the href value of the link tag with rel value = "shortcut icon", I'm trying to achieve that using XPa...
I need to write a simple app that runs two threads:
- thread 1: runs at timed periods, let's say every 1 minute
- thread 2: just a 'normal' while True loop that does 'stuff'
if not the requirement to run at timed interval I would have not looked at twisted at all, but simple sleep(60) is not good enough and construction like:
l = task....
Hello!
I'm using @beaker_cache() decorator in my Pylons application.
How can I disable the cache under development mode?
...
Hi!
What´s the most efficient, elegant and pythonic way of solving this problem?
Given a list (or set or whatever) of n elements, we want to get the k biggest ones. ( You can assume k<n/2 without loss of generality, I guess)
For example, if the list were:
l = [9,1,6,4,2,8,3,7,5]
n = 9, and let's say k = 3.
What's the most efficient a...
Hi All
I need to read a CSV file in python.
Since for last row I receive a 'NULL byte' error I would like to avoid using for keyword but the while.
Do you know how to do that?
reader = csv.reader( file )
for row in reader # I have an error at this line
# do whatever with row
I want to substitute the for-loop wit...
I have a web camera running in Linux using the uvcvideo module. And I'm using a python application to access the web camera and display the image.
I want the python program to handle it if the web camera for some reason don't work anymore. Have tested with just unloading the module. Works fine if i just unload the module before I run th...
Hello,
in my work I use a lot of Venn diagrams, and so far I've been relying on the web-based "Venny". This offers the nice option to export the various intersections (i.e., the elements belonging only to that specific intersection). Also, it does diagrams up to 4 lists.
Problem is, doing this with large lists (4K+ elements) and more t...
Hi all,
I'm writing a python library that has a per-user configuration file that can be edited by the user of the library. The library also generates logging files.
On *nix, the standard seems to be to dump them in $HOME/.library_name.
However, I am not sure what to do with Windows users. I've used windows for years before switchi...
Hello,
I'm pretty new to Python programming so I have this question:
How can I log a Python application activity into /var/log with Mac OS X?
I tried using syslog module, but it does not seem to write anything. I tried also with the logging module, but I always run into a permission error.
How can I do it?
Update:
import logging
im...
My Django app, deployed in mod_wsgi under Apache using Django's standard WSGIHandler, authenticates users via form login on the Django side. So to Apache, the user is anonymous. This makes the Apache access log less useful.
Is there a way to pass the username back through the WSGI wrapper to Apache after handling the request, so that it...
The Mac OS X system startup program launchd enables job scheduling (similar to cron.) By creating a launchd agent, one can trigger programs through one of the following events:
an interval of time has elapsed
a certain calendar date has come
a file path has been modified
something has been placed in a certain directory (queue directory...
Hello,
I am trying to get a user to enter a number between 1 and 4. I have code to check if the number is correct but I want the code to loop around several times until the numbers is correct. Does anyone know how to do this? The code is below:
def Release():
try:
print 'Please select one of the following?\nCompletion = 0...
I have made a command-line interface for virtualbox such that the virtualbox can be controlled from a remote machine. now I am trying to implement the commmand-line interface using python virtualbox api. For that I have downloaded the pyvb package (python api documentation shows functions that can be used for implementing this under pyv...
Here is my code:
import matplotlib.pyplot as plt
plt.loglog(length,time,'--')
where length and time are lists.
How do I find the slope of this graph?
...