Python Forum
Text conversion to lowercase is not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Text conversion to lowercase is not working
#1
I am trying to change text which contain these capitalized words surrounded by space. But this Autokey script is not working. Can someone point out what I am doing wrong?
text_.replace(" A "," a ")
time.sleep(0.1)
text_.replace(" An "," an ")
time.sleep(0.1)
text_.replace(" And "," and ")
time.sleep(0.1)
text_.replace(" As "," as ")
time.sleep(0.1)
text_.replace(" At "," at ")
time.sleep(0.1)
text_.replace(" De "," de ")
time.sleep(0.1)
text_.replace(" Du "," du ")
time.sleep(0.1)
text_.replace(" For "," for ")
time.sleep(0.1)
text_.replace(" In "," in ")
time.sleep(0.1)
text_.replace(" Is "," is ")
time.sleep(0.1)
text_.replace(" It "," it ")
time.sleep(0.1)
text_.replace(" Not "," not ")
time.sleep(0.1)
text_.replace(" Of "," of ")
time.sleep(0.1)
text_.replace(" On "," on ")
time.sleep(0.1)
text_.replace(" The ", " the ")
time.sleep(0.1)
text_.replace(" To "," to ")
time.sleep(0.1)
Yoriz write Jan-13-2024, 11:19 AM:
Please post all code, output and errors (in its entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Linux Mint Cinnamon 21.3 - Python 3.10.12 - Autokey-gtk 0.96.0 as of 2024-01-13.
Reply
#2
The string method replace returns a copy of the string with all occurrences of substring old replaced by new.
old_text = " A B C D "
new_text = old_text.replace(" A ", " a ")
print(old_text)
print(new_text)
Output:
A B C D a B C D
Reply
#3
The str object has many useful string-methods: https://docs.python.org/3/library/stdtyp...ng-methods
One of them is title and capitalize.

text = "We always eat dinner together."
print(text.title())
Output:
We Always Eat Dinner Together.
With capitalize:
Output:
We always eat dinner together.
tester_V likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
Much thanks for your replies. It was my lack Python of coding practice that was the error. I corrected the Autokey script pasted below and is working fine.

I must apply Title Case to the text to be displayed as Small Caps in Wikisource/wikipedia, but the connecting words must be reverted to lowercase.

# [ alt + s ] title and small case selected text
# 240115_2129 - *alt-s-title-with-small-caps.py - /home/ineuw/.config/autokey/data/english - Geany

# clear clipboard
clipboard.fill_clipboard('')
time.sleep(0.05)

# small caps wiki template set
open_ = '{{sc|'
close_ = '}}'
copy_ = '<ctrl>+<insert>'
paste_ = '<shift>+<insert>'
time.sleep(0.05)

try:
	keyboard.send_keys(copy_)
	time.sleep(0.05)

	text_ = clipboard.get_clipboard()

except:
	time.sleep(0.05)

else:
	text_ = text_.title()
	time.sleep(0.05)

	text_=text_=text_.replace(" A "," a ")
	time.sleep(0.05)
	text_=text_.replace(" An "," an ")
	time.sleep(0.05)
	text_=text_.replace(" And "," and ")
	time.sleep(0.05)
	text_=text_.replace(" As "," as ")
	time.sleep(0.05)
	text_=text_.replace(" At "," at ")
	time.sleep(0.05)
	text_=text_.replace(" De "," de ")
	time.sleep(0.05)
	text_=text_.replace(" Du "," du ")
	time.sleep(0.05)
	text_=text_.replace(" For "," for ")
	time.sleep(0.05)
	text_=text_.replace(" In "," in ")
	time.sleep(0.05)
	text_=text_.replace(" Is "," is ")
	time.sleep(0.05)
	text_=text_.replace(" It "," it ")
	time.sleep(0.05)
	text_=text_.replace(" Not "," not ")
	time.sleep(0.05)
	text_=text_.replace(" Of "," of ")
	time.sleep(0.05)
	text_=text_.replace(" On "," on ")
	time.sleep(0.05)
	text_=text_.replace(" The ", " the ")
	time.sleep(0.05)
	text_=text_.replace(" To "," to ")
	time.sleep(0.05)

	combined_ = open_ + text_ + close_
	time.sleep(0.8)

clipboard.fill_clipboard(combined_)
time.sleep(0.05)

keyboard.send_keys(paste_)
Linux Mint Cinnamon 21.3 - Python 3.10.12 - Autokey-gtk 0.96.0 as of 2024-01-13.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Decryption not working if key has same symbol like text Paragoon2 0 320 Nov-11-2023, 09:32 PM
Last Post: Paragoon2
  while loop not working-I am using sublime text editor mma_python 4 1,149 Feb-05-2023, 06:26 PM
Last Post: deanhystad
  ANSI not working for change of text colors BliepMonster 10 3,420 Nov-10-2022, 09:28 AM
Last Post: BliepMonster
  How to properly scale text in postscript conversion to pdf? philipbergwerf 3 1,136 Nov-07-2022, 01:30 PM
Last Post: philipbergwerf
  python-docx- change lowercase to bold, italic Tmagpy 0 1,420 Jul-01-2022, 07:25 AM
Last Post: Tmagpy
  Replace changing string including uppercase character with lowercase character silfer 11 6,230 Mar-25-2019, 12:54 PM
Last Post: silfer
  Printing from a text file not working as I thought it would PythonZenon 10 6,109 Jun-02-2018, 09:19 PM
Last Post: snippsat
  Ending loop with string (capital & lowercase) MattWilk97 3 3,460 Oct-22-2017, 09:13 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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