How to allow for multiple file names when searching through a directory in python?
How can I write something like: module_path = os.path.join(root_dir,_dir,'Tests.py') to be able to also take into considerations files named Test.py and test.py and tests.py? If the file Tests.py isn't found, how can it check for another of the two to make sure that who ever wrote the program gets their file seen? What I am trying to say is is there something that would allow me to do this?: module_path = os.path.join(root_dir,_dir,'(T or t)est(s).py')
If it is literally those four files you are searching for then something like the following will work: import os _dir = 'test' names=['Test.py','test.py','Tests.py','tests.py'] for fname in names: test_path = os.path.join(_dir, fname) if os.path.isfile(test_path): module_path = test_path break You will need to modify to suit your environment.
You could use the glob module, which supports a simple version of regular expressions ("Unix-style wildcards"). E.g., you can use this: for name in glob.glob("[tT]est*.py"): print("I found", name) This matches files whose name begins with "Test" or "test", and ends with .py. It won't give you the names in order of preference, but it might be all you need.
Is there a way to quickly create many files many sequential files (ex1 . . . ex 50) in Python?
Pygame playing sound with pygame.mixer.music.load(file) gives NoneType error
How to update multiple values in Mongodb using pymongo?
Manually return an error result and status failure for a celery task?
Python backtrace from C++ embedded in Python
Find nth smallest element in numpy array [duplicate]
How to extract array from the first element of triples in 2d array of triples using numpy
Simulate user clicking in QSystemTrayIcon
Parsing GeoRSS feed with python scripting
User interface optimization when using pack
Selenium doesn't return after starting Chrome but returns after starting Firefox?
Python JSON decoding error TypeError: can't use a string pattern on a bytes-like object
Equivalent of \b word boundary in str.contains?
How to store django objects as session variables ( object is not JSON serializable)?
SQLAlchemy (w/ Postgres) - How to limit full-text search to one column of many indexed?
Split on separators not giving exact output