Re: [Tutor] RE:

2005-01-17 Thread Danny Yoo


> >  >>> stuff = [[0,'sdfsd','wrtew'], [1, 'rht','erterg']]
> >  >>> stuff
> > [[0, 'sdfsd', 'wrtew'], [1, 'rht', 'erterg']]
> >  >>> print [stuff[i][0] for i in range(len(stuff))]
> > [0, 1]
> >
> > An alternative way to write this is:
> >
> > ###
> > print [row[0] for row in stuff]
> > ###
> >
> > which extracts the first element out of every "row" sublist in
> > 'stuff'.


> This is fine.  I just want to know if row is a reserve word? or is it a
> built in function in IDLE environment.  The word row is not highlighted.
> What data type is (row)?


Hello!

When we have 'stuff' like this:

###
>>> stuff = [[0,'sdfsd','wrtew'], [1, 'rht','erterg']]
###

then we can ask for an element out of 'stuff'.  One thing we can do is
variable assignment:

###
>>> row = stuff[0]
###

'row' here is just an arbitrarily chosen variable name.  We can see that
"row"'s value is one of the sublists in 'stuff' by trying:

###
>>> print row
[0, 'sdfsd', 'wrtew']
###


We can also use a 'for' loop to march --- to "iterate" --- across a list:

###
>>> for row in stuff:
... print row, "is another element in 'stuff'"
...
[0, 'sdfsd', 'wrtew'] is another element in 'stuff'
[1, 'rht', 'erterg'] is another element in 'stuff'
###

'row' here is also used as a temporary variable name.  In a 'for' loop, it
is assigned to each element, as we repeat the loop's body.


If you have more questions, please feel free to ask.

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


[Tutor] RE:

2005-01-17 Thread Gopinath V, ASDC Chennai
Title: RE: 





On Wed, 12 Jan 2005, Orri Ganel wrote:


>  >>> stuff = [[0,'sdfsd','wrtew'], [1, 'rht','erterg']]
>  >>> stuff
> [[0, 'sdfsd', 'wrtew'], [1, 'rht', 'erterg']]
>  >>> print [stuff[i][0] for i in range(len(stuff))]
> [0, 1]



Hi Orri,


An alternative way to write this is:


###
print [row[0] for row in stuff]
###


which extracts the first element out of every "row" sublist in 'stuff'.



Best of wishes!



   This is fine.i just want to know if row is a reserve word ?
or is it a built in function 
 in IDLe environment .. the word row is not highlighted ,what data type is (row) 



___
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


Re: [Tutor] need advice on streamlining code...

2005-01-17 Thread Liam Clarke
yeah, I wasn't sure about that readline/lines thing, cos I'm not sure
how popen works.


On Mon, 17 Jan 2005 21:38:37 -0500, Jacob S. <[EMAIL PROTECTED]> wrote:
> I seem to always be the one to suggest this, but --
> 
> "String methods are better than using the string module because the string
> module has been ?deprecated? or will be soon. I think that is the word here.
> So, do this instead."
> 
> insideipgrepfd = os.popen("grep ifconfig_fxp0 /etc/rc.conf")
> insideipgrep = insideipgrepfd.readline()  ## Says same thing below --
> readline() just reads first line
> insideipfield, insideip = insideipgrep[0].strip().split("=")
> insideipsplit = insideip.split()
> insideipquads = insideipsplit[1].split(".")
> insidemaskquads = insideipsplit[4].split(".")
> 
> And, heck, I know it wouldn't be that simple, but if the line stays the same
> but just the numbers change, you can do,
> 
> insideipgrepfd = os.popen("grep ifconfig_fxp0 /etc/rc.conf")
> insideipgrep = insideipgrepfd.readlines()  ##Wait, if you're just using the
> first line use insideipgrepfd.readline()
> insideipgrep = insideipgrep.lstrip("ifconfig_fxp0=\"inet ")
> temp = insideipgrep.split(" netmask ")
> insideipquads = temp[0].split(".")
> insideipmaskquads = temp[1].split(".")
> 
> Warning, code just above is not very stable --  if the text of the line
> changes in anyway it won't work.
> 
> HTH,
> Jacob Schmidt
> 
> > The following block of code works, and provides the necessary output I'm
> > looking for...but I have a feeling that it's working through sheer brute
> > force and could be better:
> >
> >insideipgrepfd = os.popen("grep ifconfig_fxp0 /etc/rc.conf")
> >insideipgrep = insideipgrepfd.readlines()
> >insideipfield, insideip = string.split(string.strip(insideipgrep[0]),
> > "=")
> >insideipsplit = string.split(insideip, " ")
> >insideipquads = string.split(insideipsplit[1], ".")
> >insidemaskquads = string.split(insideipsplit[4], ".")
> >
> > the line in /etc/rc.conf looks like:
> >
> > ifconfig_fxp0="inet 172.31.2.100 netmask 255.255.255.0"
> >
> > Any and all thoughts/pointers are appreciated.
> >
> >~elh
> >
> > --
> > Eric L. Howard   e l h @ o u t r e a c h n e t w o r k s . c o m
> > 
> > www.OutreachNetworks.com313.297.9900
> > 
> > JabberID: [EMAIL PROTECTED] Advocate of the Theocratic Rule
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
> 
> ___
> 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


Re: [Tutor] Objects & Classes...

2005-01-17 Thread Max Noel
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


Re: [Tutor] Walking a directory

2005-01-17 Thread Jacob S.
Kent's suggestions are always my favorites, along with others, 
c.   --nevermind
To get the full path in your list-- change Kent's to this

import os
filelist = []
for root,directories,filenames in os.walk("Aircraft"):
   for filename in filenames:
   if filename.endswith("-set.xml"):
   filelist.append(os.path.join(root,filename))
for x in filelist:
   print x
What I want to do is rather simple, but I cannot find any good
documentation for something like this.
The directory structure is sort of like this:
Aircraft
A-10
+A-10cl-set.xml
+A-10fg-set.xml
For example Aircraft/A-10/A-10cl-set.xml
Now I want to loop though each aircrafts folder (such as A-10) and
find each *-set.xml file, get the aircraft part (such as A-10cl) and
add it to a list.
While this does seem simple, how is the question.
I know about the walk function, but cannot find any good examples for it.
--

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

___
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] need advice on streamlining code...

2005-01-17 Thread Jacob S.
I seem to always be the one to suggest this, but --
"String methods are better than using the string module because the string 
module has been ?deprecated? or will be soon. I think that is the word here. 
So, do this instead."

insideipgrepfd = os.popen("grep ifconfig_fxp0 /etc/rc.conf")
insideipgrep = insideipgrepfd.readline()  ## Says same thing below --  
readline() just reads first line
insideipfield, insideip = insideipgrep[0].strip().split("=")
insideipsplit = insideip.split()
insideipquads = insideipsplit[1].split(".")
insidemaskquads = insideipsplit[4].split(".")

And, heck, I know it wouldn't be that simple, but if the line stays the same 
but just the numbers change, you can do,

insideipgrepfd = os.popen("grep ifconfig_fxp0 /etc/rc.conf")
insideipgrep = insideipgrepfd.readlines()  ##Wait, if you're just using the 
first line use insideipgrepfd.readline()
insideipgrep = insideipgrep.lstrip("ifconfig_fxp0=\"inet ")
temp = insideipgrep.split(" netmask ")
insideipquads = temp[0].split(".")
insideipmaskquads = temp[1].split(".")

Warning, code just above is not very stable --  if the text of the line 
changes in anyway it won't work.

HTH,
Jacob Schmidt
The following block of code works, and provides the necessary output I'm
looking for...but I have a feeling that it's working through sheer brute
force and could be better:
   insideipgrepfd = os.popen("grep ifconfig_fxp0 /etc/rc.conf")
   insideipgrep = insideipgrepfd.readlines()
   insideipfield, insideip = string.split(string.strip(insideipgrep[0]), 
"=")
   insideipsplit = string.split(insideip, " ")
   insideipquads = string.split(insideipsplit[1], ".")
   insidemaskquads = string.split(insideipsplit[4], ".")

the line in /etc/rc.conf looks like:
ifconfig_fxp0="inet 172.31.2.100 netmask 255.255.255.0"
Any and all thoughts/pointers are appreciated.
   ~elh
--
Eric L. Howard   e l h @ o u t r e a c h n e t w o r k s . c o m

www.OutreachNetworks.com313.297.9900

JabberID: [EMAIL PROTECTED] Advocate of the Theocratic Rule
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] COP vs OOP

2005-01-17 Thread Max Noel
On Jan 17, 2005, at 23:07, Bernard Lebel wrote:
Okay... so if I follow you, a class that has methods not part of 
itself, it's not a static class...? So should I understand that a 
class that gets inherited methods can be considered OOP?
	Not exactly. Basically, object-oriented programming is just that; that 
is, working with objects, which are instances of classes.
	Now, class methods/attributes, which I call "static" because that's 
the C++/Java keyword that triggers them, are methods and attributes 
that are shared by all the instances of that class, not specific to a 
particular instance. The class doesn't even have to be instanciated (no 
objects have to be created) for them to be used. They are effectively 
part of the class itself, hence the name, class methods (as opposed to 
instance methods).
	A common use for class attributes is to keep track of how many times 
the class has been instanciated (number of objects created).

	So, if my class only has static methods and attributes, any object I 
create with that class is empty: it has no attributes of its own, and 
is impossible to be interacted with. Thus, you could just as well say 
it doesn't exist, and that the class can't be used to create objects.
	Therefore, you're using a class to do procedural programming.

	However, the class has its separate namespace: when you're calling 
methods from that class from outside its body, the call syntax is 
Class.method(). Which is exactly the same thing as using a function 
from Python module.

I hope that answers your question...
-- 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] Posting a large amount of code?

2005-01-17 Thread Bill Burns
[Jacob]
> > Actually according to the above paragraph, he suggests putting them
>
> all in
>
> > a seperate class. So pseudo-code...
> >
> > class Pipe:
> > All things related to pipe program here.
> >
> > class GUI:
>

[Alan]
> Exactly so. The rationale for that was that you could work with
> a collection of pipes each with their own dimensions etc.
> I forgot to explain that part
>

Alan, Jacob,Orri, Liam,

Thank you for your help! I appreciate it!!

Alan, as you had suggested in an earlier post, I will put the pipe into a
class of it's own. Actually I think I will make the command line version of
the program. Once I have that working, then I can look at putting a GUI
front-end on it. Like you said, 'Separating the GUI code from the logical
functions is always a good idea'. I had just never considered doing it that
way, what can I say, I'm just learning :-) It now makes complete sense to
have the two separate. I like the idea of having a command line version and
as you said, it would be easier to port to different GUI's.

Thanks again,

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


Re: [Tutor] Objects, persistence & getting

2005-01-17 Thread Mike Hansen

Subject:
Re: [Tutor] Objects, persistence & getting
From:
"Alan Gauld" <[EMAIL PROTECTED]>
Date:
Mon, 17 Jan 2005 07:48:28 -
To:
"Liam Clarke" <[EMAIL PROTECTED]>, "Tutor Tutor" 
To:
"Liam Clarke" <[EMAIL PROTECTED]>, "Tutor Tutor" 

Well, one thing learning Java is good for is for thoroughly
demystifying OOP.
   


I'd have to disagree here because Java's version of OOP has
very little to do with real OOP. Java just uss classes as
a kind of modularisation mechanism and does not make much
use of tthe real OO features. In fact it doesn't even
support several of the things that enable real OO
programming.
And its class library, a strong feature because it is a
standard, is dreadful from an OOP p[erspective. In fact
I usually refer to Java as a Class Oriented Programming
rather than Object Oriented.
It is possible to use Java in an OOP way (read Brice Eckel's
"Thinking in Java" to see how) but the language itself
encourages a style of programming that is much more like
Pythons modules than true OOP.
 

It's not some magical acronym of programming
goodness, it's just an 'organic' way to organise code.
   

Certainly in Java thats true, and indeed even at the
higher level OOP is a way of organizing code - by
finding high level abstractions and building tree
structures based on common intefaces. But Java doesn't
encourage that structuring as much as Python does!

 

Alan G.
 

I've been reading The Object Oriented Thought Process, and it's been 
clearing up the OOP mystery for me. After reading a big chunk of it, I 
re-read the OOP sections in Learning Python. It's making a lot more 
sense now.

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


Re: [Tutor] COP vs OOP

2005-01-17 Thread Bernard Lebel
Max Noel wrote:
   if you're only using static (class) methods, then your class
can't/needn't be instanciated, and then is nothing more than the 
equivalent of a Python module. I think that's what Alan means by 
class-oriented programming.

Okay... so if I follow you, a class that has methods not part of itself, 
it's not a static class...? So should I understand that a class that 
gets inherited methods can be considered OOP?

Thanks for answering my questions!
Bernard
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] COP vs OOP (was: Objects, persistence & getting)

