我的数组没有超过第一个值

时间:2014-05-30 17:40:31

标签: python-2.7

出于某种原因,代码缩进对我来说并不适合。 " def cleanup():"没有缩进,其余的缩进1。 我的问题是当我使用" print s"时,数组将打印区域中所有25个(estimante)的值。但是当代码运行编辑outfile时,它只打印数组中的第一个值。我无法弄清楚发生了什么,因为" print s"产生我想要的东西。

   def cleanup():

infile = open('HDDprices-pre.txt')
outfile = open('HDDprices.txt', 'wt')
for s in hdd:
    line = infile.readline()
    #line = line.replace("('","")
    line = line.replace("Decimal('",s+": ")
    line = line.replace("'),","\n")
    line = line.replace("'))","")
    outfile.write(line)
    print s
infile.close()
outfile.close()
os.remove('HDDprices-pre.txt') #erase pre file

hdd的内容(位于脚本顶部)

 hdd = ('HDD_Desktop_SATA_4TB, HDD_Desktop_SATA_3TB, HDD_Desktop_SATA_2TB, HDD_Desktop_SATA_1TB, HDD_Desktop_SATA_750GB, HDD_Desktop_SATA_500GB, HDD_Desktop_SATA_250GB, HDD_Desktop_SATA_200GB, HDD_Laptop_SATA_2TB, HDD_Laptop_SATA_1TB, HDD_Laptop_SATA_750GB, HDD_Laptop_SATA_500GB, HDD_Laptop_SATA_400GB, HDD_Laptop_SATA_320GB, HDD_Laptop_SATA_300GB, HDD_Laptop_SATA_250GB, HDD_Laptop_SATA_200GB, HDD_Laptop_SATA_160GB, HDD_Laptop_SATA_150GB, HDD_Laptop_SATA_120GB, HDD_Laptop_SATA_100GB, HDD_Desktop_IDE_750GB, HDD_Desktop_IDE_500GB, HDD_Desktop_IDE_400GB, HDD_Desktop_IDE_320GB, HDD_Desktop_IDE_250GB, HDD_SSD_512GB, HDD_SSD_480GB, HDD_SSD_256GB, HDD_SSD_250GB, HDD_SSD_240GB, HDD_SSD_160GB, HDD_SSD_128GB, HDD_SSD_80GB, HDD_SSD_64GB, HDD_SSD_60GB, HDD_SSD_32GB, HDD_SSD_30GB')
 hdd = hdd.split(',')

HDDprices-pre.txt

(Decimal('164.98'), Decimal('110.00'), Decimal('87.00'), Decimal('54.99'), Decimal('64.99'), Decimal('44.95'), Decimal('26.98'), Decimal('0.00'), Decimal('153.98'), Decimal('72.48'), Decimal('56.99'), Decimal('42.99'), Decimal('82.00'), Decimal('35.99'), Decimal('92.00'), Decimal('31.99'), Decimal('0.00'), Decimal('29.88'), Decimal('139.00'), Decimal('85.00'), Decimal('79.00'), Decimal('207.00'), Decimal('119.95'), Decimal('110.00'), Decimal('34.95'), Decimal('24.88'), Decimal('285.20'), Decimal('229.50'), Decimal('148.99'), Decimal('119.99'), Decimal('119.99'), Decimal('166.00'), Decimal('72.00'), Decimal('90.30'), Decimal('56.99'), Decimal('53.48'), Decimal('34.99'), Decimal('67.99'))

1 个答案:

答案 0 :(得分:1)

输入文件中只有一行。每个"十进制('"将被替换为' HDD_Desktop_SATA_4TB'。在下一次迭代readline()将返回一个空字符串。