Computer Hope

Software => Computer programming => Topic started by: Geek-9pm on January 04, 2014, 07:35:21 PM

Title: Python in One Easy Lesson
Post by: Geek-9pm on January 04, 2014, 07:35:21 PM
Here 'ya go!  ;D
Python in One Easy Lesson (http://www-cs-faculty.stanford.edu/~nick/python-in-one-easy-lesson/)
Quote
By Nick Parlante Nov 2010
This is a one-hour introduction to Python used for Stanford's CS107. This material should work as an introduction for any experienced programmer.
Give me about 12 hours, please.  :-\
Title: Re: Python in One Easy Lesson
Post by: Squashman on January 09, 2014, 08:31:26 AM
I have been going over Snake Wrangling with my kids the last few months when i can pull them away from their electronics.
Title: Re: Python in One Easy Lesson
Post by: DaveLembke on January 09, 2014, 08:16:48 PM
Quote
I have been going over Snake Wrangling with my kids the last few months when i can pull them away from their electronics.

You could control electronics with Python programming and really get them hooked  ;D Animatronics on front lawn etc  :P

http://kmtronic.com/control-kmtronic-usb-relays-the-python-library.html (http://kmtronic.com/control-kmtronic-usb-relays-the-python-library.html)

I have a nut case that lives next house down that is a problem. Her problem is that she is always looking out her window to see what we are up to and calls the cops on us and 911 on the UPS guy who came to deliver a package the one day, she claimed the guy was trying to break in. After she was threatening our 7 yr old daughter with cursing and hand gestures and making actions like she knows kung fu we put up a tall stockade fence and she is annoyed by not having a view of what we are up to. I have been tempted to add moving silhouette's on my lawn with smiley faces that extend just above the fence. This relay control would work perfect for that. BUT fact of the matter is we are moving in a few months and so hopefully the problem goes away with the move!  ::) The last problem I had with her she complained that the lawn mower was too loud. I was fed up and said you want to hear LOUD... Took channel locks to the muffler and removed it and put the throttle to the max and had occasional flashes of flames shooting out the side of the engine block at about 120db vs the 60db of with the muffler on.

I can only hope that no one else here has a nut case neighbor like or worse than this one  >:(
Title: Re: Python in One Easy Lesson
Post by: Geek-9pm on January 09, 2014, 09:26:21 PM
Look here at a device that can be controlled with Python.
(http://kmtronic.com/images/kmtronics/python_usb8relay.jpg)
Yes, Python is a high-level programming toll,yet it can control a low-level device.
The Python library has excellent code for serial devices .
Here are a coupe of  clips showing  the above  controlling relays.
http://kmtronic.com/kmtronic-projects.html (http://kmtronic.com/kmtronic-projects.html)


Title: Re: Python in One Easy Lesson
Post by: briandams on January 09, 2014, 11:44:22 PM
So can Perl. http://search.cpan.org/~cook/Device-SerialPort-1.04/SerialPort.pm
Title: Re: Python in One Easy Lesson
Post by: camerongray on January 10, 2014, 05:07:02 AM
That is what I love with Python - The sheer number of libraries you can easily install and use.

There's nothing really to stop a high level programming language having low level I/O operations, it just doesn't have some of the really low level concepts such as pointers and manual memory management in other languages like C.

Perl is also good for this but I much prefer Python as a language - Perl can get really unreadable and messy very easily due to having a mass of punctuation to do trivial tasks.
Title: Re: Python in One Easy Lesson
Post by: Squashman on January 10, 2014, 06:40:19 AM
So can Perl. http://search.cpan.org/~cook/Device-SerialPort-1.04/SerialPort.pm
Seriously.  Did you post that just to provoke me!  It is a Python thread.  Not perl!!!!!
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 07:40:25 AM
Perl is also good for this but I much prefer Python as a language - Perl can get really unreadable and messy very easily due to having a mass of punctuation to do trivial tasks.

Its the programmer, not the programming language.
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 07:43:26 AM
Seriously.  Did you post that just to provoke me!  It is a Python thread.  Not perl!!!!!
Chill. You are the last person I would think even if there's no one else in this world. What makes you think that you deserve my provocation? I am merely just stating a fact about Perl able to do low level stuff just like Python. Its all about the libraries. So, not just Perl, other languages could also do it, as long as libraries are around! That does not mean I am bashing any language! Just chill will you? This is not dostips ! This is a computer programming forum!
Title: Re: Python in One Easy Lesson
Post by: Squashman on January 10, 2014, 07:48:57 AM
Chill. You are the last person I would think even if there's no one else in this world. What makes you think that you deserve my provocation? I am merely just stating a fact about Perl able to do low level stuff just like Python. Its all about the libraries. So, not just Perl, other languages could also do it, as long as libraries are around! That does not mean I am bashing any language! Just chill will you? This is not dostips ! This is a computer programming forum!
What does the Thread TITLE SAY.

If you want to push your PERL agenda start your own thread.  Telling Cameron "It's the Programmer, not the language" is taking a pot shot at him.

When you start posting off topic stuff in a thread that is consider THREAD HIJACKING.
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 07:52:16 AM
What does the Thread TITLE SAY.
what does the forum say?

Quote
If you want to push you PERL agenda start your own thread.  Telling Cameron "It's the Programmer, not the language" is taking a pot shot at him.
he is entitled to his opinion. that goes the same for me. Even though half of what he say may be true, but if the programmer is disciplined enough, code can be written just as beautifully as well. Obviously, you have not heard of
perlstyle  (http://perldoc.perl.org/perlstyle.html)

Java can do it as well (http://en.wikibooks.org/wiki/Serial_Programming/Serial_Java), so can Ruby (http://ruby-serialport.rubyforge.org/). So, not only Python can do it. And I am just stating a fact. Don't like it? no my problem.
Title: Re: Python in One Easy Lesson
Post by: camerongray on January 10, 2014, 08:02:23 AM
Its the programmer, not the programming language.

Which is why I stated "but I much prefer Python as a language".  I actually use Perl quite a lot at work and Python a lot for my own projects so I have good experience in both.  If anything, I've been using Perl longer than I have used Python!

In some cases your statement is true such as when programmers blame a language instead of their own ability but not when a programmer criticises a language for a legitimate reason such as lacking certain concepts/data structures or having messy/cluttered syntax.
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 08:07:03 AM
When you start posting off topic stuff in a thread that is consider THREAD HIJACKING.
since when does the thread says anything other that Python is prohibited to be discussed? this is not dostips where only DOS can be discussed! don't be so narrow minded.
Title: Re: Python in One Easy Lesson
Post by: camerongray on January 10, 2014, 08:07:49 AM
Quote
Obviously, you have not heard of perlstyle
I certainly have!  If I'm writing from scratch I will strictly follow the style recommendations for whatever I'm using (even if it's not what I prefer myself).  If I'm working on an existing project I will use the same style as used elsewhere in the project.

How can you comment on my style in Perl when you have never seen any of my Perl code?
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 08:10:56 AM
I certainly have!
that's good for you then.
Title: Re: Python in One Easy Lesson
Post by: camerongray on January 10, 2014, 08:13:37 AM
that's good for you then.

I was pointing out that you can't make claims of what I "have never heard of" or take a stab at my abilities because I criticised a language that you like (And I do as well).

You are taking this thread way off topic, not really making a good first impression on this forum.
Title: Re: Python in One Easy Lesson
Post by: Squashman on January 10, 2014, 08:20:30 AM
since when does the thread says anything other that Python is prohibited to be discussed? this is not dostips where only DOS can be discussed! don't be so narrow minded.
That is why you can start another THREAD!!!!!!  If the thread says Python you don't go and start talking about Batch, Perl, AWK or even Baking Bread.  You have no idea about Forum Etiquette!   Now we all have Hijacked this thread.  You can not tell me you have never heard of thread HiJacking with all your great knowledge!
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 08:24:08 AM
I was pointing out that you can't make claims of what I "have never heard of" or take a stab at my abilities
"its the programmer, not the programming  language" is a general comment. Not intended to poke at your abilities. Where in the world did i write in a way that pokes at your abilities?
Title: Re: Python in One Easy Lesson
Post by: Allan on January 10, 2014, 08:27:09 AM
Guys, you need to cut out the bickering and get back on topic. There have been no warnings issued so far - let's keep it that way.  This thread is about Python and I think the OP has the right to request that it stays about Python.
Title: Re: Python in One Easy Lesson
Post by: Quantos on January 10, 2014, 08:28:17 AM
"its the programmer, not the programming  language" is a general comment. Not intended to poke at your abilities. Where in the world did i write in a way that pokes at your abilities?

Grow up.
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 08:29:24 AM
That is why you can start another THREAD!!!!!!  If the thread says Python you don't go and start talking about Batch, Perl, AWK or even Baking Bread.  You have no idea about Forum Etiquette!   Now we all have Hijacked this thread.  You can not tell me you have never heard of thread HiJacking with all your great knowledge!
so what's the deal with this Snake Wrangling? To me, its out of topic as well. What makes it so different to what I commented? I merely just stated a factual comment, not only Python has the capability to do that. It does not mean I advocate one particular language. Are you so dense you can't understand? So I did say Java and Ruby also has libraries to do it. So what? now I have forsaken Perl and jumped ship? Seriously, don't make a mountain out of a molehill.
Title: Re: Python in One Easy Lesson
Post by: camerongray on January 10, 2014, 08:29:44 AM
"its the programmer, not the programming  language" is a general comment. Not intended to poke at your abilities. Where in the world did i write in a way that pokes at your abilities?

Around the bit where you said "its the programmer, not the programming  language" then claimed that I had never heard of the Perl style guide after I commented about my thoughts that Perl isn't as readable as Python.

Quote
so what's the deal with this Snake Wrangling? To me, its out of topic as well.
It was a joke that I found rather amusing.

You may want to drop this now - You have really made a bad first impression on this forum.  Keep threads on topic, as this thread was started about Python, then it should probably stick to Python.
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 08:30:17 AM
Guys, you need to cut out the bickering and get back on topic. There have been no warnings issued so far - let's keep it that way.  This thread is about Python and I think the OP has the right to request that it stays about Python.
I agree. OP, please state that its only for Python and nothing else, not even idle talk, and i will shut up
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 08:31:16 AM
then claimed that I had never heard of the Perl style guide a
that's not directed at you.
Title: Re: Python in One Easy Lesson
Post by: Allan on January 10, 2014, 08:33:01 AM
I agree. OP, please state that its only for Python and nothing else, not even idle talk, and i will shut up

Okay. NOW a warning has been issued. If you don't stop, your posting privileges will be restricted. Last time - let's move on.
Title: Re: Python in One Easy Lesson
Post by: camerongray on January 10, 2014, 08:33:09 AM
In more relevant news, I might try to get Python working with my Arduino.  That relay thing also looks really cool - May get one to play with if I can think of something to use it for (Internet connected Christmas tree maybe :P)
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 08:35:54 AM
This thread is about Python and I think the OP has the right to request that it stays about Python.
you seem to be a fair moderator, so you be the judge. Please see my comment. Is it that a fact that not only Python has this capability? And its a fact, pointed out so that there will not be any misconception. second, the OP does not specifically state its only for Python discussion. Why is everyone my enemy now? A general comment on facts deserves to get shot down?
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 08:37:03 AM
Okay. NOW a warning has been issued. If you don't stop, your posting privileges will be restricted. Last time - let's move on.
why not you tell the rest? why only me.? On 2nd thoughts, you are not that fair as well.
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 08:37:22 AM
Grow up.
same to you
Title: Re: Python in One Easy Lesson
Post by: Allan on January 10, 2014, 08:37:36 AM
Knock it off. Last warning.
Title: Re: Python in One Easy Lesson
Post by: Geek-9pm on January 10, 2014, 08:56:00 AM
Thanks Allen. The post was about somebody who made a real serious effort to teach Python quickly  to programmers that already have some skills.

Older programming tools are very strict about making declarations as to date type and functions. Python belongs to a set of tools that makes the right guess as to what a human wants n do do with code.

The Arduino controller, and other s like it, is programmed mostly in C.  And sometimes in Tiny BASIC or Java.  But for many, the style of a language is not as important as to its libraries. Python has a rich set o libraries and is easy to learn.

EDIT: Relevant to Python and Arduino.
Recent articles about Arduino  and Python

http://makezine.com/projects/arduino-and-python-learn-serial-programming/

http://learn.adafruit.com/arduino-lesson-17-email-sending-movement-detector/installing-python-and-pyserial

http://www.wired.co.uk/news/archive/2013-12/06/micro-python

Title: Re: Python in One Easy Lesson
Post by: Squashman on January 10, 2014, 08:58:18 AM
For those of you who don't know what Snake Wrangling is, here is the link to it.
http://www.briggs.net.nz/snake-wrangling-for-kids.html

It is a FREE E-BOOK that helps teach kids to program in python.  It makes it very fun for them to learn it.  I have my two boys using it.
Title: Re: Python in One Easy Lesson
Post by: BC_Programmer on January 10, 2014, 10:35:46 AM
For those of you who don't know what Snake Wrangling is, here is the link to it.
http://www.briggs.net.nz/snake-wrangling-for-kids.html

It is a FREE E-BOOK that helps teach kids to program in python.  It makes it very fun for them to learn it.  I have my two boys using it.

Perhaps I'm too pedantic but I'd avoid any source that uses Snake metaphors with Python, because the language was not actually named after the animal, but rather Monty Python's flying Circus. Though in retrospect that's a dumb reason not to use a specific source. I guess it's just liable to make me wonder what else they got wrong. On the other hand I imagine retconning the name temporarily makes it more kid-friendly.

One thing nice about Python is that it is actually pretty tricky to make unreadable. You'd have to put effort into it, because readability constraints are part of the syntax (eg. the spacing for control flow).

On the other hand, one weird thing is that the self reference has to be specified explicitly (I guess since the methods don't have modifiers, it's the only way to differentiate a class method from an instance method), and "special" methods like __getitem__ have those funky underscores to flag them as a special function, but because those are usually accessed using something else they don't typically appear except at declaration. (And they have to be tagged somehow).


Quote
second, the OP does not specifically state its only for Python discussion.

Title: About Python
Reply #1: Python.
Reply #2: Python.
Reply #3: Python.
Reply #4: Python.
Reply #5: Perl.

Thread subjects are not a game of Duck, Duck, Goose.

Title: Re: Python in One Easy Lesson
Post by: Squashman on January 10, 2014, 10:54:07 AM
Perhaps I'm too pedantic but I'd avoid any source that uses Snake metaphors with Python, because the language was not actually named after the animal, but rather Monty Python's flying Circus. Though in retrospect that's a dumb reason not to use a specific source. I guess it's just liable to make me wonder what else they got wrong. On the other hand I imagine retconning the name temporarily makes it more kid-friendly.

Page 3 of the book.
Quote
Apart from being a snake, Python is also a programming language. However,
it was not named after a legless reptile; rather it is one of the few programming
languages named after a TV show. Monty Python was a British comedy show
popular during the 1970’s (and still popular now, actually), which you have to be a
certain age to find amusing. Anyone below the age of about. . . let’s say 12. . . will
wonder what all the fuss is all about
Title: Re: Python in One Easy Lesson
Post by: BC_Programmer on January 10, 2014, 11:00:37 AM
Page 3 of the book.

Cool, it was a purposeful/temporary retcon to make it more accessible.
Title: Re: Python in One Easy Lesson
Post by: Geek-9pm on January 10, 2014, 11:27:51 AM
Video about Python. From UK, of course.  ::)
http://www.mirror.co.uk/news/uk-news/monty-python-dance-remix-johnny-2986720
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 06:34:48 PM
One thing nice about Python is that it is actually pretty tricky to make unreadable. You'd have to put effort into it, because readability constraints are part of the syntax (eg. the spacing for control flow).
well, because its object oriented, most often times you can write code like this
Code: [Select]
method1(**args).method2( **args ).somethingelse( **args)
still, it depends on programmer. If he chooses to write something like this
Code: [Select]
f=lambda x="8<:477\02092020162\020\037",y="01001000110100101":reduce(lambda
x,y:x+y,map(lambda y,x:chr(ord(y)*2+x),x,map(int,y)));print f();
or this
Code: [Select]
  print ''.join('%(pre)s%(num)s %(bot)s on the wall, %(nul)s %(bot)s,\n%(tak)s\n' % (lambda c,b:
  {'pre':['','%s %s on the wall.\n\n' % (c,b)][abs(cmp(c,'Ninety-nine'))],
 'num':c, 'nul':c.lower(), 'bot':b,
 'tak':['Go to the store and buy some more... Ninety-nine %s.' % b,'Take one down, pass it around,'][abs(cmp(x,0))]
  })((lambda x,o: [(['Twenty','Thirty','Forty','Fifty',
  'Sixty','Seventy','Eighty','Ninety'][x/10-2]+'-'+o.lower()).replace('-no more',''), o][int(x<20)])(x, ['No more','One','Two',
  'Three','Four','Five','Six','Seven','Eight',
  'Nine','Ten','Eleven','Twelve','Thirteen','Fourteen',
  'Fifteen','Sixteen','Seventeen','Eighteen','Nineteen'][[x,x%10][int(x>=20)]]),'bottle%s of beer' % ['','s'][abs(cmp(x,1))])
  for x in xrange(99,-1,-1))

some of the things that can lead to unread Python code
 - nested lambdas
 - redefine functions by assignment
 - make an single instance of the % operator used for both modulus and string formatting
 - same with +, * for addition, string concatenation, etc.
 - evade indentation enforcement by writing things in recursive pseudo-functional ways
 - do something like foo(bar(), baz()) where bar() redefines foo() and baz()
 - litter the code with numeric and string literals that look like they're doing something (but don't)
 - cause exceptions solely for the purpose of later extracting obscure data from them

Copied from here (http://c2.com/cgi/wiki?ObfuscatedPython)

Python code, can be made unreadable! Its all about the programmer! No one can deny that, not even Quantos.
and not to mention, because languages that doesn't have static typing often make it not easy to understand what variables stand for, unless we have good naming convention. eg myvar_int , myvar_str 

On the other hand, one weird thing is that the self reference has to be specified explicitly (I guess since the methods don't have modifiers, it's the only way to differentiate a class method from an instance method), and "special" methods like __getitem__ have those funky underscores to flag them as a special function, but because those are usually accessed using something else they don't typically appear except at declaration. (And they have to be tagged somehow).
all language have their quirks. What matters is, use their syntax correctly and make it do the job. That's more important than ranting.


Title: About Python
Reply #1: Python.
Reply #2: Python.
Reply #3: Python.
Reply #4: Python.
Reply #5: Perl.

Thread subjects are not a game of Duck, Duck, Goose.
wrong. #2 is game. I didn't post any Perl code , or Java code, or Ruby code, or PHP code. Please, if you want to start this, I am game. The thread just  merely says "Python in one easy lesson". Thread author didn't say anything else with regards to discusson on other languages. Why are all these assumptions made that only Python can be discussed. This is a fact. Don't deny it. If you people don't like my comments, then debate it and refute my points like a knowledgable adult, don't keep giving the excuse that "this thread is only for Python" and only Python can be discussed. FYI, this thread is in a Computer programming forum. Its not in a purely Python forum. And this is also a fact.

What is so hard to understsand that I merely posted a factual comment, that most languages with good RS232 libraries can also do the job ? So difficult to understand that its a general observable, factual comment and you people have to make it sound like a language war.
Title: Re: Python in One Easy Lesson
Post by: Geek-9pm on January 10, 2014, 07:50:30 PM
Quote
most languages with good RS232 libraries can also do the job
That is true. Nowadays a serial library ought  also have other serial standards. USB 2.0 ought to be in the library for applications using embedded devices. I was mildly pressurized that good libraries on now available in Python and other popular computer languages. In the days of my youth I had write code at the lowest level and integrate it into a higher language. 
Title: Re: Python in One Easy Lesson
Post by: briandams on January 10, 2014, 08:13:25 PM
That is true. Nowadays a serial library ought  also have other serial standards. USB 2.0 ought to be in the library for applications using embedded devices. I was mildly pressurized that good libraries on now available in Python and other popular computer languages. In the days of my youth I had write code at the lowest level and integrate it into a higher language.

at last, some decent discussion. Last time there was cheeseshop, now they call it pypi , the "CPAN" of Python.