diff --git a/notes/code.python.bestpractices.md b/notes/code.python.bestpractices.md new file mode 100644 index 0000000..3a72e2a --- /dev/null +++ b/notes/code.python.bestpractices.md @@ -0,0 +1,26 @@ +--- +id: cwab3v7c5fbe9heqos93k0e +title: Best Practices +desc: '' +updated: 1687284332737 +created: 1687284123125 +--- + +# Linters + + +Linters perform static analysis of source codes and check for symantic discrepancies. +When you lint your code, it’s passed through a basic quality checking tool that provides +instructions on how eliminate basic syntactic inconsistencies. + + +# Formatters + +Formatters are similar tools that tries to restructure your code spacing, line length, +argument positioning etc to ensure that your code looks consistent across different +files or projects. + + +# References + +1. [https://py-vscode.readthedocs.io/en/latest/files/linting.html](https://py-vscode.readthedocs.io/en/latest/files/linting.html) diff --git a/notes/code.python.testing.md b/notes/code.python.testing.md new file mode 100644 index 0000000..3fdef2a --- /dev/null +++ b/notes/code.python.testing.md @@ -0,0 +1,42 @@ +--- +id: vvdgu21ycbtn2zfytwremiy +title: Testing +desc: '' +updated: 1687289774366 +created: 1687289451077 +--- + + +# Create named temporary file + +```python +import tempfile + +def create_temp_file(prefix): + temp_file = tempfile.NamedTemporaryFile(prefix=prefix, delete=False) + temp_file.close() + return temp_file.name + +# Example usage +prefix = "my_prefix" +temp_file_path = create_temp_file(prefix) +print("Temporary file created:", temp_file_path) +``` + +From the above code, note that the file path can be retrived with `temp_file.name`. + +## Access the file directory + + +```python +from pathlib import Path + +temp_file = create_temp_file("my_prefix") +path = Path(temp_file) +print(path.parent) +``` + + +# References + +1. [Source](https://chat.openai.com/share/abe75dba-545e-4e17-83db-b59d60ed8c98) \ No newline at end of file