Re: What was your strategy?

2010-11-19 Thread Lou Pecora
In article <7xr5ei1p2j@ruckus.brouhaha.com>,
 Paul Rubin  wrote:

> Lou Pecora  writes:
> >> > I'll jump in and recommend the book "Python in a Nutshell" by Martelli.  
> >> It's encyclopedic.
> > Indeed.  I hope Martelli updates it.  I'd buy another copy right away.
> 
> It's a great book but not a starting point for beginners.  It's
> definitely worth having for more advanced users.

I would beg to differ.  I used it from the start of my Python learning 
curve and was greatly helped by it.  For me it gave explanations at just 
the right level with paths to more detail if you wanted.  I found it 
helpful from the beginning.  I would recommended others to at least look 
at it.  You might be helped right away and it's a good addition to any 
Python programmer's library.

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


Re: What was your strategy?

2010-11-18 Thread Lou Pecora
In article ,
 Steve Holden  wrote:

> On 11/16/2010 2:22 PM, Lou Pecora wrote:
> > I'll jump in and recommend the book "Python in a Nutshell" by Martelli.  
> > It may be a little dated now, but it covers many Python topics in good 
> > detail without becoming a bloated reference. Nicely written.  It's still 
> > the first book I reach for after 6 years of Python coding and it rarely 
> > disappoints.
> 
> +1
> 
> It's encyclopedic.

Indeed.  I hope Martelli updates it.  I'd buy another copy right away.

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


Re: What was your strategy?

2010-11-16 Thread Lou Pecora
In article ,
 Dennis Lee Bieber  wrote:

> On Sun, 14 Nov 2010 16:32:24 -0600, Jorge Biquez 
> declaimed the following in gmane.comp.python.general:
> 
> > I was wondering if you can share what was the strategy you followed 
> > to master Python (Yes I know I have to work hard study and practice a 
> > lot). I mean did you use special books, special sites, a plan to 
> 
>   I picked up the first edition "Programming Python" (and a now
> forgotten competitor book) since the Amiga was mentioned... 

I'll jump in and recommend the book "Python in a Nutshell" by Martelli.  
It may be a little dated now, but it covers many Python topics in good 
detail without becoming a bloated reference. Nicely written.  It's still 
the first book I reach for after 6 years of Python coding and it rarely 
disappoints.

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


Re: Am I The Only One Who Keeps Reading ?Numpy? as ?Numpty??

2010-11-10 Thread Lou Pecora
In article <2010111007444115344-nom...@thisaddresscom>,
 Sven  wrote:

> On 2010-11-10 01:53:58 -0500, Lawrence D'Oliveiro said:
> 
> > Sorry...
> 
> no.

Yes, except for one other, above.  :-) 

Bigger question:  How do you pronouce it?  Some say "num pee".  Not the 
greatest image to English speakers.  I say "num pie".  Makes more sense 
to me since the "pie" sound is already in python a root for the name.

This, of course, is a burning issue for us all.

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


Re: I strongly dislike Python 3

2010-07-01 Thread Lou Pecora
In article 
<3f35dcf5-25ff-4aa7-820c-592cbffa4...@u26g2000yqu.googlegroups.com>,
 rantingrick  wrote:

> On Jun 30, 4:21 pm, geremy condra  wrote:
> 
> > Actually, I agree with this complaint though- it is much easier to type
> > spaces than parens.
> 
> Oh Geremy please. If you're going to whine about something at least
> find something worth whining about! Yes a few more key strokes are
> needed. But print should have been a function from day one. The
> benefits of a print function over a print statement are obvious to
> those who seek the truth and lost on those who wallow in self pity. If
> it's that much trouble for you then pick up an editor that auto
> inserts parenthesis for you, or *gasps* write a routine yourself. Look
> i know masturbation makes you lazy, but geez!


Hey, guys (gals?), Don't any of you have typing utilities that will fill 
in text after you hit a special key-combination?  I get   print "  typed 
automatically by holding two modifier keys and hitting 'p' key.  Sounds 
harder than it is and it's really fast. So if I switch to Python 3 I 
would change that to   print(" .  

E.g. for the Mac there are programs (utilities that run in the 
background) like Quickeys and TypeItForMe that allow you to do all sorts 
of automatic inserting of commonly used text.  They're cheap and easy to 
use.  There must be something like this for Linux and Windows, no?

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


A fix for pylab and TkAgg plotting in SAGE (Mac OS X)

2010-02-16 Thread Lou Pecora
A few weeks ago I posted a problem with Mac OS X with matplotlib in the 
SAGE distribution in which attempting to import pylab gave an error 
message which stated that there was an import error and the module 
_tkagg could not be found. The problem appears to be with matplotlib 
(I'm not clear about this).  After much searching and some emailing I 
have found a solution to this problem and it is easy to do.  

Full credit goes to Eric Sonnendrucker who sent it to me.

Here it is:

1) Download the Tcl/Tk sources (go to http://www.tcl.tk/, click on Get 
Tcl/Tk Now, click on Sources Download Page,, download the latest 
version).

2) In the Terminal cd to the unix folder in the tcl folder.  Compile the 
unix version (of Tcl and Tk) as follows 
./configure --enable-framework --disable-xft
make
make install

3) Install SAGE from source.  Download the SAGE source code (go to 
http://www.sagemath.org/, click on Download, click on Download complete 
source code).  In the terminal cd to the SAGE folder and *before* you 
run the sage install you need to set

SAGE_MATPLOTLIB_GUI=True

using export SAGE_MATPLOTLIB_GUI=True with bash. The installer then 
picks it up automatically.

Complete the SAGE installation by typing make and hit return. That's it. 
This will take a while (up to a few hours depending on the computer).

4) You might also need to modify you matplotlibrc by setting 
backend='TkAgg'  after the installation


Test this by doing an import pylab in sage.  You should not get an error.

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


Re: YAML (was: Python and Ruby)

2010-02-05 Thread Lou Pecora
In article <00f4bb3a$0$15566$c3e8...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> On Thu, 04 Feb 2010 09:57:59 -0500, Lou Pecora wrote:
> 
> > Well, that looks a bit more complicated than I would like, but maybe
> > it's doing more stuff than I can grok.  Here's what I needed and how I
> > did it in Python:
> [...]
> > # Reading same list in:
> > instr=fp.readline()
> > inlist=eval(instr)
> > x1,y1,astr1,z1= inlist
> > 
> > 
> > That's what I needed.  3 lines to write or read a inhomogeneous
> > collection of variables. 
> 
> Easy, but also quick and dirty -- good enough for small scripts, but not 
> really good enough for production applications.
> 
> 
> > I can add more variables, shuffle the order,
> > whatever without messing with formatting, etc. 
> 
> This is nice and easy. But there are at least four catches:
> 
> 
> * you can't safely treat the data file as human-editable
> (although a sufficiently careful and Python-aware user could edit it)
> 
> * you can't use any data that isn't a built-in, or that contains 
> something that is not a built-in
> 
> * there may be reliability issues with floats - you're at the mercy of 
> changes to the underlying repr of float objects, and it almost certainly 
> will blow up in your face if you get an inf or nan (at least prior to 
> Python 2.6)
> 
> * you're using eval, which is a security risk if you can't trust the 
> source of the data file.
> 
> However, be aware that neither marshal nor pickle guarantees to be safe 
> against malicious data either. The docs for both warn against using them 
> on untrusted data. YAML or JSON *might* be safer, I haven't looked.

I understand where you are coming from: Production Code.  I was just 
making a point about Python and my code is only used by me.  I can edit 
the file for the simple I/O I do.  I am not recommending this way for 
everyone. Just an example.

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


Re: Python and Ruby

2010-02-04 Thread Lou Pecora
In article <7x8wb9j4r2@ruckus.brouhaha.com>,
 Paul Rubin  wrote:

> Lou Pecora  writes:
> > after much noodling around and reading it hit me that I could just put
> > all that output of different types of variables into a list, hit it
> > with a repr() function to get a string version, and write the string
> > to a file -- no formatting necessary-- three lines of code. Later
> > reading in the string version (no formatting necessary), and hitting
> > it with an eval() function returned all the values I originally had in
> > those variables.  How simple, but beautiful.
> 
> FYI: I do that too sometimes, but in general using repr/eval that way
> is poor style and not very reliable.  It's better to use the pickle
> module, which is intended for that sort of thing, or the json module
> if your datatypes are suitable and you want to follow a semi-standard.

Yeah, I should look into pickle.  Haven't messed with that.  Most of 
what I do is numerical calculations for my consumption/research so quick 
and easy comes first.  Thanks for the hint.

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


Re: YAML (was: Python and Ruby)

2010-02-04 Thread Lou Pecora
In article <87eil1ddjp.fsf...@castleamber.com>,
 John Bokma  wrote:

> Lou Pecora  writes:
> 
> > That's a pretty accurate description of how I transitioned to Python 
> > from C and Fortran.
> 
> Not C, but C++ (but there are also C implementations): YAML, see:
> http://code.google.com/p/yaml-cpp/wiki/HowToParseADocument
> 
> I use YAML now and then with Perl for both reading/writing data and for
> debugging purposes (YAML is quite human readable, for programmers at least)
> 
> Of course there is also YAML support for Python:
> http://pyyaml.org/.

Well, that looks a bit more complicated than I would like, but maybe 
it's doing more stuff than I can grok.  Here's what I needed and how I 
did it in Python:

# Make some variables
x=1.234e-8
y=2
astr="An output string...whatever"
z=4.5+1j*1.3456  # a complex number

# Output them to a file already opened as fp
outlist=[x, y, astr, z]
repvars= repr(outlist)+"\n"
fp.write(repvars)

# Reading same list in:
instr=fp.readline()
inlist=eval(instr)
x1,y1,astr1,z1= inlist


That's what I needed.  3 lines to write or read a inhomogeneous 
collection of variables. I can add more variables, shuffle the order, 
whatever without messing with formatting, etc. That's pretty easy for me 
and it's easy for anyone to see and understand what's being done.  Not 
trying to start an argument, just showing how the former messasge I was 
replying to made a good point about Python's way of doing things and the 
effort to shake off old habits from other languages.

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


Re: Python and Ruby

2010-02-03 Thread Lou Pecora
In article 
<1944d953-25ad-440b-9317-a7a4b4de6...@f17g2000prh.googlegroups.com>,
 Jonathan Gardner  wrote:

> 
> I can explain all of Python in an hour; I doubt anyone will understand
> all of Python in an hour.
> 
> Coming from perl to python, the big "aha!" moment was when I realized
> there wasn't anything more than what I saw before me. I kept expecting
> something big around the corner, kind of like when I first discovered
> refs in perl, or when I realized how hard it truly was to write OO
> code in perl that actually does what you think it should do.
> 
> Perl has trained me to be fearful of the language, constantly on the
> lookout for jabberwockies. If you fall into one of those traps in
> perl, it's because you weren't smart enough and aren't worthy of the
> language, or so they say. It's never perl's fault. I mean, doesn't
> everyone know what the Schwartzian Transform is?
> 
> Python is the complete opposite. Go through http://docs.python.org/reference/
> . Once you've familiarized yourself with all the operators,
> statements, and the special methods, you're done with syntax and the
> core language. There is no more.
> 
> The next step is to learn the basic objects and functions in builtins.
> That's in the first seven chapters of 
> http://docs.python.org/library/index.html.
> You can always fall back to the "help" function to remind yourself if
> you forget. I do it all the time.
> 
> After that, it's merely figuring out which standard libraries do what
> and how. The documentation there is complete and awesome, and there
> are more than enough people willing to point you in the right
> direction here.
> 
> There are no dragons in this forest. Heck, this isn't even a forest---
> it's a single-room apartment with everything you need right there
> where you can see it. The thermostat is set to room temperature, and
> no matter what happens outside, you're safe and protected from it all.


