Re:Learn Python in minutes
by ufo on Friday June 28, 2013 @08:00PM
(#5960977)
"""-delimited text is not actually a comment. Its a multiline string literal
x = """aaa
bbb"""
And you can also use single quotes if you want.
x = '''aaa'''
The reason this might have been confused with a comment is because triple-quoted strings are often used for documentation strings, a Python feature that gives special meaning to string literals that occur as the first statement in a function or class. Those strings get associated to the function as its documentation and can even be inspected at runtime:
def foo():
"my documentation string"
return 17
print help(foo)
Re:Learn Python in minutes
by xhrpost on Friday June 28, 2013 @03:42PM
(#5959957)
This is exactly what I wanted a few years ago while working on a GAE project. I had never touched Python but I knew programming and just wanted to know what the language had and how in basic terms to use it.
I remember picking up a large book from a store shelf titled something like "Python for Programmers". Thinking, "Oh, this is for people who already know how to program and just want to learn Python". I open the book randomly and start reading it's explanation on what functions are in programming and why they're useful. I sighed and placed the book back on the shelf.
Re:Learn Python in minutes
by chrismorgan on Friday June 28, 2013 @09:51PM
(#5961243)
An error: *args arrive as a tuple, not a list, so the first line that all_the_args(1, 2, a=3, b=4) prints is not:
[1, 2]
but is instead
(1, 2)
The second line of that output also happens to be wrong, because printing a dictionary uses repr() on its keys and values and str.__repr__ normally uses single quotes, so instead of
{"a": 3, "b": 4}
It will instead print
{'a': 3, 'b': 4}
For that matter, I would prefer it if this guide used single quotes primarily; that is the preferred standard in Python.
Re:Learn Python in minutes
by tveita on Friday June 28, 2013 @04:23PM
(#5960157)
Nice and concise. It would be complemented nicely by a list of Python "gotchas".
E.g., off the top of my head, mutable default arguments, or trying to catch multiple exceptions with "except Exception1, Exception2:". That's the kind of thing people new to the language can spend a lot of time debugging when they first run into it.
Edit: and any introduction to tuples should probably show how to write empty and one-element tuples, since that can be non-intuitive. Writing (1) instead of (1,) is also a fairly common gotcha.
Re:Learn Python in minutes
by ZanderEarth32 on Friday June 28, 2013 @03:54PM
(#5960022)
This looks very similar to the notes I was taking on my own when going through "learning python the hardway". Yours are much better and easier to read though, and make more sense in terms of going from very easy to more complicated in staggered steps.
Great stuff!
As a sidenote, how does everyone take note (if you even do) when learning something new like a language or some kind of skill?
Re:Learn Python in minutes
by bitsoda on Friday June 28, 2013 @06:34PM
(#5960664)
What taking notes does for me -- and I assume most other people -- is that it forces me to internalize what I just learned in a way that makes sense to my brain and fits within previous constructs I've already developed through n years of living.
Re:Learn Python in minutes
by 6d0debc071 on Saturday June 29, 2013 @04:19AM
(#5961771)
I make guesses about what the result of something will be, check the guesses to see if they work and then write down why I think they worked or didn't work.
Re:Learn Python in minutes
by wf on Friday June 28, 2013 @04:47PM
(#5960268)
What this needs is Rap Genius style annotations, so people can make comments and additions. I recently (re:yesterday) decided to pick up and try out python for a small project and this is a great quick and dirty start.
Re:Learn Python in minutes
by cinbun8 on Friday June 28, 2013 @04:32PM
(#5960202)
While I see value in a cheat sheet that helps you remember a language's features, using the words 'Learn X in minutes' is a bit stretching it. It takes a good few weeks to get comfortable building something in a new language.
Re:Learn Python in minutes
by frankcaron on Friday June 28, 2013 @03:35PM
(#5959918)
Having just recently learned Python the "hard" way, I really wish I would've seen this beforehand. Even having done some hands-on work and a lot of Googling, I picked up a few new things from this I hadn't seen before. Thanks!
Re:Learn Python in minutes
by 404error on Friday June 28, 2013 @03:40PM
(#5959945)
Same here, I just went through the same course. (Learn Python the hard way).
Coming from a php background I had (and am having) problems wrapping my head around the packaging section. I started to lose interest because of it. It's as if I hit a wall.
Can any Python hackers offer some good resources for learning more about packaging?
If you email me with the problems you had I'll see what's wrong with the exercise and figure it out. There was a particularly stupid ordering problem with it where I had people install requirements after they needed them, so go double check it again and see if it got better.
Also, email me [email protected] with what you ran into. If you're in San Francisco I'll even meet you in person to figure out what you're doing live (works way faster).
Re:Learn Python in minutes
by 404error on Friday June 28, 2013 @05:55PM
(#5960538)
I'm trying to create packages.
I haven't been able to find a decent tutorial on creating packages. That particular section in "Learn Python the Hard Way" was hard for ME to follow. I was able to create a package but only after finding a link on stackoverflow question that then redirected me to a github page containing a sample package from an individual who also had problems. He states that his package worked but he wasn't sure if he created the package correctly.
I've tried reading the python documentation but I'm too dumb to understand some of the language. (No CS background, just a regular dude and a computer here.)
Re:Learn Python in minutes
by nickpresta on Friday June 28, 2013 @06:32PM
(#5960662)
The bit about exceptions, using a comma instead of as, should just be left out. I don't imagine anyone starting out today is using Python < 2.6, and having both in the document is confusing.
Re:Learn Python in minutes
by fs111 on Friday June 28, 2013 @05:10PM
(#5960358)
int, boolean, float etc. are not _primitive_ data types in python. If you say that, you really have no idea, what you are talking about. They are objects like everything else. You can inherit from them and do all the good OO stuff.
Sorry for the nitpicking, but calling them primitive types, is just plain wrong.
Re:Learn Python in minutes
by Loadin on Friday June 28, 2013 @06:58PM
(#5960759)
Author here.
Sorry for that. I know they are objects but if you consider everything an object then really you have no primitives except object itself. Certainly this has a place in programming philosophy but not really a helpful point in a language-primer/cheat sheet.
Re:Learn Python in minutes
by ufo on Friday June 28, 2013 @08:12PM
(#5961007)
I agree that "everything is an object" doesn't mean much but "primitive types" has a strong meaning when it comes to OO programming so a different term might be more appropriate.
Re:Learn Python in minutes
by krob on Saturday June 29, 2013 @06:39PM
(#5963949)
I'm usually a php guy, and recently I had to use some vendor's python api to do some data integration and this might have come in handy. I picked up python, or atleast the basic syntax in roughly 1 day, and was done with my implementation within the next day.
Re:Learn Python in minutes
by cben on Tuesday July 02, 2013 @07:50PM
(#5981487)
This might be even more useful as an ipython notebook so that people can modify and execute any of the examples.
The easiest way to host a notebook that users can try from their browser seems to be Wakari (public viewing, free signup needed to modify/run).
Re:Learn Python in minutes
by kunai on Friday June 28, 2013 @09:59PM
(#5961254)
I don't know the efficacy of this as an educational tool, but as a Python programmer, it's a really handy "cheat sheet" to have around whenever doing general scripting. It's really well written as well.
Re:Learn Python in minutes
by ModernTypo on Friday June 28, 2013 @07:25PM
(#5960859)
I would love a version of this that is incredibly comprehensive. I mean like, go over the entire Python doc in this format. Don't get me wrong, this goes over a lot, and but there's still a lot missing.
Re:Learn Python in minutes
by eurleif on Friday June 28, 2013 @04:21PM
(#5960144)
Yes, that is the same with or without parentheses. You're creating a tuple on the right-hand side of the equal sign, and using tuple unpacking on the left-hand side to assign the members of that tuple to variables. To make it a bit more clear, you can add parentheses on the left to match the ones on the right:
Re:Learn Python in minutes
by madelfio on Friday June 28, 2013 @04:36PM
(#5960227)
You get a list if you do "object_a = [1, 2, 3]" and a tuple if you do "object_b = (1, 2, 3)". Then try "object_c = 1, 2, 3" and you'll also get the tuple.
I remember picking up a large book from a store shelf titled something like "Python for Programmers". Thinking, "Oh, this is for people who already know how to program and just want to learn Python". I open the book randomly and start reading it's explanation on what functions are in programming and why they're useful. I sighed and placed the book back on the shelf.
E.g., off the top of my head, mutable default arguments, or trying to catch multiple exceptions with "except Exception1, Exception2:". That's the kind of thing people new to the language can spend a lot of time debugging when they first run into it.
Edit: and any introduction to tuples should probably show how to write empty and one-element tuples, since that can be non-intuitive. Writing (1) instead of (1,) is also a fairly common gotcha.
I didn't want to overload the reader. Perhaps a more in-depth guide is required.
I am waiting for "Learn X While You Sleep--wake up as an expert!"
If Michael Jackson just knew that......
Great stuff!
As a sidenote, how does everyone take note (if you even do) when learning something new like a language or some kind of skill?
I learn better when I read the same thing over and over from different sources, which might have additional details or different points of view.
Not taking notes forces me to go back when I don't remember something, often finding new sources.
How would you improve the retention rate?
This article is meant for programmers from other languages who want to quickly look up a language specific detail.
This is a good cheat sheet.
but all snark aside, good work so far! like the concept.
Coming from a php background I had (and am having) problems wrapping my head around the packaging section. I started to lose interest because of it. It's as if I hit a wall.
Can any Python hackers offer some good resources for learning more about packaging?
http://learnpythonthehardway.org/book/ex46.html
If you email me with the problems you had I'll see what's wrong with the exercise and figure it out. There was a particularly stupid ordering problem with it where I had people install requirements after they needed them, so go double check it again and see if it got better.
Also, email me [email protected] with what you ran into. If you're in San Francisco I'll even meet you in person to figure out what you're doing live (works way faster).
I haven't been able to find a decent tutorial on creating packages. That particular section in "Learn Python the Hard Way" was hard for ME to follow. I was able to create a package but only after finding a link on stackoverflow question that then redirected me to a github page containing a sample package from an individual who also had problems. He states that his package worked but he wasn't sure if he created the package correctly.
I've tried reading the python documentation but I'm too dumb to understand some of the language. (No CS background, just a regular dude and a computer here.)
That would've been impossible because I wrote that 2 days ago =]
Add about line 89, before assignment to some_var,
Added a try-except around line 186, to guard the KeyError, Added a definition of foo around 320, so calls would workSorry for the nitpicking, but calling them primitive types, is just plain wrong.
Sorry for that. I know they are objects but if you consider everything an object then really you have no primitives except object itself. Certainly this has a place in programming philosophy but not really a helpful point in a language-primer/cheat sheet.
Kudos to whomever wrote it.
Glad you find it useful!
With or without the parens I'm getting the same result for "a, b, c = (1, 2, 3)"
http://www.stavros.io/tutorials/python/
for you gurus, it's got a cool new feature: debugging Python & C++ together: http://www.youtube.com/watch?v=wvJaKQ94lBY
"I know kung-fu"