I wrote a decorator that looks like this
def login_required_message(*args, **kwargs):
kwargs.setdefault('message', "You must be logged in to do that.")
return _user_passes_test_message(lambda u: u.is_authenticated(), *args, **kwargs)
But when I try to use it without the () at the end, it fails, unless I rewrite it like this:
...
Howdy,
I have been developing under Python/Snowleopard happily for the part 6 months. I just upgraded Python to 2.6.5 and a whole bunch of libraries, including psycopg2 and Turbogears. I can start up tg-admin and run some queries with no problems. Similarly, I can run my web site from the command line with no problems.
However, if I tr...
If you happen to have
from <module> import *
in the middle of your program (or module), you would get the warning:
/tmp/foo:100: SyntaxWarning: import * only allowed at module level
I understand why import * is discouraged in general (namespace invisibility),
but there are many situations where it would prove convenient, especially...
Coming to Python from Java, I've been told that factories are not Pythonic. Thus, I'm looking for a the Python way to do something like the following. (I'm oversimplifying my goal so that I don't have to describe my entire program, which is very complicated).
My script will read in names of people (along with some information about them...
Hi,
I am using Popen to run a command but I don't know how I can write a callback that gets called once the command is finished. Any idea?
Thanks.
Bin
...
I'm using a linux machine to make a little python program that needs to input its result in a SQL Server 2000 DB.
I'm new to python so I'm struggling quite a bit to find what's the best solution to connect to the DB using python 3, since most of the libs I looked only work in python 2.
As an added bonus question, the finished version o...
Ive tried the gtk method, but it is very slow and doesn't work for a 'large' image (120 kb)
import pygtk
pygtk.require('2.0')
import gtk
import os
def copy_image(f):
assert os.path.exists(f), "file does not exist"
clipboard = gtk.clipboard_get()
img = gtk.Image()
img.set_from_file(f)
clipboard.set_image(img.get_pixbu...
Hello everyone, I am trying to process various texts by regex and NLTK of python -which is at http://www.nltk.org/book-. I am trying to create a random text generator and I am having a slight problem. Firstly, here is my code flow:
Enter a sentence as input -this is called trigger string, is assigned to a variable-
Get longest word in ...
I have windows 7 and I wrote a python program that loops ("for loops", i.e., "for key in dict") over multiple databases, checks for various conditions (e.g., if x in dict, y += 1) and then tallies the results. I didn't do anything to parralelize the proceesing. I have 8 CPU cores on my computer. When I start Windows task manager while...
I want to try to use the Yahoo Fantasy Sports API for my fantasy football league, but it seems like I can only access the data if I authenticate with Yahoo. Makes sense. However, I am new to Python and have no idea how to get started.
I found a python module on the web
link text
but I don't know how to "install" a file that has a .gz...
I can't, for the life of me, get Django to find my JavaScript files! I am trying to plug in a custom widget to the admin page, like so:
class MarkItUpWidget(forms.Textarea):
class Media:
js = (
'js/jquery.js',
'js/markitup/jquery.markitup.js',
'js/markitup/sets/markdown/set.js',
'js/markitup.init.js',...
I have 100 units having TCP socket implementation and answering to commands from a server, I would like to implement this server listening on other end from web framework (registering or deleting a unit, then create a tcp client to this twisted server) then the server creates a task.LoopingCall with specific delay per unit to run multipl...
I have a Python class C which should have two pseudo-dicts a and b. The term pseudo-dicts means that the dictionaries don't actually exist and that they are “recomputed” each time a key is accessed.
In pseudocode this would look like this:
class C:
def a.__getitem__(self, key):
return 'a'
def b.__getitem__(self, key):
...
I have a C extension in which I'd like to use OpenMP. When I import my module, though, I get an import error:
ImportError: /home/.../_entropysplit.so: undefined symbol: GOMP_parallel_end
I've compiled the module with -fopenmp and -lgomp. Is this because my Python installation wasn't compiled with the -fopenmp flag? Will I have to bui...
With lxml.html, how do I access single elements without using a for loop?
This is the HTML:
<tr class="headlineRow">
<td>
<span class="headline">This is some awesome text</span>
</td>
</tr>
For example, this will fail with IndexError:
for row in doc.cssselect('tr.headlineRow'):
headline = row.cssselect('td span.headlin...
I am trying to UPDATE a MySQL table using Python's MySQLdb module. Although the query seems fairly simple it just won't update the information. Here is my code:
for username,info in users.iteritems():
if info[0] > 0 and info[1] > 0:
month = 8
year = 2010
cursor.execute("""
UPDATE users_disk
SET
...
for example, 2 classes in a 1-to-many relationship:
class owner(db.model):
name = db.StringProperty()
class cat(db.model):
name = db.StringProperty()
owner = db.ReferenceProperty(owner)
so how do i produce a list of cats ordered by owner.name (then optionally by cat.name)?
i tried
"SELECT * FROM cat ORDER BY owner.na...
In python, I can do:
args = [1,2,3,4]
f(*args) # this calls f(1,2,3,4)
Is this possible in java?
to clarify - f has an argument list of variable length.
...
I am trying to establish a bluetooth connection between my J2ME application (using JSR-082 API) and my desktop application written with Python (using pybluez bluetooth API). However, I could not find a suitable bluetooth communication protocols to pair them.
In pybluez, the way you connect to a server is as follows:
addr, port = "01:23...
I have a bunch of Python modules I want to clean up, reorganize and refactor (there's some duplicate code, some unused code ...), and I'm wondering if there's a tool to make a map of which module uses which other module.
Ideally, I'd like a map like this:
main.py
-> task_runner.py
-> task_utils.py
-> deserialization.py
-> file_...