472,146 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

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 2440
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by google account | last post: by
3 posts views Thread by Pascal | last post: by
2 posts views Thread by Daniel Alexandre | last post: by
8 posts views Thread by abhi147 | last post: by
4 posts views Thread by LouArnold | last post: by
5 posts views Thread by =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

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.