Re: [Tutor] Complex roots

2004-12-12 Thread Dick Moores
Tim (was: Bill) Peters wrote at 20:45 12/10/2004:
[Dick Moores]
> Aw, that's just amazing.


> I put your function in http://www.rcblue.com/Python/croots.py,
That's fine by me -- but I'd appreciate it if you stopped claiming
there that my name is Bill .
Are you sure? Well, OK. Tim it is.
> Actually, I'm trying to write a Python script that computes all 3
> roots of a cubic equation. Do you happen to have one tucked
> away in your store of wisdom and tricks? (One for real coefficients
> will do).
I don't, no.  You can code one for cubics from Cardano's formula, e.g.,
http://mathworld.wolfram.com/CubicFormula.html
but it's rarely worth the bother -- it's complicated and doesn't
generalize.
I accept this challenge to write a complicated script of little value.
In practice, roots for polynomials beyond quadratics are
usually obtained by numerical approximation methods that don't care
much about the polynomial's degree.
Are these "numerical approximation methods" pythonically possible?
Dick (AKA George) Moores
[EMAIL PROTECTED]
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] OT?: how to google just the 2.4 tutorial?

2004-12-12 Thread Dick Moores
I know how to limit google search results to a single site, but is it 
possible to google just one section of a site?

I'd like to be able to search just the 2.4 tutorial, 
http://www.python.org/doc/2.4/tut/tut.html
Possible? And if so, how to?

Thanks,
Dick Moores
[EMAIL PROTECTED]
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Complex roots

2004-12-12 Thread Alan Gauld
> Are these "numerical approximation methods" pythonically possible?
>

Yes and that's how they are normally found - not necessarily with
Python,
but by applying computer simulations of the equations. Generally you
calculate values in ever decreasing increments until you get enough
accuracy. eg you discover a zero crossingh between 3 and 4, then
between 3.3 and 3.4 then between 3.36 and 3.37 and so on...

Caveat:
You also need to look out for double crossings within a single step
change, so don't make the steps too big. And check the number of
roots you expect versus the number you get as an error detection
scheme.

Alan G.

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difference between for i in range(len(object)) andfor i in object

2004-12-12 Thread Bob Gailer
At 08:27 AM 12/12/2004, kumar s wrote:
Thank you for clearing up some mist here.  In fact I was depressed by that 
e-mail
I appreciate Alan's response and yours. I forgot that this was the Tutor 
list, as I see so many Python e-mails it is easy to get confused. Please 
resume seeing this list and me as resources. I regret my comments that led 
to your depression.

because there are not many tutorials that clearly explains the issues that
one faces while trying to code in python.
So what can we do as a community to provide tutorials that help students 
like you to more easily "get it". Can you give us some ideas as to what is 
missing? Also I 'd be interested in knowing a bit about your academic 
background and field of study. Would you give us a brief CV?

I taught programming for the Boeing Company. I always wondered "what are 
these students doing here? Why don't they just read the book?" That's how I 
learned almost everything I know about programming. So it can be hard for 
me to understand your struggle.

Nuf said for now...
[snip]
Bob Gailer
[EMAIL PROTECTED]
303 442 2625 home
720 938 2625 cell 

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT?: how to google just the 2.4 tutorial?

2004-12-12 Thread Brian van den Broek
Dick Moores said unto the world upon 2004-12-12 11:53:
I know how to limit google search results to a single site, but is it 
possible to google just one section of a site?

I'd like to be able to search just the 2.4 tutorial, 
http://www.python.org/doc/2.4/tut/tut.html
Possible? And if so, how to?

Thanks,
Dick Moores
[EMAIL PROTECTED]
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
Hey Dick and all,
that's odd. I tried searching with
  site:www.python.org/doc/
and
  site:www.python.org/doc
