'str' object is not callable even not used str in code












-2














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?










share|improve this question
























  • 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 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 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 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 at 9:27
















-2














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?










share|improve this question
























  • 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 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 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 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 at 9:27














-2












-2








-2







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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 20:44









Mark Tolonen

90.7k12109175




90.7k12109175










asked Nov 11 at 18:57









kamal 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 with with open(infile, 'r') as fh: looks wrong; please provide a minimal, complete, and verifiable example
    – landru27
    Nov 11 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 at 9:27












2 Answers
2






active

oldest

votes


















0














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.





share|improve this answer





























    0














    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.






    share|improve this answer





















      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      0














      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.





      share|improve this answer


























        0














        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.





        share|improve this answer
























          0












          0








          0






          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.





          share|improve this answer












          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.






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 4 at 9:17









          ParvBanks

          50117




          50117

























              0














              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.






              share|improve this answer


























                0














                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.






                share|improve this answer
























                  0












                  0








                  0






                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 4 at 9:28









                  Stael

                  1,291314




                  1,291314






























                      draft saved

                      draft discarded




















































                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Coverage of Google Street View

                      Full-time equivalent

                      Surfing