Friday 12 June 2015

Learning Enough Python to Land a Job


If you want a job programming in Python, prepare to do a lot of work beforehand. The language is easy to pick up, but you need to do more than just learn the basics; to get a job, you need to have a strong understanding of some pretty complex processes.
Python is a general-purpose language, which means it isn’t used for just one purpose such as Web development. Rather, it’s used in many different industries, and the industry in which you choose to work will determine how you actually learn the language.
For example, if you’re hired to write apps that interact with operating systems and monitor devices, you might not need to know how to use the Python modules for scientific and numerical programming. In a similar fashion, if you’re hired to write Python code that interacts with a MySQL database, then you won’t need to master 


how it works with CouchDB.
Therefore, I’m going to suggest that there are three levels to learning the basics of Python:
  • Learn the core language itself, such as the syntax and basic types; learn the difference between Python 2 and Python 3.
  • Learn the commonly used modules, and familiarize yourself with other modules.
  • Learn the bigger picture of software development with Python, such as including Python in a build process, using the pip package manager, and so on. This involves learning about different databases and other technology, depending on where you want to work.

True Beginners

At a basic level, Python is an easy language to learn and use. You can quickly learn how to create variables and loops, for example, and expand beyond that to tuples, lists, and dictionaries. Any Python newbie needs to know which types are immutable, which means an object of that type can’t be changed (answer: tuples and strings). With immutable types, the object’s value itself can’t change, but the variable containing the object can:

a = 'abc'

a = a.upper()
In the above example, the original string “abc” did not change, as strings can’t change; instead, we calculated a brand new string, “ABC,” and stored that back into the original variable. Knowing that sort of thing should be second nature to anyone who seeks to understand how Python works.
In addition, anyone learning Python should know how the language deals with object-oriented programming, and how to create classes and instantiate objects. It’s also important to know how to use exceptions and exception handlers, and how modules interact. (For key insights, I recommend you read and understand thePython Language Reference; if you’re ever unsure about syntax or how the language works, or are arguing with a coworker, that website will have the final word.)

The Python beginner must also know how Python 2 and Python 3 are different. Python 3 has been out for quite some time, but there are still a lot of projects that rely on Python 2. If you’re interviewing for a position, you’ll want to ask which Python they’re using; if you’re knowledgeable, you can then speak about the differences.

Slightly More Advanced


Once you’ve mastered some basic concepts, you can move on to slightly more advanced concepts. If you’re familiar with languages such as JavaScript, Python’s strong typing might surprise you; for example, you can’t just add “hello” to “10” to get “hello10.” (You’ll get an exception.) This is meant to prevent bugs in your code, and it means you’ll need to become very familiar with dynamic typing, strong typing, duck typing, and how Python implements all three.

C++ programmers coming to Python might be surprised that you don’t need to provide an interface for a parameter in a function; if the object passed in has the required methods, you’re good to go. This makes polymorphism easy.
From there, it’s important to know about closures and “first class objects.” Python supports both, which leads to a concept called decorators, which this article explains very well. Here’s an interesting example of closures, modified from one offered in the linked article; this is entered from the interactive shell:




>>> def outer(x):

...     y = x * 2

...     def inner(z):

...         return y + z

...     return inner

...

>>> q = outer(5)

>>> r = outer(6)

>>> q(2)

12

>>> q(3)

13

>>> r(2)

14

>>> r(3)

15

>>>



The function outer creates a closure with the variable called y, and returns a new function that you can call. I called the outer function twice to create two such functions; then I called those two functions each twice.
Last but certainly not least: Read “The Zen of Python,” which is funny and real, and check out this thread on Stack Overflow for some great suggestions about how to master the language. Go to GitHub and find any of the many popular Python projects; study the code as much as you can.


Side Note: Learn the Modules

The modules are your libraries, your helpers. Know what’s available in the standard library; you don’t have to memorize every member of every class, and every class of every module, but you do want to know what’s available so that when you need something, you don’t go rewrite one from scratch.

Familiarize yourself with each module. Many, such as file I/O, have access in almost every application; know these inside and out. For example, know how to open a file with different access, how to read a file, how to write a file, and how to determine if a file or directory exists. Know how to use the os.path module for file-path joining and normalization, rather than writing your own string routines to handle file paths. Finally, understand the cross-platform implications.



Next: Learn Software Development With Python


There are many tools for integrating Python into a software development cycle. If you want to master the language in a real-world context, learn how to obtain Python packages using pip. You should also learn how to do unit testing, which is fundamental to software development in Python; many people get turned down for Python-related jobs because they can’t answer interview questions in this area. (The Hitchhiker’s Guide to Python includes some great information on unit testing.)
You should also know how to package up Python programs for distribution, and know your way around both the Windows command prompt and Linux bash shell. Any developer worth their salt can use the tools for general software development, from editors and IDEs to git for source-code control.

Targeting an Industry or Technology

Once you’re familiar with all the above, you can begin to move into industry-specific knowledge.
If writing C or C++ extensions to Python interests you, check out this resource. If Web development tickles your fancy, you’ll need to understand the difference between a Web server written in Python that you can extend, and a Web frameworkthat allows you to write your own server software in Python. If you go the Web route, you’ll need to become proficient in Web technologies—not only other languages such as JavaScript, but how to develop Web-scalable software.

There’s also some crossover between specializations. For example, if you’re building Web server software in Python that runs on a cloud, you might need to know how to build cloud-monitoring and management tools (possibly in Python as well). Those tools include Amazon AWS SDK for Python, or the OpenStack’s official clients, which are also written in Python.
If you want to land a job in a scientific industry, you’ll need to know the various scientific and numerical modules inside and out, and have strong skills in writing tight algorithms. For jobs in high-performance computing, you need skills such as concurrent algorithms, SIMD vectorization and multicore programming. For a full list of how to use Python in a work context, check out the dedicated page for applications for the language.


ReadMore

No comments:

Post a Comment