这种对私有变量的访问(不改变它们!)——如何安全和可接受?
class MyClass:
def __init__(self):
self.__private_var = 66
class_instance = MyClass()
print(class_instance._MyClass__private_var)
动态创建按钮并将其添加到 LinearLayout
fun but_gen (line:String, dec:String, contactframe:LinearLayout, tag:String) {
val contacts = "Vasya|Fedya|Masha".split("|")
for (contact in contacts) {
val button = Button(this).apply {
text = contact
}
contactframe.addView(button)
}
}
如何为他们创建一个组监听器setOnClickListener并通过文本进行识别?如果它是在按钮之前创建的,它还能运行吗?
有一行:
const txt = ' #text # textx saad #asadsas '
执行 3 项操作的最佳方法是什么
name = input("Your name: ")
while len(name) > 100:
print(name)
name *=1
我写了这个,但是代码不正确。
我需要复制之前的名字100。
我不明白,它应该是这样的:
#1 Маша
#2 МашаМаша
#3 МашаМашаМаша
#так далее я не понимаю как написать код.
我无法理解它的工作原理,在button_onclick事件的开头我调用textBox.Clear(),即我希望每次单击此按钮时,文本框都会被清除,但如果我不关闭表单,则不会发生这种情况,输出结果会累积。在这段代码中:
private void but_OK_Click(object sender, EventArgs e)
{
txt_output.Clear();
string str_input = txt_input.Text;
Format_Rule(str_input);
for (int i = 0; i < str_in.Count; i++)
{
txt_output.Text += str_in.GetKey(i) + " " + str_in.Get(i) + Environment.NewLine;
}
}
这是所有代码
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ТЯП_Лаб1
{
public partial class Form1 : Form
{
NameValueCollection str_in = new NameValueCollection();
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string alpha_number = "0123456789";
string alpha_operand = "-+*/";
private bool Search_Operand(string str)
{
for (int i = 0; i < alpha_operand.Length; i++)
{
if (str.Contains(alpha_operand[i]))
{
return true;
}
}
return false;
}
private bool Search_Number(string str)
{
for (int i = 0; i < alpha_number.Length; i++)
{
if (str.Contains(alpha_number[i]))
{
return true;
}
}
return false;
}
private bool Search_Word(string str)
{
for (int i = 0; i < alphabet.Length; i++)
{
if (str.Contains(alphabet[i]))
{
return true;
}
}
return false;
}
private void Format_Rule(string str )
{
string str_oper = "";
string str_set = "";
if (!Search_Operand(str))
{
for (int i = 0; i < str.Length; i++)
{
if(i == str.Length)
str_set += str[i];
else
str_set += str[i] + " | ";
}
str_in.Add("S->", "T");
str_in.Add("T->", "T | TF");
str_in.Add("F->", str_set);
}
else
{
for (int i = 0; i < str.Length; i++)
{
if(str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
{
if(i != str.Length)
str_oper += str[i] + "T" + " | ";
else
str_oper += str[i] + "T";
}
else
{
if(i != str.Length)
str_set += str[i] + " | ";
else
str_set += str[i];
}
}
str_in.Add("S->", str_oper);
str_in.Add("T->", "T | TF");
str_in.Add("F->", str_set);
}
}
public Form1()
{
InitializeComponent();
}
private void but_OK_Click(object sender, EventArgs e)
{
txt_output.Clear();
string str_input = txt_input.Text;
Format_Rule(str_input);
for (int i = 0; i < str_in.Count; i++)
{
txt_output.Text += str_in.GetKey(i) + " " + str_in.Get(i) + Environment.NewLine;
}
}
}
}