Re: [Tutor] threads and webpy

2006-08-17 Thread emilia12
> I just looked at web.py.
> It's not a webserver.  It's a toolkit you use to write
> your own webserver.
> Why are you under the impression that it's a webserver?
> Did you just google for 'web server in Python' and find
> this?

you are right, i mean that it is the core of the webserver

> If you're using some code that you've written (or found)
> to handle web
> requests
> using the 'web.py' module, then show us your code and
> we'll tell you
> how to make it into a class that listens on a single IP
> and how to
> start two listen() methods of the class using threads, or
> maybe even
> handling multiple IPs using a single class instance.
> But just knowing that you are using 'web.py' isn't very
> helpful.
> What actual code are you using to run the webserver?
i am playng around this code :

import socket
import sys
import web
import datetime

urls = (
'/(.*)', 'view'
)

class view:
def GET(self, name):
print datetime.datetime.today()

if __name__ == "__main__":
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
sys.argv.append(ip +':8080') # <-- probably this is not
the right way, but it works
web.run(urls)



> (Or maybe web.py contains a simple webserver in the
> module when it's run
> as main?)
yes - in this case it responds to http request like a server

regards
e.

-

Как да получите 10% отстъпка от цените
за оригинални консумативи и принтери на HP
http://digiteq.com/

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


Re: [Tutor] Actual code that illustrates problem

2006-08-17 Thread Danny Yoo
> #def strongfac(z,w):
[function body cut]

Ok, let's go through this step by step.

 * What is the intent of strongfac?
 * What are the inputs?  What is 'z', and what is 'w'?
 * What are the outputs?  What is the return value of strongfac?

Same questions for fermat().  What are the inputs and outputs, and what's 
the intent?

Get those out and documented, because although I think I can guess at it, 
I'd rather know that we are sharing the same understanding.


There's a bit of code in strongfac() that's nonsensical from a purely 
technical sense.  For example:

> #face = [x,y,0]
[some code cut]
> #face[0] = x
> #face[1] = y
> #face[2] = 0

The three assignments to face[0] through face[2] don't do anything 
effective and clutter the code.



In fermat(), there are magic numbers:

#for j in range(2,3):
 

#for k in range(100):
 ^^^

These seem pretty arbitrary.  Can you explain them?



The strongfac() function you have is a good case for writing smaller 
functions: I can not tell where the function really ends.  I see that you 
have several sub-tests, which I'll categorize as:

 * P-1
 * square = square
 * ...

and there's a few others that I can not categorize yet.  But I bet you 
can.  Have you considered breaking those out as independent helper 
functions?


Most of us don't have experience with number theory.  What people here on 
the list have is experience with writing software.  My experience informs 
me that the functions you're writing are way too large.  They are 
monolithic and imposing enough that very few people will be able to (or 
want to!) understand their reasoning.  They really cry out to be broken 
into smaller subtest functions that can be individually understood.

(And even if your program were running perfectly well, I'd still strongly 
recommend you practice the skill of small, easy-to-understand functions.)



You mentioned later that:

> One of the numbers for which strongfac fails to return factors which it
> correctly calculates is 137

Two questions:

 * How do you know that it is being "correctly calculated?"

 * How do you know that your program is doing something wrong?

That is, state explicitely to us what you expected the program to do. 
What is the expected result, in terms of return values, that your function 
failed to produce?  What part of the program --- which particular subtest 
--- should have returned those values?  Where are you looking at?


Again, you have to assume that we don't know anything about number theory. 
Things that may seem "obvious" to you are not obvious to this audience. 
*grin*
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [whitelist] Re: regular expressions question

2006-08-17 Thread nimrodx
Hi Alan,

I found a pretty complicated way to do it (Alan's way is way more elegant).
In case someone is searching the archive, maybe they will find something 
in it that is useful.
It uses the regular experessions module.

import re

def dehexlify_websites(fle):
   # get binary data
   inpt = open(fle,'rb')
   dat = inpt.read()
   inpt.close()
   #strip out the hex "0"'s
   pattern = r"\x00"
   res = re.sub(pattern, "", dat)
   #-
   #it seemed easier to do it in two passes
   #create the pattern regular expression for the stuff we want to keep
   web = re.compile(
r"(?P[/a-zA-Z0-9\.\-:\_%\?&=]+)"
)
   #grab them all and put them in temp variable
   res = re.findall(web,res)
   tmp = ""
   #oops need some new lines at the end of each one to mark end of
#web address,
   #and need it all as one string
   for i in res:
   tmp = tmp + i+'\n'
   #compile reg expr for everything between :// and the newline
   web2 = re.compile(r":/(?P[^\n]+)")
   #find the websites
   #make them into an object we can pass
   res2 = re.findall(web2,tmp)
   #return 'em
   return res2


Thanks Alan,

Matt


Alan Gauld wrote:
>> if you look carefully at the string below, you see
>> that in amongst the "\x" stuff you have the text I want:
>> z tfile://home/alpha
>
> OK, those characters are obviously string data and it looks
> like its using 16 bit characters, so yes some kind of
> unicode string. In between and at the end ;lies the binary
> data in whatever format it is.
>
 Here is the first section of the file:
 '\x00\x00\x00\x02\xb8,\x08\x9f\x00\x00z\xa8\x00\x00\x01\xf4\x00\x00\x01\xf4\x00\x00\x00t\x00f\x00i\x00l\x00e\x00:\x00/\x00h\x00o\x00m\x00e\x00/\x00a\x00l'
  

>
>
>> In a hex editor it turns out to be readable and sensible url's with 
>> spaces between each digit, and a bit of crud at the end of url's, 
>> just as above.
>
> Here's a fairly drastic approach:
>
 s = 
 '\x00\x00\x00\x02\xb8,\x08\x9f\x00\x00z\xa8\x00\x00\x01\xf4\x00\x00\x01 

> \xf4\x00\x00\x00t\x00f\x00i\x00l\x00e\x00:\x00/\x00h\x00o\x00m\x00e\x00/\x00a\x
>  
>
> 00l'
 ''.join([c for c in s if c.isalnum() or c in '/: '])
> 'ztfile:/home/al'

>
> But it gets close...
>
> Alan g.
>

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


Re: [Tutor] (no subject)

2006-08-17 Thread Danny Yoo

> hello is there a way if a condition is not met to restart the whole 
> program? for example if and if statement returns true then re start the 
> whole program?

Question before we go on: why are you trying to do this?

It's possible to do this, but it sounds so unusual that I want to know 
more about the problem.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] threads and webpy

2006-08-17 Thread anil maran
did u try os.spawnv()to spawn other unix commands[EMAIL PROTECTED] wrote: > Hi!Hi !> I don't know what web.py is.> Is it something you wrote?no, this is a simple webserver, (http://webpy.org/)> You'll have to write multi-threaded code if you want it> to run multiple> threads :)> (Unless, of course, Web.py supports threads?)i will ask the authors about this ...> What's your experience with Python?> Do you need help with threads in general? threads in> Python?yes, but python related part of threads>  >Maybe i can do this with 'threads' but how ? is there> some>  >example ??> There are plenty of examples of threaded code that you> could find by> googling around,> or do you mean 'is there some
 example [of multi-threading> the web.py> program]??'> If the latter case, I guess you could find that by> googling as well, if> it exists.yes - i will ask the webpy authorsbut i expected to fond out a way to start two (or more)scripts (web.py) in different threads from one puthon'sscrypt. OR two pythons interpretators to execute the abovescrypt ?cheerse.-Êîëèòå. Ñàìî â êèíàòà îò 4 àâãóñò.___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor 
		Do you Yahoo!? Next-gen email? Have it all with the  all-new Yahoo! Mail Beta.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] threads and webpy

2006-08-17 Thread anil maran
hi likeyour post about how to make it listen on one ip and then on two ips isnt this general python, can you please explain how to go about this, this would be very usefulthanks then show us your code and we'll tell youhow to make it into a class that listens on a single IP and how tostart two listen() methods of the class using threads, or maybe evenhandling multiple IPs using a single class instance.But just knowing that you are using 'web.py' isn't very helpful.What actual code are you using to run the webserver?(Or maybe web.py contains a simple webserver in the module when it's run as main?)HTH,-LukeLuke Paireepinart <[EMAIL PROTECTED]> wrote: > yes - i will ask the webpy authors>> but i expected to fond out a way to start two (or more)> scripts (web.py) in different threads from one puthon's> scrypt. OR two pythons interpretators to execute the above> scrypt ?>   Python is a programming language. It's not a question about whether it's possible;rather, it's who will do it.  If all you
 really want to do is start 2 web.py scriptsfrom one python script you'd do something like this:#  (non-working code)import subprocesssubprocess.Popen('python web.py')subprocess.Popen('python web.py')#-This may or may not work.  You may only be able to subprocess actual executable files.This is probably not what you want to do, though.You'll probably have to learn how to program in Python to do this. ... ... ... ... ... ...I just looked at web.py.It's not a webserver.  It's a toolkit you use to write your own webserver.Why are you under the impression that it's a webserver?Did you just google for 'web server in Python' and find this?If you're using some code that you've written (or found) to handle web requestsusing the 'web.py' module, then show us your code and we'll tell youhow to make it into a class that listens on a single IP and how tostart two listen() methods of the
 class using threads, or maybe evenhandling multiple IPs using a single class instance.But just knowing that you are using 'web.py' isn't very helpful.What actual code are you using to run the webserver?(Or maybe web.py contains a simple webserver in the module when it's run as main?)HTH,-Luke> cheers> e.>>> ->> Êîëèòå. Ñàìî â êèíàòà îò 4 àâãóñò.>> ___> Tutor maillist  -  Tutor@python.org> http://mail.python.org/mailman/listinfo/tutor>   ___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor 
	
	
		Do you Yahoo!? Next-gen email? Have it all with the  all-new Yahoo! Mail Beta.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] about threads

