示例#1
0
def delete_range(workSheet, end, start=-99):
    flag = 0
    loge('max row %d', workSheet.max_row)
    for row in range(workSheet.max_row, 1, -1):
        data = workSheet.cell(row, 3).value
        if data == '--' or int(data) > start and data < end:
            flag = 1
        if flag == 1:
            logi('delete %s, %s, %s', workSheet.cell(row, 1).value, workSheet.cell(row, 2).value, workSheet.cell(row, 3).value)
            workSheet.delete_rows(row)
            flag = 0
    return workSheet
示例#2
0
def process_excel(finename, sheetname, filetemp):
    wb = openpyxl.load_workbook(finename)
    # sheet = wb.active
    sheet = wb.create_sheet(sheetname)
    loge('start file %s------------------------', filetemp)
    wb_temp = openpyxl.load_workbook(filetemp)
    sheet_temp = wb_temp.active

    sheet_temp = excel_utils.find_and_delete_key(sheet_temp, 'SH688', 1)
    sheet_temp = excel_utils.find_and_delete_key(sheet_temp, 'ST', 1)
    sheet_temp = excel_utils.delete_range(sheet_temp, 9)
    # for row in range(2, sheet_temp.max_row + 1):
    #     logi('%s, %s', sheet_temp.cell(row, 1).value, sheet_temp.cell(row, 2).value)
    for row in range(1, sheet_temp.max_row + 1):
        for cell in sheet_temp[row]:
            sheet.cell(row, cell.column).value = cell.value


# wb.create_sheet('new', 2)
    wb.save(summary)
示例#3
0
# -*- coding:UTF-8 -*-
import log_utils as log

# 循环语句

# while判断条件:
#  执行语句
log.loge("while判断条件")
count = 0
while (count < 9):
    print("the count is :", count)
    count += 1
print("good bye!")
print()
"""
while 语句时还有另外两个重要的命令 continue,break 来跳过循环,continue 用于跳过该次循环,break 则是用于退出循环,
此外"判断条件"还可以是个常值,表示循环必定成立,具体用法如下:
"""

# continue 和 break 用法
i = 1
while i < 10:
    i += 1
    if i % 2 > 0:  # 非双数时跳过输出
        continue
    print(i)
print()

i = 1
while 1:
    print(i)
示例#4
0
# -*- coding:UTF-8 -*-
import log_utils as log

# Python算术运算符
log.loge("Python算术运算符")

a = 21
b = 10
c = 0

c = a + b
print("1 -> c的值为:", c)

c = a - b
print("2 -> c的值为:", c)
c = a * b
print("3 -> c的值为:", c)
c = a / b
print("4 -> c的值为:", c)

# 取余数
c = a % b
# 1
print("5 -> c的值为:", c)

# a的n次幂
a = 2
b = 3
c = a**b
# 8
print("6 -> c的值为:", c)
使用图 (graph) 来表示计算任务.
在被称之为 会话 (Session) 的上下文 (context) 中执行图.
使用 张量(tensor) 表示数据.
通过 变量 (Variable) 维护状态.
使用 feed 和 fetch 可以为任意的操作(arbitrary operation) 赋值或者从其中获取数据.
"""

import log_utils as log

# 一,基本语法:

# 语法例子1
# 创建2个矩阵,前者1行2列,后者2行1列,然后矩阵相乘:
import tensorflow as tf

log.loge("语法例子1")
matrix1 = tf.constant([[3, 3]])
matrix2 = tf.constant([[2], [2]])
product = tf.matmul(matrix1, matrix2)

# 上面的操作是定义图,然后用会话session去计算
with tf.Session() as sess:
    result2 = sess.run(product)
    print(result2)

sess.close()
log.loge("语法例子1")

log.loge("语法例子2")
# 语法例子2
# 定义一个tensorflow的变量
# -*- coding:UTF-8 -*-
'''
Python面向对象
'''

import log_utils as log

# 类的导入
from common_obj import Point, Child, T_Child, Vector, JustCounter

log.loge("类定义与调用")


# 创建类
class Employee:
    '所有员工基类'
    empCount = 0

    def __init__(self, name, salary):
        print("构造方法被调用了")
        self.name = name
        self.salary = salary
        Employee.empCount += 1

    def displayCount(self):
        print("displayCount方法被调用了")
        print("Total Employee %d " % Employee.empCount)

    def displayEmployee(self):
        print("displayEmployee方法被调用了")
        print("Name: ", self.name, " , Salary: ", self.salary)
示例#7
0
"""
TensorFlow有几个概念需要进行明确:

1 图(Graph):用来表示计算任务,也就我们要做的一些操作。

