Nick I can't grab your email from the to field can you drop me a line in email I have something off list I would like to ask you. kperry@xxxxxxxxxxxxx Ken -----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Nick Stockton Sent: Sunday, December 07, 2008 2:46 PM To: programmingblind@xxxxxxxxxxxxx Subject: python examples $ # Lets run the python interpreter. $ python Python 2.5.2 (r252:60911, Nov 14 2008, 19:46:32) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>># To join a line you use the ';' character. >>> print "Hello world!";print "My name is Nick." Hello world! My name is Nick. >>># To split an expression over multiple lines you use the '\' character. >>> sum\ ... =\ ... 1\ ... +\ ... 2 >>> print \ ... sum 3 >>># As a side note, I could have just typed 'print 1+2' and gotten 3. >>> quit() $ # Now for a final example I will use python to print the title on the google home page. $ # There are several ways I could have done this but I chose to use the BeautifulSoup module. $ # Here is the code. $ cat print_google_site_title.py import urllib from BeautifulSoup import BeautifulSoup data = BeautifulSoup(urllib.urlopen("http://www.google.com";)) print data.title.string $ # Now I will run the code to make sure it works. $ python print_google_site_title.py Google $ Nick Stockton ----- Original Message ----- From: "Octavian Rasnita" <orasnita@xxxxxxxxx> To: <programmingblind@xxxxxxxxxxxxx> Sent: Sunday, December 07, 2008 12:41 PM Subject: Re: ewby on programming need some tips and tricks > From: "Nick Stockton" <nstockton@xxxxxxxxx> >> """ >> In perl you can write the entire program in a single line. You can even >> write the program in the command line. Can you do that with python? >> """ >> >> Yes you can do boath with python. > > Can you give an example? > Here is a very simple example of a command line that downloads the first > page of Google and prints the title of that page: > > perl -MLWP::Simple -e "$p=get('http://www.google.com/'); > ($t)=$p=~/<title>(.+?)<\/title>/gsi; print $t;" > > It would be very interesting, especially for those who like python to see > how it could be done with python, and I would be also very interested, > because it could convince me easier that python has real advantages. > >> You asked: >> """ >> In perl you can split an expression on more lines and it will work. Can >> you do the same thing with python? >> """ >> >> yes you can do that with python. > > Can you give an example? > > Here is a simple math operation that is easy to understand in perl, of > course very exagerated to see how flexible are some languages: > > my > $ > variable > = > 1 > + > 2 > ; > > print > $ > variable > ; > > This will print of course "3". > >> >> You stated: >> """ >> In perl you can indent the code with more or less spaces, whatever you >> like, or you can not indent the code at all. But you can't do that with >> python. >> """ >> >> in python you can indent the code with more or less spaces as well even >> just one space as long as you indent. I tend to use four spaces as for >> me, anything more is to many and anything less is to few. > > I think you didn't understand what I said. > In python you should keep a consistent indenting and if you indent a line > with a space, you should indent all other lines in the same block with a > space, because if it happends to indent them with 2 or more spaces, the > program won't be very happy. > >> Also in another message you asked: >> """ >> If python wouldn't have this issue of indentation, it wouldn't need >> workarounds for making it a little bit friendlier. >> So I don't understand what you don't like when I said that python is less >> friendly for the blind than other languages. >> """ >> >> Because most languages and programs in general for that matter to one >> extent or another can be a little unfriendly and require workarounds. I >> mentioned visual studio in my last message. Do you think it would be >> very >> accessible with out the screen reader scripts for it? The screen reader >> scripts and learning all the hotkeys for them are probably even bigger >> workarounds then adding a couple commented braces in python code. I >> don't >> use VS so someone else will have to confirm that but I do define screen >> reader scripts as > > Yes of course you are right. That's one of the reasons I don't use Visual > Studio too much. :-) > >> workarounds. Now lets say you use the console to compile and you get >> some >> output that scrolls off the screen. As far as I know it's quite hard for >> a blind user to use the cmd scrollback buffer and so What do you do? You >> pipe the output to a text file and read it with a text editor or pipe it >> directly to a program for reading even though it might be a bit >> inconvenient to do. Pipes are workarounds too. > > Yes pipes are workarounds too, because you need to make an effort each > time > you need to do the pipes. > But I have defined a shortcut in TextPad to run a certain program with the > current program as a parameter, so if I want to compile the program I am > currently developing, I just press the hot key I defined, then press > enter, > or I could also add some command line parameters before pressing enter. > But this is not special to perl or other languages, because I can use the > same technique with python, or ruby, or C#, or Java... > > And the result from STDERR or STDOUT will be printed as another common > document window, which would be very accessible no matter if it has 3 > lines or 100 MB. > > Octavian > > __________ > View the list's information and change your settings at > //www.freelists.org/list/programmingblind > > > __________ Information from ESET Smart Security, version of virus > signature database 3668 (20081206) __________ > > The message was checked by ESET Smart Security. > > http://www.eset.com > > > __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind