Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Testing Split elements
#4
I do not have a problem splitting.
I need to replace the fourth element in a split if the element does not exist.
Here is a line to split:
   Motherboard:   Ao11   Build-211   DT 2021 SN-0123A456
if the line has nothing after the word "Motherboard:"
   Motherboard:  
I want to print something like "not there" or "empty" or "No Serial Num"
I thought I could split the line and test elements if they are ==0 or not.
That is why I'm testing element 4 if it is empty.

    mb=re.split(r" {2,}", rn_l)
    if not mb[4] :
       mb[4] ="No Serial Num"
    else :
        print (f" Motherboard Serial number   -->> {mb[4]}")
Reply


Messages In This Thread
Testing Split elements - by tester_V - May-08-2021, 05:41 AM
RE: Testing Split elements - by bowlofred - May-08-2021, 05:57 AM
RE: Testing Split elements - by buran - May-08-2021, 06:17 AM
RE: Testing Split elements - by tester_V - May-08-2021, 09:56 PM
RE: Testing Split elements - by snippsat - May-08-2021, 10:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,291 May-17-2022, 11:38 AM
Last Post: Larz60+
  Sorting Elements via parameters pointing to those elements. rpalmer 3 2,673 Feb-10-2021, 04:53 PM
Last Post: rpalmer
  How to sum up the elements of an integer using python split/join? mohanraj1986 5 3,599 Aug-27-2018, 09:13 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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