-1

IDLE keeps closing whenever I try to run some code.I've uninstalled IDLE and installed it again twice now. I've also tested other python files to be sure it isn't a problem in my code.

I opened Python command line, wrote from idlelib import idle, opened a Python file and tried running it and got this:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python34\lib\tkinter\__init__.py", line 1487, in __call__
    return self.func(*args)
  File "C:\Python34\lib\idlelib\MultiCall.py", line 179, in handler
    r = l[i](event)
  File "C:\Python34\lib\idlelib\ScriptBinding.py", line 127, in run_module_event

    return self._run_module_event(event)
  File "C:\Python34\lib\idlelib\ScriptBinding.py", line 141, in _run_module_event

    code = self.checksyntax(filename)
  File "C:\Python34\lib\idlelib\ScriptBinding.py", line 102, in checksyntax
    return compile(source, filename, "exec")
TypeError: source code string cannot contain null bytes

I am not using Tkinter, I am using Pygame at the moment. I also know that IDLE is written in Tkinter. I am running Python 3.4 Does anyone know what this means? Or even better, how to get IDLE working again?

UPDATE: IT ONLY CRASHES WITH PYGAME PROGRAMS

Rex Nihilo
  • 604
  • 2
  • 7
  • 16
Astro Nato
  • 99
  • 2
  • How are you opening the Python file and running it? – martineau Jun 07 '14 at 17:08
  • I go to file, open. Select my python file and then press F5. Also, I checked a file not using Pygame and it worked fine, so that may be it. – Astro Nato Jun 07 '14 at 20:46
  • Try running IDLE the normal way, which is by selecting it through the Start Menu | Python 3.4 | IDLE (Python GUI). – martineau Jun 08 '14 at 01:51
  • The error message means what it says: the file you are running has a null (0) byte or code, and that is not allowed. The messages comes from the builtin compile function, not IDLE. You should see the same message if you try to run the file from a console with 'python -m path/to/myfile.py'. What is you OS? If on Windows, you can right click the file in Explorer and select 'run'. – Terry Jan Reedy Jun 06 '16 at 03:23
  • By 'Pygame program', I presume you mean one that you write that has 'import pygame'. Since compile does not execute anything, I do not see why that import should make a difference. Do you have a template for pygame programs that might have the null code? – Terry Jan Reedy Jun 06 '16 at 03:26

1 Answers1

0

To test a file for null bytes/codes, try the following:

with open('myfile.py') as f:
    for i, line in enumerate(f, 1):  # lines begin with 1
       for j, char in enumerate(line):
           if not char:
               print('Line %s: col %s' % (i,j))
Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52