2 ms·
Oh, the standard library is so big and knowing what you don't know such a big problem that I forgot to mention some things you need to know about when you actua
by anigbrowl 4y ago
Oh, the standard library is so big and knowing what you don't know such a big problem that I forgot to mention some things you need to know about when you actually sit down to write code.
It's super easy to do text-based interactive little utilities in Python (that you run in the terminal) and not much harder to do command-line utilities with keywords etc. A basic Python reference will move you quickly thought he basics of open and closing files, doing numeric calculations, and manipulating strings (one of the things that Python does incredibly well and which is kinda miserable in C by default). Pay attention to data types, Python kinda does sensible defaults for everything in the background and gets it right most of the time, but mismatched data types are the most common bug that cause your programs to crash horribly (as opposed to keep running but doing the wrong thing).
That's all fine at the learning-the-language stage, but if you get stuck here you'll just end up making command line tools forever and become one of those people that insists everything be stored in text files and eventually lose the ability to operate a mouse altogether.
Chances are sooner or later you will want to write a program that goes on the internet to grab some data or do a thing and give the sense of god-like power that you secretly crave. For this you will need to get familiar with the Requests library (and later Sockets) which will let you do web-type things. Requests are how you ask the internet for things, sockets are the networking infrastructure you build if you want more low-level control. Most of your requests will involve either sending or receiving json, to be opened or saved in files and later in data frames, which are like smart tables.
You'll find json is not that hard but nor is it that easy, so you'll need a library to translate back and forth between json and standard data types or advanced ones like data frames, which I am repeating because you will end up using them all the time for everything. This doesn't mean you can skimp on understanding the standard data types. So get used to the json library, then learn to use the json builtins in pandas, which are the same but different because standardization is more of an idea than a reality in many respects. This is especially true for csv and json files, which everyone uses because they're easy, until they become unmanageable.
(A lot of HN discussion is about the tools that do a good job once the volume/flow speed of data becomes so overwhelming that your basic hacker knowledge isn't sufficient, and you'll either need to become a much better programmer fast, lock in to bad solution and become a creator of Weird Software, or use a database.
(Databases are for when you want less control and it's someone else's job to make shit work, which it will, and often far faster than anything you could have achieved. Working programmers have strong opinions about databases the same way truck drivers have opinions about trucks, and they're all valid. If you are not trying to make a commercial product where the product is simple but the infrastructure is complex, you might find you never need anything more than SQLite for a database. Database design is its own big subject and it depends very much on your problem. You will need to learn SQL (structured query language) as well as Python once you start using databases but it's easy, you can pick up the basics in am afternoon.)
You absolutely have to get comfy with json because most APIs are just about computers slinging json back and forth and once you get the hang of how to do this it opens up an entirely new vista, suddenly large chunks of the internet are accessible from inside your IDE allowing you to do all sorts of interesting stuff with relatively limited expertise. This is where it gets much more fun and rewarding, in terms of both emotion and utility.
See something cool on the web, but no json? No problem, that's what BeautifulSoup is for, it'll help you scrape data directly off web pages, it's super easy to use, you're going to need it all the time. Selenium is also important to know about if you want to do remote control of something without an API (ie use Python to drive a browser and fake the typing and mouse clicks). But you won't often need to use it, just know that it exists when you can't find any other way to do something you could do by hand.
Dataframes in (pandas and other libraries) are great for tabular data, numpy is great for multi-dimensional numeric data, and together they can meet most of your needs. But if you're at all interested ing graph theory you'll want to use Networkx. Graph theory is a kind of essential tool for anything where you don't know your data layout in advance and you want to represent the relations between things and analyze them mathematically. Networkx is not the most performant library but it's really easy to use and there's a ton of people working on it. Like Pandas, it's the de facto standard and competitors try to match its syntax/concepts so as to be more accessible.
Basically with all the above you'll be able to prototype anything, it just won't run at outstanding speed and if it turns into a large project you'll probably have maintenance issues as you hit the limits of Python, the most mainstream libraries, and your own knowledge, cause there's always more to learn. But if you're more interested in problem-solving and demonstration than building consumer ready products, then these are the must-haves in your toolkit that you'll find yourself using on a daily basis.