[ wraith46 @ 12.04.2017. 19:32 ] @
Imam jednu metodu napisanu u C#: Code: void LoadWords() { words.Clear(); listView1.Items.Clear(); string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string vocabulary_path = path + "\\Vocabulary\\Words.xml"; if (!Directory.Exists(path + "\\Vocabulary")) Directory.CreateDirectory(path + "\\Vocabulary"); if (!File.Exists(vocabulary_path)) { XmlTextWriter xW = new XmlTextWriter(vocabulary_path, Encoding.UTF8); xW.WriteStartElement("Words"); xW.WriteEndElement(); xW.Close(); } XmlDocument xDoc = new XmlDocument(); xDoc.Load(vocabulary_path); foreach (XmlNode xNode in xDoc.SelectNodes("Words/Word")) { Word w = new Word(); w.WordOrPhrase = xNode.SelectSingleNode("Word").InnerText; w.Explanation = xNode.SelectSingleNode("Explanation").InnerText; w.Translation = xNode.SelectSingleNode("Translation").InnerText; w.Examples = xNode.SelectSingleNode("Examples").InnerText; words.Add(w); listView1.Items.Add(w.WordOrPhrase); WordCount(); } } ...koju treba da konvertujem u Python. Evo sta sam dosad uradio: Code: def load_words(self): self.listBox.delete(0, END) self.words.clear() vocabulary = os.path.join(path, "Vocabulary", "Words.xml") if not os.path.exists(vocabulary): if not os.path.exists(os.path.dirname(vocabulary)): os.mkdirs(os.path.dirname(vocabulary)) doc = ET.Element('Words') tree = ET.ElementTree(doc) tree.write(vocabulary) else: tree = ET.ElementTree(file=vocabulary) |