Skip to content

Commit

Permalink
Best practices python
Browse files Browse the repository at this point in the history
  • Loading branch information
renegarcia committed Jun 20, 2023
1 parent 34ae5ad commit 23e3f94
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
26 changes: 26 additions & 0 deletions notes/code.python.bestpractices.md
Original file line number Diff line number Diff line change
@@ -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)
42 changes: 42 additions & 0 deletions notes/code.python.testing.md
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 23e3f94

Please sign in to comment.