"ExportFormat" is not defined
miknai opened this issue · comments
Geonsoo Kim commented
Describe the bug
I get "ExportFormat" is not defined
when using export(...)
call.
To Reproduce
- Install package with
pip install gspread
- Create a Python script with the below code snippet
- Run the script
import gspread
if __name__ == "__main__":
gc = gspread.oauth()
sh = gc.open("running-tracker")
my_export(sh)
data = sh.export(format=ExportFormat.CSV)
print(data)
Expected behavior
No such error happens. Currently, I added this code snippet from utils.py (LINK) in script to avoid the error, "ExportFormat" is not defined
from collections import defaultdict, namedtuple
MimeType = namedtuple(
"MimeType",
["google_sheets", "pdf", "excel", "csv", "open_office_sheet", "tsv", "zip"],
)(
"application/vnd.google-apps.spreadsheet",
"application/pdf",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"text/csv",
"application/vnd.oasis.opendocument.spreadsheet",
"text/tab-separated-values",
"application/zip",
)
ExportFormat = namedtuple(
"ExportFormat", ["PDF", "EXCEL", "CSV", "OPEN_OFFICE_SHEET", "TSV", "ZIPPED_HTML"]
)(
MimeType.pdf,
MimeType.excel,
MimeType.csv,
MimeType.open_office_sheet,
MimeType.tsv,
MimeType.zip,
)
Environment info:
- Operating System: Windows 11
- Python version: 3.11.5
- gspread version: 5.12.0
alifeee commented
hi :) thanks for the issue
Please try this code. I import ExportFormat
from gspread.utils
:
import gspread
from gspread.utils import ExportFormat
if __name__ == "__main__":
gc = gspread.oauth()
sh = gc.open("running-tracker")
my_export(sh)
data = sh.export(format=ExportFormat.CSV)
print(data)
you could also replace ExportFormat.CSV
with gspread.utils.ExportFormat.CSV
Geonsoo Kim commented
Ah, works. Thanks!