问题
Sorry for my bad English.. I'm programming in Ironpython a WPF Apllication. I want to storage the number, which is in self.nummer.Text, in the variable a[1]. how can i do this? this don't work(list):
def __init__(self):
wpf.LoadComponent(self, 'WpfApplication1.xaml')
self.mitarbeiter.Content=1
array = [0,0,0,0,0,0,0,0,0,0,0,0]
def eingabe(self, sender, e):
for x in range(1,13):
a = self.nummer.Text
self.tt.Content = a
and this also don't work (arrays):
import wpf
from Window1 import *
from System import Array
from System.Windows import Application, Window
class MyWindow(Window):
def __init__(self):
wpf.LoadComponent(self, 'WpfApplication1.xaml')
self.mitarbeiter.Content=1
array = Array[int]((0,0,0,0,0,0,0,0,0,0,0,0))
def eingabe(self, sender, e):
for x in range(1,13):
array[x] = self.nummer.Text
self.tt.Content = array[x]
can anybody help me?
回答1:
In python you usually use list instead of array docs
test = []
test.append("Hello")
test.append("Hello second time")
print(test)
test.insert(0, "Hello first time")
print(test)
You could, just use the test.insert(0, value) to get the desired effect.
Instead of doing this:
a = [0,0,0,0,0,0,0,0,0,0,0,0]
Do this:
a = [0] * 12
My guees is that you need to change you code to the below. In your code you create the array, but then in the function you try to store the value to another variable that you declare in a loop. That is not possible to do, either you do as I have below, or you initiate the array before entering the loop.
def __init__(self):
wpf.LoadComponent(self, 'WpfApplication1.xaml')
self.mitarbeiter.Content=1
array_a = [0,0,0,0,0,0,0,0,0,0,0,0]
def eingabe(self, sender, e):
for x in range(1,13):
self.array_a.insert(x, self.nummer.Text)
self.tt.Content = a
来源:https://stackoverflow.com/questions/62422480/how-can-i-access-on-arrays-in-ironpython