473,569 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about string.printabl e and non-printable characters

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi there,

I'm using the following method in my program to check whether a message
received is printable or not and to strip the non-printable characters:

CheckPrintable( self,message):
printablemessag e = ""
for char in message:
if char in string.printabl e: printablemessag e = printablemessag e +
char
return printablemessag e

The method is working fine, except in one detail, it's also stripping
the accented letters which I didn't want to happen. Is there a
string.printabl e declaration which contains accented letters? Thanks in
advance. If you can, please reply to my email.
- --
Best Regards,
Daniel Alexandre ( df****@student. dei.uc.pt )
PGP Public Key: http://student.dei.uc.pt/~dfcruz/pubring.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCNv94L3+ DjgQV3LgRAk0yAK DN5lzrXqsVY5zgv ZD2X3oGtWS5IwCc CtsA
qv5d+KGP3n9Gbx0 iUm46f/k=
=sw9h
-----END PGP SIGNATURE-----

Jul 18 '05 #1
2 5450
Daniel Alexandre wrote:
CheckPrintable( self,message):
printablemessag e = ""
for char in message:
if char in string.printabl e: printablemessag e = printablemessag e
+ char
return printablemessag e


That would probably be best written (using Python 2.4) as:

def check_printable (self, message, printable=strin g.printable):
return "".join(cha r for char in message if char in printable)

It would be much more efficient for one thing. And you can change printable to
be whatever you want. Unfortunately, no one knows what letters you want to
define as printable other than you, or what is printable on your codeset.
string.printabl e is a least-common denominator ASCII set. You can certainly
make it string.printabl e + "aeioun" (replacing the ASCII letters with their
accented versions in your codeset of course).

Of course I might be proven totally wrong when the i18n heavies weigh in ;)
--
Michael Hoffman
Jul 18 '05 #2
Michael Hoffman schrieb:
string.printabl e is a least-common denominator ASCII set. You can certainly
make it string.printabl e + "aeioun" (replacing the ASCII letters with their
accented versions in your codeset of course).

There is something I don't understand about string.printabl e: on the one
hand the library reference says "This is a combination of digits,
letters, punctuation, and whitespace." The value of string.letters is
locale-dependent, so string.printabl e should change as well after
calling locale.setlocal e(). But it doesn't.

But you could always call locale.setlocal e() and afterwards combine your
"printable" string yourself.

--
Dr. Sibylle Koczian
Universitaetsbi bliothek, Abt. Naturwiss.
D-86135 Augsburg

Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : Si************* @Bibliothek.Uni-Augsburg.DE
Jul 18 '05 #3

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

Similar topics

11
2228
by: JustSomeGuy | last post by:
I have a structure typedef struct { string a; string b; } atype; string ABC = ("123"); string DEF = ("456");
4
1246
by: Andrew | last post by:
Is it possible a constructor of a class to use a funtion defined in the same class ????
10
2253
by: Christof Krueger | last post by:
Hello, I'm quite new to C++ and have some base C knowledge. So I know how to solve a given problem, by I sometimes tend to fall back to C. That is what I want to avoid in my current project. Therefore I have the following question: I maintain a list of objects that are created. There is some information that is logically related to each...
3
1688
by: lestrov1 | last post by:
Hello all!! How I can return data from a hash: #include <stdlib.h> #include <stdio.h> #include <string.h> #include <search.h> void exists(char *k){
53
4030
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
2
2940
by: djc | last post by:
out of all the overloads that pop up via intellisense for console.writeline() the following one confuses me: Console.WriteLine (string format, params object arg) 1) whats the deal with 'params' there? I am used to this pattern: type var, type var, type var etc... like: string str, int i, double x. This console.writeline overload says...
3
1717
by: Brian | last post by:
A quick question here - What can be achieved in IL which is not possible in C# ? o Creation of an ArrayList o Creation of a Dictionary o Creation of a two dimensional array o Creation of a non-zero based array Please let me know what is the right answer. Many thanks.
3
1782
by: xllx.relient.xllx | last post by:
I have a question about an example presented in the book "INFORMIT C++ Reference Guide" by Danny Kalev: <code> string getmagicword() ( return string("Supercalifragilisticexpialidocious"); );
5
509
by: John | last post by:
I thought I had a fairly good understanding of typedefs until I came across the following passage from C++ Primer, fourth edition by Stanley B. Lippman: "The mistake is in thinking of a typedef as a textual expansion" (page 129). All of my other C++ books and every mention of typedefs that I've seen on the Internet simply call typedefs a...
20
4016
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This tells me if a variable has changed, give me the original and current value, and whether the current value and original value is/was null or not. ...
0
7701
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...
0
7924
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. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
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...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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...
0
3653
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...
1
2115
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
1
1223
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.