import os
import tempfile
temp = tempfile.NamedTemporaryFile(prefix="456")
try:
print 'temp:', temp
print 'temp.name:', temp.name
finally:
# Automatically cleans up the file
temp.close()
print 'Exists after close:', os.path.exists(temp.name)
# -*- codng: utf8 -*-
import sys
sys.putenv('PYTHONIOENCODING', 'utf8')
OPC_CLASS = 'Matrikon.OPC.Automation;Graybox.OPC.DAWrapper;HSCOPC.Automation;RSI.OPCAutomation;OPC.Automation'
opc = OpenOPC.client(opc_class = "......")
def get_list_mail():
server = imaplib.IMAP4_SSL(server_imap, port_imap)
server.login("*****@mail.ru", password)
server.select()
result, ids = server.search(None, '(UNSEEN)')
print "New emails with your email in TO is %d" % len(ids[0].split())
for id in ids[0].split():
subject = server.fetch(id,
'(BODY.PEEK[HEADER.FIELDS (SUBJECT)])')[1][0][1].strip()
print "\t" + quopri.decodestring(subject.encode('utf-8')).decode('utf-8')
server.close()
server.logout()
class ClassPropertyDescriptor(object):
def __init__(self, fget, fset=None):
self.fget = fget
self.fset = fset
def __get__(self, obj, klass=None):
if klass is None:
klass = type(obj)
return self.fget.__get__(obj, klass)()
def __set__(self, obj, value):
if not self.fset:
raise AttributeError("can't set attribute")
type_ = type(obj)
return self.fset.__get__(obj, type_)(value)
def setter(self, func):
if not isinstance(func, (classmethod, staticmethod)):
func = classmethod(func)
self.fset = func
return self
def classproperty(func):
if not isinstance(func, (classmethod, staticmethod)):
func = classmethod(func)
return ClassPropertyDescriptor(func)
class Bar(object):
_bar = 1
@classproperty
def bar(cls):
return cls._bar
@bar.setter
def bar(cls, value):
cls._bar = value
# test instance instantiation
foo = Bar()
assert foo.bar == 1
baz = Bar()
assert baz.bar == 1
# test static variable
baz.bar = 5
assert foo.bar == 5
# test setting variable on the class
Bar.bar = 50
assert baz.bar == 50
assert foo.bar == 50
lsusb -v | grep -i bcdusb
bcdUSB 1.10
bcdUSB 2.00
bcdUSB 2.00
bcdUSB 2.00