That's a pretty accurate description of how I transitioned to Python 
from C and Fortran.  I kept trying to think of how to output data and 
parameter variables of different types to files for later reading in.  
How to format them all consistently and then get them back in with the 
exact same accuracy.  I was stuck in printf and scanf land.  Then after 
much noodling around and reading it hit me that I could just put all 
that output of different types of variables into a list, hit it with a 
repr() function to get a string version, and write the string to a file 
-- no formatting necessary-- three lines of code. Later reading in the 
string version (no formatting necessary), and hitting it with an eval() 
function returned all the values I originally had in those variables.  
How simple, but beautiful.  I was making it harder when Python was 
making it easier.  Trained on the wrong language.

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


SAGE help & support?

2010-01-14 Thread Lou Pecora
Does anyone know of any SAGE support or help newsgroups or email lists?

I know this is not a SAGE group and there is at least one support group 
for SAGE (http://groups.google.com/group/sage-support/), but I have gone 
there and asked similar questions twice and gotten zero replies (it's 
been about a month now).  Any suggestions appreciated.

If you interested more info:  I've installed SAGE from a full successful 
source build on my Mac Book Pro (OS X 10.4.11). SAGE runs in Terminal 
and I can import the usual suspects (numpy, matplotlib) into SAGE, but 
when I try to import pylab I get this message:

ImportError: No module named _tkagg

from inside the tkagg.py module in the site-packages in SAGE folder.  I 
cannot figure out what's going on here.  I use pylab a lot, so I really 
need it.  I've tried to track down the problem, but that's a huge 
framework and I get lost.  I have no idea where to go with this. 

Thanks for any pointers.

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


Re: Problem with multithreading

2009-06-25 Thread Lou Pecora
In article ,
 "larudwer"  wrote:

> "Jeffrey Barish"  schrieb im Newsbeitrag 
> news:mailman.2091.1245902997.8015.python-l...@python.org...
> > Jeffrey Barish wrote:
> >
> >> I have a program that uses multithreading to monitor two loops.  When
> >> something happens in loop1, it sends a message to loop2 to have it 
> >> execute
> >> a command.  loop2 might have to return a result.  If it does, it puts the
> >> result in a queue.  loop1, meanwhile, would have blocked waiting for
> >> something to appear in the queue.  The program works for a while, but
> >> eventually freezes.  I know that freezing is a sign of deadlock. 
> >> However,
> >> I put in print statements to localize the problem and discovered 
> >> something
> >> weird.  The freeze always occurs at a point in the code with the 
> >> following
> >> statements:
> >>
> >> print "about to try"
> >> try:
> >> print "in try"
> >> 
> >>
> >> I get "about to try", but not "in try".  Is this observation consistent

Try putting a flush in after the 2nd print statement in case the output 
is left in some I/O buffer when the thing terminates.  e.g.

import sys



try:
   print 'in try"
   sys.stdout.flush()
   

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


Re: Using C++ and ctypes together: a vast conspiracy? ;)

2009-06-03 Thread Lou Pecora
In article ,
 Lawrence D'Oliveiro  wrote:

> In message , Sebastian Wiesner wrote:
> 
> > 
> > 
> >> That said I've used C++ with ctypes loads of times, but I always wrap
> >> the exported stuff in extern "C" { } blocks.
> > 
> > No wonder, you have never actually used C++ with C types.  An extern "C"
> > clause tells the compiler to generate C functions (more precisely,
> > functions that conform to the C ABI conventions), so effectively you're
> > calling into C, not into C++.
> 
> Seems like the only sane way to do it. In all other directions lies madness.

Agreed. I've done this several times and it works fine.  Once I'm in C 
I'm really in C++ and can use all my C++ code and libraries.  Not a big 
problem really.  But maybe I'm missing something.

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


Re: Your Favorite Python Book

2009-05-15 Thread Lou Pecora
In article 
,
 Mike Driscoll  wrote:

> On May 11, 4:45 pm, Chris Rebert  wrote:

> >
> > I like "Python in a Nutshell" as a reference book, although it's now
> > slightly outdated given Python 3.0's release (the book is circa 2.5).
> >
> > Cheers,
> > Chris

"Python in a Nutshell" -- Absolutely!  Covers a lot in an easily 
accessible way.  The first book I reach for.  I hope Martelli updates it 
to 3.0.

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


Re: numpy.where

2009-04-11 Thread Lou Pecora
In article <747te7f1209a...@mid.individual.net>,
 Peter Pearson  wrote:

> On Thu, 09 Apr 2009 09:09:18 -0400, Lou Pecora wrote:
> >
> > Really,  I've gotta RTFM. :-)
> 
> Hey, if you find TFM, please tell me where it is.  I haven't
> found anything Fine.  I even bought Travis Oliphant's book,
> which helps a little, but . . .

Travis' book is what I have and what I was thinking of when I made the 
statement.

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


Re: numpy.where

2009-04-10 Thread Lou Pecora
In article ,
 Robert Kern  wrote:

> http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

That helps, thanks.  So I can RTFWP, too.  :-)

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


Re: numpy.where

2009-04-09 Thread Lou Pecora
In article ,
 Neil Crighton  wrote:

> 
> I'm not sure exactly what you're trying to do, but maybe you want a boolean
> array to select the right elements? So if time and energy are 1-d numpy arrays
> of the same length:
> 
> >>> condition = (min_time <= time) & (time <= max_time)
> >>> new_time = time[condition]
> >>> new_energy = energy[condition]
> 
> There's also a Numpy list for these kind of questions:
> 
> http://dir.gmane.org/gmane.comp.python.numeric.general
> 
> Neil


Thanks, Neil.  Always something to learn.  I've used Numpy for several 
years, but still have not plumbed the depths.  Just tried this script 
and, yep, it works.

  arr=array([-1,1.0,2.2,-10.0,1.1, 0.9,-0.9])
  cond= arr < 1.0
  print cond
  brr=arr[cond]
  print brr

Output:

[ True False False  True False  True  True]
[ -1.  -10.0.9  -0.9]

Really,  I've gotta RTFM. :-)

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


Re: python for loop

2009-04-03 Thread Lou Pecora
In article 
<5c92e9bd-1fb4-4c01-a928-04d7f6733...@e21g2000yqb.googlegroups.com>,
 Aaron Brady  wrote:

> On Apr 2, 6:34 pm, Tim Wintle  wrote:
> > On Thu, 2009-04-02 at 15:16 -0700, Emile van Sebille wrote:
> > > Lou Pecora wrote:
> > > > Confusion only comes when you try to force the
> > > > defintion of one of them on the other and then say it's illogical or not
> > > > natural.  Both are natural.
> >
> > > Consider the French 'Premiere etage' vs the American 'First Floor'
> >
> > or even in the same language - "first floor" in English (UK) is very
> > different from "first floor" in English (US).
> 
> Did I tell you guys that 'natural' has 38 definitions at
> dictionary.com?


Amazing.  I suggest you pick the one that fits best.

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


Re: python for loop

2009-04-02 Thread Lou Pecora
In article 
,
 Carl Banks  wrote:


> 
> I think people were being facetious.  To me the first item in the list
> is x[0]--ordinal does not match cardinal.  However, I don't use
> ordinals much when talking about list items; I'll say item 2, not
> third item.


Well, it's been said in many forms in this thread, but maybe this 
version will click with some.  Thinking of ordinals as specifying 
position by order and cardinals as counting the number of steps from a 
specified place to an item you just have to realize that 0 and 1 based 
indexing have decided to use *different* definitions for the 
conglomerate symbols A[i] or A(i):

1 based indexing (ordinality):
  A[i] is the ith item in the ordered list (1st, 2nd, etc. - no need for 
0th as an ordinal)

0 based indexing (cardinality):
  A[i] is the item i steps from the beginning of the list.

I know most of what's been said is all around the above, I just thought 
explict statements might help.  Both are prefectly reasonable and 
consistent definitions.  Confusion only comes when you try to force the 
defintion of one of them on the other and then say it's illogical or not 
natural.  Both are natural.

Of course, in some languages like C an array name, say A, points to the 
first item in memory of the array which is assumed to be structured 
sequentially.  Then A[0] is the first item at the address A or since we 
are using cardinality (0 based indexing) it's the item 0 steps from the 
beginning.  A[1] is the item at address A+1, i.e. 1 step from the 
address A, the array beginning.

I suspect that was a very practical choice for C since it's a systems 
language and down at that level you're flipping bit, bytes, addresses, 
etc.  But a practical consequence was that there was very little +1 or 
-1 arithmetic necessary to manipulate the array elements.  That carried 
over into other languages and their design.  People have already pointed 
out the nice features of such in Python where A[n:n] is an empty list, 
A[:n]+A[n:]=A, etc.

Now, I'm not a systems/computer guy. Just a scientist who does a lot of 
number crunching.  But I have found out that even in that case you end 
of traversing lists, tuples, etc. a lot.  Slicing and dicing them.  And 
you quickly come to appreciate the 0 based approach to indexing and soon 
don't miss the Fortran 1-based indexing.

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


Re: python for loop

2009-04-02 Thread Lou Pecora
In article ,
 Steven D'Aprano  wrote:

> So an ordinality of zero just means the number 
> of elements of something that doesn't exist.


You do realize that will give most people headaches.   :-)

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


Re: python for loop

2009-04-01 Thread Lou Pecora
In article <91t6t4hfjicgvdrcgkhdjfro3ko3ktu...@4ax.com>,
 Lada Kugis  wrote:

> On Wed, 1 Apr 2009 00:40:17 -0700 (PDT), Carl Banks
>  wrote:
> 
> >
> >Lada,
> >
> >I am also an engineer, and I can tell your idea of intuitive is not
> >universal, even among engineers.  I certainly do not lean toward one-
> >based indexing.
> >
> >From a programming standpoint--and remember Python is a programming
> >language--zero-based indexing eliminates the need for a whole lot of
> >extra +1s and -1s when indexing, slicing, and iterating, a lot more
> >than it causes, and that is worth the "cost".  This might not be
> >apparent to you if you never tried seriously taking advantage of
> >indexing from zero, or if your programming experience is very narrow.
> >These both seem to be true for you, so you'll just have to take my
> >word for it.
> 
> 
> You have repeated several cs based points already stated. But apart
> from a programming standpoint - could you give a few examples, where
> "on paper" (as to avoid stepping into "programmer's territory") zero
> indexing could be more intuitive ?

This has become a moving target.  I thought your original complaint was 
about Python (the programming language) vs. Fortran (the programming 
language) and C (the programming language used in an odd way).

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


Re: python for loop

2009-04-01 Thread Lou Pecora
In article <72i5t4tgfo2h4gd6ggcs02flkca85kg...@4ax.com>,
 Lada Kugis  wrote:


>  and
> the (m-n) point Chris was trying to explain doesn't seem that relevant
> to me.

That's because you haven't done enough programming really using the 
Python structures and objects.  You can really do a lot with lists and 
tuples.  When you do you will see Chris' point emphatically.

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


Re: python for loop

2009-04-01 Thread Lou Pecora
In article <1ej5t4930m29h0f6ttpdcd83t08q2q3...@4ax.com>,
 Lada Kugis  wrote:

