Thursday 15 August 2013

Running multiple functions in Python -


I have had a program that reads a text file and required Siriyllaijheshn in Turtle format Aradif graph. I had code crude and I was advised to separate it in tasks as I am new to Python, I did not know how to do it. Below are some functions of the program.

I am confused as to when the parameters should go into the function and when they should be started manually with . Here are some of my actions if I can get an explanation of what I am doing that would be nice.

  #! / Rdbb import Uaraiarf, graph Stringaioaipi import Stringio import Upproses sub-word WordNet (): def __init __ (self, charts): self.graph = graph () def process_file (self-file): file = open ( "new_2 .txt "," r ") return file def line_for_loop (self-file) for the line in the file: self.split_pointer_part () self.split_word_part () self.split_gloss_part () self.process_lex_filenum () self.process_synset_offset () + More functions ............ self By default, "1", "1", "D", "F", "3" == '0a': num_words = 10 others: num_words = int (word_part [3] ) return num_words Def get_pointers_list (self-pointers, After_at, Num_pointers, pointer Lees T): pointers = after_at.split () [0: 0 +4 * num_pointers: 4] pointer list = inter (pointer) returns pointer list ... ......... Code to make Triple for the graph ... ............ def print_graph (self): Print graphs. SERIALIZE (format = 'NT') def main (): wordnet = Wordnet () my_file = wordnet.process_file () wordnet.line_for_loop (My_file) If __name__ == "__main__": main ()    

Your question is mainly what is a question about object-oriented programming will quickly try to explain, but I do this and / or create

recommend reading a proper tutorial on me when you have a class and start it) with (mywordnet = WordNet (somegraph) If you are set up on the MyWorldet several times each variable you own. In WordNet, that example is stored in. For example, if you call any method of MyWiredNet, self.graph is always available. If you do not store it in self.graph, you will need to specify it as a parameter in each method (function), which requires if all these method calls require a single graph, then It will be tedious.

To look at another way to do this: whatever you set with yourself, can be seen as a type of configuration for that specific example of Wordnet. Affects. For example, you can do two wordnet instances with an individual graph, but all other functionality is the same.

I hope this will help you a little bit.

No comments:

Post a Comment