Re: [Tutor] Introduction - log exercise

2009-11-17 Thread Nick Stinemates
> I will read lines from file, with the 'for loop', and then I will check them 
> for
> 'foo' matches with a 'while loop', if matches I (somehow) re-initialise the
> list, and if there is no matches for foo, I will append line to the list. 
> When I
> get to a blank line (end of block), write myList to an external file. And 
> start

Can you please explain what you mean by _re-initialize the list_ ?

> with another line.
> 
> I am stuck with defining 'blank line', I don't manage to get throught the 
> while
> loop, any hint here I will really appreciate it.
> I don't expect the solution, as I think this is a great exercise to get wet
> with python, but if anyone thinks that this is the wrong way of solving the
> problem, please let me know.
> 
> 

Can you explain why the following won't work?


#!/usr/bin/python
 
import sys
import gzip
# At the moment not bother with argument part as I am testing it with a
# testing log file
#fileIn = gzip.open(sys.argv[1])

fileIn = gzip.open('big_log_file.gz', 'r')
fileOut = open('outputFile', 'a')

for line in fileIn:
while line != 'blank_line':
if 'foo' not in line:
fileOut.write(line)
> 
> 
> Somehow rename outputFile with big_log_file.gz
> 
> fileIn.close()
> fileOut.close()
> 
> -
> 
> The log file will be fill with:
> 
> 
> Tue Nov 17 16:11:47 GMT 2009
>   bladi bladi bla
>   tarila ri la
>   patatin pataton
>   tatati tatata
> 
> Tue Nov 17 16:12:58 GMT 2009
>   bladi bladi bla
>   tarila ri la
>   patatin pataton
>   foo
>   tatati tatata
> 
> Tue Nov 17 16:13:42 GMT 2009
>   bladi bladi bla
>   tarila ri la
>   patatin pataton
>   tatati tatata
> 
> 
> etc, etc ,etc
> ..
> 
> Again, thank you.
> 
> -- 
> -
> Antonio de la Fuente Mart?nez
> E-mail: t...@muybien.org
> -
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python on Ubuntu 10.10?

2011-01-15 Thread Nick Stinemates
Python comes pre installed on Ubuntu, as most of the GUI is written in it.

Nick

On Friday, January 14, 2011, Joel Knoll  wrote:
>
>
>
>
>
> Hello,
>
> I am new to programming and to Python.  I've been using Python with IDLE on 
> Windows Vista for a few weeks now.
> (And I'm loving it!)  However, I'm thinking about switching to Ubuntu 10.10.  
> If I download Ubuntu, will I still be able to use the
> IDLE environment?  I am really quite fond of it (mostly because it's what I 
> know!).  To use Python in Ubuntu,
> will I have to do any additional downloading, or do Python and IDLE come 
> built in and ready to use?
>
> Thanks for your time,
>
> JC Knoll
>
>
>   
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OOP question

2011-01-18 Thread Nick Stinemates
Updated inline. Check the updated definiton of winAmount.

Nick

On Tue, Jan 18, 2011 at 9:25 AM, Ben Ganzfried wrote:

> Hey guys,
>
> I'm trying to get a version of Roulette working and I had a quick
> question.  Here is my code:
>
> class Outcome:
>
> def __init__(self, name, odds):
> self.name = name
> self.odds = odds
>
> def winAmount(self, amount):
> return self.odds*amount
>
> def __eq__(self, other):
> if (self == other):
> return True
> else:
> return False
>
> def __ne__(self, other):
> if (self != other):
> return True
> else:
> return False
>
> def __str__(self):
> return "%s (%d:1)" % ( self.name, self.odds )
>
> Now whenever I try to call the winAmount method, I get the following error:
> NameError: global name 'odds' is not defined
>
> I'm wondering the following: I had thought that by initializing "odds" in
> the first initialization method that "odds" should then be accessible to all
> the other methods in the class.  This does not seem to be the case.  So what
> is the ideal fix?  On the one hand I still need to initialize "odds",
> right?  But if "odds" is within the initialization method, how else can it
> be accessed by the other methods?
>
> Thanks so much!
>
> Ben
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OOP question

2011-01-19 Thread Nick Stinemates
If you want to test if one outcome is equal to another, you probably want to
know if

The name of the outcome is the same
The odds of the outcome is the same

So, you'd implement it like so

class Outcome:

   def __eq__(self, other):
   if self.name == other.name and self.odds == other.odds:
   return True
   return False


Make sense?

Nick

On Wed, Jan 19, 2011 at 9:07 AM, Ben Ganzfried wrote:

> yeah I was actually pretty confused about those methods as well.  I mean I
> get the general idea that we are testing to see if two outcomes are the same
> (hence a winning bet)...when you say expand on them, what do you mean
> exactly?
>
> Thanks again, really much appreciated!
>
>
> On Tue, Jan 18, 2011 at 4:31 PM, Nick Stinemates wrote:
>
>> You may also want to look in to the __eq__ and __ne__ methods. You're just
>> re-implementing standard behavior (so redefining them is useless.) You'll
>> probably want to expand on them to be more concise.
>>
>>
>> On Tue, Jan 18, 2011 at 10:00 AM, Ben Ganzfried 
>> wrote:
>>
>>> Thanks, Nick!
>>>
>>>
>>> On Tue, Jan 18, 2011 at 12:52 PM, Nick Stinemates >> > wrote:
>>>
>>>> Updated inline. Check the updated definiton of winAmount.
>>>>
>>>> Nick
>>>>
>>>> On Tue, Jan 18, 2011 at 9:25 AM, Ben Ganzfried >>> > wrote:
>>>>
>>>>> Hey guys,
>>>>>
>>>>> I'm trying to get a version of Roulette working and I had a quick
>>>>> question.  Here is my code:
>>>>>
>>>>> class Outcome:
>>>>>
>>>>> def __init__(self, name, odds):
>>>>> self.name = name
>>>>> self.odds = odds
>>>>>
>>>>> def winAmount(self, amount):
>>>>> return self.odds*amount
>>>>>
>>>>>
>>>>> def __eq__(self, other):
>>>>> if (self == other):
>>>>> return True
>>>>> else:
>>>>> return False
>>>>>
>>>>> def __ne__(self, other):
>>>>> if (self != other):
>>>>> return True
>>>>> else:
>>>>> return False
>>>>>
>>>>> def __str__(self):
>>>>> return "%s (%d:1)" % ( self.name, self.odds )
>>>>>
>>>>> Now whenever I try to call the winAmount method, I get the following
>>>>> error: NameError: global name 'odds' is not defined
>>>>>
>>>>> I'm wondering the following: I had thought that by initializing "odds"
>>>>> in the first initialization method that "odds" should then be accessible 
>>>>> to
>>>>> all the other methods in the class.  This does not seem to be the case.  
>>>>> So
>>>>> what is the ideal fix?  On the one hand I still need to initialize "odds",
>>>>> right?  But if "odds" is within the initialization method, how else can it
>>>>> be accessed by the other methods?
>>>>>
>>>>> Thanks so much!
>>>>>
>>>>> Ben
>>>>>
>>>>> ___
>>>>> Tutor maillist  -  Tutor@python.org
>>>>> To unsubscribe or change subscription options:
>>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>>
>>>>>
>>>>
>>>
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sound question

2011-04-08 Thread Nick Stinemates
On Fri, Apr 8, 2011 at 5:12 PM, Alan Gauld wrote:

>
> "Jan Erik Moström"  wrote
>
>  A couple of my students need to be able to play sounds, ...
>>
>>
>> I looked around and found several packages but they all
>> seem to have some kind platform restrictions.
>>
>
> Sound tends to be platform specific but pygame seems
> to have hidden most of that. Then again it may not offer
> all the facilities the dedicated packages do, and it may
> be a bit heavyweight for sound alone. But worth a look see.
>
> Personally I've only played with it on Windows but it
> claims to work across platforms...
>

Personally I've only played with it on Linux so it seems we have it covered
:)

Nick


>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor