Python syntax

Golly! I forgot that I still had that on my website. I do not think I have had any links to it since Lua became my scripting language of choice, at least a decade ago.
--
Gavin Wraith (gavin@wra1th.plus.com) 
Home page: http://www.wra1th.plus.com/
Reply to
Gavin Wraith
Loading thread data ...
I think these days we have enough ways to transfer text files without modification that this should not be a problem. C source fed through such a system is often (not always!) still syntactically correct, but still it is unusable except for an obfuscated C contest.
Tabstops that are not at 8-character positions are much more of a nuisance.
Reply to
Rob
Why? If ssh is working, then scp and sftp will also work for transferring files between the two computers. For the OP: scp is used to copy files to a specific directory, sftp has similar capabilities to ftp.
Some graphical ftp clients can also talk to the sshd server using the sftp file transfer protocol. I do it all the time with gftp.
--
martin@   | Martin Gregorie 
gregorie. | Essex, UK 
 Click to see the full signature
Reply to
Martin Gregorie
I could cheerfully shoot whoever managed to get 8 character tabs accepted as a default standard: its far too wide for use in block structured programming. Three or four spaces is a much more sensible width.
However, that's easily fixed: any decent editor will allow you to associate a tab width, an auto-indentation switch and the ability to replace tabs with the file extension. Find and learn to use an editor that can do this and most of your indentation problems just vanish.
My editor of choice for Linux, Unices, OS-9 and DOS is MicroEmacs and used to be PFE for Windows. PFE is, I think, still around but I don't know if it runs on anything later than XP.
--
martin@   | Martin Gregorie 
gregorie. | Essex, UK 
 Click to see the full signature
Reply to
Martin Gregorie
I recommend Nettle as an SSH client for the Iyonix.
formatting link

One other thing that has been alluded to but not spelt out. Python is whitespace-sensitive. That means that the number of spaces, tabs etc matters. It also means that replacing a tab with (say) 8 spaces changes the meaning of the program. So, when entering a program, you have to count the number of spaces at the beginning of each line to make sure they're correct.
In your example you had:
try: something() except KeyboardInterrupt: print 'it broke'
The spaces before 'something()' (a nonexistent function I made up, I forget what the code originally was) and 'print' are critical. If you don't have them right, it won't work. Two spaces is fine, but if you had another level of indent that would then need three (or more) spaces.
So you'd have something like:
try: something except KeyboardInterrupt: print 'it broke' if (x=4): y=5 for i=range(0,4): print 'sorry'
each colon means 'the next line will be indented'. The indent means 'this is a block' (for example, 'print it broke', 'for' and 'print sorry') are all part of the 'except KeyboardInterrupt' block. A block is terminated when the amount of indent becomes less than that of the start of the block. If you indent more you start a new block within the current one. So the for loop will only be executed when x=4 because it's part of the if (x=4) block. If a space were deleted before the 'for' and 'print sorry' they would execute whatever value of x.
This can be a bit of a nightmare if you're copying programs (eg from a book) because you can never tell what's a space or what's a tab. And if the font is not monospaced it's very hard to count spaces.
Theo
Reply to
Theo Markettos
LOL, you must be younger than 55 !!
8-char positions came from the typewriter, have you seen pictures of those in history books ? ;-)
The need of "modern" computing does not negate the history of what came before.
Yea, we all have to live with it.
h
Reply to
hamilton
In a mad moment - Theo Markettos mumbled :
[snip]
Thanks theo! I have been trying to follow this thread and ended more and more confused.com
Your simple and clear explanation has covered all my misunderstanding.
--

|)ryn [vans            mail to - BrynEvans@bryork.freeuk.com
Reply to
Bryn Evans
Ah. The one with the baby Jesus? Divinely inspired..
--
Ineptocracy 

(in-ep-toc?-ra-cy) ? a system of government where the least capable to  
 Click to see the full signature
Reply to
The Natural Philosopher
I dont think so.
I clearly remember SETTING the tab stops on manual typewriters. TO a one character resolution.
And most competent typists did the same depending on what they were typing.
--
Ineptocracy 

(in-ep-toc?-ra-cy) ? a system of government where the least capable to  
 Click to see the full signature
Reply to
The Natural Philosopher
I never said you should indent your code by one tabstop a block. But I do think that you should never set the tabstops for the ASCII TAB character to something else than 8 character intervals.
E.g. in "vi" you specify a "shiftwidth" that you set equal to your code block indent, e.g. 4 :set sw=4
Then you can indent your code using Ctrl-T, Ctrl-D and/or :set autoindent, and it will automatically insert as many tabs as possible and some spaces to make up the difference. "shiftwidth" can be 2 or 3 just as well.
You use the vi commands < and > to change the indentation level of a block, using movement operators like % or } to denote the end of the block.
It *is* possible to set the tabstop size in vi (:set ts=) but one should never do that, IMHO.
Right.
Reply to
Rob
Thankyou Theo. As said by another poster that is a lucid explanation covering points of significance of which I was not aware despite a lot of reading. I have got the program that was giving me trouble working, except for one point concerning 'pass'. I am sure I will sort that soon now.
Changes I made was to use 4 space indents using a different editor; and properly identifying the version of Python. And more strictly sticking to line spacing.
Thanks to everyone for the help and info given. Now back to the pi.
Malcolm
--
T M Smith 
Using an Iyonix and RISC OS 5.20 in the North Riding of Yorkshire
Reply to
T M Smith
On Tue, 03 Jun 2014 15:20:08 +0100, Gavin Wraith declaimed the following:
It's called a proper SMTP/NNTP compliant client and server
So.. No Google Groups, no web-mail, and probably no Outlook...
--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/
Reply to
Dennis Lee Bieber
On Tue, 03 Jun 2014 12:07:20 -0600, hamilton declaimed the following:
Not on any typewriter I ever encountered. Tab(ulation) stops were mechanical pins that had to be set "out" for every desired stop position -- the typical typewriter would thereby have between 80 and 130+ individual pins (depending upon width of platen and character pitch).
There were no fixed/automatic "8-space" tab stops. If no stops were set, pressing the tab key would have the platen glide all the way to the end.
The first place I encountered 8-space tabs were Hazeltine 1200/2000 terminals (late 70s; as those are what my college terminal room used). VT-52/100/+++ also defaulted to 8-space tabs.
--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/
Reply to
Dennis Lee Bieber
When I was in high school (1960s) all typewriters were set for 5 or 8 char tab stops.
Why, I did not know at the time.
formatting link

"A common horizontal tab size of eight characters evolved, despite five characters being half an inch and the typical paragraph indentation of the time, because as a power of two it was easier to calculate in binary for the limited digital electronics available."
I doubt my 8th grade typing teacher know powers of two, but I remember 5 or 8.
Go Figure.
Reply to
hamilton
The "teletype" hardcopy terminals that predated those video terminals also had 8-space tabstops. On those machines they were not adjustable at all. In certain models of video terminal maybe they were (using some escape sequence), but the default still was 8 positions.
Reply to
Rob
They were already at 8 positions on the mechanical teletype terminals, that had no limited digital electronics but only mechanical gears.
Reply to
Rob
AFAIK 8-char tabs are not any kind of universal standard. That just happens to be what some popular programs use. There are other widths out there.
The real lesson, IMO, is to either use all tabs or all spaces when indenting code in Python.
Some editors automatically convert runs of spaces to tabs. That's a real bad idea for Python programming. IME the best option is to use a plain editor which does not play any games with tabs and to indent with just spaces. On Windows, plain old Notepad is absolutely fine. If word wrapping is turned off (Format menu) then control-g will allow you to jump to a line by number which can be handy when a compiler or interpreter reports the line numbers of errors.
On Unix there are many editors that behave properly. I use vi but there are lots of others.
Yes, though if having to type spaces to indent each line two spaces per indent can be enough.
I would suggest to the OP to go the other way: use the simplest editor you can find and one that is widely available. Especially as he is starting out with Python there's a lot to be said for plain simple text editing. Keeping it simple and using plain old text and spaces just works.
James
Reply to
James Harris
all the mechanical typewriters I've used had user-programmable tab stops there was like 80 little metal pins that could be individually raised or lowered by the tab-setting lever and the tab button would scoot to the next raised stop,
--
umop apisdn
Reply to
Jasen Betts
The first formal course I ever did on programming was taught in Ada - and I've always thought that did me more good than C/C++/Java etc would have done me.
I haven't used Ada in anger since 1997, and have probably forgotten enough that I'd have to effectively learn it from scratch - but I do have fond memories of it as a teaching language.
-Paul
--
http://paulseward.com
Reply to
Little Paul
And so has every card punch I've seen - including the old 12 key hand punches. For PLAN (ICL assembler) you needed tabs at columns 7,12,14,40 and 72 IIRC: that's scarcely every 8 characters!
Flexowriters, which I used for Elliott 503 Algol programming, definitely had tab stops though I don't know how they were set - probably every 5 character positions since that would suit Algol's begin...end block structure rather well.
I don't remember whether teletypes had tab stops or how they were set: we used KSR33 teletypes as terminals and the operator's console on ICL 1900s. Anyone?
--
martin@   | Martin Gregorie 
gregorie. | Essex, UK 
 Click to see the full signature
Reply to
Martin Gregorie

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.