> On 01 Apr 2009 01:26:41 GMT, Steven D'Aprano
>  wrote:
> 
> >
> >Why Python (and other languages) count from zero instead of one, and 
> >why half-open intervals are better than closed intervals:
> >
> >http://www.johndcook.com/blog/2008/06/26/why-computer-scientists-count-from-z
> >ero/
> >http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
> 
> steven, thanks for answering,
> 
> yes, i saw the second one a little time ago (someone else posted it as
> well in really cute handwriting version :) and the first time just
> now, but the examples which both of them give don't seem to me to be
> that relevant, e.g. the pros don't overcome the cons.
> 
> imho, although both sides (mathematical vs engineer) adress some
> points, none of them give the final decisive argument.
> i understand the math. point of view, but from the practical side it
> is not good. it goes nicely into his tidy theory of everything, but
> practical and intuitive it is not. as i said, being an engineer, i
> tend towards the other side, so this is biased opinion (nobody can be
> unbiased) but from a practical side it seems unpractical for
> engineering problems (and to me, the purpose of computers is to help
> humans to build a better world, not to prove theories - theories are
> useless if they don't help us in reality. so we should try to adapt
> computing to real world, not our world to computers).

There is nothing more practical than a good theory. 
 --- James Clerk Maxwell

You said you came from the C world (besides Fortran).  If so, you have 
already seen array indexing starting with 0 and going to n-1.  

Why, then, should Python be so foreign to you?

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


Re: Problem: Terminal (OS X) window exits immediately on opening. & Solution.

2009-03-17 Thread Lou Pecora

Python wrote:


On 16 mrt 2009, at 22:15, Lou Pecora wrote:


Because the shell process in the Terminal window would exit right after
it started even when I was just trying to open a new window (not even
running a script), i.e. command-N in Terminal.  So I could not run
anything from the Terminal.

More info:  There is an Executestring in the Terminal preferences that
is executed (I would guess as a shell command or script) when the shell
starts up (which happens whenever a new window is opened).  If that is
bad in any way, the shell exists with an error message.  There is no way
to run any shell in the Terminal at that point.  The only option appears
to be to clean up the preferences.  I don't know why the preferences got
a bad command while I was running Python scripts.  Maybe nothing to do
with Python, maybe it does.  Not sure.

--
-- Lou Pecora
--
oh i think it understand i now... it has nothing to do with python, 
has it?

Well, I can't figure out which app/system is to "blame."

just with some garbage left by a python script that should have been
deleted at startup of OSX
The garbage was left in the Terminal's preferences (the Property List). 
That's pretty specific.  Why?  I don't know.  It just shouldn't have 
been there, I think.  It had nothing to do with the startup of OS X.


501 is the default user ID in OSX
maybe it's a bash thing?
That's interesting.  Could be.  At least I found the solution and since 
it seemed to involve Python, I thought the OS X people on the list might 
be interested.  Thanks for the info.


--
Cheers,

Lou Pecora

Code 6362
Naval Research Lab
Washington, DC  20375, USA
Ph:  +202-767-6002
email:  louis.pec...@nrl.navy.mil

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


Re: Problem: Terminal (OS X) window exits immediately on opening. & Solution.

2009-03-16 Thread Lou Pecora

Python wrote:


On 16 mrt 2009, at 22:10, Lou Pecora wrote:




why don't you just execute the script directly form the terminal?
then you will be able to read all error messages...
and you can delete all the files you want

just my 2c

Arno


Because the shell process in the Terminal window would exit right 
after it started even when I was just trying to open a new window 
(not even running a script), i.e. command-N in Terminal.  So I could 
not run anything from the Terminal.

--

(please use reply-all so it also goes to the list :)  )


i don't understand...
if you open the terminal from /Applications/Utilities/Terminal
it comes up with a window and you can execute any script from there

No.

without the window closing when the script exits, or not?


No, I could not execute anything when I opened a window.  A shell would 
start, then immediately exit leaving an error message and a logout.  The 
Terminal has an 'Executestring' property in the preferences (Property 
List) which it tries to execute before giving you a shell prompt.  If 
that string has a bad command or refers to a file that does not exist 
(my case), the shell exits (Logout).  The Terminal is incapacitated 
until you remove that bad 'Executestring' from the preferences.  
Terminal does not crash.  The window stays open, but the shell is logged 
out.  Open another window, same thing happens.


I got that problem while running Python scripts from an Editor.  But 
even trying to just open a window/shell caused a failure.  The strange 
thing was that the bad file was a .py file down in the /var directory 
which something (BBEdit? The Terminal? Python? The System? ??) put 
there.  Why?  I don't know.


--
Cheers,

Lou Pecora

Code 6362
Naval Research Lab
Washington, DC  20375, USA
Ph:  +202-767-6002
email:  louis.pec...@nrl.navy.mil

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


Re: Problem: Terminal (OS X) window exits immediately on opening. & Solution.

2009-03-16 Thread Lou Pecora
In article ,
 Python  wrote:

> > --
> why don't you just execute the script directly form the terminal?
> then you will be able to read all error messages...
> and you can delete all the files you want
> 
> just my 2c
> 
> Arno

Because the shell process in the Terminal window would exit right after 
it started even when I was just trying to open a new window (not even 
running a script), i.e. command-N in Terminal.  So I could not run 
anything from the Terminal. 

More info:  There is an Executestring in the Terminal preferences that 
is executed (I would guess as a shell command or script) when the shell 
starts up (which happens whenever a new window is opened).  If that is 
bad in any way, the shell exists with an error message.  There is no way 
to run any shell in the Terminal at that point.  The only option appears 
to be to clean up the preferences.  I don't know why the preferences got 
a bad command while I was running Python scripts.  Maybe nothing to do 
with Python, maybe it does.  Not sure.

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


Problem: Terminal (OS X) window exits immediately on opening. & Solution.

2009-03-16 Thread Lou Pecora
Since this happened with a Python script and some people here use OS X 
and Terminal to run scripts I thought this might be helpful.

I recently ran into this problem using Terminal and found the solution.  
I thought those who use the Terminal in OS X might be interested.

The problem appeared suddenly.  Whenever I tried to open a new window in 
Terminal I would get the message that Terminal tried to execute a 
certain file (way down in the /var directory), but the file didn't 
exist.  And the process would Exit.  Very frustrating since you can't 
use the Terminal to help find the problem.

E.g error message:

/var/tmp/folders.501/Cleanup\ At\ 
Startup/drvrSDWB_2-258580497.358.py.command; exit
-bash: /var/tmp/folders.501/Cleanup At 
Startup/drvrSDWB_2-258580497.358.py.command: No such file or directory

The Solution is to go into the preference file for the Terminal (located 
in 
/Users/your_account_name_here/Library/Preferences/com.apple.Terminal.plis
t) and open it with the Property List Editor (should open automatically 
with a double click or you might have to install the Property List 
Editor from the System CDs that came with your computer).  Under the 
heading Executionstring you will see the name of the file that the 
Terminal is choking on.  Double click the name and delete it.  Save. and 
quit the Property List Editor.  The Terminal should work normally now. 

More info.  I got this problem while running Python scripts from BBEdit 
(which automatically launches the scripts in a Terminal Window). Why it 
happened is lost on me.  I don't know if Python, BBEdit, or Terminal 
munged the property list.  At least I managed to track it down.

I hope this helps someone if you've had this problem.

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


Re: quick beginners List comprehension question

2009-01-21 Thread Lou Pecora
In article ,
 Philip Semanchuk  wrote:

> 
> Other answers have been good; to them I'll add the comment that list  
> comprehensions are for *constructing* lists, not manipulating the  
> elements thereof.
> 
> HTH
> Philip


Well this seems to work just fine.  What am I missing:

   A=[1,2,3]
   print A
   A=[2*a for a in A]
   print A

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


Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-12 Thread Lou Pecora
In article ,
 Roy Smith  wrote:

> In article 
> <34c95e04-5b3f-44bc-a5bf-498518507...@p36g2000prp.googlegroups.com>,
>  "Madhusudan.C.S"  wrote:
> 
> > In such situations, where the Instance variables come into existence
> > only when they are used it is very difficult to track the flow of code.
> 
> As the saying goes, "It's possible to write Fortran in any language".
> 
> My personal habit is to "declare" all instance variables in the __init__() 
> method of every class.  If there's no better value, I set them to None.  
> This isn't strictly required, but I think it makes it easier for somebody 
> reading the code to understand the class.

I agree with you. I do exactly this. It prevents a lot of problems by 
giving one place to look for class variables and comments on them.  
Setting to None is good, too, since many times if I use one before 
setting a value I'll get an exception or really bad results that I can 
easily trace to the unset variable.

> I'm not a big fan of dogmatic rules, other than the rule that says you 
> should make your code as easy for somebody else to understand as possible.

Right.

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


Re: Python is slow

2008-12-22 Thread Lou Pecora
In article ,
 "James Mills"  wrote:

