[Tutor] Re: Create list of IPs

2005-02-20 Thread Greg T


> I am wondering how I would go about making a list of
> IPs between two set 
> IPs.
> This is my initial code:
> 
> 
> 
> def list2str(list):
> ip=''
> for part in list:
> if len(ip)!=0:
> ip=ip+'.'+part
> else:
> ip=ip+part
> return ip
> 
> iplist = []
> 
> minip = ['1','0','0','1'] # starting IP
> maxip = ['1','0','15','16'] # ending IP
> 
> currentip = minip # set currentip to value of minip
> 
**snip**

> I'd appreciate any help.
> 
> Thanks,
> Ralf
> 

It looks like you need not concern yourself with
the ['1','0',...] part of your array(s).
Only to increment from '0','1' to '15','16'
Keeping with arrays, you could get last position
of the array and increment number until 16.
If last position > 15, stop incrementation and move to
next to last position in the array until it reaches 15
(also breaks to to adding 15 to each octet in the last
two array positions, one by one)


> 
> 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Learning python as a thing to do

2005-02-27 Thread Greg T
Hi,
I am a Rubyist, but I've decided to learn Python so
that when a conversation springs up about the merits
of the two languages amd how they compare, I will be
well informed. As it stands now, what you usually see
is people well versed in one or the other, making
generalizations when they dont really know the other
language.

At any rate, so far Python seems to be a very good
language. Not a great language, but still very good.

So far, some things I dont care for and have me
scratching my head:
immutable strings
no case statement
lack of internal iterators
The mixing of functions and methods

Some things that I like:
-list comprehensions
-the indentation scheme (I know alot of people dont
like
it at first experience, but I do)
-'one way to do it' philosophy (I dont have a problem
with 'more than one way to do it', but it makes a
language easier to learn with a 'one way' philosophy)

Question(s):
Are there any good books/documents that actually
examine the ruby way vs python way? (by someone that
knows both languages)

The other day I saw a post from a gentleman trying to
do a basic prompt and add type of calculator.
He wanted to assign the +, or * operator to a variable
to use, but I believe he was told you have to use the
literal +, or *.

Are these operators constanst in Python?
If so, is there not a way to send that constant to
act apon another variable or variables that refer to
numbers?

In ruby, you can rerence the * operator
operator = :*   
num1 = 4
num2 = 6
num1.send(operator,num2)
which returns 24

Have a nice day :-)




__ 
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] Re: design questions: pythonic appraoch to ostriches

2005-04-25 Thread Greg T
Greetings.
Any comments made by me will certainly not be the
'pythonic' way to do things, but I would like to
make a few comments on the subject, and possibly
weave in a few questions of my own.
(I took a brief detour into Common Lisp after joining
this list, not too long ago. Thanks Mr. Gauld.)

>This is an excellent observation and points to the
>real problem with 
>the
>original question.  The problem is that the base
class >has more 
>features
>than some of the classes that will be dervied from it
>which is usually
>just plain wrong.

I agree with that satement.
My understanding is to move from the highest level
of abstraction to the detailed, or idividually
specific.

>Think about it in the abstract.  The Bird class makes
>the statement: 
>all
>birds fly.  Then you want to turn around and define a
>Bird that 
>doesn't.
>Even doing

>def fly:
>   pass

>makes no sense since what you've really done is to
>re-defined what 
>'fly'
>means for this bird. 

Personally, I see nothing wrong with redefining a
method in a subclass. From my limited dealings with
multiple inheritance, it seems to me the less you have
to deal with it, the better off you are.
I think my general view would be to cut out any excess
complexity unless its absolutely necessary.
Ostiches did fly at one point in time, and I'm pretty
sure all birds did. (though I'd have to reseach that
to be sure)

What do you all think about dealing with 'all birds
fly, but not these' based on an attribute?
Mass, or weight might be one factor...
Ostiches are too large to fly. (at least with their
current wing size)

>Again in the abstract:  all >birds fly and for 
>some
>birds that will mean that they don't.

>The only sensible solution to this that will cause
the >least confusion
>from a maintenance stanpoint and allow for the
largest >possible reuse 
>is
>multiple inheritance for languages that support it.  

I disagree, but then I come from the ruby language
which has an interesting take on MI.
Attributes and methods without the full complexity
of MI.
(though I'm certainly not an expert in ruby)

>Jeff


>Behalf Of Alan Gauld
>Sent: Sunday, April 24, 2005 3:48 AM
>To: Brian van den Broek; Tutor
>Subject: Re: [Tutor] design questions: pythonic
>approach to ostriches


> I do remain a bit surprised that there seems to be
no >way to
>implement
> what I naively thought would be the obvious solution
-- to remove an 
> inherited method from the instance's dictionary.

>You can, as Kent said, override the method to do
>nothing. Some
>languages, like Eifell offer better support for that
>than others.

What would be the harm in having the fly() ethod in
ostrich perform a different action?
"Im flapping my wings to no avail, but I'm running
quite fast"

>But there is a danger in removing methods too. By
>doing so you break 
>one
>of the fundamental principles of inheritence: that
>everywhere that you
>use the superclass you can use the sub class.

>If you remove the fly() method from your subclass of
>birds code like
>this will break:

>birds = [ aSwallow, anOstrich, anEmu, anEagle]

>for bird in birds:
>   bird.fly()

Where I come from, it wold look in the super class
for the fly() method when it wasnt found in ostrich,
and then you would have an action that wasnt right.
Ostriches dont fly.

>Whereas if you simply make fly a null method you can
>still call it but
>nothing happens - a lot safer...

>But conceptually the problem (and it is common) is
>that bird has a
>fly() method when not all birds can fly - the object
>model is broken at
>a high level of abstraction.

What about subclassing bird with FlightlessBird?


As I learn more about the python way, I will be able
to
contribute something more usefull and intelligent.

I hope it was ok to post my general thoughts about it
here...

--Greg



>HTH,

>Alan G.

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor