Syntax error

Peter Otten __peter__ at web.de
Sat Jan 10 17:02:11 EST 2015


Abdul Abdul wrote:

> Hello,
> 
> I have the following program that employs the dcm2jpg.exe software:
> 
> import os
> os.system(“dcm2jpg.exe IM-0004-0004.dcm”)
> exit
> 
> When I tried to run it, I got the following error:
> 
> SyntaxError: Non-ASCII character '\xe2' in file dicomjpg.py on line 2, but
> no en
> coding declared; see http://python.org/dev/peps/pep-0263/ for details
> 
> Why is that? 

As the error message says, you are using non-ascii characters (the “ and ”) 
in your code.

> How can this error be solved?

But even if you were to read the linked document and would add the line

# -*- coding: utf-8 -*

at the beginning of your script you would run into the next SyntaxError.

You are trying to quote a string literal with

“...”

but Python only understands

"..."

or 

'...'

Change the os.system() call to

os.system("dcm2jpg.exe IM-0004-0004.dcm")

and your script should work.

An unrelated issue:

> exit

to call a function the () is required -- to end the script at an arbitrary 
point use

exit()

However, as execution also ends automatically when the last line of the 
script is reached it is better to remove the

> exit

line completely.




More information about the Python-list mailing list