473,698 Members | 2,635 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 5469
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
2240
by: JustSomeGuy | last post by:
I have a structure typedef struct { string a; string b; } atype; string ABC = ("123"); string DEF = ("456");
4
1250
by: Andrew | last post by:
Is it possible a constructor of a class to use a funtion defined in the same class ????
10
2268
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 instance. I encapulate this in a struct like this:
3
1695
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
4067
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
2950
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 'params object arg' ? 2) I noticed that the console.writeline( string, object, object, object,
3
1723
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
1793
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 new name as an alias for a type, e.g. typedef char byte ; // make byte an alias for char (from C++...
20
4037
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. This one works fine but is recreating the same methods over and over for each variable type. ...
0
8683
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
8610
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
9170
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...
0
7740
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...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
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...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.