VasaraBharat
VasaraBharat

Reputation: 81

file open throws an error float type

I have one method which takes many argument and also return multiple value

I am trying to open a file in that method but it shows me error like

fc=open("ABC.txt","a")
Type Error: 'float' object is not callable`

I don't know why it is showing this error i mean there is nothing like a float value. The same line if I put in the calling function then it will create/open file successfully.

  fc=open("ABC.txt","a")

Upvotes: 0

Views: 519

Answers (2)

DevShark
DevShark

Reputation: 9122

You must have used the variable name "open" and assigned a float to it in your code before arriving to this line of code. Something like this:

open = 2.3

Note that it is considered very bad practice to use names of built-in functions for your own variables (you end up with issues like the one you are raising).

If you want to convince yourself that this is the issue, you can print your variable before your line:

print open

If you wanted to be very lazy, and can't find where "open" is in your code, you can use this horrible hack:

openTemp = open
del open
open("file_name", "a")
open = openTemp

This would be the fastest hack to get this to work, but I can't recommend it... Cleaning your code is better! I just mention it because it's interesting to see this, it is an example of how del works. In this case, it gives you back access to the built-in function.

Upvotes: 0

Anand S Kumar
Anand S Kumar

Reputation: 90979

The issue might be that somewhere else in your code, you have defined a variable called open which is storing a float type value. Example -

open = 0.1

The above line actually overwrites the inbuilt function open with the float variable, hence after this line any call to open would be referencing the float variable, causing the issue. You should not use built-in names for variables, try renaming the variable.

Upvotes: 2

Related Questions