python-2.6

Python logging with rsyslog

丶灬走出姿态 提交于 2019-12-06 07:00:00
问题 I've inherited the following python file: import logging from logging.handlers import SysLogHandler class Logger(object): # Return a logging instance used throughout the library def __init__(self): self.logger = logging.getLogger('my_daemon') # Log an info message def info(self, message, *args, **kwargs): self.__log(logging.INFO, message, *args, **kwargs) # Configure the logger to log to syslog def log_to_syslog(self): formatter = logging.Formatter('my_daemon: [%(levelname)s] %(message)s')

Generator to yield gap tuples from zipped iterables

三世轮回 提交于 2019-12-06 06:37:56
Let's say that I have an arbitrary number of iterables, all of which can be assumed to be sorted, and contain elements all of the same type (integers, for illustration's sake). a = (1, 2, 3, 4, 5) b = (2, 4, 5) c = (1, 2, 3, 5) I would like to write a generator function yielding the following: (1, None, 1) (2, 2, 2) (3, None, 3) (4, 4, None) (5, 5, 5) In other words, progressively yield sorted tuples with gaps where elements are missing from the input iterables. My take on this, using only iterators, not heaps: a = (1, 2, 4, 5) b = (2, 5) c = (1, 2, 6) d = (1,) inputs = [iter(x) for x in (a, b

Can I sort a list of objects by 2 keys?

百般思念 提交于 2019-12-06 05:21:09
I have the following class (trimmed down): class DiskInstance(object): def __init__(self, name, epoch, size) self.name = name self.epoch = epoch self.size = size Then I define a external function (external to the class above): def getepoch(object): return object.epoch I then instantiate several objects of this class and append to a list called DISKIMAGES. I am currently sorting like this: for image in sorted(DISKIMAGES, key=getedate, reverse=True): Is there any way I can sort first by getedate and then by size? Thx for any help. If you want to sort by epoch and then size, this should work:

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

假装没事ソ 提交于 2019-12-06 04:10:37
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 threadedFuntion(args): if len(sourceFiles) > 3: for count, item in enumerate(sourceFiles): t1=Thread

how can i test an abstract method in python 2.6

人走茶凉 提交于 2019-12-06 03:48:00
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 code coverage. I need call the add method and the remove method Extra question: anybody knows how can i

Using matplotlib (for python 2.6) with Abaqus 6.12

徘徊边缘 提交于 2019-12-05 21:51:21
I'm wondering if any of you use matplotlib for your python codes that are coupled with ABAQUS. I really want to load matplotlib onto the abaqus-python interface. I'm using ABAQUS 6.12, which has python 2.6. Also, I'm using Windows 64 bit. However, when I download the matplotlib for python 2.6, it fails to install and says that "Python 2.6 required, which is not found in the Registry." Could anyone help me out? Does anyone know of a step-by-step way to install matplotlib such that it works for Abaqus 6.12? Any help would be appreciated! Thanks Note: For those unfamiliar with FEA Software, the

Python Subprocess Call with variables [duplicate]

最后都变了- 提交于 2019-12-05 19:41:46
This question already has an answer here: OSError: [Errno 2] No such file or directory while using python subprocess in Django 3 answers I am currently writing a script for a customer. This script reads from a config file. Some of these infos are then stores in variables. Afterwards I want to use subprocess.call to execute a mount command So I am using these variables to build the mount command call("mount -t cifs //%s/%s %s -o username=%s" % (shareServer, cifsShare, mountPoint, shareUser)) However this does not work Traceback (most recent call last): File "mount_execute.py", line 50, in

Python 2.6 ImportError: No module named argparse

泪湿孤枕 提交于 2019-12-05 15:05:23
I'm trying to run git-cola from Red Hat Enterprise Linux Server release 6.5 and receive: Traceback (most recent call last): File "....../bin/git-cola", line 24, in <module> from argparse import ArgumentParser ImportError: No module named argparse I think I have all of the required packages installed: * git-1.7.1-3.el6_4.1.x86_64 * python-2.6.6-51.el6.x86_64 * PyQt4.x86_64 0:4.6.2-9.el6 * /usr/lib/python2.6/site-packages/argparse-1.2.1-py2.6.egg I read in other blogs that there may be a problem with Python 2.6 and may need to move to 2.7. Additional information - @iljau noticed that argparse is

How can get Python isidentifer() functionality in Python 2.6?

…衆ロ難τιáo~ 提交于 2019-12-05 14:21:13
问题 Python 3 has a string method called str.isidentifier How can I get similar functionality in Python 2.6, short of rewriting my own regex, etc.? 回答1: the tokenize module defines a regexp called Name import re, tokenize, keyword re.match(tokenize.Name + '$', somestr) and not keyword.iskeyword(somestr) 回答2: re.match(r'[a-z_]\w*$', s, re.I) should do nicely. As far as I know there isn't any built-in method. 回答3: Invalid Identifier Validation All of the answers in this thread seem to be repeating a

Python 2.6.1 : expected path separator ([)

折月煮酒 提交于 2019-12-05 13:54:32
问题 I am getting a path separator error in python 2.6.1. I have not found this issue with python 2.7.2 version, but unfortunately I need this in 2.6.1 only. Is there any another way to achieve the same? :( my code :- import xml.etree.ElementTree as ET #version 1.2.6 import sys class usersDetail(object): def __init__(self, users=None): self.doc = ET.parse("test.xml") self.root = self.doc.getroot() def final_xml(self,username): r = self.root.find("user[@username='user1']") #not working in 2.6.1 :(