Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Never trust an operating system.


devel / comp.lang.python / Re: How to replace characters in a string?

SubjectAuthor
o Re: How to replace characters in a string?Chris Angelico

1
Re: How to replace characters in a string?

<mailman.571.1654676099.20749.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18516&group=comp.lang.python#18516

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: How to replace characters in a string?
Date: Wed, 8 Jun 2022 18:14:46 +1000
Lines: 20
Message-ID: <mailman.571.1654676099.20749.python-list@python.org>
References: <B1F63761-AA3A-4B9D-B135-ED80C56E015A@looktowindward.com>
<CAPTjJmqynw1UqQk2wXMOhdRocyRursBhUnAouZLc0hMVDNGA+w@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de L7mAm/eePpEveskDwt5gNQcluFsbduYgU9q+6KgxFzPg==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=KA139rwY;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.008
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '2022': 0.05; 'string':
0.07; 'string,': 0.09; 'chrisa': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'step,': 0.16; 'stick': 0.16;
'subject:characters': 0.16; 'subject:string': 0.16; 'wrote:':
0.16; 'python': 0.16; 'probably': 0.17; 'to:addr:python-list':
0.20; 'returns': 0.22; 'version': 0.23; 'subject:How': 0.23;
'actual': 0.25; 'tried': 0.26; 'jun': 0.26; '>>>': 0.28; 'it,':
0.29; 'seem': 0.31; "doesn't": 0.32; 'message-id:@mail.gmail.com':
0.32; 'but': 0.32; 'same': 0.34; 'printing': 0.34; 'header:In-
Reply-To:1': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'change': 0.36; "it's": 0.37;
'received:209.85': 0.37; 'received:209': 0.39; 'wed,': 0.39;
'true': 0.63; 'spam': 0.65; 'back': 0.67; '(you': 0.76; 'strings':
0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:content-transfer-encoding;
bh=7dDfX93A11HgsNVYDBQ3Q5iKzQujmnm0pqZpHsv96ao=;
b=KA139rwYIXgCvZOqTBRBBb9p+HFeAoo7sf5r8ftz2TTspKDXOS5PrZrYN1GbQouxY+
58/+/x1jCtKGhcibpPe2RGxPyVHzHrB6R8dEeTVAU4WEIfKqqvRUIvisIYUGmb+8qcac
MAu1jZ0gtvzU0two0hdMntudTkSaRHkLijo/X2JRPZFLRlJ7SFU1ojVkZZ3wH/HSxFQ1
AvPu7cxb91zBGLYUQtkRvgooxXoCIq52dzPSF1MdGnxo2V0TWjtX5J/yg+7LIvhfHYKs
K1aTYDfZ1xcliKZSsKIh4VLlfDUgqUpo+Vr4Mbtyk713ZHpCWFNsbFTXwoiGT5fH6uL/
Ih6A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:content-transfer-encoding;
bh=7dDfX93A11HgsNVYDBQ3Q5iKzQujmnm0pqZpHsv96ao=;
b=BJsxvLfQCP9quyikslepSqoMbr71Gr6Q5Dm8892D+N5MI3RjbJRGiWJlSbBcdvISpc
7bAXdSErPFVny2Y6ukBxjBCBtomq1ppQBCcyohP8m8jDPnb6g5h82qtLLxE/DJHND5ug
hVCM32xWX/8VRZjXkyOOJtHpmrhEPf5bWbOiLzuR870B9vstTahObieOkMQu7sxnH68x
Fa2itPbaErIdBMSfm0dbjgqDHXAt01VCUXdhx1HPaQVP0jsEvXHAq33LQ40G2qOWrwQi
dem1Oi6nwKGjsweJwL+3OD8lP8JlBP8aZnLyQAV1gIx9/uFE1S0iMh7CJgY01ZZvs6+5
5HqA==
X-Gm-Message-State: AOAM531IPez+zy40pu/887AHo8d883jimPa8cN44nqjVW+4vtjg+IZI2
b5MLy9j2xPQPww8ezQ5knNZpFronDhj+O3phWpUwQKlAXjY=
X-Google-Smtp-Source: ABdhPJwFtRElcP2KO4WUWVV72blHT8rFWAZA4oO70QJhWzrF0l/ShFVSupWTKKw7BlIgwhY5g8zIlTQd/OPcUiN3EhU=
X-Received: by 2002:a05:600c:3d8d:b0:39c:5232:107a with SMTP id
bi13-20020a05600c3d8d00b0039c5232107amr14019276wmb.191.1654676097252; Wed, 08
Jun 2022 01:14:57 -0700 (PDT)
In-Reply-To: <B1F63761-AA3A-4B9D-B135-ED80C56E015A@looktowindward.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmqynw1UqQk2wXMOhdRocyRursBhUnAouZLc0hMVDNGA+w@mail.gmail.com>
X-Mailman-Original-References: <B1F63761-AA3A-4B9D-B135-ED80C56E015A@looktowindward.com>
 by: Chris Angelico - Wed, 8 Jun 2022 08:14 UTC

On Wed, 8 Jun 2022 at 18:12, Dave <dave@looktowindward.com> wrote:

> I tried the but it doesn’t seem to work?
> myCompareFile1 = ascii(myTitleName)
> myCompareFile1.replace("\u2019", "'")

Strings in Python are immutable. When you call ascii(), you get back a
new string, but it's one that has actual backslashes and such in it.
(You probably don't need this step, other than for debugging; check
the string by printing out the ASCII version of it, but stick to the
original for actual processing.) The same is true of the replace()
method; it doesn't change the string, it returns a new string.

>>> word = "spam"
>>> print(word.replace("sp", "h"))
ham
>>> print(word)
spam

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor