我正在使用Powershell进行一些ETL工作,读取压缩文本文件并根据每行的前三个字符将它们拆分.
如果我只是过滤输入文件,我可以将过滤后的流传输到Out-File并完成它.但我需要将输出重定向到多个目标,据我所知,这不能用简单的管道完成.我已经在使用.NET流读取器来读取压缩的输入文件了,我想知道是否需要使用一个streamwriter来编写输出文件.
天真的版本看起来像这样:
while (!$reader.EndOfFile) {
$line = $reader.ReadLine();
switch ($line.substring(0,3) {
"001" {Add-Content "output001.txt" $line}
"002" {Add-Content "output002.txt" $line}
"003" {Add-Content "output003.txt" $line}
}
}
Run Code Online (Sandbox Code Playgroud)
这看起来像坏消息:每行查找,打开,写入和关闭文件一次.输入文件是巨大的500MB +怪物.
是否有一种惯用的方法来处理这个有效的Powershell构造,或者我应该转向.NET编写器?
是否有我可以使用的(New-Item"path"-type"file")对象的方法?
编辑上下文:
我正在使用DotNetZip库将ZIP文件作为流读取; 因此streamreader而不是Get-Content/ gc.示例代码:
[System.Reflection.Assembly]::LoadFrom("\Path\To\Ionic.Zip.dll")
$zipfile = [Ionic.Zip.ZipFile]::Read("\Path\To\File.zip")
foreach ($entry in $zipfile) {
$reader = new-object system.io.streamreader $entry.OpenReader();
while (!$reader.EndOfFile) {
$line = $reader.ReadLine();
#do something here
}
}
Run Code Online (Sandbox Code Playgroud)
我应该Dispose()同时使用$ zipfile和$ reader,但这是另一个问题!
假设我有这样的多态结构.
map.resources :bar, :has_many => :foo
map.resources :baz, :has_many => :foo
map.resources :qux, :has_many => :foo
class Foo
belongs_to :parent, :polymorphic => true
end
class FooController < AC
before_filter :find_parent
...
private
def find_parent
# ugly way:
@parent = if params[:bar_id]
Bar.find(params[:bar_id])
elsif params[:baz_id]
Baz.find(params[:baz_id])
elsif params[:qux_id]
Qux.find(params[:qux_id])
end
end
end
Run Code Online (Sandbox Code Playgroud)
那太难看了.每当我们添加一个它可能属于的新东西时,我们需要将它非干扰地添加到before_filter.
它也变得更糟.假设Foos 真的是可以在任何地方出现的多态事物,比如评论或标签.并假设您有以下路线:
map.resources :bar, :has_many => :foo do |bar|
bar.resources :baz, :has_many => :foo
end
map.resources :qux, :has_many => :foo do |qux|
qux.resources :baz, :has_many => :foo …Run Code Online (Sandbox Code Playgroud) 我想以二进制模式读取图像,以便将其保存到我的数据库中,如下所示:
img = open("Last_Dawn.jpg")
t = img.read()
save_to_db(t)
Run Code Online (Sandbox Code Playgroud)
这适用于Mac.但在Windows上,img.read()是不正确的.它只是整个集合中的一点点.
所以我的第一个问题是:为什么上面的代码在Windows中不起作用?
第二是:有没有其他方法可以做到这一点?
非常感谢!
我有一个带有两个不同提交按钮的django表单,在提交表单的视图中我需要知道按下了什么提交按钮并相应地采取不同的操作.
从我所看到的提交按钮的名称或ID应该在request.POST字典中的某个地方,但它不存在!
这是我的表单的一个片段:
<form id="editPaperForm" action="{{paper.editURL}}" method="POST">
<input type="submit" name="savePaperButton" id="savePaperButton" value="Save and Send Later"/>
<input type="submit" name="sendPaperButton" id="sendPaperButton" value="Save and send"/>
...
</form>
Run Code Online (Sandbox Code Playgroud)
在视图中:
...
if 'sendPaperButton' in request.POST:
return applicants_confirmSend(request, paperID)
else:
return applicants_home(request)
Run Code Online (Sandbox Code Playgroud)
sendPaperButton永远不在request.POST中,也不是另一个,我应该在其他地方寻找吗?
我唯一的想法就是在发送表单之前添加一个隐藏字段并通过javascript修改它,但这似乎有点多余,因为我很确定数据应该存在于某个地方......
谢谢!
在Swing应用程序中,我有许多子面板,每个子面板都听一个JSlider.周围的父面板也会监听所有子面板.为了在下面的示例中获得一致的结果,我必须首先添加父级,然后添加本地侦听器.考虑到本文中规定EventListenerList和解释的顺序,这是有道理的.我可以依赖该订单,还是应该安排发送不同的活动?
class SubPanel extends JPanel implements ChangeListener {
private final JSlider slider = new JSlider();
private final JLabel label = new JLabel();
private final String name;
private float value;
public SubPanel(String name, float value, ChangeListener parent) {
this.name = name;
this.value = value;
...
slider.addChangeListener(parent);
slider.addChangeListener(this);
}
...
}
Run Code Online (Sandbox Code Playgroud)
附录:讨论EventListenerList似乎是实施建议而不是保证.pstanton建议的链接方法更可靠地强制执行正确的顺序.例如,SubPanel的ChangeListener可以简单地将事件转发到父.
@Override
public void stateChanged(ChangeEvent e) {
...
parent.stateChanged(e);
}
Run Code Online (Sandbox Code Playgroud) 当mount命令失败时,我想找出网络共享的安装位置,如下所示:
$ mkdir ~/share
$ mount_afp afp://server/share ~/share
mount_afp: the volume is already mounted
Run Code Online (Sandbox Code Playgroud)
看起来很有希望......
$ mount
... snip ...
afp_000000004oMw0q76003DF78u-1.2d000006 on /Volumes/share-1 (afpfs, nodev, nosuid, mounted by username)
afp_000000004oMw0q76003DF78u-2.2d000007 on /Volumes/share-2 (afpfs, nodev, nosuid, mounted by username)
Run Code Online (Sandbox Code Playgroud)
似乎应该有一种方法将这些长afp_000...数字映射到URI ...有没有办法确定卷的位置,因为它的afp:// URI?
我实际上是用Python的子进程模块执行这些命令,所以如果有一个模块或库可以做到这一点也是可以接受的.
gcc 4.4.2 c89
我有这个代码片段,我必须在很多代码中重复.我只是想知道有没有办法通过使用宏功能来缩短它?
有我想改变的代码.
ERR_INFO error_info; /* create error object */
ErrorInfo(&error_info); /* pass the address for it to be filled with error info */
fprintf(stderr, "And the error is? [ %s ]\n", error_info.msg); /* display the error msg */
Run Code Online (Sandbox Code Playgroud)
我试图创建一个宏功能来使用它.
#define DISPLAY_ERR(error_info) ErrorInfo(&error_info) error_info.msg
fprintf(stderr, "And the error is? [ %s ]\n", DISPLAY_ERR); /* display the error
Run Code Online (Sandbox Code Playgroud)
任何建议都会有所帮助,
这就是问题.我有一个div,其中包含几段文字,然后是一个浮动的图像.图像按原样浮动,但包含的div不会垂直扩展以适应图像.我知道我可以手动设置div的高度,但这会产生问题,因为我想对我的网站的每个页面使用相同的div,因此高度需要不同.
这是一个代码示例:
#main_contentbox {
width: 918px;
margin: 10px auto;
padding: 10px 20px 20px 20px;
background-color: #ffffff;
border-style: solid;
border-width: 1px;
border-color: #000;
}
#main_contentbox img#sample {
float: right;
}Run Code Online (Sandbox Code Playgroud)
<div id="main_contentbox">
<h1 class="page"> The Event </h1>
<img id="sample" src="sample.jpg" />
<p>
stackoverflow is awesome!stackoverflow is awesome!stackoverflow is awesome!stackoverflow is awesome!stackoverflow is awesome!stackoverflow is awesome!stackoverflow is awesome!</p>
<p>stackoverflow is awesome!stackoverflow is awesome!stackoverflow is awesome!stackoverflow is awesome!
</div>Run Code Online (Sandbox Code Playgroud)
我正在努力使用EditText和Spannable文本对象,这些天,我已经阅读了大约十次的API文档,即使我不确定我是否理解正确.所以我正在寻找一个向我展示如何利用EditText和Spannable的例子.
当我ps -aux在我的linux服务器上运行命令时,我使用putty连接到该命令,很少有进程太长而无法适应我当前的窗口宽度.还有其他选择吗?
- 更新 -
我很抱歉降级,我认为其他人也不会觉得答案有用,所以我降级了.
这是您要求的信息.
hadoop-user@hadoop-desk:~$ echo $TERM
xterm
hadoop-user@hadoop-desk:~$ stty -a
speed 38400 baud; rows 47; columns 158; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 …Run Code Online (Sandbox Code Playgroud)