我正在尝试使用telnetlib在Telnet会话中捕获和操作数据,事情进展顺利,但是我对Python的新见解让我头疼.
My issue is pretty straight forward, I am able to capture and display the data I want (So far) however I just seem to be cycling through errors whenever I try to remove the last line of data from the data I have captured. My code goes something like this:
... Snipped Boring Stuff ...
tn.write('command to gather data' + '\r')
data = tn.read_very_eager()
print data
... snipped more boring stuff ...
Run Code Online (Sandbox Code Playgroud)
Pretty simple... So, how in the world …
我正在尝试重新使用我在网上找到的函数来删除字符串中的特殊字符,这样我就可以在交换中将其用作别名,但我收到了上述错误.
我似乎无法找到这个错误抱怨的内容.这是功能:
Function Convert-ToFriendlyName{
param ($Text)
# Unwanted characters (includes spaces and '-') converted to a regex:
$SpecChars = '!', '"', '£', '$', '%', '&', '^', '*', '(', ')', '@', '=', '+', '¬', '`', '\', '<', '>', '.', '?', '/', ':', ';', '#', '~', "'", '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', ' '
$remspecchars = [string]::join('|', ($SpecChars | % {[regex]::escape($_)}))
# Convert the text given to correct naming format (Uppercase)
$name = (Get-Culture).textinfo.totitlecase(“$Text”.tolower())
# Remove …Run Code Online (Sandbox Code Playgroud) 所以我是PHP的新手,我正在努力完成一些非常简单的事情.将文本文件导入到数组中,让foreach遍历该数组以查找值,并在找到时打印该值.
这是我到目前为止所尝试的:
$testers = file('test.txt');
foreach ($testers as $test) {echo $test . "<br />";}
Run Code Online (Sandbox Code Playgroud)
这很好用,每行都打印出来.完善.然后我添加一个IF语句.
$testers = file('test.txt');
foreach ($testers as $test) {if ($test){echo $test . "<br />";}}
Run Code Online (Sandbox Code Playgroud)
工作正常,似乎是返回数据.现在,如果我尝试添加一个运算符,它就会崩溃.
$testers = file('test.txt');
foreach ($testers as $test) {if ($test == "One"){echo $test . "<br />";}}
Run Code Online (Sandbox Code Playgroud)
我应该说,文本文件中包含从"一"到"六"的每一行的数字我也尝试过:
$testers = file('test.txt');
foreach ($testers as $test) {if ($test === "One"){echo $test . "<br />";}}
Run Code Online (Sandbox Code Playgroud)
这也没有回复......
任何见解都会很棒!谢谢!
我到底错过了什么?为什么这个if语句没有返回我正在寻找的值?!