Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79860 > unrolled thread

checking whether a string is text or binary

Started byRick Dooling <rpdooling@gmail.com>
First post2014-10-28 15:21 -0700
Last post2014-10-28 16:03 -0700
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  checking whether a string is text or binary Rick Dooling <rpdooling@gmail.com> - 2014-10-28 15:21 -0700
    Re: checking whether a string is text or binary Dan Stromberg <drsalists@gmail.com> - 2014-10-28 15:30 -0700
      Re: checking whether a string is text or binary richarddooling@gmail.com - 2014-10-28 16:03 -0700

#79860 — checking whether a string is text or binary

FromRick Dooling <rpdooling@gmail.com>
Date2014-10-28 15:21 -0700
Subjectchecking whether a string is text or binary
Message-ID<b03c4e73-daac-4020-97f8-1506a4f3d8fd@googlegroups.com>
I'm an English major who hacks scripts together to do things as needed.

I used this code from the Python Cookbook for years.

https://www.safaribooksonline.com/library/view/python-cookbook-2nd/0596007973/ch01s12.html

Especially when I need to convert old WPD files to markdown, some of which don't even have file extensions, so the code helps determine what kind of file it is I am reading in conversion scripts.

I tried to convert the code using 2to3 and it broke.

The error I get when using Python 3 is on this line:

_null_trans = string.maketrans("", "")

and the error reads

AttributeError: 'module' object has no attribute 'maketrans'

Any help? I barely understand the whole unicode business, but any guidance in updating the code would be much appreciated.

THANKS

Rick

[toc] | [next] | [standalone]


#79861

FromDan Stromberg <drsalists@gmail.com>
Date2014-10-28 15:30 -0700
Message-ID<mailman.15273.1414535418.18130.python-list@python.org>
In reply to#79860
On Tue, Oct 28, 2014 at 3:21 PM, Rick Dooling <rpdooling@gmail.com> wrote:
> I tried to convert the code using 2to3 and it broke.
>
> The error I get when using Python 3 is on this line:
>
> _null_trans = string.maketrans("", "")
>
> and the error reads
>
> AttributeError: 'module' object has no attribute 'maketrans'
>
> Any help? I barely understand the whole unicode business, but any guidance in updating the code would be much appreciated.

Top hit on "python3 maketrans" in Google:

http://stackoverflow.com/questions/3031045/how-come-string-maketrans-does-not-work-in-python-3-1

[toc] | [prev] | [next] | [standalone]


#79862

Fromricharddooling@gmail.com
Date2014-10-28 16:03 -0700
Message-ID<3e6d0ee5-057b-47a7-ad4e-c97b39f10d17@googlegroups.com>
In reply to#79861
On Tuesday, October 28, 2014 5:30:31 PM UTC-5, Dan Stromberg wrote:
> On Tue, Oct 28, 2014 at 3:21 PM, Rick Dooling wrote:
> > I tried to convert the code using 2to3 and it broke.
> >
> > The error I get when using Python 3 is on this line:
> >
> > _null_trans = string.maketrans("", "")
> >
> > and the error reads
> >
> > AttributeError: 'module' object has no attribute 'maketrans'
> >
> > Any help? I barely understand the whole unicode business, but any guidance in updating the code would be much appreciated.
> 
> Top hit on "python3 maketrans" in Google:
> 
> http://stackoverflow.com/questions/3031045/how-come-string-maketrans-does-not-work-in-python-3-1

THANK YOU

I read that twice before without being able to figure what I needed to change, but third time is a charm.

Rick

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web