python

I think I have a memory leak in my python script

This is my code: from xgoogle.search import GoogleSearch, SearchError import urllib, urllib2, sys, argparse global stringArr stringArr = ["string 1", "string 2", "string 3", "string etc"] def searchIt(url): try: if(args.verbose>='1'): print "[INFO] Opening URL: "+url response...

Creating ScrolledWindow in wxPython

I am trying to make a ScrolledWindow that can scroll over a grid of images, but the scrollbar isn't appearing. wxWidgets documentation says: The most automatic and newest way [to set the scrollbars in wxScrolledWindow] is to simply let sizers determine the scrolling area. This is now the default when you set an interior sizer into a ...

Do dictionaries have a has key method? I'm checking for 'None' and I'm having issues

I have 2 dictionaries, and I want to check if a key is in either of the dictionaries. I am trying: if dic1[p.sku] is not None: I wish there was a hasKey method, anyhow. I am getting an error if the key isn't found, why is that? ...

I need to free up RAM by storing a Python dictionary on the hard drive, not in RAM. Is it possible?

Hi... In my case, I have a dictionary of about 6000 instantiated classes, where each class has 1000 attributed variables all of type string or list of strings. As I build this dictionary up, my RAM goes up super high. Is there a way to write the dictionary as it is being built to the harddrive rather than the RAM so that I can save some...

python: list assignment index out of range

for row in c: for i in range(len(row)): if i not in keep: del row[i] i am getting this error on the last line: IndexError: list assignment index out of range i dont understand how it can be out of range if it exists! please help ...

How to scale down the y-axis in matplotlib/python?

This is more of a math question than a matplotlib question but if there is a way to do this specifically in matplotlib that would be great. I have a set of points with the max-y-value and the min-y-value can have a difference anywhere from a few hundred to a few thousand. I am trying to plot these points in a very small scale on the ...

python: append a list of values into a list

c1=[] for row in c: c1.append(row[0:13]) c is a variable containing a csv file i am going through every row in it and i want only the first 14 elements to be in the c1 what am i doing wrong? ...

python s3 using boto, says 'attribute error: 'str' object has no attribute 'connection'

I have a connection that works as I can list buckets, but having issues when trying to add a object. conn = S3Connection(awskey, awssecret) key = Key(mybucket) key.key = p.sku key.set_contents_from_filename(fullpathtofile) I get the error: 'attribute error: 'str' object has no attribute 'connection' the error is in the file: /us...

Lazy Evaluation for iterating through NumPy arrays

I have a Python program that processes fairly large NumPy arrays (in the hundreds of megabytes), which are stored on disk in pickle files (one ~100MB array per file). When I want to run a query on the data I load the entire array, via pickle, and then perform the query (so that from the perspective of the Python program the entire array...

Nothing executes in code

Possible Duplicate: Python Application does nothing #Dash Shell import os import datetime class LocalComputer: pass def InitInformation(): Home = LocalComputer() #Acquires user information if (os.name == "nt"): Home.ComputerName = os.getenv("COMPUTERNAME") Home.Username = os.getenv("USERNAME")...

need help with splitting a string in python

Hi, I am trying to tokenize a string using the pattern as below. >>> splitter = re.compile(r'((\w*)(\d*)\-\s?(\w*)(\d*)|(?x)\$?\d+(\.\d+)?(\,\d+)?|([A-Z]\.)+|(Mr)\.|(Sen)\.|(Miss)\.|.$|\w+|[^\w\s])') >>> splitter.split("Hello! Hi, I am debating this predicament called life. Can you help me?") I get the following output. Could someone...

How do I store a fetched entity in memcache for App Engine?

Because each new request in App Engine creates a new Handler, the entity I'd like to alter and put (using POST) has to be retrieved again. This seems wasteful, since I've populated the form with the information from GET a moment earlier. How do I store a key, fetched entity, or key/entity pair in memcache for App Engine? ...

Updating an object in a for loop using SqlAlchemy, should this work in theory?

So first I am fetching the rows: q = session.query(products) for p in q: p.someproperty = 23 session.commit() Should the above work in theory? Or is that the wrong pattern? I am getting an error saying can't modify the property, which is strange so I figured I was doing something fundamentally wrong. ...

Why is class variable accessible at the instance without the __class__ prefix?

See example below. Using the _class_ prefix with the class instance 'object' gives the expected result. Why is the class variable even available at the class instance 'c()' without the _class_ prefix? In what situation is it used? >>> class c: x=0 >>> c.x 0 >>> c().x 0 >>> c().__class__.x 0 >>> c.x += 1 >>> c.x 1 >>> c().x += ...

Prevent A User From Downloading Files from Python?

Hello. I am working on a project that requires password protected downloading, but I'm not exactly sure how to implement that. If the target file has a specific extension (.exe, .mp3, .mp4, etc), I want to prompt the user for a username and password. Any ideas on this? I am using Python 26 on Windows XP. ...

Django: merging objects

Hello! I have such model: class Place(models.Model): name = models.CharField(max_length=80, db_index=True) city = models.ForeignKey(City) address = models.CharField(max_length=255, db_index=True) # and so on Since I'm importing them from many sources, and users of my website are able to add new Places, I need a way to...

Python/feedparser script won't display on CGI/ character coding

#!/usr/bin/python # -*- coding: utf-8 -*- import sys import os import cgi import string import feedparser count = 0 print "Content-Type: text/html\n\n" print """<PRE><B>WORK MAINTENANCE/B></PRE>""" d = feedparser.parse("http://www.hep.hr/ods/rss/radovi.aspx?dp=zagreb") for opis in d: try: print """<B>Place/Time:</B> %s...

How to counting not 0 elements in an iterable?

I'm looking for a better/more Pythonic solution for the following snippet count = sum(1 for e in iterable if e) ...

Vibrate window in wxPython.

How would I vibrate a window in wxPython. I'd like some way of specifying how long to do it for and distance and stuff like that. Is there a builtin function I'm not noticing or would I have to code it myself? (I'm thinking of moving the window sideways a few times but I'd rather have a builtin function that might be faster.) ...

Python property and method override issue: why subclass property still calls the base class's method

Here is an example class A(object): def f1(self): return [] test1 = property(f1) class B(A): def f1(self): return [1, 2] if __name__ == "__main__": b = B() print b.test1 I expect the output to be [1, 2], but it prints [] instead. It is contrary to my expec...