Python - Using cPickle to load a previously saved pickle uses too much memory?
My pickle file is about 340MB but takes up 29% of 6gb of memory when loaded. This seems a bit too much. The pickle file is a dictionary of dictionaries. Is this appropriate?
Code used:
import cPickle as pickle
file = pickle.load( file_handle )
Thanks
...
I'm working on a project where someone wrote a PyGTK GUI that uses docks from GDL. He has the GUI saved as an XML file:
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<object class="GtkUIManager" id="uimanager"/>
<object class="GtkWindow" id="mainWindow">
<property name="title" translatable="yes">Title...
I have a cherrypy application and on some of the views I want to start only allowing certain users to view them, and sending anyone else to an authorization required page.
Is there a way I can do this with a custom decorator? I think that would be the most elegant option.
Here's a basic example of what I want to do:
class MyApp:
...
Hello, I am building a Facebook canvas application that loads in an iframe with Django. I would like the login process to work similarly to the way Zynga does it. In this method, if you are not logged in you are redirected to a Facebook login page and then to a permissions request page for the app (without any popups).
As far as I can...
I have a Tkinter GUI running two threads, the main tread for the GUI and a worker thread. The worker thread creates a subprocess using the following code:
myProcess = subprocess.Popen(['python', '-u', 'runTests.py'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
The file ru...
Hi,
I'm doing a lot of development in IPython where
In[3]: from mystuff import MyObject
and then I make lots of changes in mystuff.py. In order to update the namespace, I have to do
In[4]: reload(mystuff)
In[5]: from mystuff import MyObject
Is there a better way to do this? Note that I cannot import MyObject by referencing mystuff...
for facebook fbml apps facebook is sending in a signed_request parameter explained here
http://developers.facebook.com/docs/authentication/canvas
they have given the php version of decoding this signed request:
http://pastie.org/1054154
how to do the same in python?
i tried base64 module but i am getting Incorrect padding error:
>>...
I want to make some unittests for my app, and I need to compare two arrays. Since array.__eq__ returns a new array (so TestCase.assertEqual fails), what is the best way to assert for equality?
Currently I'm using
self.assertTrue((arr1 == arr2).all())
but I don't really like it :\
...
I'm trying to add some gui elements (dialog boxes with buttons) to a game I'm writing with pygame. I looked around for a decent gui toolkit and ended up with pgu. Anyway, I'm trying to get it to pop up a dialog box, which it does (sort of), but it isn't closing.
Here's a simplified version of my code that just shows the behavior I care ...
I need some help understanding what's happening here. This code is from a models/log.py module in web2py, and is meant to allow for global logging.
def _init_log():
logger=logging.getLogger(request.application)
...
return logger
logging=cache.ram('mylog',lambda:_init_log(),time_expire=99999999)
Can someone explain how...
I have a list of strings parsed from somewhere, in the following format:
[key1, value1, key2, value2, key3, value3, ...]
I'd like to create a dictionary based on this list, like so:
{key1:value1, key2:value2, key3:value3, ...}
An ordinary for loop with index offsets would probably do the trick, but I wonder if there's a Pythonic wa...
Python n00b here
I need to convert an arbitrary string to a string that is a valid variable name in python.
Here's a very basic example:
s1 = 'name/with/slashes'
s2 = 'name '
def clean(s):
s = s.replace('/','')
s = s.strip()
return s
print clean(s1)+'_'#the _ is there so I can see the end of the string
That is a very n...
I have installed the Image module http://www.pythonware.com/products/pil/. I then try and import it in the python interpreter and successfully so:
>>> import Image
>>>
But when I try to import the module in Zope via DTML page:
DTML page looks like:
<dtml-var import_image>
Which calls this script:
def import_image(self):
impo...
How can you loop through the HttpRequest post variables in Django?
I have
for k,v in request.POST:
print k,v
which is not working properly.
Thanks!
...
From here I've copied an example of python gui app, but it's not working.
It starts up and show window, but when i click the Quit button it just freze. And if I run it again then i got another quit button in previous window.
Is there error in example code or is this problem with win 7 ?
I am using python 2.6.5 and win 7 32 bit.
...
I have an existing program that has its own main loop, and does computations based on input it receives - let's say from the user, to make it simple. I want to now do the computations remotely instead of locally, and I decided to implement the RPCs in Twisted.
Ideally I just want to change one of my functions, say doComputation(), to m...
I am using Python 2.5, I want an enumeration like so (starting at 1 instead of 0):
[(1, 2000), (2, 2001), (3, 2002), (4, 2003), (5, 2004)]
I know in Python 2.6 you can do: h = enumerate(range(2000, 2005), 1) to give the above result but in python2.5 you cannot...
Using python2.5:
>>> h = enumerate(range(2000, 2005))
>>> [x for x in ...
Hi folks, I have tried editing SConstruct to point to a different gcc compiler but it always seems to use the one defined in /usr/bin/gcc and /usr/bin/g++.
env = DefaultEnvironment()
env['CC'] = '/home/aaron/devel/bin/gcc'
env['CXX'] = '/home/aaron/devel/bin/g++'
What am I doing wrong? Also, is there a way to specify a different comp...
I want to disconnect cleanly, and then stop the reactor. If I do this, however:
controller.connection.disconnect()
reactor.stop()
then I get a "connection was lost in a non-clean fashion" message. If I insert a time.sleep(1) in between them, the connection closes cleanly. How can I wait until the connection is really closed?
...
I am trying to test for an exception.
I have:
def test_set_catch_status_exception(self):
mro = self.mro
NEW_STATUS = 'No such status'
self.assertRaises(ValueError,mro.setStatus(NEW_STATUS))
I get the following error:
======================================================================
ERROR: test_set_catch_status_excep...