python-2.6

how can i test an abstract method in python 2.6

十年热恋 提交于 2019-12-07 16:26:31
问题 I have an abstract class: import abc class Hello(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def add(self, foo): pass @abc.abstractmethod def remove(self, foo): pass I'm using abc for do abstract methods, so, when i do: hello = Hello() and this error is raised: TypeError: Can't instantiate abstract class Hello with abstract methods add, remove So I can test this type error with: self.assertRaises(Exception, Hello) # but this only test the constructor and i can't get the 100% of

Python - Using threads or a queue to iterate over a for loop that calls a function

主宰稳场 提交于 2019-12-07 16:25:15
问题 I'm fairly new to python and am making a script that allows one to bring point cloud data from other programs into Autodesk Maya. I have my script functioning fine but what i'm trying to do is make it faster. I have a for loop that iterates through a list of numbered files. I.e. datafile001.txt, datafile002.txt and so on. Is what i'm wondering is if there is a way to have it to do more then one at a time, possibly using threads or a queue? Below I have the code i have been working on: def

Can Python's list comprehensions (ideally) do the equivalent of 'count(*)…group by…' in SQL?

泄露秘密 提交于 2019-12-07 06:04:42
问题 I think list comprehensions may give me this, but I'm not sure: any elegant solutions in Python (2.6) in general for selecting unique objects in a list and providing a count? (I've defined an __eq__ to define uniqueness on my object definition). So in RDBMS-land, something like this: CREATE TABLE x(n NUMBER(1)); INSERT INTO x VALUES(1); INSERT INTO x VALUES(1); INSERT INTO x VALUES(1); INSERT INTO x VALUES(2); SELECT COUNT(*), n FROM x GROUP BY n; Which gives: COUNT(*) n ========== 3 1 1 2 So

python - getting the MAC address properly in Windows

点点圈 提交于 2019-12-07 04:18:54
问题 I'm using Windows 7 and Python 2.6. I would like to get the MAC address of my network interface. I've tried using the wmi module: def get_mac_address(): c = wmi.WMI () for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1): return interface.MACAddress However, experienced issues when executed without internet connectivity. I've tried using the uuid module: from uuid import getnode print getnode() However, return value is a 48 byte representation of the MAC address 66610803803052 1

How do I install pip for Python 2.6 on OS X?

眉间皱痕 提交于 2019-12-07 04:05:37
问题 I have an OS X system where I need to install a module for python 2.6. Both pip and easy_install-2.6 are failing: # /usr/bin/easy_install-2.6 pip Searching for pip Reading http://pypi.python.org/simple/pip/ Download error: unknown url type: https -- Some packages may not be found! Couldn't find index page for 'pip' (maybe misspelled?) Scanning index of all packages (this may take a while) Reading http://pypi.python.org/simple/ Download error: unknown url type: https -- Some packages may not

fd.seek() IOError: [Errno 22] Invalid argument

陌路散爱 提交于 2019-12-07 02:17:27
问题 My Python Interpreter (v2.6.5) raises the above error in the following codepart: fd = open("some_filename", "r") fd.seek(-2, os.SEEK_END) #same happens if you exchange the second arg. w/ 2 data=fd.read(2); last call is fd.seek() Traceback (most recent call last): File "bot.py", line 250, in <module> fd.seek(iterator, os.SEEK_END); IOError: [Errno 22] Invalid argument The strange thing with this is that the exception occurs just when executing my entire code, not if only the specific part with

Can't install python module “pycrypto” on Debian lenny

自闭症网瘾萝莉.ら 提交于 2019-12-06 17:18:10
问题 I tried to install pycrypto module by downloading the source code and executing the following command python setup.py install , then an error came running install running build running build_py running build_ext warning: GMP library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Hash.MD2' extension gcc -pthread -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -fPIC -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python2.5 -c src/MD2.c -o build/temp.linux

Grabbing non-HTML data from a website using python

烂漫一生 提交于 2019-12-06 10:53:36
问题 I'm trying to get the current contract prices on this page to a string: http://www.cmegroup.com/trading/equity-index/us-index/e-mini-sandp500.html I would really like a python 2.6 solution. It was easy to get the page html using urllib, but it seems like this number is live and not in the html. I inspected the element in Chrome and it's some td class thing. But I don't know how to get at this with python. I tried beautifulsoup (but after several attempts gave up getting a tar.gz to work on my

How to format an output in Python?

浪尽此生 提交于 2019-12-06 09:29:15
I am having difficulty in formatting some code in Python: My code is here: keys = ['(Lag)=(\d+\.?\d*)','\t','(Autocorrelation Index): (\d+\.?\d*)', '(Autocorrelation Index): (\d+\.?\d*)', '(Semivariance): (\d+\.?\d*)'] import re string1 = ''.join(open("dummy.txt").readlines()) found = [] for key in keys: found.extend(re.findall(key, string1)) for result in found: print '%s = %s' % (result[0],result[1]) raw_input() So far, I am getting this output: Lag = 1 Lag = 2 Lag = 3 Autocorrelation Index = #value ...... ...... Semivariance = #value But the desired output I want is: Lag AutoCorrelation

Cassandra update fails

て烟熏妆下的殇ゞ 提交于 2019-12-06 09:04:17
Solved I was testing update on 3 nodes, and the time on one of those nodes was 1 second behind, so when update a row, the write time is always behind the timestamp, cassandra would not update the rows. I sync all nodes time, and the issue fixed. Edit: I double checked the result, all insertions are succeed, partial updates failed. There's no error/exception messages I have a cassandra cluster(Cassandra 2.0.13) which contains 5 nodes. Using python(2.6.6) cassandra driver(2.6.0c2) for inserting data into database. my server systems are Centos6.X The following code is how i connect to cassandra