traceback nameerror in python2 - python-2.7

I am relatively new to programming,
and i was trying to do a checkbutton and i'm getting a traceback (most recent call last): and NameError message. please help. thanks!
chack_button = Chackbutton(root, text="show password", commend=show_password)
chack_button.place(x=290, y=170)
Traceback (most recent call last):
File "new2.py", line 19, in <module>
chack_button = Chackbutton(root, text="show password", commend=show_password)
NameError: name 'Chackbutton' is not defined

You've written Chackbutton instead of Checkbutton

Related

How to fix "EOF when reading a line" using plugin Python-Notepad++

I'm using python plugin in Notepad++ and trying to use input() in a script I get this error
>>> name=input()
Traceback (most recent call last):
File "<console>", line 1, in <module>
EOFError: EOF when reading a line
I've tried solutions in other threads of SO like using try/except block as below, but still getting the error. Is there a workaround for this? Thank you.
>>> try:
... input("Please enter something")
... except:
... break
File "<console>", line 4
SyntaxError: 'break' outside loop
>>> try:
... name=input()
... except EOFError:
... break
File "<console>", line 4
SyntaxError: 'break' outside loop
Traceback (most recent call last):
UPDATE
>>> try:
... input("Please enter something: ")
... except EOFError as e:
... print(e)
...
Please enter something: EOF when reading a line
>>> abc
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'abc' is not defined
change break to pass and you should pass that error or use
except EOFError as e:
print(e)
so you will know when it happened. All I can help as I can't replicate it here, works just fine for me. Use break only in loops.

Why isdigit is working but isdecimal is not for a simple age code

This is the part of code I am talking about:
while True:
print 'What is your age(only numeric):'
age = raw_input()
if age.isdigit():
break
print 'Please try again. We take only numeric value.'
When I replace isdigit with isdecimal, I get this error no matter what value i enter.
Traceback (most recent call last):
File "test.py", line 4, in <module>
if age.isdecimal():
AttributeError: 'str' object has no attribute 'isdecimal'
Although it runs fine with isdigit.
Also, when I replace raw_input with input, it give this error.
Traceback (most recent call last):
File "test.py", line 4, in <module>
if age.isdigit():
AttributeError: 'int' object has no attribute 'isdigit'
Am I doing something wrong which I am not able to catch? I am new to python and did my research about isdigit, is decimal, input and raw_input before putting down question here. It may be very minute error but I am not sure what is it.
For the first part:
In Python 2, isdecimal is a method of the unicode class, not of str (i.e. bytes). Hence:
>>> '3.2'.isdecimal()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'isdecimal'
>>> u'3.2'.isdecimal()
For the second part, input tries to guess what kind of input it gets, and will properly cast "1" into an int, while raw_input will always return the raw string. Since isdigit is a method defined in the str class, you get the error.

Is there a reason `tolist()` can't operate on a list?

I often think it would be nice to have the following work even if the original object is a list... Is there a reason why this functionality is not implemented (in python 2.7)?
Example:
>>> a = [1,2,3,4]
>>> a.tolist()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'tolist'

something errors were thrown out when I was testing the scikit-learn with nosetests

I cannot find how to solve the problem like below. The mac is OS 10.10.3 and python is 2.7.6(the original one in mac). All the way to get the scikit-learn is so smooth except testing. I cannot understand the error at all...
failure is listed below:
======================================================================
FAIL: sklearn.feature_extraction.tests.test_image.test_connect_regions
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.6-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Library/Python/2.7/site-packages/sklearn/feature_extraction/tests/test_image.py", line 63, in test_connect_regions
assert_equal(ndimage.label(mask)[1], connected_components(graph)[0])
AssertionError: 777 != 767
======================================================================
FAIL: sklearn.feature_extraction.tests.test_image.test_connect_regions_with_grid
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.6-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Library/Python/2.7/site-packages/sklearn/feature_extraction/tests/test_image.py", line 70, in test_connect_regions_with_grid
assert_equal(ndimage.label(mask)[1], connected_components(graph)[0])
AssertionError: 777 != 767
This is caused by a bug in scipy. Upgrade scipy and it'll go away.

Formatting error reporting

I am logging all errors to a file, since there is no other way to see them properly in my case, especially in prod environment. Like this:
sys.stderr = open('py/log/my_logfile.error.log', 'a')
I am getting something similar to this:
Traceback (most recent call last):
File "my_awesome_file.py", line 50, in <module>
revision = session.Query()
AttributeError: 'Awesome' object has no attribute 'SomeSortOfAttribute'
Traceback (most recent call last):
File "my_awesome_file.py", line 50, in <module>
revision = session.Query()
AttributeError: 'Awesome' object has no attribute 'SomeSortOfAttribute'
It's two errors here (well, same error logged twice). I'd like to have if formatted a bit nicer (i.e. additional newline in between errors), and add a datetime if possible. Can I do it using this method of error logging?
After a little bit of reading Python manuals, it seems the solution is rather easy - instead of directly using file open() as a stream for stderr, I just have to use a custom stream. It's so painfully obvious it puzzles me why I didn't come up with it immediately. Well, it was Friday evening after all.
A very basic version would be:
import time
class LogStream(object):
def write(self, text):
f = open('py/log/my.custom.error.log', 'a')
f.write(time.strftime("%H:%M:%S ") + text + "\r\n")
f.close()
And then
sys.stderr = LogStream()
Result:
12:03:05 Traceback (most recent call last):
12:03:05 File "py/stuff.py", line 38, in <module>
12:03:05
12:03:05 raise Exception("just some test")
12:03:05 Exception
12:03:05 :
12:03:05 just some test
12:03:05
I might want to customize it a bit more but it's good enough already.