首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    python向打印机发送数据(3)--

    #!/usr/local/bin/python2.7 # encoding: utf-8 import parallel import time import logging from logging.handlers import TimedRotatingFileHandler def lpt_data_printer(title,txt):       printer=open("LPT1", "wb")     printer.write(txt)     printer.close()     print u"正在运行第"+str(count)+u"次"     looger.info(u"正在运行第 %s 次" % str(count)) def hello(count):     if  count%6==1:         f = open(r"D:\test\FP00001.txt")         lines1 = f.read()         f.close()         lpt_data_printer("lines",lines1)     elif  count%6==2:         f = open(r"D:\test\FP00002.txt")         lines2 = f.read()         f.close()         lpt_data_printer("lines",lines2)     elif  count%6==3:         f = open(r"D:\test\FP00003.txt")         lines3 = f.read()         f.close()         lpt_data_printer("lines",lines3)     elif  count%6==4:         f = open(r"D:\test\FP00004.txt")         lines4 = f.read()         f.close()         lpt_data_printer("lines",lines4)     elif  count%6==5:         f = open(r"D:\test\FP00005.txt")         lines5 = f.read()         f.close()         lpt_data_printer("lines",lines5)     elif  count%6==0:         f = open(r"D:\test\FP00006.txt")         lines6 = f.read()         f.close()         lpt_data_printer("lines",lines6) if __name__ == '__main__':     looger = logging.getLogger('LPTPrint')     formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')     LogHandLer=TimedRotatingFileHandler(r'E:\count.log',when="midnight")     LogHandLer.setFormatter(formatter)     looger.addHandler(LogHandLer)     looger.setLevel(logging.INFO)     count=1     while(1):         hello(count)         count = count +1         f = open(r"D:\time.txt")         line = f.read()           time.sleep(int(line))         f.close()

    02

    (转)JAVA拾遗--关于SPI机制

    JDK提供的SPI(Service Provider Interface)机制,可能很多人不太熟悉,因为这个机制是针对厂商或者插件的,也可以在一些框架的扩展中看到。其核心类java.util.ServiceLoader可以在jdk1.8的文档中看到详细的介绍。虽然不太常见,但并不代表它不常用,恰恰相反,你无时无刻不在用它。玄乎了,莫急,思考一下你的项目中是否有用到第三方日志包,是否有用到数据库驱动?其实这些都和SPI有关。再来思考一下,现代的框架是如何加载日志依赖,加载数据库驱动的,你可能会对class.forName(“com.mysql.jdbc.Driver”)这段代码不陌生,这是每个java初学者必定遇到过的,但如今的数据库驱动仍然是这样加载的吗?你还能找到这段代码吗?这一切的疑问,将在本篇文章结束后得到解答。

    03
    领券