but neither gave hits. :-(
From the "Department of there has to be a better way, but . . . ",
try entering something like this into the google search box:
  site:www.python.org inurl:tut string
That will search www.python.org pages with 'tut' in the url that have 
'string' in the page body. That doesn't restrict it to 2.4, or non-dev docs.

My best attempt:
  site:www.python.org inurl:tut -inurl:dev inurl:current string
still pulls up hits like  
which don't have 'current' in the url. And, adding inurl:node to the 
suggested search yields no results, either. I'm not sure why. :-|

So, none of this gets you there, but it does get you closer.
 shows how to use some of the 
more esoteric google operators.

You might also check out (and maybe improve) 
.

Best,
Brian vdB
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] listing all combinations of elements of a list

2004-12-12 Thread Bill Kranec
Is there a module containing a function for listing the unique k-element 
subsets of an n-item list?  I have written some code (right now I only 
need it for 2 element subsets):

def combination(items)
   list = []
   for i in range(0,len(items)):
  for j in range(0,len(items)):
 if j > i:
list.append((list[i],list[j]))
   return list
My problems with this code being that a) code I write is usually pretty 
inefficient, b) it doesn't extend to subsets of size > 2, and c) it uses 
nested loops, which I have gathered from some previous discussions on 
this list to be less than ideal.

Any thoughts on how to improve / replace this code would be appreciated.
Thanks,
Bill
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: listing all combinations of elements of a list

2004-12-12 Thread Lee Harr
Is there a module containing a function for listing the unique k-element
subsets of an n-item list?  I have written some code (right now I only
need it for 2 element subsets):

Apparently not, but maybe this will help:
http://www.google.com/search?q=python+recipe+list+combinations
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465
_
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT?: how to google just the 2.4 tutorial?

2004-12-12 Thread Dick Moores
Brian van den Broek wrote at 10:43 12/12/2004:
Dick Moores said unto the world upon 2004-12-12 11:53:
I know how to limit google search results to a single site, but is it 
possible to google just one section of a site?
I'd like to be able to search just the 2.4 tutorial, 
http://www.python.org/doc/2.4/tut/tut.html
Possible? And if so, how to?
Thanks,
Dick Moores
[EMAIL PROTECTED]
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor
Hey Dick and all,
that's odd. I tried searching with
  site:www.python.org/doc/
and
  site:www.python.org/doc