2005-01-17 Thread Max Noel
On Jan 17, 2005, at 22:41, Bernard Lebel wrote:
Alan Gauld wrote:
 In fact
I usually refer to Java as a Class Oriented Programming
rather than Object Oriented.

If you allow me a question
What is the fundamental difference between the two? To me this is not 
clear. I thought that a class was basically a programming object with 
properties and methods, but I never thought a class could not be an 
object.
	if you're only using static (class) methods, then your class 
can't/needn't be instanciated, and then is nothing more than the 
equivalent of a Python module. I think that's what Alan means by 
class-oriented programming.

	However, all the Java programming I've done so far has been true OOP 
(hopefully; it was for a Uni module called Object-Oriented Software 
Engineering), and I fail to see what in its design does not encourage 
this practice.

-- 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 Max Noel
On Jan 17, 2005, at 22:02, Chad Crabtree wrote:
(why would an attri bute need to be a separate class?)
	So that the points or Karma (depending on the generation system) cost 
of the Attribute can be calculated without having to resort to 
procedural programming.

	You'd be then able to get the Karma cost of all the attributes by 
using a line such as:

return sum([att.getKarmaCost() for att in attributes])
	The following is a preliminary Attribute class I dug up from my hard 
drive, made for the BeCKS creation system. Feel free to use bits of 
it...


#!/usr/bin/env python
class Attribute:
"""Shadowrun character attribute."""
def __init__(self, baseRating = 1, racialMod = 0, augCyber = 0, 
augMagic = 0):
"""Create an Attribute."""

# Initialize the class attributes...
self._baseRating = 1
self._racialMod = 0
self._augCyber = 0
self._augMagic = 0
self.setBaseRating(baseRating)
self.setRacialMod(racialMod)
self.setAugCyber(augCyber)
self.setAugMagic(augMagic)
def getRating(self):
"""Return the attribute's modified Rating."""
return self._baseRating + self._augCyber + self._augMagic
def getBaseRating(self):
"""Return the attribute's base Rating (unmodified by magic or 
cyber)."""
return self._baseRating

def setBaseRating(self, baseRating):
"""Set the attribute's base Rating. baseRating must be an int 
equal to or greater than max(1, 1 + racial mod)."""
if type(baseRating) != int:
raise TypeError, "Attribute rating must be an int."
if baseRating < 1:
# Attribute rating can't be lower than 1.
baseRating = 1
if baseRating < 1 + self._racialMod:
# Attribute rating can't be lower than 1 + racial mod.
baseRating = 1 + self._racialMod
self._baseRating = baseRating

def getRacialMod(self):
return self._racialMod
def setRacialMod(self, racialMod = 0):
"""Set the racial modifier for the attribute. racialMod must be 
an int."""
if type(racialMod) != int:
raise TypeError, "Racial modifier must be an int."
self._racialMod = racialMod
# Re-set the base Rating to enforce the racial limits
self.setBaseRating(self._baseRating)

def getAugCyber(self):
return self._augCyber
def setAugCyber(self, augCyber):
"""Set the cyber augmentation(s) for the Attribute. augCyber 
must be an int."""
if type(augCyber) != int:
raise TypeError, "Cyber augmentation must be an int."
self._augCyber = augCyber

def getAugMagic(self):
return self._augMagic
def setAugMagic(self, augMagic):
"""Set the magic augmentation(s) for the Attribute. augMagic 
must be an int."""
if type(augMagic) != int:
raise TypeError, "Magic augmentation must be an int."
self._augMagic = augMagic

def getKarmaCost(self):
"""Return the BeCKS Karma cost of the Attribute."""
rating = self.getBaseRating()
racialMod = self.getRacialMod()
minr = max(1, 1 + racialMod)
maxr = 6 + racialMod
if rating <= maxr:
# Could (will) be optimized for speed, but the formula is 
much clearer this way
cost = sum([2*i for i in range(minr + 1, rating + 1)])
else:
cost = sum([2*i for i in range(minr + 1, maxr + 1)]) + 
sum([3*i for i in range(maxr + 1, rating + 1)])
return cost


if __name__ == '__main__':
# Run a simple test procedure
atr = Attribute()
print atr.getRating()
atr.setRacialMod(1)
print atr.getRating()
atr.setAugCyber(1)
atr.setAugMagic(1)
atr.setBaseRating(3)
print atr.getBaseRating(), atr.getRating()
print 'Karma total cost', atr.getKarmaCost()
del atr

-- 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] COP vs OOP (was: Objects, persistence & getting)

2005-01-17 Thread Bernard Lebel
Alan Gauld wrote:
 In fact
I usually refer to Java as a Class Oriented Programming
rather than Object Oriented.

If you allow me a question
What is the fundamental difference between the two? To me this is not 
clear. I thought that a class was basically a programming object with 
properties and methods, but I never thought a class could not be an object.

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


[Tutor] Getting access to the speakers

2005-01-17 Thread Orri Ganel
Hello all,
I've googled the topic a bit, and can't seem to find any relevant 
information.  Does anyone know how to gain access to the speakers and, 
for example, tell when they are playing a sound and when they are not? I 
would think it's something with sockets, but I don't know how to go 
about it. Any help would be appreciated.

Thanks in advance,
Orri
--
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Objects & Classes...

2005-01-17 Thread Chad Crabtree
I was thinking (it's been a while since I played)  that I would do it

like this.  (strawman code)

class Character:
def  __init__(self,name,attribs,skills,cyberware):
   ...initialize..
and code to check attrib and skill mins and maxes
physical and menatl attributes should be part of the character
(why would an attri bute need to be a separate class?)
def addCyberware(self...):
def removeCyberware(...):
etc et al.
class Troll(Character):
update min max code in class for each race
class Skill:
def __init__(self, stuff):
   perhaps have a subclass for each skill?
   in addition the class would be responsible for it's
presentation
class Cyberware:
set attributes skill atribute mods and sanity or what ever thne
subclass for each item.  Also taking care of presentation
class Spell:
just like cyberware but perhaps one level further abstraction

class Augment(Spell):
class Damage(Spell):
class Curse(Spell):
 
I guess the question is should the character class be a *is a* or
*has 
a* relationship with Race.  Perhaps they could be mixins.

For persistence the only reasonable solution would be an object 
persistence scheme of some sort.  Then throw in a Top Down RPG Engine

and life is good.

   

Max Noel wrote:

>
> 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?"
>
>
>




__ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. 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 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] need advice on streamlining code...

2005-01-17 Thread Liam Clarke
Well, if you're looking to extract the IP & mask you could use a
regEx. They're not to bad

If it's only that line that you're extracting, and it's format doesn't change 

import re
pattern='ifconfig_fxp0="inet (?P*.?) netmask (?P*.?)"
reObj=re.compile(pattern, IGNORECASE)

jay = os.popen("grep ifconfig_fxp0 /etc/rc.conf").readlines()

matches=reObj.search(jay[0])

ip = matches.group('ip')
netmask =matches.group('mask') #You can then do your string splits,
whatever now.

HTH

Liam Clarke

regExs, can be your friends. If you KISS.

On Mon, 17 Jan 2005 11:05:59 -0800 (PST), Chad Crabtree
<[EMAIL PROTECTED]> wrote:
> I can't really think of a more elegant solution than what you have,
> maybe regex's but I hate those.  You *can* reduce the number of lines
> by
> two, and there was a variable you never used.
> HTH
> Eric L. Howard wrote:
> 
> >The following block of code works, and provides the necessary output
> I'm
> >looking for...but I have a feeling that it's working through sheer
> brute
> >force and could be better:
> >
> >insideipgrepfd = os.popen("grep ifconfig_fxp0 /etc/rc.conf")
> >insideipgrep = insideipgrepfd.readlines()
> >
> >
> insideipgrep=os.popen("grep ifconfig_fxp0 /etc/rc.conf").readlines()
> 
> >insideipfield, insideip =
> string.split(string.strip(insideipgrep[0]), "=")
> >
> >
> insideip = string.split(string.strip(insideipgrep[0]), "=")[1]
> 
> >insideipsplit = string.split(insideip, " ")
> >insideipquads = string.split(insideipsplit[1], ".")
> >insidemaskquads = string.split(insideipsplit[4], ".")
> >
> >
> insideipquads=string.split(string.split(insideip, " ")[1],".")
> insidemaskquads = string.split(string.split(insideip, " ")[4], ".")
> 
> >the line in /etc/rc.conf looks like:
> >
> >ifconfig_fxp0="inet 172.31.2.100 netmask 255.255.255.0"
> >
> >Any and all thoughts/pointers are appreciated.
> >
> >~elh
> >
> >
> >
> 
> 
> __
> Do you Yahoo!?
> Meet the all-new My Yahoo! - Try it today!
> http://my.yahoo.com 
> 
> 
> ___
> 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


