-1

My python program crashes when run in windows CMD, but doesn't crash in IDLE. I have sought the possible reason and i found that those quotation marks are the cause of the crash.

Here is my code:

import time
time.sleep(1)
print('“suspects”')
time.sleep(1)
print('done')
input('finish')

What is the reason for that? Those quotation marks are from internet web pages.

update1: - I didn't know kinds of crash, that is why I ask questions. - crash means that when run in windows console, the cmd window is closed entirly unexpectedly.

update 2: this is the output when opening the console then run the script

when run by double clicking the script it is closed unexpectedly. - when opening the console first then run the scrpit (d:\test.py) it gives me : treaceback (most recent call last): file "D:\test.py", line 4, in print('\u201csuspects\u210d') -- file "C:\pythonn34\lib\encodings\cp720.py", line 21, in encode. --- return codecs.charmap_encode(input,self.errors,encoding_table)[0] -- unicodeEncodeError: 'charmap' codec can't encodez character '\u201c' in position 0: character maps to --- sorry I couldn't copy and paste it from the console

salah othman
  • 23
  • 1
  • 7
  • 1
    Define 'crash'. Do you get a `UnicodeEncodeError` exception, or a blue screen of death? Be *specific*. There are plenty of questions here about printing to the Windows console from Python, by the way, please do search for your error and `print` and `python-3.x`. – Martijn Pieters May 22 '16 at 10:53
  • update1: - I didn't know kinds of crash, that is why I ask questions. - crash means that when run in windows console, the cmd window is closed entirly unexpectedly. python windows cmd – salah othman May 22 '16 at 11:01
  • What happens when you open the cmd window *first*, then run `python.exe yourscript.py` (with full paths as needed)? If you double-click a script, the window doesn't stay open. – Martijn Pieters May 22 '16 at 11:03
  • when run by double clicking the script it is closed unexpectedly. - when opening the console first then run the scrpit (d:\test.py) it gives me : treaceback (most recent call last): – salah othman May 22 '16 at 11:15
  • Post that in your question, you can [edit] it. – Martijn Pieters May 22 '16 at 11:16
  • And see [How to keep a Python script output window open?](http://stackoverflow.com/q/1000900) for your specific issue that the window closes immediately. – Martijn Pieters May 22 '16 at 11:16
  • when run by double clicking the script it is closed unexpectedly. - when opening the console first then run the scrpit (d:\test.py) it gives me : treaceback (most recent call last): file "D:\test.py", line 4, in print('\u201csuspects\u210d') -- file "C:\pythonn34\lib\encodings\cp720.py", line 21, in encode. --- return codecs.charmap_encode(input,self.errors,encoding_table)[0] -- unicodeEncodeError: 'charmap' codec can't encodez character '\u201c' in position 0: character maps to --- sorry I couldn't copy and paste it from the console, – salah othman May 22 '16 at 11:22
  • Use the `[-]` menu to start the copying procedure, then select the text and use the same menu again to grab that text. Yes, you have a `UnicodeEncodeError` because your console doesn't know how to print curly quotes. – Martijn Pieters May 22 '16 at 11:24
  • I've duplicated you to the canonical post. – Martijn Pieters May 22 '16 at 11:25
  • ok, i'll check for the answer there – salah othman May 22 '16 at 11:35
  • thank you for the new stuff I've learned from discussion. – salah othman May 22 '16 at 11:39

1 Answers1

0

Python 2.x by default does not support unicode characters. To allow them, paste this at the beginning of your file:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
Dleep
  • 1,045
  • 5
  • 12
  • Emisor, the problem is in windows console. the utf-8 didn't fix it. I think it is from the windows cmd. because in idle the program works fine> and it is python 3.x – salah othman May 22 '16 at 11:02