but neither gave hits. :-(
From the "Department of there has to be a better way, but . . . ",
try entering something like this into the google search box:
  site:www.python.org inurl:tut string
That will search www.python.org pages with 'tut' in the url that have 
'string' in the page body. That doesn't restrict it to 2.4, or non-dev docs.

My best attempt:
  site:www.python.org inurl:tut -inurl:dev inurl:current string
still pulls up hits like  
which don't have 'current' in the url. And, adding inurl:node to the 
suggested search yields no results, either. I'm not sure why. :-|

So, none of this gets you there, but it does get you closer.
 shows how to use some of the 
more esoteric google operators.

You might also check out (and maybe improve) 
.
Thanks, Brian.
I stumbled across http://docs.python.org as a site, so at least searching 
within Python docs (which include the tutorial) is possible.

For example,
site:http://docs.python.org "complex number"
This finds 23 results, compared to the 334 returned by
site:http://www.python.org "complex number"
To find the results for the tutorial, search the results page for
site:http://docs.python.org "complex number" and search the page on 
"/tut/". These will be for the tutorial. There are just 2 for "complex 
number"

A much simpler way to find things in the tutorial (after all) seems to be 
to use the "Python Documentation" help file that comes with 2.4. I 
searched on
"complex number" tutorial  and got 3 hits, the 2 found with the method of 
the paragraph immediately above, plus one more in the index of the tutorial.

Dick



___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [ANN] RUR: a Python Learning Environment (alpha)

2004-12-12 Thread André Roberge
RUR: a Python Learning Environment is a successor of Karel the Robot,
PyRobot and Guido van Robot. Its purpose is to provide an environment
for beginners, including children, to learn python.
(Note that Guido van Robot still exists and has been upgraded recently.)
Source for the program (python files; requires wxPython 2.4)
can be found on SourceForge.net at
https://sourceforge.net/projects/rur-ple/
The current (first) release has been tested under
Windows and everything (except the "radio box") should work.
For those using a platform other than Windows,
I have been told that a much earlier version had problems
displaying the robot world properly. If you're interested in trying and
encounter problems, I suggest changing the window size,
or clicking in the middle panel (the robot's world).
Do not hesitate to give me some feedback.
To my knowledge, no one (other than myself!) has tested it yet.
The project's home page is located at:
http://rur-ple.sourceforge.net/index.html
It features a number of lessons, with an outline for future lessons. 
It should give you an idea of what this program is about, without having 
to try it.

Note: This is my very first Python program
(other than some very simple ones) and the first program
I share with anyone.  Comments, suggestions, criticisms are most welcome.
André Roberge
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Subject: Re: [Tutor] os.listdir fn

2004-12-12 Thread Nandan


> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Are you sure this does what you want? You compute 'scripts' and 'filenames' 
> and throw them away. I
> think this function will return the base name of all the files *and folders* 
> in ./icon.scripts/opname.

I meant to keep the x.script version, but realised I could append '.script' to 
the basename anytime.

> If you are trying to return the base name of every file or directory whose 
> extension is '.script',
> you can use a list comprehension to filter the list:
>
> def createaproposjlist(opname):
>  filelist=os.listdir('./icon.scripts/'+opname)
>  spltnames=map(os.path.splitext,filelist)
>  return [ name for name, ext in spltnames if ext == '.script' ]

The list comp is much nicer! thanks.

> If you are concerned about directories with names ending in '.script' then 
> add another filter using
> os.path.isdir:

No, I'm keeping a list of icons and associated scripts in the directory, and I 
know there
won't be any subdirs. But I'll keep isdir in mind.

Cheers,
Nandan

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Complex roots

2004-12-12 Thread Dick Moores
Thanks for the sobering advice, and for the two sites I knew nothing 
about. So there's a SciPy!

Dick
Tim Peters wrote at 20:37 12/12/2004:
> Are these "numerical approximation methods" pythonically possible?
Of course, but coding general-purpose root finders-- even if "general"
is limited to just polynomials --requires mathematical and numeric
expertise.  If it interests you, there are book-length treatments of
the subject, and there's really no easy reliable approach.  Good
online sources for numeric algorithms include:
http://www.netlib.org/
Just Googling on
polynomial roots Python
will point you to
http://www.scipy.org/
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Complex roots

2004-12-12 Thread Tim Peters
[Dick Moores]
>>> Actually, I'm trying to write a Python script that computes all 3
>>> roots of a cubic equation. Do you happen to have one tucked
>>> away in your store of wisdom and tricks? (One for real coefficients
>>> will do).

[Tim Peters]
>> I don't, no.  You can code one for cubics from Cardano's formula, e.g.,
>>
>> http://mathworld.wolfram.com/CubicFormula.html
>>
>> but it's rarely worth the bother -- it's complicated and doesn't
>> generalize.

[Dick]
> I accept this challenge to write a complicated script of little value.

Cool!  If it's just for fun, it's fun.

>> In practice, roots for polynomials beyond quadratics are
>> usually obtained by numerical approximation methods that don't care
>> much about the polynomial's degree.

> Are these "numerical approximation methods" pythonically possible?

Of course, but coding general-purpose root finders-- even if "general"
is limited to just polynomials --requires mathematical and numeric
expertise.  If it interests you, there are book-length treatments of
the subject, and there's really no easy reliable approach.  Good
online sources for numeric algorithms include:

http://www.netlib.org/

Just Googling on

polynomial roots Python

will point you to

http://www.scipy.org/
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Complex roots

2004-12-12 Thread Dick Moores
Hmm, sounds like something to sink my teeth into for a while. Thanks for 
just enough of a hint as to how to go about it.

But on second thought, how about another hint. How are imaginary roots 
approximated? For each root, do you try to approximate root.real and 
root.imag simultaneously, or what? Sounds mind-boggling. Maybe I should 
start by approximating real roots, if they exist; and cut my teeth on 
quadratic equations where b**2 - 4*a*c >= 0! Or linear equations.

Thank you.
Dick Moores
Alan Gauld wrote at 09:25 12/12/2004:
> Are these "numerical approximation methods" pythonically possible?
>
Yes and that's how they are normally found - not necessarily with
Python,
but by applying computer simulations of the equations. Generally you
calculate values in ever decreasing increments until you get enough
accuracy. eg you discover a zero crossingh between 3 and 4, then
between 3.3 and 3.4 then between 3.36 and 3.37 and so on...
Caveat:
You also need to look out for double crossings within a single step
change, so don't make the steps too big. And check the number of
roots you expect versus the number you get as an error detection
scheme.
Alan G.

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to launch multiple processes from script?

2004-12-12 Thread Mike in Seattle
I'm working my way through the sockets module. To test my simple
server and clients, I'd like a way to launch the server and multiple
clients from one script or batch file,all running simultaneously. Each
server/client should run as it's own process and have a console
window.  I've briefly played with spawn and forkpty with no success.
Running WinXP right now.

I am hoping that there is something as simple as this psuedo code:

for i in range(1..10):
  run_with_console("client.py " +  arg0[i] +" " +arg1[i])

My question is what is pythonese for run_with_console?

Thanks,
Mike
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difference between for i in range(len(object)) andfor i in object

2004-12-12 Thread kumar s
Thank you for clearing up some mist here.  In fact I
was depressed by that e-mail because there are not
many tutorials that clearly explains the issues that
one faces while trying to code in python.  Also, due
to lack of people who are proficient in python around
our univ. campus in baltimore, i am very much relying
on tutors mailing list. I am poor enough to go to Mark
Lutz's python training course(~ $1000 for 2 days and
3.5K for 5 days at a python bootcamp) and helpless to
the fact that there is no one offering a python course
on the campus. I am very much depended on this list
and I cannot tell you people, how much I respect and
appreciate the help from tutors. I cannot finish my
Ph.D. thesis without tutors help and tutors will
always be praised in my thesis acknowledgements. 

Thank you again for a supportive e-mail Mr.Gauld.

P.S: My intention is not to hurt tutor's opinion and
it is their right to express their opinion freely.

kumar.

--- Alan Gauld <[EMAIL PROTECTED]> wrote:

> > Personally I am getting weary of a lot of requests
> that to me seem
> to come
> > from a lack of understanding of Python..
> 
> To be fair that is what the tutor list is for -
> learning Python.
> 
> > Would you be willing to take a good tutorial so
> you understand
> > basic Python concepts and apply them to your code.
> 
> But as a tutor author I do agree that I am often
> tempted
> (and sometimes succumb) to just point at the
> relevant topic
> in my tutorial. Particularly since the latest
> version tries
> to answer all of the most common questions asked
> here, but
> still they come up...
> 
> > I also despair that you don't seem to benefit from
> some of our
> suggestions.
> 
> And this too can be frustrating but sometimes it is
> the case
> that the "student" simply didn't fully appreciate
> the
> significance of what was offered. I'm feeling
> generous tonight!
> 
> :-)
> 
> Alan G
> Author of the Learn to Program web tutor
> http://www.freenetpages.co.uk/hp/alan.gauld
> 
> 




__ 
Do you Yahoo!? 
Send holiday email and support a worthy cause. Do good. 
http://celebrity.mail.yahoo.com
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] function that returns a fn

2004-12-12 Thread Alan Gauld

> def getjlistrenderer(opname):
> def listrender():
> # use opname, eg ops=getlist(opname)
> # or set local fn variable
> return renderer;
> return listrender;
> #?or f=listrender(); return f;
>
> Is it really as simple as this?

Assuming your indentation is actually OK then yes, it is
as easy as that.

> books too, but thought I'd get some more pointers as well. Web
searching
> so far only shows lambda, which is one-liner, and that won't do.

Lambda is actually a single *expression* which may cross several
lines. But with nested functions available lambda is the wrong way
to go for higher order programming in Python.

Alan g.


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor