Python Forum
Python 3.8 Nested varible not updating
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 3.8 Nested varible not updating
#6
(Aug-27-2021, 08:34 PM)snippsat Wrote:
(Aug-27-2021, 07:42 PM)Teknohead23 Wrote: If I use a while loop, which I think I should, I get an infinite loop as it will always be true
A for loop is always the first choice in Python,here a example with enumerate and f-string which you should use.
import os

letters = input("Enter the first 3 letters : ").upper()
num_start = 1
for index,item in enumerate(letters, num_start):
    dir_look = fr"C:\Users\user\Documents\Client Drawings\{letters}{index:03}"
    print(dir_look)
    check_for_folder = os.path.isdir(dir_look)
    print(check_for_folder
Output:
Enter the first 3 letters : aaa C:\Users\user\Documents\Client Drawings\AAA001 False C:\Users\user\Documents\Client Drawings\AAA002 False C:\Users\user\Documents\Client Drawings\AAA003 False

I cant use enumerate as it's only going to iterate 3 times as there are 3 input letters, I tried using aaaa, and it iterates 4 times, but you get AAAA001
So for the programs purpose, it's not a viable solution
Reply


Messages In This Thread
RE: Python 3.8 Nested varible not updating - by Teknohead23 - Oct-02-2021, 11:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python openyxl not updating Excel file MrBean12 1 393 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  local varible referenced before assignment SC4R 6 1,578 Jan-10-2023, 10:58 PM
Last Post: snippsat
  Updating nested dict list keys tbaror 2 1,311 Feb-09-2022, 09:37 AM
Last Post: tbaror
  Looping through nested elements and updating the original list Alex_James 3 2,178 Aug-19-2021, 12:05 PM
Last Post: Alex_James
  UPDATING PYTHON TO USE LATEST VERSION OF JAVA? nicklesprout 6 7,513 Jul-27-2017, 08:58 PM
Last Post: nicklesprout
  Inputting a varible BlathaBlather 3 3,629 Apr-05-2017, 08:09 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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