954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Python Code Working in Eclipse But Not in Command Prompt

Hi Guys,

I was hoping someone can help me with this. I have a python program that reads and writes files in utf-8(unicode). When I run it in Eclipse, the output is perfectly fine. When I try making an exe file of my program it is not working. I also tried double clicking the python program to run it in windows dos but the same problem occurred. I tried running it in pythonWin still the same problem. Now I have a problem debugging my program since it is working perfectly fine in Eclipse. Is it a problem about encoding? I placed this:

#!/usr/bin/env python
# -*- coding: utf-8 -*-


but it doesn't seem to work. hope someone can help me with this. I am reading and writing files in xml with utf-8/unicode characters

gishi
Newbie Poster
14 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

And what code page have you set up for the windows dos? I found CHCP 1252 works best for me, before I thought I had to live with code page 850 or 437, but fortunately it is not true.

I have not tried how well the code page chcp 65001 (UTF-8) works yet though.

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

Hi! How do you set the codepage for dos? If i do this will my program run when I make an exe file and use it using other's pc? My program is to read and write in xml. I need to look for characters that is not converted to their xml/html entities. It's now difficult to debug my program since it is doing fine in eclipse but not in dos or in exe. Do I need to write something at the top of my program to make windows read it that it has such encoding?

And what code page have you set up for the windows dos? I found CHCP 1252 works best for me, before I thought I had to live with code page 850 or 437, but fortunately it is not true.

I have not tried how well the code page chcp 65001 (UTF-8) works yet though.

gishi
Newbie Poster
14 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

Eclipse has the fonts installed to print the encoding. The command line obviously does not. You can try to change the default font but that is dependent on which distro you are using as well as which terminal program (xterm is -fa font-name).

woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
 

I think encoding of your program to match what CHCP says in command line is enough. Code page 1252 makes scandinavian letter work from command line arguments and show correct in file name for DIR command. However, if I use GNU ls command in windows, those letters are missing. I hope that setting the code page in AUTOEXEC.BAT is enough, but I am not sure. I have only set it by hand and prove now to put there to see if the code page becomes default. If not, must see some windows settings and environment variables.

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: