Re: [Tutor] Objects Classes...

2005-01-18 Thread Max Noel
On Jan 18, 2005, at 03:46, Liam Clarke wrote:
Curious - what's mod_python?
	A Python module for the Apache web server, that among other things 
addresses the main shortcoming of CGI: mod_python (and mod_perl, 
mod_php and mod_ruby, for that matter) keeps the interpreter into 
memory (and as part of the server, so to speak). The server doesn't 
need to load and initialize a new interpreter each time a page is 
requested. This yields a tremendous speed increase (speaking in 
requests/second there, not in script execution time), and ensures that 
mod_python scales up *much* better than CGI.

http://www.modpython.org/
-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Objects Classes...

2005-01-17 Thread Jack Cruzan
Hello!

I am writing (or at least attempting) to write a Character generation
utility for Shadowrun in Python of course! After reading about other
attempts to make and RPG dealing with with character generation it looks
like OOP is the best way to go. I have no experiance with OOP and its
kinda throwing me for a loop.

Here is what I mean...

I make a class

class Character:
def __init__(self, name = ' ', race = 'Human', magic = 'None'):
self.name=name
self.race=race
self.magic=magic

Great, now I need some from the user to create the character. This is
what I have.

def createChar(book):
name = raw_input(Enter your character's name. )
race = int(raw_input(What race? (1: Human, 2: Elf, 3: Ork, 4: Troll,
5: Dwarf,)))
book[name] = race

What am I doing wrong? 

Oh and one other thing I can't load my data. I can create a new file,
but not load it. Here is the code for that...

def loadChar(book):
import os
filename = 'SRchargen.dat'
if os.path.exists(filename):
store = open(filename,'r')
while store:
name = store.readline().strip()
race = store.readline().strip()
book[name] = race
else:
store = open(filename, 'w')
store.close

Any help would be greatly appreciated!





___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Objects Classes...

2005-01-17 Thread Jack Cruzan
Ok, so each character has his name, race, his stats, his skills, and his
gear.

since the name and character is unique there is no need for a class
these things.

hmmm maybe I am conceptualizing this wrong.

would each new character then be a dictonary? Made up of different
elements or would the character be a list? Since each character is
basically just a list of stats... the stats get modified up and down by
race and certain gear... am I conceptulizing this correctly?

On Mon, 2005-01-17 at 10:59 -0800, Chad Crabtree wrote:
 Jack Cruzan wrote:
 
 class Character:
 
  def __init__(self, name = ' ', race = 'Human', magic = 'None'):
 
  self.name=name
 
  self.race=race
 
  self.magic=magic
   
 
 I know your going to need some other stuff.
 
 class NewCharacter(Character):
 def __init__(self,stats,*args,**kwds):
super(Character,self).__init__(*args,**kwds)
self.stats=stats
 
 super is a function that calls a specific function from a parent
 class.  
 This way you can still use the previous __init__ code and then extend
 
 it.  *args represents a tuple of arguments of unspecified length or 
 type, **kwds is a dictionary of named arguments, like name='' like 
 above.  That way you capture the keywords needed to pass to the
 parent 
 class so that name race magic is still updated at class
 instantiation.
 
 This way you can extend classes.  So you *could* subclass Character
 as a 
 Dwarf, a Troll etc so that each class already knows about being a
 Dwarf, 
 eg special abilities skill bonuses and such.  If you don't understand
 
 this, that's ok it took me quite a while.  However once I got this it
 
 made certain tasks much easier.  I could figure out how to do
 something, 
 then never need to think about how it works later in the project.
 
 def createChar(book):
 
  name = raw_input(Enter your character's name. )
 
  race = int(raw_input(What race? (1: Human, 2: Elf, 3: Ork, 4:
 Troll,
 
 5: Dwarf,)))
 
  book[name] = race
 
   
 
 try this (untested)
 
 races={1:'Human',2:'Elf',3:'Ork',4:'Troll',5:'Dwarf'} #this is a
 dictionary
 book[name]=races[race]
 print The Name is  + name
 print The Race is  + book[name]
 
 def loadChar(book):
 
  import os
 
  filename = 'SRchargen.dat'
 
  if os.path.exists(filename):
 
  store = open(filename,'r')
 
  while store:
 
  name = store.readline().strip()
 
  race = store.readline().strip()
 
  book[name] = race
 
  else:
 
  store = open(filename, 'w')
 
  store.close
   
 
 I'm not sure why this doesn't work, perhaps you should post what is
 in 
 'SRchargen.dat'.  You do know that this format will only work with
 one 
 character?  Do you get an error? If so post that traceback message.
 
 Anyway good luck.
 
 
   
 __ 
 Do you Yahoo!? 
 Yahoo! Mail - now with 250MB free storage. Learn more.
 http://info.mail.yahoo.com/mail_250

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Objects Classes...

2005-01-17 Thread jfouhy
On Mon, 2005-01-17 at 10:59 -0800, Chad Crabtree wrote:
 class NewCharacter(Character):
   def __init__(self,stats,*args,**kwds):
 super(Character,self).__init__(*args,**kwds)
 self.stats=stats
 
 super is a function that calls a specific function from a parent
 class. This way you can still use the previous __init__ code and then extend
 it. 

Is that the right idiom these days?

I would write:

def __init__(self, stats, *args, **kw):
Character.__init__(self, *args, **kw)
self.stats = stats

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Objects Classes...

2005-01-17 Thread Max Noel
On Jan 17, 2005, at 20:51, Jack Cruzan wrote:
Ok, so each character has his name, race, his stats, his skills, and 
his
gear.

since the name and character is unique there is no need for a class
these things.
hmmm maybe I am conceptualizing this wrong.
would each new character then be a dictonary? Made up of different
elements or would the character be a list? Since each character is
basically just a list of stats... the stats get modified up and down by
race and certain gear... am I conceptulizing this correctly?
	I've thought about it a few times. Actually, when I learn a language, 
I often try to design and implement a SR character generator. Then I 
give up because it's really complicated and I don't have time (other 
things to do using the aforementioned programming languages, mostly :D 
).
	I'm probably gonna end up making a web-based one at some point, using 
either mod_python or Ruby on Rails. Gah, so many things to do, and so 
little time...

	Anyway, my view of the problem was that at least the following should 
be classes:
- Character
- Attribute
- Skill (perhaps a subclass: Specialization?)
- Augmentation (with subclasses like Cyberware, Bioware, AdeptPower)
- GearItem

	Character would mostly be a container for the other classes, so most 
of its attributes would be dictionaries, like:

class Character:
	def __init__():
		self.attributes = {'Body': Attribute(), 'Quickness': Attribute(), 
'Strength': Attribute(), 'Charisma': Attribute(), 'Intelligence': 
Attribute(), 'Willpower': Attribute()}

	Ah, things would be so much easier if McMackie would release the NSRCG 
source code (despite this abomination being written in Visual Basic), 
wouldn't they? ;)

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Objects Classes...

2005-01-17 Thread Jack Cruzan
Wouldn't it though! I haven't checked but doesn't he use xml for his
equipment lists - if that was the case it would be worth it to ask him
for those files 'eh?

Thanx for the input by the way will have to let you know how this
goes...
   Ah, things would be so much easier if McMackie would release the NSRCG 
 source code (despite this abomination being written in Visual Basic), 
 wouldn't they? ;)
 
 -- Max
 maxnoel_fr at yahoo dot fr -- ICQ #85274019
 Look at you hacker... A pathetic creature of meat and bone, panting 
 and sweating as you run through my corridors... How can you challenge a 
 perfect, immortal machine?
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Objects Classes...

2005-01-17 Thread Liam Clarke
Curious - what's mod_python?


On Tue, 18 Jan 2005 03:10:44 +, Max Noel [EMAIL PROTECTED] wrote:
 
 On Jan 18, 2005, at 02:59, Jack Cruzan wrote:
 
  Wouldn't it though! I haven't checked but doesn't he use xml for his
  equipment lists - if that was the case it would be worth it to ask him
  for those files 'eh?
 
 Last time I checked, he didn't. I have the DAT files here (extracted
 them off a Windows installation of the program) and have been trying to
 write a Python script that would convert them to XML.
 However, the file format is exotic and inconsistent (just like VB,
 some would say ;) ), so I haven't found a way yet to write an
 universal converter: the script has to be modified for each file. I'm
 pleased neither with this solution, nor with the way my script looks:
 it's ugly.
 
 At some point, such a converter will have to be written, though,
 unless you want to go through the extreme pleasure of going through 1
 meg of text files by hand.
 
 Hmm, I really should try to start working again on this web-based SRCG
 idea of mine... The whole thing just screams database. Daaargh, so
 many things to do, so little time. I suppose no good mod_python
 tutorials have spawned since last time I asked, right?
 
 -- Max
 maxnoel_fr at yahoo dot fr -- ICQ #85274019
 Look at you hacker... A pathetic creature of meat and bone, panting
 and sweating as you run through my corridors... How can you challenge a
 perfect, immortal machine?
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor