变量:
private string filePath1 = null;
private string filePath2 = null;
private string filePath3 = null;
private string filePath4 = null;
private string filePath5 = null;
private string filePath6 = null;
private string filePath7 = null;
private string filePath8 = null;
private string filePath9 = null;
private string filePath10 = null;
Run Code Online (Sandbox Code Playgroud)
当前 If 语句
if (string.IsNullOrEmpty(filePath1))
{
errors.Add("File Not Attached");
}
if (string.IsNullOrEmpty(filePath2))
{
errors.Add("File Not Attached");
}
....
Run Code Online (Sandbox Code Playgroud)
题:
对于每个变量,而不是有多个 if 语句。如何创建 1 个 if 语句来遍历所有这些变量?
像这样的东西:
if (string.IsNullOrEmpty(filePath …Run Code Online (Sandbox Code Playgroud) 代码
#Variables
var1 = ['Warehouse Pencil 1.docx', 'Production Pen 20.docx']
list1 = []
for x in var1:
splitted = x.split()
a = [splitted[0] + ' ' + splitted[1]]
list1.append(a)
print(list1)
Run Code Online (Sandbox Code Playgroud)
输出
[['Warehouse Pencil']]
[['Warehouse Pencil'], ['Production Pen']]
Run Code Online (Sandbox Code Playgroud)
目标
我打算拆分列表,获取每个部分的第 1 个和第 2 个单词,然后将它们放入一个新列表中。
题
为什么我的输出给我一个奇怪的输出?我哪里错了?
期望输出
我想要的输出应该是这样的:
['Warehouse Pencil', 'Production Pen']
Run Code Online (Sandbox Code Playgroud)
抓取第 1 个和第 2 个单词并将它们放入 1 个列表中。
目标
目前正在寻找一种方法,如何从 DataGridView 中选择项目并按顶部选择的第一个进行排序。
例子
用户的第一个选择:
Selected Column1 Column2
a 1
b 2
c 3
x d 4
Run Code Online (Sandbox Code Playgroud)
第二次选择...
Selected Column1 Column2
a 1
x b 2
c 3
x d 4
Run Code Online (Sandbox Code Playgroud)
第三次选择...
Selected Column1 Column2
x a 1
x b 2
c 3
x d 4
Run Code Online (Sandbox Code Playgroud)
命令
4th row
2nd row
1st row
Run Code Online (Sandbox Code Playgroud)
概括
用户选择的第一个项目是第 4 行,然后是第 2 行,最后是第 1 行。
题
如何按上述顺序获取所有行的列表?
当前代码
我像这样创建了一个复选框列,这样用户就可以看到他们选择了什么。
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.Name = "Selected";
checkBoxColumn.HeaderText = "Selected";
checkBoxColumn.ReadOnly = false; …Run Code Online (Sandbox Code Playgroud) 目标:
我的目标是每次运行该函数时将最后一个结果与新结果进行比较。
代码:
starttime = time.time()
def countRows():
while True:
#Get number of rows from SQL table
sqlCursor = sqlConnection.cursor()
sqlCursor.execute("Select count(*) from SalesOrder")
rowcount = sqlCursor.fetchone()[0]
print(rowcount)
if rowcount != rowcount:
print("changed")
time.sleep(10.0 - ((time.time() - starttime) % 10.0))
countRows()
Run Code Online (Sandbox Code Playgroud)
细节:
在这里,我从 SQL 表中获取计数。
这是每 10 秒的输出:
1000
1000
1000
1000
Run Code Online (Sandbox Code Playgroud)
如果将一条记录添加到 sql 表中,则计数显然会更改为1001.
当前代码的问题:
该if语句不起作用 - 当数字更改时。它只是打印数字。
题:
虽然该功能每 10 秒运行一次。print("changed")如果值与以前的值不同,如何触发?
首要目标:
查找特定文件的版本号。
我正在做一个项目 - 我找不到任何与我的问题类似的东西。我发现正则表达式可能对我有帮助,但它非常复杂。所以寻找更简单的方法。
问题:
我有这样的变量:
a = 'Section 1 - Analyse (i01).docx'
b = 'Section 1 - All Vitamins (i02).docx'
c = 'Section 1 - (i03) Removed Vitamins .docx'
Run Code Online (Sandbox Code Playgroud)
题:
如何查看(i)上面各个变量的内部数字?
钥匙:
(i01)-i仅代表一个问题编号。
例子:
一个例子,(i)变量的问题编号a是01。
另一个例子,ifor 变量b是02。这是因为它会查找i并显示 旁边的数字i。
笔记:
有谁知道查看变量中的版本号并返回数字。