I have code that looks like this:
def tearDown(): try: os.remove("SomeFile1") os.remove("SomeFile2") except FileNotFoundError: print("No files made")
These files can be created in a unittest, this code is from the tearDown. But when SomeFile1 wasnt made but SomeFile2 was, SomeFile2 will not be removed.
I could do it like this:
def tearDown(): try: os.remove("SomeFile1") except FileNotFoundError: print("No SomeFile1") try: os.remove("SomeFile2") except FileNotFoundError: print("No SomeFile2")
Is there a better way than this? Seems not very pythonic
submitted by /u/noob_main22
[link] [comments]
r/learnpython I have code that looks like this: def tearDown(): try: os.remove(“SomeFile1”) os.remove(“SomeFile2”) except FileNotFoundError: print(“No files made”) These files can be created in a unittest, this code is from the tearDown. But when SomeFile1 wasnt made but SomeFile2 was, SomeFile2 will not be removed. I could do it like this: def tearDown(): try: os.remove(“SomeFile1”) except FileNotFoundError: print(“No SomeFile1”) try: os.remove(“SomeFile2”) except FileNotFoundError: print(“No SomeFile2”) Is there a better way than this? Seems not very pythonic submitted by /u/noob_main22 [link] [comments]
I have code that looks like this:
def tearDown(): try: os.remove("SomeFile1") os.remove("SomeFile2") except FileNotFoundError: print("No files made")
These files can be created in a unittest, this code is from the tearDown. But when SomeFile1 wasnt made but SomeFile2 was, SomeFile2 will not be removed.
I could do it like this:
def tearDown(): try: os.remove("SomeFile1") except FileNotFoundError: print("No SomeFile1") try: os.remove("SomeFile2") except FileNotFoundError: print("No SomeFile2")
Is there a better way than this? Seems not very pythonic
submitted by /u/noob_main22
[link] [comments]