【发布时间】:2019-04-14 13:55:08
【问题描述】:
我收到此错误。如何解决这个问题?请帮帮我。
# Import pandas
import pandas as pd
import csv
# Load csv
#df = pd.read_csv("D:\Harsha\Trading\cm14SEP2018bhav.csv")
# Read in csv file
#for row in csv.reader(open("D:\Harsha\Trading\cm14SEP2018bhav.csv"), delimiter=','):
#print(row)
#import csv
infile = 'H:\cm09NOV2018bhav.csv'
outfile = 'H:\output_cm09NOV2018bhav.csv'
wfh = open (outfile, 'w')
with open(infile, 'r') as fh:
reader = csv.DictReader(fh, delimiter=',')
wfh.write("{},{},{},{},{},{},{}".format("SYMBOL", "OPEN", "HIGH", "LOW", "CLOSE", "ISIN", "TOTTRDQTY", "STATUS"))
wfh.write("\n")
for row in reader:
symbol = row['SYMBOL']
series = row['SERIES']
open = row['OPEN']
high = row['HIGH']
low = row['LOW']
close = row['CLOSE']
last = row['LAST']
prevclose = row['PREVCLOSE']
tottrdqty = row['TOTTRDQTY']
tottrdval = row['TOTTRDVAL']
timestamp = row['TIMESTAMP']
totaltrades = row['TOTALTRADES']
isin = row['ISIN']
print(low.rstrip())
if float(high.rstrip()) in [9,25,49,81,121,169,225,289,301,441,529,625]:
wfh.write("{},{},{},{},{},{},{},{}".format(symbol, open, high, low, close, isin, tottrdqty, "SELL"))
wfh.write("\n")
elif float(low.rstrip()) in [9,25,49,81,121,169,225,289,301,441,529,625]:
wfh.write("{},{},{},{},{},{},{},{}".format(symbol, open, high, low, close, isin, tottrdqty, "BUY"))
wfh.write("\n")
elif float(close.rstrip()) in [9,25,49,81,121,169,225,289,301,441,529,625]:
wfh.write("{},{},{},{},{},{},{},{}".format(symbol, open, high, low, close, isin, tottrdqty, "CLOSE PRICE"))
wfh.write("\n")
elif float(open.rstrip()) in [9,25,49,81,121,169,225,289,301,441,529,625]:
wfh.write("{},{},{},{},{},{},{},{}".format(symbol, open, high, low, close, isin, tottrdqty, "OPEN PRICE"))
wfh.write("\n")
#wfh._archive.close()
wfh.close()
我没有在我的代码中使用 str 。为什么会出现此错误?
【问题讨论】:
-
我认为这不是您的完整代码;对我来说,python 只是试图编译它就会抛出一个语法错误,并且以
with open(infile, 'r') as fh:结尾看起来是错误的;请提供minimal, complete, and verifiable example -
乞求和大喊而不是阅读 cmets 和改进您的问题无济于事。将代码格式化为可读并发布错误消息。很可能在某个时候你已经完成了
str = 'something'并覆盖了str的默认值。重新启动编辑器。 -
马克,我不是对任何人大喊大叫,也不是在乞求。我正在寻求前辈的指导来解决这个 str 可调用错误。我的整个代码中都没有包含 str 。那为什么我会收到这个错误?
-
@kamalsharma 通常产生此错误的方式是,如果您执行以下操作:
a = 'hello'; print(a());- 如果您将str类型对象分配给变量,然后尝试“调用”该对象好像它是一个函数。您在此代码中使用了大量字符串,但我没有看到任何会导致此错误的内容。如果您用字符串对象覆盖内置函数(或您自己的函数之一),然后尝试调用它,也是可能的。
标签: python-3.x pandas csv