Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Add encoding to file writing function #405

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bibtexparser/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def write_file(
parse_stack: Optional[Iterable[Middleware]] = None,
append_middleware: Optional[Iterable[Middleware]] = None,
bibtex_format: Optional[BibtexFormat] = None,
encoding: str = "UTF-8",
) -> None:
"""Write a BibTeX database to a file.

Expand All @@ -134,15 +135,16 @@ def write_file(
If None, a default stack will be used.
:param append_middleware: List of middleware to append to the default stack.
Only applicable if `parse_stack` is None.
:param bibtex_format: Customized BibTeX format to use (optional)."""
:param bibtex_format: Customized BibTeX format to use (optional).
:param encoding: Encoding for the .bib file. Default encoding is "UTF-8"."""
bibtex_str = write_string(
library=library,
unparse_stack=parse_stack,
prepend_middleware=append_middleware,
bibtex_format=bibtex_format,
)
if isinstance(file, str):
with open(file, "w") as f:
with open(file, "w", encoding=encoding) as f:
f.write(bibtex_str)
else:
file.write(bibtex_str)
Expand Down
Loading