steve+comp.lang.python at pearwood.info
Mon Sep 12 23:28:33 EDT 2011
(I sent this reply a week ago, but it seems to have disappeared. So trying
On Tue, 6 Sep 2011 06:18 pm 守株待兔 wrote:
> when i add (date,open,high,low,close,vol,adjclose) = (row, row,
> row, row,row, row, row) change the code into
Here you define a new variable called "open", which has the value of row.
This shadows (hides) the built-in function also called "open", so later
when you do this:
> file = open(filename,'r')
> TypeError: 'str' object is not callable
Python uses your string variable "open" instead of the built-in function.
The best solution is to avoid using the name "open", instead call it "open_"
(underscore at the end is the usual convention to avoid shadowing
built-ins). Or "open_value" or any other appropriate name.
Another solution is to save a reference to the open built-in first:
my_open = open
open = "something"
file = my_open("filename", "r")
More information about the Python-list