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

Dict representation as a copy/pastable code #28758

Open
scls19fr opened this issue Aug 19, 2018 · 3 comments
Open

Dict representation as a copy/pastable code #28758

scls19fr opened this issue Aug 19, 2018 · 3 comments
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects.

Comments

@scls19fr
Copy link
Contributor

scls19fr commented Aug 19, 2018

Hello,

it will be nice if Dict representation could be improved to be copy/pastable code.

For example representation of a Dict in REPL Julia is

julia> params
Dict{String,String} with 3 entries:
  "token"   => "NzXXXXXXXXXXXXXXWnp"
  "message" => "My first message"
  "user"    => "RAXXXXXXXXXXXStjN"

maybe this kind of representation

julia> params
Dict{String,String}(
  "token"   => "NzXXXXXXXXXXXXXXWnp",
  "message" => "My first message",
  "user"    => "RAXXXXXXXXXXXStjN",
)
3 entries

could be much more useful as it's easily copy/pastable.

This is maybe generalisable to any type implementing AbstractDict.

Kind regards

@KristofferC
Copy link
Sponsor Member

Isn't this what repr is for?

@scls19fr
Copy link
Contributor Author

julia> println(repr(params))
Dict("token"=>"NzXXXXXXXXXXXXXXWnp","message"=>"My first message","user"=>"RAXXXXXXXXXXXStjN")

this is not default representation for REPL
it doesn't show type of key / type of value
Return to the line and indentation helps for reading

@JeffBezanson
Copy link
Sponsor Member

this is not default representation for REPL

It would be difficult to convince everybody to change the default printing in the REPL --- it probably won't happen. The default REPL format has certain conveniences, like showing fewer digits and truncating arrays, that people will not want to give up and yet aren't appropriate for a parse-able representation.

it doesn't show type of key / type of value

It doesn't in this case because it's fully implied by the contents. In other cases it will, e.g.

julia> repr(Dict{Any,Any}(1=>2))
"Dict{Any,Any}(1=>2)"

If there are cases that don't work they can be fixed.

Return to the line and indentation helps for reading

It would probably be ok to add that to the show/repr format.

@JeffBezanson JeffBezanson added the domain:display and printing Aesthetics and correctness of printed representations of objects. label Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

No branches or pull requests

3 participants