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

generating tables from external sources #5339

Closed
jlgerber opened this issue Apr 26, 2022 · 4 comments
Closed

generating tables from external sources #5339

jlgerber opened this issue Apr 26, 2022 · 4 comments
Labels
question the issue author asks something

Comments

@jlgerber
Copy link

I have a python script which prints data to stdout and it looks exactly like the documented format for tables. However, it does not generate a table. Likewise, when capturing the output to a variable and subsequently echoing the contents of the variable - no luck. Is this supposed to work? I am printing to stdout without a trailing carriage return. Is there something else required?

@rgwood
Copy link
Contributor

rgwood commented Apr 26, 2022

Hi, it's hard to know exactly what you're trying without seeing an example. But generally the easiest way to create a Nu table from text is by using one of the from commands (type help from to see them all). For example:

python3 my_python_script_that_returns_json.py | from json

@fdncred fdncred added the question the issue author asks something label Apr 26, 2022
@fdncred
Copy link
Collaborator

fdncred commented Apr 26, 2022

@jlgerber if you want to generate a table in nushell from an external source there are a few ways to do it.

  1. use data that is represented by a table like .csv, .yaml, .toml, .json, or our nuon format
  2. use data that uses record literals like { key: a value: 1 } and wrap it in brackets like [{ key: a value: 1}
  3. use data that uses table literals like [[key value]; [a 1]]
  4. use data that is spatially delimited and then use from ssv or detect columns

@jlgerber
Copy link
Author

so for #2 / #3 how does one convert a string into record or table literals?

@jlgerber
Copy link
Author

jlgerber commented Apr 27, 2022

as a concrete example, here is what i am printing to stdout

[{'type': 'Asset', 'id': 13064, 'code': 'Book Illustration'}]

I realize that isn't valid json (just printing a list of dicts). I guess i can convert it to json and print it out... which works!
so following rgwood's advice and doing a 'pycomd | from json' for the win

@fdncred fdncred closed this as completed Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question the issue author asks something
Projects
None yet
Development

No branches or pull requests

3 participants