Python Forum
Write text expander in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write text expander in Python
#4
str.translate is for replacing character for character, string or None. So 'δ' -> 'delta_low' is possible, but 'delta_low' -> 'δ' is not.

>>> mapping = str.maketrans({"δ": 'delta_low'})                                                                                            
>>> 'Some measurement with δ did get get wrong'.translate(mapping)                                                                         
'Some measurement with delta_low did get get wrong'
>>> mapping = str.maketrans({'delta_low': "δ"})                                                                                            
/../
ValueError: string keys in translate table must be of length 1
.maketrans documentation:

Quote:Character keys will be then converted to ordinals.
If there are two arguments, they must be strings of equal length, and
in the resulting dictionary, each character in x will be mapped to the
character at the same position in y.

.translate documentation:

Quote:Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Write text expander in Python - by constantin01 - Jan-15-2020, 03:46 PM
RE: Write text expander in Python - by Gribouillis - Jan-15-2020, 06:17 PM
RE: Write text expander in Python - by snippsat - Jan-15-2020, 07:27 PM
RE: Write text expander in Python - by perfringo - Jan-16-2020, 07:44 AM
RE: Write text expander in Python - by constantin01 - Jan-16-2020, 08:18 AM
RE: Write text expander in Python - by buran - Jan-16-2020, 08:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Read text file, modify it then write back Pavel_47 5 1,696 Feb-18-2023, 02:49 PM
Last Post: deanhystad
  How to write in text file - indented block Joni_Engr 4 6,542 Jul-18-2022, 09:09 AM
Last Post: Hathemand
  CSV to Text File and write a line in newline atomxkai 4 2,763 Feb-15-2022, 08:06 PM
Last Post: atomxkai
  Is there a way to move text created by turtle.write()? derekered 7 6,126 Dec-16-2020, 09:44 AM
Last Post: itexamples
  List Won't Write in Text File IILawrenceII 4 2,197 Jul-17-2020, 11:16 PM
Last Post: j.crater
  read text file and write into html with correct link jacklee26 4 2,964 Aug-02-2019, 05:48 AM
Last Post: jacklee26
  write image into string format into text file venkat18 2 4,455 Jun-01-2019, 06:46 AM
Last Post: venkat18
  write each line of a text file into separate text files and save with different names Shameendra 3 2,824 Feb-20-2019, 09:07 AM
Last Post: buran
  How to display what I write on sublime text editor on the CMD el_bueno 5 3,298 Feb-04-2019, 02:00 PM
Last Post: buran
  How to write a code to open and read text file by clicking on the "text file" kavindu 4 4,190 Jul-06-2018, 06:55 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020