Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Problem with For "str" in str["str"]
Forum Updated to NodeBB v4.3 + New Features

Problem with For "str" in str["str"]

Scheduled Pinned Locked Moved Unsolved Qt for Python
1 Posts 2 Posters 223 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Tarik EL JABIRIT Offline
    Tarik EL JABIRIT Offline
    Tarik EL JABIRI
    wrote on last edited by
    #1

    Hi,
    I have a List like this :

    myList = [
     "LOT_1,T49359/22",
     "LOT_2,T49360/22",
     "LOT_3,T49361/22",
     "LOT_4,T49362/22",
     "LOT_5,T49363/22",
     "LOT_6,T49364/22",
     "LOT_7,T49365/22",
     "LOT_8,T49366/22",
     "LOT_9,T49367/22",
     "LOT_10,T49368/22",
     "LOT_11,T49369/22",
     "LOT_12,T49370/22",
     "LOT_13,T49371/22",
     "LOT_14,T49372/22",
     "LOT_15,T49373/22",
           "..."
     "LOT_995,T50125/22"]
    

    and i have folders like this: C:/subfolder/subfolder1/LOT_830 folders from LOT_1 to LOT_995.
    My code Source is :

    for f in subfolders:
     
        folder_is_not_renamed = True
     
        for line in myList:
            result = line.replace("\n", "").replace("/", "-").split(",")
            if result[0] in f:
                myDirectory = f.replace(os.path.dirname(f), "")
     
                # src source
                src = f
                # dist distination
                dist = f.replace(myDirectory, '/' + result[1])
     
                if not os.path.exists(dist):
     
                    os.rename(src, dist)
                     
                    folder_is_not_renamed = False
        if folder_is_not_renamed:
            print(f + " is not Renamed \n")
    print('Finished')
    
    

    the problem is when it arrives to folder "C:/subfolder/subfolder1/LOT_10" the "if result[0] in f" return True for LOT_1 but not the case it should return False. I know that "LOT_1" in "C:/subfolder/subfolder1/LOT_10" return True it is correct but i want a way to avoid it.

    I want to mention some folders contains like "C:/subfolder/subfolder1/LOT_10 BIS" or something else.
    I am always looking for LOT_10 no matter what after it or before it.

    thank you.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved