1. 判斷 檔案 是否為空

本來用for i in data: if i==None:

來作為判斷檔案是否為空的code

但發覺這是無效的...

 

底下是用 os.stat("/wayne_code/of.txt").st_size == 0: 來做判斷!!

#!/usr/bin/env python

import os
import subprocess
import time

data=open('/wayne_code/of.txt')

if os.stat("/wayne_code/of.txt").st_size == 0:
  print("None of lines in file")

else:
  print("It has lines in file")


data.close()

 

2. 判斷 資料表 是否為空

 

db = MySQLdb.connect(host="localhost", user="root", passwd="5796857968", db="OVS")
cursor = db.cursor() #Create instance to access DB

cursor.execute("SELECT FK, Help_Nu FROM Pica8_Switch_Help")

return_del_nu_rows = cursor.rowcount #rows
return_del_switch_info = cursor.fetchall()#Return information, tuple type


if not return_del_switch_info: #資料表 "為空" 的話

 

 

 

文章標籤
全站熱搜
創作者介紹
創作者 Wayne 的頭像
Wayne

Wayne Technique Study

Wayne 發表在 痞客邦 留言(0) 人氣(623)