Working with classes

Discussion in 'Python' started by laila@bneakiwa.nl, Dec 3, 2012.

  1. Guest

    Hello, I've been working on this program for a long time but can't seem to get it to work.. The first array is the input file, then a class, another class and the actual program. Could anyone see what is wrong? I'm sorry if the program doesn't make any sense at all I'm just starting to learn this..

    The exercise wants us to do the following:
    5,4 4,5 8,7
    Add behind 6,3 3,2 9,6 4,3
    Add in front 7,6
    Add behind 9,8
    Add in front 5,5 7,8 6,5 6,4
    These are coordinates in the form(x,y) and the x coordinates need to be raised by 1.

    pirateinvoer:
    5,4 4,5 8,7=6,3 3,2 9,6 4,3=7,6=9,8=5,5 7,8 6,5 6,4




    '''
    Created on 2 dec. 2012

    @author: Laila
    '''
    class CoordinateRow():
    def __init__(self) :
    self.coordinate_row = []

    def row_even(self,EVEN, rows):
    self.row_even=[rows[row] for row in EVEN]
    return self.row_even

    def row_odd(self,ONEVEN,rows):
    self.row_odd=[rows[row] for row in ONEVEN]
    return self.row_odd

    def rows_front(self,index, row_front):
    self.new_row_front=self.row_even.insert(index,row_front)
    return self.new_row_front

    def rows_back(self,index, row_back):
    self.new_row_back=self.row_odd.append(index,row_back)
    return self.new_row_back



    class Coordinaat:
    def __init__(self,x,y):
    self.x = x
    self.y = y



    def correct_coordinates(self, OPHOGING_X, OPHOGING_Y):
    self.x=self.x + OPHOGING_X
    self.y=self.y + OPHOGING_Y
    return self.y
    return self.x


    from coordinaat import Coordinaat
    from coordinate_row import CoordinateRow

    file_input=file('pirateinvoer','r')
    all_coordinates=file_input.read()
    EVEN=range(0,4,2)
    ONEVEN=range(1,5,2)
    OPHOGING_X=1
    OPHOGING_Y=0

    def make_coordinate_row(all_coordinate_rows):
    for coordinate_rows in all_coordinate_rows:
    coordinate_rows=coordinate_rows.split()

    make_x_y(coordinate_rows)

    def make_x_y(coordinate_rows):
    for coordinate_row in coordinate_rows:
    x_y=coordinate_row.split(',')
    return Coordinaat (x_y[0],x_y[1])

    def make_route(coordinate_rows):
    result=[]
    new_row=row.coordinate_rows.row_even(EVEN, coordinate_rows)
    result+=new_row

    new_row=row.coordinate_rows.row_oneven(ONEVEN, coordinate_rows)
    result+=new_row

    print result

    all_coordinate_rows = all_coordinates.strip().split('=')
    make_coordinate_row(all_coordinate_rows)
    for coordinates in all_coordinate_rows:
    row = CoordinateRow()
    print row
     
    , Dec 3, 2012
    #1
    1. Advertising

  2. On Tue, Dec 4, 2012 at 9:47 AM, <> wrote:
    > Hello, I've been working on this program for a long time but can't seem to get it to work.. The first array is the input file, then a class, anotherclass and the actual program. Could anyone see what is wrong? I'm sorry ifthe program doesn't make any sense at all I'm just starting to learn this...
    >
    > The exercise wants us to do the following:


    Hi! Thanks for being up-front about it being homework :)

    In what way does your code not work? Is it giving an exception? Paste
    the exception and traceback to us - it'll be a lot easier to see
    what's going on.

    > file_input=file('pirateinvoer','r')
    > all_coordinates=file_input.read()


    No idea if it's your issue or not, but this is an unusual way to read
    files. Normally you'll want to use the open() function, and probably
    use 'with' to ensure it's closed promptly.

    Note that Python is not Java. You don't have to put one class in one
    file. Instead of importing classes from other files, just have them
    all in your main file - it makes a lot more sense, usually. In Python,
    a file usually is a module, on par with the modules in the standard
    library. It can contain lots of (related) classes and functions.

    ChrisA
     
    Chris Angelico, Dec 4, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David

    Classes within classes

    David, Jul 21, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,952
    David
    Jul 22, 2005
  2. lonelyplanet999
    Replies:
    1
    Views:
    2,226
    VisionSet
    Nov 13, 2003
  3. Carfield Yim
    Replies:
    1
    Views:
    1,438
    Andrew Thompson
    May 31, 2004
  4. Razvan
    Replies:
    11
    Views:
    921
    Andrew Thompson
    Jul 17, 2004
  5. Razvan
    Replies:
    5
    Views:
    11,310
    Dale King
    Jul 27, 2004
Loading...

Share This Page