python-2.6

Handling large dense matrices in python

五迷三道 提交于 2019-12-03 00:45:53
Basically, what is the best way to go about storing and using dense matrices in python? I have a project that generates similarity metrics between every item in an array. Each item is a custom class, and stores a pointer to the other class and a number representing it's "closeness" to that class. Right now, it works brilliantly up to about ~8000 items, after which it fails with a out-of-memory error. Basically, if you assume that each comparison uses ~30 (seems accurate based on testing) bytes to store the similarity, that means the total required memory is: numItems^2 * itemSize = Memory So

Using Google App Engine SDK with Python 2.7 on Mac OS X 10.6

徘徊边缘 提交于 2019-12-02 21:59:18
I need to run Python 2.7 on my Mac Snow Leopard, which has Python 2.6 installed. According to this answer , running the Python 2.7 mpkg installer from Python.org should get me there. The reason I need to do this is that I'm trying to run the Google App Engine SDK for the Python 2.7 runtime. After installing Python 2.7, I'm still getting the following warning in my GAE server log: Warning: You are using a Python runtime (2.6) that is older than the production runtime environment (2.7). What else must I do to get the GAE SDK to recognize the new Python version? EDIT 2: Running: $ sudo find /

How to get the current running module path/name

风格不统一 提交于 2019-12-02 20:14:46
I've searched and this seems to be a simple question without a simple answer. I have the file a/b/c.py which would be called with python -m a.b.c . I would like to obtain the value a.b.c in the module level. USAGE = u'''\ Usage: python -m %s -h ''' % (what_do_i_put_here,) So when I receive the -h option, I display the USAGE without the need to actually write down the actual value in each and every script. Do I really need to go through inspect to get the desired value? Thanks. EDIT: As said, there are answers (I've searched), but not simple answers. Either use inspect , use of traceback , or

“outsourcing” exception-handling to a decorator [closed]

妖精的绣舞 提交于 2019-12-02 19:54:14
Many try/except/finally-clauses not only "uglify" my code, but i find myself often using identical exception-handling for similar tasks. So i was considering reducing redundancy by "outsourcing" them to a ... decorator. Because i was sure not to be the 1st one to come to this conclusion, I googled and found this - imho - ingenious recipe which added the possibility to handle more than one exception. But i was surprised why this doesn't seem to be a wide known and used practice per se, so i was wondering if there is maybe an aspect i wasn't considering? Is it bogus to use the decorator pattern

How to fix symbol lookup error: undefined symbol errors in a cluster environment

≡放荡痞女 提交于 2019-12-02 17:29:27
I'm working on some python code that extracts some image data from an ECW file using GDAL ( http://www.gdal.org/ ) and its python bindings. GDAL was built from source to have ECW support. The program is run on a cluster server that I ssh into. I have tested the program through the ssh terminal and it runs fine. However, I would now like to submit a job to the cluster using qsub, but it reports the following: Traceback (most recent call last): File "./gdal-test.py", line 5, in <module> from osgeo import gdal File "/home/h3/ctargett/.local/lib/python2.6/site-packages/GDAL-1.11.1-py2.6-linux-x86

Why does Python have a format function as well as a format method

江枫思渺然 提交于 2019-12-02 17:28:02
The format function in builtins seems to be like a subset of the str.format method used specifically for the case of a formatting a single object. eg. >>> format(13, 'x') 'd' is apparently preferred over >>> '{0:x}'.format(13) 'd' and IMO it does look nicer, but why not just use str.format in every case to make things simpler? Both of these were introduced in 2.6 so there must be a good reason for having both at once, what is it? Edit: I was asking about str.format and format , not why we don't have a (13).format I think format and str.format do different things. Even though you could use str

find command with subprocess not working with out Shell=True

萝らか妹 提交于 2019-12-02 11:47:34
问题 I have below lines in my code. I have embedded a short a line which fetches the list of files that are older than 10 mins. My sub process have been failing with few errors. It seems to work when I give Shell=True, but I read that it is a very risky to use that option and I am very new to the Python, Don't want to mess up with something I am not understanding. I have tried changing quotes with in and around that find statement, but its not helping me. can you please suggest how could I get the

Python subprocess throws [Errno 2] No such file or directory, error generated only when it on a remote host

梦想与她 提交于 2019-12-02 08:37:55
I'm running python 2.6. I'm getting the subprocess throws [Errno 2] No such file or directory only when I run the script via ssh. For example, if I run the script manually on the machine, there are no errors, but if I do ssh hostname script.py --host hostname it generates the error and tells me that File "/usr/lib64/python2.6/subprocess.py is missing, but that's not true as both servers have that file. I've written the subprocess call like this: p4 = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) The command just contains a list. Any ideas why it works

How to use logging NullHandler in python 2.6

六月ゝ 毕业季﹏ 提交于 2019-12-02 06:09:35
问题 Most of my code at this point has been designed to run on python 2.76. So the library I wrote uses the following code so that any consumers of my libraries can have debug logging coming from the library: So in each library file I have this: log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) This way if a client script using my library instantiates a logger object, the library will have log output as well. However, I now need to tweak this library so it runs on python 2.6

Convert QDate to seconds

Deadly 提交于 2019-12-02 05:33:30
问题 I take date from QDateTimeEdit and convert it to seconds like this: import time from datetime import datetime date = self.__ui.dateTimeEdit.date().toString("dd/MM/yy") dateString = str(date) seconds = time.mktime(datetime.strptime(dateString, "%d/%m/%y").timetuple()) This works well, but since it looks to long to me, my question is: Is it possible to convert self.__ui.dateTimeEdit.date() directly, without those string conversions? EDIT1 Unfortunately toMSecsSinceEpoch() as falsetru suggested,