Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
boolean result of loop
#1
a classic loop structure tests for one of a sequence of possible conditions.  in python the loop iterates over an iterator or equivalent (a sequence).  a variable starts at an initial state and is set by the condition.  it is then tested after the loop.

here is an example:

unsafe = False
for part in filename.split('/'):
    if part == '..':
        unsafe = True
if unsafe:
    raise UnsafeFileError(filename)
what i am looking for is if python has any simpler-code method for doing this kind of test.  since this is a example it needs to be not specific to this example.  any clues?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
boolean result of loop - by Skaperen - Mar-31-2017, 01:47 AM
RE: boolean result of loop - by wavic - Mar-31-2017, 02:27 AM
RE: boolean result of loop - by Skaperen - Mar-31-2017, 05:50 AM
RE: boolean result of loop - by Ofnuts - Mar-31-2017, 08:30 AM
RE: boolean result of loop - by Skaperen - Apr-01-2017, 04:10 AM
RE: boolean result of loop - by buran - Apr-01-2017, 04:48 AM
RE: boolean result of loop - by wavic - Apr-01-2017, 05:02 AM
RE: boolean result of loop - by buran - Apr-01-2017, 05:13 AM
RE: boolean result of loop - by wavic - Apr-01-2017, 06:09 AM
RE: boolean result of loop - by ichabod801 - Apr-01-2017, 10:45 AM
RE: boolean result of loop - by wavic - Apr-01-2017, 11:20 AM
RE: boolean result of loop - by buran - Apr-01-2017, 12:07 PM
RE: boolean result of loop - by ichabod801 - Apr-01-2017, 12:42 PM
RE: boolean result of loop - by Skaperen - Apr-02-2017, 01:03 AM
RE: boolean result of loop - by Skaperen - Apr-02-2017, 02:52 AM
RE: boolean result of loop - by Ofnuts - Apr-02-2017, 08:33 PM
RE: boolean result of loop - by wavic - Apr-02-2017, 11:34 PM
RE: boolean result of loop - by micseydel - Apr-02-2017, 11:50 PM
RE: boolean result of loop - by wavic - Apr-02-2017, 11:56 PM
RE: boolean result of loop - by ichabod801 - Apr-03-2017, 12:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Running A Loop Until You See A Particular Result knight2000 6 32,139 Sep-04-2021, 08:55 AM
Last Post: knight2000
  Noob Alert! Wrong result using loop and if statemnent GJG 7 3,091 Dec-19-2020, 05:18 PM
Last Post: buran

Forum Jump:

User Panel Messages

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