Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Working with classes

Reply
Thread Tools

Working with classes

 
 
laila@bneakiwa.nl
Guest
Posts: n/a
 
      12-03-2012
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_ba ck)
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







 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      12-04-2012
On Tue, Dec 4, 2012 at 9:47 AM, <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Classes within classes David ASP .Net 2 07-22-2005 07:13 PM
What is the difference between nested classes and inner classes ? Razvan Java 5 07-27-2004 07:59 PM
Modifiers applied to attributes, local variables, member functions, classes and inncer classes ! Razvan Java 11 07-17-2004 08:57 PM
Can I using reflection to get all child classes or classes undera package dynamically? Carfield Yim Java 1 05-31-2004 05:33 PM
How to access inner classes variables & methods from outer classes lonelyplanet999 Java 1 11-13-2003 01:54 PM



Advertisments