import os DIR = os.path.join(os.getcwd(), 'venv') def list_venv(): """ List venv dirs and files """ try: print((ve := os.listdir(DIR))) for x in ve: list_subs(x) except: print("Error: venv dir not found in the path") def list_subs(x): """ For files in venv, which will be (Libs, and Scripts) """ try: # subdirs print(x, os.listdir(os.path.join(DIR, x))) for y in x: list_sub_sub(x, y) except: print_config(x) def list_sub_sub(x, y): """ List subdirs and files in subdirs Warning: the next code was full of `This does not get executed` messages """ try: print(x, os.listdir(os.path.join(DIR, x, y))) for z in y: try: print_file(x, y) # not y, z? except: print("...goes on...") except: try: print_file_fallback(x) except: print("") # This gets executed (the only one!) def print_file(x, y): with open(os.path.join(DIR, x, y), 'r') as file: print(file.read()) def print_file_fallback(x): with open(os.path.join(DIR, x), 'r') as file: print(file.read()) def print_config(x): """ This will get executed twice, opening the .gitignore, and pyvenv.cfg file """ with open(os.path.join(DIR, x), 'r') as file: print(file.read()) list_venv()
- import os
- DIR = os.path.join(os.getcwd(), 'venv')
- def list_venv():
- """ List venv dirs and files """
print((ve := os.listdir(DIR)))for x in ve:list_subs(x)- try:
- print((ve := os.listdir(DIR)))
- for x in ve:
- list_subs(x)
- except:
- print("Error: venv dir not found in the path")
- def list_subs(x):
"""For files in venv, which will be (Libs, and Scripts) """- """ For files in venv, which will be (Libs, and Scripts) """
- try:
- # subdirs
- print(x, os.listdir(os.path.join(DIR, x)))
- for y in x:
- list_sub_sub(x, y)
- except:
- print_config(x)
def print_config(x):""" This will get executed twice, openingthe .gitignore, and pyvenv.cfg file """with open(os.path.join(DIR, x), 'r') as file:print(file.read())- def list_sub_sub(x, y):
""" Warning: the next code was full of- """ List subdirs and files in subdirs
- Warning: the next code was full of
- `This does not get executed` messages """
- try:
- print(x, os.listdir(os.path.join(DIR, x, y)))
- for z in y:
- try:
- print_file(x, y) # not y, z?
- except:
- print("...goes on...")
- except:
- try:
- print_file_fallback(x)
- except:
- print("") # This gets executed (the only one!)
- def print_file(x, y):
- with open(os.path.join(DIR, x, y), 'r') as file:
- print(file.read())
- def print_file_fallback(x):
- with open(os.path.join(DIR, x), 'r') as file:
- print(file.read())
- def print_config(x):
- """ This will get executed twice, opening
- the .gitignore, and pyvenv.cfg file """
- with open(os.path.join(DIR, x), 'r') as file:
- print(file.read())
- list_venv()
import os DIR = os.path.join(os.getcwd(), 'venv') def list_venv(): """ List venv dirs and files """ print((ve := os.listdir(DIR))) for x in ve: list_subs(x) def list_subs(x): """For files in venv, which will be (Libs, and Scripts) """ try: # subdirs print(x, os.listdir(os.path.join(DIR, x))) for y in x: list_sub_sub(x, y) except: print_config(x) def print_config(x): """ This will get executed twice, opening the .gitignore, and pyvenv.cfg file """ with open(os.path.join(DIR, x), 'r') as file: print(file.read()) def list_sub_sub(x, y): """ Warning: the next code was full of `This does not get executed` messages """ try: print(x, os.listdir(os.path.join(DIR, x, y))) for z in y: try: print_file(x, y) # not y, z? except: print("...goes on...") except: try: print_file_fallback(x) except: print("") # This gets executed (the only one!) def print_file(x, y): with open(os.path.join(DIR, x, y), 'r') as file: print(file.read()) def print_file_fallback(x): with open(os.path.join(DIR, x), 'r') as file: print(file.read())
- import os
# The subprocess module is never used# import subprocess# Setting constant:- DIR = os.path.join(os.getcwd(), 'venv')
# Using the walrus operator to ve tp DIR, and printing results of venv directory:print((ve := os.listdir(DIR)))# For files in venv, which will be (Libs, and Scripts)for x in ve:- def list_venv():
- """ List venv dirs and files """
- print((ve := os.listdir(DIR)))
- for x in ve:
- list_subs(x)
- def list_subs(x):
- """For files in venv, which will be (Libs, and Scripts) """
- try:
# Printing a list of files, and directories within first directory of (venv)- # subdirs
- print(x, os.listdir(os.path.join(DIR, x)))
# FOr subfile in file:for y in x:- for y in x:
- list_sub_sub(x, y)
- except:
- print_config(x)
- def print_config(x):
- """ This will get executed twice, opening
- the .gitignore, and pyvenv.cfg file """
- with open(os.path.join(DIR, x), 'r') as file:
- print(file.read())
- def list_sub_sub(x, y):
- """ Warning: the next code was full of
- `This does not get executed` messages """
- try:
- print(x, os.listdir(os.path.join(DIR, x, y)))
- for z in y:
- try:
# This does not get executedprint(x, os.listdir(os.path.join(DIR, x, y)))# FOr super-sub file in subfilefor z in y:try:# This des not get executedwith open(os.path.join(DIR, x, y), 'r') as file:print(file.read())except:# This does not get executedprint("...goes on...")- print_file(x, y) # not y, z?
- except:
try:# This does not get executedwith open(os.path.join(DIR, x), 'r') as file:print(file.read())except:# This gets executedprint('')- print("...goes on...")
- except:
# This will get executed twice, opening the .gitignore, and pyvenv.cfg filewith open(os.path.join(DIR, x), 'r') as file:print(file.read())- try:
- print_file_fallback(x)
- except:
- print("") # This gets executed (the only one!)
- def print_file(x, y):
- with open(os.path.join(DIR, x, y), 'r') as file:
- print(file.read())
- def print_file_fallback(x):
- with open(os.path.join(DIR, x), 'r') as file:
- print(file.read())
import os DIR = os.path.join(os.getcwd(), 'venv') def list_venv(): """ List venv dirs and files """ print((ve := os.listdir(DIR))) for x in ve: list_subs(x) def list_subs(x): """For files in venv, which will be (Libs, and Scripts) """ try: # subdirs print(x, os.listdir(os.path.join(DIR, x))) for y in x: list_sub_sub(x, y) except: print_config(x) def print_config(x): """ This will get executed twice, opening the .gitignore, and pyvenv.cfg file """ with open(os.path.join(DIR, x), 'r') as file: print(file.read()) def list_sub_sub(x, y): """ Warning: the next code was full of `This does not get executed` messages """ try: print(x, os.listdir(os.path.join(DIR, x, y))) for z in y: try: print_file(x, y) # not y, z? except: print("...goes on...") else: try: print_file_fallback(x) except: print("") # This gets executed (the only one!) def print_file(x, y): with open(os.path.join(DIR, x, y), 'r') as file: print(file.read()) def print_file_fallback(x): with open(os.path.join(DIR, x), 'r') as file: print(file.read())
- import os
# The subprocess module is never used# import subprocess# Setting constant:- DIR = os.path.join(os.getcwd(), 'venv')
# Using the walrus operator to ve tp DIR, and printing results of venv directory:print((ve := os.listdir(DIR)))# For files in venv, which will be (Libs, and Scripts)for x in ve:- def list_venv():
- """ List venv dirs and files """
- print((ve := os.listdir(DIR)))
- for x in ve:
- list_subs(x)
- def list_subs(x):
- """For files in venv, which will be (Libs, and Scripts) """
- try:
# Printing a list of files, and directories within first directory of (venv)- # subdirs
- print(x, os.listdir(os.path.join(DIR, x)))
# FOr subfile in file:for y in x:- for y in x:
- list_sub_sub(x, y)
- except:
- print_config(x)
- def print_config(x):
- """ This will get executed twice, opening
- the .gitignore, and pyvenv.cfg file """
- with open(os.path.join(DIR, x), 'r') as file:
- print(file.read())
- def list_sub_sub(x, y):
- """ Warning: the next code was full of
- `This does not get executed` messages """
- try:
- print(x, os.listdir(os.path.join(DIR, x, y)))
- for z in y:
- try:
# This does not get executedprint(x, os.listdir(os.path.join(DIR, x, y)))# FOr super-sub file in subfilefor z in y:try:# This des not get executedwith open(os.path.join(DIR, x, y), 'r') as file:print(file.read())except:# This does not get executedprint("...goes on...")- print_file(x, y) # not y, z?
- except:
try:# This does not get executedwith open(os.path.join(DIR, x), 'r') as file:print(file.read())except:# This gets executedprint('')except:# This will get executed twice, opening the .gitignore, and pyvenv.cfg filewith open(os.path.join(DIR, x), 'r') as file:print(file.read())- print("...goes on...")
- else:
- try:
- print_file_fallback(x)
- except:
- print("") # This gets executed (the only one!)
- def print_file(x, y):
- with open(os.path.join(DIR, x, y), 'r') as file:
- print(file.read())
- def print_file_fallback(x):
- with open(os.path.join(DIR, x), 'r') as file:
- print(file.read())