2 会话(Session):建立会话,此时会生成一张空图;在会话中添加节点和边,形成一张图,一个会话可以有多个图,通过执行这些图得到结果。如果把每个图看做一个车床,那会话就是一个车间,里面有若干个车床,用来把数据生产成结果。

3 Tensor:用来表示数据,是我们的原料。

4 变量(Variable):用来记录一些数据和状态,是我们的容器。

5 feed和fetch:可以为任意的操作(arbitrary operation) 赋值或者从其中获取数据。相当于一些铲子,可以操作数据。

形象的比喻是:把会话看做车间,图看做车床,里面用Tensor做原料,变量做容器,feed和fetch做铲子,把数据加工成我们的结果。
"""
log.loge("矩阵乘法")
# 创建图和运行图
# 创建一个常量v1,它是一个1行2列的矩阵
v1 = tf.constant([[2, 3]])
# 创建一个常量v2,它是一个2行一列的矩阵
v2 = tf.constant([[2], [3]])
# 创建一个矩阵乘法,这里要注意的是,创建了乘法后,是不会立即执行的,要在会话中运行才行
product = tf.matmul(v1, v2)
# 这个时候打印,得到的不是他们乘法之后的结果,而是得到乘法本身
print(product)

# 定义一个会话
sess = tf.Session()
# 运行乘法,得到结果
result = sess.run(product)
# 打印结果
示例#8
0
# -*- coding:UTF-8 -*-
'''
    正则表达式
'''

import re

import log_utils as log

# re.match函数
log.loge("match函数")
# 在起始位置匹配
print(re.match("www", "www.baidu.com").span())
# 不在起始位置匹配
print(re.match("com", "www.baidu.com"))

line = "Cat are smarter than dogs"
matchObj = re.match(r'(.*) are (.*?) .*', line, re.M | re.I)

if matchObj:
    print("matchObj.group(): ", matchObj.group())
    print("matchObj.group(1): ", matchObj.group(1))
    print("matchObj.group(2): ", matchObj.group(2))
else:
    print("No match!")
log.loge("match函数")

log.loge("search方法")
# re.search方法
# 在起始位置匹配
print(re.search("www", "www.baidu.com").span())
示例#9
0
time_strftime = time.strftime("%y-%m-%d %H:%M:%S", time.localtime())
print("格式化后的本地时间为:", time_strftime)

# 格式化成Sat Mar 28 22:24:24 2016形式
time_strftime = time.strftime("%a %b %d %H:%M:%S %Y", time.localtime())
print("格式化后的本地时间为:", time_strftime)

#  将格式字符串转换为时间戳
a = "Fri Jun 08 15:30:55 2018"
print("将a格式字符串转换为时间戳:", time.mktime(time.strptime(a, "%a %b %d %H:%M:%S %Y")))
"""
获取某月日历
Calendar模块有很广泛的方法用来处理年历和月历
"""

log.loge("获取某月日历")
import calendar

cal = calendar.month(2018, 7)
print("以下是2018年7月份的日历:")
print(cal)
log.loge("获取某月日历")

# 使用datetime模块来获取当前的日期和时间
log.loge("datetime")
import datetime

i = datetime.datetime.now()
print("当前的日期和时间是 %s" % i)
print("ISO格式的日期和时间是 %s" % i.isoformat())
print("当前的年份是 %s" % i.year)
# -*- coding:UTF-8 -*-
'''
    多线程
'''
import log_utils as log

# -----------------     _thread 使用     -----------------

log.loge("_thread 使用")
import time


# 为纯种定义一个函数
def print_time(threadName, delay):
    count = 0
    while count < 5:
        time.sleep(delay)
        count += 1
        print("%s: %s" % (threadName, time.ctime(time.time())))


# 创建两个线程
# _thread.start_new(print_time, ("Thread-1", 2,))
# _thread.start_new(print_time, ("Thread-2", 4,))
#
# while 1:
#     pass
log.loge("_thread 使用")
# -----------------     _thread 使用     -----------------

# -----------------     threading 使用     -----------------
示例#11
0
# -*- coding:UTF-8 -*-

'''
    json解析与生成
'''

# -----------------     json.dumps 与 json.loads 实例     -----------------
import log_utils as log

log.loge("对数据进行编码")
'''
json.dumps(): 对数据进行编码。
json.loads(): 对数据进行解码。
'''
import json

# python字典类型转换为Json对象
data = {
    'no': 1,
    'name': 'test01',
    'url': 'http://www.baidu.com'
}

json_str = json.dumps(data)
print("Python 原始数据: ", repr(data))
print("Json对象: ", json_str)

log.loge("对数据进行编码")

log.loge("对数据进行解码")
# 将Json对象转换为Python字典