Python syntax

You only have to add brackets to the print statements to make that particular piece of code work in both Python 2 and Python 3.

I think it's time to take a step back and ask why getting _six_ lines of code entered correctly has been such an uphill task for you, taking several days, and you're _still_ not there yet. There's nothing wrong with the "try:" statement, and if it's entered correctly, it will be fine.

I applaud attempts to learn programming but if you're having this much trouble to even take the first step, then you have to start considering what's wrong with your approach and the programming environment that you're using. For example, not even being able to cut-and-paste is like having a hand tied behind your back.

Point1. Are you testing your initial attempts at writing Python on a Raspberry Pi or on your main computer? _Is_ a Raspberry Pi your main computer? You'd be better off taking the first steps on the same machine that you're reading these newsgroups with. And do figure out how to cut-and-paste at least.

Point2. Given that most Python examples on the web are Python2 and most users seem to be putting off updating to Python3 until the associated tools have caught up, you'd be very much better off starting with Python2. If you're hoping to get support from web-users, then that's the version of Python that gets the support. There's not that many differences with Python3, so it shouldn't be difficult to update later when the time is right.

Point3. Which OS are you using on the Pi? RISCOS? Again, that's not the one to go for if you want support. Not many people here use it. In fact, I'd only recommend it to people that used it during the 1980s and already know exactly what they're doing with it. _Raspbian_ is the one to use if you want support. Raspbian might be a little bit more fiddly to set up, to boot into the desktop automatically, and to figure out how to install software from the Raspbian repositories (using the Synaptic app). But Raspbian is a modern Linux distro with plenty of web support with web tutorials and videos.

Point4. If you get the above sorted out, you should find it easier to ask questions because you can run Python code from the command line and cut-and-paste the exact error report into a forum post.

For example, if I have a file containing the work "try:", but say I forgot to add the colon on the end, then if I ran it from the command line, I'd get an error. I'll do that now and cut-and-paste the result.

[dsf: /work/tmp]$ echo "try" >test.py # that creates the one liner [dsf: /work/tmp]$ chmod a+x test.py # that adds the execute flag [dsf: /work/tmp]$ python test.py # now i run it File "test.py", line 1 try ^ SyntaxError: invalid syntax [dsf: /work/tmp]$

See? Easy. That's what you should be trying to do now: making it easier for yourself.

Reply to
Dave Farrance
Loading thread data ...

Thanks

Thanks for being so patient and helpful though I sense you are now becoming somewhat irritated for which I am sorry.

I was given the Pi so it was set up when I got it. I bought a book 'Raspberry Pi for beginners(updated to 2014)' and I am working my way through the book. I upgraded to the latest Rasbian distro and do my programming using that on the Pi. I do my emailing on my Iyonix but nothing else to do with the Pi. My Pi programming is being done on the Pi.

I am not sure whether a rasbian equivalent is available for the Iyonix.

You are probably right in this.

Rasbian (Linux) is the one I am using

Yes that does seem easy. I will look into. Thankyou for your considered advice; this is my first contact with linux and the Pi and it shows.

Malcolm

--
T M Smith 
Using an Iyonix and RISC OS 5.20 in the North Riding of Yorkshire
Reply to
T M Smith

Agree to all above

But if you run it like python test.py instead of ./test.py I do not understand why you make it executable (chmod()ing)

Reply to
Björn Lundin

Good point. I decided not to put a hashbang in the file there and forgot to leave out the chmod as unnecessary.

Reply to
Dave Farrance

And presumably you'd want to keep your Usenet newsgroup access on the same machine as your email. OK, if you get past the initial hurdle, then maybe working from the book will be fine and you won't need interconnection between your email/usenet/web machine and the Pi. The problems with that do start if you need to ask for help on the web, though.

Reply to
Dave Farrance

Yes I understand that.But I had not quite expected the steep initial learning curve I am on. Still I feel fairly sure I will make progress, it is only this try - effect problem that has me puzzled but still working on it.

Malcolm

--
T M Smith 
Using an Iyonix and RISC OS 5.20 in the North Riding of Yorkshire
Reply to
T M Smith

Many Pi users just hook it up to their network and use an ssh client on their main workstation to log on to it. Then they can cut-and-paste material they find on the web or newsgroups into a program running on the Pi.

Reply to
Rob

Thanks Rob I will follow up on this

Malcolm

--
T M Smith 
Using an Iyonix and RISC OS 5.20 in the North Riding of Yorkshire
Reply to
T M Smith

Python does seem to have a "different" syntax to other languages. Most of my previous programing has been in Pascal (ages ago), Perl, PHP and recently (since I got a couple of Pi's) a little bit of bash.

Python appears to use what I would term code layout, ie blank lines and/or indents, to define code blocks and such like, something a little alien to me. There doesn't appear to be any closure symbols or keywords like } or esac etc that other languages have.

Seems almost as if the book you have has assumed that the reader already knows that line breaks and indents are significant in python. Bad assumption. B-)

Well done for sticking with it. I think a great many people would have consigned their Pi to the back of the kitchen drawer by now. Presumably your Pi has keyboard mouse and monitor attached, to help with the cut 'n paste you could use the GUI and the browser supplied for webmail reading forums etc. Personally I ssh in over the LAN but then one of my Pi's is working as a media player with XBMC, the other a webcam/time lapse camera in another building.

--
Cheers 
Dave.
Reply to
Dave Liquorice

If you do want to try connecting to the PI, there's ssh'ing to the PI for a terminal, as already mentioned, and you'd also need to remotely mount the Pi filesystem for file operations. That's easy enough for those of us running Debian or Ubuntu because Raspian is a variant of the same OS. Googling "riscos nfs client" and "riscos samba client" does suggest that it's possible at first glance, but it's likely to be a bit tricky.

But googling for "iyonix riscos python" turns up this conversation:

formatting link

and somebody claiming that this Python is suitable:

formatting link

If that does work, then you can learn the basics of Python programming on an environment that you're familiar with.

Reply to
Dave Farrance

I think it is a good idea, because it forces the programmer to neatly format the code in the same layout as it is structured.

In other languages, errors in the block structure can be hidden when the programmer makes a mess of the layout, as some lazy programmers do, or when he simply forgets to add { } when expanding a block from one to two statements.

Of course it helps a lot when you have a good editor. It would be terrible when you need to change the block level of a long block of code when working with a notepad-style editor (everything you type is inserted at the cursor position and no clever editing functions available), but with an editor like "vi" changing the indent of a long block of lines is a breeze.

Reply to
Rob

Only if you need to shift files to/from the Pi. I don't use any "file shareing" to/from my Pi's, SSH in edit/create etc on the Pi's file system normally with Midnight Commander(*). If I do need to shift a file (rare) mc can ftp to the server from the Pi, where I can get at it from the other machine(s).

(*) Excellent text/terminal based dual "window" directory browser with decent built in editor (with sytax highlighting) and all the normal copy/move/symlink/chown/chmod etc facilities.

sudo apt-get install mc

On your pi.

--
Cheers 
Dave.
Reply to
Dave Liquorice

a terminal, as already mentioned, and you'd also need to remotely mount t he Pi filesystem for file operations.

Well, there is actually another way, that is simple enough.

Use an editor, on your favorite desktop, that can do sftp/ssh/scp

I use (on windows) Notepad++ and it has NppFTP plugin that can us sftp.

That is, it uses the ssh daemon on the pi to transfer files (fairly) transparent to the user. No setup, more that a working ssh daemon is needed on the pi.

Together with a ssh windows, you are set, if you don't program graphics.

That os is unheard of in my ears, so I don't no if is has any sftp enabled editors

Reply to
Björn Lundin

Den tisdagen den 3:e juni 2014 kl. 10:09:42 UTC+2 skrev Rob:

That is good. But using python, coding in different editors on different os:es /mac/win/linux with different tab settings, I find that the code sometimes breaks. One editor had tab settings = 4 spaces and another had tab setting s= 2 spaces, while the third was set to convert tabs to spaces... Using svn to keep files in sync, yes I got Indentation errors, where there should be none. So, it is not just good, I think.

c/java/c++ if (a==b) b=c; e=f;

even if indention is correct, the outcome is probably not what the programm er intended, i.e. that e=f is ALWAYS run an not part of the if-branch.

But that is more a flaw of c/java/c++ than anything else. its the dangling else -

This is another reason I manly use Ada for any serious programming. Python's idiom is 'least surprising outcome', but it has surprised me enough to prefer Ada.

But that might trigger a language-war which I do not want. I just wanted to point out that Python's indentation block structure is not always a good thing, in my eyes anyway.

Reply to
Björn Lundin

Agreed. That's one of the things that I disliked with Pascal, that it allowed single-statements in structures in a way that could make the end of a given block unclear if somebody used that. (Same with C.) Pascal's creator, Niklaus Wirth, recognised that as a problem, so he fixed it by creating Modula 2, with Pascal's quirks ironed out. I was disappointed that it never caught on.

So Python looked even less likable at first glance, but I soon found that the strict enforcement of the indenting makes it fine as a visual guide to block structure.

Reply to
Dave Farrance

Developed by Acorn, the ARM developers, in 1987 for the first ARM-based computer, the Acorn Archimedes. It was better than the early versions of Windows apparently, but it didn't catch on because the IBM PC architecture was already entrenched by then. There's people that determinedly hang on to it, saying there's nothing quite so easy to use, but I bet it's showing its age by now.

Reply to
Dave Farrance

Does it ever. More importantly, *so* many unfamiliar quirks for people accustomed to Mac/Win (mainly GUI but also other paradigms). There is of course a distribution for Raspberry Pi, available as one of the options in NOOBS or

formatting link

Reply to
A. Dumas

Den tisdagen den 3:e juni 2014 kl. 13:22:12 UTC+2 skrev A. Dumas:

Ok, that one I've seen mentioned here and at the pi forum, but I never actu ally tried it. My days of trying (for me) new and obscure os:es I think is over. The third last I tried was BeOS that became Haiku. Second last is Linux and latest is OS/X which was in 2005. Who could resist their mac-mini then, wi th a ppc ? I could not...

Funny how people love the underdog. I know that we are a small group of people who defends Ada until the bitter end. I also know that most people n ever heard of it, and those who actually did, dislike it for a number of (mostly invalid) reasons.

I guess it is fun to belong to a group that "knows" they are right, and look down on others, that are not yet "enlighted".

Linux desktop is such a group as well. We know it is best, yet the main bulk of the world turn to Windows or OS/X...

However, with age, I kind of learned that it easier to go with the flow, unless you really "into the cause"

Reply to
Björn Lundin

The linux desktops I've tried all have the same sort of failings as Windows. Presentation Manger under OS/2 is my much prefered desktop enviroment ...

--
Cheers 
Dave.
Reply to
Dave Liquorice

As far as I know Haskell was the first programming language to use indentation for block structure. The drawback with letting blank space have semantic content is that if you send program source as a text file some mail servers may savage it. For that reason Haskell provides an alternative and safer format. Does Python?

--
Gavin Wraith (gavin@wra1th.plus.com) 
Home page: http://www.wra1th.plus.com/
Reply to
Gavin Wraith

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.