Python Forum
remove spaces with exceptions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
remove spaces with exceptions
#3
Ok, managed to write some piece of code to do the job:
word = "asdas asdd sd a2123 3234 \"test asd sdd 12 3231  123\" asda"

quo = False
wordT = ""

for letter in word:
        
    if letter == "\"" and quo == False:
        quo = True
        wordT += letter
        continue
        
    if quo == False:
        wordT += letter
    
    if quo == True:
        if letter == " ":
            wordT += "_"
        else:
            wordT += letter
    
    if letter == "\"" and quo == True:
        quo = False

print(wordT.replace(" ","").replace("_"," "))
Output:
asdasasddsda21233234"test asd sdd 12 3231 123"asda
But the solution is not very elegant.
Reply


Messages In This Thread
remove spaces with exceptions - by catosp - May-29-2020, 08:12 AM
RE: remove spaces with exceptions - by buran - May-29-2020, 08:55 AM
RE: remove spaces with exceptions - by catosp - May-29-2020, 09:21 AM
RE: remove spaces with exceptions - by pyzyx3qwerty - May-29-2020, 09:30 AM
RE: remove spaces with exceptions - by catosp - May-29-2020, 09:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PiCamera - print exceptions? korenron 2 854 Dec-15-2022, 10:48 PM
Last Post: Larz60+
  Class exceptions DPaul 1 1,314 Mar-11-2022, 09:01 AM
Last Post: Gribouillis
  is this a good way to catch exceptions? korenron 14 4,754 Jul-05-2021, 06:20 PM
Last Post: hussaind
  Python, exceptions KingKhan248 6 3,083 Nov-15-2020, 06:54 AM
Last Post: buran
  Split string between two different delimiters, with exceptions DreamingInsanity 2 2,055 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity
  handling 2 exceptions at once Skaperen 2 2,330 Jun-27-2020, 08:55 AM
Last Post: Yoriz
  Looking for advice and Guidance on Exceptions used within Functions paul41 1 2,180 Nov-14-2019, 12:33 AM
Last Post: Larz60+
  multi-line messages in raised exceptions? Skaperen 3 7,399 Aug-01-2019, 02:17 AM
Last Post: Skaperen
  Creating custom exceptions that co-operate LadySvetlana 4 3,100 Mar-19-2019, 04:24 PM
Last Post: LadySvetlana
  Problems with not having exceptions crash my script league55 7 4,926 Feb-16-2018, 09:06 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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