Re: [Tutor] py2exe

2005-01-17 Thread jfouhy
Quoting Guillermo Fernandez Castellanos <[EMAIL PROTECTED]>:

> but when I try to package it with py2exe, I obtain the following
> result: The following modules appear to be missing
> ['mx']

I've got a program that uses mx.texttools..  Whenever I freeze it (with py2exe),
I get a list of about three modules that it can't find.  Nevertheless, the
frozen executable works fine :-)

> And when i run it, it crashes with this error message:
> Traceback (most recent call last):
>  File "openwar.py", line 41, in ?
>  File "Tix.pyc", line 210, in __init__
> _tkinter.TclError: can't find package Tix

When I tried, I couldn't figure out how to freeze Tix.  I ended up giving up and
recoding all my Tix stuff to use Pmw instead...
(although I was a lot more new to python in those days)

(and the fact that Pmw has actual documentation is an added bonus over Tix :-) )

-- 
John.
___
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 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] Walking a directory

2005-01-17 Thread Kent Johnson
Something like this (not tested!):
import os
for dirpath, dirnames, filenames in os.walk('Aircraft'):
for filename in filenames:
if filename.endswith('-set.xml'):
print filename[:-8]
This is probably a good time to mention Jason Orendorff's wonderful path module, which makes this 
even simpler:

import path
for filepath in path.path('Aircraft').walkfiles(pattern='*-set.xml'):
print filepath.name[:-8]
http://www.jorendorff.com/articles/python/path/
(though the server seems to be down at the moment...)
Kent
Arthur Wiebe wrote:
What I want to do is rather simple, but I cannot find any good
documentation for something like this.
The directory structure is sort of like this:
Aircraft
A-10
+A-10cl-set.xml
+A-10fg-set.xml
For example Aircraft/A-10/A-10cl-set.xml
Now I want to loop though each aircrafts folder (such as A-10) and
find each *-set.xml file, get the aircraft part (such as A-10cl) and
add it to a list.
While this does seem simple, how is the question.
I know about the walk function, but cannot find any good examples for it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Objects, persistence & getting

2005-01-17 Thread Liam Clarke
Law of Demeter?

And, OK I'll just pass references, it was a passing idle thought.
But thanks : )

What kind of languages espouse real OOP? Smalltalk gets mentioned a lot. Ruby?

Regards,

Liam Clarke

On Mon, 17 Jan 2005 07:48:28 -, Alan Gauld <[EMAIL PROTECTED]> wrote:
> > Well, one thing learning Java is good for is for thoroughly
> > demystifying OOP.
> 
> 
> I'd have to disagree here because Java's version of OOP has
> very little to do with real OOP. Java just uss classes as
> a kind of modularisation mechanism and does not make much
> use of tthe real OO features. In fact it doesn't even
> support several of the things that enable real OO
> programming.
> 
> And its class library, a strong feature because it is a
> standard, is dreadful from an OOP p[erspective. In fact
> I usually refer to Java as a Class Oriented Programming
> rather than Object Oriented.
> 
> It is possible to use Java in an OOP way (read Brice Eckel's
> "Thinking in Java" to see how) but the language itself
> encourages a style of programming that is much more like
> Pythons modules than true OOP.
> 
> > It's not some magical acronym of programming
> > goodness, it's just an 'organic' way to organise code.
> 
> Certainly in Java thats true, and indeed even at the
> higher level OOP is a way of organizing code - by
> finding high level abstractions and building tree
> structures based on common intefaces. But Java doesn't
> encourage that structuring as much as Python does!
> 
> 
> > If I understand correctly, once an object is created, as long as
> > references to it exist, it isn't garbage collected.
> 
> Yes.
> 
> > Does that make sense? So, foo is floating around in the namespace,
> and
> > bar just wants to grab a field of foo. Can it?
> 
> It shouldn't - it should be sending a message. One of
> the bad things about Java is it encourages the use
> of getXXX and setXXX style methods which are a total
> anathema to real OOP. They break the Law of Demeter.
> 
> Alan G.
> 
> 


-- 
'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


[Tutor] Walking a directory

2005-01-17 Thread Arthur Wiebe
What I want to do is rather simple, but I cannot find any good
documentation for something like this.

The directory structure is sort of like this:
>Aircraft
>>A-10
+A-10cl-set.xml
+A-10fg-set.xml

For example Aircraft/A-10/A-10cl-set.xml

Now I want to loop though each aircrafts folder (such as A-10) and
find each *-set.xml file, get the aircraft part (such as A-10cl) and
add it to a list.

While this does seem simple, how is the question.

I know about the walk function, but cannot find any good examples for it.
-- 

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


Re: [Tutor] need advice on streamlining code...

2005-01-17 Thread Chad Crabtree
I can't really think of a more elegant solution than what you have, 
maybe regex's but I hate those.  You *can* reduce the number of lines
by 
two, and there was a variable you never used.
HTH
Eric L. Howard wrote:

>The following block of code works, and provides the necessary output
I'm
>looking for...but I have a feeling that it's working through sheer
brute
>force and could be better:
>
>insideipgrepfd = os.popen("grep ifconfig_fxp0 /etc/rc.conf")
>insideipgrep = insideipgrepfd.readlines()
>  
>
insideipgrep=os.popen("grep ifconfig_fxp0 /etc/rc.conf").readlines()

>insideipfield, insideip =
string.split(string.strip(insideipgrep[0]), "=")
>  
>
insideip = string.split(string.strip(insideipgrep[0]), "=")[1]

>insideipsplit = string.split(insideip, " ")
>insideipquads = string.split(insideipsplit[1], ".")
>insidemaskquads = string.split(insideipsplit[4], ".")
>  
>
insideipquads=string.split(string.split(insideip, " ")[1],".")
insidemaskquads = string.split(string.split(insideip, " ")[4], ".")

>the line in /etc/rc.conf looks like:
>
>ifconfig_fxp0="inet 172.31.2.100 netmask 255.255.255.0"
>
>Any and all thoughts/pointers are appreciated.
>
>~elh
>
>  
>




__ 
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 
 

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


Re: [Tutor] Objects & Classes...

2005-01-17 Thread Chad Crabtree
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


[Tutor] need advice on streamlining code...

2005-01-17 Thread Eric L. Howard
The following block of code works, and provides the necessary output I'm
looking for...but I have a feeling that it's working through sheer brute
force and could be better:

insideipgrepfd = os.popen("grep ifconfig_fxp0 /etc/rc.conf")
insideipgrep = insideipgrepfd.readlines()
insideipfield, insideip = string.split(string.strip(insideipgrep[0]), "=")
insideipsplit = string.split(insideip, " ")
insideipquads = string.split(insideipsplit[1], ".")
insidemaskquads = string.split(insideipsplit[4], ".")

the line in /etc/rc.conf looks like:

ifconfig_fxp0="inet 172.31.2.100 netmask 255.255.255.0"

Any and all thoughts/pointers are appreciated.

~elh

-- 
Eric L. Howard   e l h @ o u t r e a c h n e t w o r k s . c o m

www.OutreachNetworks.com313.297.9900

JabberID: [EMAIL PROTECTED] Advocate of the Theocratic Rule
___
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] py2exe

2005-01-17 Thread Chad Crabtree
Right what he said.  I'm sorry I didn't make that clear.  This way 
py2exe can look and see import Tix and see it's needed.  Py2exe does
not 
ship the whole python distribution, rather only what is needed. 
Indeed 
it tends to ship many things that are not needed but it's better than

the whole distribution, especially if you are using several libraries

and such.



__ 
Do you Yahoo!? 
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter Radiobutton

2005-01-17 Thread Kent Johnson
Is this code running in a larger program that has a window? You are only supposed to have one root 
window (Tk()) in a program, maybe that is the problem.

Kent
Ismael Garrido wrote:
Ismael Garrido wrote:
Hello.
I can't figure out what's wrong in here! For some reason I can't 
understand, the radiobuttons don't work. The code itself is correct, 
the problem arises when I tell them that their master is 
self.configurar. I don't know why, but they don't like it.

After changing this:
   def _configurar(self):
   self.configurar = Tk() 

To this: self.configurar= Toplevel(self.root)
Works
I don't understand why it didn't work the other way around. Is it some 
kind of bug or strange 'feature'? Or was I making a silly mistake?

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