Python Forum
four commands i wrote the other day
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
four commands i wrote the other day
#1
i wrote these four commands the other day:

wait_for_all_files_to_exist.py:
#!/usr/bin/env python3
from sys import argv
from time import sleep,time as secs
import os

step = 1/4
exe = argv.pop(0)
nxet = int(secs())+0.5
if not argv:
    exit('need one or more file names')
while 1:
    e = 1
    for n in argv:
        if not os.path.exists(n):
            e = 0
    if e:
        break
    nxet += step
    diff = nxet-secs()
    while diff<0:
        nxet += step
        diff = nxet-secs()
    sleep(diff)
exit(0)
wait_for_all_files_to_not_exist.py:
#!/usr/bin/env python3
from sys import argv
from time import sleep,time as secs
import os

step = 1/4
exe = argv.pop(0)
nxet = int(secs())+0.5
if not argv:
    exit('need one or more file names')
while 1:
    e = 1
    for n in argv:
        if os.path.exists(n):
            e = 0
    if e:
        break
    nxet += step
    diff = nxet-secs()
    while diff<0:
        nxet += step
        diff = nxet-secs()
    sleep(diff)
exit(0)
wait_for_any_file_to_exist.py:
#!/usr/bin/env python3
from sys import argv
from time import sleep,time as secs
import os

step = 1/4
exe = argv.pop(0)
nxet = int(secs())+0.5
if not argv:
    exit('need one or more file names')
while 1:
    e = 0
    for n in argv:
        if os.path.exists(n):
            e = 1
    if e:
        break
    nxet += step
    diff = nxet-secs()
    while diff<0:
        nxet += step
        diff = nxet-secs()
    sleep(diff)
exit(0)
wait_for_any_file_to_not_exist.py:
#!/usr/bin/env python3
from sys import argv
from time import sleep,time as secs
import os

step = 1/4
exe = argv.pop(0)
nxet = int(secs())+0.5
if not argv:
    exit('need one or more file names')
while 1:
    e = 0
    for n in argv:
        if not os.path.exists(n):
            e = 1
    if e:
        break
    nxet += step
    diff = nxet-secs()
    while diff<0:
        nxet += step
        diff = nxet-secs()
    sleep(diff)
exit(0)
edit:

changed variable next to nxet.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Note that you are overwritting the built in function next

https://docs.python.org/3/library/functions.html#next Wrote:next(iterator[, default])
Retrieve the next item from the iterator by calling its __next__() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised.
Reply
#3
where have i done that? i don't see it (yet).

oh, now i see what you mean, the name. yeah bad choice of name; but it didn't break anything, the commands work.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
It won't break anything in the code shown, it would be when you go to use next for its original intention and it doesn't do what you expected.
Reply
#5
i changed it.
Tradition is peer pressure from dead people

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  I wrote a cryptographic algorithm! keames 3 3,302 May-11-2021, 06:10 AM
Last Post: Gribouillis
  I wrote an emulator! keames 8 4,860 Nov-13-2019, 10:13 PM
Last Post: keames

Forum Jump:

User Panel Messages

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