douliaodun9153 2017-10-15 01:34
浏览 39
已采纳

在go的Stringer界面中修改默认值

I'm looking at the print interface in the gota dataframe here: https://github.com/kniren/gota/blob/master/dataframe/dataframe.go#L99

I see the default value is shortCols = true, given here.

When I call the print data frame, how can I override this value to print with shortCols = false when I println?

fmt.Println(fil)

eg, I'd like to print all columns, rather than just the first 5 as the above produces the below:

[31x16] DataFrame

    valA   valB    valC    valD    valE        ...
 0:  578   8.30     491    7959    1.040000    ...
 1:  577   8.30     291    7975    2.050000    ...
 2:  466   16.7     179    6470    3.210000    ...
 3:  592   9.03     194    8212    4.040000    ...
  • 写回答

1条回答 默认 最新

  • doulu7174 2017-10-15 07:35
    关注

    Without modifying the library there is nothing you can do.

    If modifying the library is an option you have a few possibilities:

    1. Change the name of the internal formatting function so it is exported and call that. This is a bit more work, since you need to explicitly call a function every time you want to print a DataFrame, but it is a reasonable option if you want to make minimal changes to the way the library works.

      Basically change print to Print on lines 101 and 104 (I think those are the only occurrences of that function; if not the compiler will be happy to point out the others :P)

    2. Change the arguments to df.print in the definition of df.String. This is positively trivial, but it has the effect of changing the default behaviour, which may or may not be a good thing.

      For this option just change line 101 to return df.print(true, false, true, true, 10, 70, "DataFrame") or whatever combination fits your needs.

    3. Add a new method for each printing format you want, and explicitly call these new methods. This is more work than #1 or #2, but some people may prefer it.

    Personally, I would go with #1, but your question makes #2 sound more like what you want.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程