'str' object is not callable even not used str in code
i am getting this error. how to solve this? please help me out.
# Import pandas
import pandas as pd
import csv
# Load csv
#df = pd.read_csv("D:HarshaTradingcm14SEP2018bhav.csv")
# Read in csv file
#for row in csv.reader(open("D:HarshaTradingcm14SEP2018bhav.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()
I have not used str in my code. Why am I getting this error?
python-3.x pandas csv
add a comment |
i am getting this error. how to solve this? please help me out.
# Import pandas
import pandas as pd
import csv
# Load csv
#df = pd.read_csv("D:HarshaTradingcm14SEP2018bhav.csv")
# Read in csv file
#for row in csv.reader(open("D:HarshaTradingcm14SEP2018bhav.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()
I have not used str in my code. Why am I getting this error?
python-3.x pandas csv
I don't think that can be your complete code; for me, python throws a syntax error just trying to compile it, and ending withwith open(infile, 'r') as fh:
looks wrong; please provide a minimal, complete, and verifiable example
– landru27
Nov 11 '18 at 19:26
Begging and SHOUTING instead of reading comments and improving your question does not help. Format the code to be readable and post the error message. Most likey at some point you've donestr = 'something'
and overridden the default value ofstr
. Restart your editor.
– Mark Tolonen
Nov 11 '18 at 20:41
Mark i am not shouting on anybody nor i am begging. I am seeking guidance from seniors to solve this str callable error. I have not included str anywhere in my whole code. Then why i am getting this error?
– kamal sharma
Nov 12 '18 at 2:50
@kamalsharma the way this error is normally produced is if you do something like this:a = 'hello'; print(a());
- if you assign astr
type object to a variable and then try to 'call' that object as if it were a function. you have used plenty of strings in this code, but I don't see anything that would cause this error. It is also possible if you overwrite a built in function (or one of your own functions) with a string object, then try to call it.
– Stael
Dec 4 '18 at 9:27
add a comment |
i am getting this error. how to solve this? please help me out.
# Import pandas
import pandas as pd
import csv
# Load csv
#df = pd.read_csv("D:HarshaTradingcm14SEP2018bhav.csv")
# Read in csv file
#for row in csv.reader(open("D:HarshaTradingcm14SEP2018bhav.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()
I have not used str in my code. Why am I getting this error?
python-3.x pandas csv
i am getting this error. how to solve this? please help me out.
# Import pandas
import pandas as pd
import csv
# Load csv
#df = pd.read_csv("D:HarshaTradingcm14SEP2018bhav.csv")
# Read in csv file
#for row in csv.reader(open("D:HarshaTradingcm14SEP2018bhav.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()
I have not used str in my code. Why am I getting this error?
python-3.x pandas csv
python-3.x pandas csv
edited Nov 11 '18 at 20:44
Mark Tolonen
93.5k12113176
93.5k12113176
asked Nov 11 '18 at 18:57
kamal sharmakamal sharma
11
11
I don't think that can be your complete code; for me, python throws a syntax error just trying to compile it, and ending withwith open(infile, 'r') as fh:
looks wrong; please provide a minimal, complete, and verifiable example
– landru27
Nov 11 '18 at 19:26
Begging and SHOUTING instead of reading comments and improving your question does not help. Format the code to be readable and post the error message. Most likey at some point you've donestr = 'something'
and overridden the default value ofstr
. Restart your editor.
– Mark Tolonen
Nov 11 '18 at 20:41
Mark i am not shouting on anybody nor i am begging. I am seeking guidance from seniors to solve this str callable error. I have not included str anywhere in my whole code. Then why i am getting this error?
– kamal sharma
Nov 12 '18 at 2:50
@kamalsharma the way this error is normally produced is if you do something like this:a = 'hello'; print(a());
- if you assign astr
type object to a variable and then try to 'call' that object as if it were a function. you have used plenty of strings in this code, but I don't see anything that would cause this error. It is also possible if you overwrite a built in function (or one of your own functions) with a string object, then try to call it.
– Stael
Dec 4 '18 at 9:27
add a comment |
I don't think that can be your complete code; for me, python throws a syntax error just trying to compile it, and ending withwith open(infile, 'r') as fh:
looks wrong; please provide a minimal, complete, and verifiable example
– landru27
Nov 11 '18 at 19:26
Begging and SHOUTING instead of reading comments and improving your question does not help. Format the code to be readable and post the error message. Most likey at some point you've donestr = 'something'
and overridden the default value ofstr
. Restart your editor.
– Mark Tolonen
Nov 11 '18 at 20:41
Mark i am not shouting on anybody nor i am begging. I am seeking guidance from seniors to solve this str callable error. I have not included str anywhere in my whole code. Then why i am getting this error?
– kamal sharma
Nov 12 '18 at 2:50
@kamalsharma the way this error is normally produced is if you do something like this:a = 'hello'; print(a());
- if you assign astr
type object to a variable and then try to 'call' that object as if it were a function. you have used plenty of strings in this code, but I don't see anything that would cause this error. It is also possible if you overwrite a built in function (or one of your own functions) with a string object, then try to call it.
– Stael
Dec 4 '18 at 9:27
I don't think that can be your complete code; for me, python throws a syntax error just trying to compile it, and ending with
with open(infile, 'r') as fh:
looks wrong; please provide a minimal, complete, and verifiable example– landru27
Nov 11 '18 at 19:26
I don't think that can be your complete code; for me, python throws a syntax error just trying to compile it, and ending with
with open(infile, 'r') as fh:
looks wrong; please provide a minimal, complete, and verifiable example– landru27
Nov 11 '18 at 19:26
Begging and SHOUTING instead of reading comments and improving your question does not help. Format the code to be readable and post the error message. Most likey at some point you've done
str = 'something'
and overridden the default value of str
. Restart your editor.– Mark Tolonen
Nov 11 '18 at 20:41
Begging and SHOUTING instead of reading comments and improving your question does not help. Format the code to be readable and post the error message. Most likey at some point you've done
str = 'something'
and overridden the default value of str
. Restart your editor.– Mark Tolonen
Nov 11 '18 at 20:41
Mark i am not shouting on anybody nor i am begging. I am seeking guidance from seniors to solve this str callable error. I have not included str anywhere in my whole code. Then why i am getting this error?
– kamal sharma
Nov 12 '18 at 2:50
Mark i am not shouting on anybody nor i am begging. I am seeking guidance from seniors to solve this str callable error. I have not included str anywhere in my whole code. Then why i am getting this error?
– kamal sharma
Nov 12 '18 at 2:50
@kamalsharma the way this error is normally produced is if you do something like this:
a = 'hello'; print(a());
- if you assign a str
type object to a variable and then try to 'call' that object as if it were a function. you have used plenty of strings in this code, but I don't see anything that would cause this error. It is also possible if you overwrite a built in function (or one of your own functions) with a string object, then try to call it.– Stael
Dec 4 '18 at 9:27
@kamalsharma the way this error is normally produced is if you do something like this:
a = 'hello'; print(a());
- if you assign a str
type object to a variable and then try to 'call' that object as if it were a function. you have used plenty of strings in this code, but I don't see anything that would cause this error. It is also possible if you overwrite a built in function (or one of your own functions) with a string object, then try to call it.– Stael
Dec 4 '18 at 9:27
add a comment |
2 Answers
2
active
oldest
votes
I believe when you're using format to print, you should avoid adding a string value to the format argument.
so all the code that's writing to the wfh file like these:
wfh.write(",,,,,,,".format(symbol, open, high, low, close, isin, tottrdqty, "SELL"))
need to be changed to:
wfh.write(",,,,,,,SELL".format(symbol, open, high, low, close, isin, tottrdqty))
# here 'Sell' is a part of the print argument which is already under quotes.
add a comment |
found it:
open = row['OPEN']
this code re-assigns the python keyword open (which you use to open files) with the contents of row['OPEN']
that means that now when you call open
you are calling a str
object, not a function.
consider this:
print(type(open))
# <class 'builtin_function_or_method'>
open = 'hello, world'
print(type(open))
# print(type('hello, world'))
you can no longer 'call' open (ie open('file.txt', 'r')
) because it is a string, not a function.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252098%2fstr-object-is-not-callable-even-not-used-str-in-code%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I believe when you're using format to print, you should avoid adding a string value to the format argument.
so all the code that's writing to the wfh file like these:
wfh.write(",,,,,,,".format(symbol, open, high, low, close, isin, tottrdqty, "SELL"))
need to be changed to:
wfh.write(",,,,,,,SELL".format(symbol, open, high, low, close, isin, tottrdqty))
# here 'Sell' is a part of the print argument which is already under quotes.
add a comment |
I believe when you're using format to print, you should avoid adding a string value to the format argument.
so all the code that's writing to the wfh file like these:
wfh.write(",,,,,,,".format(symbol, open, high, low, close, isin, tottrdqty, "SELL"))
need to be changed to:
wfh.write(",,,,,,,SELL".format(symbol, open, high, low, close, isin, tottrdqty))
# here 'Sell' is a part of the print argument which is already under quotes.
add a comment |
I believe when you're using format to print, you should avoid adding a string value to the format argument.
so all the code that's writing to the wfh file like these:
wfh.write(",,,,,,,".format(symbol, open, high, low, close, isin, tottrdqty, "SELL"))
need to be changed to:
wfh.write(",,,,,,,SELL".format(symbol, open, high, low, close, isin, tottrdqty))
# here 'Sell' is a part of the print argument which is already under quotes.
I believe when you're using format to print, you should avoid adding a string value to the format argument.
so all the code that's writing to the wfh file like these:
wfh.write(",,,,,,,".format(symbol, open, high, low, close, isin, tottrdqty, "SELL"))
need to be changed to:
wfh.write(",,,,,,,SELL".format(symbol, open, high, low, close, isin, tottrdqty))
# here 'Sell' is a part of the print argument which is already under quotes.
answered Dec 4 '18 at 9:17
ParvBanksParvBanks
62017
62017
add a comment |
add a comment |
found it:
open = row['OPEN']
this code re-assigns the python keyword open (which you use to open files) with the contents of row['OPEN']
that means that now when you call open
you are calling a str
object, not a function.
consider this:
print(type(open))
# <class 'builtin_function_or_method'>
open = 'hello, world'
print(type(open))
# print(type('hello, world'))
you can no longer 'call' open (ie open('file.txt', 'r')
) because it is a string, not a function.
add a comment |
found it:
open = row['OPEN']
this code re-assigns the python keyword open (which you use to open files) with the contents of row['OPEN']
that means that now when you call open
you are calling a str
object, not a function.
consider this:
print(type(open))
# <class 'builtin_function_or_method'>
open = 'hello, world'
print(type(open))
# print(type('hello, world'))
you can no longer 'call' open (ie open('file.txt', 'r')
) because it is a string, not a function.
add a comment |
found it:
open = row['OPEN']
this code re-assigns the python keyword open (which you use to open files) with the contents of row['OPEN']
that means that now when you call open
you are calling a str
object, not a function.
consider this:
print(type(open))
# <class 'builtin_function_or_method'>
open = 'hello, world'
print(type(open))
# print(type('hello, world'))
you can no longer 'call' open (ie open('file.txt', 'r')
) because it is a string, not a function.
found it:
open = row['OPEN']
this code re-assigns the python keyword open (which you use to open files) with the contents of row['OPEN']
that means that now when you call open
you are calling a str
object, not a function.
consider this:
print(type(open))
# <class 'builtin_function_or_method'>
open = 'hello, world'
print(type(open))
# print(type('hello, world'))
you can no longer 'call' open (ie open('file.txt', 'r')
) because it is a string, not a function.
answered Dec 4 '18 at 9:28
StaelStael
1,336314
1,336314
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252098%2fstr-object-is-not-callable-even-not-used-str-in-code%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I don't think that can be your complete code; for me, python throws a syntax error just trying to compile it, and ending with
with open(infile, 'r') as fh:
looks wrong; please provide a minimal, complete, and verifiable example– landru27
Nov 11 '18 at 19:26
Begging and SHOUTING instead of reading comments and improving your question does not help. Format the code to be readable and post the error message. Most likey at some point you've done
str = 'something'
and overridden the default value ofstr
. Restart your editor.– Mark Tolonen
Nov 11 '18 at 20:41
Mark i am not shouting on anybody nor i am begging. I am seeking guidance from seniors to solve this str callable error. I have not included str anywhere in my whole code. Then why i am getting this error?
– kamal sharma
Nov 12 '18 at 2:50
@kamalsharma the way this error is normally produced is if you do something like this:
a = 'hello'; print(a());
- if you assign astr
type object to a variable and then try to 'call' that object as if it were a function. you have used plenty of strings in this code, but I don't see anything that would cause this error. It is also possible if you overwrite a built in function (or one of your own functions) with a string object, then try to call it.– Stael
Dec 4 '18 at 9:27