how to resolve 'int' object is not callable
I am new over here
-68+(((68)**2-4(34)(-510))**0.5)/(2*34)
Traceback (most recent call last):
File "", line 1, in
-68+(((68)**2-4(34)(-510))**0.5)/(2*34)
TypeError: 'int' object is not callable
there is no output only the error message written above. How to resolve this error message?
Python does not support multiplication through parentheses (like (34)(-510) and 4(34)). Change this to (34) * (-510). So, your full line would be:
>>> -68+(((68)**2-4*(34)*(-510))**0.5)/(2*34)
-64.0
When you say 4(34), you're actually telling the interpreter to call the function named 4 with the argument 34. (This is the same syntax as saying a(34), where a is a function.) The error is because 4 is not a function, so you can't call it.
If you don't work in the python interpreter directly, you need to do something with your calcul, like putting it in a variable like this :
a = -68+(((68)**2-4*(34)*(-510))**0.5)/(2*34)
or print it :
print(-68+(((68)**2-4*(34)*(-510))**0.5)/(2*34))
Also you can't do maths with two values into parenthesis, you need to include a '*'.
Finally, doing 4(34) is like you're calling a function named "4", with an argument (34).
Related
I'm having trouble wrapping my brain around this error. It's really basic, but it seems to say the opposite of what is true.
>>> x=b'hi'
>>> urllib.parse.unquote(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 609, in unquote
if '%' not in string:
TypeError: a bytes-like object is required, not 'str'
I've passed the code a bytes object, I would hope that's bytes-like enough. urllib.parse.unquote() seems to only work with a str object.
So why would it generate an error saying it needs a bytes-like object?
I suggest to use urllib.parse.unquote_to_bytes, which encodes its string parameter to bytes if it receives a str object.
urllib.parse.unquote_to_bytes(x)
I'm currently trying to understand Pyth. I know Python quite well, but I don't get Pyth sometimes.
My code:
DhNKlNFzrKZaY#Nz;Y;hQ
It's just a basic script for reversing string, and traceback gives me ValueError,
ValueError: malformed node or string: <_ast.Name object at 0x7ff2fde45c18>
Despite my Python knowledge I have no idea what does this error mean. Can you show me where is this error coming from?
I assume you are getting an error like this one here:
Traceback (most recent call last):
File "pyth.py", line 771, in <module>
File "<string>", line 3, in <module>
File "/app/macros.py", line 691, in eval_input
File "/app/.heroku/python/lib/python3.4/ast.py", line 84, in literal_eval
File "/app/.heroku/python/lib/python3.4/ast.py", line 83, in _convert
ValueError: malformed node or string: <_ast.Name object at 0x7fac26eb2b70>
First off, you use z and Q inconsistently. With your current code, input should have been taken like this instead:
"abcd"
abcd
When Q is used in a Pyth program, z implicitly jumps to the next line of input, it just skips whatever has been inputted before using Q. Instead, just use:
DhNKlNFzrKZaY#Nz;Y;hz
And the errors should go away.
I am not sure why you would want to perform string reversal that way, though. I use _z if the input is not quoted and _ alone otherwise, since Q is implicit at the end of any Pyth program.
I'm new to folium. I was able to produce the map I wanted from a dataframe.
df_map = folium.Map(location=[37.750999450684, -97.821998596191], zoom_start=4)
for each in df[0:len(df)].iterrows():
folium.CircleMarker(location=[each[1]["GEO_LAT_0"], each[1]["GEO_LNG_0"]],
radius=5.0, color='#3186cc', fill_color='#3186cc').add_to(df_map)
Map comes out nicely.
Next I wanted to add popups from a third column in data frame, and can't seem to get syntax right. Not clear how I might add these popups from folium documentation. An error message I can't interpret results from this code:
df_map = folium.Map(location=[37.750999450684, -97.821998596191], zoom_start=4)
for each in df[0:len(df)].iterrows():
folium.CircleMarker(location=[each[1]["GEO_LAT_0"], each[1]["GEO_LNG_0"]],
**popup=each[1]["GEO_CITY_0"],**
radius=5.0, color='#3186cc',fill_color='#3186cc').add_to(df_map)
To verify my loop and dataframe were ok, I substituted a
print each[1]["GEO_CITY_0"]
within the for-each loop instead of folium.circlemarker and it worked fine. Something is wrong when I use the popup syntax above.
AttributeError: 'float' object has no attribute 'get_name'
Your help appreciated. Thanks p.s. Full message is:
Traceback (most recent call last):
File "", line 4, in
radius=1, color='#3186cc', fill_color='#3186cc').add_to(df_map)
File "C:\Users\Peter\Anaconda3\lib\site-packages\folium\features.py", line 870, in init
super(CircleMarker, self).init(location=location, popup=popup)
File "C:\Users\Peter\Anaconda3\lib\site-packages\folium\map.py", line 652, in init
self.add_child(popup)
File "C:\Users\Peter\Anaconda3\lib\site-packages\branca\element.py", line 96, in add_child
name = child.get_name()
AttributeError: 'float' object has no attribute 'get_name'
I was under the impression that #pzajonc's syntax of popup=each[1]["GEO_CITY_0"] would work in recent versions (OP's has 0.4.0) of folium.
Here's a github issue that mentions the error and the fix
Regardless, changing it to popup=folium.Popup(each[1]["GEO_CITY_0"]) will resolve the issue.
This question already has answers here:
Python: function and variable with the same name
(3 answers)
Closed 6 years ago.
I'm newbie in python.
As I learned, str(123) returns the string format of value 123 which is '123'
but what if we have a variable named str, how can I call the str function?
In[2]: str(123)
Out[2]: '123'
In[3]: str='hello world'
In[4]: str(123)
Traceback (most recent call last):
File "/Users/x625/anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2885, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-6d97c31da288>", line 1, in <module>
str(123)
TypeError: 'str' object is not callable
How can I call str() function again?
You still can access it:
import builtins
builtins.str(123)
Don't use str as a variable name, it is a keyword.
Just don't call your variables str.
If you made a mistake in interactive mode and need to get rid of a variable you picked a bad name for, you can do del str, but don't do that in an actual program.
Your variable name str='hello world' collides withe the function str.
Just pick another name to your variable.
I have tried to understand this by looking in previous threads but I still don't understand why I get this error for only one of two variables in the following piece of code (the code sucks I know):
alfaphet=('abcdefghijklmnopqrstuvxyz')
cryptalfaphet=('defghjiklmnopqrstuvxyzabc')
spaceNumber=[]
textCopy=[]
def crypt():
textCopy=[]
print('print the text that you want to encrypt:')
text=input()
for i in range(len(text)):
for j in range(len(alfaphet)):
if text[i]==alfaphet[j]:
textCopy.append(cryptalfaphet[j])
if text[i]==' ':
spaceNumber.append(i)
for i in range(len(spaceNumber)):
for j in range(len(text)):
if list(range(len(text)))[j]==int(spaceNumber[i]):
textCopy.insert(j, ' ')
textCopy=''.join(textCopy)
print(textCopy)
crypt()
This code works fine, but if I remove the
textCopy=[]
asignment from the beginning of the def-block, I get an error like this:
Traceback (most recent call last):
File "C:/Python33/dekrypt.py", line 26, in <module>
crypt()
File "C:/Python33/dekrypt.py", line 13, in crypt
textCopy.append(cryptalfaphet[j])
UnboundLocalError: local variable 'textCopy' referenced before assignment
My question is why this doesn't happen with the spaceNumber variable. spaceNumber is as far I can see also referenced before asignment with the
spaceNumber.append(i)
asignment? It is referenced before the def-block, but so was the textCopy vaiable right? What is the difference, they're both empty lists from the beginning and I use the .append() method on both, but Python seems to treat them differently!?
You can avoid this error by adding the following line at beginning of your function
def crypt():
global textCopy
...
however, this isn't a python best practice. See this post for further details.