Python Forum
How to make an activation flag?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make an activation flag?
#1
Hello,
I have a program, which runs well.
It looks like

os.chdir('zips')
a = open("ziplist.txt", "w")
for path, subdirs, files in os.walk(r'./'):
    for filename in files:
        if filename.endswith(".zip"):
            commands....
            for line in open('%s.txt' % (date_ID)).readlines():
                if line.startswith('range_samples:'):
                    commands...
                    os.chdir('../')
Now I want to expand it with an if/else statement as an activation flag, something like: if the first argv is 1, run the whole program written above
and else do nothing.

I am trying it like this:

if activate_flag == 1 :
    os.chdir('zips')
    a = open("ziplist.txt", "w")
    for path, subdirs, files in os.walk(r'./'):
        for filename in files:
            if filename.endswith(".zip"):
                commands....
                for line in open('%s.txt' % (date_ID)).readlines():
                    if line.startswith('range_samples:'):
                       commands...
                       os.chdir('../')
else: 
   print("NO")
But it just write out the else statement: NO
Where is my mistake?
Reply
#2
If you want it to do nothing when the flag is 0, just remove the else clause. Or is there something you want it to do when the flag is 0?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(Oct-11-2018, 01:19 PM)Krszt Wrote: But it just write out the else statement: NO
Where is my mistake?


Show us how you assign the value of activation_flag before that if statement. Wild guess - it's a str and that is why '1' != 1
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
(Oct-11-2018, 01:19 PM)Krszt Wrote: Hello, I have a program, which runs well. It looks like
os.chdir('zips') a = open("ziplist.txt", "w") for path, subdirs, files in os.walk(r'./'): for filename in files: if filename.endswith(".zip"): commands.... for line in open('%s.txt' % (date_ID)).readlines(): if line.startswith('range_samples:'): commands... os.chdir('../') 
Now I want to expand it with an if/else statement as an activation flag, something like: if the first argv is 1, run the whole program written above and else do nothing. I am trying it like this:
if activate_flag == 1 : os.chdir('zips') a = open("ziplist.txt", "w") for path, subdirs, files in os.walk(r'./'): for filename in files: if filename.endswith(".zip"): commands.... for line in open('%s.txt' % (date_ID)).readlines(): if line.startswith('range_samples:'): commands... os.chdir('../') else: print("NO")
But it just write out the else statement: NO Where is my mistake?
Yes, Itried, but my problem is that it doesnt do anything.
Reply
#5
(Oct-11-2018, 01:40 PM)buran Wrote: Show us how you assign the value of activation_flag before that if statement.

Boosting the signal.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Big Grin Variable flag vs code outside of for loop?(Disregard) cubangt 2 1,167 Mar-16-2022, 08:54 PM
Last Post: cubangt
  how to check for thread kill flag nanok66 1 2,170 May-09-2020, 10:06 PM
Last Post: nanok66
  Check for a special characters in a column and flag it ayomayam 0 2,044 Feb-12-2020, 03:04 PM
Last Post: ayomayam
  Using a flag error blackjesus24 1 1,613 Jan-30-2020, 09:42 AM
Last Post: buran
  Identifying string success flag graham23s 4 3,103 Aug-14-2019, 09:27 PM
Last Post: graham23s
  Practicing using a "flag": please point in right direction magsloo 5 3,076 May-10-2019, 04:58 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