The first code that should print an expression on more lines doesn't do this, but just prints it in a single line escaping the end of line char with \.
And the second code that in perl is done in the command line, here it needs a full program with more lines. So you were not right when you told that you can write a full program in the command line, without needing to press enter more than once.
Am I right? Octavian----- Original Message ----- From: "Nick Stockton" <nstockton@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx> Sent: Sunday, December 07, 2008 9:45 PM 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\ ... +\ ... 2print \... sum 3$ # 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.# As a side note, I could have just typed 'print 1+2' and gotten 3. quit()$ # 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 tricksFrom: "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 lessfriendly 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. Imentioned visual studio in my last message. Do you think it would be veryaccessible with out the screen reader scripts for it? The screen reader scripts and learning all the hotkeys for them are probably even biggerworkarounds then adding a couple commented braces in python code. I don'tuse VS so someone else will have to confirm that but I do define screen reader scripts asYes 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? Youpipe 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 timeyou need to do the pipes.But I have defined a shortcut in TextPad to run a certain program with thecurrent program as a parameter, so if I want to compile the program I amcurrently 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