Ich erstelle ein einfaches GUI-Programm, um Prioritäten zu verwalten.Python-Äquivalent für C# 's generische Liste <T>
Ich habe erfolgreich ein Element hinzufügen, um das Listenfeld Managed Funktionalität hinzuzufügen. Jetzt möchte ich das Element zu etwas hinzufügen, was als List <> in C# bekannt ist. Gibt es so etwas in Python?
Zum Beispiel in C#, ein Element zur Listenansicht hinzufügen möchte ich zunächst erstellen:
List<Priority> priorities = new List<Priority>();
... und erstellen Sie die folgende Methode:
void Add()
{
if (listView1.SelectedItems.Count > 0)
{
MessageBox.Show("Please make sure you have no priorities selected!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (txt_Priority.ReadOnly == true) { MessageBox.Show("Please make sure you refresh fields first!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); }
else
{
if ((txt_Priority.Text.Trim().Length == 0)) { MessageBox.Show("Please enter the word!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); }
else
{
Priority p = new Priority();
p.Subject = txt_Priority.Text;
if (priorities.Find(x => x.Subject == p.Subject) == null)
{
priorities.Add(p);
listView1.Items.Add(p.Subject);
}
else
{
MessageBox.Show("That priority already exists in your program!");
}
ClearAll();
Sync();
Count();
}
}
SaveAll();
}
Und Sie konnten keine Informationen finden, die nach "Python-Liste" suchen ?! – jonrsharpe