0

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 Answer 1

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
Sign up to request clarification or add additional context in comments.

4 Comments

but how can i storage a number in a list?
If you want to add number 7 to index 0, you write: test.insert(0, 7). Then the number is stored in the list. You can verify it with: print(test)
String and int works the same way when inserting into an list. When you do this: a = [0] * 12 you actually store 12 zeros in the list
so do you mean this? x is the part where in the list i want to isert it, and sef.nummer.text is the textbox a.insert(x,self.nummer.Text)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.