> In case anyone is not aware, Python is
> also used for heavy scientific computational
> problems, games such as Civilisation and
> others, and I believe (correct me if I"m wrong)
> it's also used by NASA.
> 
> --JamesMills

Python has become very popular in scientific computation.  You'll find 
it in use lots of places (universities, national labs, defense labs).  I 
use it for solving partial differential equations for quantum chaos 
calculations and went to C for speed up where needed using ctypes which 
is very straightforward and plays nice with numpy array/matrix 
libraries.  I've been doing scientific programming for 30 years.  Python 
with C extensions and libraries is the best approach I've ever used.  
Calculation speed is not a problem and the code can be "tweaked" to 
increase it easily.  Programming speed is incredible.  I can get 
substantial object oriented code up and running much faster than 
anything I've ever used.

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


Re: python on Mac

2008-08-28 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> Hi All.
> I'm really new in the python world, so, sorry if my question is particulary
> stupid.
> I've just installed on my system (Mac OS X 10.4 PPC) the python version
> 2.5.2 and all works fine.
> My next step is to install the version 3.0 (when available). I've read
> somewhere that this version will break the backward compatibility with the
> 2.x series. I know that several Mac apps (such as Xcode developement
> environment) use python for its internal functionalities. Now, my question
> is: what will appen to the Mac apps if I install the version 3.0 of python?
> Is it safe to install this version without to compromise the behaviour of
> the system?
> 
> Thanks in advance for any answer and, again, sorry if my question is
> particulary stupid, I will learn with time.
> 
> Luca.

The standard Python installs that I have put the new python in the 
directory /Library/Frameworks/Python.framework/Versions/Current/   and 
the additional packages in some subdirectory of that one.

The Apple installed Python is in 
/System/Library/Frameworks/Python.framework/Versions/Current/

DO NOT TOUCH that one.  Just leave it alone.  You can set your 
.bash_profile path to make sure your Python is used when you run your 
scripts.  This shouldn't affect the Apple Python.  Basically, the 
directories /usr/local/:/usr/local/bin/ should come *before* the system 
/bin directories.  So your .bash_profile should have something like this 
line in it:

PATH="/usr/local/:/usr/local/bin/:${PATH}"
export PATH

Bottom line:  your installs and Apples' Python are separate and that's 
how it should be.  

Hope that helps.  Others: please correct if I am wrong. Thanks.

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


Re: php vs python

2008-06-02 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Ethan Furman <[EMAIL PROTECTED]> wrote:

> Jerry Stuckle wrote:
> 
>  >
>  > As I've said before - good programmers can write good code in any
>  > language.
>  >
> 
> So... an eloquent speaker of English is also an eloquent speaker of 
> Spanish/French/German?

Oh, Bull.  Computer languages are so narrow they are more like dialects 
of a single language. If you know English you can learn to speak to a 
Brit, Scot, or Aussie.   That's more like it...if you really want to 
stretch the definition of a language.  And it is a stretch.  Anyone 
speak C?

Sheeze.

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


Re: Hungarian Notation

2008-05-27 Thread Lou Pecora
In article 
<[EMAIL PROTECTED]>,
 Dan Bishop <[EMAIL PROTECTED]> wrote:

> On May 27, 12:28 am, "inhahe" <[EMAIL PROTECTED]> wrote:
> > Does anybody know of a list for canonical prefixes to use for hungarian
> > notation in Python?  Not that I plan to name all my variables with hungarian
> > notation, but just for when it's appropriate.
> 
> pnWe vUse adjHungarian nNotation prepAt nWork, conjAnd pnI vauxDont
> vLike pnIt advVery advMuch.  conjSo pnI vAvoid pnIt prepIn nPython.

HAHAHAHAHAHA! Beautifully done.  Next time I need to diagram a sentence 
I will come to you.  You're the man.  :-)

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

Re: Using Python for programming algorithms

2008-05-19 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Roel Schroeven <[EMAIL PROTECTED]> wrote:

> Bruno Desthuilliers schreef:
> > 1/ being interpreted or compiled (for whatever definition of these 
> > terms) is not a property of a language, but a property of an 
> > implementation of a language.
> > 
> > 2/ actually, all known Python implementations compile to byte-code.
> > 
> 
> You keep saying that, and in theory you're right. But I'm still inclined 
> to disagree with it, since the practical reality is different. Python is 
> indeed compiled to byte code, but if you compare that byte code with 
> assembly code you'll see that there's a whole world of difference 
> between the two, largely because of the dynamical nature of Python. Fact 
> is that Python was designed from the start to run on a virtual machine, 
> not on the native hardware.
> 
> C OTOH was designed to be compiled to assembly code (or directly to 
> machine code) and as a result there are no (or virtually) no 
> implementations that interpret C or compile it to bytecode.


But how about this C/C++ interpreter.  Dr. Dobbs article:  
http://www.ddj.com/cpp/184402054.  Title and first two paragraphs:

Ch: A C/C++ Interpreter for Script Computing
Interactive computing in C 

Ch is a complete C interpreter that supports all language features and 
standard libraries of the ISO C90 Standard, but extends C with many 
high-level features such as string type and computational arrays as 
first-class objects.

For some tasks, C and its compile/ link/execute/debug process are not 
productive. As computer hardware becomes cheaper and faster, to be 
productive and cost effective, script computing in C/C++ can be an 
appealing solution. To this end, we have developed Ch, an embeddable 
C/C++ interpreter for cross-platform scripting, shell programming, 2D/3D 
plotting, numerical computing, and embedded scripting [1].

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


Re: Mathematics in Python are not correct

2008-05-12 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Terry Reedy" <[EMAIL PROTECTED]> wrote:

> "Mark Dickinson" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> On May 11, 9:36 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> |> Do you have in mind any situations in which it is advantageous to have 
> 0**0
> |> undefined?
> 
> | (Playing devil's advocate here.) If you regard x**y as exp(y*log(x))
> 
> Which, of course, I was not, but for the sake of discussion
> 
> | then it's not at all clear that 0.**0. should be considered well-defined.
> 
> Then it seems equally dubious that 0.**y, y>0, should be well-defined.
> It seems to me that lim as x goes to 0. exp(y*log(x)) is equally well 
> defined whether y is 0 or not, even though there is a discontinuity in the 
> limit.

Huh?  That "discontinuity" is the problem.  Actually, the problem is 
that the function f(x,y)=x**y=exp(y*ln(x)) will be double valued at x=0 
and y=0.  It's value will depend on the direction in which the limit 
approaches (x,y)=(0,0).  You cannot have a function that has two values 
at one domain point without adding branch cuts (see complex functions 
like ln(z), z is complex).  That's not well defined -- in your sense.  
You are choosing a branch cut and you must make sure the rest of your 
math and code are consistent with that.  You should also tell any users 
of your code about that decision.

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


Re: Mathematics in Python are not correct

2008-05-12 Thread Lou Pecora
In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> I am stunned that this simple misunderstanding of mine ended in a
> mathematical clash of a sort. :)  You guys really blew me away wih
> your mathematical knowledge. And also the 0**0 is a thing I've never
> thought about trying, until now that is. If the mathematical rule is
> that EVERYTHING raised to the power of 0 is 1, then we should accept
> that, even in the case of 0**0. This is just the way it is.

Well, it's really not that simple.  You've seen that 0**0 can lead to 
problems in various areas of mathematics (check the Wikipedia article on 
analysis/calculus application vs. combinatorics and discrete math).  You 
have to be aware of those dangers, what the language (Python here), and 
what your application requires.  Consistency in mathematics is vital.  
If you are using 0**0=1, then your code should be consistent with that 
usage.

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


Re: Mathematics in Python are not correct

2008-05-10 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Terry Reedy" <[EMAIL PROTECTED]> wrote:

> "Lou Pecora" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> | In article <[EMAIL PROTECTED]>,
> | "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> |
> | > "Luis Zarrabeitia" <[EMAIL PROTECTED]> wrote in message
> | > news:[EMAIL PROTECTED]
> | > | Btw, there seems to be a math problem in python with 
> exponentiation...
> | > | >>> 0**0
> | > | 1
> | > | That 0^0 should be a nan or exception, I guess, but not 1.
> | >
> | > a**b is 1 multiplied by a, b times.  1 multiplied by 0 no times is 1.
> | > But there are unenlighted people who agree with you ;-)
> | > Wikipedia has a discussion of this.
> | >
> | > tjr
> |
> | I like that argument better.  But...
> |
> | I've also heard the very similar a**b is a multiplied by a b-1 times.
> 
> Me too, in school, but *that* definition is incomplete: it excludes b=0 and 
> hence a**0 for all a.  It was the best people could do before 0 was known.
> But 0 was introduced to Europe just over 800 years ago ;-)

[cut some interesting examples]

Yes, I was also thinking about the b=0 case and then the case when b<0.  
If you solve the b<0 case, you solve the b=0 case for a !=0.  Define

a**b= a multiplied by 1/a |b-1| times when b<0.  Then for b=0 we get 
a*(1/a)=1.

Of course, I can avoid all this mathematical dancing around by using 
some of the other simpler definitions like the original one.  :-)

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


Re: Mathematics in Python are not correct

2008-05-09 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Terry Reedy" <[EMAIL PROTECTED]> wrote:

> "Luis Zarrabeitia" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> | Btw, there seems to be a math problem in python with exponentiation...
> | >>> 0**0
> | 1
> | That 0^0 should be a nan or exception, I guess, but not 1.
> 
> a**b is 1 multiplied by a, b times.  1 multiplied by 0 no times is 1.
> But there are unenlighted people who agree with you ;-)
> Wikipedia has a discussion of this.
> 
> tjr

I like that argument better.  But...

I've also heard the very similar a**b is a multiplied by a b-1 times.  
That gives 0**0=0*(1/0).  Uh, Oh!  If you want consistency with the 
treatment of exponents that might cause problems.  Tough situation when 
you have a "discontinuity" at 0 for x^x.

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


Re: Mathematics in Python are not correct

2008-05-09 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Michael Torrie <[EMAIL PROTECTED]> wrote:

> [EMAIL PROTECTED] wrote:
> > Have a look at this:
> > 
> >>>> -123**0
> > -1
> > 
> > 
> > The result is not correct, because every number (positive or negative)
> > raised to the power of 0 is ALWAYS 1 (a positive number 1 that is).
> 
> No python is correct.  you're expression parses this way, when converted
> to a lisp-ish prefix expression:
> 
> (- (123 ** 0 ))

Yeah, it's just the standard parser.  For other situations Python does 
fine.  E.g.

In [1]: x=-1

In [2]: x**0
Out[2]: 1

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


Re: #!/usr/bin/env python vs. #!/usr/bin/python

2008-05-03 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Grant Edwards <[EMAIL PROTECTED]> wrote:

> On 2008-05-02, D'Arcy J.M. Cain <[EMAIL PROTECTED]> wrote:
> > On Sat, 03 May 2008 00:44:00 +1000
> > Ben Finney <[EMAIL PROTECTED]> wrote:
> >> "D'Arcy J.M. Cain" <[EMAIL PROTECTED]> writes:
> >> > As someone else pointed out, not all the world is Linux.
> >> 
> >> It's a good thing I've never implied such to be the case.
> >
> > You haven't *said* it but you have definitely *implied* it.
> > Installing Python in /usr/bin is not common.
> 
> It is common.  That's where it's installed by almost all Linux
> distributions.

MacOS X system python (or links to them) is in the same place.

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


Re: Python 2.5 adoption

2008-04-21 Thread Lou Pecora
In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> On Apr 21, 9:28 am, [EMAIL PROTECTED] (Aahz) wrote:
> > 
> >
> > Why is this newsgroup different from all other newsgroups?  
> 
> Different is a verbally atomic relation.


It's a Passover question.

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

Re: Basic optimization of python.

2008-04-09 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Hrvoje Niksic <[EMAIL PROTECTED]> wrote:

> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes:
> 
> >> Eg:
> >> a = 1 + 2
> >> .vs.
> >> a = 3
> >> which one is more effective? Does the compiler calculate the result at
> >> compile time? How about constant spreading?
> >
> > Algebraic optimizations aren't done AFAIK
> 
> Just try it:
> 
> Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32) 
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> dis.dis(lambda: 10+5)
>   1   0 LOAD_CONST   2 (15)
>   3 RETURN_VALUE

Not always. On a Mac running Python 2.4, here's what I get:

In [3]: dis.dis(lambda: 3+4)
  1   0 LOAD_CONST   1 (3)
  3 LOAD_CONST   2 (4)
  6 BINARY_ADD  
  7 RETURN_VALUE

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-24 Thread Lou Pecora
In article 
<[EMAIL PROTECTED]>,
 Nicola Musatti <[EMAIL PROTECTED]> wrote:

> On Feb 22, 12:07 pm, Paul Rubin <http://[EMAIL PROTECTED]> wrote:
> > Nicola Musatti <[EMAIL PROTECTED]> writes:
> > > In C++ memory is just another resource which you can handle just like
> > > any other one, possibly using RAII.
> >
> > Ok, I'll bite.  Here's a straightforward Python expression:
> >
> >a = [f(x) + g(y) for x,y in izip(m1, m2) if h(x,y).frob() == 7]
> >
> > Consider how many intermediate objects are being allocated in figuring
> > out that listcomp.  Do you REALLY want to manage all the deallocation
> > with something like RAII?
> 
> 
> What makes you think that a translation of a similar expression would
> involve explicit dynamic allocation at all? Barring bugs, here's an
> equivalent example:
> 
> #include 
> #include 
> #include 

[cut a lot of C++ code]

I realize the original point was about dynamic allocation and GC, but 
for me the raw juxtaposition of the *one* line of clear Python code with 
the equivalent mass of C++ code is shocking.  Thanks for that.

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-24 Thread Lou Pecora
Just some anecdotal confirmation:

In article <[EMAIL PROTECTED]>,
 "Ryan Ginstrom" <[EMAIL PROTECTED]> wrote:

> I personally used C++ for about 90% of my code for 10 years. During that
> time, I was chugging the C++ Kool-Aid so hard I almost peed myself. I still
> think that C++ is a beautiful language, but I have also come to think that
> starting a program with C++ is a premature optimization. 

Yes, I came to the same conclusion and now start all projects in Python, 
then add C/C++ extensions for optimization.  

> I think that very few Python programmers today started with Python. Most of
> them came to Python for a reason. 

Exactly right in my case.  In fact this observation is directly related 
to the one your the previous paragraph.  Python is a good language in 
which to start a progrom.

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


Re: Article of interest: Python pros/cons for the enterprise

2008-02-22 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:

> 
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:python-
> > [EMAIL PROTECTED] On Behalf Of Carl Banks
> > Sent: Wednesday, February 20, 2008 8:39 PM
> > To: python-list@python.org
> > Subject: Re: Article of interest: Python pros/cons for the enterprise
> 
> > C++ is a compile-time, type-checked language, which means it is
> > totally safer for newbies than Python.  Yep, your big company is
> > totally safe with newbie C++ programmers.
> 
> Eh, don't laugh too hard.  Since Python code isn't type-checked until
> the actual code block is executed, you have to go through the extra step
> of testing/running  every  line of code before you'll find an error.
> Then there's the problem of how mutable Python objects are.  So even if
> you execute every line of code, you might not have executed the code
> with every possible type of object combination.
> 
> Compared to a statically typed language, it can get very expensive to
> write comprehensive test cases for python scripts.  So I wouldn't be
> quick to dismiss the notion that Java/C#/C++ are more newbie-safe than
> Python. =/
> 
> An amusing case in point was where I had a type-cast error in an
> exception's catch block's print statement.  This simple error caused the
> program to stop with an unhandled exception.  Something that basic would
> have been caught in a statically typed language very early in the dev
> cycle when it's cheaper to fix the problem.  And the idea of
> running/testing exceptions or simple print statements isn't always
> foremost in people's minds.  =P


Well, you're technically right about static typing. That could head off 
some bugs... But my experience over several years has been that this has 
never happened to me.  That is, where I need to test every line of code 
or even half of them.  What usually happens is that I get an error, I 
get the line and module, go there, and realize I tried to use data that 
didn't fit the expression (e.g. an object without the required method).  
Usually, a one-step fix.  What still occasionally gets me is mutable 
objects where I just use "=" to set two things (accidentally) equal to a 
mutable object instead of copying. Then modify one and get and error 
when the other object is used since they were the same object.  I know 
better, but I have a half life on this of about 4 months which means 
that about twice a year this one gets me.

Looking at it the other way having done C++ development, I am  w a y  
more productive in Python and overall spend far less time debugging.  
Just my experience.  YMMV.

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


Re: OT: Star Wars and parsecs [was Re: Why not a Python compiler?]

2008-02-11 Thread Lou Pecora
In article 
<[EMAIL PROTECTED]>,
 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> On Feb 8, 2:53?pm, Lou Pecora <[EMAIL PROTECTED]> wrote:
> > In article <[EMAIL PROTECTED]>,
> > ?Grant Edwards <[EMAIL PROTECTED]> wrote:
> >
> > > On 2008-02-08, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> >
> > > > ? ? ? A Parsec is a fixed value (which, admittedly, presumes the culture
> > > > developed a 360degree circle broken into degrees => minutes =>
> > > > seconds... or, at least, some units compatible with the concept of an
> > > > "arc second", like 400 grads of, say, 100 "minutes", each of 100
> > > > "seconds")
> >
> > > It also presumes a standard diamter of that circle.
> >
> > Which is the Earth's orbit. ?So, long, long ago in a galaxy far, far
> > away did they know about the Earth and decide to use it as the basis for
> > length in the universe? ?Even before people on earth defined it? ?
> >
> > Or (ominous music builds here, switch to low voice) is it as some now
> > contend? ?We are the decendents of a long, lost civilization who
> > colonized Earth and used it as a base for their operations to the point
> > of adopting it as their own home?
> >
> > ... ?You Betcha!
> >
> > :-)
> 
> How come they spoke English?


Because they taught it to us.  It's obvious.

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


Re: OT: Star Wars and parsecs [was Re: Why not a Python compiler?]

2008-02-08 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Grant Edwards <[EMAIL PROTECTED]> wrote:

> On 2008-02-08, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> 
> > A Parsec is a fixed value (which, admittedly, presumes the culture
> > developed a 360degree circle broken into degrees => minutes =>
> > seconds... or, at least, some units compatible with the concept of an
> > "arc second", like 400 grads of, say, 100 "minutes", each of 100
> > "seconds")
> 
> It also presumes a standard diamter of that circle.

Which is the Earth's orbit.  So, long, long ago in a galaxy far, far 
away did they know about the Earth and decide to use it as the basis for 
length in the universe?  Even before people on earth defined it?  

Or (ominous music builds here, switch to low voice) is it as some now 
contend?  We are the decendents of a long, lost civilization who 
colonized Earth and used it as a base for their operations to the point 
of adopting it as their own home?

...  You Betcha!



:-)

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


Re: Why not a Python compiler?

2008-02-07 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Torsten Bronger <[EMAIL PROTECTED]> wrote:

> > a parsec was a unit of time.
> 
> The latter because it was corrected in the novelization.
> 
> Tschö,
> Torsten.

Sounds like one.  The reverse of light year that sounds like a unit of 
time, but isn't.  I've heard it used seriously like time in some movie.

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

Re: a Python person's experience with Ruby

2007-12-11 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:

> Lou Pecora a écrit :
> > In article <[EMAIL PROTECTED]>,
> >  Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> > 
> > 
> >>>Thus: close;
> >>>could replace close();
> 
> *Please* give proper attribution. I'd *never* suggest such a thing.

I apologize.

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

Re: a Python person's experience with Ruby

2007-12-09 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:

> > Thus: close;
> > could replace close();

Wouldn't this give an ambiguity?  

afcn=close   # make an "alias" to the close function
val=close()  # set val to the return value of the close function

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


Re: Python surpasses Perl in TIOBE index

2007-12-04 Thread Lou Pecora
In article 
<[EMAIL PROTECTED]>,
 George Sakkis <[EMAIL PROTECTED]> wrote:

> On Dec 4, 10:08 am, [EMAIL PROTECTED] wrote:
> > This is *not* an attempt to start yet another Python-versus-
> > AnyOtherProgrammingLanguage flame war, but I thought people might be
> > interested in this:
> >
> > http://www.tiobe.com/tpci.htm
> >
> > Marc
> 
> Cool (assuming these numbers actually mean something), but this has
> more to do with Perl's fall than Python's increase:
> http://www.tiobe.com/tiobe_index/Perl.html.
> Even more amazing is the rate C++ is losing ground:
> http://www.tiobe.com/tiobe_index/C__.html
> 
> George

How about Visual Basic going up?

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


Re: Python surpasses Perl in TIOBE index

2007-12-04 Thread Lou Pecora
In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> http://www.tiobe.com/tpci.htm

But dreaded Ruby is coming up fast. Run Away! Run Away!

HAHAHAHAHAHA.

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


Re: Books on Python

2007-11-28 Thread Lou Pecora
In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> On Nov 27, 10:05 pm, "barcaroller" <[EMAIL PROTECTED]> wrote:
> > Can someone kindly recommend some good books on the following:
> >
> > Python for beginners
> > Python for advanced users
> >
> > Is there a bible like Larry Wall's Programming Perl or Bjarne Stroustrup's
> > The C++ Programming Language?
> 
> Python in a Nutshell is a very good reference.

I second that.  I also found Learning Python (Lutz & Ascher, O'Reilly 
pub.) to be helpful when I first started, but Nutshell is what I keep 
going back to.  Very good book.

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


Re: Iteration for Factorials

2007-10-25 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> > def factorial(i):
> >fact=1.0
> >for n in xrange(i):
> >   fact=n*fact
> >return fact
> 
> Simple minded indeed.
> 
> >>> factorial(3)
> 0.0
> 

Whoops, should have xrange(i)+1 there. Or, better, xrange(2,n+1). Save a 
multiplication.  Just trying to show the OP the scheme for iteration 
here.

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


Re: Iteration for Factorials

2007-10-24 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Nick Craig-Wood <[EMAIL PROTECTED]> wrote:

> Py-Fun <[EMAIL PROTECTED]> wrote:
> >  I'm stuck trying to write a function that generates a factorial of a
> >  number using iteration and not recursion.  Any simple ideas would be
> >  appreciated.
> 
> Here is the math geek answer ;-)
> 
> import math
> 
> def factorial(i):
> n = i + 1
> return math.exp(-n)*(n**(n-0.5))*math.sqrt(2*math.pi)*(1. + 1./12/n + 
> 1./288/n**2 - 139./51840/n**3)
> 
> Works for non integer factorials also...
> 
> See here for background
> 
>   http://mathworld.wolfram.com/StirlingsSeries.html


Well, that's Sterling's formula.  You do have to worry about 
convergence/accuracy.

How about (for intergers - simple-minded version):

def factorial(i):
   fact=1.0
   for n in xrange(i):
  fact=n*fact
   return fact

There might even be an array method that can be adapted to get the 
product.  Is there a product method? (analogous to a sum method)

Then you could use,

   arr=arange(i)+1
   fact=arr.product()  # or something like that

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


Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-28 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Jorgen Bodde" <[EMAIL PROTECTED]> wrote:

> I had the same feeling when I started, coming from a C++ background, I
> forgot about self a lot, creating local copies of what should be an
> assign to a class instance, or methods that could not be found because
> I forgot 'self' .
> 
> Now I am 'kinda' used to it, as every language has some draw backs
> (you can't please all). But, what about something in between like only
> using the dot (.) for a shorter notation?
> 
> self.some_var = True
> 
> Could become:
> 
> .some_var = True
> 
> Which basically shows about the same thing, but you leave 'self' out
> of the syntax. Ofcourse it should not be allowed to break a line
> between the dot and the keywords, else Python would never know what to
> do;
> 
> my_class()
> .my_var = True
> 
> Should not be parsed the same as;
> 
> my_class().my_var = True
> 
> Just a suggestion. I am pretty happy with self, but I could settle for
> a shorter version if possible.
> 
> - Jorgen

Hmmm... I like this idea.  Would you put a dot in the argument of a 
class method?

  def afcn(.,x,y):
  # stuff here

??

I still like it.  self remains a wart on python for me after 5 years of 
use despite a deep love of the language and developers' community.

-- 
-- Lou Pecora

When I was a kid my parents moved a lot, but I always found them.
  (R.Dangerfield)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plot with scipy

2007-05-06 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 redcic <[EMAIL PROTECTED]> wrote:

> I've already got this package. I just wanted to try something new.
> 
> However, since you talk about it, I've got a question regarding this
> package. The execution of the code stops after the line:
> pylab.show()
> which is off course the last line of my code. My problem is that I
> have to close the figure window in order to launch my program another
> time. I'd like to be able to launch my program many times with
> different parameters without having to close the figure windows before
> each launch.
> Just so you know, I'm using TkAgg backend.
> 
> Any hint ?

Here's what I do and it works well.  I am using a Mac so the text 
programs I mention are available there, but I bet you can find similar 
programs on Windows, Linus, or Unix (I think Emacs can do this, too).

I use a text editor to write the source code and launch it in a Terminal 
window.  On the Mac BBEdit does this and you can get its free version 
TextWrangler.  I can launch a program to do a plot, go back to the 
editor to change somehting and launch it again all while the first plot 
window is still open.  I get two terminal windows waiting on the closing 
of their respective plot windows.  I can click on each plot window and 
bring them to the front for comparison. Of course, I can continue to 
launch more and compare many plot windows.  Works for me.

Maybe there are other approaches that others can tell about.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plot with scipy

2007-05-04 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 redcic <[EMAIL PROTECTED]> wrote:

> Hi all,
> 
> I've just downloaded scipy v 0.5.2 and I would like to be able to draw
> plots. I've tried:
> import scipy.gplt
> import scipy.plt
> import scipy.xplt
> 
> and none of them work. Are these modules still included in scipy ? If
> not, where can I find them ?
> 
> Thanks for your answers,
> 
> Cédric
> 

You really want matplotlib and PyLab the library built on top of it.  
Search on the python.org site for examples.  Google will turn up a lot. 
Matplotlib w/ PyLab is a nice, easy plotting package.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: The smallest and largest values of numeric types

2007-04-17 Thread Lou Pecora
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote:

> Hi!
> How can I determine the smallest and largest values of numeric types 
> (for example int) possible in my system? I think there exists a function 
> for this task but I don't know it.

There is or was a module called "kinds" which was an implementation of 
PEP  0242.  I have it and it gives the values you are looking for (and 
more).  But I don't know where I got it.  I think it was once 
distributed with Macpython on MacPython.org, but I'm not sure.  I've 
searched for it, but nothing shows up except my own questions about it 
from many years ago and they have no clues.  

Does anyone know where this package is?  Or what might replace it.  It 
is very useful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error of matrix inversion using NumPy

2007-04-04 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "lancered" <[EMAIL PROTECTED]> wrote:

> Here is the eigenvalues of KK  I obtained:
> 
>  >>> linalg.eigvals(KK)
> array([  1.11748411e+05,   3.67154458e+04,   3.41580846e+04,
>  2.75272440e+04,   2.09790868e+04,   1.86242332e+04,
>  8.68628325e+03,   6.66127732e+03,   6.15547187e+03,
>  4.68626197e+03,   3.17838339e+03,   2.84888045e+03,
>  1.88279736e+03,   1.32427574e+03,   1.04946287e+03,
>  5.79303171e+02,   3.83111876e+02,   4.93826556e-12,
>  1.50263232e-12])
> 
> You are right. The ratio of max/min eigenvalues is 7.4368432669e+016
> Maybe this exceed the of precision of my machine?
> 
> Is there any tricks for me to be able to deal with this matrix
> correctly with
> NumPy?

That sounds large to me, too.  Close to the floating point accuracy.  
The problem is not with NumPy,but with double precision numbers. No 
routine can save you if the condition number is large.  However, several 
people here have noted that you might be able to solve your problem by 
avoiding inverting the matrix in the first place.  In other words, 
depending on your particular problem, there may be other ways to solve 
it beside brute force inversion.  Can you Use a QR or SVD approach?

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An error of matrix inversion using NumPy

2007-04-04 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "lancered" <[EMAIL PROTECTED]> wrote:

> Hi dear all,
> I am using Python2.4.2+NumPy1.0.1 to deal with a parameter
> estimation problem with the least square methods. During the
> calculations, I use  NumPy package to deal with matrix operations,
> mostly matrix inversion and trasposition. The dimentions of the
> matrices used are about 29x19,19x19 and 29x29.
> 
> During the calculation, I noticed an apparent error of
> inverion of a 19x19 matrix. Denote this matrix as KK, U=KK^ -1, I
> found the product of U and KK is not equivalent to unit matrix! This
> apparently violate the definition of inversion. The inversion is
> through the function linalg.inv().
> 
>I have checked that det(KK)=-1.2E+40. At first, I thought the
> error may be caused by such a large determinant, so I scaled it as
> LL=KK/100, then invert LL. Since det(LL)=11.5 and all its elements are
> within -180.0 to 850.0, this seems easier. But the result is still not
> correct, the product of LL^-1 thus obtained and LL still not unit
> matrix ... At the same time, the inversion results of some 29x19
> matrices are correct.
> 
>So,  can you tell me what goes wrong?  Is this a bug in
> Numpy.linalg? How to deal with this situation?  If you need, I can
> post the matrix I used below, but it is so long,so not at the moment.
> 
>Thanks in advance!
> 

Changing the overall scaling won't help unless the numbers themselves 
are near the double floating point boundary (perhaps).  The real number 
you want to calculate is the condition number of the matrix. Roughly the 
ratio of the largest to the smallest eigenvalue.  If that's large, then 
you're attempt at inversion is dealing with differences between very 
large and very small numbers and/or very small differences between two 
large numbers which probably goes beyond the number of digits (bits) the 
machine can provide to represent floating point numbers.  No rescaling 
of the original matrix will change that.  Do a google on "condition 
number".

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python shell on mac os x

2007-03-19 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Kevin Walzer <[EMAIL PROTECTED]> wrote:

> 7stud wrote:
> > On Mar 16, 2:53 am, [EMAIL PROTECTED] wrote:
> >> or go tohttp://pythonmac.org/packages/
> >>  and you have python 2.5 or python 2.4.4 with readline support
> > 
> > The download instructions seem to steer Mac users to version 2.4.4
> > because it has more modules available. What is the consensus on that?
> > 
> 
> If you just want binary packages installed, it might make sense to use 
> 2.4.4, but building new packages with 2.5 is easy: either use 
> easy_install or sudo python setup.py. I've had no trouble building the 
> stuff I need with 2.5.

And what is the stuff you need?  So we can see what definitely works.  
Thanks.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python in a desktop environment

2007-03-13 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Grant Edwards <[EMAIL PROTECTED]> wrote:

> > I'm a Python developer, I don't give a rats ass about what
> > people say about C#, Python, or c++, they all have their uses.
> > My main reasoning for considering C++ as the backend is some
> > things (reading memory for example) are much easier to do in
> > C++ than in Python, and we already have a lot written in C++.
^

[cut]

> > Anyways, thanks for everyones feedback, we will most likely go
> > with a combination of Python and C++.
> 
> I think you're nuts to decide that you need C++ before you've
> tested a Python implementation, but it's your nickle. :)

It really sounds like it's the C++ legacy that's driving Mr. Edward's 
decision.  The rest are just arguing points. Which several people have 
jumped at.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to Python

2007-03-12 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Dustan" <[EMAIL PROTECTED]> wrote:

> > What is the best way to get documentation about the functions
> > and classes of python? I tried to google, but usually I can just
> > find the __doc__ of the objects, without examples or anything that
> > can help me use it.
> >
> > Alberto Monteiro
> 
> Refer to this as a reference:
> http://docs.python.org/
> 
> It includes a tutorial and documentation on the functions and classes
> in all the global modules, as well as builtin functions (http://
> docs.python.org/lib/built-in-funcs.html) and syntax. If you have prior
> experience with programming, you may be able to learn python from the
> tutorial, but otherwise, I would highly recommend you get a good book
> for beginners on python (http://wiki.python.org/moin/PythonBooks);
> there's plenty of them out there.


Python in a Nutshell by Martelli (O'Reilly publ.) is very good.  

I also liked Learning Python by Lutz and Ascher (O'Reilly publ.) when I 
started Python, but I don't know if that's been updated recently.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this right? Multiple imports of same module.

2007-03-10 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Ben Finney <[EMAIL PROTECTED]> wrote:

> Lou Pecora <[EMAIL PROTECTED]> writes:
> 
> > ['import mymodule' in three separate modules]
> >
> > Then mymodule is imported only once, but each module has access to
> > it through the module name (mod1 and mod2) and the alias MM (mod3).
> > Is that right?
> 
> Not quite. The module is imported three times, and is assigned to
> three different namespaces; but the code in the module is executed
> only once, the first time it is imported. Each subsequent import skips
> the "execute the code" step.

Thanks.  That's clear.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this right? Multiple imports of same module.

2007-03-10 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Simon Brunning" <[EMAIL PROTECTED]> wrote:

> On 3/9/07, Lou Pecora <[EMAIL PROTECTED]> wrote:
> > I have noticed that using from xxx import * can lead to problems when
> > trying to access variables in the xxx module.
> 
> Don't do it, then. ;-)

I don't anymore.  But I find it's good to understand these things since 
there's something fundamental that I am missing that may later be 
useful.  This turned out to be the case as someone else in this thread 
(Dennis) gave a very good explanation of the source of the problem.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this right? Multiple imports of same module.

2007-03-10 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:

> 
>   Expected behavior if you 1) understand how Python variable binding
> works, and 2) that "from <> import *" is equivalent to
> 
> import <>
> name1 = <>.name1
> name2 = <>.name2
> 
>   IOWs, one is creating local names that are bound to the objects
> inside the imported module. If, subsequently, one does
> 
> name2 = 123
> 
> one has UNbound the connection to <>.name2 and rebound the local name to
> the integer object 123. Whereas 
> 
> <>.name2 = 123 
> 
> says "go into the module <>, and rebind its 'name2' to the integer
> object 123"; since you "went inside" to do the rebinding, any other code
> that also uses the <>.name2 reference will see the change inside <>.


Ah! (light bulb goes on)  Yes, I get it.  Thanks.  No more from ** 
import *.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this right? Multiple imports of same module.

2007-03-09 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Bart Ogryczak" <[EMAIL PROTECTED]> wrote:

> On Mar 9, 3:30 pm, Lou Pecora <[EMAIL PROTECTED]> wrote:
> > Then mymodule is imported only once, but each module has access to it
> > through the module name (mod1 and mod2) and the alias MM (mod3).  Is
> > that right?
> 
> Yes, it is.

Praise the Lord.  :-)  I got one right in the namespaces puzzles. (But 
see my followup on using  'from XXX import *' in this thread.  I'm still 
not a namespace guru.

> > I was concerned about multiple imports and efficiency.
> 
> If the module is already loaded, it won't be loaded again. Dictionary
> of loaded modules is avaliable as sys.modules.

Good to know.  Thank you.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this right? Multiple imports of same module.

2007-03-09 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:

> In <[EMAIL PROTECTED]>, Lou Pecora wrote:
> 
> > *In mod1.py
> > 
> > import mymodule
> > 
> > *In mod2.py
> > 
> > import mymodule
> > 
> > *In mod3.py
> > 
> > import mymodule as MM
> > 
> > Then mymodule is imported only once, but each module has access to it 
> > through the module name (mod1 and mod2) and the alias MM (mod3).  Is 
> > that right?
> 
> Yes, that's correct.
> 
> Ciao,
>   Marc 'BlackJack' Rintsch

Thank you.

A further confusion (if I may):

I have noticed that using from xxx import * can lead to problems when 
trying to access variables in the xxx module.

E.g.

-- File f2.py

imvar=1

def prn():
   print imvar

-- File junk.py

from f2 import *
prn()
imvar=2
prn()

-- Running junk.py gives the output:

1
1

Not what I would expect which is,

1
2

Namespaces get confusing.  I have begun to switch to using 'import f2 
as' which gives the 2nd expected result. Safer, but still a bit puzzling.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Is this right? Multiple imports of same module.

2007-03-09 Thread Lou Pecora
>From what I gleaned on some messages this is the way multiple imports of 
the same module work.  Say, I have 3 modules (mod1.py, mod2.py, and 
mod3.py) and in the same session they all import another module 
mymodule.py like this:

*In mod1.py

import mymodule

*In mod2.py

import mymodule

*In mod3.py

import mymodule as MM

Then mymodule is imported only once, but each module has access to it 
through the module name (mod1 and mod2) and the alias MM (mod3).  Is 
that right?

I was concerned about multiple imports and efficiency.

Thanks for any info.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy, numarray, or numeric?

2007-02-18 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "RickMuller" <[EMAIL PROTECTED]> wrote:

> Use numpy; it is the "officially blessed one" that you refer to. It
> has all of the advantages of the other two.
> 
> Numeric was the first library, but it had some drawbacks that led some
> people to develop Numarray, which had some additional features.
> Finally, the numpy project was started to unify the two groups by
> providing some of the new features in a code base consistent with the
> old library as well.

I agree completely, having converted all my code from Numeric to NumPy.

Just my 2 cents.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: alternate language

2006-12-11 Thread Lou Pecora
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Aahz) 
wrote:

> In article <[EMAIL PROTECTED]>,
> Lou Pecora  <[EMAIL PROTECTED]> wrote:
> >In article <[EMAIL PROTECTED]>,
> > Bryan <[EMAIL PROTECTED]> wrote:
> >>
> >> what is a good alternate language to learn? i just want something to expand
> >> my mind and hopefully reduce or delay any chance of alzheimer's. i would
> >> especially like to hear from those of you who learned python _before_ these
> >> languages.
> >> 
> >> haskell, erlang, ocaml, mozart/oz, rebel, etc.
> >
> >I have no experience with any of these.  Of course, now I will give my 
> >opinions.  :-)  Just based on my experience with Python, C, C++, BASIC 
> >(several flavors), Fortran 77 (mostly).
> > 
> >> i don't require any of these features, but extra browny points for any of
> >> the following:
> >> 
> >> interactive interpreter
> >
> >Python has several.
> 
> Um...  I think the original poster is saying that he already knows Python
> and wants to learn another language.  He particularly wants opinions from
> other people who have learned these languages *after* learning Python.

Oh...never mind.  :-)

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: alternate language

2006-12-11 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Bryan <[EMAIL PROTECTED]> wrote:

> what is a good alternate language to learn? i just want something to expand
> my mind and hopefully reduce or delay any chance of alzheimer's. i would
> especially like to hear from those of you who learned python _before_ these
> languages.
> 
> haskell, erlang, ocaml, mozart/oz, rebel, etc.

I have no experience with any of these.  Of course, now I will give my 
opinions.  :-)  Just based on my experience with Python, C, C++, BASIC 
(several flavors), Fortran 77 (mostly).
> 
> i don't require any of these features, but extra browny points for any of
> the following:
> 
> interactive interpreter

Python has several.

> batteries included

Not sure what you mean here.  Certainly the standard Python packages 
would offer you an immediately usable Python from Terminal and some 
other interpreters.  But there are LOTS of add-ons available.  A big 
plus with Open Source.  Keeping them coordinated is a task, though (a 
big minus with Open Source).  Overall, I haven't had to mess too much to 
get lots of usability from Python, especially for Scientific computing.

> can integrate with c

Yes. Several approaches, but none trivial.

> compiles to native code

No.

> can use a gui toolkit such as wx

Yep.  Wx is here for Python.  Also a book on it by Rappin and Dunn 
(Manning , publ. 2006)

> doesn't take 60 hour weeks over years to master

You'll be writing code on day 1. Useful code, too.  Very, very nice 
language to learn and use.  I recommend Python in a Nutshell by Martelli 
(O'Reilly Publ.) to read as you learn.  Lots of online tutorials.  See 
Python.org, SourceForge and google.  I think you can get pretty good at 
Python coding in a month or so.  


Along with Perl and Ruby, Python is really a very popular 
interpreted/scripting language rather than a niche language (which I 
think most of the ones you mentioned are somewhat niche).  That means 
there's a big, helpful community out there to talk to and lots of code 
available.  I do all my new coding in it and then when I need speed in 
some routine I rewrite it in C as a Python extension.  I can develop 
many times faster than I could in C/C++ or Fortran or BASIC (even).  I 
cannot compare, however, to the languages you mentioned.  Sorry.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good script editor for Python on Mac OS 10.3

2006-11-29 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Scott_Davies" <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I have an old Mac with OS X Panther installed.  I also have the Python
> language download file, but I haven't got a text/script editor to use
> for it.  Does anyone have a recommendation for a good Python text
> editor in OS 10.3?
> 
> Thanks,
> 
> Scott D.
> 

Try TextWrangler.  It's free.  I use it's big brother BBEdit and like it.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pylab package dependencies

2006-10-17 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Robert Kern <[EMAIL PROTECTED]> wrote:

> > 
> > I assume you are telling me to install ipython from a tar distribution 
> > using setup etc.  I originally installed it from the SciPy Super Pack 
> > which apparently put in the site packages, but neglected the script in 
> > /usr/local/bin.  Sound right?
> 
> Indeed. The SuperPack is broken and does not contain the ipython script. It 
> also 
> puts the documentation in the wrong place.
> 
> ipython is a pure-Python package and easy to install from source.

Bingo!  Now it is clear why I am having problems.  I will install from 
source as you suggest.  Looks pretty straightforward.

Sorry to hear the SuperPack is broken.  It's a nice idea for us users.  
Other packages seem to be working fine.  Any chance it will be fixed?  

> > On the ipython web site for MacOS X it says to do the following after 
> > the install using python setup.py etc. in the extracted directories,
> > 
> > python?setup.py?install_scripts?--install-dir=/usr/local/bin
> > 
> > Is that what you are suggesting with the pydistutils.cfg ?  
> 
> Yes, it does the same thing, only it will apply to all packages (probably 
> what 
> you want) and you only have to do it once instead of remembering to do it 
> every 
> time.

Robert,  thanks for the insight and the solution.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pylab package dependencies

2006-10-17 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Robert Kern <[EMAIL PROTECTED]> wrote:

> Lou Pecora wrote:
> 
> > The only problem I'm having is getting ipython to run.  Not installed in 
> > /usr/local/bin (although all other IPython files look to be installed in 
> > /Library/Framewaorks/python..blah/site-packages).  I'm still searching 
> > the web sites for answers.
> 
> Create a file ~/.pydistutils.cfg with the following section (unindented):
> 
>[install]
>install-scripts=/usr/local/bin
> 
> Now install ipython again, and the ipython script should be installed to 
> /usr/local/bin/. You may need to be root to do so.
> 
> For more information on that configuration file:
> 
>http://docs.python.org/inst/config-syntax.html

I assume you are telling me to install ipython from a tar distribution 
using setup etc.  I originally installed it from the SciPy Super Pack 
which apparently put in the site packages, but neglected the script in 
/usr/local/bin.  Sound right?

On the ipython web site for MacOS X it says to do the following after 
the install using python setup.py etc. in the extracted directories,

python setup.py install_scripts --install-dir=/usr/local/bin

Is that what you are suggesting with the pydistutils.cfg ?  

Sorry, if I'm dense on this, but I only partially grok the command line 
install. Thanks for any help.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: pylab package dependencies

2006-10-17 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Robert Kern <[EMAIL PROTECTED]> wrote:

> > 
> > Is pylab part of matplotlib? 
> 
> Yes.
> 
> > I always thought it was the other way 
> > around. I have a similar view of numpy as part of scipy. 
> 
> It is not.
> 
> > Maybe I'm 
> > confused on the dependencies.  I find it confusing in the examples 
> > sometimes when the "bigger" package is imported (e.g. scipy) and then a 
> > "subpackage" is also imported.  Like this:
> > 
> > from scipi import *
> > from scipi import numpy
> 
> The latter would definitely be bad form if it worked. numpy is a package all 
> by 
> itself and should be imported by itself.
> 
> > I know I've seen stuff like that, but I don't get it.  The dependencies 
> > are confusing to me.  
> 
> pylab is a module provided with matplotlib that exposes a nice interface for 
> certain purposes. Somewhat confusingly, it is provided in two places, as its 
> own 
> module:
> 
>import pylab
> 
> and as a submodule in the matplotlib package:
> 
>from matplotlib import pylab
> 
> Both do the same thing. You get to ask John Hunter if you want to know the 
> whys 
> and wherefores.

[cut]

Got it.  Thanks, Robert, for the quick tutorial.  It's a lot clearer now.

Now, to just remember it.  

By the way, from what I have seen so far they are beautiful packages.

The only problem I'm having is getting ipython to run.  Not installed in 
/usr/local/bin (although all other IPython files look to be installed in 
/Library/Framewaorks/python...blah/site-packages).  I'm still searching 
the web sites for answers.

But all else seems to run pretty smoothly.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to invoke ipython in Mac OS X?

2006-10-17 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Jerry" <[EMAIL PROTECTED]> wrote:

> Did you install it with the --install-scripts command line option?  If
> you did, then there will be a ipython script located in the
> $INSTALL_SCRIPTS/bin directory.  If you didn't, then I think the
> default location is /usr/lib/python or something like that.

No, I did not use the install-scripts command line option.  It was 
installed from the Package (it's down there in 
/Library/Frameworks/Python...blah, blah/site-packages/IPython).

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to invoke ipython in Mac OS X?

2006-10-17 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:

> Lou Pecora wrote:
> 
> > I installed the SciPy superpackage and have pylab, matplotlib, scipy,
> > and numpy apparently running well.  But I want to use matplotlib/pylab
> > interactively.  The instructions suggest doing this in IPython.  But
> > using ipython on the command line gives me an error.  The system doesn't
> > know the command.  Apparently there is no ipython executable in one of
> > the bin directories.  I thought the superpackage would add that
> > automatically, but I guess not.
> > 
> > Can anyone tell me how to get ipython running on my MacOSX 10.4 system?
> 
> This is just a guess - but did you check your
> 
> /Library/Frameworks/Python.framework/Versions/Current/bin


Just checked it. Nothing there for IPython.

> directory for the ipython-binary? Usually, that will be the prefix of
> anything compiled/installed to framework-builds. So either you add that to
> your path, or create links to e.g. /usr/local/bin

I'm not quite following this last suggestion.  Can you explain more. 
Sorry.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to invoke ipython in Mac OS X?

2006-10-17 Thread Lou Pecora
I installed the SciPy superpackage and have pylab, matplotlib, scipy, 
and numpy apparently running well.  But I want to use matplotlib/pylab 
interactively.  The instructions suggest doing this in IPython.  But 
using ipython on the command line gives me an error.  The system doesn't 
know the command.  Apparently there is no ipython executable in one of 
the bin directories.  I thought the superpackage would add that 
automatically, but I guess not.  

Can anyone tell me how to get ipython running on my MacOSX 10.4 system?

Thanks for any help.

(Yes, I asked on the SciPy email list, but never got an answer.)

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


pylab package dependencies (was: Plotting histograms)

2006-10-17 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Robert Kern <[EMAIL PROTECTED]> wrote:

> I presume what you did was something like this:
> 
>from matplotlib import pylab
>[N,x] = hist(eig, 10)
> 
> What you actually want is this:
> 
>from matplotlib import pylab
>[N,x] = pylab.hist(eig, 10)
> 
> Or, if you're at the interactive prompt (but remember that it is inadvisable 
> to 
> do so in modules):
> 
>from matplotlib.pylab import *
>[N,x] = hist(eig, 10)
> 
> You will probably want to review the section of the tutorial on importing 
> modules if you don't understand the differences.


