Re: [Tutor] All of Kermit's E-Mails [was: Global Variables]
Hello, Kermit. Kermit Rose wrote: > > > From: Bob Gailer > Date: 08/14/06 20:24:00 > To: [EMAIL PROTECTED]; tutor@python.org > Subject: RE: [Tutor] Global variables > > A while back you attached factor34.py. Is that the program you are > having trouble with? > > > > > Yes! > > And you said it misbehaves "consistently with certain numbers to be > factored." > What are these numbers? > > > * > > One of the numbers for which strongfac fails to return factors which it > correctly calculates is > > Search for a factor of 137 > 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. There are two reasons why I think this. First, consider this example. Hello, how are you today? *** I'm fine. Did you have a good day? *** Yes, I did. Now while I'm reading this, I see the dialog going like this. person: 'hello, how are you today?' kermit: 'i'm fine. did you have a good day?' Oh wait! there are stars there. That must mean that part of what I thought was you talking was actually person talking. So I have to actually try to judge which part was the original post and which part is your reply. On this example it's easy to see that 'did you have a good day' is person's speech and not yours because there are only two lines of text between the stars and we know that the first line immediately after any set of stars has to be your reply. Now consider this example: > Hello, how are you today? I'm fine. > Did you have a good day? Yes, I did. Tell me that isn't orders of magnitude clearer. Point 2: I recently read an article on UI design. Basically, what it said was 'the easier it is for your users to intuitively understand your application, the more they'll enjoy it and consider it a good application. This is largely governed by how they've experienced similar applications working in the past, and they expect if they perform similar actions in your application they'll garner similar results as in your predecessor.' How this applies to you: Right away, when I see those stars, I get really agitated, because I know I'm going to have to work twice as hard trying to decipher who's talking when I read your e-mail, and right off the bat you've alienated me and made me not want to address the issue at hand. Clearly you can see this as I've written quite a long reply that is based on nothing to do with your original question. The place where I had a problem understanding who was speaking in this particular e-mail was: >A while back you attached factor34.py. Is that the program you are >having trouble with? > > > > >Yes! > >And you said it misbehaves "consistently with certain numbers to be >factored." >What are these numbers? > > >* > >One of the numbers for which strongfac fails to return factors which it >correctly calculates is As I was reading this, I assumed the 'Yes!' and following paragraph were part of the same thought. When I got to the second set of stars, my immediate reaction was "Why is kermit replying to something she just said?" That was followed by "Oh, somewhere along the line it must've switched between the original poster's and kermit's dialog." I figured out that the 'And you said it misbehaves ...' part was where the OP continued to speak. Now that I'm done with that topic, let's move on. From one of your other e-mails: >From: Alan Gauld >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. >* >Huh??? >What side effects do you have in mind? >I certainly did not know any side effects existed. >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. 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'] #--- 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 -
Re: [Tutor] Build a simple ftp server in python
On Wed, Aug 16, 2006 at 11:09:26AM +0200, J?nos Juh?sz wrote: > Hi All, > > I am just plannig to make a small ftp server that would serv not a > filesystem, but some kind of objects, like stocks or assets. > In that case I can use my favorite commander to delete, copy, move objects > from one place to another. > > Have you got any idea which module to use ? > Look at Twisted: http://twistedmatrix.com/projects/core/ and Medusa: http://www.nightmare.com/medusa/ And, you might be interested in this thread on twisted and medusa: http://www.gossamer-threads.com/lists/python/python/379675 Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
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? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Global variables
From: Alan Gauld Date: 08/15/06 03:37:21 To: Kermit Rose; [EMAIL PROTECTED] Cc: tutor@python.org; [EMAIL PROTECTED] Subject: Re: [Tutor] Global variables . 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. * Huh??? What side effects do you have in mind? I certainly did not know any side effects existed. 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. >>> Confusion of names is of very little import, that really isn't the issue. ** Is it that global variables are no implemented correctly? I can't imagine what the issue would be if it isn't confusion of names. >> I'd be very very doubtful that its a bug in Python. Python is very well tested and while occasionally bugs do surface, the type of bug you are describing is extremely unl;ikely to have remained hidden. It is far more likely to be an error in the code or in the data. *** I understand your skepiticism. I would be too in if I were in your position. I've just sent the documentation to the list, in my message to Luke. > All of which points to an error in the code not in Python. The way Python is written it is virtually never going to result in that kind of error dependant on data values. ** Which is why it surprised me. >>> That might happen is if the values are very close to zero and a type conversion occurs, but otherwise I'm very dubious about a Python bug of that type. * Indeed. Errors of this type would be found by chance, like I found it. It would be impractical to search for this type of error. It is not a type conversion. The error is occuring between the return statement in the called function and the picking up of that value in the calling function. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Global variables
From: Bob Gailer Date: 08/14/06 20:24:00 To: [EMAIL PROTECTED]; tutor@python.org Subject: RE: [Tutor] Global variables A while back you attached factor34.py. Is that the program you are having trouble with? Yes! And you said it misbehaves "consistently with certain numbers to be factored." What are these numbers? * One of the numbers for which strongfac fails to return factors which it correctly calculates is Search for a factor of 137 Kermit < [EMAIL PROTECTED] > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Actual code that illustrates problem
Message: 11 Date: Tue, 15 Aug 2006 11:50:47 +1200 From: "John Fouhy" <[EMAIL PROTECTED]> Subject: Re: [Tutor] Global variables Cc: tutor@python.org Can you post actual code to illustrate the problem? Don't post your entire module; just show us the functions involved, the input that causes the problem, and what output you expect to get. -- John. *** Here is the output that illustratrates the problem. After the output I'll list the code for the called function, strongfac, and the calling function, fermat. IDLE 1.1.2 >>> import factor34 >>> from factor34 import testrange >>> testrange(10**14+37,10**14+37) Begin calculating constants to be used in factoring. Finished calculating constants to be used in factoring. Search for a factor of 137 Could not find factors by strong probable prime test using witnesses < 1. Try to find factors by using power of 2 mod z as a witness. Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 0 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 1 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 2 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 3 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 4 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 5 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 6 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 7 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 8 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 9 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 10 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 11 x = 0 y = 0 face = [0, 0, 0] Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 12 x = 0 y = 0 face = [0, 0, 0] In strongfac Found1: x = 53799857 Found1: y = 1858741 face = [53799857L, 1858741L, 0] Found1: factor by strong probable prime test, using witnes 15306543515214 . 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] In strongfac Found1: x = 53799857 Found1: y = 1858741 face = [53799857L, 1858741L, 0] Found1: factor by strong probable prime test, using witnes 12123044576953 . Found1: factors are 53799857 1858741 Found1: returning [53799857L, 1858741L, 0] to fermat routine. Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 14 x = 0 y = 0 face = [0, 0, 0] In strongfac Found1: x = 53799857 Found1: y = 1858741 face = [53799857L, 1858741L, 0] Found1: factor by strong probable prime test, using witnes 45391315949900 . Found1: factors are 53799857 1858741 Found1: returning [53799857L, 1858741L, 0] to fermat routine. Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 15 x = 0 y = 0 face = [0, 0, 0] In strongfac Found1: x = 53799857 Found1: y = 1858741 face = [53799857L, 1858741L, 0] Found1: factor by strong probable prime test, using witnes 59571344259390 . Found1: factors are 53799857 1858741 Found1: returning [53799857L, 1858741L, 0] to fermat routine. Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 16 x = 0 y = 0 face = [0, 0, 0] In strongfac Found1: x = 53799857 Found1: y = 1858741 face = [53799857L, 1858741L, 0] Found1: factor by strong probable prime test, using witnes 78029752396948 . Found1: factors are 53799857 1858741 Found1: returning [53799857L, 1858741L, 0] to fermat routine. Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 17 x = 0 y = 0 face = [0, 0, 0] In strongfac Found1: x = 53799857 Found1: y = 1858741 face = [53799857L, 1858741L, 0] Found1: factor by strong probable prime test, using witnes 35863146075772 . Found1: factors are 53799857 1858741 Found1: returning [53799857L, 1858741L, 0] to fermat routine. Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 18 x = 0 y = 0 face = [0, 0, 0] In strongfac Found1: x = 53799857 Found1: y = 1858741 face = [53799857L, 1858741L, 0] Found1: factor by strong probable prime test, using witnes 19712913203085 . Found1: factors are 53799857 1858741 Found1: returning [53799857L, 1858741L, 0] to fermat routine. Retrieved from strongfac, face = [0, 0, 0] In fermat: k = 19 x = 0 y = 0 face = [0, 0, 0] In strongfac Found1: x = 53799857
Re: [Tutor] threading
On Tue, 15 Aug 2006, Jeff Peery wrote: > hello, how do I stop a thread? In all the threaded apps I have so far, I've worked with Queues to give them work. So my technique has been to put a special-purpose element on the Queue, which is recognized by the thread, which exits. I usually have multiple threads accessing the Queue (or what's the point?), so before exiting, the ending thread requeues the "stop" element back onto the Queue it took it from, so that other executing threads can pick it up and process it the same way. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and storing favicon.ico
>>> i want to get the favicon.ico from the URL when a blog is added to >>> the aggregator >> >> I have no idea what this means. > > Anil is referring to an icon image file that's often associated with > web sites: > > http://en.wikipedia.org/wiki/Favicon Sure, that much I understood, but which url, and what is the aggregator? Is this one he is creating? Is his code part of the server or a client monitoring a blog site? Is he trying to detect events on a server site he uses, or one he manages? or one he is writing? Despite his many posts I still don't really understand what exactly anil is trying to do and which parts of it are in Python, which are server side, which are client side and if any of it is server admin related. Nor do I understand what specifically Anil has tried himself and where he is getting stuck and what exactly he wants us to help with. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] threads and webpy
> 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 scripts from one python script you'd do something like this: # (non-working code) import subprocess subprocess.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 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? (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.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] threads and webpy
> 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 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 ? cheers e. - Колите. Само в кината от 4 август. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and storing favicon.ico
>> i want to get the favicon.ico from the URL when a blog is added to >> the aggregator > > I have no idea what this means. Anil is referring to an icon image file that's often associated with web sites: http://en.wikipedia.org/wiki/Favicon The Python Imaging Library (PIL) should be able to open .ICO files. See: http://www.pythonware.com/products/pil/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] about threads
[EMAIL PROTECTED] wrote: > Hi all, > > 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 ;-) > Maybe i can do this with 'threads' but how ? is there some > example ?? What are the commands you use to run the two copies of web.py? Introductory material on threading is pretty scarce, try these: http://mail.python.org/pipermail/tutor/2005-October/041866.html http://linuxgazette.net/107/pai.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Build a simple ftp server in python
Hi All, I am just plannig to make a small ftp server that would serv not a filesystem, but some kind of objects, like stocks or assets. In that case I can use my favorite commander to delete, copy, move objects from one place to another. Have you got any idea which module to use ? Yours sincerely, __ János Juhász ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting and storing favicon.ico
Anil, Can you please ask more useful questions? You have already been pointed to the url which describes how to ask good questions. Please read it! > /favicon.ico > > i want to get the favicon.ico from the URL when a blog is added to > the aggregator I have no idea what this means. > and then display the image, > this is the usage scenario Display the image where? On the blog? On a client GUI? In a browser? Don't make us guess, we cannot see your code, we cannot see your system. We only have a vague idea of what you are trying to do based on these fragmentary postings. We try to help but you are making it nearly impossible to give any sensible guidance. What code have you tried to read this icon file? > Please let me know how to do this in python > > i m willing to use os.spawnv() and call convert if need be I have no idea why you think either would be necessaary. 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] about threads
Luke Paireepinart escribió: > 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. Bear in mind that python threads have the GIL "Global interpreter lock". If you've got two processors, one interpreter, and two python threads there, at most you'll be able to use one processor. The GIL means that only one instruction at a time can be executed. Depending on what you're doing and the load you've got, this may or may not be important. Ismael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor