read csv error question

2009-02-23 Thread Vincent Davis
I am trying to read a csv file from excel on a mac. I get the following
error.SystemExit: file some.csv, line 1: new-line character seen in unquoted
field - do you need to open the file in universal-newline mode?
I was using the example code
import csv, sys

reader = csv.reader(open('/Volumes/vincentdavis
2/match/data/matchdata2008.csv', rb))
try:
for row in reader:
print row
except csv.Error, e:
sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))

I think this has to do with the end of line character but I am unsure how to
fix it. I don't what to change the actual csv file I would like to fix the
code.

Thanks
Vincent Davis
--
http://mail.python.org/mailman/listinfo/python-list


Re: read csv error question

2009-02-23 Thread Vincent Davis
Thanks for the help the U was what I needed. I was reading the
documentation here.http://docs.python.org/library/csv.html
but I could not find the term universal-newline mode, In fact where do you
find U I have not read it word for word but it is not obvious to me. I do
even see anything about rb but I might just be really blind.

Thanks again

Vincent Davis



On Mon, Feb 23, 2009 at 4:52 PM, Benjamin Kaplan
benjamin.kap...@case.eduwrote:



 On Mon, Feb 23, 2009 at 6:43 PM, MRAB goo...@mrabarnett.plus.com wrote:

 Vincent Davis wrote:

 I am trying to read a csv file from excel on a mac. I get the following
 error.
 SystemExit: file some.csv, line 1: new-line character seen in unquoted
 field - do you need to open the file in universal-newline mode?
 I was using the example code
 import csv, sys

 reader = csv.reader(open('/Volumes/vincentdavis
 2/match/data/matchdata2008.csv', rb))
 try:
for row in reader:
print row
 except csv.Error, e:
sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))

 I think this has to do with the end of line character but I am unsure how
 to fix it. I don't what to change the actual csv file I would like to fix
 the code.

  FYI, Mac line endings are carriage-return '\r', Linux line endings are
 linefeed '\n', and Windows endings are _both_ '\r\n'.


 Just to clarify, only the old Mac OSes (1-9) use carriage returns. OS X is
 Unix-based so it uses line feeds.





 --
 http://mail.python.org/mailman/listinfo/python-list



 --
 http://mail.python.org/mailman/listinfo/python-list


--
http://mail.python.org/mailman/listinfo/python-list


Re: read csv error question

2009-02-23 Thread Vincent Davis
I just thought to look in the documentation for open() It seems this may
contain the answers to my questions. I am just to new to python to know
where my problem is,
Thanks
Vincent Davis
720-301-3003


On Mon, Feb 23, 2009 at 4:52 PM, Benjamin Kaplan
benjamin.kap...@case.eduwrote:



 On Mon, Feb 23, 2009 at 6:43 PM, MRAB goo...@mrabarnett.plus.com wrote:

 Vincent Davis wrote:

 I am trying to read a csv file from excel on a mac. I get the following
 error.
 SystemExit: file some.csv, line 1: new-line character seen in unquoted
 field - do you need to open the file in universal-newline mode?
 I was using the example code
 import csv, sys

 reader = csv.reader(open('/Volumes/vincentdavis
 2/match/data/matchdata2008.csv', rb))
 try:
for row in reader:
print row
 except csv.Error, e:
sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))

 I think this has to do with the end of line character but I am unsure how
 to fix it. I don't what to change the actual csv file I would like to fix
 the code.

  FYI, Mac line endings are carriage-return '\r', Linux line endings are
 linefeed '\n', and Windows endings are _both_ '\r\n'.


 Just to clarify, only the old Mac OSes (1-9) use carriage returns. OS X is
 Unix-based so it uses line feeds.





 --
 http://mail.python.org/mailman/listinfo/python-list



 --
 http://mail.python.org/mailman/listinfo/python-list


--
http://mail.python.org/mailman/listinfo/python-list


PYTHONPATH on Mac 10.5

2009-02-25 Thread Vincent Davis
I have looked around for a good howto setup PYTHONPATH on Mac os x
10.5 Although I get many results I am not sure which is correct. I am not
sure if it is different for 10.5 over previous versions. Does anyone know of
a well documented set of instructions.
In my python scripts I specify which python I want to use like this
#!/Library/Frameworks/Python.framework/Versions/4.1.30101/bin/python

Is there a way to specify a module location or working directory? Which is
best? Or should I just add location to PYTHONPATH?


Thanks
Vincent Davis
--
http://mail.python.org/mailman/listinfo/python-list


help understanding class or function

2009-03-05 Thread Vincent Davis
If I have a list and I what to make changes to it.a = [1,2,3,4,5,6,7,8,9]
and maybe I want to drop the odd and double the  even numbers and I will
need to do this repeatedly.
How is this best done? That is as a function or class. All I know how to do
is

def doubleeven(alist):
blist = [2*x for x in a if x % 2 ==0]
   return blist

then when I am using it I do this

a = doubleeven(a)
I what to keep it named a

I am not sure if this is the best way in terms of format or structure. Is
there a better way.

Thanks
Vincent Davis
720-301-3003
--
http://mail.python.org/mailman/listinfo/python-list


Re: help understanding class or function

2009-03-05 Thread Vincent Davis
I guess I am thinking of it as an operation that I am preforming on a list
and not making a new list. Also looking to learn better methods. This is
difficult when you are working alone. It is difficult to know where to
improve.
The actual functions I am making are more complicated than this example.
Thanks
Vincent Davis
720-301-3003


On Thu, Mar 5, 2009 at 5:13 PM, Gabriel Genellina gagsl-...@yahoo.com.arwrote:

 En Thu, 05 Mar 2009 14:43:12 -0200, Vincent Davis 
 vinc...@vincentdavis.net escribió:


  If I have a list and I what to make changes to it.a = [1,2,3,4,5,6,7,8,9]
 and maybe I want to drop the odd and double the  even numbers and I will
 need to do this repeatedly.
 How is this best done? That is as a function or class. All I know how to
 do
 is

 def doubleeven(alist):
blist = [2*x for x in a if x % 2 ==0]
   return blist

 then when I am using it I do this

 a = doubleeven(a)
 I what to keep it named a

 I am not sure if this is the best way in terms of format or structure. Is
 there a better way.


 I don't grasp what you're worried about... Your function does exactly what
 you have specified above, so it's correct. Don't you like the fact that it
 returns a *new* list instead of modifying the original one in-place? You may
 use:

 a[:] = doubleeven(a)

 Or rewrite the function using a while loop (to avoid having two lists alive
 at the same time), but I would not bother unless there are strong reasons
 (the lists is really huge, or there is very few memory available).

 --
 Gabriel Genellina

 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: How to import Python files in the other directories?

2009-03-06 Thread Vincent Davis
If the documentation is not clear to you as it was not to me, the following
adds the search path, /Volumes/iDisk/match/python/matchmod, to the list of
places python looks for modules, I have this included  as an
import statement at the beginning of a program.

from sys import path
path.append(/Volumes/iDisk/match/python/matchmod)

Thanks
Vincent Davis
720-301-3003


On Fri, Mar 6, 2009 at 12:10 AM, Christian Heimes li...@cheimes.de wrote:

 Muddy Coder schrieb:
  Hi Folks,
 
  If I have a python file foo.py in the current directory, I can simply
  import it in the way below:
 
  import foo
 
  when a project keeps grow, more and more Python files are created, and
  they are also needed to put into different directories. Then, a
  problem comes: how to import the Python files residing in the other
  directories? Somebody helps me out? Thanks!

 Use packages: http://docs.python.org/tutorial/modules.html#packages

 Christian

 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


engadget; a language that few understand these days (it's Python, and no, we're not joking)

2009-03-17 Thread Vincent Davis
Thought you might find his interesting.

A standalone Eye-Fi server has now been presented to the general public,
and while it's written in a language that few understand these days (it's
Python, and no, we're not joking), the functionality here is second to
none.
http://www.engadget.com/2009/03/17/sandalone-eye-fi-server-hack-one-ups-eye-fi-manager/

Thanks
Vincent Davis
720-301-3003
--
http://mail.python.org/mailman/listinfo/python-list


understanding nested lists?

2009-01-24 Thread Vincent Davis
I have a short peace of code that is not doing what I expect. when I assign
a value to a list in a list alist[2][4]=z this seems replace all the 4
elements in all the sub lists. I assume it is supposed to but this is not
what I expect. How would I assign a value to the 4th element in the 2nd
sublist. here is the code I have. All the printed values are what I would
expect except that all sublist values are replaced.
Thanks for your help
Vincent

on the first iteration I get ;
new_list [[None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None], [None,
0, 1, None], [None, 0, 1, None], [None, 0, 1, None]]

and expected this;
new_list [[None, 0, 1, None], [None, None, None, None], [None, None, None,
None], [None, None, None, None], [None, None, None, None],
[None, None, None, None]]

Code;
list1=[[1,2],[0,3,2,1],[0,1,3],[2,0,1],[3],[2,3]]
new_list=[[None]*4]*6
print 'new_list',new_list
for sublist in range(6): # 6 becuase it is the # of rows lists1
print 'sublist', sublist
for x in list1[sublist]:
print list1[sublist]
print 'new_list[sublist][x]', new_list[sublist][x]
new_list[sublist][x]=list1[sublist].index(x)
print 'sublist', sublist, 'x', x
print new_list[sublist][x]
print 'new_list', new_list
--
http://mail.python.org/mailman/listinfo/python-list


Re: understanding nested lists?

2009-01-24 Thread Vincent Davis
Thanks for the info. I did not know that.
Thanks
Vincent Davis



On Sat, Jan 24, 2009 at 10:46 AM, Steve Holden st...@holdenweb.com wrote:

 Vincent Davis wrote:
  I have a short peace of code that is not doing what I expect. when I
  assign a value to a list in a list alist[2][4]=z this seems replace all
  the 4 elements in all the sub lists. I assume it is supposed to but this
  is not what I expect. How would I assign a value to the 4th element in
  the 2nd sublist. here is the code I have. All the printed values are
  what I would expect except that all sublist values are replaced.
 
  Thanks for your help
  Vincent
 
  on the first iteration I get ;
  new_list [[None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None],
  [None, 0, 1, None], [None, 0, 1, None], [None, 0, 1, None]]
 
  and expected this;
  new_list [[None, 0, 1, None], [None, None, None, None],
  [None, None, None, None], [None, None, None, None], [None, None, None,
  None], [None, None, None, None]]
 
  Code;
  list1=[[1,2],[0,3,2,1],[0,1,3],[2,0,1],[3],[2,3]]
  new_list=[[None]*4]*6
  print 'new_list',new_list
  for sublist in range(6): # 6 becuase it is the # of rows lists1
  print 'sublist', sublist
  for x in list1[sublist]:
  print list1[sublist]
  print 'new_list[sublist][x]', new_list[sublist][x]
  new_list[sublist][x]=list1[sublist].index(x)
  print 'sublist', sublist, 'x', x
  print new_list[sublist][x]
  print 'new_list', new_list
 
 When you create new_list you are actually filling it with six references
 to the same list. Consequently when you change one of those list
 elements they all appear to change (because they are all referencing the
 same list object).

 Try instead

 new_list = [[None]*4 for i in range(6)]

 and you should find your code works as expected. In this case the list
 is constructed with a new sublist as each element.

 regards
  Steve
 --
 Steve Holden+1 571 484 6266   +1 800 494 3119
 Holden Web LLC  http://www.holdenweb.com/

 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


print formating for matrix/table

2009-01-26 Thread Vincent Davis
I have a list of listsa matrix in that all sub lists are the
same length. I there a nice why to prin these so that the columns and rows
line up nicely?
I have looked around for a good way to do this and haven't found one I am
like. It seems that all involve repeating a print for each line. I would
have thought I could find a prebuilt function to do this. Surly lots of
people are printing matrixes and would like nice formating. So what am I
missing?
Vincent Davis
720-301-3003
--
http://mail.python.org/mailman/listinfo/python-list


Re: print formating for matrix/table

2009-01-26 Thread Vincent Davis
I do have numpy but am using lists as did not need any functions of array.
Well maybe print now. I am new to python and don't really know the details
about the difference between lists and arrays. I do know that there are
different/additional functions available for arrays.Anyway is this the best
solution, convert the list to an array before printing?

Thanks
Vincent Davis



On Mon, Jan 26, 2009 at 5:23 PM, Robert Kern robert.k...@gmail.com wrote:

 On 2009-01-26 18:18, Vincent Davis wrote:

 I have a list of listsa matrix in that all sub lists are the same
 length. I there a nice why to prin these so that the columns and rows
 line up nicely?
 I have looked around for a good way to do this and haven't found one I
 am like. It seems that all involve repeating a print for each line. I
 would have thought I could find a prebuilt function to do this. Surly
 lots of people are printing matrixes and would like nice formating. So
 what am I missing?


 Most people using matrices are also using numpy, and numpy arrays do print
 with columns lined up.

 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless
 enigma
  that is made terrible by our own mad attempt to interpret it as though it
 had
  an underlying truth.
  -- Umberto Eco

 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: print formating for matrix/table

2009-01-26 Thread Vincent Davis
I called it a matrix mostly because this is how I am visualizing it. They
are full of numbers but only as representatives of students and schools. It
looks like pprint will work after I read the instructions. At least I know
where to look now. In the end I need to figure out how to save the data a
csv formated for excel but that is for later I was just trying to make
it easier to debug my code.
Thanks
Vincent Davis
720-301-3003


On Mon, Jan 26, 2009 at 7:03 PM, Robert Kern robert.k...@gmail.com wrote:

 On 2009-01-26 19:53, Vincent Davis wrote:

 I do have numpy but am using lists as did not need any functions of
 array. Well maybe print now. I am new to python and don't really know
 the details about the difference between lists and arrays. I do know
 that there are different/additional functions available for arrays.


 Python lists are one-dimensional, appendable sequences of heterogeneous
 Python objects. numpy arrays are multi-dimensional, non-appendable
 containers usually of homogeneously-typed numerical data (but can also
 contain heterogeneous Python objects, too). numpy arrays have many
 conveniences over lists of lists if you need to do math on bunches of
 numbers.

  Anyway is this the best solution, convert the list to an array before
 printing?


 I wouldn't use numpy *just* for this, but I suspect that you could actually
 use numpy for other things if you are actually using your lists of lists as
 matrices.


 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless
 enigma
  that is made terrible by our own mad attempt to interpret it as though it
 had
  an underlying truth.
  -- Umberto Eco

 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


regular expression, help

2009-01-27 Thread Vincent Davis
I think there are two parts to this question and I am sure lots I am
missing. I am hoping an example will help meI have a html doc that I am
trying to use regular expressions to get a value out of.
here is an example or the line
td colspan='2'Parcel ID: 39-034-15-009 /td
I want to get the number 39-034-15-009 after Parcel ID: The number will
be different each time but always the same format.
I think I can match Parcel ID: but not sure how to get the number after.
Parcel ID: only occurs once in the document.

is this how i need to start?
pid = re.compile('Parcel ID: ')

Basically I am completely lost and am not finding examples I find helpful.

I am getting the html using myurl=urllib.urlopen().
Can I use RE like this
thenum=pid.match(myurl)


I think the two key things I need to know are
1, how do I get the text after a match?
2, when I use myurl=urllib.urlopen(http://...). can I use the myurl as
the string in a RE, thenum=pid.match(myurl)

Thanks
Vincent
--
http://mail.python.org/mailman/listinfo/python-list


regular expression, help

2009-01-27 Thread Vincent Davis
I think there are two parts to this question and I am sure lots I am
missing. I am hoping an example will help meI have a html doc that I am
trying to use regular expressions to get a value out of.
here is an example or the line
td colspan='2'Parcel ID: 39-034-15-009 /td
I want to get the number 39-034-15-009 after Parcel ID: The number will
be different each time but always the same format.
I think I can match Parcel ID: but not sure how to get the number after.
Parcel ID: only occurs once in the document.

is this how i need to start?
pid = re.compile('Parcel ID: ')

Basically I am completely lost and am not finding examples I find helpful.

I am getting the html using myurl=urllib.urlopen().
Can I use RE like this
thenum=pid.match(myurl)


I think the two key things I need to know are
1, how do I get the text after a match?
2, when I use myurl=urllib.urlopen(http://...). can I use the myurl as
the string in a RE, thenum=pid.match(myurl)

Thanks
Vincent
--
http://mail.python.org/mailman/listinfo/python-list


Re: How many followers of comp.lang.python

2009-01-27 Thread Vincent Davis
Being a newbie and not aware of other good places to ask dump questions. I
have been very happy with the help I have gotten. Some of the
other discussions are a little interesting to me but I wonder/am grateful if
these keep the knowledgeable people around so us newbies can ask questions.
Since I am a beginner programer and new to python it is really help to have
a place to ask quick or long questions. Books are nly so good, Google helps
but it doesn't debug code for you.
Thanks
Vincent Davis



On Tue, Jan 27, 2009 at 10:13 AM, Grant Edwards inva...@invalid wrote:

 On 2009-01-27, Bruno Desthuilliers
 bruno.42.desthuilli...@websiteburo.invalid wrote:

  Please visit comp.databases or comp.lang.javascript for really
  unfriendly and unhelpful places where few happens except
  bickering and name-calling.

 I've always found comp.lang.c to be a rather dangerous place as
 well.

 Of the newsgroups I read, c.l.python is probably the most
 friendly and has one of the highest S/N ratios.  People who
 would have been roasted alive in other newsgroups for their
 laziness or presumptuousness get surprisingly gentle treatment
 in c.l.python.  I do know of a few low-volume mailing lists
 that are probably as good, but for a Usenet news group with any
 volume at all, c.l.pythong is exceptionally good.

 --
 Grant Edwards   grante Yow! I wonder if I
 should
  at   put myself in ESCROW!!
   visi.com
 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: regular expression, help

2009-01-27 Thread Vincent Davis
is BeautifulSoup really better? Since I don't know either I would prefer to
learn only one for now.
Thanks
Vincent Davis



On Tue, Jan 27, 2009 at 10:39 AM, MRAB goo...@mrabarnett.plus.com wrote:

 Vincent Davis wrote:

 I think there are two parts to this question and I am sure lots I am
 missing. I am hoping an example will help me
 I have a html doc that I am trying to use regular expressions to get a
 value out of.
 here is an example or the line
 td colspan='2'Parcel ID: 39-034-15-009 /td
 I want to get the number 39-034-15-009 after Parcel ID: The number
 will be different each time but always the same format.
 I think I can match Parcel ID: but not sure how to get the number after.
 Parcel ID: only occurs once in the document.

 is this how i need to start?
 pid = re.compile('Parcel ID: ')

 Basically I am completely lost and am not finding examples I find helpful.

 I am getting the html using myurl=urllib.urlopen(). Can I use RE like this
 thenum=pid.match(myurl)

 I think the two key things I need to know are
 1, how do I get the text after a match?
 2, when I use myurl=urllib.urlopen(http://...). can I use the myurl
 as the string in a RE, thenum=pid.match(myurl)

  Something like:

 pid = re.compile(r'Parcel ID: (\d+(?:-\d+)*)')
 myurl = urllib.urlopen(url)
 text = myurl.read()
 myurl.close()
 thenum = pid.search(text).group(1)

 Although BeautifulSoup is the preferred solution.
 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


change syntax coloring in IDLE

2009-01-27 Thread Vincent Davis
I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it
states I can change he text coloring by using Configure IDLE but I not
sure what this is. It's not sn the menu, running Configure does nothing. How
do I change the color (text and background)
Thanks
Vincent Davis
--
http://mail.python.org/mailman/listinfo/python-list


Re: change syntax coloring in IDLE

2009-01-27 Thread Vincent Davis
I am using EPD with Py2.5 4.0.30002when I try to launch IDLE.app which is
in the above folder i get  -bash: IDLE.app: command not found
which is strange because when I do ls it is listed.
the path to the folder is
/Applications/EPD\ with\ Py2.5\ 4.0.30002
ls returns
Build Applet.app Mayavi.terminal
Docs Pylab.terminal
Examples Python Launcher.app
Extras Update Shell Profile.command
IDLE.app

Then I do/get
vincent-daviss-macbook-pro:EPD with Py2.5 4.0.30002 vmd$ IDLE.app
-bash: IDLE.app: command not found

Not sure what I am doing wrong

Is the a way do download a new version of IDLE.app?

That last part is ugh!

Thanks
Vincent Davis


On Tue, Jan 27, 2009 at 12:40 PM, Ned Deily n...@acm.org wrote:

 In article
 77e831100901270950i6b0b510chf80a495a65ca9...@mail.gmail.com,
  Vincent Davis vinc...@vincentdavis.net wrote:
  I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it
  states I can change he text coloring by using Configure IDLE but I not
  sure what this is. It's not sn the menu, running Configure does nothing.
 How
  do I change the color (text and background)

 There is supposed to be a Preferences menu option for IDLE on OS X but,
 depending on the Python version and how IDLE is launched, it may or may
 not appear due to various bugs.  (I'm working on some patches for these.)

 If you have been launching IDLE via /Applications/MacPython
 2.5/IDLE.app, try launching it via the shell command line:
 /usr/local/bin/idle2.5.  There may now be a working Preferences menu
 item under the Python item in the menu bar; there may also be an Options
 - Configure IDLE... .   If that doesn't work, it should be possible to
 copy the default def files from idlelib in the python installation to
 your .idlerc directory and manually edit them there - ugh!.  Something
 like:

 $ cd `python2.5 -c 'import sys; print sys.prefix'`
 $ cd lib/python2.5/idlelib
 $ ls *.def
 config-extensions.def config-highlight.def  config-keys.def
 config-main.def
 $ cp -i *.def ~/.idlerc
 $ cd ~/.idlerc
 $ vi ...

 --
  Ned Deily,
  n...@acm.org

 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: change syntax coloring in IDLE

2009-01-27 Thread Vincent Davis
using terminal and openingIn Vincent's case (EPD), this would be
/Library/Frameworks/Python/Versions/Current/bin/idle2.5

Worked!!
Thanks for the help.
Vincent Davis



On Tue, Jan 27, 2009 at 2:42 PM, Robert Kern robert.k...@gmail.com wrote:

 On 2009-01-27 13:40, Ned Deily wrote:

 In article
 77e831100901270950i6b0b510chf80a495a65ca9...@mail.gmail.com,
  Vincent Davisvinc...@vincentdavis.net  wrote:

 I am using mac with python 2.5.2 and IDLE verison 1.2.2. in the help it
 states I can change he text coloring by using Configure IDLE but I not
 sure what this is. It's not sn the menu, running Configure does nothing.
 How
 do I change the color (text and background)


 There is supposed to be a Preferences menu option for IDLE on OS X but,
 depending on the Python version and how IDLE is launched, it may or may
 not appear due to various bugs.  (I'm working on some patches for these.)


 I'd love to get these patches so we can include them in EPD. Is there an
 issue on the Python bug tracker that I can follow?

  If you have been launching IDLE via /Applications/MacPython
 2.5/IDLE.app, try launching it via the shell command line:
 /usr/local/bin/idle2.5.


 In Vincent's case (EPD), this would be
 /Library/Frameworks/Python/Versions/Current/bin/idle2.5 .

  There may now be a working Preferences menu
 item under the Python item in the menu bar; there may also be an Options
 -  Configure IDLE... .


 Yes, to both.

 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless
 enigma
  that is made terrible by our own mad attempt to interpret it as though it
 had
  an underlying truth.
  -- Umberto Eco


 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


program organization question

2009-01-28 Thread Vincent Davis
Basically my program simulates the Medical Residency Match, generating
simulated data, running the match and then summarizing results. Currently it
does this all in one document (starting conditions--Gen data--run
match--summarize results). I will be running multiple simulations on
different starting condition and data generation. My question is how should
I organize this. My plane was to have a separate document for staring
conditions, data generation because these will change for each simulation.
Then on for the match a summarizing data as this will always be the same
except for saving the results as different names.
I don't even know how to pass data from on program to another although I
think I can figure this out.

Any guidance?

Thanks
Vincent Davis
--
http://mail.python.org/mailman/listinfo/python-list


question about Z=[[x for y in range(1,2) if AList[x]==y] for x in range(0,5)]

2009-02-01 Thread Vincent Davis
Z=[[x for y in range(1,2) if AList[x]==y] for x in range(0,5)]
I am not sure how to ask this but which for is looped first? I could
test but was wondering if there was a nice explanation I could apply
to future situations.

Thanks
Vincent Davis
720-301-3003
--
http://mail.python.org/mailman/listinfo/python-list


faster scipy.percentileofscore ?

2009-02-02 Thread Vincent Davis
Currently I am using the following:
pgrades = [scipy.percentileofscore(grades,x) for x in grades]

I need the percentile of each number in grades. The problem is that it
takes a long time (a few minutes) because there are 15,000 items in
the list.
does anyone know is there is a faster way?

Thanks
Vincent Davis
720-301-3003
--
http://mail.python.org/mailman/listinfo/python-list


Re: faster scipy.percentileofscore ?

2009-02-02 Thread Vincent Davis
Did not know about http://www.scipy.org/Mailing_Lists but did not look,

Thanks for the help
Vincent Davis




On Mon, Feb 2, 2009 at 11:28 AM, Robert Kern robert.k...@gmail.com wrote:
 On 2009-02-02 12:08, Vincent Davis wrote:

 Currently I am using the following:
 pgrades = [scipy.percentileofscore(grades,x) for x in grades]

 I need the percentile of each number in grades. The problem is that it
 takes a long time (a few minutes) because there are 15,000 items in
 the list.
 does anyone know is there is a faster way?

 from scipy import stats
 pgrades = (stats.rankdata(grades)-1) / (len(grades)-1) * 100

 You will probably want to ask further scipy questions on the scipy mailing
 list.

  http://www.scipy.org/Mailing_Lists

 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it
 had
  an underlying truth.
  -- Umberto Eco

 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Use list name as string

2009-02-04 Thread Vincent Davis
Do to laking knowledge my google searches have not turned up an answer for me.
I know this is wrong it uses the items in the list as the filename,
how do I refer to the dataname and not the items in it.

def savedata(dataname):
filename = str(dataname)  # this does not do what I would like it to
ext1 = '\.csv'
flex = filename + ext1
datawrite = csv.writer(open(flex, wb))
datawrite.writerows(dataname)


Thanks
Vincent Davis
--
http://mail.python.org/mailman/listinfo/python-list


Re: Use list name as string

2009-02-04 Thread Vincent Davis
Sorry for not being clearI would have something like this
x = [1, 2, 3,5 ,6 ,9,234]

Then
def savedata(dataname): ..

savedata(x)

this would save a to a file called x.csv This is my problem, getting the
name to be x.csv which is the same as the name of the list.

and the data in the file would be
1,2,3,5,6,9,234 this parts works

Thanks
Vincent Davis
720-301-3003


On Wed, Feb 4, 2009 at 9:48 AM, Tim Chase python.l...@tim.thechases.comwrote:

 I know this is wrong it uses the items in the list as the filename,
 how do I refer to the dataname and not the items in it.


 Without a sample value for dataname, it's hard to tell what you're trying
 to do.  Do you mean

  dataname = ['path', 'to', 'file']
  ...
  filename = os.sep.join(dataname)

 Or you have a list of one value, and just want its first item?

  filename = dataname[0]

  def savedata(dataname):
filename = str(dataname) # this does not do what I would like it to


 It would help if you detailed what you *would* like it to do...

   from MindReading import answer
  Traceback (most recent call last):
File stdin, line 6, in comp.lang.python
  ImportError: No module named MindReading

 Similar failure attempting

   import dwim

 -tkc








--
http://mail.python.org/mailman/listinfo/python-list


Re: Use list name as string

2009-02-04 Thread Vincent Davis
I know nothing but that sucks. I can think of a lot of times I would like to
do something similar. There really is no way to do this, it seems like there
would be some simple way kind of like str(listname) but backwards or
different.
Thanks
Vincent Davis



On Wed, Feb 4, 2009 at 10:07 AM, MRAB goo...@mrabarnett.plus.com wrote:

 Vincent Davis wrote:
  Sorry for not being clear I would have something like this x = [1, 2,
  3,5 ,6 ,9,234]
 
  Then def savedata(dataname): ..
 
  savedata(x)
 
  this would save a to a file called x.csv This is my problem, getting
  the name to be x.csv which is the same as the name of the list.
 
  and the data in the file would be 1,2,3,5,6,9,234 this parts works
 
 The list itself doesn't have a name. You need to pass in both the name
 and the list:

 def savedata(name, data): ..

 savedata(x, x)

 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: Use list name as string

2009-02-04 Thread Vincent Davis
I guess what I am saying is that it does not seem like I am adding any
information that is not already there when I have to enter that list and
list name after all they are the same.
Thanks
Vincent Davis



On Wed, Feb 4, 2009 at 10:18 AM, Vincent Davis vinc...@vincentdavis.netwrote:

 I know nothing but that sucks. I can think of a lot of times I would like
 to do something similar. There really is no way to do this, it seems like
 there would be some simple way kind of like str(listname) but backwards or
 different.
 Thanks
 Vincent Davis




 On Wed, Feb 4, 2009 at 10:07 AM, MRAB goo...@mrabarnett.plus.com wrote:

 Vincent Davis wrote:
  Sorry for not being clear I would have something like this x = [1, 2,
  3,5 ,6 ,9,234]
 
  Then def savedata(dataname): ..
 
  savedata(x)
 
  this would save a to a file called x.csv This is my problem, getting
  the name to be x.csv which is the same as the name of the list.
 
  and the data in the file would be 1,2,3,5,6,9,234 this parts works
 
 The list itself doesn't have a name. You need to pass in both the name
 and the list:

 def savedata(name, data): ..

 savedata(x, x)

 --
 http://mail.python.org/mailman/listinfo/python-list



--
http://mail.python.org/mailman/listinfo/python-list


Re: Use list name as string

2009-02-04 Thread Vincent Davis
can I do it the otherway, that issavedata('nameoflist')


Thanks
Vincent Davis
720-301-3003


On Wed, Feb 4, 2009 at 10:23 AM, Vincent Davis vinc...@vincentdavis.netwrote:

 I guess what I am saying is that it does not seem like I am adding any
 information that is not already there when I have to enter that list and
 list name after all they are the same.
 Thanks
 Vincent Davis




 On Wed, Feb 4, 2009 at 10:18 AM, Vincent Davis 
 vinc...@vincentdavis.netwrote:

 I know nothing but that sucks. I can think of a lot of times I would like
 to do something similar. There really is no way to do this, it seems like
 there would be some simple way kind of like str(listname) but backwards or
 different.
 Thanks
 Vincent Davis




 On Wed, Feb 4, 2009 at 10:07 AM, MRAB goo...@mrabarnett.plus.com wrote:

 Vincent Davis wrote:
  Sorry for not being clear I would have something like this x = [1, 2,
  3,5 ,6 ,9,234]
 
  Then def savedata(dataname): ..
 
  savedata(x)
 
  this would save a to a file called x.csv This is my problem, getting
  the name to be x.csv which is the same as the name of the list.
 
  and the data in the file would be 1,2,3,5,6,9,234 this parts works
 
 The list itself doesn't have a name. You need to pass in both the name
 and the list:

 def savedata(name, data): ..

 savedata(x, x)

 --
 http://mail.python.org/mailman/listinfo/python-list




--
http://mail.python.org/mailman/listinfo/python-list


Re: Use list name as string

2009-02-04 Thread Vincent Davis
if I start with
M = [1,3,5,7]
M is [1,3,5,7]
This seems one way, as [1,3,5,7] is not M in the sense that there is
no operation I can preform on [1,3,5,7] and get M back. Other than
asking/testing M==[1,3,5,7]
This seems fine to me. but when I savedata(M) it seems I should be
able to refer to both [1,3,5,7] and M, I mean I did just type it
why type it again)
My argument comes down to; we use M so we don't have to type
[1,3,5,7], I realize that this is in part because we might not no what
M will be.
This is starting to sound like double talk on my part, I have only
been programing in python for 2 weeks so my credibility is only that
of an outside that MAY have a reasonable way of thinking of this or at
least a feature I would like.

Thanks for the comments

by the way what is **kwargs I can't find any documentation on this?


Thanks
Vincent Davis




On Wed, Feb 4, 2009 at 5:09 PM, Rhodri James
rho...@wildebst.demon.co.uk wrote:
 On Wed, 04 Feb 2009 17:23:55 -, Vincent Davis vinc...@vincentdavis.net
 wrote:

 I guess what I am saying is that it does not seem like I am adding any
 information that is not already there when I have to enter that list and
 list name after all they are the same.
 Thanks

 But you are.  Consider just for a moment what happens when you execute
 savedata([1, 2, 3, 55]).

 Fundamentally, the concept of a single unique name for any object isn't
 something built into the language (or, indeed, most languages I can think
 of).  An object can have no names (though it'll promptly get garbage
 collected if it isn't assigned to a name somehow), or just as easily
 one or many names.

 --
 Rhodri James *-* Wildebeeste Herder to the Masses
 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: Use list name as string

2009-02-04 Thread Vincent Davis
The problem is you seem to be thinking in terms of objects having names.
They don't.  Names have objects.I agree this is my problem. This is not
correct terminology then?
The name of the object is anobject

Let me give another example and let me know if I am just beating a dead
horse.

In my current script I have may print statements to verify I am manipulating
my list as I hope.
I have many lines like;

print 'alist', alist

I need to print the names so I know what I am looking at on the output.
It would be nice if I could define fuction that did this
def lp(thelist):
magic occurs

Then I could just type

lp(alist)

note I am entering the name which has an object that is a list. I am not
entering [1,3,5,7]
and it would

print 'alist' alist

Does it not seem reasonable to what to do this.


Vincent Davis
720-301-3003


On Wed, Feb 4, 2009 at 7:55 PM, Rhodri James rho...@wildebst.demon.co.ukwrote:

 On Thu, 05 Feb 2009 01:36:17 -, Vincent Davis 
 vinc...@vincentdavis.net wrote:

  if I start with
 M = [1,3,5,7]
 M is [1,3,5,7]
 This seems one way, as [1,3,5,7] is not M in the sense that there is
 no operation I can preform on [1,3,5,7] and get M back. Other than
 asking/testing M==[1,3,5,7]


 Correct.  If you actually try that, you get this:

 Python 2.5.2 (r252:60911, May  7 2008, 15:21:12)
 [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
 Type help, copyright, credits or license for more information.

 M = [1,3,5,7]
 M is [1,3,5,7]

 False

 This isn't just me being funny with your suggested syntax, it's
 making an important point: the second [1,3,5,7] is an entirely
 different object to the list we named M, it just happens to
 contain the same data.

  This seems fine to me. but when I savedata(M) it seems I should be
 able to refer to both [1,3,5,7] and M, I mean I did just type it
 why type it again)
 My argument comes down to; we use M so we don't have to type
 [1,3,5,7], I realize that this is in part because we might not no what
 M will be.


 That's an oversimplification, and you're battering away well past the
 point where it works.  In any language, not just Python.

  This is starting to sound like double talk on my part, I have only
 been programing in python for 2 weeks so my credibility is only that
 of an outside that MAY have a reasonable way of thinking of this or at
 least a feature I would like.


 The problem is you seem to be thinking in terms of objects having names.
 They don't.  Names have objects.

 What I mean by that is that when you type M = [1,3,5,7], you are saying
 when I say 'M', substitute in this list (not just one that looks like it,
 this exact list.  When you type N = M, similarly you get the name N
 bound to the same exact list; if you then type N[1] = 2 and print out
 M, it'll show up as [1,2,5,7] -- it's still the same list under both names.
 In effect (to oversimplify more than a bit), Python looks up the name
 in a dictionary to get the object it represents.

 The reverse lookup doesn't exist, largely because it isn't unique.  Our
 [1,3,5,7] list has no idea what names, if any, refer to it, and in all
 but the most trivial cases the information isn't really meaningful.
 Suppose that we did have a getvariablename function, what would you
 expect the following code to do?

 def f(thing):
print getvariablename(thing)

 m = [1,3,5,7]
 for n in m:
f(n)


 Should it say n for all of them?  Or ['n', 'thing'], since 'thing'
 is after all a perfectly valid name for it?

 Then what about this:

 for i in range(len(m)):
f(m[i])


 Should it say m[i] for all of them, or m[0] m[1] and so on, or
 what?

  by the way what is **kwargs I can't find any documentation on this?


 http://docs.python.org/tutorial/controlflow.html#keyword-arguments

 In a function definition, **name mops up all the keyword arguments
 to the function that aren't explicit formal parameters into a
 dictionary called name, indexed by keyword.  kwargs seems to be
 the traditional name to use.  So:

  def demo(action, **kwargs):

 ...   print kwargs
 ...

 demo(action=dummy, text=wombats are go)

 {'text': 'wombats are go'}


 You can also use it the other way round to expand a dictionary into
 keyword parameters to a function call:

  myargs = { 'action': 'avoid', 'where': 'Camelot', 'because': 'it is a
 silly place' }
 demo(**myargs)

 {'because': 'it is a silly place', 'where': 'Camelot'}

 --
 Rhodri James *-* Wildebeeste Herder to the Masses
 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: Use list name as string

2009-02-04 Thread Vincent Davis
Jervis Whitley wrote Although you should really solve your problem by
thinking about it
from a completely different angle, maybe subclassing your datatype and
adding a 'name'
attribute ? I'm sure some of the others here have suggested that already.
That is beyond my current knowledge. Any suggestions for reading about this?

Thanks
Vincent Davis



On Wed, Feb 4, 2009 at 8:24 PM, Jervis Whitley jervi...@gmail.com wrote:

 On Thu, Feb 5, 2009 at 3:57 AM, Vincent Davis vinc...@vincentdavis.net
 wrote:
  Sorry for not being clear
  I would have something like this
  x = [1, 2, 3,5 ,6 ,9,234]
  Then
  def savedata(dataname): ..
 
  savedata(x)
  this would save a to a file called x.csv This is my problem, getting the
  name to be x.csv which is the same as the name of the list.
  and the data in the file would be
  1,2,3,5,6,9,234 this parts works

 It sounds like you would _really_ like to attach a name to this list of
 data.

 How about this terrible example to solve your problem.

 x = dict(x=[1,2,3,5,6,9,234])

 then
 def savedata(dataname):
   # extract the first key(name) and value(data) from the dataname data
 type.
   try:
  name, data = dataname.items()[0]
   except AttributeError:
  raise TypeError(Expecting a datatype that declares method 'items'
 :).)
   # we could catch other exceptions here but I wont (like empty items).


 now you have your name and your data variable.
 This way you don't declare your variable name when calling savedata
 but when you
 create your variable.

 Although you should really solve your problem by thinking about it
 from a completely
 different angle, maybe subclassing your datatype and adding a 'name'
 attribute ? I'm
 sure some of the others here have suggested that already.

 Cheers,

--
http://mail.python.org/mailman/listinfo/python-list


return multiple objects

2009-02-05 Thread Vincent Davis
Is it correct that if I want to return multiple objects from a function I
need to in some way combine them?
def test1():
a = [1,3,5,7]
b = [2,4,6,8]
c=[a,b]
   return a, b # this does not work?
   return [a, b] # does not work?
   return c # this works but I don't like it, , is there a better way?

I saw examples where dictionaries where used but I would prefer to
just access the object names directly. As in

test1()
print a # not haing to refer to it as

is there something I am missing?


Thanks
Vincent Davis
--
http://mail.python.org/mailman/listinfo/python-list


Re: return multiple objects

2009-02-05 Thread Vincent Davis
That is what I was missing,
Thanks
Vincent Davis



On Thu, Feb 5, 2009 at 8:37 PM, Rhodri James rho...@wildebst.demon.co.ukwrote:

 On Fri, 06 Feb 2009 03:03:01 -, Vincent Davis 
 vinc...@vincentdavis.net wrote:

  Is it correct that if I want to return multiple objects from a function I
 need to in some way combine them?
 def test1():
a = [1,3,5,7]
b = [2,4,6,8]
c=[a,b]
   return a, b # this does not work?
   return [a, b] # does not work?
   return c # this works but I don't like it, , is there a better way?


 Strictly speaking, you can only return one object from a function.
  However,
 that one object can be a container (list, tuple, dict, set, or what have
 you) that contains multiple objects.  Tuples are a popular choice:

  return a, b

 ...but almost any ordered type would do, because you can automagically
 unpack the results if you want to:

  x, y = test1()

 (You might be expecting brackets around the a, b and the x, y, and
 you'd be sort of right.  The brackets (parentheses) for tuples are
 optional, except for a couple of cases where you *have* to put them
 in to avoid ambiguity.  I tend to put them in always, but leaving them
 out in cases like this seems to be normal practice.)

 --
 Rhodri James *-* Wildebeeste Herder to the Masses
 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


simple web app, where to start

2009-02-06 Thread Vincent Davis
I have a simple script that takes a few input values and returns a csv file
and a few stats. If I wanted to host this on the web how would I. I have no
idea where to begin. If someone could point me in the right direction like
maybe a tutorial, tools I will need, functions. I would appreciate it.I
know a little html but am not sure how to integrate python or know what
servers will handle it .

Thanks
Vincent Davis
--
http://mail.python.org/mailman/listinfo/python-list


Re: simple web app, where to start

2009-02-07 Thread Vincent Davis
Thanks http://www.cherrypy.org/ looks like a good and simple option.
Thanks
Vincent Davis



On Sat, Feb 7, 2009 at 5:09 PM, n...@stinemates.org wrote:

 On Fri, Feb 06, 2009 at 09:16:02PM -0700, Vincent Davis wrote:
  I have a simple script that takes a few input values and returns a csv
 file
  and a few stats. If I wanted to host this on the web how would I. I have
 no
  idea where to begin. If someone could point me in the right direction
 like
  maybe a tutorial, tools I will need, functions. I would appreciate
 it.I
  know a little html but am not sure how to integrate python or know what
  servers will handle it .
 
  Thanks
  Vincent Davis

 I'd suggest CherryPy[1]. It's fairly welcoming to newbies, because the
 web server and the framework and bundled together.

 1: http://www.cherrypy.org/

 HTH,
 Nick

 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: MacPython 2.5 IDLE font size

2009-02-07 Thread Vincent Davis
There is a option menu in idle but you may not be able to see it.
Try launching idle via terminal. For me it was located
/Library/Frameworks/Python/Versions/Current/bin/idle2.5
When I did this I had the option menu, I guess this is a known bug. I assume
there is a font option once you get the menu.

Vincent Davis



On Sat, Feb 7, 2009 at 4:03 PM, choha...@gmail.com wrote:

 Hi,
 Is there a way to adjust the default font size in IDLE, in MacPython
 2.5? The default now is too tiny.
 I have to use this version of MacPython. As far as I searched, I can't
 find how I do this.
 Thanks.
 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: Spam

2009-02-12 Thread Vincent Davis
I am a little disturbed that there are no moderators,
mostly because I received an email back from the listYour mail to
'Python-list' with the subject. Above and beyond, critique request. Is being
held until the list moderator can review it for approval. The reason it is
being held: Message body is too big: 41670 bytes with a limit of 40
KB. Either the message will get posted to the list, or you will receive
notification of the moderator's decision.  If you would like to cancel
this posting, please visit the following URL:

So does this mean it will never actually be reviewed?

Thanks
Vincent Davis



On Thu, Feb 12, 2009 at 12:42 PM, Terry Reedy tjre...@udel.edu wrote:

 Terry Reedy wrote:

 andrew cooke wrote:

 A quick search on imap nntp turned up this list that might be useful -
 http://deflexion.com/messaging/ although I wonder when it was written
 because I remember using Aaron's RSS to email aggregator when RSS was
 new(!).

 It mentions gmane, though, which certainly still exists (I assume it
 carries this list too).


 Yes.  For everything possible, I read and post via gmane.  Gmane mirrors
 technical mailing lists.  As near as I can tell, posts via gmane go to the
 mailing list first, for whatever filtering the list does. Conversely then,
 gmane only posts the filtered output from the mailing list.

And this page suggests you can read gmane via

 nntp - http://reticule.gmane.org/


 news.gmane.org works fine.

  Aha!  yes!  It;s in the FAQ :o)

  Can I read news via secure NNTP (nntps)?
  Yes. Point your news reader towards nntps://snews.gmane.org/.

 http://www.gmane.org/faq.php


 I just switched my Thunderbird gmane account to snews... and [x] use ssl
 and it seems to work ok.  It did, however, reset everything to unread.


 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Above and beyond, A critique request

2009-02-15 Thread Vincent Davis
So I am new to python and not much of a programmer. Mostly program using
statistical packages. I been working on a project to simulate the
medical residency match for about 2 weeks. I don't know any python
programmers so I would greatly appreciate any comment or suggestions you may
have to improve my programing skills. My program does work but I have no
comparison or experience to know if I have used best practices. Suggestion
may be broad or specific all input is appreciated. I have
already benefited from the group and am appreciative of it.

Due to python-list@python.org limited post size I have only included the
final step. If someone is willing to review my complete program ~250 lines
it can be downloaded at http://vincentdavis.org/match

In word this is what it does.


   - Creates a population of institutions and applicants, quality and score
   are generated for each by drawing from a random dist.
   - The is an observation error, that is the institutions do not see the
   true applicant score and the applicant do not see the true institution
   quality.
   - applicants apply to institution that are near there ability
   - institutions reject if applicant is not qualified
   - applicant rank the institutions 0 best large values worse
   - institutions rank applicants
   - The Match is best described here
   http://www.nrmp.org/res_match/about_res/algorithms.html


I have a lot of print functions mostly to track what was going on during
development.

Thanks
Vincent Davis
720-301-3003

# NumApp  is the number of applicants
# NumInst  is the number of institutions
# ari  is a list of institutions rank by each applicant, [[5, 6, 2], [8, 3,
6, 2], [.  So applicant 1 ranked institution 2 first and institution
6 second, applicant 2 ranked institution 6 third
# ira  institutions ranking of applicants same format as ari but from the
institutions perspective
# iram  is a matrix version of ira, rows are applicants, colums are
institutions values represent the rank, that is the rank the institution
gave the applicant
# I think that is all that is used in this part that is not defined below.


 Starts here 
app_match = [None]*NumApp # the list of institution each applicant is
matched to
try_list = [] # makes a copy of ari
try_list.extend(ari) # makes a copy of ari
inst_match=[[] for x in range(NumInst)] # this is a list of applicants each
Institution accepted

#get list of applicants not matched

notmatched = [x for x in range(NumApp) if (app_match[x] == None and
len(try_list[x])  0)]

print 'notmatched', notmatched
print 'len(notmatched)', len(notmatched)
while len(notmatched)  0:
for x in notmatched:
try_inst = try_list[x][0] # try this institution
try_rank = ari[x].index(try_inst) # try_inst is ranked --
app_ranked = iram[x][try_inst] # this is what try_inst ranked the
applicant
print 'Try to match Applicant', x, ' to rank', try_rank, 'at inst',
try_inst
print 'Who is in inst', try_inst, inst_match[try_inst]
print 'Institution', try_inst, 'ranked applicant', x, app_ranked

ranklist = [iram[i][try_inst] for i in inst_match[try_inst]] # this
is the rank of each applicant matched to try_inst

if len(ranklist)  0:
max_rank = max(ranklist) # the max rank value lowest rank
max_app = inst_match[try_inst][ranklist.index(max_rank)] # the
applicant corresponding to max_rank

if len(inst_match[try_inst])  NumAccept : #Does the institution
have an empty spot.
print 'Institution', try_inst, 'has an empty spot for', x
inst_match[try_inst].append(x) # Add to institutions list
print x, 'in now in', try_inst, 'with', inst_match[try_inst]
app_match[x] = try_inst # assign inst to app
try_list[x].remove(try_inst) # remove the institution so it is
not tried later

elif (len(inst_match[try_inst]) == NumAccept and app_ranked 
max_rank) :
print 'Applicant',x , 'is ranked', app_ranked, 'which is higher
than', max_app, 'who was ranked', max_rank
print 'so applicant', x, 'bumps', max_app

app_match[max_app] = None
inst_match[try_inst].remove(max_app)

app_match[x] = try_inst
inst_match[try_inst].append(x)
try_list[x].remove(try_inst) # remove the institution so it is
not tried later

elif (len(inst_match[try_inst]) == NumAccept and iram[x][try_inst] 
max_rank) :
print 'Applicant',x , 'is ranked', app_ranked, 'which is Lower
than', max_app, 'who was ranked', max_rank
print 'therefor', x, 'does not match at', try_inst
try_list[x].remove(try_inst) # remove the institution so it is
not tried later

elif (len(inst_match[try_inst])  NumAccept) :
print ' to many matched to institution, fix
this, some thing is broke ###'

else:
print ' fix

Re: illegal list name

2009-02-15 Thread Vincent Davis
You probably have got 2.6 installed you just need to tell terminal to use
2.6, there should be a shell command inside the 2.6 folder that updates the
terminal to use 2.6 otherwise you start python by referring directly to the
python you need to use. Sorry I have no advise on mailman.

Thanks
Vincent Davis



On Sun, Feb 15, 2009 at 5:24 PM, Sandra Quiles sandr...@silverica.comwrote:


 Hello. I have followed the instructions of a post on Installing mailman on
 OS X 10.4, and got to step 7 and hit this error.

 The hard- and software involved is: OS X 10.4.x, Python 2.3.5, Mailman
 2.1.5 (using this outdated version because I don't know how to upgrade
 Python despite going to the Python site.  It wasn't obvious to me which
 Linux package was an upgrade, and the installation of MacPython 2.6.1 was
 not recognized by Terminal).

 So. illegal name error. it list listname as 'mailman@mycomputername'

 that's in response to the 'bin/newlist mailman' command

 also, I purchased the Postfix Enabler, but have no clue what to do with the
 software.

 Tips, advise, hand-holding welcomed.

 -- sandra

 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Re: code challenge: generate minimal expressions using only digits 1,2,3

2009-02-20 Thread Vincent Davis
Having looked long at this how does the prime factorization play into this.
I would consider an approach similar to factoring a number. Of course the
issue with prime factoring is your ned to know the primes. I assume this
would be a similar problem you may need to know the solutions to the
factors. I might look closer at this please post if you come across a
solution.
Thanks
Vincent Davis
720-301-3003


On Fri, Feb 20, 2009 at 7:31 AM, Trip Technician luke.d...@gmail.comwrote:

 anyone interested in looking at the following problem.

 we are trying to express numbers as minimal expressions using only the
 digits one two and three, with conventional arithmetic. so for
 instance

 33 = 2^(3+2)+1 = 3^3+(3*2)

 are both minimal, using 4 digits but

 33 = ((3+2)*2+1)*3

 using 5 is not.

 I have tried coding a function to return the minimal representation
 for any integer, but haven't cracked it so far. The naive first
 attempt is to generate lots of random strings, eval() them and sort by
 size and value. this is inelegant and slow.

 I have a dim intuition that it could be done with a very clever bit of
 recursion, but the exact form so far eludes me.
 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


A different take on finding primes

2009-11-14 Thread Vincent Davis
Out of pure curiosity I would like to compare the efficiency of different
methods of finding primes (need not be consecutive). Let me be clear, given
2min, how many primes can you find, they need not be in order or
consecutive. I have not seen any examples of this. I am assume the solution
is different depending on the time give,  2min or 2 hours. I assume a sieve
solution would be best for larger times. When the numbers get really large
checking to see if they are a prime gets costly.
So what do you think?

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Delaunay triangulation

2009-12-02 Thread Vincent Davis
Anyone know of a python implementation of Delaunay triangulation?

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Delaunay triangulation

2009-12-02 Thread Vincent Davis
Thanks for all the replies I will look at each.

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


On Wed, Dec 2, 2009 at 10:20 AM, sturlamolden sturlamol...@yahoo.no wrote:

 On 2 Des, 15:28, David Robinow drobi...@gmail.com wrote:
  On Tue, Dec 1, 2009 at 8:31 PM, Vincent Davis vinc...@vincentdavis.net
 wrote:
   Anyone know of a python implementation of Delaunay triangulation?
 
  Matplotlib has one.
  There's also Delny  @pypi
 
  It's been several years since I needed this. I can't remember the
 pros/cons.

 There is also a skikit add-on to NumPy/SciPy.

 http://scikits.appspot.com/delaunay
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


speed question, reading csv using takewhile() and dropwhile()

2010-02-19 Thread Vincent Davis
I have some some (~50) text files that have about 250,000 rows each. I am
reading them in using the following which gets me what I want. But it is not
fast. Is there something I am missing that should help. This is mostly an
question to help me learn more about python. It takes about 4 min right now.

def read_data_file(filename):
reader = csv.reader(open(filename, U),delimiter='\t')
read = list(reader)
data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x in
read])
data = [x for x in data_rows][1:]

mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow,
list(dropwhile(lambda drow: '[MASKS]' not in drow, read)))
mask = [row for row in mask_rows if row][3:]

outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, read)
outlier = [row for row in outlier_rows if row][3:]


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-19 Thread Vincent Davis
In reference to the several comments about [x for x in read] is basically a
copy of the entire list. This isn't necessary. or list(read). I had thought
I had a problem with having iterators in the takewhile() statement. I
thought I testes and it didn't work. It seems I was wrong. It clearly works.
I'll make this change and see if it is any better.

I actually don't plan to read them all in at once, only as needed, but I do
need the whole file in an array to perform some mathematics on them and
compare different files. So my interest was in making it faster to open them
as needed. I guess part of it is that they are about 5mb so I guess it might
be disk speed in part.
Thanks

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


On Fri, Feb 19, 2010 at 2:13 PM, Jonathan Gardner 
jgard...@jonathangardner.net wrote:

 On Fri, Feb 19, 2010 at 10:22 AM, Vincent Davis 
 vinc...@vincentdavis.netwrote:

 I have some some (~50) text files that have about 250,000 rows each. I am
 reading them in using the following which gets me what I want. But it is not
 fast. Is there something I am missing that should help. This is mostly an
 question to help me learn more about python. It takes about 4 min right now.

 def read_data_file(filename):
 reader = csv.reader(open(filename, U),delimiter='\t')
 read = list(reader)


 You're slurping the entire file here when it's not necessary.


 data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x in
 read])


 [x for x in read] is basically a copy of the entire list. This isn't
 necessary.


  data = [x for x in data_rows][1:]



 Again, copying here is unnecessary.

 [x for x in y] isn't a paradigm in Python. If you really need a copy of an
 array, x = y[:] is the paradigm.


 mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow,
 list(dropwhile(lambda drow: '[MASKS]' not in drow, read)))






 mask = [row for row in mask_rows if row][3:]


 Here's another unnecessary array copy.



 outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows,
 read)
 outlier = [row for row in outlier_rows if row][3:]



 And another.

 Just because you're using Python doesn't mean you get to be silly in how
 you move data around. Avoid copies as much as possible, and try to avoid
 slurping in large files all at once. Line-by-line processing is best.

 I think you should invert this operation into a for loop. Most people tend
 to think of things better that way than chained iterators. It also helps you
 to not duplicate data when it's unnecessary.

 --
 Jonathan Gardner
 jgard...@jonathangardner.net

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-20 Thread Vincent Davis
Thanks for the help, this is considerably faster and easier to read (see
below). I changed it to avoid the break and I think it makes it easy to
understand. I am checking the conditions each time slows it but it is worth
it to me at this time.
Thanks again
Vincent

def read_data_file(filename):
reader = csv.reader(open(filename, U),delimiter='\t')

data = []
mask = []
outliers = []
modified = []

data_append = data.append
mask_append = mask.append
outliers_append = outliers.append
modified_append = modified.append

maskcount = 0
outliercount = 0
modifiedcount = 0

for row in reader:
if '[MASKS]' in row:
maskcount += 1
if '[OUTLIERS]' in row:
outliercount += 1
if '[MODIFIED]' in row:
modifiedcount += 1
if not any((maskcount, outliercount, modifiedcount, not row)):
data_append(row)
elif not any((outliercount, modifiedcount, not row)):
mask_append(row)
elif not any((modifiedcount, not row)):
outliers_append(row)
else:
if row: modified_append(row)

data = data[1:]
mask = mask[3:]
outliers = outliers[3:]
modified = modified[3:]
return [data, mask, outliers, modified]

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


On Fri, Feb 19, 2010 at 4:36 PM, Jonathan Gardner 
jgard...@jonathangardner.net wrote:


 On Fri, Feb 19, 2010 at 1:58 PM, Vincent Davis 
 vinc...@vincentdavis.netwrote:

 In reference to the several comments about [x for x in read] is basically
 a copy of the entire list. This isn't necessary. or list(read). I had
 thought I had a problem with having iterators in the takewhile() statement.
 I thought I testes and it didn't work. It seems I was wrong. It clearly
 works. I'll make this change and see if it is any better.

 I actually don't plan to read them all in at once, only as needed, but I
 do need the whole file in an array to perform some mathematics on them and
 compare different files. So my interest was in making it faster to open them
 as needed. I guess part of it is that they are about 5mb so I guess it might
 be disk speed in part.nks



 Record your numbers in an array and then work your magic on them later.
 Don't store the entire file in memory, though.

 --
 Jonathan Gardner
 jgard...@jonathangardner.net

-- 
http://mail.python.org/mailman/listinfo/python-list


Not sure why this is filling my sys memory

2010-02-20 Thread Vincent Davis
Code is below, The files are about 5mb and 230,000 rows. When I have 43
files of them and when I get to the 35th (reading it in) my system gets so
slow that it is nearly functionless. I am on a mac and activity monitor
shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit).
The getsizeof() returns 6424 bytes for the alldata . So I am not sure what
is happening.
Any ideas
Thanks

*Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-20 Thread Vincent Davis
Thanks again for the comment, not sure I will implement all of it but I will
separate the if not row The files have some extraneous blank rows in the
middle that I need to be sure not to import as blank rows.
I am actually having trouble with this filling my sys memory, I posted a
separate question Why is this filling my sys memory or something like that
is the subject.
I might be that my 1yr old son has been trying to help for the last hour. It
is very distracting.

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


On Sat, Feb 20, 2010 at 6:18 PM, Jonathan Gardner 
jgard...@jonathangardner.net wrote:

 On Sat, Feb 20, 2010 at 4:21 PM, Vincent Davis 
 vinc...@vincentdavis.netwrote:

 Thanks for the help, this is considerably faster and easier to read (see
 below). I changed it to avoid the break and I think it makes it easy to
 understand. I am checking the conditions each time slows it but it is worth
 it to me at this time.


 It seems you are beginning to understand that programmer time is more
 valuable than machine time. Congratulations.



 def read_data_file(filename):
 reader = csv.reader(open(filename, U),delimiter='\t')

 data = []
 mask = []
 outliers = []
 modified = []

 data_append = data.append
 mask_append = mask.append
 outliers_append = outliers.append
 modified_append = modified.append



 I know some people do this to speed things up. Really, I don't think it's
 necessary or wise to do so.


 maskcount = 0
 outliercount = 0
 modifiedcount = 0

 for row in reader:
 if '[MASKS]' in row:
 maskcount += 1
 if '[OUTLIERS]' in row:
 outliercount += 1
 if '[MODIFIED]' in row:
 modifiedcount += 1
  if not any((maskcount, outliercount, modifiedcount, not row)):
 data_append(row)
 elif not any((outliercount, modifiedcount, not row)):
 mask_append(row)
 elif not any((modifiedcount, not row)):
 outliers_append(row)
 else:
 if row: modified_append(row)



 Just playing with the logic here:

 1. Notice that if not row is True, nothing happens? Pull it out
 explicitly.

 2. Notice how it switches from mode to mode? Program it more explicitly.

 Here's my suggestion:

 def parse_masks(reader):
 for row in reader:
 if not row: continue
 elif '[OUTLIERS]' in row: parse_outliers(reader)
 elif '[MODIFIED]' in row: parse_modified(reader)
masks.append(row)

 def parse_outliers(reader):
 for row in reader:
 if not row: continue
 elif '[MODIFIED]' in row: parse_modified(reader)
outliers.append(row)

 def parse_modified(reader):
 for row in reader:
 if not row: continue
modified.append(row)

 for row in reader:
 if not row: continue
 elif '[MASKS]' in row: parse_masks(reader)
 elif '[OUTLIERS]' in row: parse_outliers(reader)
 elif '[MODIFIED]' in row: parse_modified(reader)
 else: data.append(row)

 Since there is global state involved, you may want to save yourself some
 trouble in the future and put the above in a class where separate parsers
 can be kept separate.

 It looks like your program is turning into a regular old parser. Any format
 that is a little more than trivial to parse will need a real parser like the
 above.

 --
 Jonathan Gardner
 jgard...@jonathangardner.net

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Not sure why this is filling my sys memory

2010-02-20 Thread Vincent Davis
Here is a sample of the output, It almost instantly uses 2GB and then starts
using VMem. This is probably the right suggestion but it's another thing to
install

 It's probably also worth being aware of guppy's heapy stuff:

http://guppy-pe.sourceforge.net/heapy_tutorialhttp://guppy-pe.sourceforge.net/heapy_tutorial.htmlI
find it quite nice to have the following to get a quick point-in-time
estimate of my app's memory usage:

print 'Current memory usage: %iMB' % (hpy().heap().stat.size/(1024*1024))


19 files of 43 using 3352 bytes of memory
Loading into memory: 3_veg_nm_rep1.txt
3_veg_nm_rep1.txt has 228484 rows of data
3_veg_nm_rep1.txt has 0 rows of masked data
3_veg_nm_rep1.txt has 141 rows of outliers
3_veg_nm_rep1.txt has 0 modified rows of data
280bytes of memory used for 3_veg_nm_rep1.txt

20 files of 43 using 3352 bytes of memory
Loading into memory: 3_veg_nm_rep2.txt
3_veg_nm_rep2.txt has 228484 rows of data
3_veg_nm_rep2.txt has 0 rows of masked data
3_veg_nm_rep2.txt has 119 rows of outliers
3_veg_nm_rep2.txt has 0 modified rows of data
280bytes of memory used for 3_veg_nm_rep2.txt

21 files of 43 using 3352 bytes of memory
Loading into memory: 3_veg_phd_rep1.txt
3_veg_phd_rep1.txt has 228484 rows of data
3_veg_phd_rep1.txt has 0 rows of masked data
3_veg_phd_rep1.txt has 63 rows of outliers
3_veg_phd_rep1.txt has 0 modified rows of data
280bytes of memory used for 3_veg_phd_rep1.txt

22 files of 43 using 6424 bytes of memory
Loading into memory: 3g_c285-11.txt
3g_c285-11.txt has 228484 rows of data
3g_c285-11.txt has 0 rows of masked data
3g_c285-11.txt has 65 rows of outliers
3g_c285-11.txt has 0 modified rows of data
280bytes of memory used for 3g_c285-11.txt

23 files of 43 using 6424 bytes of memory
Loading into memory: 3g_c285-42.txt
3g_c285-42.txt has 228484 rows of data
3g_c285-42.txt has 0 rows of masked data
3g_c285-42.txt has 27 rows of outliers
3g_c285-42.txt has 0 modified rows of data
280bytes of memory used for 3g_c285-42.txt

24 files of 43 using 6424 bytes of memory
Loading into memory: A6AF.txt
A6AF.txt has 228484 rows of data
A6AF.txt has 0 rows of masked data
A6AF.txt has 36 rows of outliers
A6AF.txt has 0 modified rows of data
280bytes of memory used for A6AF.txt

25 files of 43 using 6424 bytes of memory
Loading into memory: Grigg_3026_rep1.txt
Grigg_3026_rep1.txt has 228484 rows of data
Grigg_3026_rep1.txt has 0 rows of masked data
Grigg_3026_rep1.txt has 949 rows of outliers
Grigg_3026_rep1.txt has 0 modified rows of data
280bytes of memory used for Grigg_3026_rep1.txt

26 files of 43 using 6424 bytes of memory
Loading into memory: Grigg_3026_rep2.txt
Grigg_3026_rep2.txt has 228484 rows of data
Grigg_3026_rep2.txt has 0 rows of masked data
Grigg_3026_rep2.txt has 361 rows of outliers
Grigg_3026_rep2.txt has 0 modified rows of data
280bytes of memory used for Grigg_3026_rep2.txt

27 files of 43 using 6424 bytes of memory
Loading into memory: Grigg_3026_rep3_both.txt
Grigg_3026_rep3_both.txt has 228484 rows of data
Grigg_3026_rep3_both.txt has 0 rows of masked data
Grigg_3026_rep3_both.txt has 41 rows of outliers
Grigg_3026_rep3_both.txt has 0 modified rows of data
280bytes of memory used for Grigg_3026_rep3_both.txt

28 files of 43 using 6424 bytes of memory
Loading into memory: Grigg_3131_rep1.txt
Grigg_3131_rep1.txt has 228484 rows of data
Grigg_3131_rep1.txt has 0 rows of masked data
Grigg_3131_rep1.txt has 537 rows of outliers
Grigg_3131_rep1.txt has 0 modified rows of data
280bytes of memory used for Grigg_3131_rep1.txt

29 files of 43 using 6424 bytes of memory
Loading into memory: Grigg_3131_rep2.txt
Grigg_3131_rep2.txt has 228484 rows of data
Grigg_3131_rep2.txt has 0 rows of masked data
Grigg_3131_rep2.txt has 238 rows of outliers
Grigg_3131_rep2.txt has 0 modified rows of data
280bytes of memory used for Grigg_3131_rep2.txt

30 files of 43 using 6424 bytes of memory

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


On Sat, Feb 20, 2010 at 7:40 PM, sstein...@gmail.com sstein...@gmail.comwrote:


 On Feb 20, 2010, at 9:21 PM, Vincent Davis wrote:

 See this article for some more info about the reported sizes of things:
 http://www.doughellmann.com/PyMOTW/sys/limits.html


 http://www.doughellmann.com/PyMOTW/sys/limits.htmlNice article but I
 must have missed something useful to my current issue. Do I get any hints?


 Oh, sorry, there was the part about getsizeof() not including attributes
 unless the class supplies a __sizeof__ method and a comment at the bottom:

 It's probably also worth being aware of guppy's heapy stuff:
 http://guppy-pe.sourceforge.net/heapy_tutorialhttp://guppy-pe.sourceforge.net/heapy_tutorial.html

 I find it quite nice to have the following to get a quick point-in-time
 estimate of my app's memory usage:

 print 'Current memory usage: %iMB' % (hpy().heap().stat.size/(1024*1024))

 Put a few of those in at various places in the collection

Re: Not sure why this is filling my sys memory

2010-02-21 Thread Vincent Davis
@sstein...@gmail.com sstein...@gmail.com
See this article for some more info about the reported sizes of things:
http://www.doughellmann.com/PyMOTW/sys/limits.html;

I posted this question on stack overflow. I now have a better appreciation
of ssteinerX suggestions of the above link and guppy, I also had pympler
suggested.

http://stackoverflow.com/questions/2306523/reading-text-files-into-list-then-storing-in-dictionay-fills-system-memory-a


Thanks again


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


On Sat, Feb 20, 2010 at 7:15 PM, sstein...@gmail.com sstein...@gmail.comwrote:


 On Feb 20, 2010, at 8:05 PM, Vincent Davis wrote:

 Code is below, The files are about 5mb and 230,000 rows. When I have 43
 files of them and when I get to the 35th (reading it in) my system gets so
 slow that it is nearly functionless. I am on a mac and activity monitor
 shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit).
 The getsizeof() returns 6424 bytes for the alldata . So I am not sure what
 is happening.


 See this article for some more info about the reported sizes of things:
 http://www.doughellmann.com/PyMOTW/sys/limits.html

 S


-- 
http://mail.python.org/mailman/listinfo/python-list


calculating a self.value, self.randomnum = normalvariate(x, y)

2009-06-19 Thread Vincent Davis
I currently have something like this.

class applicant():
def __int__(self, x, y):
self.randomnum = normalvariate(x, y)
then other stuff

x, y are only used to calculate self.randomnum   and this seems to
work. But I want self.randomnum to be 0 = randomnum = 100. The only
way I can thing of to do this is is with a while statement and that
seems more complicated than necessary. I would really like to keep it
on one line. How would I do that?

Thanks
Vincent Davis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calculating a self.value, self.randomnum = normalvariate(x, y)

2009-06-20 Thread Vincent Davis
 # Clamp a normal distribution outcome

 import random

 class applicant():
     def __init__(self, x, y):
     self.randomnum = clamp(random.normalvariate(x, y), 0, 100)

 def clamp(input, min=0, max=100):
     Clamps the input between min and max.

     if  input  min, returns min
     min  input  max, returns input
     input  max, returns max

     Default: min = 0, max = 100.
     if input  min:
     return min
     elif input  max:
     return max
     else:
     return input

 if __name__ == __main__:
     for num in range(10):
     print applicant(random.randint(0,100),
 random.randint(0,100)).randomnum

Why not have the def clamp inside the class? I would prefer to keep
everything I need for the class together.
I am new to classes but I have to say things like if __name__ ==
__main__: have no intuitive meaning to me. It is true I don't know
what __name__ and __main__ do and I can look it up but I don't even
have a guess based on the names and usage.

I am Now not sure if that is what I want or If I want to redraw from
the distribution. I am wanting to simulate test scores. My option see
to be to draw from a normal (I don't want linear) distribution and
scale it to 0-100 or clamp it as you (Xavier) suggested or draw from
the distribution again (this is what I was thinking) I think this is
still what I want but I should look up the implications of each. The
problem I have with the clamp is that the tails in the sample could be
large.

Thanks
Vincent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calculating a self.value, self.randomnum = normalvariate(x, y)

2009-06-20 Thread Vincent Davis
Quoting Steven,
Truncating with a while loop will result in something closer to this:
 000: *
 010: *
 020: **
 030: 
 040: ***
 050: *
 060: **
 070: 
 080: *
 090: **
 100: *

 which is far less distorted.

That is why I was thinking of a while loop.

 Strictly speaking, you want a different distribution, not normal. Possibly
 the F-distribution?

Why do you suggest a F dist, I have to admit I am not really sure how most
test score are distributed. I was thinking it would be a truncated skewed
normal. i.e. scores range from 0-100, mean is 80. For my I realize this is
venturing more into statistics.

Thanks
Vincent Davis
720-301-3003
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calculating a self.value, self.randomnum = normalvariate(x, y)

2009-06-20 Thread Vincent Davis
Quoting Dennis Lee Bieber

limitedNormal ( 75, 20 )
computed statistics: mu = 75.5121294828 sigma = 8.16374859991

Note how computing the input sigma such that 3*sigma does not exceed
 boundaries results in a narrow bell curve (hmm, and for this set, no one
 scored 95-100)

 retryNormal ( 75, 20 )
computed statistics: mu = 73.283826412  sigma = 16.9151951316

The retry model produces a skew, but perhaps somewhat unnatural; a
 real skew should still have relatively few entries in the 95-100 bin,
 whereas this is still rather symmetrical about the mean.  Compare the
 45, 65, and 80 bins between these two, those show most of the retried
 values that otherwise clipped to 100 below.

 clippedNormal ( 75, 20 )
computed statistics: mu = 75.3240108464 sigma = 18.1008966385

 Note the unnatural peak of grades in the 95-100 range resulting from
 clipping out of range values into the range.
*
See,  the full results below*

Wow thanks for this Dennis, I am actually trying to simulate the scores on
the step 1 medical boards exam. The actual distribution is not readily
available. I like your limitedNormal approach. I think this is the way for
me to go. I can come up with some reasonable mean and sd numbers from actual
results then I this approach seems the best to simulate those results. I
should actualy know more about this as I do a lot of stats but mostly
regressions. I need to look up ome more about the F dist, but I think your
limited approuch is the way to go. Trying to combine learning python and
simulating the medical residency application process has been interesting.
Here is a graph of past test results, I relize they are not on a 0 - 100
score but they is easy to address
[image: step1_score_distribution_custom.GIF]

Thanks
Vincent Davis
720-301-3003


On Sat, Jun 20, 2009 at 7:43 PM, Dennis Lee Bieber wlfr...@ix.netcom.comwrote:


I must be bored today...

Expanded variation:

 -=-=-=-=-=-
 
Random Scores
 

 import random
 import numpy

 def limitedNormal(mu, sigma=None):
 
returns a random score from a normal (bell) distribution in
 which
the mean, mu, is supplied by the caller, and in which the
standard deviation, sigma, is computed such that 3-sigma does
not drop below 0 [for mu  50] or rise above 100 [for mu  50]
 sigma is shown as a parameter but is not used -- it permits
using the same arguments for all three *Normal() methods
 
if mu  50.0:
sigma = mu / 3.0
else:
sigma = (100.0 - mu) / 3.0
return random.normalvariate(mu, sigma)

 def clippedNormal(mu, sigma):

returns a random score from a normal distribution in which
the mean, mu, and standard deviation, sigma, are supplied
by the caller.
the result is clipped to the range 0..100
 
return max(0.0,
   min(100.0,
random.normalvariate(mu, sigma)))

 def retryNormal(mu, sigma):

returns a random score from a normal distribution in which
the mean, mu, and the standard deviation, sigma, are supplied
by the caller.
if the result falls outside the range 0..100 a new score
is generated.
extremely large sigma, or mu close to the range end points
will cause slowness, as many results are thrown out and retried

score = -1
while not (0.0 = score = 100.0):
score = random.normalvariate(mu, sigma)
return score


 def clippedGamma(mu, B):
 
returns a random score from a gamma distribution in which the
 shape, a, is computed as the mean, mu, as from a normal
distribution divided by the B, rate. Both mu and B are
 supplied by the caller.
as the gamma distribution has a long tail to the right, for mu 
 50
the result is computed as 100 - gamma(100-mu) to reflect the
desired skewness
results are clipped to the boundaries 0..100 as there is no easy
way to compute B to limit results, as is done for sigma in
limitedNormal()
NOTE: while the mean of the results will approach mu, the peak
 of
the curve will be to the right (for mu50) or left (for mu50)
relative to a normal curve

 if mu  50.0:
return max(0.0,
   min(100.0,
random.gammavariate(mu / B, B)))
 else:
return 100.0 - max(0.0,
 min(100.0,
  random.gammavariate((100.0 - mu) / B,
 B)))

 def retryGamma(mu, B):
 
returns a random score from a gamma distribution in which the
 shape, a, is computed as the mean, mu, as from a normal
distribution divided by the B, rate. Both mu and B are
 supplied by the caller.
as the gamma distribution has a long tail to the right, for mu 
 50
the result is computed

python needs a tutorial for install and setup on a Mac

2009-06-21 Thread Vincent Davis
I am running python on a mac and when I was getting going it was difficult
to setup information. Specifically how modify bash_profile, how pythonpath
works and how to set it up. how to switch between python versions. How/where
to install modules if you have multiple installed versions. I am thinking
about this from perspective  of a new pythoner (is there a word for a person
who programs in python). I think many new pythoners may be like me and don't
mess with the underling UNIX on a mac.
My question/suggestion is that there be a nice tutorial for this. I am
wiling to contribute much but I am still somewhat new to python and may need
help with some details. Also where should this be posted, how do I post it.
Do other think there is a need? Any willing to help?
But of course I may have missed a great tutorial out there if so I think It
needs to be easier to findor I need to learn how to look.

Thanks
Vincent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python needs a tutorial for install and setup on a Mac

2009-06-22 Thread Vincent Davis
 tkp...@hotmail.com wrote:

 I think a setup guide for the Mac would prove very useful. Earlier
 this year, I tried installing Python 2.6 on my iMac, and ran into all
 sorts of problems, largely as a result of the fact that I knew very
 little about Unix. I finally downloaded and installed the Enthought
 Python distribution for the Mac and it worked like a charm.


Exactly why I think this is needed. I did the same thing, installed
Enthought. Then I wanted to use 2.6 and now 3.0.1 . I have all versions
installed. They work and I know how to switch between but not so sure what s
going on when I things  a package. I should not require lots of googling for
the answers. The mailing lists are great and everyone is helpful but do you
really want to answer the same questions again and agian.

Kushal Kumaran Have you seen the page at
http://www.python.org/download/mac/ and the
pages linked from it?

Yes I have as I am sure tkp...@hotmail.com and did not find it usefull, or I
should say only a little.

So I still have no answer, There seems to be a need but, no one has said
post it hear or volunteered to help.
Am I going about this wrong?

Thanks
Vincent
-- 
http://mail.python.org/mailman/listinfo/python-list


lambda question

2010-06-11 Thread Vincent Davis
Starting with an example.
In [23]: x = [1,2,3,4,4,4,5,5,3,2,2,]
In [24]: y = set(x)
In [25]: y
Out[25]: set([1, 2, 3, 4, 5])
In [26]: y2 = len(set(x))
In [27]: y2
Out[27]: 5

How would I do the above y2 = len(set(x)) but have len(set()) in a
dictionary. I know how to do ..
In [30]: d = dict(s=set)
In [32]: d['s'](x)
Out[32]: set([1, 2, 3, 4, 5])

but not sure how to add the len() and thought maybe the answer in a
lambda function.
I know I could def a function but would prefer to keep it all on one line.

Thanks
Vincent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda question

2010-06-12 Thread Vincent Davis
On Fri, Jun 11, 2010 at 10:11 PM, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Fri, Jun 11, 2010 at 9:31 PM, Vincent Davis vinc...@vincentdavis.net 
 wrote:
 Starting with an example.
 In [23]: x = [1,2,3,4,4,4,5,5,3,2,2,]
 In [24]: y = set(x)
 In [25]: y
 Out[25]: set([1, 2, 3, 4, 5])
 In [26]: y2 = len(set(x))
 In [27]: y2
 Out[27]: 5

 How would I do the above y2 = len(set(x)) but have len(set()) in a
 dictionary. I know how to do ..
 In [30]: d = dict(s=set)
 In [32]: d['s'](x)
 Out[32]: set([1, 2, 3, 4, 5])

 but not sure how to add the len() and thought maybe the answer in a
 lambda function.
 I know I could def a function but would prefer to keep it all on one line.

 d = dict(s=lambda x: len(set(x)))
 d['s'](x)
 5

I must have been half asleep, I thought for sure I tried that. Well it
works great this morning :)

Thanks
Vincent

 Cheers,
 Ian
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


getting up arrow in terminal to scroll thought history of python commands

2010-06-13 Thread Vincent Davis
I just installed 2.6 and 3.1 from current maintenance source on Mac
OSx. When I am running as an interactive terminal session the up arrow
does not scroll thought the history of the py commands I have entered
I just get ^[[A. When I install from a compiled source it works fine.
Whats the fix for this?

Thanks
Vincent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting up arrow in terminal to scroll thought history of python commands

2010-06-13 Thread Vincent Davis
On Sun, Jun 13, 2010 at 5:28 PM, Gerry Reno gr...@verizon.net wrote:
 sounds like your keymapping got messed with.

 you could just:
 set -o vi
 python
 ESC, Ctrl-j
 and now ESC-k and ESC-j will take you back and forth in history (std vi
 editing)

This is done within python? Let make sure I am clear. This is only an
issue within the interactive python for the python dist I have built
from source not other pythons or terminal in general. I look into the
commands you suggested more but ESC-k and ESC-j don't sound very
appealing to me.

Thanks
Vincent

 -Gerry



 Jun 13, 2010 07:22:40 PM, vinc...@vincentdavis.net wrote:

 I just installed 2.6 and 3.1 from current maintenance source on Mac
 OSx. When I am running as an interactive terminal session the up arrow
 does not scroll thought the history of the py commands I have entered
 I just get ^[[A. When I install from a compiled source it works fine.
 Whats the fix for this?

 Thanks
 Vincent
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting up arrow in terminal to scroll thought history of python commands

2010-06-14 Thread Vincent Davis
On Sun, Jun 13, 2010 at 6:24 PM, Irmen de Jong irmen-nosp...@xs4all.nl wrote:
 On 14-6-2010 1:19, Vincent Davis wrote:

 I just installed 2.6 and 3.1 from current maintenance source on Mac
 OSx. When I am running as an interactive terminal session the up arrow
 does not scroll thought the history of the py commands I have entered
 I just get ^[[A. When I install from a compiled source it works fine.
 Whats the fix for this?

 Thanks
 Vincent

 I'm guessing you don't have the readline module.

 Compile and install GNU Readline, then type 'make' again in your Python
 source tree. It should now no longer report a missing 'readline' module.

What exactly do you mean by 'make' again in your Python source tree.

Thanks
Vincent


 -irmen
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getting up arrow in terminal to scroll thought history of python commands

2010-06-14 Thread Vincent Davis
On Mon, Jun 14, 2010 at 6:49 AM, Thomas Jollans tho...@jollans.com wrote:
 On 06/14/2010 02:37 PM, Vincent Davis wrote:
 On Sun, Jun 13, 2010 at 6:24 PM, Irmen de Jong irmen-nosp...@xs4all.nl 
 wrote:
 On 14-6-2010 1:19, Vincent Davis wrote:

 I just installed 2.6 and 3.1 from current maintenance source on Mac
 OSx. When I am running as an interactive terminal session the up arrow
 does not scroll thought the history of the py commands I have entered
 I just get ^[[A. When I install from a compiled source it works fine.
 Whats the fix for this?

 Thanks
 Vincent

 I'm guessing you don't have the readline module.

 Compile and install GNU Readline, then type 'make' again in your Python
 source tree. It should now no longer report a missing 'readline' module.

 What exactly do you mean by 'make' again in your Python source tree.

 You installed Python from source didn't you? At some point you'll have
 to invoke make, unless some tool did that for you.

 Anyway, make sure readline is installed, and then recompile Python.

So I should run
./configure
make install
again?
Will this overwrite other py packages I have installed?

Vincent





 Thanks
 Vincent


 -irmen
 --
 http://mail.python.org/mailman/listinfo/python-list


 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Installing or adding python dev installed python.

2010-06-19 Thread Vincent Davis
I have several versions of python installed and some I have built from
source which seems to install the python-dev on osx. I know that on
ubuntu python-dev is an optional install. The main python version I
use is the enthought distribution. Can I install the python-dev tools
with this? How. It there a good place for me to better understand what
python-dev is and how to get it installed on osx?

Thanks
Vincent
-- 
http://mail.python.org/mailman/listinfo/python-list


Python script to install python

2010-07-08 Thread Vincent Davis
I would like to have a python script that would download the most
recent svn of python, configure, make, install and cleanup after
itself. I am not replacing the python version I would be using to run
the script.
I was struggling to get this to work and I assume someone else has
done it better.  Any pointers?

Thanks
Vincent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python script to install python

2010-07-08 Thread Vincent Davis
On Thu, Jul 8, 2010 at 9:11 AM, Daniel Fetchinson
fetchin...@googlemail.com wrote:
 I would like to have a python script that would download the most
 recent svn of python, configure, make, install and cleanup after
 itself. I am not replacing the python version I would be using to run
 the script.
 I was struggling to get this to work and I assume someone else has
 done it better.  Any pointers?

 Assuming you are on linux I recommend not using a python script for
 this but rather a shell script. From a python script you would most of
 the time be calling shell commands anyway. In a shell script you would
 do something like this:

 
 #!/bin/bash

 svn checkout 
 cd whatever
 ./configure --whatever-options-you-like
 make
 # you probably want to run this as root
 make install
 # you probably don't want to be root anymore
 cd ..
 rm -rf whatever

 

Ok I'll take your advice and just use a shell script. I am on osx by the way.

Thanks
Vincent

 If you are on windows I assume a similar strategy is best.

 Cheers,
 Daniel



 --
 Psss, psss, put it down! - http://www.cafepress.com/putitdown
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Setting a python application as the default app to open a file on a mac?

2010-04-25 Thread Vincent Davis
I have been using ulipad to edit .rst and .py files. I have currently been
launching using terminal  python32 ulipad.py and then opening the file I
what to edit. I would like to be able to set ulipad as the defualt editor
for .rst and .py files. I posted this question on superuser.com and got a
solution using automator.
http://superuser.com/questions/134594/set-default-open-with-app-to-a-python-program-on-a-mac

I am asking the question on this list to see if there is another (better?)
way.
python32 is an terminal alias to the 32 bit python version on my machine.

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Simple game like graphics

2010-04-27 Thread Vincent Davis
I am working on a simulation of a bicycle race. I would like a very simple
real time graphic of the position of the bicycles during the simulation and
a few of the key values. I will not be iterating with the simulation while
it is running.

I am not really sure where to start. Currently to watch the values of the
variables I just print them at intervals.

I know there are many option to do this. For me, I would like the option
that would be quick, easy and few lines of code. I am not sure of a better
way to describe my requirements.
Any suggestions would be great especially if you have a
tutorial/documentation you would recommend.

Thanks

*Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Bug Search Browser Plugin (Firefox)

2010-04-30 Thread Vincent Davis
The Bug Search Browser Plugin (Firefox)
http://python.org/dev/searchplugin does
not seem to install.
http://www.python.org/dev/searchplugin/

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: jpeg package

2010-05-01 Thread Vincent Davis
This gets you the cached page

linkhttp://webcache.googleusercontent.com/search?q=cache:Tjn4WG8auGIJ:www.emilas.com/jpeg/+http://www.emilas.com/jpeg/cd=2hl=enct=clnkgl=usclient=firefox-a

I also fond some of the source pages in googles cache

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

On Sat, May 1, 2010 at 2:16 PM, Paul Johnston paul@gmail.com wrote:

 Hi,

 I've used the jpeg library on PyPI in the past and it's been great:
 http://pypi.python.org/pypi/jpeg/0.1.4

 However, the library home page is now unaccessible. I can't even find
 the library on archive.org. Any idea how I can get it?
 http://www.emilas.com/jpeg/

 Thanks,

 Paul
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Encrypt password within source code.

2010-05-05 Thread Vincent Davis
I can't think of a way to do this, not sure it is possible but I feel as
though I might not know what I don't know.

I want to share and example of a python script, to run it needs a google
username and password. Is there a way for me to encrypt my username and
password in the source code? I though about openID but don't really know
anything about it.

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encrypt password within source code.

2010-05-05 Thread Vincent Davis
Thanks for the replies I though the answer was no.
Vincent

On Wed, May 5, 2010 at 7:48 PM, Tim Chase python.l...@tim.thechases.comwrote:

 On 05/05/2010 08:12 PM, Vincent Davis wrote:

 I can't think of a way to do this, not sure it is possible but I feel as
 though I might not know what I don't know.

 I want to share and example of a python script, to run it needs a google
 username and password. Is there a way for me to encrypt my username and
 password in the source code?


 No-ish.  You can encrypt it, but if you encrypt it, you need to include the
 keys or algorithm for decrypting it, and all it takes is a pdb.set_trace()
 before the decrypted uname/pwd get sent to Google to get it, and poof all
 your encryption/decryption has been in vain:

  uname = SUPER_ENCRYPTED_USER
  pwd = SUPER_ENCRYPTED_PASSWORD
  u = secret_decrypt(uname)
  p = secret_decrypt(pwd)
  # regardless of how good the stuff above is
  # you're vulnerable right here:
  # print %r %r % (u, p)
  do_google_stuff(u, p)

 Unless the Google API you're using allows for chain-of-authority creation
 of sub-credentials (so your account creates secondary accounts that are then
 distributed in your code/config files and managed via your dev login), two
 possibilities that come to mind:

 1) put in a bogus uname/password and make them get their own Google login
 to put in (which can be done in a config file if they're squeamish about
 editing source code)  This assumes that any arbitrary Google login can grant
 access to what you want (sometimes this is a developer key, in which case
 the user would need to get their own dev key).

 2) create a web-service on a server somewhere that has your credentials,
 but your distributed code merely hits this web service instead of having
 your actual credentials in the source (plain-text or encrypted).  The server
 would have them (I'd just put them in plain-text -- no need to be fancy.  If
 you can't trust your hosting service, don't use them) but you wouldn't
 expose the credentials outside the application.

 -tkc





  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


2to3 as a unittest

2010-05-06 Thread Vincent Davis
I have used 2to3 from the command line. is there a way to run it as a
unittest.
Actually I guess my question is; is there a built in utility for running py3
compatibility on source code as a unittest?

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


is there a functional assert(x==y, 'error msg')

2010-05-07 Thread Vincent Davis
Is there a functional assert(x==y, 'error msg') ?
I can only find the assert that is used like;
assert x==y, 'error msg'


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a functional assert(x==y, 'error msg')

2010-05-07 Thread Vincent Davis
On Fri, May 7, 2010 at 8:38 PM, James Mills prolo...@shortcircuit.net.auwrote:

 On Sat, May 8, 2010 at 12:04 PM, Vincent Davis 
 vinc...@vincentdavis.netwrote:

 Is there a functional assert(x==y, 'error msg') ?
 I can only find the assert that is used like;
 assert x==y, 'error msg'


 What about:

 def assertfunc(expr, msg):
assert expr, msg


I know but there are such nice asserts in unittest, but should (I assume
can) they only be used in a unittest or would it be ok to use in code like
the normal assert?



*Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need help with my 1st python program

2010-05-08 Thread Vincent Davis
I think what is not clear by what is being said is that you have passed in
pressure and not 'pressure'. The first is undefined, pressure = 1 would
define it. Where as 'pressure' is a string type.

On Sat, May 8, 2010 at 1:35 PM, Walter Brameld IV 
wb4remove_this_t...@wbrameld4.name wrote:

 Dave Luzius wrote:

 On Sat, 08 May 2010 19:02:42 +, Steven D'Aprano wrote:

  On Sat, 08 May 2010 18:52:33 +, Dave Luzius wrote:

  Pleaser help me with this. Here's a copy of the program, but it keeps
 calling for me to define pressure.

 That's because you haven't defined pressure.

 When Python tells you there is a bug in your program, it is almost
 always correct.


  # A small program to fetch local barometer reading   from weather.com #
 and convert the value from   metric to imperial. # My first attempt at
 Python.
 #
 import urllib

 # next line does the fetching
 urllib.urlopen(http://xoap.weather.com/weather/local/USMI0060;,
 pressure)

 What is pressure? It is an undefined name. Where does pressure get its
 value from?


 Pressure is a term for barometric pressure, and is understood by Conky,
 which this program is designed to work with, and is understood by
 weather.com. But the value it passes to conky is metric, and I want it to
 display in imperial.

 What should I do


 You're passing in the value of pressure as the 'data' parameter to
 urllib.urlopen.  So...what is the value of pressure?  You haven't assigned
 any value to it before calling urlopen.  Therein lies the problem.

 --
 http://mail.python.org/mailman/listinfo/python-list


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Access to comp.lang.python

2010-05-16 Thread Vincent Davis
I have no problem with threads
Using gmail in a browser.
That said I like how google groups handles email.
I am also ways having to fix the reply on this list to send back to the list
and not to the list and the last author. If someone knows a way to fix that
I would be happy to hear it.

Vincent


On Sat, May 15, 2010 at 4:34 PM, cjw c...@ncf.ca wrote:

 This isn't about Python but I'm seeking suggestions as to the best way to
 access the newsgroup.

 It seems that messages are coming from a number of sources, such as gmane
 and google groups.

 The problem is that many messages seem to get unlinked from their threads.

 I use Thunderbird 3.0.5 and wonder whether the problem lies with the merge
 process, the server or my reader.

 Would it be better to go to gmane, google groups or some such provider.

 In the past, use of Ctrl K had neatly disposed of thread that are of no
 interest.

 I would welcome advice.

 Colin W.
 --
 http://mail.python.org/mailman/listinfo/python-list


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Is this an ok thing to do in a class

2010-05-17 Thread Vincent Davis
Just wondering if there is a problem with mixing a dictionary into a class
like this. Everything seems to work as I would expect.

class foo(object):
def __init__(self, x):
self.letter = dict(a=1,b=2,c=3)
self.A=self.letter['a']
self.x=self.letter[x]

 afoo = foo('b')
 afoo.x
2
 afoo.A
1
 afoo.letter['a']
1
 afoo.letter.items()
[('a', 1), ('c', 3), ('b', 2)]

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this an ok thing to do in a class

2010-05-18 Thread Vincent Davis
Thanks for the feed back

Vincent

On Tue, May 18, 2010 at 8:50 AM, Bruno Desthuilliers
bruno.42.desthuilli...@websiteburo.invalid wrote:

 Simon Brunning a écrit :

 On 18 May 2010 06:21:32 UTC+1, Vincent Davis vinc...@vincentdavis.net
 wrote:

 Just wondering if there is a problem with mixing a dictionary into a
 class like this. Everything seems to work as I would expect.


 No problem at all AFAIC.


 OP didn't show up on c.l.py, so too bad you snipped the relevant code
 snippet...

 --
 http://mail.python.org/mailman/listinfo/python-list


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


how to cause a request for a missing class attribute cause its calculation

2010-05-18 Thread Vincent Davis
Lets say I have
class foo(object):
def __init__(self, x, y):
self.x=x
self.y=y
def xplusy(self):
self.xy = x+y

inst = foo(1,2)
inst.xy   # no value, but I what this to cause the calculation of inst.xy

I don't what to have self.xy calculated before it is called.


Thanks

*Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this an ok thing to do in a class

2010-05-18 Thread Vincent Davis
On Tue, May 18, 2010 at 2:41 PM, Ethan Furman et...@stoneleaf.us wrote:

 Do you expect afoo.letter[x] to always be afoo.x?  Because they aren't:

  afoo.A = 9
  afoo.letter['a']
 1


What you are pointing out is that the assignment is not reversed . But that
does make me thing of something I had not.

 afoo.letter['a'] = 345
 afoo.A
1

Thats kinda a bummer, whats a good way to make sure affo.A gets updated?

Vincent


 ~Ethan~

 --
 http://mail.python.org/mailman/listinfo/python-list


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this an ok thing to do in a class

2010-05-18 Thread Vincent Davis
On Tue, May 18, 2010 at 3:15 PM, Ethan Furman et...@stoneleaf.us wrote:

 Vincent Davis wrote:


 What you are pointing out is that the assignment is not reversed . But
 that does make me thing of something I had not.

   afoo.letter['a'] = 345
   afoo.A
 1

 Thats kinda a bummer, whats a good way to make sure afoo.A gets updated?


 It's possible, and not too tough, but... why do you need it done that way?
  Keeping redundant information seems like extra work with no advantage.

 Not sure I do, basicly I have a long list of values that could be
calculated from data. Some may take some time depending on the amount of
data. I don't what to calculate them all if not needed but I don't what the
user to need to know which are and which are not. But maybe @property is
what I need to be looking at, see my other post on the list.
Thanks
Vincent


 ~Ethan~
 --
 http://mail.python.org/mailman/listinfo/python-list


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sound effects in python

2010-05-18 Thread Vincent Davis
There was a talk at pycon about this. Sounded interecting but I don't know
much about it.
http://us.pycon.org/2010/conference/schedule/event/136/

Vincent

On Tue, May 18, 2010 at 4:05 PM, Astan Chee astan.c...@al.com.au wrote:

 Hi,
 I have a sound file (e.g. .wav; .mp3, etc) in python that I'd like to
 modify (e.g. change tempo, pitch, add echo, amplify, etc).
 Any recommendation on how I can achieve this in python independent of
 platform?
 Thanks
 --
 http://mail.python.org/mailman/listinfo/python-list


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


__str__ for each function in a class

2010-05-18 Thread Vincent Davis
I am sure this is easy but I am not sure how to do it and google was failing
me.
Lets say I have a class() with an def x() and def y() and I want
print(class.x) and (class.y) to have custom prints (__str__) how do I do
this
For example
class C(object):
def __init__(self, new):
self.letter = dict(a=1,b=2,c=3, amin=np.amin)
self.new = new
self._x = None
self._Y = None

@property
def x(self):
I'm the 'x' property.
self._x = self.new
return self._x

@property
def y(self):
I'm the 'x' property.
self._y = self.new*-1
return self._y

...
 print(class.x)
x
 print(class.y)
-
y
-

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script for Website Mirroring

2010-05-19 Thread Vincent Davis
Probably need a little more info to help. Are you running both sites, are
there database involved?
If it is a simple site you could just transfer with ftp and have the script
updated any urls.

Vincent

On Wed, May 19, 2010 at 8:21 AM, Kevin Rea kcronl...@gmail.com wrote:

  Hello Folks:

 Can you please point me to a decent Python script(s) that I could customize
 to do automatic Website mirroring?

 Thanks Much!
 Kevin

 --
 http://mail.python.org/mailman/listinfo/python-list


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: speed up a numpy code with huge array

2010-05-25 Thread Vincent Davis
It makes me think you are filling you available memory and using the disk as
cache. If this happens things will get real slow. You might take a look at
your system resources when this is running. I don't have much else to offer
and could be completely wrong.

Vincent

On Tue, May 25, 2010 at 1:05 PM, Alexzive zasaconsult...@gmail.com wrote:

 Hello Pythonguys!

 is there a way to improve the performance of the attached code ? it
 takes about 5 h on a dual-core (using only one core) when len(V)
 ~1MIL. V is an array which is supposed to store all the volumes of
 tetrahedral elements of a grid whose coord. are stored in NN (accessed
 trough the list of tetraelements -- EL)


 Thanks in advance!
 Alex

 
 print 'start ' + nameodb
 #path = '/windows/D/SIM-MM/3D/E_ortho/' + nameodb + '.odb'
 path = pt + nameodb + '.odb'
 odb = openOdb(path)

 N = odb.rootAssembly.instances['PART-1-1'].nodes
 if loadV==1:
  pathV=pt+vtet
  V=numpy.loadtxt(pathV)
  VTOT = V[0]
  L3 = V[1]
  print 'using ' + vtet
 else:
  NN=[]
  B=[0,0,0,0]
  for i in range(len(N)):
B[0] = N[i].label
B[1] = N[i].coordinates[0]
B[2] = N[i].coordinates[1]
B[3] = N[i].coordinates[2]
NN = append(NN,B)

  NN=NN.reshape(-1,4)
  EL = odb.rootAssembly.instances['PART-1-1'].elements

  L1 = max(NN[:,1])-min(NN[:,1])
  L2 = max(NN[:,2])-min(NN[:,2])
  L3 = max(NN[:,3])-min(NN[:,3])
  VTOT=L1*L2*L3
  print 'VTOT: [mm³]' + str(VTOT)

  V = array([])

  print 'calculating new Vtet '
  V = range(len(EL)+2)
  V[0] = VTOT
  V[1] = L3
  for j in range(0,len(EL)):
Va = EL[j].connectivity[0]
Vb = EL[j].connectivity[1]
Vc = EL[j].connectivity[2]
Vd = EL[j].connectivity[3]
ix = where(NN[:,0] == Va)
Xa = NN[ix,1][0][0]
Ya = NN[ix,2][0][0]
Za = NN[ix,3][0][0]
ix = where(NN[:,0] == Vb)
Xb = NN[ix,1][0][0]
Yb = NN[ix,2][0][0]
Zb = NN[ix,3][0][0]
ix = where(NN[:,0] == Vc)
Xc = NN[ix,1][0][0]
Yc = NN[ix,2][0][0]
Zc = NN[ix,3][0][0]
ix = where(NN[:,0] == Vd)
Xd = NN[ix,1][0][0]
Yd = NN[ix,2][0][0]
Zd = NN[ix,3][0][0]
a =  [Xa,Ya,Za]
b =  [Xb,Yb,Zb]
c =  [Xc,Yc,Zc]
d =  [Xd,Yd,Zd]
aa = numpy.diff([b,a],axis=0)[0]
bb = numpy.diff([c,b],axis=0)[0]
cc = numpy.diff([d,c],axis=0)[0]
D=array([aa,bb,cc])
det=numpy.linalg.det(D)
V[j+2] = abs(det)/6
  pathV = pt + vtet
  savetxt(pathV, V, fmt='%.3e')
 ###
 --
 http://mail.python.org/mailman/listinfo/python-list


  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog http://vincentdavis.net |
LinkedInhttp://www.linkedin.com/in/vincentdavis
-- 
http://mail.python.org/mailman/listinfo/python-list


Question about permutations (itertools)

2010-05-31 Thread Vincent Davis
As a note I am doing this in py3.

I am looking for the most efficient (speed) way to produce an an
iterator to of permutations.
One of the problem I am having it that neither combinations nor
permutations does not exactly what I want directly.
For example If I want all possible ordered lists of 0,1 of length 3
(0,0,0)
(0,0,1)
(0,1,1)
(1,1,1)
(1,0,1)
(1,1,0)
(1,0,0)
I don't see a way to get this directly from the itertools. But maybe I
am missing something. I see ways to get a bigger list and then remove
duplicates.

 list(permutations([0,1], 3))
[]

 list(combinations_with_replacement('01',3))
('0', '0', '0')
('0', '0', '1')
('0', '1', '1')
('1', '1', '1')

Is it possible to get combinations_with_replacement to return numbers
rather than strings? (see above)

Thanks
Vincent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about permutations (itertools)

2010-05-31 Thread Vincent Davis
On Mon, May 31, 2010 at 8:17 AM, Xavier Ho cont...@xavierho.com wrote:

  list(combinations_with_replacement('01',3))
 ('0', '0', '0')
 ('0', '0', '1')
 ('0', '1', '1')
 ('1', '1', '1')

 Is it possible to get combinations_with_replacement to return numbers
 rather than strings? (see above)

 list(combinations_with_replacement(range(0,2), 3))
 [(0, 0, 0), (0, 0, 1), (0, 1, 1), (1, 1, 1)]

Thanks, for some reason I didn't combinations_with_replacement took a
list as an argument.

 Hopefully that'll give you some ideas.

 Cheers,
 Xav
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Jobs

2010-06-09 Thread Vincent Davis
On Wed, Jun 9, 2010 at 2:21 PM, Michael Chambliss em...@mchambliss.com wrote:
 I use Python for my own entertainment and for quick jobs, but haven't been
 able to use it professionally up to this point.  As a former Perl developer
 and someone that's currently required to code in Java I'm starting to wish I
 had this opportunity.  Can anyone comment on the Python job market?  If
 you're currently employed writing Python apps, I'd be particularly
 interested in knowing any of the following:
 - Your location - country, state or city, whatever you care to provide
 - Your focus - Product Development (web sites/apps), Education, RD/Science,
 IT/Sys Admin, etc
 - Your company size
 - Your compensation relative to the .NET/Java developers you know -
 generally higher/lower?

 In my area (Denver, CO) I predominantly see Java positions, followed closely
 by .NET.  I'll occasionally see something pop up related to PHP or Ruby web
 development but hardly ever Python, so I'm just curious if I'm looking in
 the wrong places.
 Thanks for any input!
 -Mike

You might take a look at Front Range pythoneers. The is a mailing list
an I think monthly meetups.  I see some job post coma across the list
now and then.
http://www.meetup.com/frpythoneers/

I am also in the Denver area and have been meaning to go to one of the meetups.

Vincent


 --
 http://mail.python.org/mailman/listinfo/python-list


-- 
http://mail.python.org/mailman/listinfo/python-list


Download an attachment from an IMAP email

2011-02-03 Thread Vincent Davis
I have a few emails I am trying to download from my google account. I seem
to be getting the message but each of these messages have an attachment. I
don't understand what I ned to do to get and save the attachment to a local
file.
Here is what I have so far.
M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT)
rc, resp = M.login('x@', 'X')
print rc, resp
M.select('[Gmail]/All Mail')
M.search(None, 'FROM', 'some...@logitech.com')
#M.fetch(121, '(body[header.fields (subject)])')
M.fetch(121, '(RFC822)')

-- 
Thanks
Vincent Davis
720-301-3003
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Download an attachment from an IMAP email

2011-02-04 Thread Vincent Davis
hgc


On Thu, Feb 3, 2011 at 6:52 PM, Kushal Kumaran 
kushal.kumaran+pyt...@gmail.com kushal.kumaran%2bpyt...@gmail.com wrote:

 On Fri, Feb 4, 2011 at 3:44 AM, Vincent Davis vinc...@vincentdavis.net
 wrote:
  I have a few emails I am trying to download from my google account. I
 seem
  to be getting the message but each of these messages have an attachment.
 I
  don't understand what I ned to do to get and save the attachment to a
 local
  file.
  Here is what I have so far.
  M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT)
  rc, resp = M.login('x@', 'X')
  print rc, resp
  M.select('[Gmail]/All Mail')
  M.search(None, 'FROM', 'some...@logitech.com')
  #M.fetch(121, '(body[header.fields (subject)])')
  M.fetch(121, '(RFC822)')

 Take a look at the email module.  The message_from_string() function
 can convert the string representation of the email (as obtained by
 M.fetch(121, '(RFC822)') into a message object.


Thanks
Vincent


 --
 regards,
 kushal




-- 
Thanks
Vincent Davis
720-301-3003
-- 
http://mail.python.org/mailman/listinfo/python-list


error in tutorial for 3.0, section 9.3.3

2009-05-23 Thread Vincent Davis
Section 9.3.3 says that given,
class MyClass:
A simple example class
i = 12345
def f(self):
return 'hello world'

and x = MyClass()
then this

x.counter = 1
while x.counter  10:
x.counter = x.counter * 2
print(x.counter)
del x.counter

will print 16

link,
http://docs.python.org/3.0/tutorial/classes.html#a-first-look-at-classes

I am reading this section so to learn about classes but if this is right I
think I need to start over.


Thanks
Vincent Davis
720-301-3003
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error in tutorial for 3.0, section 9.3.3

2009-05-23 Thread Vincent Davis
let me add that I see that this could be right if x.counter = 1 and counter
need not have anything to do with MyClass but this could be more clear.
Thanks
Vincent Davis
720-301-3003


On Sat, May 23, 2009 at 7:08 AM, Vincent Davis vinc...@vincentdavis.netwrote:

 Section 9.3.3 says that given,
 class MyClass:
 A simple example class
 i = 12345
 def f(self):
 return 'hello world'

 and x = MyClass()
 then this

 x.counter = 1
 while x.counter  10:
 x.counter = x.counter * 2
 print(x.counter)
 del x.counter

 will print 16

 link,
 http://docs.python.org/3.0/tutorial/classes.html#a-first-look-at-classes

 I am reading this section so to learn about classes but if this is right I
 think I need to start over.


 Thanks
 Vincent Davis
 720-301-3003

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error in tutorial for 3.0, section 9.3.3

2009-05-23 Thread Vincent Davis
Thank you that makes sense to me. Much more clear then the tutorial, I think
so anyway. If you are learning about classes that you kinda expect MyClass
to have counter in it. I might be nice to show that x.counter = 1 creates an
instance that would look like (is this correct?)

class MyClass:
A simple example class
i = 12345
counter = 1
def f(self):
return 'hello world'

Thanks again

Vincent Davis


On Sat, May 23, 2009 at 8:24 AM, Benjamin Kaplan
benjamin.kap...@case.eduwrote:



 On Sat, May 23, 2009 at 9:13 AM, Vincent Davis 
 vinc...@vincentdavis.netwrote:

 let me add that I see that this could be right if x.counter = 1 and
 counter need not have anything to do with MyClass but this could be more
 clear.
 Thanks
 Vincent Davis
 720-301-3003


 On Sat, May 23, 2009 at 7:08 AM, Vincent Davis 
 vinc...@vincentdavis.netwrote:

 Section 9.3.3 says that given,
 class MyClass:
 A simple example class
 i = 12345
 def f(self):
 return 'hello world'

 and x = MyClass()
 then this

 x.counter = 1
 while x.counter  10:
 x.counter = x.counter * 2
 print(x.counter)
 del x.counter

 will print 16

 link,
 http://docs.python.org/3.0/tutorial/classes.html#a-first-look-at-classes

 I am reading this section so to learn about classes but if this is right
 I think I need to start over.


 The code given is correct, though the description in the tutorial could be
 clearer. Basically, a class in Python is represented by a dict with strings
 mapping to other stuff. Internally, x.counter = 1 is just a shortcut for
 x.__dict__['counter'] = 1. This appears in the code as dynamically adding
 the variable counter to the instance of MyClass. Unlike in static
 languages, an instance variable in python doesn't need to be declared inside
 the class for you to use it. It also doesn't need to appear in every
 instance of the class.

 The last line in the code (del x.counter) removes the counter key from x
 so that the instance variable disappears. That's how the code works without
 leaving a trace.





 Thanks
 Vincent Davis
 720-301-3003



 --
 http://mail.python.org/mailman/listinfo/python-list



 --
 http://mail.python.org/mailman/listinfo/python-list


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import _sqlite3 no module named error

2009-06-04 Thread Vincent Davis
 when I try to run his app I get the no module named _sqlite3 , I am
 not sure what this is caused by as it looks to me like sqlite3 is
 trying to import it. Any idea how to fix this? Other than the obvious

 of getting _sqlite3 somehow, or maby it is that simple
   
 /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/s
   qlite3/dbapi2.py,
 line 27, in module
     from _sqlite3 import *
 ImportError: No module named _sqlite3
 logout


 From the path names, it appears you are using the MacPorts python2.5.
 Try:

    sudo port install py25-sqlite3

 which will bring along sqlite3 if not already installed.


Yes I am using macports I think sqlite is installed? here is what I
get when I run
sudo port install py25-sqlite3

vincent-daviss-macbook-pro-2:~ vmd$ sudo port install py25-sqlite3
Skipping org.macports.activate (py25-sqlite3 ) since this port is already active
---  Cleaning py25-sqlite3
vincent-daviss-macbook-pro-2:~ vmd$
-- 
http://mail.python.org/mailman/listinfo/python-list


Understanding and dealing with an exception

2012-10-13 Thread Vincent Davis
I am working on a script to find bad image files. I am using PIL
and specifically image.verify() I have a set of known to be bad image files
to test. I also what to be able to test any file for example a .txt and
deal with the exception.
Currently my code is basically

try:
im = Image.open(ifile)
try:
print(im.verify())
except:
print('Pil image.verify() failed: ' + afile)
except IOError:
print('PIL cannot identify image file: ' + afile)
except:
print(ifile)
print(Unexpected error doing PIL.Image.open():, sys.exc_info()[0])
raise

I have a lot of file that have an IOError.  I would expect this error for
any non image file.
I have yet to have image.verify() All failures have been IOError.

Then I got this error (below). Which to me to me is a bug in PIL?
The file seems ok when I open it for editing in an external editor.

So my question, I don't what to raise this exception thereby stoping the
script nor record the image as bad or good. This would possibly lead to
false positives or negatives.
Then again I assume it would be possible to get this error because the file
is corrupt.
I am not really sure how to deal with this. Any advise.

fixed-width.psd
('Unexpected error doing PIL.Image.open():', type
'exceptions.OverflowError')



OverflowError: Python int too large to convert to C long
File /Volumes/Hafnium/Google Drive/bad images/untitled-2.py, line 21, in
module
  im = Image.open(ifile)
File
/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/Image.py,
line 1965, in open
  return factory(fp, filename)
File
/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/ImageFile.py,
line 91, in __init__
  self._open()
File
/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/PsdImagePlugin.py,
line 123, in _open
  self.layers = _layerinfo(self.fp)
File
/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/PsdImagePlugin.py,
line 230, in _layerinfo
  t = _maketile(file, m, bbox, 1)
File
/Library/Frameworks/Python.framework/Versions/7.0/lib/python2.7/site-packages/PIL/PsdImagePlugin.py,
line 266, in _maketile
  bytecount = read(channels * ysize * 2)

Vincent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding and dealing with an exception

2012-10-13 Thread Vincent Davis
Oops, I was going to make note of the file size. 1.2MB

Vincent



On Sat, Oct 13, 2012 at 10:31 PM, Chris Angelico ros...@gmail.com wrote:

 On Sun, Oct 14, 2012 at 3:23 PM, Vincent Davis vinc...@vincentdavis.net
 wrote:
  OverflowError: Python int too large to convert to C long
  line 266, in _maketile
bytecount = read(channels * ysize * 2)

 Is the file over 2GB? Might be a limitation, more than a bug, and one
 that could possibly be raised by using a 64-bit build.

 Alternatively, you could deem them invalid for exceeding your file
 size limit (either before passing to PIL, or on catching this
 exception).

 ChrisA
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding and dealing with an exception

2012-10-13 Thread Vincent Davis
I can open it is and all looks good using Pixelmator (I don't have
Photoshop installed). I don't think there is anything wrong with the image.

Part of my question is a result of being new to actually using exceptions
in my programs and dealing with the exceptions is a primary part of what I
need to do with this program. When I get an exception that seems to be an
issue with PIL (i.e. not my program or a problem with the image) I am not
sure what the right or conventional way to deal with it is.

Vincent


On Sat, Oct 13, 2012 at 10:49 PM, Chris Angelico ros...@gmail.com wrote:

 On Sun, Oct 14, 2012 at 3:36 PM, Vincent Davis vinc...@vincentdavis.net
 wrote:
  Oops, I was going to make note of the file size. 1.2MB

 Then I'd definitely declare the file bad; I don't know what the valid
 ranges for channels and ysize are, but my reading of that is that your
 file's completely corrupt, maybe even malicious. PIL probably ought to
 check these things, so there may be a tracker issue coming from this,
 but I'd be inclined to declare any thrown exception as meaning it's a
 bad file. Call it failed a security check perhaps.

 ChrisA
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding and dealing with an exception

2012-10-14 Thread Vincent Davis
Yes afile is the file name and extension, ifile is the full file name and
path.

Thanks
Vincent

On Sunday, October 14, 2012, MRAB wrote:

 On 2012-10-14 05:23, Vincent Davis wrote:

 I am working on a script to find bad image files. I am using PIL
 and specifically image.verify() I have a set of known to be bad image
 files to test. I also what to be able to test any file for example a
 .txt and deal with the exception.
 Currently my code is basically

 try:
  im = Image.open(ifile)
  try:
  print(im.verify())
  except:
  print('Pil image.verify() failed: ' + afile)
 except IOError:
  print('PIL cannot identify image file: ' + afile)
 except:
  print(ifile)
  print(Unexpected error doing PIL.Image.open():, sys.exc_info()[0])
  raise

  [snip]
 I notice that you have both ifile and afile. Is that correct?

 --
 http://mail.python.org/**mailman/listinfo/python-listhttp://mail.python.org/mailman/listinfo/python-list



-- 
Vincent Davis
720-301-3003
-- 
http://mail.python.org/mailman/listinfo/python-list


get each pair from a string.

2012-10-21 Thread Vincent Davis
I am looking for a good way to get every pair from a string. For example,
input:
x = 'apple'
output
'ap'
'pp'
'pl'
'le'

I am not seeing a obvious way to do this without multiple for loops, but
maybe there is not :-)
In the end I am going to what to get triples, quads... also.

Thanks
Vincent
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >