473,786 Members | 2,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IDLE and non-ascii encoding workaround?

Hello everyone,

there have already been a couple of threads about IDLE's sometimes
annoying disability to use special characters (in my case I would like
to use for example german umlauts like "ä" etc.).
I have made a workaround that *seems* to work, so I can at least store
files in the editor that use such characters ( on the python shell I
still get:

UnicodeError: ASCII encoding error: ordinal not in range(128)

but that does not matter much to me).
However I don't know very much about encoding issues, so maybe someone
can tell me if there might be problems that I don't see at the moment.
Here's what I did:

I changed one line in the writefile function in IOBinding.py into a
try-except statement. My function now looks like this:

def writefile(self, filename):
self.fixlastlin e()
#chars = str(self.text.g et("1.0", "end-1c"))#origina l line
#workaround to fix the "umlaut" problem:
try:
chars = str(self.text.g et("1.0", "end-1c"))
except:
c = self.text.get(" 1.0", "end-1c")
chars = ''
for i in c:
j = ord(i)
k = chr(j)
chars = chars + k
chars = str(chars)
#end of workaround
try:
f = open(filename, "w")
f.write(chars)
f.close()
## print "saved to", `filename`
return 1
except IOError, msg:
tkMessageBox.sh owerror("I/O Error", str(msg),
master=self.tex t)
return 0

This may take a few seconds if you want to save a large file, but at
least it is better as if it wasn't possible at all.

Any hints on this would be very appreciated.
Thanks in anticipation.

Michael
Jul 18 '05 #1
1 2568
kl*******@web.d e (klappnase) writes:
Any hints on this would be very appreciated.


I recommend to use the IDLE that comes with Python 2.3.

Regards,
Martin
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3421
by: gjohannes | last post by:
Hi. I use Idle 1.1.1 on Python 2.4.1. The "Ctrl-" key bindings for indenting do not work on non-us keyboards where brackets are accessed by the "Alt Gr" key. The Tab key seem to work for indenting a selected textblock on my swedish keyboard, but Shift-tab does not dedent as you would have expected.
19
46685
by: Frank Rizzo | last post by:
I want to log the user out when there has been a period of inactivity in the application. The key here is inactivity of the application, not the system. I know that you can retrieve the inactivity of the system via GetLastInputInfo. That's not what I want - I want inactivity of the application. Thanks.
5
2140
by: Kevin Buchan | last post by:
How can I tell if the system is 'idle', or the screen saver is running, or the machine is locked? I am writing an application that could really benefit from knowing this information. During 'idle' time, I could do some of the slightly heavier processing; during the 'working' time, I would display the non-intrusive notifications that I don't want my customer to miss. I see that I can apparently set the thread priority of my background...
14
2692
by: John Coleman | last post by:
Greetings, I am currently trying to learn Python through the excellent "Learning Python" book. I wrote my first non-trivial program, which began with several comment lines. One of the comment lines began with '#hash'. IDLE doesn't colorize it as a comment line but instead colors the word 'hash' in purple as if it were a key word. Wierd. The behavior seems easy to trigger: Just open up a new window in IDLE and enter these two lines: ...
5
1871
by: sam | last post by:
hi all, i continue to footle around on my spanking new ultra 20 (1.8GHz / Opteron Model 144), gradually trying to get to grips with python and unix both. the slow print time in IDLE had already struck me as rather odd. running programs with heavy print requirements from the terminal was a major discovery though, printing being so fast as to make everything appear at once except in the case of literally thousands of items to be
6
5253
by: John (Z R) L | last post by:
Hi all, I am very new to programming, and I chose to study the Python language before C++. I am currently using the Wikibooks "Non-Programmer's Tutorial for Python", and am up to the section "Who goes there"? http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python/Who_Goes_There%3F But after clicking "run module" for " a = 1
0
2090
by: Michael Boldin via alt email | last post by:
I installed python 2.5 and used the win package for installing MySQLdb. (Iam running Windows XP) Everything works as expected using python directly (Windows command shell) but using IDLE gives the import error below. Same error with PythonWin as my IDE and everything works using python 2.4-- with IDLE and without, mySQLdb is loaded with out error. Below is the IDLEscreen capture Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32...
3
5440
by: Dominique | last post by:
Hello, Sorry bothering you with such a trivial problem. I installed python on a new mac at office. It seems everything is fine: in the console, I access to python. But I just can't start Idle. It seems to open but closes immediately (it appears in the dock and closes immediately). It is also impossible to open any .py file.
1
2715
by: George2 | last post by:
Hello everyone, In your experience, what is system idle process doing? In my experience, this means system is (CPU is waiting for) doing some I/O, 1. like hard page fault; 2. waiting for information from network. Are there any other cases which will cause system idle process happen
0
1043
by: Terry Reedy | last post by:
Murphy.MarkS@epamail.epa.gov wrote: I have both 2.5.2 and 3.0b2 loaded for all users on stock xp with all upgrades. I put /Python25 and /Python30 under Program Files instead of C:. As normal non-admin user, I can edit files in ./misc (added by me) under either, or in ./Lib/site-packages/my_package or, of course, under My Documents. You did not specify the 'problems'. If it is saving (which is required to run a file), then perhaps...
0
9650
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8992
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.