2006-08-17 Thread anil maran
you can configure lighttpd virtual hosts to spawn new webpy instances for each of your ip addressEmilia can you explain your problem a little more I have spent quite some time using and asking questions abt the problems ur posting...[EMAIL PROTECTED] wrote: Hi all,my question is probably about the threads... I have two IPsand i want to run web.py server for each IP in the sametime from one script file. I can run them in two commandboxes (and this works) but i want to do this from one ;-)Maybe i can do this with 'threads' but how ? is there someexample ??regardse. 
		Do you Yahoo!? Next-gen email? Have it all with the  all-new Yahoo! Mail Beta.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] about threads

2006-08-17 Thread anil maran
You'll have to write multi-threaded code if you want it to run multiple threads :)(Unless, of course, Web.py supports threads?)Luke, what is the easiest way to run multithreaded programs from webpyis there a page that has common gotchas and pitfalls for doing the same.Luke Paireepinart <[EMAIL PROTECTED]> wrote: [EMAIL PROTECTED] wrote:> Hi all,>   Hi!> my question is probably about the threads... I have two IPs> and i want to run web.py server for each IP in the same> time from one script file. I can run them in two command> boxes (and this works) but i want to do this from one ;-)>>   if you run two instances of the python interpreter (like you're doing when you start
 two command windows,)they're executing in different threads, it's just that the threads are OS level instead of application level.Windows automatically switches between the two instances of the interpreter and gives them both time to do something.This is why you can run an E-mail application at the same time as your web browser.I suspect that OS-level threading in this way would be more efficient in regard to speed, butit'd use more RAM because two interpreter instances would be loaded into memory at the same time.I don't know what web.py is.Is it something you wrote?You'll have to write multi-threaded code if you want it to run multiple threads :)(Unless, of course, Web.py supports threads?)What's your experience with Python?Do you need help with threads in general? threads in Python? >Maybe i can do this with 'threads' but how ? is there some >example ??There are plenty of examples of
 threaded code that you could find by googling around,or do you mean 'is there some example [of multi-threading the web.py program]??'If the latter case, I guess you could find that by googling as well, if it exists.> regards> e.>   Cheers,-Luke___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor 
		Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1¢/min.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Low level socket and threading code in python in HUGE websites -

2006-08-17 Thread anil maran
What kind of low-level socket and threading code is necessary for a db   intensive site such as yahoo. How do we use it from python? does   anyone  have experience using it http://redditblog.blogspot.com/2005/12/on-lisp.html  >From moving to python by the founders of reddit  Because of the low-level socket and threading code we had to write, 
 reddit would not run on my Mac, and I was always tethered to our  FreeBSD development server. Not being able to program offline is a  pain.  I would imagine that they aren't just using a database.  most of the "low level socket stuff" I've seen is about setting    timeouts and doing Async IO.   
		Do you Yahoo!? 
Get on board. You're invited to try the new Yahoo! Mail Beta.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] server push

2006-08-17 Thread anil maran
Hi guys  i was wondering if someone has successfuly used server push for apps  such as meebo etc using webpy  if so can you share some guidelines on using them I have a continuously running python webserver and a website, if there is a new mail or message, how do i ping and let the website or the user know without polling, using twisted web2thanks a lot  New server software is often required to make applications built using  Comet scale, but the patterns for event-driven IO on the server side  are becoming better distributed. Even Apache will provide a Comet-ready worker module in the upcoming 2.2 release. Until then, tools like Twisted, POE, Nevow, mod_pubsub, and other higher-level event-driven IO abstractions are making Comet available to developers on the bleeding edge. Modern OSes almost all now support some sort of kernel-level event-driven IO system as well. I've even heard that Java's NIO packages will start to take
 advantage of them in a forthcoming release. These tools are quietly making the event-driven future a reality.   
	
		Do you Yahoo!? Everyone is raving about the  all-new Yahoo! Mail Beta.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] web application and database caching technique

2006-08-17 Thread anil maran
i m trying to build a webapplication, i need to cache db records as it has become very slow the sql queries and retrivalcan you guys helpe me out in designing cache structures/ hash tables for these cases 1. Scenario One:     * Huge number of reads     * Few writes     * One row accessed from db per request     * All data written to db is used.     * Medium number of records.  Since the large number of read need to be fast I chose this design:  A hashtable caches records. They are cleared based on expiration time  and limit on maximum number of cached records. When a record is updated  in the db, it is deleted from the cache and recached next time it is  queried. This part could be handled by implementation you linked to.  A persistent background thread periodically flushes the changed/new  values in the cache to the
 database. Additional calculations could be  added here to chose the optimal cache entrees to delete or precache.  2. Scenario Two:     * Few reads     * Huge number of writes     * Many rows accessed from db per request     * Most data written to db is discarded.     * Huge number of small records.  This is the strangest so far. Because of the huge number of records,  most of which will just be discarded anyway, I try to keep away from  the database as much as possible. When it's time to flush them to the  db I aggregate the records into groups, cpickle, and lzo them. I am  still playing with this but I notice a good performance improvement  already.  3. Scenario Three:     * Huge number of writes     * Huge number of reads     * One row accessed from db per request     * Small
 number of records.  This is the same as the first except I have space to cache everything.  This means I can get rid of the time() check for each cache check.  
		Stay in the know. Pulse on the new Yahoo.com.  Check it out. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2006-08-17 Thread Kent Johnson
Amadeo Bellotti wrote:
> hello is there a way if a condition is not met to restart the whole 
> program? for example if and if statement returns true then re start 
> the whole program?

You can probably achieve what you want just by structuring the program 
correctly. My guess you need to use nested loops, something like this:

while True:
  initialize_everything()
  while True:
if something_is_wrong():
  break
do_some_work()

This will do_some_work() until something_is_wrong(), then it will 
initialize_everything() and try again.

If the test for something_is_wrong() is buried deep in the code you can 
break the loop by raising an exception which you catch in the top-level 
loop.

Kent

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


[Tutor] Communicating with Win2000 runas.exe

2006-08-17 Thread Barnaby Scott
I have a problem which I was hoping that Python could solve for me, but
I have become stuck for days now after only 2 lines of code.

My son has a Microsoft game on a shared family computer, which Microsoft
in its infinite wisdom requires you to run as 'administrator'. Call me
old-fashioned but I don't want to promote an 8 year-old to administrator
just so he can run his game!

Enter 'runas.exe'...

However, because we are on Windows 2000, runas does not allow you to
save a password - it has to be entered every time: not much further forward.

So I'm thinking along these lines:

import subprocess
sp = subprocess.Popen(r'C:\WINNT\SYSTEM32\runas.exe /user:administrator
C:\Program Files\Microsoft Games\Age of Mythology\aom.exe')
#some sort of code to send the password here...
#help!

Sure enough, this brings up a prompt asking for the administrator's
password, but I can't get anything to work in terms of getting the 
script to provide the password.

Am I barking up the wrong tree here? Any clues would be gratefully
received. (Even if I do get this to work, my next trick is to hide the
password from any prying eyes looking at the script...)

Thanks

Barnaby Scott


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


Re: [Tutor] Communicating with Win2000 runas.exe

2006-08-17 Thread Tim Golden
[Barnaby Scott]

| So I'm thinking along these lines:
| 
| import subprocess
| sp = subprocess.Popen(r'C:\WINNT\SYSTEM32\runas.exe 
| /user:administrator
| C:\Program Files\Microsoft Games\Age of Mythology\aom.exe')
| #some sort of code to send the password here...
| #help!

I *think* -- and I'm happy to be wrong -- that there's
no way you're going to get that password in there. One
place to start looking might be:

pywinauto - http://pywinauto.pbwiki.com/

which lets you automate Windows in general; don't know
how much use it'll be here. 

Alternatively, look into the pywin32 package, and in 
particular at the win32security functions which let you 
impersonate another user. They're not trivial to use, 
but their use has been explained a few times over the 
years I think. Mostly by Roger Upole who wrote most if 
not all of the Python bindings.

Here's a post which looks useful; you'll have to hunt
around for others:

http://groups.google.com/group/comp.lang.python/msg/6bbefb9d4d45d253

I suggest you ask this question again on the main
python / python-win32 lists; it's a bit too platform-specific
for the tutor list, I would say.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: [Tutor] (no subject) (fwd)

2006-08-17 Thread Danny Yoo


-- Forwarded message --
Date: Thu, 17 Aug 2006 09:44:40 -0400
From: Amadeo Bellotti <[EMAIL PROTECTED]>
To: Danny Yoo <[EMAIL PROTECTED]>
Subject: Re: [Tutor] (no subject)

Mr. Yoo im working on a program to write a sudoku puzzle and if something is
wrong with the last row i need to re make the whole puzzle over again.

On 8/17/06, Danny Yoo <[EMAIL PROTECTED]> wrote:
>
>
>> hello is there a way if a condition is not met to restart the whole
>> program? for example if and if statement returns true then re start the
>> whole program?
>
> Question before we go on: why are you trying to do this?
>
> It's possible to do this, but it sounds so unusual that I want to know
> more about the problem.
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2006-08-17 Thread Danny Yoo
> Mr. Yoo im working on a program to write a sudoku puzzle and if 
> something is wrong with the last row i need to re make the whole puzzle 
> over again.

Hi Amadeo,

In the future, please use the "Reply to All" feature of your email client, 
so that we can keep the conversation on the mailing list.

Here's a separate question that's related to the first: can you write a 
function that asks the user to enter a word, and continues prompting until 
the user enters a non-empty word?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2006-08-17 Thread Amadeo Bellotti
Yes I can Mr. Yoo, but i dont really want to make my whole program a loop.On 8/17/06, Danny Yoo <[EMAIL PROTECTED]
> wrote:> Mr. Yoo im working on a program to write a sudoku puzzle and if
> something is wrong with the last row i need to re make the whole puzzle> over again.Hi Amadeo,In the future, please use the "Reply to All" feature of your email client,so that we can keep the conversation on the mailing list.
Here's a separate question that's related to the first: can you write afunction that asks the user to enter a word, and continues prompting untilthe user enters a non-empty word?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2006-08-17 Thread Danny Yoo


>> > Mr. Yoo im working on a program to write a sudoku puzzle and if
>> > something is wrong with the last row i need to re make the whole puzzle
>> > over again.

>> Here's a separate question that's related to the first: can you write a
>> function that asks the user to enter a word, and continues prompting until
>> the user enters a non-empty word?

Hi Amadeo,


> Yes I can Mr. Yoo, but i dont really want to make my whole program a 
> loop.

Ok.  Why not?  I'm curious: is there a particular constraint you're trying 
to work under, or is it something else?

Also, I'm not sure what you mean by "whole program".


In any case, here's a way to do it without an explicit 'for' or 'while' 
loop:


def ask_for_input():
 msg = raw_input("enter a word:")
 if msg:
 return msg
 else:
 return ask_for_input()


This would not be the idiomatic way to do this in Python only because of a 
technical limitation in the main Python implementation (it doesn't support 
"tail call optimization").

Still, would this be more acceptable to you, or do you also consider this 
a "loop"?

(Personally, I do. *grin*)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] All of Kermit's E-Mails

2006-08-17 Thread Kermit Rose
 
 
From: Luke Paireepinart 
Date: 08/17/06 02:29:01 
To: Kermit Rose 
Cc: tutor@python.org 
Subject: Re: [Tutor] All of Kermit's E-Mails [was: Global Variables] 
 
 
>>>
 
I really dislike the way you reply. 
Follow the standard format! Leave all the greater-than signs before the 
previous person's reply 
so that it will be structured correctly and easy to read. All of this 
star business is bad. 
 
*
 
Suggest an alternative,
because my email program does not insert the > sign like the standard email
program does.
 
I also prefer the standard format, and the first few times I replied in
email I
typed in all the > in front of each line.
 
After a while I decided that I should find some alternative equivalent that
took less time.
 
>>>
 
Okay. 
>From this it appears that you have no academic training in programming. 
The term 'side-effect' means that something outside the scope of the 
called function is modified by the called function. 
 
 
Here is a very basic example. 
 
#--- test.py 
a = ['a','b','c'] 
def modify_list(alist): 
del(alist[0]) 
 
modify_list(a) 
modify_list(a) 
print a 
#--- 
 
#--- output of test.py 
['c'] 
#--- 
 

 
>From your example:
 
You haven't declared any variable global.
does 
a = [a',b'c']  
implicitly  declare the variable "a" to be global because it is not inside a
function definition?
 
I did not know Python syntax  would permit statements to not be inside some
function definition.
 
I see that modify_list deletes the zero'th element.
 
The structure of my factor functions are such that this type of mistake
could not happen.
 
If I knew how, I would follow up Alan's suggestion of making the module into
a class.
 
>>>
 
Now remember that in Python, when you pass a variable to a function, 
only the reference is passed to the function. 
Imagine that variables are themselves references (which they are.) 
 
a = ['a','b','c'] 
 
creates the following picture: 
 
a --> ['a','b','c'] 
 
modify_list(a) 
 
doesn't do 
 
modify_list(['a','b','c']) 
 
it does 
 
modify_list(ptr) where ptr --> ['a','b','c'] <- a 
 
they both refer to the same object ( a python list containing three
characters.) 
 
now when in the body of modify_list we say del(alist[0]), what takes place
is 
the index operator, [0], says 'what object is the variable 'alist' pointing
to? 
and python says 'alist > ['a','b','c'] < a' 
so when we delete the element out of alist we're also deleting the element 
out of the calling function's list. 
This is probably NOT desired behavior. 
As such it's an unwanted side-effect. 
 
***
 
This confuses me.
 
Isn't the calling functions list  [a',b',c'} ?
 
Therefore,  wouldn't the resultt of modify_list(a) 
be 
[b',c']?
 
That's what I would expect it to be and what I would want it to do.
 
>>>
 
 
A function printing to the screen is also considered a side-effect. 
Anything a function does that affects anything outside of its own scope 
is considered a side-effect. 
 
*
 
Ok.  Why is this  bad.  If I'm using global  variables, this would be
exactly what I would want.
 
But I don't insist on using global variables.
 
The idea of making a factor class appeals to me.  I haven't yet learned how.
 
.>>>
 
 
To refresh your memory, here's the next part of the e-mail I'm going to
address: 
 
>The names have very little to do with it, the danger of global 
>variable 
>use is the reliance on side-effects and the tight coupling that you 
>introduce between the calling module and the called module. 
>Changes to the state of the calling module in an unpredictable 
>manner lead to subtle bugs which are extremely hard to see and fix. 
>* 
>What do you mean by tight coupling? 
>The only change I can see that would lead to a bug would be if I changed
the 
>name of the global variable in 
>the calling routine and not in the function it called. 
>I would know not to do that. 
 
 
'tight coupling' is an English phrase meaning roughly 
(for our purposes) 'close interaction' or 'dependence on each other.' 
 
you say, I quote: 
'The only change ... that would lead to a bug would be if I changed the 
name of the global variable in the calling routine.' 
I think you're misunderstanding Alan. 
consider this following example 
(it was hard to come up with something this convoluted) 
 
#--- start code 
def b(): 
global has_been_greeted 
has_been_greeted = False 
print "function B is doing lots of stuff" 
return "whatever we did in function B that's so important" 
 
def greet(): 
global has_been_greeted 
if has_been_greeted: 
print 'we already greeted you.' 
else: 
print 'hello!' 
has_been_greeted = True 
 
def c(): 
print "function C is doing lots of stuff." 
a = b() 
print "function C is using value a here." 
 
b() 
greet() 
greet() 
c() 
greet() 
 
# --- end code. 
 
Now we know we're going to call b() every time on startup, 
so we set has_been_greeted to false inside of it. 
Then we call greet, once b() is done calcu

Re: [Tutor] Actual code that illustrates problem

2006-08-17 Thread Kermit Rose
>>>
 
From: Danny Yoo 
Date: 08/17/06 04:02:35 
To: Kermit Rose 
Cc: Tutor 
Subject: Re: [Tutor] Actual code that illustrates problem 
 
> # def strongfac(z,w): 
[function body cut] 
 
Ok, let's go through this step by step. 
 
* What is the intent of strongfac? 
 
***
 
To try to find factors of z, using w.
 
>>>
 
* What are the inputs? What is 'z', and what is 'w'? 
 
**
 
z is the number to be factores.
 
w is a "witness", a number that may help find the factors of z.
 
>>>
 
* What are the outputs? What is the return value of strongfac? 
 

 
The output is the return value of strongfac.
 
fac = [ x, y, difficulty of factoring z using w]
 
or  
fac = [0,0,0] if strongfac could not factor z using w.
 
 
 
>>>
 
Same questions for fermat(). What are the inputs and outputs, and what's 
the intent? 
 
The input z is the number to be factored.
 
The other inputs are constants which may help in finding factors of z.
 
 
>>>
 
Get those out and documented, because although I think I can guess at it, 
I'd rather know that we are sharing the same understanding. 
 

 

 
How?
 
 
>>> 
 
There's a bit of code in strongfac() that's nonsensical from a purely 
technical sense. For example: 
 
> # face = [x,y,0] 
[some code cut] 
> # face[0] = x 
> # face[1] = y 
> # face[2] = 0 
 
The three assignments to face[0] through face[2] don't do anything 
effective and clutter the code. 
 
 ***
 
In fact, I knew that.  I inserted it in an attempt to overide the apparent
bug that I saw.
 
Sometimes it worked.
 
>>>
 
In fermat(), there are magic numbers: 
 
# for j in range(2,3): 
 
 
# for k in range(100): 
^^^ 
 
These seem pretty arbitrary. Can you explain them? 
 
*
 
Yes.  These are limits of ranges.  I had not yet evolved the module to
replace the range limits with parameters.
 
>>> 
 
The strongfac() function you have is a good case for writing smaller 
functions: I can not tell where the function really ends. I see that you 
have several sub-tests, which I'll categorize as: 
 
* P-1 
* square = square 
* ... 
 
and there's a few others that I can not categorize yet. But I bet you 
can. Have you considered breaking those out as independent helper 
functions? 
 
 
*
 
I have considered it. 
 
>>>
 
Most of us don't have experience with number theory. What people here on 
the list have is experience with writing software. My experience informs 
me that the functions you're writing are way too large. They are 
monolithic and imposing enough that very few people will be able to (or 
want to!) understand their reasoning. They really cry out to be broken 
into smaller subtest functions that can be individually understood. 
 

 
Luke has promised to work with me to write my module as a class.
 
Perhaps this will automatically shorten the individual functions.
 
I don't expect that you would need to know much number theory to understand
what my program is doing, but I'll be glad to answer any question you may
have of it.
 
 
>>>  
 
You mentioned later that: 
 
> One of the numbers for which strongfac fails to return factors which it 
> correctly calculates is 137 
 
Two questions: 
 
* How do you know that it is being "correctly calculated?" 
 

 
Part of the process of finding  any factor is to divide it into z to get
remainder equal to zero.
 
Also when I noticed the problem, I printed it out in strong fac, and also in
fermat 
and then saw the strange behavior of having one value before return 
and another value after return.
 
>>>
 
* How do you know that your program is doing something wrong? 
 
That is, state explicitely to us what you expected the program to do. 
What is the expected result, in terms of return values, that your function 
failed to produce? What part of the program --- which particular subtest 
--- should have returned those values? Where are you looking at? 
 
 

I first noticed it when I had
 
Strong fac calculate the factors if possible.  If it found factors,
 
it printed out that it had found factors using w, and it printed the value
of w.
 
After I noticed that strongfac printed out that it had found factors, but
fermat
did not pick up those factors, I looked more closely.
 
After I had documented to myself that the return value had changed by the
time it got back
to fermat,  I emailed the Tutor list.
 
>>> 
 
Again, you have to assume that we don't know anything about number theory. 
Things that may seem "obvious" to you are not obvious to this audience. 
*grin* 
 
 

 
So noted.   I had not intended to ask any number theory questions here.
 
Kermit   <  [EMAIL PROTECTED]   >
 
 
 
 
 

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


Re: [Tutor] All of Kermit's E-Mails

2006-08-17 Thread Danny Yoo
> Suggest an alternative way of transmitting code.

Hi Kermit,

Try sending the code as a file attachment.  It's large enough that we want 
to make sure it goes through without being messed up, but small enough 
that it can still be posted to the list.

Alternatively, post the code on the web somewhere and send the list a link 
to the URL.  This is preferable for large blocks of code, and your 
factoring program is large enough that this would also be a good way to 
share the code with the mailing list.


Just as a side note: you may want to investigate a good email client such 
as Thunderbird if you have spare time.

 http://www.mozilla.com/thunderbird/

Much of the frustration I've been seeing on this thread deals with 
IncrediMail's feature set; what it is providing you isn't so well suited 
for the kind of technical communication that's on this list.


> This is obviously a case for ... .dun-dun-dun! object-oriented 
> programming. When you have a collection of functions that all operate 
> together to create something, you make a Class to contain them.

I'm going to have to interject and disagree with Luke here; for Kermit's 
application, classes are not necessary.  Kermit's still trying to learn 
basic structured programming with functions; I'm not convinced that 
leaning Kermit toward Object Oriented Programming is going to help matters 
much.


Good luck to you!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Which Book

2006-08-17 Thread Nagendra Singh
Hi All,

I have very little programming experience, I have decided to learn
Python..there are tons of material and refernces on the web-pages, can
you guys please suggest what is the best way to start or which ONE
book which I should follow to start.

thanks..

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


Re: [Tutor] Which Book

2006-08-17 Thread jim stockford

i think it's a mistake to concentrate on one book.
Cull responses and pick three books to start with.
The benefit is that where one book presents a
poor explanation, another will do a good job (and
one book will omit certain things that another
presents).
Also, you'll probably find yourself more often
refreshed by turning from one book to another as
you proceed.

On Aug 17, 2006, at 9:14 AM, Nagendra Singh wrote:

> Hi All,
>
> I have very little programming experience, I have decided to learn
> Python..there are tons of material and refernces on the web-pages, can
> you guys please suggest what is the best way to start or which ONE
> book which I should follow to start.
>
> thanks..
>
> Nagendra
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

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


Re: [Tutor] Actual code that illustrates problem

2006-08-17 Thread Danny Yoo


> To try to find factors of z, using w.
>

>
> * What are the inputs? What is 'z', and what is 'w'?
>
> **
>
> z is the number to be factores.
>
> w is a "witness", a number that may help find the factors of z.

[My apologies in advance; this message is a bit long.]



Hi Kermit,

Ok, good.  You should add this as a comment to the function's header, so 
that other people can see this.  Here is an example:

def strongfac(z, w):
 """z is the number to be factored.
w is a witness that may help find the factors of z.
 """
 ## rest of function body.

At the very beginning of the function body, we're allowed to make a string 
that acts as function documentation.  Python programmers expect this kind 
of "documentation string" at the head of a function, so that they're 
prepared for what comes next.



> * What are the outputs? What is the return value of strongfac?
>
> The output is the return value of strongfac.
> fac = [ x, y, difficulty of factoring z using w]
> or
> fac = [0,0,0] if strongfac could not factor z using w.

Great!  Ok, I'm assuming that 'x' and 'y' are two arbitrary factors of 
'z'.  Are there other properties about x and y that you want to state, 
such as: "x is always prime", or do we make no guarantees about this?



At this point, I'm distilling what you've said into a documentation 
string:

def strongfac(z, w):
 """strongfac: number number -> [x, y, difficulty]

 Factors z into two pieces, returning those two pieces as well as the
 difficulty in factoring z.  w is a witness that may help find the
 factors of z.

 If no factors can be found, returns [0, 0, 0].
 """
 ## rest of function body.


Does this make sense so far?  The point is to make it easy for humans to 
understand your program.




>> # face = [x,y,0]
> [some code cut]
>> # face[0] = x
>> # face[1] = y
>> # face[2] = 0
>
>> The three assignments to face[0] through face[2] don't do anything 
>> effective and clutter the code.
>
> In fact, I knew that.  I inserted it in an attempt to overide the 
> apparent bug that I saw.
>
> Sometimes it worked.

This is a bad sign.  It should not have worked.  *grin*

Next time you hit something mysterious like this, mention it to the list. 
It'll be a good puzzle for the others here to take a look at.  Your code 
should be as rational as possible.  Don't just add code in hoping that 
it'll fix some problem: try to understand why it's not working first. 
Look for root causes.




>> In fermat(), there are magic numbers:
> [cut]
>> These seem pretty arbitrary. Can you explain them?

> Yes.  These are limits of ranges.  I had not yet evolved the module to 
> replace the range limits with parameters.



About strongfac():

> Have you considered breaking those out as independent helper functions?
>
> I have considered it.

Consider it more strongly.  *grin*



Here, I'll help you get started.  strongfac() starts off looking something 
like this:

#
def strongfac(z,w):
 x = gcd(z,w-1)
 if x > 1:
 if x < z:
 y = z/x
 return [x,y,0]
 w2 = (w * w)%z
 s = ksqrt(w2)
 if w2 == s * s:
 if s != w:
 x = gcd(z,kabs(w2 - s))
 if x > 1:
 if x < z:
 return [x,y,0]
 ## other tests


(I'm trimming out the print statements just to keep this small.)


Those two tests, the P-1 and square=square tests, can be broken out into 
two separate functions.  Let's see what this might look like:


def check_p_minus_1(z, w):
 """Checks to see if z can be factored by the P-1 Method.
 If so, returns [x, y, 0]; otherwise, returns [0, 0, 0].
 """
 x = gcd(z,w-1)
 if x > 1:
 if x < z:
 y = z/x
 return [x,y,0]
 return [0, 0, 0]


This "refactoring" allows us to look at check_p_minus_1's action in 
isolation, and also makes it easier to ask questions like: what happens if 
x > z?  Is it really possible that the return value from gcd() is bigger 
than the initial inputs to gcd()?  (As far as I understand gcd(), NO!)

So this refactoring is useful just as a matter of letting someone just 
look at a small bit of code and understand it completely.  As far as I can 
understand, check_p_minus_1() should work even if it's simplified to:

##
def check_p_minus_1(z, w):
 x = gcd(z, w-1)
 if x != 1:
 return [x, z/x, 0]
 return [0, 0, 0]
##




Anyway, once we break out the P-1 check out into a separate function, we 
can rewrite strongfac() to use check_p_minus_1():


def strongfac(z, w):
 face = check_p_minus_1(z, w)
 if face != [0, 0, 0]:
 return face
 

Re: [Tutor] (no subject)

2006-08-17 Thread Kent Johnson
Amadeo Bellotti wrote:
> Mr. Johnson i was hoping i didnt have to make my whole program into a 
> loop because its about 900 lines of code and tabbing that would take a 
> long time
If your whole program is 900 lines without a subroutine then you have 
more problems than just tabbing...really, a program this big should have 
many functions to divide up the work. Looking for a workaround for poor 
program structure is not a good solution in the long run; fixing the 
program structure so it is workable is a better idea.

As a practical matter, many editors allow you to select and indent a 
block, including TextPad and Eclipse, the two editors I usually use.

Kent

PS please reply to the list, not to me personally.
>
>
>
> On 8/17/06, *Kent Johnson* <[EMAIL PROTECTED] > 
> wrote:
>
> Amadeo Bellotti wrote:
> > hello is there a way if a condition is not met to restart the whole
> > program? for example if and if statement returns true then re start
> > the whole program?
>
> You can probably achieve what you want just by structuring the
> program
> correctly. My guess you need to use nested loops, something like this:
>
> while True:
>   initialize_everything()
>   while True:
> if something_is_wrong():
>   break
> do_some_work()
>
> This will do_some_work() until something_is_wrong(), then it will
> initialize_everything() and try again.
>
> If the test for something_is_wrong() is buried deep in the code
> you can
> break the loop by raising an exception which you catch in the
> top-level
> loop.
>
> Kent
>
> ___
> Tutor maillist  -  Tutor@python.org 
> http://mail.python.org/mailman/listinfo/tutor
> 
>
>


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


Re: [Tutor] (no subject)

2006-08-17 Thread Amadeo Bellotti
thank you Mr. Johnson this is my first program so its a little sloppy.
I'm using gedit ill check out the other editors that u have thank youOn 8/17/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
Amadeo Bellotti wrote:> Mr. Johnson i was hoping i didnt have to make my whole program into a
> loop because its about 900 lines of code and tabbing that would take a> long timeIf your whole program is 900 lines without a subroutine then you havemore problems than just tabbing...really, a program this big should have
many functions to divide up the work. Looking for a workaround for poorprogram structure is not a good solution in the long run; fixing theprogram structure so it is workable is a better idea.As a practical matter, many editors allow you to select and indent a
block, including TextPad and Eclipse, the two editors I usually use.KentPS please reply to the list, not to me personally. On 8/17/06, *Kent Johnson* <
[EMAIL PROTECTED] [EMAIL PROTECTED]>>> wrote:>> Amadeo Bellotti wrote:> > hello is there a way if a condition is not met to restart the whole
> > program? for example if and if statement returns true then re start> > the whole program?>> You can probably achieve what you want just by structuring the> program
> correctly. My guess you need to use nested loops, something like this:>> while True:>   initialize_everything()>   while True:> if something_is_wrong():
>   break> do_some_work()>> This will do_some_work() until something_is_wrong(), then it will> initialize_everything() and try again.>> If the test for something_is_wrong() is buried deep in the code
> you can> break the loop by raising an exception which you catch in the> top-level> loop.>> Kent>> ___
> Tutor maillist  -  Tutor@python.org Tutor@python.org>> 
http://mail.python.org/mailman/listinfo/tutor> >>___
Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] All of Kermit's E-Mails

2006-08-17 Thread Brian van den Broek
Danny Yoo said unto the world upon 17/08/06 12:16 PM:
>> Suggest an alternative way of transmitting code.
> 
> Hi Kermit,



> Just as a side note: you may want to investigate a good email client such 
> as Thunderbird if you have spare time.
> 
>  http://www.mozilla.com/thunderbird/
> 
> Much of the frustration I've been seeing on this thread deals with 
> IncrediMail's feature set; what it is providing you isn't so well suited 
> for the kind of technical communication that's on this list.




Hi Kermit,

I'd like to second Danny's suggestion of Thunderbird. It is a very 
nice client by the same people that produce firefox.

I spent a few minutes trying to find out how to set IncrediMail to 
quote properly. Unfortunately, there is no downloadable documentation 
(at least not separate from the program itself). Searching 
 for `quote' 
gave no results :-(  So, IncrediMail doesn't quite seem so Incredi to 
me ;-)

For what its worth, the feature set that they promote it with (things 
such as ``Amazing animations'', ''beautiful email backgrounds'', and 
the ability to ''add funny animations to your emails'') are all likely 
to be *very* unwelcome on any python or other technical list.

If you really like IncrediMail for your personal email, you might 
think of installing Thunderbird, getting a gmail account and using the 
combination to post to technical lists, keeping IncrediMail for 
messages to friends, etc.[*] (If you need help with any of that, you 
can write me off-list.)

[*] My guess is that after a while, you'll find yourself switching to 
Tbird. :-)

Best wishes,

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


Re: [Tutor] (no subject)

2006-08-17 Thread Danny Yoo
> thank you Mr. Johnson this is my first program so its a little sloppy. I'm
> using gedit ill check out the other editors that u have thank you

More fundamentally, spend some time to learn about functions; they'll 
address much of the original concerns you had.  See any of the tutorials 
on:

 http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

and almost all of them should talk about what functions are, and how to 
use them.

Best of wishes!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Making it easier to discuss programs (fwd)

2006-08-17 Thread Danny Yoo

Kermit accidently added a typo to the tutor@python.org address; I'll 
forward this message to the list for him.


-- Forwarded message --
Date: Thu, 17 Aug 2006 13:38:10 -0400
From: Kermit Rose <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED], "Luke Paireepinart; tutor"@python.org
Subject: Making it easier to discuss programs

From" Danny Yoo
/*Date:*/ 08/17/06 12:16:16
To: Kermit Rose
/*Cc:*/ Luke Paireepinart ; tutor@python.org 

/*Subject:*/ Re: [Tutor] All of Kermit's E-Mails




>  Hi Kermit,

> Try sending the code as a file attachment.  It's large enough that we want
> to make sure it goes through without being messed up, but small enough
>  that it can still be posted to the list.

> Alternatively, post the code on the web somewhere and send the list a link
> to the URL.  This is preferable for large blocks of code, and your
> factoring program is large enough that this would also be a good way to
> share the code with the mailing list.

I will consider making it a permanent part of my web page.

After I upload it, I can send you the specific URL for it.


> Just as a side note: you may want to investigate a good email client such
> as Thunderbird if you have spare time.

> http://www.mozilla.com/thunderbird/

> Much of the frustration I've been seeing on this thread deals with
> IncrediMail's feature set; what it is providing you isn't so well suited
> for the kind of technical communication that's on this list.


I've download and installed Thunderbird.

I'm sending this message through Thunderbird.

I did notice one annoying feature of Thunderbird. 
When I used the up arrow , intending to go up a line, it went up a page.

I got around this by using the mouse cursor to move up a line.

Does everyone else, that uses Thunderbird,  have to move up a few lines by 
using the mouse cursor, or
is there another way,
for example by setting preferences?


>From Luke:

>> This is obviously a case for ... .dun-dun-dun! object-oriented
>> programming. When you have a collection of functions that all operate
>> together to create something, you make a Class to contain them.

> I'm going to have to interject and disagree with Luke here; for Kermit's
> application, classes are not necessary.  Kermit's still trying to learn
> basic structured programming with functions; I'm not convinced that
> leaning Kermit toward Object Oriented Programming is going to help matters
> much.


>Good luck to you!
>
Thank you.  I will consider everyone's suggestions.

Those that make sense to me I will try to implement.

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


Re: [Tutor] Undeliverable Mail

2006-08-17 Thread Kermit Rose

> From" Danny Yoo
> /*Date:*/ 08/17/06 12:16:16
> To: Kermit Rose
> /*Cc:*/ Luke Paireepinart ; 
> tutor@python.org 
> /*Subject:*/ Re: [Tutor] All of Kermit's E-Mails
>
>
>
>  
>  >  Hi Kermit,
>  
>  > Try sending the code as a file attachment.  It's large enough that we 
> want
>  > to make sure it goes through without being messed up, but small enough
>  >  that it can still be posted to the list.
>  
>  > Alternatively, post the code on the web somewhere and send the list a 
> link
>  > to the URL.  This is preferable for large blocks of code, and your
>  > factoring program is large enough that this would also be a good way to
>  > share the code with the mailing list.
>
> I will consider making it a permanent part of my web page.
>
> After I upload it, I can send you the specific URL for it.
>
>  
>  > Just as a side note: you may want to investigate a good email client such
>  > as Thunderbird if you have spare time.
>  
>  > http://www.mozilla.com/thunderbird/
>  
>  > Much of the frustration I've been seeing on this thread deals with
>  > IncrediMail's feature set; what it is providing you isn't so well suited
>  > for the kind of technical communication that's on this list.
>  
>
> I've download and installed Thunderbird.
>
> I'm sending this message through Thunderbird.
>
> I did notice one annoying feature of Thunderbird.  
>
> When I used the up arrow , intending to go up a line, it went up a page.
>
> I got around this by using the mouse cursor to move up a line.
>
> Does everyone else, that uses Thunderbird,  have to move up a few lines 
> by using the mouse cursor, or
>
> is there another way,
>
> for example by setting preferences?
>
>
>
>
>
> From Luke:
>
>
>
> >> This is obviously a case for ... .dun-dun-dun! object-oriented
>
> >> programming. When you have a collection of functions that all operate
>
> >> together to create something, you make a Class to contain them.
>
>
>
> > I'm going to have to interject and disagree with Luke here; for Kermit's
>
> > application, classes are not necessary.  Kermit's still trying to learn
>
> > basic structured programming with functions; I'm not convinced that
>
> > leaning Kermit toward Object Oriented Programming is going to help 
> matters
>
> > much.
>
>
>
>
>
> >Good luck to you!
>
> >
>
> Thank you.  I will consider everyone's suggestions.
>
>
>
> Those that make sense to me I will try to implement.
>
>
>
> Kermit   <  [EMAIL PROTECTED]  >
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>   

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


Re: [Tutor] (no subject)

2006-08-17 Thread Amadeo Bellotti
Thank you again i no im a newbie and really inexperianced but thank youOn 8/17/06, Danny Yoo <[EMAIL PROTECTED]
> wrote:> thank you Mr. Johnson this is my first program so its a little sloppy. I'm
> using gedit ill check out the other editors that u have thank youMore fundamentally, spend some time to learn about functions; they'lladdress much of the original concerns you had.  See any of the tutorials
on: http://wiki.python.org/moin/BeginnersGuide/NonProgrammersand almost all of them should talk about what functions are, and how to
use them.Best of wishes!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2006-08-17 Thread Amadeo Bellotti
thank you again but i think i found a way to fix itOn 8/17/06, Danny Yoo <[EMAIL PROTECTED]
> wrote:>> > Mr. Yoo im working on a program to write a sudoku puzzle and if
>> > something is wrong with the last row i need to re make the whole puzzle>> > over again.>> Here's a separate question that's related to the first: can you write a>> function that asks the user to enter a word, and continues prompting until
>> the user enters a non-empty word?Hi Amadeo,> Yes I can Mr. Yoo, but i dont really want to make my whole program a> loop.Ok.  Why not?  I'm curious: is there a particular constraint you're trying
to work under, or is it something else?Also, I'm not sure what you mean by "whole program".In any case, here's a way to do it without an explicit 'for' or 'while'loop:
def ask_for_input(): msg = raw_input("enter a word:") if msg: return msg else: return ask_for_input()This would not be the idiomatic way to do this in Python only because of a
technical limitation in the main Python implementation (it doesn't support"tail call optimization").Still, would this be more acceptable to you, or do you also consider thisa "loop"?
(Personally, I do. *grin*)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which Book

2006-08-17 Thread Brian van den Broek
Nagendra Singh said unto the world upon 17/08/06 12:14 PM:
> Hi All,
> 
> I have very little programming experience, I have decided to learn
> Python..there are tons of material and refernces on the web-pages, can
> you guys please suggest what is the best way to start or which ONE
> book which I should follow to start.
> 
> thanks..
> 
> Nagendra


``Beware the man of one book.''
 Saint Thomas Aquinas

Free ($ sense) books I read and liked:

http://www.ibiblio.org/obp/thinkCSpy/  (easy)

http://diveintopython.org/  (less easy)


Both of those can be bought in dead-tree form, as can 



I'd start with the first and if you don't like it, try the next. 
Either way, multiple books compliment each other.

Best,

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


Re: [Tutor] Actual code that illustrates problem

2006-08-17 Thread Kermit Rose
Danny Yoo wrote:
>
>
> Hi Kermit,
>
> Ok, good.  You should add this as a comment to the function's header, 
> so that other people can see this.  Here is an example:
>
> def strongfac(z, w):
> """z is the number to be factored.
>w is a witness that may help find the factors of z.
> """
> ## rest of function body.

Ok.  I've added the suggested documentation for strongfac.

>
>> * What are the outputs? What is the return value of strongfac?
>>
>> The output is the return value of strongfac.
>> fac = [ x, y, difficulty of factoring z using w]
>> or
>> fac = [0,0,0] if strongfac could not factor z using w.
>
> Great!  Ok, I'm assuming that 'x' and 'y' are two arbitrary factors of 
> 'z'.  Are there other properties about x and y that you want to state, 
> such as: "x is always prime", or do we make no guarantees about this?
>
>
Yes.  That is correct.  There is not any expectation that x and y would 
be prime unless z just happens to be the product of exactly two primes.



>
> At this point, I'm distilling what you've said into a documentation 
> string:
>
> def strongfac(z, w):
> """strongfac: number number -> [x, y, difficulty]
>
> Factors z into two pieces, returning those two pieces as well as the
> difficulty in factoring z.  w is a witness that may help find the
> factors of z.
>
> If no factors can be found, returns [0, 0, 0].
> """
> ## rest of function body.
>
>
> Does this make sense so far?  The point is to make it easy for humans 
> to understand your program.
>
>

Yes.  I've replaced the previously suggested documentation with the above.





>
>>> # face = [x,y,0]
>> [some code cut]
>>> # face[0] = x
>>> # face[1] = y
>>> # face[2] = 0
>>
>>> The three assignments to face[0] through face[2] don't do anything 
>>> effective and clutter the code.
>>
>> In fact, I knew that.  I inserted it in an attempt to overide the 
>> apparent bug that I saw.
>>
>> Sometimes it worked.
>
> This is a bad sign.  It should not have worked.  *grin*
>
> Next time you hit something mysterious like this, mention it to the 
> list. It'll be a good puzzle for the others here to take a look at.  
> Your code should be as rational as possible.  Don't just add code in 
> hoping that it'll fix some problem: try to understand why it's not 
> working first. Look for root causes.
>
>
I agree.  I reasoned as follows.

The root cause is that Python is not returning the correct value of a list.

So before I return the list, I will remind Python what's in the list.



>
> About strongfac():
>
>
>
> Can you try this?  Can you try breaking out the square=square test in 
> a similar way to how I treated the check_p_minus_1() code?
>
>
>

I have followed your suggestion and have done so.

>
> The high level goal here is to turn strongfac() into a very simple 
> looking function.  In pseudocode, it'll look something like:
>
> 
> def strongfac(z, w):
> use check_p_minus_1 test and return if it succeeds
> use square=square test and return if it succeeds
> ...
> 
>
> This will make strongfac very regular to read.  It'll also make it 
> much easier to trace why one of your return values isn't returning 
> what you want.
> you want.

Ok.  I will work on splitting up the rest of strong fac into a set of 
functions.

I will attempt to maintain a compromise between having too many levels 
of function calls and
having any one function be too long.


Kermit  <  [EMAIL PROTECTED]  >




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


Re: [Tutor] All of Kermit's E-Mails

2006-08-17 Thread Kermit Rose
Brian van den Broek wrote:
>
>
> Hi Kermit,
>
> I'd like to second Danny's suggestion of Thunderbird. It is a very 
> nice client by the same people that produce firefox.
>
> I spent a few minutes trying to find out how to set IncrediMail to 
> quote properly. Unfortunately, there is no downloadable documentation 
> (at least not separate from the program itself). Searching 
>  for `quote' 
> gave no results :-(  So, IncrediMail doesn't quite seem so Incredi to 
> me ;-)

I agree.  In fact, I never did use any of the proudly proclaimed 
features of IncrediMail .  I used it only because when I accidently 
clobbered my previous email program
Pegasus,

IncrediMail  was the first replacement  email program I found on the 
internet.



>
> For what its worth, the feature set that they promote it with (things 
> such as ``Amazing animations'', ''beautiful email backgrounds'', and 
> the ability to ''add funny animations to your emails'') are all likely 
> to be *very* unwelcome on any python or other technical list.
>
Yes.   I simply ignored their special features as long as I could get it 
to send simple emails.  

When several of you on the tutor list showed me that IncrediMail caused 
frustration, I agreed to, and did, switch to Thunderbird. 

Before Danny's suggestion, I did not know of the existence of Thunderbird.


Now if I can only get Thunderbird to quit treating the up and down arrow 
as a page up or page down,
whenever it's at the top line or bottom line of what it thinks is a page.


Kermit   <  [EMAIL PROTECTED]   >


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


Re: [Tutor] Actual code that illustrates problem

2006-08-17 Thread Danny Yoo
 # face = [x,y,0]
>>> [some code cut]
 # face[0] = x
 # face[1] = y
 # face[2] = 0
>
> I agree.  I reasoned as follows.
>
> The root cause is that Python is not returning the correct value of a list.
>
> So before I return the list, I will remind Python what's in the list.

Hi Kermit,

Let's take those last three assignments out: they don't do anything as far 
as I can see.  If you do see a functional change in your program after 
doing so, I'll be very surprised and intrigued.  *grin*

The reason for taking them out is to, again, make the program as short 
and sweet as we can for humans to read.  A program's readability matters.


> Ok.  I will work on splitting up the rest of strong fac into a set of 
> functions.

That sounds good!  Definitely keep us up-to-date while you do it.  We can 
give suggestions if we see something that can be simplified, and we want 
to make sure you don't run into any big ruts as you do this.

Once your program is in smaller functional chunks, let's look again at 
your original problem.  I'm hoping that it'll be easier to chase the 
problem down then.


> I will attempt to maintain a compromise between having too many levels 
> of function calls and having any one function be too long.

I wouldn't worry about having heavy function call depth too much yet.  If 
it does turn out to be an issue, reversing the refactoring by inlining 
should be mechanically easy to do.


Good luck to you!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] banners

2006-08-17 Thread josip
  Hi, I want to solve thi question, but I don't know how  Can someone help?     When dot matrix printers were at the height of hi- tech fashion, university students  used to create banners with words on them using special characters (e.g. a banner  with a student’s initials on it formed out of # characters). Write a Python program that  spells out your name or nickname using special characters. Call your program  banner.py.  *  * *  *  *  *  *      *  *  *    *  *  *    *  *  *    *           Thanks! 
		Get your email and more, right on the  new Yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] banners

2006-08-17 Thread Danny Yoo


On Thu, 17 Aug 2006, josip wrote:

>  Hi, I want to solve thi question, but I don't know how

[homework question cut]

This is homework; our policy is not to give much help on this, as it's 
your work to do.  Do you have any specific questions?  Otherwise, all I 
can do here is point you toward introductory Python tutorial material at:

 http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

As far as I can tell, you should be able to solve this problem after 
reading the first section of any Python tutorial.

Try to do this homework problem on your own.  Frankly speaking, it is not 
a difficult problem; it's easy in the sense that you can do this if you 
honestly read through your course materials.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which Book

2006-08-17 Thread Mike Hansen
> 
> Hi All,
> 
> I have very little programming experience, I have decided to learn
> Python..there are tons of material and refernces on the web-pages, can
> you guys please suggest what is the best way to start or which ONE
> book which I should follow to start.
> 
> thanks..
> 
> Nagendra

http://pyfaq.infogami.com/tutor-what-are-some-good-books-on-python 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Low level socket and threading code in python in HUGEwebsites -

2006-08-17 Thread Alan Gauld
Anil,

I don't know if this is the kind of thuing they did on reddit, but a
few years ago I was working on a large network management
system (in C++ FWIW). It was monitoring a network of around
100,000 nodes.To ensure a timely flow of alarm traffic the server
had 4 network cards and the code used multi threading and
low level comms code to access those 4 IP addresses.

But the Sun Sparcstation I was using at the time onlky
had one network card and IP address, so the code couldn't
run without mmajor invasive debug statements, almosty
rendering the threading inactive. So in practice I had to
run my code on the server each time I worked on the
threaded code.

I don;t know if thats the kind of issue he means but it might be
an example of the kind of thing that a big web farm might
experience.

On another project I had similar issues where my workstation
didn't have enough RAM to compile (actually link)  the code
(in C++ again), so although I could edit the code on my local
machine I had to do the builds on the server (I only had
128M RAM, the server had 512M - and at the time
128M RAM cost over $400 - 8x16M modules!)

HTH,

Alan G.

- Original Message - 
From: "anil maran" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, August 17, 2006 10:48 AM
Subject: [Tutor] Low level socket and threading code in python in 
HUGEwebsites -


> What kind of low-level socket and threading code is necessary for a 
> db
>  intensive site such as yahoo. How do we use it from python? does
>  anyone  have experience using it
>
>
> http://redditblog.blogspot.com/2005/12/on-lisp.html
> >From moving to python by the founders of reddit
>
>
> Because of the low-level socket and threading code we had to write,
> reddit would not run on my Mac, and I was always tethered to our
> FreeBSD development server. Not being able to program offline is a
> pain.
>
> I would imagine that they aren't just using a database.
> most of the "low level socket stuff" I've seen is about setting
> timeouts and doing Async IO.
>
>
>
> -
> Do you Yahoo!?
> Get on board. You're invited to try the new Yahoo! Mail Beta. 

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


Re: [Tutor] web application and database caching technique

2006-08-17 Thread Alan Gauld
>i m trying to build a webapplication, i need to cache db records 
> as it has become very slow the sql queries and retrival
> can you guys helpe me out in designing cache structures/ hash 
> tables for these cases 

Which database? Most relational databases have caching as a 
feature that you can configure. It may be that you can simply 
increase the size of the database cache on the server?

A lot easier and usually a lot more efficient and reliable too.

Fixing database scaleability issues is rarely best done 
outside of the database! (Small volume query improvements 
are another matter entirely!)

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


Re: [Tutor] web application and database caching technique

2006-08-17 Thread Danny Yoo


On Thu, 17 Aug 2006, Alan Gauld wrote:

>> i m trying to build a webapplication, i need to cache db records as it 
>> has become very slow the sql queries and retrival can you guys helpe me 
>> out in designing cache structures/ hash tables for these cases

I second Alan's suggestion: talk to your database administrator and make 
sure you're not doing something that he or she is responsible for. 
Offhand, it sounds like you're trying to reinvent database indices.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which Book

2006-08-17 Thread Alan Gauld
> I have very little programming experience, I have decided to learn
> Python..there are tons of material and references on the web-pages, 
> can
> you guys please suggest what is the best way to start or which ONE
> book which I should follow to start.

Despite the fact that my tutor is available in paper form I personally
don't recommend buying a beginners book - -they quickly become
redundant so they are poor value. I would advocate working through
the web tutorials (mine if you like:-) and then buy a goood reference
book (or two). Maybe a general treference like Python in a Nutshell
plus maybe a specialised one in the areas you are interested in
(Networks, Databases, Web, GUI, text processing etc)

But tastes in books is so subjective its hard to give recommendations.
I like generalist books like Programming Python, but many people
don't like that one at all. I didn't particularly like Text Processing 
in
Python, even though its the best book in its class - but I just didn't
like the style much. But I know others who think its a bit of a
masterpiece...

A lot will depend on your previoius experience too.
For example if you can already program in another language and
have a fair grasp of computer science terminology then my book
would be a complete waste of time, but if you only have ac minimal
experience and don;t know the CS terms my book would be a good
choice (he says immodestly!)

Best thing if possible is to borrow a copy (from a friend or library)
or if there is a web version read a bit there first.

HTH,

Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 

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


Re: [Tutor] (no subject)

2006-08-17 Thread Alan Gauld
> thank you Mr. Johnson this is my first program so its a little 
> sloppy. I'm
> using gedit ill check out the other editors that u have thank you

If you have Python you will have either IDLE or Pythonwin (or both)
Both of these will allow block indent/unindent so simply load the
code into IDLE to do the indentation.. You can go back to gedit
afterwards if you like.

But as Kent said you should ideally aimto write the code as
functions, each about 5-50 lines long (less than 5 and the advantage
is minimal, mor than 50 is just too long - around 12 lines per 
functoion
is a good average IMHO

But don't use number of lines as the deciding factor! Divide the code
into blocks of code that do something logical that you can describe
in a few words (see the comments from Danny to Kermit for examples!)
Use those few words to name the function. Consider how to pass key
data between the funbctions using parameters and return values.

If you don't know how to write functions take a look at the Functions
topic of my tutor.

HTH,

Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

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


Re: [Tutor] All of Kermit's E-Mails

2006-08-17 Thread Alan Gauld
> gave no results :-(  So, IncrediMail doesn't quite seem so Incredi 
> to me ;-)

I'll second that!

I have an elderly friend who loves the net and is on lots of non 
techie mailing lists.
She was waxing lyrical about incredimail to me and was amazed that I 
didn't use
it, it was so good.

So I downloaded it and used it for 1 day before giving up in disgust
- I couldn't find a single feature that lifted it above even the
most basic Outlook Express functions! It's big on frippery and zero
on useful functions. (For my purposes at least - my friend still 
thinks
its the best thing out there! - and sends me every message with
an HTML attached version for free... :-()

Alan G. 

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


Re: [Tutor] Actual code that illustrates problem

2006-08-17 Thread Alan Gauld
While others have made good suggestions to clarify the code I thought
I'd try to tackle the question of whether we had a bug in Python.

Unfortunately the debug output does not come from the code that's
posted so its difficult to figure out what's been happening.

For example, one apparently good and one "faulty" test:

>  In strongfac
>  Found1: x =  53799857
>  Found1: y =  1858741
>  face =  [53799857L, 1858741L, 0]
>  Found1: factor by strong probable prime test, using witnes 
> 15306543515214

Note the mis-spelling of witnes(sic) - it does not appear in the code!

>  Found1: factors are  53799857 1858741
>  Found1: returning  [53799857L, 1858741L, 0]  to fermat routine.
>  Retrieved from strongfac, face =  [0, 0, 0]
>  In fermat: k =  13  x =  0  y =  0  face =  [0, 0, 0]

Similarly the first line has the text "factors are 53..."

But in the code all instances of "factors are" are followed by the 
word "by"

So I conclude the tests are not from this code. The fault may be in 
this code
but I can't be sure...

However a couple of observations might help:

> #def strongfac(z,w):
> #x = gcd(z,w-1)
> #if x > 1:
> #if x < z:

You can simpliffy this 2 stage test using either boolean operartors:

if x > 1 and x < z:

OR, almost uniquie to pyhon:

if 1 < x < z:

That removes one whole layer of indentation.
This trick can be applied in many places in the algorithm.


Also


> #y = z/x
> #print "Found factors by P-1 Method as part of 
> Strong
> probable prime test, using witness",w,"."
> #print " x = ",x," y = ",y
> #return [x,y,0]
> #w2 = (w * w)%z
> #s = ksqrt(w2)
> #if w2 == s * s:
> #if s != w:
> #x = gcd(z,kabs(w2 - s))
> #if x > 1:
> #if x < z:
> #print "Found factors by square = square as 
> part of
> Strong probable prime test, using witness",w,"."
> #return [x,y,0]

If x was not between 1 and z in the first test y is not defined at 
this point.

> #trace = 0
> #t = z - 1
> #a = 0
> #while t%2 == 0:
> #t = t/2
> #a = a + 1
> #test = pow(w,t,z)
> #if test ==1:
> #x = gcd(z,w-1)
> #if x > 1:
> #if x < z:
> #y = z/x
> #print " Found factor by Strong probable prime 
> test,
>using withness ",w,"."
> #return [x,y,0]
> #else:
> #x = gcd(test-1,z)
> #if x > 1:
> #print " "
> #print " In strongfac "
> #print " Found1: x = ",x

You could do all of this with a single print:

print "\n In strongfac \nFound1: x = ", x

I won't go any further because its pointless given the discrepency 
between
the data and the code, but hopefully those pointers will be helpful in 
your
efforts to tidy the code into separate functions.

Alan G. 

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


Re: [Tutor] banners

2006-08-17 Thread Alan Gauld
> As far as I can tell, you should be able to solve this problem after 
> reading the first section of any Python tutorial.

I'm not so sure Danny, figuring out how to draw the letters in the
banner is not obvious after having read a hello-world program
example. There are some tricky-ish aspects to this one.

To the OP, Danny is right that we don't give answers to homeworks
but if you give it a try and get stuck come back to us with the
code you have written and we might ask you some questions
to make you think about the solution...

Alan G. 

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


Re: [Tutor] banners

2006-08-17 Thread Danny Yoo
> I'm not so sure Danny, figuring out how to draw the letters in the 
> banner is not obvious after having read a hello-world program example. 
> There are some tricky-ish aspects to this one.

Hi Alan,

It's simpler than that: the homework states that the message is hardcoded 
to show either josip's name or nickname.  If the homework had asked to 
more generally print a banner of a arbitrary message, that would be 
harder, but his homework assignment is much easier because of the 
hardcoded nature of it.


If I were to write this, my banner.py would be required to display:

*   *   *
*   *   *   *
*  *  *
***

on the screen.


So the parameterization is based on the person who is writing it.  It's 
very much a program in the same difficulty level as "Hello World", which 
is why I'm trying very hard not to say more about it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Actual code that illustrates problem

2006-08-17 Thread Kermit Rose
Alan Gauld wrote:
>
> While others have made good suggestions to clarify the code I thought
> I'd try to tackle the question of whether we had a bug in Python.
>
> Unfortunately the debug output does not come from the code that's
> posted so its difficult to figure out what's been happening.
>
> For example, one apparently good and one "faulty" test:
>
>>  In strongfac
>>  Found1: x =  53799857
>>  Found1: y =  1858741
>>  face =  [53799857L, 1858741L, 0]
>>  Found1: factor by strong probable prime test, using witnes 
>> 15306543515214
>
> Note the mis-spelling of witnes(sic) - it does not appear in the code!
>
HmmPerhaps I caught that spelling error between the time I sent 
the attached program file and the time I reran the program to demostrate 
the error.


>>  Found1: factors are  53799857 1858741
>>  Found1: returning  [53799857L, 1858741L, 0]  to fermat routine.
>>  Retrieved from strongfac, face =  [0, 0, 0]
>>  In fermat: k =  13  x =  0  y =  0  face =  [0, 0, 0]
>
> Similarly the first line has the text "factors are 53..."
>
> But in the code all instances of "factors are" are followed by the 
> word "by"
>
> So I conclude the tests are not from this code. The fault may be in 
> this code
> but I can't be sure...
>
After I've followed the many good suggestions for making my program more 
concise and readable,
I'll re-run it and see if I get the same difficulty at the same z's to 
factor.

I will upload the source to my web page and create a path to it in my 
index.html file.


> However a couple of observations might help:
>
>> #def strongfac(z,w):
>> #x = gcd(z,w-1)
>> #if x > 1:
>> #if x < z:
>
> You can simpliffy this 2 stage test using either boolean operartors:
>
> if x > 1 and x < z:
>
> OR, almost uniquie to pyhon:
>
> if 1 < x < z:
>

Hmm.

A good syntax to remember.


> That removes one whole layer of indentation.
> This trick can be applied in many places in the algorithm.
>
>
> Also
>
>
>> #y = z/x
>> #print "Found factors by P-1 Method as part of Strong
>> probable prime test, using witness",w,"."
>> #print " x = ",x," y = ",y
>> #return [x,y,0]
>> #w2 = (w * w)%z
>> #s = ksqrt(w2)
>> #if w2 == s * s:
>> #if s != w:
>> #x = gcd(z,kabs(w2 - s))
>> #if x > 1:
>> #if x < z:
>> #print "Found factors by square = square as 
>> part of
>> Strong probable prime test, using witness",w,"."
>> #return [x,y,0]
>
> If x was not between 1 and z in the first test y is not defined at 
> this point.
>
Yep.  I should have calculated y = z/x before printing.

The syntax checker would have found this as soon as I encountered a z 
that took me to that point.

I'll fix it before re-submitting.


>> #trace = 0
>> #t = z - 1
>> #a = 0
>> #while t%2 == 0:
>> #t = t/2
>> #a = a + 1
>> #test = pow(w,t,z)
>> #if test ==1:
>> #x = gcd(z,w-1)
>> #if x > 1:
>> #if x < z:
>> #y = z/x
>> #print " Found factor by Strong probable prime test,
>> using withness ",w,"."
>> #return [x,y,0]
>> #else:
>> #x = gcd(test-1,z)
>> #if x > 1:
>> #print " "
>> #print " In strongfac "
>> #print " Found1: x = ",x
>
> You could do all of this with a single print:
>
> print "\n In strongfac \nFound1: x = ", x
>
uh.. Too compact for me.

I need to see the logic more spread out.



> I won't go any further because its pointless given the discrepency 
> between
> the data and the code, but hopefully those pointers will be helpful in 
> your
> efforts to tidy the code into separate functions.
>
> Alan G.

Also a warning to me to not edit the final output to compensate for 
faulty programming.

Thank you.

Kermit  <   [EMAIL PROTECTED]   >


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


Re: [Tutor] All of Kermit's E-Mails

2006-08-17 Thread R. Alan Monroe
 
> my email program does not insert the > sign like the standard email
> program does.

"The Bat" mail client does a great job of it, but it's not free.
http://www.ritlabs.com/

You might try Pegasus Mail, although I don't remember how well it does
it. http://www.pmail.com/

If you were desperate and crazy, you could also try typing the
messages in XNews's editor and copy/paste them to your mail.
http://xnews.newsguy.com/


Alan

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


Re: [Tutor] Which Book

2006-08-17 Thread Amadeo Bellotti
A good book is Practical Python by Magnus Lie Hetland.On 8/17/06, Alan Gauld <[EMAIL PROTECTED]
> wrote:> I have very little programming experience, I have decided to learn
> Python..there are tons of material and references on the web-pages,> can> you guys please suggest what is the best way to start or which ONE> book which I should follow to start.Despite the fact that my tutor is available in paper form I personally
don't recommend buying a beginners book - -they quickly becomeredundant so they are poor value. I would advocate working throughthe web tutorials (mine if you like:-) and then buy a goood referencebook (or two). Maybe a general treference like Python in a Nutshell
plus maybe a specialised one in the areas you are interested in(Networks, Databases, Web, GUI, text processing etc)But tastes in books is so subjective its hard to give recommendations.I like generalist books like Programming Python, but many people
don't like that one at all. I didn't particularly like Text ProcessinginPython, even though its the best book in its class - but I just didn'tlike the style much. But I know others who think its a bit of a
masterpiece...A lot will depend on your previoius experience too.For example if you can already program in another language andhave a fair grasp of computer science terminology then my bookwould be a complete waste of time, but if you only have ac minimal
experience and don;t know the CS terms my book would be a goodchoice (he says immodestly!)Best thing if possible is to borrow a copy (from a friend or library)or if there is a web version read a bit there first.
HTH,Alan GauldAuthor of the Learn to Program web sitehttp://www.freenetpages.co.uk/hp/alan.gauld___
Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] All of Kermit's E-Mails

2006-08-17 Thread Brian van den Broek
Kermit Rose said unto the world upon 17/08/06 02:38 PM:

> Now if I can only get Thunderbird to quit treating the up and down arrow 
> as a page up or page down,
> whenever it's at the top line or bottom line of what it thinks is a page.


Hi Kermit,

I'm glad you've given Thunderbird a try and that you seem to have 
taken all of the advice in the right spirit.

I'm not sure what you mean by a `page' in the context of email. Could 
you describe the exhibited and expected behaviour in a bit more detail?

For now, have you tried clicking in the message body and then using 
the arrows? (That's all I've got.)

You might also what to try the mozilla support forums and knowledge base.

Best,

Brian



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


Re: [Tutor] (no subject)

2006-08-17 Thread Amadeo Bellotti
thank you but IDLE doesnt seem to work on Suse 9.2 do you know a way to fix it?On 8/17/06, Alan Gauld <[EMAIL PROTECTED]
> wrote:> thank you Mr. Johnson this is my first program so its a little
> sloppy. I'm> using gedit ill check out the other editors that u have thank youIf you have Python you will have either IDLE or Pythonwin (or both)Both of these will allow block indent/unindent so simply load the
code into IDLE to do the indentation.. You can go back to geditafterwards if you like.But as Kent said you should ideally aimto write the code asfunctions, each about 5-50 lines long (less than 5 and the advantage
is minimal, mor than 50 is just too long - around 12 lines perfunctoionis a good average IMHOBut don't use number of lines as the deciding factor! Divide the codeinto blocks of code that do something logical that you can describe
in a few words (see the comments from Danny to Kermit for examples!)Use those few words to name the function. Consider how to pass keydata between the funbctions using parameters and return values.If you don't know how to write functions take a look at the Functions
topic of my tutor.HTH,Alan GauldAuthor of the Learn to Program web sitehttp://www.freenetpages.co.uk/hp/alan.gauld

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


Re: [Tutor] Communicating with Win2000 runas.exe

2006-08-17 Thread Barnaby Scott
Tim Golden wrote:
> [Barnaby Scott]
> 
> | So I'm thinking along these lines:
> | 
> | import subprocess
> | sp = subprocess.Popen(r'C:\WINNT\SYSTEM32\runas.exe 
> | /user:administrator
> | C:\Program Files\Microsoft Games\Age of Mythology\aom.exe')
> | #some sort of code to send the password here...
> | #help!
> 
> I *think* -- and I'm happy to be wrong -- that there's
> no way you're going to get that password in there. One
> place to start looking might be:
> 
> pywinauto - http://pywinauto.pbwiki.com/
> 
> which lets you automate Windows in general; don't know
> how much use it'll be here. 
> 
> Alternatively, look into the pywin32 package, and in 
> particular at the win32security functions which let you 
> impersonate another user. They're not trivial to use, 
> but their use has been explained a few times over the 
> years I think. Mostly by Roger Upole who wrote most if 
> not all of the Python bindings.
> 
> Here's a post which looks useful; you'll have to hunt
> around for others:
> 
> http://groups.google.com/group/comp.lang.python/msg/6bbefb9d4d45d253
> 
> I suggest you ask this question again on the main
> python / python-win32 lists; it's a bit too platform-specific
> for the tutor list, I would say.
> 
> TJG

Thanks for your tips. In fact the first link you gave put me onto 
Sendkeys (http://www.rutherfurd.net/python/sendkeys/), which is a 
prerequisite for pywinauto. In the end that was all I needed. In case 
anyone else is interested here is my code now (with SendKeys installed):


import subprocess, SendKeys

subprocess.Popen(r'C:\WINNT\system32\runas.exe /user:administrator 
"C:\Program Files\Microsoft Games\Age of Mythology\aom.exe"')

SendKeys.SendKeys('{PAUSE 1}MyAdministratorPassword{ENTER}')


Worth knowing about - might be quite useful for all sorts of things, 
however 'quick and dirty' it feels as a technique!

Thanks again

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


Re: [Tutor] (no subject)

2006-08-17 Thread John Fouhy
On 18/08/06, Amadeo Bellotti <[EMAIL PROTECTED]> wrote:
> thank you but IDLE doesnt seem to work on Suse 9.2 do you know a way to fix
> it?

Why not -- what goes wrong?  Is there an error message?

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


Re: [Tutor] (no subject)

2006-08-17 Thread Dave Kuhlman
On Thu, Aug 17, 2006 at 01:28:56PM -0400, Amadeo Bellotti wrote:
> thank you Mr. Johnson this is my first program so its a little sloppy. I'm
> using gedit ill check out the other editors that u have thank you
> 

I'd also encourage you to look at other editors, as others on this
list have.

However, if you like and want to stay with gedit, try to do the
following (if you have not already) -- Click on menu item
Edit/Preferences, then click on the Plugins tab and enable 
"Indent lines" plugin.  After doing so, there should be Indent and
Unindent items in the Edit menu.  Highlight a block of code, and
try those operations.

Indent and Unindent operations will enable you to easily convert top
level code into a function: specifically, Indent block and add a
"def" statement at the top.

I apologize if the above is overly simple-minded and if you are
already past this.

Dave



-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2006-08-17 Thread Amadeo Bellotti
Mr. Kuhlman it says python is not configured for tk.

but on another note does anyone know how to make a 2d array?
On 8/18/06, John Fouhy <[EMAIL PROTECTED]> wrote:
On 18/08/06, Amadeo Bellotti <[EMAIL PROTECTED]> wrote:> thank you but IDLE doesnt seem to work on Suse 9.2 do you know a way to fix> it?Why not -- what goes wrong?  Is there an error message?
--John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2006-08-17 Thread John Fouhy
On 18/08/06, Amadeo Bellotti <[EMAIL PROTECTED]> wrote:
> Mr. Kuhlman it says python is not configured for tk.
>
> but on another note does anyone know how to make a 2d array?

Are you in charge of your machine, or does someone else administer it?

I don't know SUSE very well, but I expect that you can fix this by
installing a package called something like "python-tkinter".

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