小编Jam*_*all的帖子

没有缩进字符的 T-SQL 多行字符串

这看起来很简单...

您如何存储多行字符串以使您的代码保持良好的格式。

这样做很丑

DECLARE @myStr NVARCHAR(MAX)
SET @myStr = 'This represents a really long
string that i need multiple lines for,
dude.'
Run Code Online (Sandbox Code Playgroud)

但上面的结果是正确的字符串输出:

SELECT @myStr
'This represents a really long string that i need multiple lines for, dude.'
Run Code Online (Sandbox Code Playgroud)

这样做可以更轻松地阅读我的代码:

DECLARE @myStr NVARCHAR(MAX)
SET @myStr = 'This represents a really long
    string that i need multiple lines for,
    dude.'
Run Code Online (Sandbox Code Playgroud)

但结果是:

SELECT @myStr
'This represents a really long     string that i need multiple lines for, 
dude.'
Run Code Online (Sandbox Code Playgroud)

是否有一些特殊的方法来转义多行字符串中的制表符(就像其他所有语言一样)。

t-sql sql-server

5
推荐指数
1
解决办法
6566
查看次数

Python在字符串的开头匹配'.\'

我需要确定一些powershell路径字符串在哪里交叉到Python中.

如何检测Python中的路径是否以.\

这是一个例子:

import re

file_path = ".\reports\dsReports"

if re.match(r'.\\', file_path):
    print "Pass"
else:
    print "Fail"
Run Code Online (Sandbox Code Playgroud)

这个失败,在它列出的调试器中

  expression = .\\\\\\
   string = .\\reports\\\\dsReports
Run Code Online (Sandbox Code Playgroud)

如果我尝试使用替换如此:

import re

file_path = ".\reports\dsReports"
testThis = file_path.replace(r'\', '&jkl$ff88')

if re.match(r'.&jkl$ff88', file_path):
    print "Pass"
else:
    print "Fail"
Run Code Online (Sandbox Code Playgroud)

所述testThis可变结束这样的:

testThis = '.\\reports&jkl$ff88dsReports'
Run Code Online (Sandbox Code Playgroud)

相当苛刻.

python regex string substring

4
推荐指数
1
解决办法
112
查看次数

Powershell将stderr和stdout重定向到两个不同的地方

如何重定向

  • stderr到logfile
  • stdout to object

我看过的事情:

>>并且2>>只能重定向到文件.
-RedirectStandardOutput并且-RedirectStandardError只能再次重定向到文件.
| Out-File无法重定向stderr.
| Tee-Object同样的问题.

powershell redirect stdout stderr

3
推荐指数
2
解决办法
2513
查看次数

Powershell点源在记事本中打开文件

每当我在PowerShell中点源文件时,它都会在记事本中打开该文件的副本.

可执行程序:

.\MyScript.ps1
Run Code Online (Sandbox Code Playgroud)

脚本运行正常 - 它真的很烦人,一直弹出这些.有没有办法压制这个?

我在Windows 7 x64上使用最新版本的PowerShell.

例2:这仍然是启动记事本.

cls

Set-Location "\\PSCWEBP00129\uploadedFiles\psDashboard\"
. .\assets\DCMPull\Powershell\SqlServerTransfer.psm1
. .\assets\DCMPull\Powershell\RunLogging.psm1
Run Code Online (Sandbox Code Playgroud)

powershell notepad

3
推荐指数
1
解决办法
1111
查看次数

异步生成器说它没有实现 __anext__,当它实现时

第一次使用 Aync 生成器。我正在使用Python 3.9。

这是我的实现:

import asyncio

class SubEventStream():
    def __init__(self) -> None:
        self.queue = asyncio.Queue()
        return

    async def __aiter__(self):
        return self

    async def __anext__(self):
        return await self.pop()

    async def append(self, request):
        return await self.queue.put(request)

    async def pop(self):
        r = await self.queue.get()
        self.queue.task_done()
        return r

def create_append_tasks(ls, q):
    return [
        asyncio.create_task(q.append(i))
        for i in ls
    ]

async def append_tasks(q):
    tasks = create_append_tasks(('a', 'b', 'c', 'd', 'e'), q)
    return await asyncio.gather(*tasks)


async def run():
    q = SubEventStream()
    await append_tasks(q)

    async for …
Run Code Online (Sandbox Code Playgroud)

python async-await python-asyncio

3
推荐指数
1
解决办法
1983
查看次数

从目录导入PowerShell脚本或模块

我想一次为基于目录的各种脚本导入一堆模块。例如,如果我在“ somedirectory \ here \”中有五个模块,我希望一个内衬将它们全部导入。

如何在PowerShell中完成?我可以使用清单中的所有模块的名称制作清单,以帮助我全部导入它们吗?

另外,我已经知道用户配置文件($ profile)。在这种情况下,这不能作为解决方案。

import powershell module

1
推荐指数
1
解决办法
1880
查看次数

MVVM 将嵌套子视图连接到子视图模型

我正在尝试在使用嵌套视图的已经工作的应用程序中建立嵌套 ViewModel。这是我想做的一个例子:

主窗口视图:

<Window x:Name="FCTWindow" x:Class="CatalogInterface.MainWindow"
        xmlns:local="clr-namespace:CatalogInterface"
        xmlns:vm="clr-namespace:CatalogInterface.ViewModels"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="532">

    <Window.Resources>
        <vm:MainWindowViewModel x:Key="ViewModel" />
    </Window.Resources>

    <Grid DataContext="{Binding Path=ViewModel.DirFilesListBoxViewModel}" x:Name="BodyGridLeft" Grid.Row="0" Grid.Column="0">
        <local:ctlDirFilesListBox>
            <!--
                Need to access the `ItemsSource="{Binding }"` and
                 `SelectedItem="{Binding Path=}"` of the ListBox in 
                 `ctlDirFilesListBox` view -->
        </local:ctlDirFilesListBox>
</Window>
Run Code Online (Sandbox Code Playgroud)

子视图:

<UserControl x:Class="CatalogInterface.ctlDirFilesListBox"
         xmlns:local="clr-namespace:CatalogInterface"
         xmlns:vm="clr-namespace:CatalogInterface.ViewModels"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">

<Grid x:Name="MainControlGrid">           
    <ListBox SelectionChanged="ListBoxItem_SelectionChanged" 
                         HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#FFFFFF"
                         Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" BorderThickness="0">
        <ListBox.ItemContainerStyle>
            <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
                <EventSetter Event="MouseDoubleClick" Handler="ListBoxItem_MouseDoubleClick"/>
                <EventSetter Event="KeyDown" Handler="ListBoxItem_KeyDown"/>
            </Style>
        </ListBox.ItemContainerStyle>
    </ListBox>
</Grid>
</UserControl> …
Run Code Online (Sandbox Code Playgroud)

c# wpf nested mvvm

1
推荐指数
1
解决办法
3127
查看次数