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 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题