473,513 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

replacement for string.printable

>From what I have read the string module is obsolete and should not be
used but I am working on a project that parses printable files created
in a DOS program and creates a web page for each file. I am using the
string.printable constant to determine which characters should be kept;
the files contain many print control codes. There seems to be nothing
like this in the string methods. isalnum() seems the nearest but gives
false for '+' '!' etc.

I realise I could define a global string to cover this but wondered if
there was another, better, way

Regards, John
--
War is God's way of teaching Americans geography
Ambrose Bierce (1842 - 1914)
Aug 15 '07 #1
4 2504
On Wed, 15 Aug 2007 19:56:01 +0100, John K Masters wrote:
From what I have read the string module is obsolete and […]
The `string` module isn't obsolete. It even contains a more or less
recent new addition: `Template`. Only the functions that are also
available as methods on `str` are deprecated.

Ciao,
Marc 'BlackJack' Rintsch
Aug 15 '07 #2
On 19:03 Wed 15 Aug , Marc 'BlackJack' Rintsch wrote:
On Wed, 15 Aug 2007 19:56:01 +0100, John K Masters wrote:
From what I have read the string module is obsolete and [???]

The `string` module isn't obsolete. It even contains a more or less
recent new addition: `Template`. Only the functions that are also
available as methods on `str` are deprecated.

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
help('string')

DESCRIPTION
Warning: most of the code you see here isn't normally used nowadays.
Beginning with Python 1.6, many of these functions are
implemented as methods on the standard string object. They used to be
implemented by a built-in module called strop, but strop is now
obsolete itself.

<quoteBeginning with Python 1.6 </quote>

We are now way past 1.6. Are you sure the string module is still being
added to?

Regards, John
--
War is God's way of teaching Americans geography
Ambrose Bierce (1842 - 1914)
Aug 15 '07 #3
On Aug 15, 1:56 pm, John K Masters <johnmast...@oxtedonline.net>
wrote:
From what I have read the string module is obsolete and should not be

used but I am working on a project that parses printable files created
in a DOS program and creates a web page for each file. I am using the
string.printable constant to determine which characters should be kept;
the files contain many print control codes. There seems to be nothing
like this in the string methods. isalnum() seems the nearest but gives
false for '+' '!' etc.

I realise I could define a global string to cover this but wondered if
there was another, better, way

Regards, John
--
War is God's way of teaching Americans geography
Ambrose Bierce (1842 - 1914)
Well, I was all set with a cocky answer to the effect of "here's half
a dozen different ways to test to see if the ordinal of a character is
between 33 and 127 inclusive," assuming that the "printable" in
string.printable meant "prints something that is not whitespace."
Well, I'm glad I checked - string.printable includes a number of
whitespace characters, including those with ASCII codes 32 (space), 9
(tab), 10 (linefeed), 13 (CR), 11 (FF), and 12 (VT). So you could
hard code such a string (you are working with a legacy DOS app after
all), or maybe better, make it a set of chars, since it seems that you
are doing massive numbers of membership tests using "if c in string:"
- create the set once, and then use "if c in setMadeFromString:".

-- Paul


Aug 16 '07 #4
On Wed, 15 Aug 2007 23:15:12 +0100, John K Masters wrote:
help('string')

DESCRIPTION
Warning: most of the code you see here isn't normally used nowadays.
Beginning with Python 1.6, many of these functions are
implemented as methods on the standard string object. They used to be
implemented by a built-in module called strop, but strop is now
obsolete itself.

<quoteBeginning with Python 1.6 </quote>

We are now way past 1.6. Are you sure the string module is still being
added to?
The `string.Template` class was added in PythonÂ*2.4:

http://docs.python.org/lib/node40.html

Ciao,
Marc 'BlackJack' Rintsch
Aug 16 '07 #5

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

Similar topics

1
1834
by: google account | last post by:
I know that string.letters and string.digits are all the letters and numbers, is there a string.???? that is a subset of all the ascii characters that are available on a US English Keyboard...
3
2484
by: Pascal | last post by:
Hello, What's the best way to delete or replace no-printable characters in a string. i.e.: "\x08toto\x00titi" -> "tototiti" or " toto titi"
2
5444
by: Daniel Alexandre | last post by:
-----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...
3
9721
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject)...
6
1854
by: Steve Bergman | last post by:
When sanitizing data coming in from HTML forms, I'm doing this (lifted from the Python Cookbook): from string import maketrans, translate, printable allchars = maketrans('','') delchars =...
2
3564
by: Bryan | last post by:
Apologies if this is a noob question, but I've been struggling with this for quite a while... I'm trying to convert a byte array (encrypted authorization code) into a *screen-printable* string...
8
5710
by: abhi147 | last post by:
Hi all , I need to convert a 32 bit string containing hex digits like "76d408cedd600bb578bc0256a751cea2" into it's corresponding 16bit ascii value like "vÎÝ` µx¼V§Q΢" . Now the presence of...
4
1340
by: LouArnold | last post by:
I have a need to replace text in a file with new text. The files may or may not be text files in the sense that there may not be "lines" and they may not contain printable characters. I tried...
5
2477
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have a project to take a MS Word doc and reformat the text into text files that are built into my App. The only issue I have is some time there are some characters in MS Word that are...
0
7160
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...
1
7099
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...
0
7525
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...
0
5685
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,...
0
4746
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...
0
3233
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...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
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 ...
0
456
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...

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.