没有从这个简单的python代码生成的输出?

时间:2018-01-18 17:28:37

标签: python

我在这里错过了吗?为什么这段代码没有将数据输出到我打开的文件中?有什么想法吗?

以下是整个代码的基本部分,它已经通过编译器而没有错误,但没有将数据输出到文件。

#! /usr/bin/python

#Basic imports
import sys
from time import sleep
from datetime import datetime,date,time
import numpy as np

#Create Bridge objects
try:
    bridge_1 = Bridge()

outfile = open("prototype.csv", "a")


# Initialize all sensors and discard the readings
    lc1_ini = bridge_1.getBridgeValue(0) * 2674.0 - 210.7

    sleep(1)

    lc1 = bridge_1.getBridgeValue(0) * 2674.0 - 210.7



# create empty array to store the converted digital data
    readings_lc1 = np.empty([])

    avg_lc1 = np.empty([])

    max_samples = 3

    readings_lc1  = np.append(readings_lc1 , lc1 )

    if len(readings_lc1) == max_samples:        
     avg_lc1  = np.mean(readings_lc1[1:])


    #Write the data to the text file

    outfile.write(str(datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')) + "," + str(round(lc1,2)) + "\n")

outfile.close()

0 个答案:

没有答案