I am trying to use the Django sessions to read and set my cookies, but when i do the following the program just does not respond!
sessionID = request.session["userid"]
The program does not pass this point!
Any ideas?
...
Hi,
I am new to Python. I was trying to define and run a simple function in a class.
Can anybody please tell me what's wrong in my code:
class A :
def m1(name,age,address) :
print('Name -->',name)
print('Age -->',age)
print('Address -->',address)
>>> a = A()
>>> a.m1('X',12,'XXXX')
Traceback (most recent call last...
I'm using site wide caching with memcached as the backend. I would like to invalidate pages in the cache when the underlying database object changes.
If the page name changes then I would invalidate the whole cache (as it affects navigation on every page. Clumsy but sufficient for my needs.
If just the page content changes then I'd li...
Whats is the python urllib equivallent of
curl -u username:password status="abcd" http://example.com/update.json
I did this:
handle = urllib2.Request(url)
authheader = "Basic %s" % base64.encodestring('%s:%s' % (username, password))
handle.add_header("Authorization", authheader)
Is there a better / simpler way?
...
BASE_URL = 'http://foobar.com?foo=%s'
variable = 'bar'
final_url = BASE_URL % (variable)
I get this 'http://foobar.com?foo=bar' # It ignores the inside string.
But i wanted something like this 'http://foobar.com?foo='bar''
Thanks for the answer.
Can you help me out with almost the same problem:
lst = ['foo', 'bar', 'foo bar']
[s...
Hi stack overflow,
I guess this is a really novice question, still I'm having trouble with django templates and CharField models.
So I have a model with a CharField that creates a slug that replaces spaces with underscores. If I create an object
Somename Somesurname this creates slug Somename_Somesurname and gets displayed as expected ...
The authentication system for an application we're using right now uses a two-way hash that's basically little more than a glorified caesar cypher. Without going into too much detail about what's going on with it, I'd like to replace it with a more secure encryption algorithm (and it needs to be done server-side). Unfortunately, it nee...
I'm looking into writing a small app (in Python) that monitors internet activity. The same idea as NetMeter except with a little more customisation (I need to be able to set off-peak time ranges).
Anyway, I've been having a little trouble researching these questions:
Does Python have an API to monitor this?
As far as data collecting g...
I'm working in wx.Python and I want to get the columns of my wx.ListCtrl to auto-resize i.e. to be at minimum the width of the column name and otherwise as wide as the widest element or its column name. At first I thought the ListCtrlAutoWidthMixin might do this but it doesn't so it looks like I might have to do it myself (Please correc...
I'm working on a project that has to read and manipulate QuickTimes on Windows. Unfortunately, all the tutorials and sample code at the Apple site seem to be pretty much Mac specific. Is there a good resource on the web that deals specifically with programming QuickTime for Windows? Yes, I know that I can bludgeon my way (eventually) thr...
I would like to do a SUM on rows in a database and group by date.
I am trying to run this SQL query using Django aggregates and annotations:
select strftime('%m/%d/%Y', time_stamp) as the_date, sum(numbers_data)
from my_model
group by the_date;
I tried the following:
data = My_Model.objects.values("strftime('%m/%d/%Y',
...
I am trying to proto-type send/recv via a packet socket using the asyncore dispatcher (code below). Although my handle_write method gets called promptly, the handle_read method doesn't seem to get invoked. The loop() does call the readable method every so often, but I am not able to receive anything. I know there are packets received on ...
I have into my main.py
from modules import controller
ctrl = controller
help(ctrl)
print(ctrl.div(5,2))
and the controllor.py is:
class controller:
def div(self, x, y):
return x // y
when I run my main I got the error:
Traceback (most recent call last):
File "...\main.py", line 8, in ?
print(ctrl.div(5,2))
Attri...
What's the best way to convert a list/tuple into a dict where the keys are the distinct values of the list and the values are the the frequencies of those distinct values?
In other words:
['a', 'b', 'b', 'a', 'b', 'c']
-->
{'a': 2, 'b': 3, 'c': 1}
(I've had to do something like the above so many times, is there anything in the stand...
Im trying to search for some values within a date range for a specific type, but content for dates that exist in the database are not being returned by the query.
Here is an extract of the python code:
deltaDays = timedelta(days= 20)
endDate = datetime.date.today()
startDate = endDate - deltaDays
result = db.GqlQuery(
"SELECT * FRO...
Hello all. I'm using Python 3.0.
How to expand an environment variable given the %var_name% syntax?
Any help is much appreciated! Thanks!
...
Hello
I have a class that acts as an item in a tree:
class CItem( list ):
pass
I have two trees, each with CItem as root, each tree item has some dict members (like item._test = 1). Now i need to compare this trees. I can suggest to overload a comparison operator for CItem:
class CItem( list ):
def __eq__( self, other ):
# f...
I'm trying to write a task for Paver that will run nosetests on my files.
My directory structure looks like this:
project/
file1.py
file2.py
file3.py
build/
pavement.py
subproject/
file4.py
test/
file5.py
file6.py
Doctests (using the --with_doctest option) should be run on all the *.py files,...
I have a blog-like application with stories and categories:
class Category(models.Model):
...
class Story(models.Model):
categories = models.ManyToManyField(Category)
...
Now I know that when you save a new instance of a model with a many-to-many field, problems come up because the object is not yet in the database. This ...
I am trying to control a console application (JTAG app from Segger) from Python using the subprocess module. The application behaves correctly for stdout, but stdin doesn't seem to be read. If enable the shell, I can type into the input and control the application, but I need to do this programmatically. The same code works fine for i...