随笔分类 -  python

摘要:In [4]: print(qsort([5,4,6,3,2,0,1]))[0, 1, 2, 3, 4, 5, 6] 阅读全文
posted @ 2019-01-16 14:01 fosonR 阅读(196) 评论(0) 推荐(0)
摘要:#!/usr/bin/env python # -*- coding: utf-8 -*- import os import socket,fcntl,struct #crontab下shell命令无法执行 def getHostInfo(): # cmd = r"ifconfig|grep -v 127|grep 'inet addr' |awk '{print $2}'|cut -... 阅读全文
posted @ 2018-09-12 16:12 fosonR 阅读(1835) 评论(0) 推荐(0)
摘要:1 #coding=utf-8 2 class MyClass(object): 3 """docstring for ClassName""" 4 def __init__(self, arg): 5 super(object, self).__init__() 6 self.arg = arg 7 8 ... 阅读全文
posted @ 2017-09-18 14:46 fosonR 阅读(164) 评论(0) 推荐(0)
摘要:>>> from datetime import * >>> datetime.now().strftime("%Y-%m-%d %H:%M:%S")'2017-08-11 17:02:08' >>> dt = (2017, 7, 13, 0, 0, 11) >>> datetime(*dt).st 阅读全文
posted @ 2017-08-11 17:07 fosonR 阅读(156) 评论(0) 推荐(0)
摘要:#!/usr/bin/env python# -*- coding:utf-8 -*-import ibm_dbtry: conn = ibm_db.connect("DATABASE=service;HOSTNAME=8.8.8.8;PORT=50000;PROTOCOL=TCPIP;\ UID= 阅读全文
posted @ 2017-08-09 13:36 fosonR 阅读(331) 评论(0) 推荐(0)
摘要:Example Example Example 1: 连接到本地或已编目的数据库 Example 2: Connect to an uncataloged database 阅读全文
posted @ 2017-08-07 21:59 fosonR 阅读(423) 评论(0) 推荐(1)
摘要:我需要提取mysql和db2的数据进行对比,所以需要用python对其都进行操作。 python对mysql进行操作应该没什么问题,就是安装drive后就可以了,在上一篇中有讲安装python-mysql的包即可。。。 python操作db2,我查了有两种方法,一个是DB2的包,一个是ibm_db的 阅读全文
posted @ 2017-08-07 20:18 fosonR 阅读(1004) 评论(0) 推荐(1)
摘要:首先,创建一个简单的动态库编程生成dll.so: gcc -fPIC -O2 -shared dll.c -o dll.soC文件:dll.c 如下 python定义传给动态库的结构体 python 使用dll.so实例 阅读全文
posted @ 2017-08-03 11:22 fosonR 阅读(3900) 评论(0) 推荐(0)
摘要:1、引用so库: from ctypes import * >>>CDLL("libc.so.6").printf("12345\n")12345 >>>cdll.LoadLibrary("libc.so.6").printf("12345\n") 12345 2、引用DLL库: 2.1、pytho 阅读全文
posted @ 2017-08-02 17:51 fosonR 阅读(365) 评论(0) 推荐(0)
摘要:1、wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py 2、在root用户下 python ez_setup.py --insecure 3、安装pip easy-install pip 4、安装模块 easy-inst 阅读全文
posted @ 2017-08-02 15:19 fosonR 阅读(291) 评论(0) 推荐(0)
摘要:os.path.split(os.path.realpath(__file__))[0] 详解: __file__:python内部变量,显示文件在当前搜索路径下的相对路径与文件名 os.path.realpath():获取文件的绝对路径 os.path.split():拆分最后一个路径后的内容,形 阅读全文
posted @ 2017-08-02 09:47 fosonR 阅读(743) 评论(0) 推荐(0)
摘要:from ctypes import cdll lib = cdll.LoadLibrary('/home/zhengli/test/test.so') lib.func() 总结: 1、引用ctypes库中的cdll类。 2、利用cdll的LoadLibrary方法加载so包,生成对象。 3、利用 阅读全文
posted @ 2017-08-02 09:46 fosonR 阅读(3055) 评论(0) 推荐(0)
摘要:# -*- coding: utf-8 -*- from Tkinter import * root = Tk() # 80x80代表了初始化时主窗口的大小,0,0代表了初始化时窗口所在的位置 root.geometry('80x80+10+10') # 填充方向 Label(root, text  阅读全文
posted @ 2017-08-02 09:45 fosonR 阅读(493) 评论(0) 推荐(0)
摘要:从理论上来说,设计模式是对程序问题比较好的解决方案。无数的程序员都曾经遇到过这些问题,并且他们使用这些解决方案去处理这些问题。所以当你遇到同样的问题,为什么要去想着创建一个解决方案而不是用现成的并且被证明是有效的呢? 例子 假定现在有一个任务,需要你找到一个有效的方法合并两个做不同事情的类,在已有系 阅读全文
posted @ 2017-08-02 09:45 fosonR 阅读(139) 评论(0) 推荐(0)
摘要:import rere.match #从开始位置开始匹配,如果开头没有则无 re.search #搜索整个字符串 re.findall #搜索整个字符串,返回一个list 举例: r(raw)用在pattern之前,表示单引号中的字符串为原生字符,不会进行任何转义 re.match(r'l','li 阅读全文
posted @ 2017-08-01 14:21 fosonR 阅读(462) 评论(0) 推荐(0)
摘要:1、python读取excel中单元格内容为日期的方式 python读取excel中单元格的内容返回的有5种类型,即上面例子中的ctype: ? 1 ctype : 0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error 即date的ctype= 阅读全文
posted @ 2017-08-01 12:45 fosonR 阅读(557) 评论(0) 推荐(0)