我有一个TraceSource对象,我用它来记录VB.Net应用程序的初始化.它附加了几个TraceListeners:
对于前两个,我希望输入输出为"原始" - 即没有标准头:
SourceName TraceEventType: Id :
我已经实现了一个包装器,当TraceEventType设置为Verbose时执行此操作:
If _buffer.EventType = TraceEventType.Verbose Then
For Each listener As TraceListener In _traceSource.Listeners
listener.Write(_buffer.Text)
Next
Else
_traceSource.TraceEvent(_buffer.EventType, id, _buffer.Text)
End If
Run Code Online (Sandbox Code Playgroud)
我可以为所有跟踪执行此操作,但然后EventLog中的所有条目都将列出Level = Information.所以我希望能够指定跟踪消息的严重性,但我无法在TraceSource或TraceListeners上找到允许我这样做的任何方法.据我所知,TraceListener有这些选项可以写入它:
最后3个允许提供TraceEventType(正确标记EventLog条目,但结果输出到控制台,然后日志文件包含前缀,并以此结束(例如):
Bootstrapper Warning: 0 : Failed to validate assembly
有没有办法覆盖ConsoleTraceListener和TextWriterTraceListener如何格式化其输出以不包含此标头,同时能够使用TraceEventType标记条目(对于EventLog)?
这是迄今为止我提出的最好的:
For Each listener As TraceListener In _traceSource.Listeners
If listener.GetType Is GetType(ConsoleTraceListener) OrElse listener.GetType Is GetType(TextWriterTraceListener) Then
listener.Write(_buffer.Text)
Else
listener.TraceEvent(Nothing, _traceSource.Name, _buffer.EventType, id, _buffer.Text)
End If
Next
Run Code Online (Sandbox Code Playgroud)
这似乎有效,但在Microsoft …
我想在R中逐行打印矢量元素,如下所示
1
2
3
然而,当我这样做paste(c(1,2,3), "\n")或者paste(c(1,2,3),sep = "\n"),新的生产线永远不会被打印出来.同样的事情cat也是如此.我总是得到以下内容:
"1" "2" "3"
我想知道解决这个问题.
因为data frames没有na.print 选择.是否有任何解决方法来抑制NA的显示?
样本数据框:
df <- data.frame(
x=c("a","b","c","d"),
a=c(1,1,1,1),
b=c(1,1,1,NA),
c=c(1,1,NA,NA),
d=c(1,NA,NA,NA))
df
Run Code Online (Sandbox Code Playgroud)
结果是:
x a b c d
1 a 1 1 1 1
2 b 1 1 1 NA
3 c 1 1 NA NA
4 d 1 NA NA NA
Run Code Online (Sandbox Code Playgroud)
但我想表明:
x a b c d
1 a 1 1 1 1
2 b 1 1 1
3 c 1 1
4 d 1
Run Code Online (Sandbox Code Playgroud) 通常,舍入到小数点后2位非常容易
printf("%.2lf",<variable>);
Run Code Online (Sandbox Code Playgroud)
但是,舍入系统通常会舍入到最近的偶数.例如,
2.554 -> 2.55
2.555 -> 2.56
2.565 -> 2.56
2.566 -> 2.57
Run Code Online (Sandbox Code Playgroud)
而我想要实现的是
2.555 -> 2.56
2.565 -> 2.57
Run Code Online (Sandbox Code Playgroud)
事实上,四舍五入在C中是可行的,但仅对于整数;
int a = (int)(b+0.5)
Run Code Online (Sandbox Code Playgroud)
所以,我要问的是如何在正值上用2位小数而不是Integer做同样的事情来实现我之前说的打印.
我有以下文件
[
{
"id": 1,
"name": "Arthur",
"age": "21"
},
{
"id": 2,
"name": "Richard",
"age": "32"
}
]
Run Code Online (Sandbox Code Playgroud)
要一起显示登录名和ID,我使用以下命令
$ jq '.[] | .name' test
"Arthur"
"Richard"
Run Code Online (Sandbox Code Playgroud)
但是当我把它放在一个shell脚本并尝试将它分配给一个变量时,整个输出显示在一行如下所示
#!/bin/bash
names=$(jq '.[] | .name' test)
echo $names
$ ./script.sh
"Arthur" "Richard"
Run Code Online (Sandbox Code Playgroud)
我想在每次迭代时打破,类似于它在命令行上的工作方式.
请帮忙
我有一个带有一些非常长的"注释"列的数据框.当我显示它们时,它们被分成不同的块,使得难以跨行读取.是否可以更改R中的设置或修改对data.frame的调用以截断特定长度的字符串?
示例:3列数据帧
data.frame(cbind(rep(1,5),rep(c("very very long obnoxious character string here" ,"dog","cat","dog",5)),rep(c("very very long obnoxious character string here" ,"dog","cat","dog",5))))
Run Code Online (Sandbox Code Playgroud)
在我的屏幕上看到的结果数据帧:
X1 X2
1 1 very very long obnoxious character string here
2 1 dog
3 1 cat
4 1 dog
5 1 5
X3
1 very very long obnoxious character string here
2 dog
3 cat
4 dog
5 5
Run Code Online (Sandbox Code Playgroud) 说我有数据框,c:
a=np.random.random((6,2))
c=pd.DataFrame(a)
c.columns=['A','B']
Run Code Online (Sandbox Code Playgroud)
打印第0行的值:
print c.loc[(0),:]
Run Code Online (Sandbox Code Playgroud)
结果是:
A 0.220170
B 0.261467
Name: 0, dtype: float64
Run Code Online (Sandbox Code Playgroud)
我想取消显示该Name: 0, dtype: float64行,以便得到:
A 0.220170
B 0.261467
Run Code Online (Sandbox Code Playgroud)
有人知道吗?
(nb我将此附加到文本文件中)
我对 R 比较陌生,所以希望这是一个简单的解决方法。
这是我的问题:
x <- data.frame(c("Thing1", "Thing2", "Thing3", "Thing4", "Thing5"), c("Sizeable line of text", "more text", "I hope this aligns", "something", "help me"))
colnames(x) <- c("T", "Text")
format(x, justify = "left")
T Text
1 Thing1 Sizeable line of text
2 Thing2 more text
3 Thing3 I hope this aligns
4 Thing4 not much
5 Thing5 help me
Run Code Online (Sandbox Code Playgroud)
如何让列名与数据框的其余部分左对齐?
提前致谢。
我正在尝试从我从RESTful API接收的JSON文件创建一个表.
当我打印json对象的属性时,我得到一个这样的输出:
PS> Write-Output JSON.Object
Object1 : @{key1=property; key2=property; key3=property; key4=property}
Object2 : @{key1=property; key2=property; key3=property; key4=property}
Object3 : @{key1=property; key2=property; key3=property; key4=property}
Object4 : @{key1=property; key2=property; key3=property; key4=property}
我希望看到的输出是这样的:
Name key1 key2 key3 key4 ----- ---- ---- ---- ---- Object1 property property property property Object2 property property property property Object3 property property property property
另外,是否可以避免显示特定键及其属性?
例:
Name key1 key2 key4 # ← Not displaying key3 ----- ---- ---- ---- Object1 property property property Object2 property property property Object3 …
我有一个MPI进程,我需要打印到文件.MPI系统使用MPI_File_iwrite等功能命令,它接受缓冲区(例如char指针)和整数长度.然后,缓冲区将打印到文件中.
因此,为了打印我需要打印到文件的内容,我需要以某种方式用一个将格式转换映射到char*缓冲区的函数替换printf函数.这是有问题的,因为字符串的长度可能不同......例如:
printf("something %d, %d, %d, %f, etc.",x,y,z,p,d,...);
Run Code Online (Sandbox Code Playgroud)
如何恢复printf格式化生成的字符串,找出长度是多少,并将其作为char*传递给mpi函数?