[Tutor] Functions output
Dear all, Here are two functions printme and change quite spaced apart. When executed the output in bold are joined. What can I do so that the results are separate in two blocks? #Function definition is here def printme(str): "This prints a passed string into this function" print str return #Now you can call printme function printme("I'm first call to user defined function!") printme("Again second call to the same function") #Function definition is here def changeme(mylist): "THIS CHANGES A PASSED LIST INTO THIS FUNCTION" mylist.append([1, 2,3,4]) return " now you can call the changme function" mylist=[10, 20, 30] print "valuse outside the function:", mylist print "values inside this function:", mylist >>> I'm first call to user defined function! Again second call to the same function valuse outside the function: [10, 20, 30] values inside this function: [10, 20, 30] >>> Regards, Henry ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] importance of Docstring
Le Thu, 16 Apr 2009 12:02:21 +0200, "A.T.Hofkamp" s'exprima ainsi: > Now what does this function do? > This is a 'what' question, namely, from a design point of view, if I call > this function, what does it do, and what is its result-value? > What I miss is a good place for "why?". Which, when needed, is different from "what?" and "how?". Why tells about the reason-to-be: why did I (need to) write the following piece of code? Not always needed (while what is nearly always needed), though, but really helpful in this case. Denis -- la vita e estrany ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Functions output
On Fri, Apr 17, 2009 at 4:42 AM, mbikinyi brat wrote: > Dear all, > Here are two functions printme and change quite spaced apart. When executed > the output in bold are joined. What can I do so that the results are > separate in two blocks? The format of the output depends only on the contents of the print statements, not on the arrangement of the code. You can print a blank line with a plain print statement or by including a newline '\n' in your output like this: print 'This is the first line\nThis is the second line' Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Functions output
mbikinyi brat wrote: Dear all, Here are two functions printme and change quite spaced apart. When executed the output in bold are joined. What can I do so that the results are separate in two blocks? ? #Function definition is here def printme(str): ??? "This prints a passed string into this function" ??? print str ??? return #Now you can call printme function printme("I'm first call to user defined function!") printme("Again second call to the same function") ? ? #Function definition is here def changeme(mylist): ??? "THIS CHANGES A PASSED LIST INTO THIS FUNCTION" ??? mylist.append([1, 2,3,4]) ??? ??? return " now you can call the changme function" mylist=[10, 20, 30] print "valuse outside the function:", mylist print "values inside this function:", mylist ? ? ? I'm first call to user defined function! Again second call to the same function valuse outside the function: [10, 20, 30] values inside this function: [10, 20, 30] Regards, Henry I can't see "bold," in a text email. But presuming you're wondering why the two output lines are deferred: starting "I'm first..." and "Again second..." I wonder as well. When I try to replicate your situation, I'm starting python.exe at the XP Windows command prompt. It starts like this: M:\>c:\ProgFiles\Python26\python.exe Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 What does yours say? Anyway when I type exactly what you did, I get several errors. So I suspect your transcript isn't faithful. You really should copy&paste from the console to the message. So I add indentation, and blank lines as appropriate, and as expected, I see each of those two lines echoes immediately after the corresponding call to printme(). I suspect you're doing this inside some shell tool, perhaps in some IDE, not at the command prompt. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Sending a disconnect after openssl s_client command?
Tutors, I'm working on a script to verify whether a particular website supports SSLv2 via the following: --- BEGIN --- #!/usr/bin/python import os, re checkssl_out = open('checkssl.txt','w') website = 'somewebsitename' sslv2 = 'Protocol : SSLv2' print 'Checking:', website checksslv2 = os.popen('openssl s_client -ssl2 -connect somewebsitename:443').read().strip() if re.search(sslv2, checksslv2) == None: print >> checkssl_out, website, 'does NOT support SSLv2' else: print >> checkssl_out, website, 'supports: SSLv2' checkssl_out.close() --- END --- It works, but the problem is that OpenSSL does not automatically disconnect after end of input. I was curious if there's a way to send a CTRL-C at the end of the command, so that it *does* capture the output, and breaks after it. Any suggestions or help is appreciated! K ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] importance of Docstring
"spir" wrote Now what does this function do? This is a 'what' question, namely, from a design point of view, if I call this function, what does it do, and what is its result-value? What I miss is a good place for "why?". Which, when needed, is different from "what?" and "how?". Why tells about the reason-to-be: I always argue that comments should be for why(the code is written this way. what (do I do with this) should be the docstring how (the code works) should be self evident from clearly written code at the function lebel or in a design document for the bigger application level how! Those are my personal rules of thumb. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Functions output
"mbikinyi brat" wrote Here are two functions printme and change quite spaced apart. The spacing of the functions inside the source file has nothing to do with the output. Python reads the input file, ignores any spacing and executes any lines it recognises as code. When executed the output in bold are joined. What can I do so that the results are separate in two blocks? If you want to separatye the output you need to insert some space. You are in complete control, the computer is not intelligent enough to deduce that you want the two outputs separated. You need to tell it to print some empty space. One way to do that is by printing newline charactrs('\n') To print 5 newlines you can do this: print '\n' * 5 #Now you can call printme function printme("I'm first call to user defined function!") printme("Again second call to the same function") add print '\n' * 3 here #Function definition is here def changeme(mylist): print "valuse outside the function:", mylist print "values inside this function:", mylist Should result in: I'm first call to user defined function! Again second call to the same function valuse outside the function: [10, 20, 30] values inside this function: [10, 20, 30] HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python and Semantic web
___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Protege and python
___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor