By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,286 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,286 IT Pros & Developers. It's quick & easy.

replacement for string.printable

P: n/a
>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
Share this Question
Share on Google+
4 Replies

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.