473,884 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

replacement for string.printabl e

>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.printabl e 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 2529
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.

<quoteBeginni ng 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...@ox tedonline.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.printabl e 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.printabl e meant "prints something that is not whitespace."
Well, I'm glad I checked - string.printabl e 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 setMadeFromStri ng:".

-- 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.

<quoteBeginni ng 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.Templat e` 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
1848
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 without going to special characters (like ß or ¿) I couldnt see anything that was explaining this stuff on the python.org site. I think what I want is soemthing like string.printable - string.whitespace but that doesn't seem to work like...
3
2496
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
5482
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 characters: CheckPrintable(self,message): printablemessage = ""
3
9755
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) method/function, I need the second argument 'replacement' to be another regular expression ( not a string) . So when I find a 'certain kind of string' in
6
1868
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 = translate(allchars, allchars, printable) input_string = translate(input_string, allchars, delchars) Which is OK. But it seems like there should be more straightforward way that I just haven't figured out. Is there?
2
3599
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 that is displayed in a text box. Once displayed, the text will be copied, transmitted and then pasted (all manually by humans) into a second utility where the string must then be reverse-engineered into the *original* byte array. The byte array will...
8
5759
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 Hex digits like "0a" ,"00" , "0b" whose ascii value is New line , NULL , Tab respectively brings the rest of the string to new line or put a tab in between .
4
1358
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 the StreamReader and StreamWriter approach and the String.Replace method. It works well, except that not all the file contents gets preserved. Three bytes at the start of the file are omitted. These occur just before the CRLF characters. Can I read...
5
2495
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 not printable when viewed in Notepad. I usually catch by looking at the text in my App. Usually the problem is an extra long hyphen --
0
9799
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
11170
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...
1
10869
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10426
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9591
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
5808
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
6009
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4231
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3243
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.