Is pylab part of matplotlib?  I always thought it was the other way 
around. I have a similar view of numpy as part of scipy.  Maybe I'm 
confused on the dependencies.  I find it confusing in the examples 
sometimes when the "bigger" package is imported (e.g. scipy) and then a 
"subpackage" is also imported.  Like this:

from scipi import *
from scipi import numpy

I know I've seen stuff like that, but I don't get it.  The dependencies 
are confusing to me.  

I did a search of the tutorial on 'import' but didn't find the answer.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bind an instance of a base to a subclass - can this be done?

2006-05-25 Thread Lou Pecora
I came up with this solution for subclassing the file object and making 
some easy I/O functions (much thanks to Maric Michaud for pointing me in 
the right direction).  My goal was to make I/O of variables easy and in 
a form that I could easily visually examine the file (which I often need 
to do).  The code also keeps it very clear as to what is being read in 
or out in a single function call.

The class (inherited from file) in file ezfile.py:

#  File subclass from file for EZ I/O ===

class ezfile(file):
   
   #  Write items to file --
   #  converts items list to string first using repr fcn.
   def printline(_, ls):
  sls=repr(ls)
  _.writelines(sls)
  
   #  Scan line from file & return items 
   #  converts scanned string to list first using eval fcn.
   def scanline(_,):
  sls=_.readline()
  return eval(sls)


An example in a Python session:

>>> from ezfile import *

#  Define some variables
>>> x=2.334
>>> i= 7
>>> str='Some stuff here'

# Open a file and output the variables to it
>>> ff=ezfile('junk','w')
>>> ff.printline([x,i,str])
>>> ff.close()

# Open the same file and read the values back in to other variables
>>> f2=ezfile('junk','r')
>>> y,j,thestr=f2.scanline()
>>> print y,j,thestr
2.334 7 Some stuff here
>>> f2.close()
>>> 

The file content looks like this:

[2.3341, 7, 'Some stuff here']

easy to see what is saved to  the file.

It works!  Thanks, again.  Comments welcome.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bind an instance of a base to a subclass - can this be done?

2006-05-25 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Maric Michaud <[EMAIL PROTECTED]> wrote:

> Le Mercredi 24 Mai 2006 22:04, Diez B. Roggisch a écrit :
> > Nope, not in that way. But you might consider writing a proxy/wrapper
> > for an object. That looks like this (rouch sketch from head):
> >
> > class FileWrapper(object):
> >     def   init  (self, f):
> >        self. f = f
> >
> >     def   getattr  (self, name):
> >        return getattr(self. f, name)
> >
> >     def myreadline(self):
> >        
> Why use a proxy when you can just inherit from the builtin file object ?
> 
> class myFile(file) :
>   def myreadline(self) : print 'yo'
> 
> 
> In [20]: myFile('frwiki-20060511-abstract.xml')
> Out[20]: 
> 
> In [21]: myFile('frwiki-20060511-abstract.xml').myreadline()
> yo
> 
> In [22]:

BINGO!  This is exactly what I want.  I didn't realize that I could open 
using file itself instead of open.  I did find this in another section 
of Python in a Nutshell thanks to your suggestion.  

Thank you.

And thanks to all who answered.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Bind an instance of a base to a subclass - can this be done?

2006-05-25 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:

> Lou Pecora schrieb:
[cut]
> > 
> > Then do something like (I know this isn't right, I'm just trying to 
> > convey the idea of what I would like)
> > 
> > mf=myfile()
> > 
> > mf=open("Afile","r")  
> > Possible in some way?  Thanks in advance for any clues.
> 
> Nope, not in that way. But you might consider writing a proxy/wrapper 
> for an object. That looks like this (rouch sketch from head):
> 
> class FileWrapper(object):
> def __init__(self, f):
>self._f = f
> 
> def __getattr__(self, name):
>return getattr(self._f, name)
> 
> def myreadline(self):
>
> 
> Then you do
> 
> f = FileWrapper(open(name, mode))
> 
> Diez

Interesting.  I have to think about this to understand if it is a 
solution I can use.  But, thank you for a very different angle on this.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Bind an instance of a base to a subclass - can this be done?

2006-05-24 Thread Lou Pecora
I've been scanning Python in a Nutshell, but this seems to be either 
undoable or so subtle that I don't know how to do it.

I want to subclass a base class that is returned from a Standard Library 
function (particularly, subclass file which is returned from open).  I 
would add some extra functionality and keep the base functions, too.  
But I am stuck.

E.g. 

class myfile(file):
   def myreadline():
  #code here to return something read from file

Then do something like (I know this isn't right, I'm just trying to 
convey the idea of what I would like)

mf=myfile()

mf=open("Afile","r")  

s=mf.myreadline() # Use my added function

mf.close()# Use the original file function


Possible in some way?  Thanks in advance for any clues.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plotting package?

2006-04-25 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Andrew Koenig" <[EMAIL PROTECTED]> wrote:

> This may be a foolish question, but what's the most straightforward way to 
> plot a bunch of data in Python?
> 
> That is, I want to write a program that does some number crunching, and then 
> I want to change some parameters and watch how the changes affect the 
> results.  I could produce a file to hand to gnuplot, but that's a bit of a 
> pain; so I'm wondering if there is a widely used package to which I can give 
> my x-y pairs and have it produce a graph for me with axes, scaling, etc.

I second all other recommendations on matplotlib.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Phython and graphing

2006-04-20 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "mostro" <[EMAIL PROTECTED]> wrote:

> Hello,
> 
> Can someone lead me to an easy way to create a graph in Python.
> 
> For example, I have a script running that creates a list of dates,
> times and values. I would like to turn this into a graph.
> 
> I can grep the info into a new file creating two columns (x,y) but the
> issue is the graph.
> 
> P.S. I'm a Python newbie so keep that in mind.
> 
> Thanks in advance...

google  matplotlib  nice package.  I've been told that another package 
called wsMpl.py also puts a nice API on the matplotlib.  You might want 
to check that, too.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class __init__ behaviour

2006-04-20 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Thomas Bartkus" <[EMAIL PROTECTED]> wrote:

> If I insert an __init__ method in my own class definition, it is incumbent
> upon me to call the __init__ of any declared ancester to my new class object
> because my __init__ will override that of any ancester I declare in the
> header.  If I fail to call the ancesters __init__, then it won't happen.
> The ancester object won't be initialized.
> 
>But
> 
> If I *don't* insert my own __init__ in my new class, then any declared
> ancester __init__ will automatically run because I haven't overridden the
> ancesters __init__ method with my own.
> 
> Did I get that straight?
> Thomas Bartkus


Sounds right to me.  That's how I use it.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python on Mac

2006-04-06 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 James Stroud <[EMAIL PROTECTED]> wrote:

> Thomas Nelson wrote:
> > I just purchased a new macbook (os 10.4.6), and I'm trying to install
> > python 2.4 on it.  I downloaded and ran the two installers recommended
> > at http://www.python.org/download/mac/.  Now I have IDLE, which runs
> > 2.4.1, but typing "python" at a terminal still opens 2.3.5, because it
> > points to /usr/bin/python.  Is there a way to run python 2.4 without
> > idle?  If I want to do a unix style script, something like
> > #!/usr/bin/python
> > print "hello world"
> > what can I put on the first line that will cause python 2.4 to
> > interpret my code?
> > 
> > Thanks a lot.
> > THN
> > 
> 
> The python in /usr/bin is a link (to a link). You can do this:
> 
> sudo rm /usr/bin/python
> sudo ln -s \
> /System/Library/Frameworks/Python.framework/Versions/2.4/bin/python \
> /usr/bin/python

YIKES!  Don't do that.  Don't mess with Apple's python.  Not 
recommended.  Check  the MacPython FAQ and Wiki pages.  Python 2.4 was 
installed in /usr/local/bin.  You should put that in your $PATH variable 
Before  /usr/bin.  That will cause the new Python to be launched.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Difference in Python and Ruby interactive shells

2006-04-04 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 "Michele Simionato" <[EMAIL PROTECTED]> wrote:

> You want this recipe from Michael Hudson:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164
> 
>   "automatically upgrade class instances on reload()"


Impressive, but YIKES, there ought to be a simpler way to do this.  I 
think during the development phase editing and reloading would be very 
common and you'd want everything updated.  So why is it done the other 
way, the reference stays the same?  Is that useful?  Maybe time for a 
'switch' to set in Python to choose which behavior you want.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Write a GUI for a python script?

2006-03-03 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Matthias Huening <[EMAIL PROTECTED]> wrote:

> Glurt Wuntal (02.03.2006 15:56):
> > I am a newbie with Python. It's a great language, but I would like to be
> > able to present a simple gui menu for some of my scripts; something better
> > than using 'raw_input' prompts.
> > 
> 
> If you only need some dialogs, input and/or message boxes, you could start 
> with EasyGUI.
> http://www.ferg.org/easygui/
> 
> Matthias


Matthias,

Thanks for pointing that out.  I got EasyGUI and it works right out of 
the box.  Very nice for quick and dirty GUI stuff.  Maybe some good 
examples of using Tkinter, too.  It is only version 0.72 and hasn't been 
updated by the author since 2004.  But it does work and is simple enough 
that novice users like me might be able to maintain it and extend it.  
Many thanks to the author (Stephen Ferg) for producing EasyGUI.

By the way it was written on a Windows machine and worked perfectly (so 
far) on my Mac OS X machine.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI programming, embedding, real time plots, etc.

2005-08-08 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Madhusudan Singh <[EMAIL PROTECTED]> wrote:

> 1. In using matplotlib (my code essentially involved creating a plot and
> show()'ing it inside a loop), the color of the plot changed. Is there a way
> to tell matplotlib to not treat each new invocation as a new plot, but to
> really overwrite the old one ?

You were able to get matplotlib to open a new plot each time (assuming 
you closed the old one, too)?  Can you show a simple example of this?  

Thanks.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OSx 10.4 lacks pythonIDE?

2005-05-17 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Robert Kern <[EMAIL PROTECTED]> wrote:

> I'm told Xcode does a tolerable job with Python.

I just took a look at Xcode and it's not obvious how to run a script.  I 
suspect I need a project?  Then run?  The docs say nothing that I can 
find.

Thanks.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OSx 10.4 lacks pythonIDE?

2005-05-17 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Robert Kern <[EMAIL PROTECTED]> wrote:

> You could learn to use vim or emacs, both of which come with Tiger. They 
> also have somewhat more Aqua-friendly GUI versions lurking around. I'm 
> partial to vim, myself.
> 
> PyOXIDE might be a good choice for you.
> http://homepage.mac.com/gandreas/Menu4.html
> 
> I'm told Xcode does a tolerable job with Python.
> 
> There are other IDEs floating around. Searching the PythonMac-SIG 
> mailing list archives should show you past discussions about them and 
> how well they work on OS X.

TextWrangler or BBEdit (it's bigger brother) can be used, too.  Both are 
nice GUI editors.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [noob] Questions about mathematical signs...

2005-02-07 Thread Lou Pecora
In article <[EMAIL PROTECTED]>,
 Steve Holden <[EMAIL PROTECTED]> wrote:

> > 2. Inputing fractions like (a / b) + (c / d), It's tiring work too.
> >Can it be simplified?

Can't this just be written as   a/b+c/d ?  How much simpler can it get?  
I would think you need at least one symbol per operation (ignoring 
possible algebraic simplifications and transformations for some 
expressions).

-- Lou Pecora  (my views are my own)
-- 
http://mail.python.org/mailman/listinfo/python-list