这看起来很简单...
您如何存储多行字符串以使您的代码保持良好的格式。
这样做很丑
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)
是否有一些特殊的方法来转义多行字符串中的制表符(就像其他所有语言一样)。
我需要确定一些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)
相当苛刻.
如何重定向
我看过的事情:
>>并且2>>只能重定向到文件.
-RedirectStandardOutput并且-RedirectStandardError只能再次重定向到文件.
| Out-File无法重定向stderr.
| Tee-Object同样的问题.
每当我在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) 第一次使用 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) 我想一次为基于目录的各种脚本导入一堆模块。例如,如果我在“ somedirectory \ here \”中有五个模块,我希望一个内衬将它们全部导入。
如何在PowerShell中完成?我可以使用清单中的所有模块的名称制作清单,以帮助我全部导入它们吗?
另外,我已经知道用户配置文件($ profile)。在这种情况下,这不能作为解决方案。
我正在尝试在使用嵌套视图的已经工作的应用程序中建立嵌套 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)