Kevin
Kevin

Reputation: 41

IDLE (Python 2.7.5) no longer opens .py files

Since updating from Ubuntu 13.04 to 13.10, IDLE 2.7.5 hangs whenever I try to open a .py file. A blank editor window opens with "idle" as the title of the window. This editor can be used to create new files, but it never displays the content of the file I tried to open and won't close by any means I've tried. I also have IDLE (with 3.3.2) on my system, and it is still working fine. Something went wrong during my first attempt to update from Ubuntu 13.04 to 13.10, so I thought that might have been part of the problem, but a fresh OS install didn't fix the problem.

Upvotes: 1

Views: 1627

Answers (2)

Sojurn
Sojurn

Reputation: 485

Reposting my comment to Thaago since the formatting got messed up in the reply. He's the one who really solved this issue and for context for what I'm talking about, read his comment first.

With Python 2.7.5+ this is no longer the issue. It looks like they took your solution but applied it a bit hastily. So that the variable passed is str, and

str = str.split("\n", 2)[:2]

is proper but the next line, is still

for line in lst:

rather than

for line in str:

That's where I got the error and changing lst to str in the next line fixed the issue. That seems super sloppy to me and I hope they fix this.

How to find the source of new errors for yourself

Incidentally, the way to really see where the problem is to start 'idle' this way: Open a terminal type idle and press enter Use idle normally and do whatever you did that reproduced the issue. In my case it was simply to click on 'File' -> 'Recent files' and open my last file.

When it screws up, the error will be in the terminal you used to open idle.

Upvotes: 1

Thaago
Thaago

Reputation: 104

One of the idlelib files has an error in it. This file must either be new or unused in previous versions, because its just a naming problem.

Go to: /usr/lib/python2.7/idlelib/IOBinding.py

If this is not a valid path, run idle from the command line, try to load a file, and look at the stack trace to see where the final error is.

Go to line 122 and change lines 122-128 to the following:

def coding_spec(lst):
    """Return the encoding declaration according to PEP 263.

    Raise LookupError if the encoding is declared but unknown.
    """
    # Only consider the first two lines
    lst = lst.split("\n", 2)[:2]

(Comments aren't needed, but preserve what comments there were). You'll notice that all you are doing is changing the variable name 'str' (which is reserved and shouldn't be used anyways) to 'lst'.

Upvotes: 3

Related Questions