Error in Tkinter; TclError: missing newline on line...) - python-2.7

I am really working with a bigger program in Tkinter but this code raises the same error:
import Tkinter as tk
root=tk.Tk()
root.title('ROOT')
root.configure(background='blue')
root.option_readfile('tkinter_style_sheet.txt')
Button(root, text='Press Me!' ).grid(row=1, column=1)
mainloop()
The "tkinter_style_sheet.txt" in question, is a .txt file written in Notepad whith text as follows:
*font: Times 8 bold
*Button*font: Times 10 bold
*Button*borderwidth:3
*Button*relief: raised
*Button*width: 3
*Button*height: 1
*Button*pady:3
With the given text file and code, I receive the following output:
Traceback (most recent call last):
File "C:/Python27/problem_with_tkinter.py", line 7, in <module>
root.option_readfile('tkinter_style_sheet.txt')
File "C:\Python27\lib\lib-tk\Tkinter.py", line 658, in option_readfile
self.tk.call('option', 'readfile', fileName, priority)
TclError: missing newline on line 7
I don't understand the error, I tried adding a '\n' character at line 7 but, not surprisingly, it didn't solve the problem. Anyone having an idea what's wrong?

do this on line 7:
*font:Times 8 bold
*Button*font:Times 10 bold
*Button*borderwidth:3
*Button*relief: raised
*Button*width: 3
*Button*height: 1
*Button*pady:3
enter a newline after the end of the last line.

Related

UTF-8 error with the python open() function

I wrote a simple code in python the only opens and read a file
def read_text():
quotes = open("‪C:/Users/Matteo/Desktop/quotes.txt")
contents_of_file = quotes.read()
print(contents_of_file)
quotes.close()
read_text()
When i try to execute it this is what appears
Traceback (most recent call last):
File "C:\Python27\read.py", line 6, in <module>
read_text()
File "C:\Python27\read.py", line 2, in read_text
quotes = open("‪C:/Users/Matteo/Desktop/quotes.txt")
IOError: [Errno 22] invalid mode ('r') or filename: '\xe2\x80\xaaC:/Users /Matteo/Desktop/quotes.txt'
Searching on the internet i understood that the problem is that IDLE recognizes an Unicode character before C, \xe2\x80\xaa, that is a "LEFT-TO-RIGHT EMBEDDING". I have no idea of what is this and how to remove from my code.
Your code contains an invisible character (probably because you copy/pasted the filename from somewhere). Try deleting the "C: part and retyping it.

reindent.py - Does not work from the command line

I have problems with indentation in Python. So I downloaded reindent.py to correct the indentation errors.
I installed reindent.py using the following command-:
pip install reindent
But I running it from the command line shows me the following error-:
Traceback (most recent call last):
File "/usr/local/bin/reindent", line 3, in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/reindent.py", line 92, in main
check(arg)
File "/usr/local/lib/python2.7/dist-packages/reindent.py", line 118, in check
if r.run():
File "/usr/local/lib/python2.7/dist-packages/reindent.py", line 177, in run
tokenize.tokenize(self.getline, self.tokeneater)
File "/usr/lib/python2.7/tokenize.py", line 170, in tokenize
tokenize_loop(readline, tokeneater)
File "/usr/lib/python2.7/tokenize.py", line 176, in tokenize_loop
for token_info in generate_tokens(readline):
File "/usr/lib/python2.7/tokenize.py", line 357, in generate_tokens
("<tokenize>", lnum, pos, line))
File "<tokenize>", line 127
for w in transcript:
^
IndentationError: unindent does not match any outer indentation level
I am running it with the following command-:
reindent -n test1.py
I thought reindent was supposed to correct the errors not show me where they occurred.
reindent.py changes tabs to spaces and can make irregular indentation a uniform 4-spaces. It does not attempt to catch or fix IndentationErrors.
Consider this code which has an IndentationError:
def foo():
print("Let's go")
for i in range(2): <-- IndentationError
print('Peay')
It produces a similar error message to the one you are getting:
% reindent.py script.py
Traceback (most recent call last):
...
File "/usr/lib/python2.7/tokenize.py", line 170, in tokenize
tokenize_loop(readline, tokeneater)
File "/usr/lib/python2.7/tokenize.py", line 176, in tokenize_loop
for token_info in generate_tokens(readline):
File "/usr/lib/python2.7/tokenize.py", line 357, in generate_tokens
("<tokenize>", lnum, pos, line))
File "<tokenize>", line 9
for i in range(2):
^
IndentationError: unindent does not match any outer indentation level
Both
def foo():
print("Let's go")
for i in range(2):
print('Peay')
and
def foo():
print("Let's go")
for i in range(2):
print('Peay')
are valid ways to fix the code. reindent.py (or the tokenize module that it
relies on) does not attempt to guess which one the coder intended. Thus,
IndentationErrors are SyntaxErrors that at least sometimes require human
intervention to fix.

Pyrouge installation test results in "FAILED (errors=10)"

In a previous question I posted in Stackoverflow, I asked about Pyrouge installation. After receiving the answer, I applied it. From the pypi installation steps, I did
pip install pyrouge
Then (here is where I substituted the pypi original step 2,
pyrouge_set_rouge_path.py /absolute/path/to/ROUGE-1.5.5/directory
with the answer I received from stackoverflow):
set pyrouge_set_rouge_path=C:\rouge
Then, I ran the following command to make sure it installed correctly:
python -m pyrouge.test
I was supposed to receive the following output:
Ran 10 tests in 3.753s
OK
But instead got the following output:
Ran 10 tests in 0.034s
FAILED (erros=10)
Above that I received an Error for every test attempt.
Error1: test_config_file (pyrouge.tests.Rouge155_test.PyrougeTest)
Error2: test_convert_summaries (pyrouge.tests.Rouge155_test.PyrougeTest)
Error3: test_evaluation (pyrouge.tests.Rouge155_test.PyrougeTest)
Error4: test_options (pyrouge.tests.Rouge155_test.PyrougeTest)
Error5: test_paths (pyrouge.tests.Rouge155_test.PyrougeTest)
Error6: test_rouge_for_plain_text (pyrouge.tests.Rouge155_test.PyrougeTest)
Error7: test_text_conversion (pyrouge.tests.Rouge155_test.PyrougeTest)
Error8: test_write_config (pyrouge.tests.Rouge155_test.PyrougeTest)
Error9: test_wrong_model_pattern (pyrouge.tests.Rouge155_test.PyrougeTest)
Error10: test_wrong_system_pattern (pyrouge.tests.Rouge155_test.PyrougeTest)
The following are the detailed first and last errors:
First Error:
"""
EEEEEEEEEE
======================================================================
ERROR: test_config_file (pyrouge.tests.Rouge155_test.PyrougeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pyrouge\tests\Rouge155_test.py", line 138,
in test_config_file
rouge = Rouge155()
File "C:\Python27\lib\site-packages\pyrouge\Rouge155.py", line 88, in __init__
self.__set_rouge_dir(rouge_dir)
File "C:\Python27\lib\site-packages\pyrouge\Rouge155.py", line 402, in __set_r
ouge_dir
self._home_dir = self.__get_rouge_home_dir_from_settings()
File "C:\Python27\lib\site-packages\pyrouge\Rouge155.py", line 416, in __get_r
ouge_home_dir_from_settings
with open(self._settings_file) as f:
IOError: [Errno 2] No such file or directory: u'C:\\Users\\IQ\\AppData\\Roaming\
\pyrouge\\settings.ini'
"""
Last Error:
"""
ERROR: test_wrong_system_pattern (pyrouge.tests.Rouge155_test.PyrougeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pyrouge\tests\Rouge155_test.py", line 59,
in test_wrong_system_pattern
rouge = Rouge155()
File "C:\Python27\lib\site-packages\pyrouge\Rouge155.py", line 88, in __init__
self.__set_rouge_dir(rouge_dir)
File "C:\Python27\lib\site-packages\pyrouge\Rouge155.py", line 402, in __set_r
ouge_dir
self._home_dir = self.__get_rouge_home_dir_from_settings()
File "C:\Python27\lib\site-packages\pyrouge\Rouge155.py", line 416, in __get_r
ouge_home_dir_from_settings
with open(self._settings_file) as f:
IOError: [Errno 2] No such file or directory: u'C:\\Users\\IQ\\AppData\\Roaming\
\pyrouge\\settings.ini'
"""
I have opened the directory: C:\Users\IQ\AppData\Roaming\pyrouge\, but it was empty.
I would like to know what it is that is wrong, and how to fix it.
Thank you.
Starting with the answer to your initial question:
"Assuming a working ROUGE-1.5.5. installation" does not correspond to your pyrouge installation. It references to the following. (Maybe you got that right immediately, I did not)
https://github.com/andersjo/pyrouge/tree/master/tools/ROUGE-1.5.5
pyrouge_set_rouge_path is a script, not a variable you have to set.
The script is located at Python_PATH\Scripts.
Hence try something like:
python Python_PATH\Scripts\pyrouge_set_rouge_path C:\rouge
Alternatively you can create a file settings.ini at the corresponding location with this content:
[pyrouge settings]
home_dir = C:\rouge
Where C:\rouge should be the location of the file ROUGE-1.5.5.pl
You should first install ROUGE-1.5.5 by following this tutorial. Only the two commands to install and no configuration is needed. Keep in mind to generate the wordnet bd file. by running
./WordNet-2.0-Exceptions/buildExeptionDB.pl ./WordNet-2.0-Exceptions ./smart_common_words.txt ./WordNet-2.0.exc.db
Under the data directory.
Then install the pyrouge from source. Remember to comment out the print lines which will trigger errors.
Then all will just goes fine.

encoding errors when replacing unwanted characters in utf-8 encoded file

Code can be downloaded here:
https://github.com/kelrien/pyretrieval/
whenever I execute my example.py, the following error pops up:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "example.py", line 21, in <module>
docs.append(proc.process(line.decode("utf-8")))
File "pyretrieval\processor.py", line 61, in process
tokens = self.tokenize(string)
File "pyretrieval\processor.py", line 47, in tokenize
temp = temp.replace(char, self.replace_characters[char])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 0: ordinal not in range(128)
As you can see - the error happens when trying to replace german umlauts I specified. If I don't use the replace_characters dict and just ignore those umlauts, I'm not getting the error.
I already tried a lot of stuff:
Using the codecs module
Using encode("utf-8") and decode("utf-8") at different
I found a solution. I had to encode the characters I wanted to replace in unicode too(in processor.py).
I already pushed the necessary changes to github. https://github.com/kelrien/pyretrieval

Sublime text 2 build tools - nothing happens

I've tried to use sublime text 2 to write lua\corona program, but I've faced with a problem.
When i add a build tool with such a text:
{
"cmd": ["C:/Program Files/Corona Labs/Corona SDK/Corona Simulator.exe", "main.lua"]
}
After F7 or ctrl+b or build button in menu - only blank small window shows and "Building" text appears on bottom of the window - nothing else happen (even when I try to check other available build tools).
I even try to put other commands in "cmd" - this blank field on the bottom of sublime still blank and this simulator doesn't appear (if I write in command line "C:/Program Files/Corona Labs/Corona SDK/Corona Simulator.exe" simulator starts).
UPDATE
I've opened console and there is some log:
Running C:/Program Files/Corona Labs/Corona SDK/Corona Simulator.exe main.lua
Traceback (most recent call last):
File ".\sublime_plugin.py", line 337, in run_
File ".\exec.py", line 154, in run
File ".\exec.py", line 45, in __init__
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 7: ordinal not in range(128)
Try this : http://www.sublimetext.com/forum/viewtopic.php?f=3&t=8512
In Packages/Default/exec.py at line 45
Replace :
proc_env[k] = os.path.expandvars(v).encode(sys.getfilesystemencoding())
With :
os.path.expandvars(v.decode(sys.getfilesystemencoding())).encode(sys.getfilesystemencoding())