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

Add support for formatting Strings as in print() (not in a addition to repr()) #22

Closed
GlenHertz opened this issue Nov 14, 2019 · 4 comments

Comments

@GlenHertz
Copy link
Contributor

If a column of strings contains " characters then they are printed like:

func(\"temp\")

I'd like to be able to print the table as in print, like:

func("temp")

I typically use PrettyTables for viewing "publication" results (not debugging Julia strings) so I think print should be the default format for strings. (Love this package, BTW.)

@ronisbr
Copy link
Owner

ronisbr commented Nov 15, 2019

Hi @GlenHertz

If a column of strings contains " characters then they are printed like:

func(\"temp\")

I'd like to be able to print the table as in print, like:

func("temp")

I typically use PrettyTables for viewing "publication" results (not debugging Julia strings) so I think print should be the default format for strings.

I agree 100%! Indeed, this is a misunderstanding from my part about the function escape_string. Depending how you use it, it also scape the ", which we do not want. I will fix this today.

(Love this package, BTW.)

Thanks! I'm glad it is being useful :)

@ronisbr
Copy link
Owner

ronisbr commented Nov 15, 2019

Done! Can you please test @GlenHertz using master?

julia> matrix = [ 1 """
       function str(str = "one string")
           return str
       end"""
       2 """
       function str(str = "")
           if isempty(str)
               return "one string"
           else
               return str
           end
       end"""];

julia> pretty_table(matrix, alignment = :l, linebreaks = true)
┌────────┬──────────────────────────────────┐
│ Col. 1 │ Col. 2                           │
├────────┼──────────────────────────────────┤
│ 1function str(str = "one string") │
│        │     return str                   │
│        │ end                              │
│ 2function str(str = "")           │
│        │     if isempty(str)              │
│        │         return "one string"      │
│        │     else                         │
│        │         return str               │
│        │     end                          │
│        │ end                              │
└────────┴──────────────────────────────────┘

@GlenHertz
Copy link
Contributor Author

I tested it and it works as desired, thanks! I also ran it through my other code just to see if anything would break and it all works fine.

@ronisbr
Copy link
Owner

ronisbr commented Nov 18, 2019

Perfect! Thanks for the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants