[Tutor] Using python's smtp server

2013-12-13 Thread Vincent Davis
I have an app that generates a file one a day and would like to email it
using python's SMTP server.
http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
The documentation is kinda sparse and I cant seem to find any good examples.

Basically what I want to do; when my app runs it would initiate a SMTP
server, send the attachment and shutdown the SMTP after.

Vincent Davis
720-301-3003
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using python's smtp server

2013-12-13 Thread Vincent Davis
Mark,
Thanks mark, It had been about 15hr since I posted to
python-list@python.organd had not seen a response so I thought I would
try
tutor.python.org.
Well I got a response now, not that it helped, but I respond on that list.
Thanks again.

Vincent Davis
720-301-3003


On Fri, Dec 13, 2013 at 10:07 AM, Mark Lawrence breamore...@yahoo.co.ukwrote:

 On 13/12/2013 16:48, Vincent Davis wrote:

 I have an app that generates a file one a day and would like to email it
 using python's SMTP server.
 http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
 The documentation is kinda sparse and I cant seem to find any good
 examples.

 Basically what I want to do; when my app runs it would initiate a SMTP
 server, send the attachment and shutdown the SMTP after.

 Vincent Davis
 720-301-3003


 Please refer to the answer you've already received on the main Python
 mailing list.

 --
 My fellow Pythonistas, ask not what our language can do for you, ask what
 you can do for our language.

 Mark Lawrence

 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] parse text file

2010-06-03 Thread Vincent Davis
On Thu, Jun 3, 2010 at 1:02 PM, Colin Talbert talbe...@usgs.gov wrote:


 Dave,
 I think you are probably right about using decompressor.  I
 couldn't find any example of it in use and wasn't having any luck getting it
 to work based on the documentation.  Maybe I should try harder on this
 front.


Is it possible write a python script to transfer this to a hdf5 file?  Would
this help?
Thanks
Vincent


 Colin Talbert
 GIS Specialist
 US Geological Survey - Fort Collins Science Center
 2150 Centre Ave. Bldg. C
 Fort Collins, CO 80526

 (970) 226-9425
 talbe...@usgs.gov



  From: Dave Angel da...@ieee.org To:
 Colin Talbert talbe...@usgs.gov
 Cc: Steven D'Aprano st...@pearwood.info, tutor@python.org Date: 06/03/2010
 12:36 PM Subject: Re: [Tutor] parse text file
 --



 Colin Talbert wrote:
  snip
  You are so correct.  I'd been trying numerous things to read in this file

  and had deleted the code that I meant to put here and so wrote this from
  memory incorrectly.  The code that I wrote should have been:
 
  import bz2
  input_file = bz2.BZ2File(r'C:\temp\planet-latest.osm.bz2','rb')
  str=input_file.read()
  len(str)
 
  Which indeed does return only 90.
 
  Which is also the number returned when you sum the length of all the
 lines
  returned in a for line in file with:
 
 
  import bz2
  input_file = bz2.BZ2File(r'C:\temp\planet-latest.osm.bz2','rb')
  lengthz = 0
  for uline in input_file:
  lengthz = lengthz + len(uline)
 
  print lengthz
 
  snip
 
 
 Seems to me for such a large file you'd have to use
 bz2.BZ2Decompressor.  I have no experience with it, but its purpose is
 for sequential decompression -- decompression where not all the data is
 simultaneously available in memory.

 DaveA




 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2010-05-11 Thread Vincent Davis
probably need to do something like
python C:\py3eg\quadratic.py

your cmd prompt/shell should know python is a command


On Tue, May 11, 2010 at 2:43 AM, Sivapathasuntha Aruliah 
sivapathasuntha.arul...@amkor.com wrote:


 Hi
 I am learning Python. When I tried to run any of the program for example
 csv2html1_ans.py it displays the following message. This error is coming on
 both Python24  Python 31. That is whether i give the any one of the
 following command

 *COMMAND GIVEN*
 1.C:\python24\python.exe C:\py3eg\quadratic.py
 2.C:\python31\python.exe C:\py3eg\quadratic.py

 A message below appears with the program name. Please advice me how to get
 over from this issue
 *ERROR MESSAGE*
 command  C:\py3eg\csv2html1_ans.py is not a valid Win32 application

 Regards,
 Siva
 Test Equipment Engineering
 Amkor Technology (S) Pte Ltd
 1 Kaki Bukit View
 #03-28 TechView Building
 Singapore 415941
 Tel: (65) 6347 1131
 Fax: (65) 6746 4815
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Unittest ...

2010-05-06 Thread Vincent Davis
I can't think of a way to do what you ask, without defining a test for each.
ButI think what you might actually want is the define the error message to
report which one failed. ie, it's one test with a meaningful error message.
'Failed to load' + str(file)+' '+ str(k)+', '+str(v)
I am not ecpert on unittests

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis

On Wed, May 5, 2010 at 6:37 PM, Damon Timm damont...@gmail.com wrote:

 Hi - am trying to write some unit tests for my little python project -
 I had been hard coding them when necessary here or there but I figured
 it was time to try and learn how to do it properly.

 I've read over Python's guide
 (http://docs.python.org/library/unittest.html) but I am having a hard
 time understanding how I can apply it *properly* to my first test case
 ...

 What I am trying to do is straightforward, I am just not sure how to
 populate the tests easily.  Here is what I want to accomplish:

 # code
 import unittest
 from mlc.filetypes import * # the module I am testing

 # here are the *correct* key, value pairs I am testing against
 TAG_VALUES = (
('title', 'Christmas Waltz'),
('artist', 'Damon Timm'),
('album', 'Homemade'),
 )

 # list of different file types that I want to test my tag grabbing
 capabilities
 # the tags inside these files are set to match my TAG_VALUES
 # I want to make sure my code is extracting them correctly
 FILES = (
FLACFile('data/lossless/01 - Christmas Waltz.flac'),
MP3File('data/lossy/04 - Christmas Waltz (MP3-79).mp3'),
OGGFile('data/lossy/01 - Christmas Waltz (OGG-77).ogg'),
MP4File('data/lossy/06 - Christmas Waltz (M4A-64).m4a'),
 )

 class TestFiles(unittest.TestCase):

# this is the basic test
def test_values(self):
'''see if values from my object match what they should match'''
for file in FILES:
for k, v in TAG_VALUES:
self.assertEqual(self.file.tags[k], v)

 This test works, however, it only runs as *one* test (which either
 fails or passes) and I want it to run as 12 different tests (three for
 each file type) and be able to see which key is failing for which file
 type.  I know I could write them all out individually but that seems
 unnecessary.

 I suspect my answer lies in the Suites but I can't wrap my head around it.

 Thanks!

 Damon
 ___
 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] Newbie Unittest ...

2010-05-06 Thread Vincent Davis
By they way you shouldn't need to use str(file) as I did. Unlessit is
not a string already. Bad habit. I am used to numbers
vincet

On Thursday, May 6, 2010, Vincent Davis vinc...@vincentdavis.net wrote:
 I can't think of a way to do what you ask, without defining a test for each. 
 ButI think what you might actually want is the define the error message to 
 report which one failed. ie, it's one test with a meaningful error message.
 'Failed to load' + str(file)+' '+ str(k)+', '+str(v)I am not ecpert on 
 unittests





   Vincent Davis
 720-301-3003

 vinc...@vincentdavis.net

   my blog http://vincentdavis.net |
   LinkedIn http://www.linkedin.com/in/vincentdavis
 On Wed, May 5, 2010 at 6:37 PM, Damon Timm damont...@gmail.com wrote:
 Hi - am trying to write some unit tests for my little python project -
 I had been hard coding them when necessary here or there but I figured
 it was time to try and learn how to do it properly.

 I've read over Python's guide
 (http://docs.python.org/library/unittest.html) but I am having a hard
 time understanding how I can apply it *properly* to my first test case
 ...

 What I am trying to do is straightforward, I am just not sure how to
 populate the tests easily.  Here is what I want to accomplish:

 # code
 import unittest
 from mlc.filetypes import * # the module I am testing

 # here are the *correct* key, value pairs I am testing against
 TAG_VALUES = (
     ('title', 'Christmas Waltz'),
     ('artist', 'Damon Timm'),
     ('album', 'Homemade'),
 )

 # list of different file types that I want to test my tag grabbing 
 capabilities
 # the tags inside these files are set to match my TAG_VALUES
 # I want to make sure my code is extracting them correctly
 FILES = (
     FLACFile('data/lossless/01 - Christmas Waltz.flac'),
     MP3File('data/lossy/04 - Christmas Waltz (MP3-79).mp3'),
     OGGFile('data/lossy/01 - Christmas Waltz (OGG-77).ogg'),
     MP4File('data/lossy/06 - Christmas Waltz (M4A-64).m4a'),
 )

 class TestFiles(unittest.TestCase):

     # this is the basic test
     def test_values(self):
         '''see if values from my object match what they should match'''
         for file in FILES:
             for k, v in TAG_VALUES:
                 self.assertEqual(self.file.tags[k], v)

 This test works, however, it only runs as *one* test (which either
 fails or passes) and I want it to run as 12 different tests (three for
 each file type) and be able to see which key is failing for which file
 type.  I know I could write them all out individually but that seems
 unnecessary.

 I suspect my answer lies in the Suites but I can't wrap my head around it.

 Thanks!

 Damon
 ___
 Tutor maillist  -  tu...@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] Newbie Unittest ...

2010-05-06 Thread Vincent Davis
On Thu, May 6, 2010 at 1:15 PM, Steve Willoughby st...@alchemy.com wrote:

 The unit test methods all take message arguments so if you just
 want to customize the reported error, that's easily done.

 something like:
  self.assertEqual(self.file.tags[k], v, Failure with key +k)

 That's easiest.  If you really want a separate test for each, you
 may want to create a factory function which will generate the individual
 test methods when the testcase object is created.

 --steve


Looks like Steve answered the question you had for me,
 self.assertEqual(self.file.tags[k], v, Failure with key +k) I think
this is the best(how I would do it) solution, 1 test for files with a
meaningful report as to which file is the problem.

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis

On Thu, May 6, 2010 at 1:15 PM, Steve Willoughby st...@alchemy.com wrote:

 The unit test methods all take message arguments so if you just
 want to customize the reported error, that's easily done.

 something like:
  self.assertEqual(self.file.tags[k], v, Failure with key +k)

 That's easiest.  If you really want a separate test for each, you
 may want to create a factory function which will generate the individual
 test methods when the testcase object is created.

 --steve

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] New class, how return value of x in interactive shell

2010-04-05 Thread Vincent Davis
I am working an a open source project and would like to add feature to a
class.
Current action:
in:b = BString.new('I am a BString object')
out:  b
in:BString - Python:0x1044846c8 / R:0x105c86f50
in:print(b)
out:   21-letter BString instance
   seq: I am a BString object

What I would like is to be able to
in   b
out 21-letter BString instance
   seq: I am a BString object

I have 2 questions
1, how do I do this?
2, how does print know what to do?

I have a lot to learn so pointing me in the right direction or to
documentation is as useful as the correct code.

Thanks

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New class, how return value of x in interactive shell

2010-04-05 Thread Vincent Davis
Take a look at the repr and str methods:
 http://docs.python.org/reference/datamodel.html#basic-customization

Ok so I am still a little confused, It seems that __str__ is used for print
and str()
byt what allows whats below. That is why does just entering the name of the
instance return print(b). I have tried a few combinations but not the right
one.
in   b
out 21-letter BString instance
   seq: I am a BString object

*Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis


On Mon, Apr 5, 2010 at 11:24 AM, Wayne Werner waynejwer...@gmail.comwrote:



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New class, how return value of x in interactive shell

2010-04-05 Thread Vincent Davis

 That' a very strange idiom in Python.
 Can you show us the class definition?


It's a bioconductor extension to rpy2
http://www.bitbucket.org/lgautier/rpy2-bioc-extensions/overview/
I am trying to learn R and at they same time more about python and R
bioconductor packages. So no it is not homework but I am trying to learn
something. I am sure the answer is obvious when you know it :)
Here is the class, although it is obviously part of something bigger, you
can checkout the full code at bitbuckit.org

class BString(XString):
 Biological string 

_bstring_constructor = biostrings.BString

@classmethod
def new(cls, x):
 :param x: a (biological) string 
res = cls(cls._bstring_constructor(conversion.py2ri(x)))
_setExtractDelegators(res)
return res

*Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis


On Mon, Apr 5, 2010 at 1:08 PM, Alan Gauld alan.ga...@btinternet.comwrote:

 Vincent Davis vinc...@vincentdavis.net wrote

 I am working an a open source project and would like to add feature to a

 class.
 Current action:
 in:b = BString.new('I am a BString object')


 That' a very strange idiom in Python.
 Can you show us the class definition?


  out:  b
 in:BString - Python:0x1044846c8 / R:0x105c86f50
 in:print(b)
 out:   21-letter BString instance
  seq: I am a BString object

 What I would like is to be able to
 in   b
 out 21-letter BString instance
  seq: I am a BString object

 I have 2 questions
 1, how do I do this?
 2, how does print know what to do?


 If you look at your class definition that should become obvious.
 Are you sure this isn't a homework?


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


Re: [Tutor] Difflib comparing string sequnces

2010-03-10 Thread Vincent Davis
@Ricardo Aráoz
Thanks for your response, Before I saw your response I had posted the
question on stack overflow. See link below. I like your solution better than
the re solution posted.
It looks like this task may take longer than I think. The .re solution I
guess might take more than 10 days. The search string in 80million digits
long. But Obviously I can stop once I find a match and then just move on the
the next sequence.
You might what to post this answer on stackoverflow. I like the more
interactive form of a mailing list but there seems to be a very p\broad
audience on stackoverflow.

Thanks again,
http://stackoverflow.com/questions/2420412/search-for-string-allowing-for-one-mismatches-in-any-location-of-the-string-pyth

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis


2010/3/10 Ricardo Aráoz ricar...@gmail.com

  Vincent Davis wrote:

 I have never used the difflib or similar and have a few questions.
 I am working with DNA sequences of length 25. I have a list of 230,000 and
 need to look for each sequence in the entire genome (toxoplasma parasite) I
 am not sure how large the genome is but more that 230,000 sequences.
 The are programs that do this and really fast, and they eve do partial
 matches but not quite what I need. So I am looking to build a custom
 solution.
 I need to look for each of my sequences of 25 characters example(
 AGCCTCCCATGATTGAACAGATCAT).
 The genome is formatted as a continuos string
 (CATGGGAGGCTTGCGGAGCCTGAGGGCGGAGCCTGAGGTGGGAGGCTTGCGGAG.)

  I don't care where or how many times on if it exists. This is simple I
 think, str.find(AGCCTCCCATGATTGAACAGATCAT)

  But I also what to find a close match defined as only wrong at 1 location
 and I what to record the location. I am not sure how do do this. The only
 thing I can think of is using a wildcard and performing the search with a
 wildcard in each position. ie 25 time.
 For example
 AGCCTCCCATGATTGAACAGATCAT
 AGCCTCCCATGATAGAACAGATCAT
 close match with a miss-match at position 13


 also :

 sequence = 'AGGCTTGCGGAGCCTGAGGGCGGAG'
 seqList = ['*' + sequence[0:i] + '?' + sequence[i+1:] + '*' for i in
 range(len(sequence))]
 import fnmatch

 genome = 'CATGGGAGGCTTGCGGAGCCTGAGGGCGGAGCCTGAGGTGGGAGGCTTGCGGAG'
 if any(fnmatch.fnmatch(genome, i) for i in seqList)
 print 'It matches'

 Which might be better if the sequence is fixed and the genome changes
 inside a loop.

 HTH




 ___
 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


[Tutor] Difflib comparing string sequnces

2010-03-09 Thread Vincent Davis
I have never used the difflib or similar and have a few questions.
I am working with DNA sequences of length 25. I have a list of 230,000 and
need to look for each sequence in the entire genome (toxoplasma parasite) I
am not sure how large the genome is but more that 230,000 sequences.
The are programs that do this and really fast, and they eve do partial
matches but not quite what I need. So I am looking to build a custom
solution.
I need to look for each of my sequences of 25 characters example(
AGCCTCCCATGATTGAACAGATCAT).
The genome is formatted as a continuos string
(CATGGGAGGCTTGCGGAGCCTGAGGGCGGAGCCTGAGGTGGGAGGCTTGCGGAG.)

I don't care where or how many times on if it exists. This is simple I
think, str.find(AGCCTCCCATGATTGAACAGATCAT)

But I also what to find a close match defined as only wrong at 1 location
and I what to record the location. I am not sure how do do this. The only
thing I can think of is using a wildcard and performing the search with a
wildcard in each position. ie 25 time.
For example
AGCCTCCCATGATTGAACAGATCAT
AGCCTCCCATGATAGAACAGATCAT
close match with a miss-match at position 13


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list to numpy record array

2010-02-23 Thread Vincent Davis
@Kent
All I know about RecordArrays is from reading this page:
http://www.scipy.org/RecordArrays
but it looks like you have done the right thing and created a
RecordArray. What is wrong with this result?

The number are completely different, or I have no idea how to read it.
Here are the first row of each
normal array  ['  0', '  0', '234.0', '24.0', ' 25']
Record array  [(3153952, 0, 0.0, 0.0, 0)

*Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis


On Tue, Feb 23, 2010 at 6:30 AM, Kent Johnson ken...@tds.net wrote:

 On Mon, Feb 22, 2010 at 11:50 PM, Vincent Davis
 vinc...@vincentdavis.net wrote:
 
  I must be missing something simple. I have a list of lists data = [['
  0', '  0', '234.0', '24.0', ' 25'], ['  1', '  0', '22428.0', '2378.1', '
 25'],.. and what to make a record array from it but it gets screwed up
 or I don't get it, maybe both.
 
  bdata = numpy.array(data, [('x', int),('y',
 int),('mean',float),('stdv',float),('npixcels',int)])
   bdata
  array([[(3153952, 0, 0.0, 0.0, 0), (3153952, 0, 0.0, 0.0, 0),
 ...
  (3486240, 0, 0.0, 0.0, 0)]],
 
dtype=[('x', 'i8'), ('y', 'i8'), ('mean', 'f8'), ('stdv',
 'f8'), ('npixcels', 'i8')])

 All I know about RecordArrays is from reading this page:
 http://www.scipy.org/RecordArrays
 but it looks like you have done the right thing and created a
 RecordArray. What is wrong with this result?

 Kent

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] list to numpy record array

2010-02-22 Thread Vincent Davis
I must be missing something simple. I have a list of lists data = [['  0',
'  0', '234.0', '24.0', ' 25'], ['  1', '  0', '22428.0', '2378.1', '
25'],.. and what to make a record array from it but it gets screwed up
or I don't get it, maybe both. Notice that at this stage the items are
strings, not numbers, and there is whitespace not sure this matters.
Here is what is happening
adata = numpy.array(data,numpy.float64)

 adata
array([[  0.e+00,   0.e+00,   2.3400e+02,
  2.4000e+01,   2.5000e+01],
   ...,
   [  4.7700e+02,   4.7700e+02,   2.0700e+02,
  4.5800e+01,   2.5000e+01]])

This is what I would expect except it is not a record array.

This is not what I expect. I think I have tried every iteration including
using numpy dtaypes numpy.int32 or bdata = numpy.array(data, dtype = [('x',
int),('y', int),('mean',float),('stdv',float),('npixcels',int)])
What am I missing?

bdata = numpy.array(data, [('x', int),('y',
int),('mean',float),('stdv',float),('npixcels',int)])
 bdata
array([[(3153952, 0, 0.0, 0.0, 0), (3153952, 0, 0.0, 0.0, 0),
(206933603122, 0, 0.0, 0.0, 0), (808334386, 0, 0.0, 0.0, 0),
(3486240, 0, 0.0, 0.0, 0)],
   [(3219488, 0, 0.0, 0.0, 0), (3153952, 0, 0.0, 0.0, 0),
(1356161439282, 0, 0.0, 0.0, 0),
(54074581398322, 0, 0.0, 0.0, 0), (3486240, 0, 0.0, 0.0, 0)],
   [(3285024, 0, 0.0, 0.0, 0), (3153952, 0, 0.0, 0.0, 0),
(206933931058, 0, 0.0, 0.0, 0), (925775666, 0, 0.0, 0.0, 0),
(3486240, 0, 0.0, 0.0, 0)],
   ...,
   [(3487540, 0, 0.0, 0.0, 0), (3618612, 0, 0.0, 0.0, 0),
(206933602866, 0, 0.0, 0.0, 0), (908996661, 0, 0.0, 0.0, 0),
(3486240, 0, 0.0, 0.0, 0)],
   [(3553076, 0, 0.0, 0.0, 0), (3618612, 0, 0.0, 0.0, 0),
(13561596370041137, 0, 0.0, 0.0, 0),
(62870573495603, 0, 0.0, 0.0, 0), (3486240, 0, 0.0, 0.0, 0)],
   [(3618612, 0, 0.0, 0.0, 0), (3618612, 0, 0.0, 0.0, 0),
(206933798962, 0, 0.0, 0.0, 0), (942552372, 0, 0.0, 0.0, 0),
(3486240, 0, 0.0, 0.0, 0)]],

  dtype=[('x', 'i8'), ('y', 'i8'), ('mean', 'f8'), ('stdv', 'f8'),
('npixcels', 'i8')])


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Structure of my simulation / monte-carlo

2009-11-01 Thread Vincent Davis
Kent Johsnon writes
This class has a lot of responsibilities:
- create applicants
- create institutions
- run a single match
- run multiple matches
- calculate statistics on the result of multiple matches
A principle of object-oriented design is that a class should have a
single responsibility. I would break your class up a bit using
multiple classes, perhaps.

I am trying to do what you recomend, as much as makes sense to me, but that
is why I ask the question so I should consider your answer.
This is what I hear you saying, (I don't mean to represent them as
sub-classes but more how they would operate on each other) Should I consider
making Institutions) a subclass of (Make Institutions)? I can't think of
anything that would make sense to inherit.

class Simulation:
class Create Institutions:
class Institutions:
class create Applicants:
class Applicants:
class Match:
class Multi Match:

I add I am thinking

class Simulation:
def__init__:(self, results, stats.repeat..)
def create_applicants():
class Applicants
def creat_institutions():
class Institutions
def one_simulation(): # one or more
create_applicants()
create_institutions()
class Match()
class Results
def repeat_simulation()
repeat one_simulations
class Results

After writing this out I now think you are right, more classes. Which means
I really need to play with function objects to understand how they are
passed down the layers

Simulation(GPA = random.gauss(50, 10), repeat = 100.)
MakeApplicants(GPA)
Applicants(GPA)  # I need to make sure the GPA is calculated at each
applicant not back at Simulation.

DaveA
ask if it will always be random.gauss? No, I would like it to be anything
from a constant to a much more complex function)

DaveA
I would caution you that each instance of RepeatMatch will then hold lots
of the other members, so keeping them around could be expensive

This means they stay in memory? Is there a way to know how much room a
instance takes up, in memory or hard drive?
I could serialize them a save them to a sqlite when done with a simulation
correct? How is a questions for later.

worried that you might find my responses too complex
I am kinda working in a vacuum, with respect to python programing. Complex
and difficult are ok, The challenge is not knowing what I don't know. I need
to practice with function objects and run a few experiments still to make
sureI understand them.

DaveA and Kent Thanks for all your help, Vincent
To add a little more to what I am doing I am using CherryPy to host this
simulation. So the GPA function and other simulation variables can be
entered in a html form and passed to the Simulation class. Then I am
calculating results as well as using matplotlib to make some plots, these
results and plots then get show. I think I have most of the CherryPy stuff
figured out once I have the Simulations class setup to do the whole thing.
The only part with CherryPy I am still working on is displaying progress on
the browser as the simulations runs, it can take several minutes.

Thanks
Vincent Davis
720-301-3003


On Sun, Nov 1, 2009 at 6:02 AM, Dave Angel da...@ieee.org wrote:

 Vincent Davis wrote:

 I ask this question in part because of a fee remarks from another question
 I
 ask class attribute to initiate more classes

 Basically I am simulation the process of applicants to schools and trying
 to
 ask/answer some questions like what conditions do you need to have an
 optimal solution Oh and to learn python. I basically had it working as a
 script rather than using a class structure but it was very inflexible and
 I
 still needed to learn about classes.

 What I have these classes
 class Applicant: has lots of attributes (self.gpa = random.gauss(50, 10)
 about the Applicant and def() defining how/why an applicant applies to an
 institution,

 class Institution: Lots of attributes (self.quality = random.gauss(50,
 10)) about the Institution and def() defining how the institution
 considers
 the applicant.

 class Match: this defines the interaction of the population of Applicants
 and Institutions, i.e. the rules of the game and returns the outcome i.e.
 which Applicants went to which Institutions.

 As of now I have been running 1 Match at a time. Which is to say generate
 8000 instances of Applicant and 300 instances of Institution and then run
 the match Match(app_list, inst_list) and I do this with a short script.

 So now I need to implement my monte-carlo. By that I mean that i want to
 set
 some of the initial condition such as GPA, and Quality and basically
 re-run
 the what I descried above, (generate applicant, institutions, match them)
  Then save the results.

 So my plan way to make a new class. This class would define the Applicant
 characteristics self.gpa = random.gauss(mean, SD) and the
 institutions self.quality = random.gauss(mean, sd)

 so it would look

Re: [Tutor] Structure of my simulation / monte-carlo

2009-11-01 Thread Vincent Davis
Just to be clear,or try, given a set of applicants and institutions the
Match will always have the same result. So when I am repeating the Match
this only makes sense to do is I am also making new applicants and
institutions. So I am sampling Match results drawn from a process that is
initiated with a distributions set at the applicant and institution level.

Thanks
Vincent Davis


On Sun, Nov 1, 2009 at 9:58 AM, Kent Johnson ken...@tds.net wrote:

 On Sun, Nov 1, 2009 at 10:47 AM, Vincent Davis vinc...@vincentdavis.net
 wrote:
  Kent Johsnon writes
  This class has a lot of responsibilities:
  - create applicants
  - create institutions
  - run a single match
  - run multiple matches
  - calculate statistics on the result of multiple matches
  A principle of object-oriented design is that a class should have a
  single responsibility. I would break your class up a bit using
  multiple classes, perhaps.
  I am trying to do what you recomend, as much as makes sense to me, but
 that
  is why I ask the question so I should consider your answer.
  This is what I hear you saying, (I don't mean to represent them as
  sub-classes but more how they would operate on each other) Should I
 consider
  making Institutions) a subclass of (Make Institutions)? I can't think of
  anything that would make sense to inherit.
  class Simulation:
  class Create Institutions:
  class Institutions:
  class create Applicants:
  class Applicants:
  class Match:
  class Multi Match:
  I add I am thinking
  class Simulation:
  def__init__:(self, results, stats.repeat..)
  def create_applicants():
  class Applicants
  def creat_institutions():
  class Institutions
  def one_simulation(): # one or more
  create_applicants()
  create_institutions()
  class Match()
  class Results
  def repeat_simulation()
  repeat one_simulations
  class Results
  After writing this out I now think you are right, more classes.

 Now you are getting too complicated. You don't need to use inheritance
 or nested classes, and you can use simple methods (not classes) to
 create applicants and institutions. You already have Applicant,
 Institution and Match classes that run a single match. Now make a
 RepeatMatch class that uses the Match class to run multiple
 simulations.

 Kent

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Structure of my simulation / monte-carlo

2009-11-01 Thread Vincent Davis
Thanks again for all your help Kent and Dave.
I think you won't here from me for a week or more as I digest your advise
and work on my project.

Thanks
Vincent Davis
720-301-3003


On Sun, Nov 1, 2009 at 6:34 PM, Dave Angel da...@ieee.org wrote:

 Kent Johnson wrote:

 On Sun, Nov 1, 2009 at 10:47 AM, Vincent Davis vinc...@vincentdavis.net
 wrote:


 Kent Johsnon writes
 This class has a lot of responsibilities:
 - create applicants
 - create institutions
 - run a single match
 - run multiple matches
 - calculate statistics on the result of multiple matches
 A principle of object-oriented design is that a class should have a
 single responsibility. I would break your class up a bit using
 multiple classes, perhaps.
 I am trying to do what you recomend, as much as makes sense to me, but
 that
 is why I ask the question so I should consider your answer.
 This is what I hear you saying, (I don't mean to represent them as
 sub-classes but more how they would operate on each other) Should I
 consider
 making Institutions) a subclass of (Make Institutions)? I can't think of
 anything that would make sense to inherit.
 class Simulation:
class Create Institutions:
class Institutions:
class create Applicants:
class Applicants:
class Match:
class Multi Match:
 I add I am thinking
 class Simulation:
def__init__:(self, results, stats.repeat..)
def create_applicants():
class Applicants
def creat_institutions():
class Institutions
def one_simulation(): # one or more
create_applicants()
create_institutions()
class Match()
class Results
def repeat_simulation()
repeat one_simulations
class Results
 After writing this out I now think you are right, more classes.



 Now you are getting too complicated. You don't need to use inheritance
 or nested classes, and you can use simple methods (not classes) to
 create applicants and institutions. You already have Applicant,
 Institution and Match classes that run a single match. Now make a
 RepeatMatch class that uses the Match class to run multiple
 simulations.

 Kent



 I mostly agree with Kent, but I apparently disagree about which classes are
 actually needed.  Think what things will have actual instances that will
 last long enough to be worth formally defining.  So you need Applicant, and
 Institution, and Simulation.  Notice they're all singular.  I'm assuming one
 simulation is a single set of test data, with its results.  Then you create
 as many instances of Simulation as you need for comparison purposes, and
 perhaps keep a list of them.  It's not clear that list needs any further
 structure than the built-in list type provides.

 You don't need a class for creating an Applicant, that's just a line or two
 in a loop in the Simulation class.  Similarly for Institution.

 And if I understand it correctly, you don't need very many different
 methods in Simulation either.  You need the __init__ to save enough
 information to tag this particular simulation (call it a label, it's
 probably just a string).  If __init__ is too complex, you may want to break
 it into several phases.  But they'll always be called in direct succession,
 so there may not be any point.  Then you need something that triggers an
 analysis, and something that queries for particular results.  That last will
 then be called from plotting or charting routines.

 But you probably don't need anything special for a collection of Simulation
 objects.  A list will probably be fine.

 And from what you said earlier, you WILL need function objects, probably as
 parameters to the Simulation constructor.  So each instance of Simulation
 will be given several function objects to specify the distribution functions
 for the parameters to be used when creating Applicants and Institutions.

 DaveA



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class attribute to initiate more classes

2009-10-31 Thread Vincent Davis
DaveA posted
import random, functools

class Person:
def __init__(self, size):
self.size = size

def __str__(self):
return Person of size %s % self.size

class MakePeople:
def __init__(self, random_func):
self.random_func = random_func

def make_them(self, count):
return [Person(self.random_func()) for i in xrange(count)]

people_maker = MakePeople(functools.partial(random.gauss, 100, 2))
persons = people_maker.make_them(100)
for person in persons:
print person.size

I changed the last line, from
print person
print person.size

So this does what I want, but I am not sure why.
I read the entry about functools.partial but it was not very clear to me.
If I
people_maker = MakePeople(random.gauss(100, 2))
then I only get 1 random #.
and if I
MakePeople('random.gauss(100, 2)')
then I just a fix string
So DaveA uses

functools.partial(random.gauss, 100, 2)

not obvious to me from that it should not be

functools.partial(random.gauss(100, 2))

and I guess the other key is

Person(self.random_func())

Also now this
people_maker = MakePeople(123)

does not work, which is not terrible.

Anyone have some more to add, I would not have confidence in applying this
to new situations and it seems.

Also I thank DaveA improving my Python conventions. I am really bad about
that. Is there a cheat sheet for Python conventions.

Like class (Capitals), def (two_words), I guess I should make my own.

Thanks
Vincent Davis
720-301-3003


On Sat, Oct 31, 2009 at 5:55 AM, Dave Angel da...@ieee.org wrote:

 Vincent Davis wrote:

 I have a program that generates many instances of a class with an
 attribute
 self.x = random.gauss(10, 2). So each instance has a different value for
 self.x. This is what I want. Now I want to make a class that starts my
 program and sets the attributes.
 class people:
def __init__(self, size)
self.size = size

 class makepeople:
def __init__(self, randomsize)
self.rsize = randomsize
self.allpeople = []
def makethem():
for x in range(1,100):
p+str(x) = people(self.rsize)
allpeople.append(p+str(x))

 so what I would like to have work is set the attribute of makepeople so
 that
 when it is used to make instances of people each will have a different
 size.

 listofp = makepeople(random.guass(100, 2))
 listofp.makethem()

 I would then what listofp.allpeople to be a list of people with different
 sizes. The above code does not work, I don't think it does anyway.

 I hope this makes sense, I am sure there is a term for what I am trying to
 do but I don't know it.

 Thanks
 Vincent Davis



 You're trying to do several things here, and I'm unclear on many of the
 details.  So here's a new spec, and the implementation for it.

 We want a factory class, which can be given a particular distribution
 function and parameters, and using those parameters generate a list of
 Person objects, whose heights are distributed according to that random
 function.  There might be duplicates in that list, but they'd be random
 coincidence, and the list as a whole would be as random as the function
 specified by the caller.

 I also took a few liberties on the names of things, trying to use Python
 conventions for naming, and things like using a singular word for a
 classname of a single item.  And I removed the allpeople attribute, as the
 class only makes sense to me if you can use its instance multiple times, to
 generate more items with the same given distribution.


 CODE
 import random, functools

 class Person:

   def __init__(self, size):
   self.size = size
   def __str__(self):
   return Person of size %s % self.size

 class MakePeople:
   def __init__(self, random_func):
   self.random_func = random_func

   def make_them(self, count):
   return [Person(self.random_func()) for i in xrange(count)]


 people_maker = MakePeople(functools.partial(random.gauss, 100, 2))
 persons = people_maker.make_them(100)
 for person in persons:
   print person

 /CODE---

 DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class attribute to initiate more classes

2009-10-31 Thread Vincent Davis


 Vincent Davis wrote:

 DaveA posted
 import random, functools

 class Person:
def __init__(self, size):
self.size = size

def __str__(self):
return Person of size %s % self.size

 class MakePeople:
def __init__(self, random_func):
self.random_func = random_func

def make_them(self, count):
return [Person(self.random_func()) for i in xrange(count)]

 people_maker = MakePeople(functools.partial(random.gauss, 100, 2))
 persons = people_maker.make_them(100)
 for person in persons:
print person.size

 I changed the last line, from
 print person
 print person.size

 So this does what I want, but I am not sure why.
 I read the entry about functools.partial but it was not very clear to me.
 If I
 people_maker = MakePeople(random.gauss(100, 2))
 then I only get 1 random #.
 and if I
 MakePeople('random.gauss(100, 2)')
 then I just a fix string
 So DaveA uses

 functools.partial(random.gauss, 100, 2)

 not obvious to me from that it should not be

 functools.partial(random.gauss(100, 2))

 and I guess the other key is

 Person(self.random_func())

 Also now this
 people_maker = MakePeople(123)

 does not work, which is not terrible.

 Anyone have some more to add, I would not have confidence in applying this
 to new situations and it seems.

 Also I thank DaveA improving my Python conventions. I am really bad about
 that. Is there a cheat sheet for Python conventions.

 Like class (Capitals), def (two_words), I guess I should make my own.

 Thanks
 Vincent Davis
 720-301-3003

 snip



 For the official Python style guide, see
 http://www.python.org/dev/peps/pep-0008/

 There are a couple of things going on in my code sample, and I'll try to
 elaborate on them.  I'm not claiming it's the 'right' answer, just that it
 satisfies what I think were the most important goals you had.  But if you
 want to save the list in the MakePeople() instance, you'd add an additional
 parameter to its constructor, and combine the second method into __init__().
  But as someone else points out, at that point, it's then hardly worth
 making a class out of it.

 First the tough part.  In your original code, your caller was doing:



 listofp = makepeople(random.guass(100, 2))

 But that passes only a single value into the makepeople constructor.  If
 you're always going to use gaussian, then you can just move the function
 call into the make_them() loop.  But if you want to do the same thing, but
 with a different distribution, you need to pass a function object instead.
  Learning about function objects is very useful.  You should really play
 with them in a simpler situation, to get an idea how they work.

 At its simplest, a function object is just the function name, without
 parentheses.  You can store it (and pass it as a parameter to another
 function) just like any other object.  And then when you actually want to
 call it, you can use the new name with parentheses, kind of like an alias to
 the original function name.

 import math

 def indirection(funcobject, argument):
   return funcobject(math.pi/180 * argument)

 print indirection(math.sin, 30)
 print indirection(math.cos, 30)


 Now what happens here?  The indirection() function calls an entirely
 different function the two times it's called, one time it calls sin, and the
 other time it calls cos.  As long as all the arguments to the function are
 going to be supplied here, there's no confusion.  Try the same thing with
 any other set of functions, given that all of them take the same number and
 types of arguments.

 This opens the door to all sorts of things, such as a mini-calculator
 (following is mostly pseudo-code):

 funcname =  getnamefrom user()
 angleinradians = getnumberfromuser()

 converter_dict = { sin: math.sin,  cos:math.cos }
 print  converter_dict[funcname](angleinradians)

 So the values of the dictionary are actual function objects, ready to be
 called.

 What happens if some of the function parameters are known to the caller,
 and not to the callee?  I'll use the random.gauss example again.  If we want
 the caller to be able to specify them, we could do something like the
 following:

 def print_indirection(funcobject, arg1, arg2, count):
   for i in xrange(count):
   print funcobject(arg1, arg2)

 and call it:
   print_indirection(random.gauss, 100, 2, 44)

 to get 44 values with a gaussian distributon.  But now suppose we wanted to
 be able to use the same function with random.getrandbits() ?  That function
 only takes a single parameter, so the print funcobject() would blow up.

 functools.partial lets us  bind a function object with some or all of its
 arguments already attached.  So in our case, the caller (who knows what the
 arguments look like) gets to lay them out, without being stuck with any
 particular ones.

 So, we rewrite print_indirection something like this:

 def print_indirection(funcobject, count):
   for i in xrange(count):
   print funcobject()

 and call

[Tutor] Structure of my simulation / monte-carlo

2009-10-31 Thread Vincent Davis
I ask this question in part because of a fee remarks from another question I
ask class attribute to initiate more classes

Basically I am simulation the process of applicants to schools and trying to
ask/answer some questions like what conditions do you need to have an
optimal solution Oh and to learn python. I basically had it working as a
script rather than using a class structure but it was very inflexible and I
still needed to learn about classes.

What I have these classes
class Applicant: has lots of attributes (self.gpa = random.gauss(50, 10)
about the Applicant and def() defining how/why an applicant applies to an
institution,

class Institution: Lots of attributes (self.quality = random.gauss(50,
10)) about the Institution and def() defining how the institution considers
the applicant.

class Match: this defines the interaction of the population of Applicants
and Institutions, i.e. the rules of the game and returns the outcome i.e.
which Applicants went to which Institutions.

As of now I have been running 1 Match at a time. Which is to say generate
8000 instances of Applicant and 300 instances of Institution and then run
the match Match(app_list, inst_list) and I do this with a short script.

So now I need to implement my monte-carlo. By that I mean that i want to set
some of the initial condition such as GPA, and Quality and basically re-run
the what I descried above, (generate applicant, institutions, match them)
 Then save the results.

So my plan way to make a new class. This class would define the Applicant
characteristics self.gpa = random.gauss(mean, SD) and the
institutions self.quality = random.gauss(mean, sd)

so it would look something like this


class RepeatMatch:
def __int__(self, app_mean, app_sd, inst_mean, inst_sd, match_ repeat)
self.app_mean = app_mean
……..
self.match_repeat = match_repeat

   def makeApplicants():

   def makeInstitutions():

   def runMatches(self)
   # runs the match match_repeat number of times, saves results

# then I calculate some characteristics of the results

def ratio_dist():
 # returns the Mean and sd of GPA/Quality
END OF CODE

Does it make sense to do it this way? Is there a better/alternative way of
thinking about this. In the end I want to compare the results of repeated
simulations RepeatMatch(50,2….) Compared to RepeatMatch(50,15….)
This is way I had ask the earlier question class attribute to initiate more
classes

Thanks
Vincent Davis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] class attribute to initiate more classes

2009-10-30 Thread Vincent Davis
I have a program that generates many instances of a class with an attribute
self.x = random.gauss(10, 2). So each instance has a different value for
self.x. This is what I want. Now I want to make a class that starts my
program and sets the attributes.
class people:
def __init__(self, size)
self.size = size

class makepeople:
def __init__(self, randomsize)
self.rsize = randomsize
self.allpeople = []
def makethem():
for x in range(1,100):
p+str(x) = people(self.rsize)
allpeople.append(p+str(x))

so what I would like to have work is set the attribute of makepeople so that
when it is used to make instances of people each will have a different size.

listofp = makepeople(random.guass(100, 2))
listofp.makethem()

I would then what listofp.allpeople to be a list of people with different
sizes. The above code does not work, I don't think it does anyway.

I hope this makes sense, I am sure there is a term for what I am trying to
do but I don't know it.

Thanks
Vincent Davis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] calculating a sort key and operator.attrgetter()

2009-07-01 Thread Vincent Davis
Thanks for the help, Looks like I will define a function. And yes you are
right self.does_observe is constant so it will not affect the outcome.

Thanks again
Vincent Davis



On Tue, Jun 30, 2009 at 11:15 PM, Kent Johnson ken...@tds.net wrote:

 On Tue, Jun 30, 2009 at 11:39 PM, Vincent Davisvinc...@vincentdavis.net
 wrote:
  I have a class with an attribute which is a list rank_list this is a
 list
  of instances f another class that has attributes quality, is_observed
  if I want to sort the list by the attribute quality I can just use,
  self.rank_list.sort(key=operator.attrgetter('quality'))
  But I want to sort like this.
  self.rank_list.sort(key=(operator.attrgetter('quality') *
  operator.attrgetter('is_observed') * self.does_observe))
  Will this work or is there a better way?

 That won't work because attrgetter() returns a function and you can't
 multiply functions. What you can do is define your own function that
 returns the value you want for the key and use that for the sort. I'm
 leaving out self.does_observe because that won't change for the list
 items, wil it?

 def make_key(item):
  return item.quality * item.is_observed

 self.rank_list.sort(key=make_key)

 Kent

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


[Tutor] calculating a sort key and operator.attrgetter()

2009-06-30 Thread Vincent Davis
I have a class with an attribute which is a list rank_list this is a list
of instances f another class that has attributes quality, is_observed
if I want to sort the list by the attribute quality I can just use,
self.rank_list.sort(key=operator.attrgetter('quality'))
But I want to sort like this.
self.rank_list.sort(key=(operator.attrgetter('quality') *
operator.attrgetter('is_observed') * self.does_observe))
Will this work or is there a better way?

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


Re: [Tutor] list of instance objects, access attribute

2009-06-19 Thread Vincent Davis
Thanks to all for the comments, It was much more than I expected.

Vincent


On Fri, Jun 19, 2009 at 4:30 PM, Lie Ryanlie.1...@gmail.com wrote:
 Alan Gauld wrote:

 Vincent Davis vinc...@vincentdavis.net wrote

 class B():
  def __init__(self, b1, b2):
     self.fooa = b1
     self.foob = b2

 I assume thats what you really meant!

 Ok now I have several instances in a list
 b1 = B(1, 2)
 b2 = B(3, 4)
 b3 = B(9, 10)
 alist = [b1, b2, b3]

 Lets say for each instance of the class I want to print the value of
 fooa if it is greater than 5. How do I do this,

 define a method of the class, say bigprint()

 def bigprint(self, limit=5):
     if self.fooa  limit: print self.fooa

 about is how I iterate over the values of fooa.

 Iterate over the objects and call the method. Make the object do the
 work, your code should not need to know about the internal attributes of
 the object.

 For x in alist:
      x.bigprint()

 Is that the right way or is there a better?
 will this work for methods?

 Methods are how you should do it. Direct access other than for simple
 reading of values is a suspicious design smell. Any processing of or
 rules about the data should be in a method.



 Personally, I often thought input/output inside an object is a design
 smell (except for debugging), preferring something like this:

 class B(object):
    def __init__(...):
        ...
    def big(self, limit=5):
        return (self.fooa  limit)

 alist = [...]

 for y in (x for x in alist if x.big()):
    print y.fooa

 although admittably often it could make certain codes more difficult to
 write; and in some cases the practical approach would be warranted. This
 is especially true as the codebase gets larger.

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

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


[Tutor] list of instance objects, access attribute

2009-06-18 Thread Vincent Davis
given a class like
class B():
def __init__(self, b1, b2):
    self.fooa = fooa
    self.foob = foob

Ok now I have several instances in a list
b1 = B(1, 2)
b2 = B(3, 4)
b3 = B(9, 10)
alist = [b1, b2, b3]

Lets say for each instance of the class I want to print the value of
fooa if it is greater than 5. How do I do this, what I am unclear
about is how I iterate over the values of fooa. As I write this I am
thinking of trying
For x in alist:
if x.fooa  5 : print(x.fooa)

Is that the right way or is there a better?
will this work for methods?

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


Re: [Tutor] 3.0 on Mac

2009-06-15 Thread Vincent Davis
Here is what my .bash_profile looks like, This is in my user directory

# Setting PATH for EPD_Py25 v4.3.0
# The orginal version is saved in .bash_profile.pysave
PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}
export PATH

PYTHONPATH=/Volumes/iDisk/match/python
export PYTHONPATH

Note that the file /Library/Frameworks/Python.framework/Versions/Current
is a symbolic link to the actual python. You could change the smbolic link
or pint the Bash_profile directly to the python you want. I also found it
difficult to understand the PYTHONPATH, As yu see it above Python will look
in my idisk for modules to import. So if I have a file names mymod.py
in /Volumes/iDisk/match/python and I import mymod it will find it.

Hope this helps, When I was learning abut python I found it difficult to
find spisific instructins for this. Part of the problem Is that it seems
that most instruction assume some understanding of terminal than I had. I
know little more that what allows me to follow clear instructions.




Thanks
Vincent Davis
720-301-3003


On Thu, Jun 11, 2009 at 9:54 PM, Dave Angel da...@ieee.org wrote:

 acfleck  wrote:

  I'm a Python nubie and having trouble with 3.0.1 on Mac (10.4.11). I did a
 default install of MacPython 3.0.1. The IDLE.app works fine, but from a
 Terminal window, the 'python' command still gets me V2.5.3 (the original
 Apple installed version). A 'python3' command is not recognized. I'd like to
 know what I need to change to access V3.0.1 from a Terminal window.


 Use the 'which' command to see what versions of python are on your PATH.
  Then, since you have two different versions of Python you want available,
 create one or more scripts (on your path), to explicitly run the other
 installed versions.  Probably, those scripts can be one line each, though
 you also might conceivably want to set an environment variable or two (such
 as pythonpath)


 As far as I know, the install will not create a script called python3, or
 anything else like it.  That's up to you.  And it's generally not good form
 to hide the system-installed version, since many utilities and scripts might
 depend on that particular version.


 ___
 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] question about class

2009-06-09 Thread Vincent Davis
Thanks for the help and comments, I think my questions have been
answered, I will know if I understand when I try to implement them.
The Match algorithm. algorithm is described in the link below. The
Applicant and School rankings will be (Attributes ?) of the Applicant
and School class, and I simulate this ranking process by considering
Applicants and Schools attributes, but basically similar qualities get
mutually ranked. (I go go on if someone is interested but I thought it
best to keep the discution on what I am trying to learn about classes)

http://www.nrmp.org/res_match/about_res/algorithms.html

Thanks Again
Vincent Davis




On Tue, Jun 9, 2009 at 1:12 AM, spirdenis.s...@free.fr wrote:
 Le Mon, 8 Jun 2009 17:31:23 -0600,
 Vincent Davis vinc...@vincentdavis.net s'exprima ainsi:

 Accidentally sent I have added the rest
 (by the way I refrain from using the terms attribute, method, as I
 will likely miss use them)

  I am reading several tutorials about classes and trying to figure out
  how to apply it to my project. I have a working program that basically
  matches up applicants and schools. Schools and applicants have and
  true quality and an observed quality. Then there is an algorithm
  that matches them up. Right now I do this all with lists which works
  ok but I would like to try using classes.

  Questions
  1, does it make seens to have a applicant and a schools class (based
  on this brief explanation)

 Based on your explanations, I don't really understand the problem you're 
 trying to solve, nore the algorithm. Still, probably it makes sense to use 
 Applicant and School classes for the simple reason these notions in your 
 program represent objects: there are single, identified, things ; as 
 opposed to values (in the ordinary sense of the term) that represent 
 qualities or information such as color, position, number, or true and 
 observed above.
 (By the way, don't use 'true', it's too misleading. Maybe 'truth' instead.)

 This notion of object identity would allow you, for instance, to match an 
 applicant to a school by letting the applicant's attribute 'matched_school' 
 directly point to a school itself, instead of a number that indirectly 
 represents the school.

 Also, you've got a collection of schools and applicants, which probably means 
 they will be stored in a set or a list. Once you have a type for them, it's 
 easier to safely manipulate them in a unified manner. Even if they have only 
 one single data attribute, I would do it: this also brings a centralised 
 place to expose the object type's structure and behaviour.

  2, is it possible to have a class for the algorithm that will modify
  values in the applicant and schools class
 for example applicant.matched = 4 and school.matched = 343 meaning
 applicant 343 is matched to school 4

 No, if I understand what you mean. You won't have a separate class only to 
 store actions (python is not java), but instead you should precisely 
 attribute these as methods to the Applicant or School types.

 3, is I have a value set in a class applicant.foo = 5 and I what to
 use a (method?) in the class to change this, what is the right way to
 do this?

 Below an example:

 
 class Point(object):
        def __init__(self, x=0,y=0):
                self.x = x
                self.y = y
        def move(self, dx,dy):
                print self,
                self.x += dx
                self.y += dy
                print -- %s % self
        def __str__(self):
                return Point (%s,%s) % (self.x,self.y)

 p0 = Point() ; print p0
 p = Point(9,8) ; print p
 p.move(-11,11)
 
 ==
 
 Point (0,0)
 Point (9,8)
 Point (9,8) -- Point (-2,19)
 

 Denis
 --
 la vita e estrany
 ___
 Tutor maillist  -  tu...@python.org
 http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] question about class

2009-06-09 Thread Vincent Davis
Thanks again for the help, A little followup.
For my applicant class I have a few initial values that need to be set
but I what to choose the value (actually the calculation to set the
value) for each applicant (instance?)
Here is the start of my Applicant Class

class Applicant(object):
  quality is refers to the quality of the Applicant
  observe refers to the accuracy of which they assess the
quality of the school
  def __init__(self, quality = 0, observe = 0):
  self. quality = quality
  self. observe = observe
  def Quality(self, mean, sd):
  print self,
  self.quality = normalvariate(mean, sd)
  print -- %s % self
 def Observe(self, mean, sd):
  print self,
  self. observe = normalvariate(mean, sd)
  print -- %s % self

Or I could I guess do it this way, Is this better? I will only be
setting the quality and observe values once for each instance.

class Applicant(object):
  quality is refers to the quality of the Applicant
 observe refers to the accuracy of which they assess the
quality of the school
  def __init__(self, mquality = 0, sdquality = 0, mobserve = 0,
sdobserve = 0):
  self. quality = normalvariate(mquality, sdquality)
  self. observe = normalvariate(mobserve, sdobserve)


Thanks
Vincent Davis
720-301-3003




On Tue, Jun 9, 2009 at 7:02 AM, Vincent Davisvinc...@vincentdavis.net wrote:
 Thanks for the help and comments, I think my questions have been
 answered, I will know if I understand when I try to implement them.
 The Match algorithm. algorithm is described in the link below. The
 Applicant and School rankings will be (Attributes ?) of the Applicant
 and School class, and I simulate this ranking process by considering
 Applicants and Schools attributes, but basically similar qualities get
 mutually ranked. (I go go on if someone is interested but I thought it
 best to keep the discution on what I am trying to learn about classes)

 http://www.nrmp.org/res_match/about_res/algorithms.html

 Thanks Again
 Vincent Davis




 On Tue, Jun 9, 2009 at 1:12 AM, spirdenis.s...@free.fr wrote:
 Le Mon, 8 Jun 2009 17:31:23 -0600,
 Vincent Davis vinc...@vincentdavis.net s'exprima ainsi:

 Accidentally sent I have added the rest
 (by the way I refrain from using the terms attribute, method, as I
 will likely miss use them)

  I am reading several tutorials about classes and trying to figure out
  how to apply it to my project. I have a working program that basically
  matches up applicants and schools. Schools and applicants have and
  true quality and an observed quality. Then there is an algorithm
  that matches them up. Right now I do this all with lists which works
  ok but I would like to try using classes.

  Questions
  1, does it make seens to have a applicant and a schools class (based
  on this brief explanation)

 Based on your explanations, I don't really understand the problem you're 
 trying to solve, nore the algorithm. Still, probably it makes sense to use 
 Applicant and School classes for the simple reason these notions in your 
 program represent objects: there are single, identified, things ; as 
 opposed to values (in the ordinary sense of the term) that represent 
 qualities or information such as color, position, number, or true and 
 observed above.
 (By the way, don't use 'true', it's too misleading. Maybe 'truth' instead.)

 This notion of object identity would allow you, for instance, to match an 
 applicant to a school by letting the applicant's attribute 'matched_school' 
 directly point to a school itself, instead of a number that indirectly 
 represents the school.

 Also, you've got a collection of schools and applicants, which probably 
 means they will be stored in a set or a list. Once you have a type for them, 
 it's easier to safely manipulate them in a unified manner. Even if they have 
 only one single data attribute, I would do it: this also brings a 
 centralised place to expose the object type's structure and behaviour.

  2, is it possible to have a class for the algorithm that will modify
  values in the applicant and schools class
 for example applicant.matched = 4 and school.matched = 343 meaning
 applicant 343 is matched to school 4

 No, if I understand what you mean. You won't have a separate class only to 
 store actions (python is not java), but instead you should precisely 
 attribute these as methods to the Applicant or School types.

 3, is I have a value set in a class applicant.foo = 5 and I what to
 use a (method?) in the class to change this, what is the right way to
 do this?

 Below an example:

 
 class Point(object):
        def __init__(self, x=0,y=0):
                self.x = x
                self.y = y
        def move(self, dx,dy):
                print self,
                self.x += dx
                self.y += dy
                print -- %s % self

[Tutor] question about class

2009-06-08 Thread Vincent Davis
I am reading several tutorials about classes and trying to figure out
how to apply it to my project. I have a working program that basically
matches up applicants and schools. Schools and applicants have and
true quality and an observed quality. Then there is an algorithm
that matches them up. Right now I do this all with lists which works
ok but I would like to try using classes.

Questions
1, does it make seens to have a applicant and a schools class (based
on this brief explanation)
2, is it possible to have a class for the algorithim that will modify
values in the applicant and schools class

Thanks
Vincent Davis
720-301-3003
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about class

2009-06-08 Thread Vincent Davis
Accidentally sent I have added the rest
(by the way I refrain from using the terms attribute, method, as I
will likely miss use them)

 I am reading several tutorials about classes and trying to figure out
 how to apply it to my project. I have a working program that basically
 matches up applicants and schools. Schools and applicants have and
 true quality and an observed quality. Then there is an algorithm
 that matches them up. Right now I do this all with lists which works
 ok but I would like to try using classes.

 Questions
 1, does it make seens to have a applicant and a schools class (based
 on this brief explanation)
 2, is it possible to have a class for the algorithm that will modify
 values in the applicant and schools class
for example applicant.matched = 4 and school.matched = 343 meaning
applicant 343 is matched to school 4

3, is I have a value set in a class applicant.foo = 5 and I what to
use a (method?) in the class to change this, what is the right way to
do this?

Ok that's all for now
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor