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

tocsv(source=None) does not output to stdout #632

Closed
blais opened this issue Nov 20, 2022 · 0 comments · Fixed by #634
Closed

tocsv(source=None) does not output to stdout #632

blais opened this issue Nov 20, 2022 · 0 comments · Fixed by #634
Labels
Bug It must work in all situations, but this failed

Comments

@blais
Copy link
Contributor

blais commented Nov 20, 2022

Minimal, reproducible code sample, a copy-pastable example if possible

petl.wrap([...]).tocsv()

Problem description

The documentation says

Load - writing tables to files and databases
The following functions write data from a table to a file-like source or database. For functions that accept a source argument, if the source argument is None or a string it is interpreted as follows:

None - write to stdout
...

I've never found this to work, and always work around it.
I looked into it this time briefly, and it looks like a blatant oversight.

The _resolve_source_from_arg function gets called from both the read_source_from_arg() and write_source_from_arg() functions below it and does this:

def _resolve_source_from_arg(source, handlers):
    if source is None:
        return StdinSource()
   ...

You need to move the conditional within each of the two functions that call it (simple solution).

Probably should be prioritized high... this looks pretty bad for newcomers to the library, as this is library one of the first things someone might do.

Version and installation information

1.7.11

@juarezr juarezr added the Bug It must work in all situations, but this failed label Nov 21, 2022
@juarezr juarezr linked a pull request Nov 22, 2022 that will close this issue
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug It must work in all situations, but this failed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants