How do I start learning Python?


nikhilavasthi

Member
Disciple
Jul 1, 2013
39
43
21
Jogeshwari, Mumbai, Maharashtra
I'd rather not diverge from the threads goal and indulge in idle speculation not related to learning python - trolls generally want to go off-topic, typically on Freenode's #python which is quite a nice place.

matplotlib is a Python library to graph/plot data.

I find studying other people's code to be quite useful: for example, "Flask" is a Python library/framework that allows a programmer to quickly display/process data via the web. I prefer YAML but for web-apps JSON is the norm. Not that I am an expert on Flask - I've forgotten a bit.

@app.route is a Flask python-decorator that basically maps the URL to a function - it's event driven. When the Flask framework/code receives the URL request (the '/home.html' or whatever) on port/whatever, it will call your function with data as arguments to it. In fact Flask will wrap all the HTTP Headers and such in an object for you to use within your code.
"from flask import request"

One thing I found very different from Perl/C was this:
nlp = Nlp.NLP() #basically you are calling a class in the module Nlp and instantiating/creating an object but in perl you can always tell what a var-name is because it'll be $foo for scalar - the '$' indicates scalar/single-value variables - so in python figuring out the type is quite tricky and extremely annoying! Why? Because the methods you can call on the object depend on the type - in Python you can't tell what 'word' is.. so I have to make it 'words' vs 'word' or sometimes do l_x for list_x.

Another curious thing is
> if Text is None: #in python 'None' is an object - 1 object - there is only one "None" no matter the number of times you use it, so you are not doing a numerical comparison - it's not a variable! Typically in C we do numeric comparisons (checking for NUL/NULL) which is an integer value/macro/direct integer comparison. With None we are actually checking it's physical address (pointer address - kind off) - because there's only one None object ever, you can do that.
Well you needed sample code, do you think I'll give you production ready code. You can run as many analysis on it and go on to compare with Ruby or C or anything else as you like. You can suit yourself with your assumptions.
 

Veek M

Member
Disciple
Sep 5, 2014
42
15
11
Bangalore
www.reddit.com
Typically I use Python code to make my life easier on Linux, so I have Hexchat scripts written in Python to auto-login to IRC, alter my version/date|time, alert me when someone checks my version of client; for vim it's useful to write python scripts to auto-complete from python's stdlib/display help and such - but that didn't work too well for me. Case to point is the pastebin script which I wrote to figure out power-tools.

So non-commercial "sample code" is usually readily available if someone uses a language to solve problems in their life - which is kind of the point of programming anyhow. (alas I can't delve into anything else as it would be off topic)
 

Veek M

Member
Disciple
Sep 5, 2014
42
15
11
Bangalore
www.reddit.com
(it's completely untrue since I've never used Python for a hobby and don't know him personally - he's trolling to elicit a response - is my guess).

To improve the quality of this post, and provide something useful to readers: the python stdlib is rather dated - YAML for config files and for DB work dataset is excellent (don't learn SQL)! My suggestion is you skip reading the stdlib from Beazley and all that UnitTesting crud: re yaml itertools functools setuptools collections glob shutil hashlib subprocess are the modules to read initially. Also os.walk and sys.argv/stdin/stdout
and pip