can anyone over here help me with python programming? im trying to write a code to read a txt file
What do you have written so far? ``` fo = open("foo.txt", "wb") ```
well i have been given a skeleton file
implement the function read_graph_from_file. The function is called with one argument (the name of a file), and must return a tuple with two elements, like this: (neighbour_list, position_list) = read_graph_from_file(filename) The first element in the tuple, neighbour_list, is the internal representation of the graph's structure. (This is defined below.) The second element is a list of node positions. This is only used for drawing the graph on screen.
this is what im ment to be doing
so far i have written: def read_graph_from_file(filename): my_file=open(filename,"rU") position_list=[] for row in my_file: value=row[:-1] my_list=value.split(",") try: if my_list[2] != "": nodenumber = my_list[0] positionX = my_list[1] positionY = my_list[2] position_list = tuple([positionX,positionY]) except IndexError: pass return([position_list]) (neighbour_list, position_list) = read_graph_from_file(filename)
the code i have written so far is to find the position of the mode on the graph
The format of the graph files is similar to the CSV files we have seen before, but different in that it contains two types of lines. For a graph with N nodes and M links, the first N lines have the form nodeNumber, positionX, positionY The nodes are numbered consecutively from 0 to N-1. The X and Y positions are integers. After this, the next M lines specify the links. They have the form nodeNumber1,nodeNumber2
tbh I know no python and prefer c++/java. I doubt I'll be of much help
Yeah I have no idea what I'm reading. Check out the computer science section
Join our real-time social learning platform and learn together with your friends!