Every line of 'file handling in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
36 def _file_is_python(path): 37 # type: (str) -> bool 38 if path.endswith('.py'): 39 return True 40 41 _, extension = os.path.splitext(path) 42 if extension: 43 return False 44 try: 45 with open(path) as might_be_python: 46 line = might_be_python.readline() 47 return line.startswith('#!') and 'python' in line 48 except UnicodeDecodeError: 49 return False
984 def is_python(self, path): 985 """Test whether argument path is a Python script.""" 986 head, tail = os.path.splitext(path) 987 return tail.lower() in (".py", ".pyw")