str.endswith
str.endswith(...)Description
Documentation for str.endswith.
Real-World Examples
Practical code examples showing how str.endswith is used in real projects.
# Get file suggestions from the repository
files = await github_mcp.suggest_files(repo.full_name, max_results=2)
for file in files:
if file.name.endswith('.py'):
content = await github_mcp.get_file_content(repo.full_name, file.path)
log_file.write(f"\nFile: {file.name}\n")
log_file.write("```python\n")
log_file.write(content)
log_file.write("\n```\n")
log_file.write("-" * 40 + "\n")
log_file.write("\n" + "=" * 80 + "\n\n")
print("Code samples have been successfully fetched and saved to sample_code.log")
except Exception as e:
print(f"Error occurred: {str(e)}")
if __name__ == "__main__":
asyncio.run(fetch_code_samples())
async def get_all_content_from_zip(self, path: Path) -> str:
with zipfile.ZipFile(path, "r") as zip_ref:
valid_files = [
file
for file in zip_ref.namelist()
if file.endswith(VALID_FILE_EXTENSIONS)
]
formatted_content = []
for file in valid_files:
try:
if zip_ref.getinfo(file).file_size > FILE_LIMIT:
logger.warning(f"Skipping file: {file} because it is too large")
continue
decoded_content = zip_ref.read(file).decode("utf-8")
except UnicodeDecodeError:
logger.warning(f"Failed to decode content for file: {file}")
continue
formatted_content.append(
self._get_formatted_content(
self._get_file_name_from_zip_name(file),
decoded_content,
)
)