PydPiper / pylightxl

A light weight, zero dependency, minimal functionality excel read/writer python library
https://pylightxl.readthedocs.io
MIT License
290 stars 47 forks source link

Temporary file creation in current directory can fail. Use standard Python tempfile mechanism. #90

Open elgow opened 1 year ago

elgow commented 1 year ago

The temp file creation at pylightxl.py:191

            f.write(fn.read())
        fn = 'pylightxlIOtemp_wb.xlsx'

fails if the current directory is not writable. This can easily happen in a web server.

Python provides a standard way to create a temporory file with the tempfile module as follows:

    with tempfile.NamedTemporaryFile(prefix='pylightxlIOtemp_wb', suffix='.xlsx', delete=False) as f:
        tmp_name = f.name
        f.write(fn.read())
    fn = tmp_name

PR to follow.