Re: [Tutor] Complete programming newbie requires tutorial.
but am a complete newbie when it comes to programming. I bought the O'Reilly Learning Python book, but have struggled Its really for existing programmers. Its a great book though so once you get over the initial hurdle go back and read it ahain. note that resources on the python.org website, All the tutorials on the Non Programmers web site have their own flavour(*) and what suits one person won't suit another. Pay a visit to a few, try out a topic or two and pick your favourite. Ask questions here (*)For instance, my tutor majors on teaching programming per se rather than Python specifically. It uses 3 languages to reinforce the common concepts. Other tutorials are much more focused on Pythonb itself, maybe with a partiucular style of programming in mind... I should be able to print it in small chunks Each topic in mine is a separate html file, or you can get the PDF version (although it tends to be updated less often than the main text). If you do print it all out it now comes to around 400 pages! Finally, I should add that I am happy to purchase a book if necessary. You should never say that to an author, but my tutorial is available in dead tree format too (and as such is Python specific). HTH, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Whois
Hello. I am trying to write a module that lets me check whois-info of ip-adresses: import socket class whois: pass def ip(self, adresse): self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.s.connect(('whois.ripe.net', 43)) #self.s.connect(('whois.norid.no', 43)) self.s.send(%s \n\n % adresse) self.data = self.s.recv(8196) self.page = '' self.page = self.page + self.data return self.page If I run the module I get the following: import whois from whois import * n = whois() n.ip('193.12.32.16') '% This is the RIPE Whois query server #2.\n% The objects are in RPSL format.\n%\n% Note: the default output of the RIPE Whois server\n% is changed. Your tools may need to be adjusted. See\n% http://www.ripe.net/db/news/abuse-proposal-20050331.html\n% for more details.\n%\n% Rights restricted by copyright.\n% See http://www.ripe.net/db/copyright.html\n\n' This is just the first part of the whois-info. However, if I don't write it into a function: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('whois.ripe.net', 43)) s.send(%s \n\n % '193.12.32.16') 15 data = s.recv(8196) page = '' page = page + data page '% This is the RIPE Whois query server #2.\n% The objects are in RPSL format.\n%\n% Note: the default output of the RIPE Whois server\n% is changed. Your tools may need to be adjusted. See\n% http://www.ripe.net/db/news/abuse-proposal-20050331.html\n% for more details.\n%\n% Rights restricted by copyright.\n% See http://www.ripe.net/db/copyright.html\n\n% Note: This output has been filtered.\n% To receive output for a database update, use the -B flag\n\n% Information related to \'193.12.32.0 - 193.12.39.255\'\n\ninetnum: 193.12.32.0 - 193.12.39.255\nnetname: SE-CLAVISTER-NET\ndescr:Clavister AB/\xd6vikshem KabelTV\n tidigare Enternet Sweden AB\n \xd6rnsk\xf6ldsvik\n \n In case of improper use, please mail\n [EMAIL PROTECTED] or [EMAIL PROTECTED] so forth. Now I get everything, not only the first part as I did above. Why? And what should I do with the module in order to get all the info? Thanks in advance. -- This email has been scanned for viruses spam by Decna as - www.decna.no Denne e-posten er sjekket for virus spam av Decna as - www.decna.no ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] while loop for satisfing two conditions , advice requested
Hi I am trying to use while loop , here I want while loop to check for two conditions , I am not getting an idea how to use while loop for checking two conditions I used condition , but it is not giving me the expected results I used in this way while (condition no 1) (condition no2): print Results I request guidance Thanks Joseph John ___ NEW Yahoo! Cars - sell your car and browse thousands of new and used cars online! http://uk.cars.yahoo.com/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] while loop for satisfing two conditions , advice requested
Hi while (condition no 1) (condition no2): print Results While (condition no 1) and (condition no2): print Results in python you use the words and, or, not, is like: if myvar1 is not None and myvar2 == '1': print 'what a nice snowing day!' Carlo what is ITER? www.iter.org ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] while loop for satisfing two conditions ,
From: John Joseph [EMAIL PROTECTED] I am trying to use while loop , here I want while loop to check for two conditions , I am not getting an idea how to use while loop for checking two conditions I used condition , but it is not giving me the expected results I used in this way while (condition no 1) (condition no2): print Results Use 'and' instead of . is a bitwise logical AND - it operates on the individual bits of its arguments. 'and' treats the full operand as a logical value. The results can be different: [1] [2] Traceback (most recent call last): File stdin, line 1, in ? TypeError: unsupported operand type(s) for : 'list' and 'list' [1] and [2] [2] 2 1 0 2 and 1 1 Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Whois
Øyvind wrote: Hello. I am trying to write a module that lets me check whois-info of ip-adresses: import socket class whois: pass def ip(self, adresse): self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.s.connect(('whois.ripe.net', 43)) #self.s.connect(('whois.norid.no', 43)) self.s.send(%s \n\n % adresse) self.data = self.s.recv(8196) self.page = '' self.page = self.page + self.data return self.page If I run the module I get the following: snip This is just the first part of the whois-info. However, if I don't write it into a function: snip Now I get everything, not only the first part as I did above. Why? And what should I do with the module in order to get all the info? You need to put socket.recv() into a loop in your program. recv() returns whatever data is available when you call it, or it blocks until more data is available. When you run interactively, there is enough of a delay between commands that the whole reply is received. When you run as a program you only get the first part. Try something like this: page = '' while True: data = s.recv(8196) if not data: break # data will be empty when the socket is closed page = page + data return page Note I have omitted the self qualifier - in the code you show, there is no benefit to making it a class, you might as well make ip() into a top-level function in your whois module. I would give it a more descriptive name as well... This essay gives some reasons why you might want to use classes; none of them apply in this case: http://www.pycs.net/users/323/stories/15.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] while loop for satisfing two conditions , advice requested
in understanding while loop someone should understand if conditional first.In If conditional there are common relational symbol and and orLet's discuss and conditional Condition 1 Condition 2 ResultTrue True TrueTrue False FalseFalse True False False False FalseIn short, and equal True if and only if both condition are true.If the while loop result condition is true it will execute its block. example:x = 1y = 1while x==1 and y==1: # it will be processed if x==1 and y==1 are both true, in this case it is!another example:x=1y=2while x==1 and y==1: # it will be processed if x==1 and y==1 are both true, in this case it is not! Hope this help!pujoOn 1/15/06, John Joseph [EMAIL PROTECTED] wrote: Hi I am trying to use "while" loop, here I wantwhile loop to check for two conditions , Iam notgetting an ideahow to use "while" loop forcheckingtwo conditionsIused condition , but it is not giving me the expected resultsI used in this way while (condition no 1) (condition no2):print "Results" I request guidanceThanks Joseph John___NEW Yahoo! Cars - sell your car and browse thousands of new and used cars online! http://uk.cars.yahoo.com/___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] PAMIE but for linux
On Sun, 2006-01-15 at 00:44 -0200, Ismael Garrido wrote: Hi Is there anything like PAMIE but for a linux browser? Even better if it works in windows and linux. PAMIE lets you control Internet Explorer programmatically. I've read about PyXPCOM (for mozilla) but I coudn't find any docs or reference to using it to alter a document (like, clicking buttons, analyzing and rewriting the DOM, etc). Also, I've seen a wxMozilla proyect, but it is in early stages of development. Does it run any site mozilla runs (IE: handling scripting, CSS)? Does it run on linux? Thanks Ismael This is not exactly what you want. There's a web browser for GNOME (the default web browser as a matter of fact) called Epiphany¹. Epiphany have a lot of _extensions_ that expands it's functionality, one of those is the Python Console² which allow some interaction between Python and Epiphany. Hope you find it useful. Ziyad. Links: 1. http://www.gnome.org/projects/epiphany/ (click on Epiphany Extensions down on the page.) 2. http://www.adamhooper.com:4242/epiphany-extensions/python-console.xhtml ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Design suggestion - is a cookie the answer?
On 1/15/06, Simon Gerber [EMAIL PROTECTED] wrote: I'd recommend using client side JavaScript for this. Create a submit function in JavaScript that will only actually submit the form if all the questions have been completed. I'm sure this is implied in Alan's post, but I'm going to point it out anyway as it's not always obvious if you're just starting to learn Javascript. To avoid further cheating you might want to sure there is no way to submit the form without javascript turned on. E.g. Don't have a submit button and a form with an 'onSubmit' validation. Which some examples do use. Otherwise, they can just turn off Javascript support in their browser and bypass your validation. Instead, have a plain old form button that uses the 'onClick' event to call a validation function, which also submits the form itself if everything works. Cheers, Thanks Alan and Simon. I must admit, I've been avoiding Javascript, but if this is the best way of doing it, then so be it. Will the URL intervene in just presenting a URL to the browser? One of the 'cheats' was just putting the cursor within the URL bar and then pressing enter. Does Javascript pick this up as well? Many thanks again, Adam -- http://www.monkeez.org PGP key: 0x7111B833 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] setuptools question
Hi, I'm not sure where's the best place to ask so I thought I'd try it here. I've got python2.3 and python2.4 installed on my machine and I'm trying to upgrade setuptools for both versions of python. So I've got no problems upgrading setuptools for python2.3 but when I try to do the same for python2.4, I get : Traceback (most recent call last): File easy_install, line 7, in ? sys.exit( File /usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py, line 236, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File /usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py, line 229, in get_distribution if isinstance(dist,Requirement): dist = get_provider(dist) File /usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py, line 115, in get_provider return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0] File /usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg/pkg_resources.py, line 382, in find raise VersionConflict(dist,req) # XXX add more info pkg_resources.VersionConflict: (setuptools 0.6a5 (/usr/lib/python2.4/site-packages/setuptools-0.6a5-py2.4.egg), Requirement.parse('setuptools==0.6a9')) and I'm not sure what's the best way to fix it. Suggestions please! Thanks, Shuying ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Design suggestion - is a cookie the answer?
I'm sure this is implied in Alan's post, but I'm going to point it out ... To avoid further cheating you might want to sure there is no way to submit the form without javascript turned on. E.g. Don't have a submit button and a form with an 'onSubmit' validation. Which some examples do use. Otherwise, they can just turn off Javascript support in their browser and bypass your validation. Nope that wasn't implied in my post. I confess I just rely on JavaScript being there. But your point is a good one! way of doing it, then so be it. Will the URL intervene in just presenting a URL to the browser? The onValidate technique just does a check before sending and if it returns false doesn't send. The onClick method actually requires you to explicitly submit the form to the URL, that's why it's more secure. One of the 'cheats' was just putting the cursor within the URL bar and then pressing enter. Does Javascript pick this up as well? No. JavaScript is an event driven paradigm and it only picks up the explicit events you register with it(*). One of the problems of using CGI is the ese of frigging it. I assume you are using GET instead of POST? GET is the default submission method but POST is nearly always better and should avoid the problem here. (I think, I haven't tried it!) (*)Not really true it will execute any inline code too. But it won't trigger to events that have not been registered, like a direct address refresh. On the subject of JavaScript being the *right* solution it ois of course only one way to do it. You could add code in your CGI that simply checks that all answers are filled in before responding, but that means a longer delay in response. In general where you want to validate that a form has been filled in its a better user experience to do it in the browser and that means JavaScript. HTH, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor