Modules in Python

In the past few weeks I have been making an effort to start learning python, and as such I should start getting into how to go about making some kind of real project with python at some point. So far I have been just toying around with small snippets of code, and working out the very basic of python programing. However when it comes to the idea of getting into making something real I am going to want to know how to go about making modules in python. That is how to go about taking code and breaking it down into separate files to which I can then import into another file that will be the main python file or script file that will be started with the python binary one way or another.

So in this post I will be going over the basics and more when it comes to modules and scripts in python as I have come to know it thus far. Such as the difference between a script and a module, how to go about using a module from a script file, and how to go about creating a module of my own.

Read More

Data Types in Python

When learning a new programing language one of the first basic things to understand is to find out what the deal is with data types in the language. Some languages have strict typing where each variable must be set to a certain type, and can not just be changed to something else. Other languages have dynamic typing where a variable can be any given type and any given moment. Some languages have many different data types for numbers that have to do with how many bytes are used to store the value, if it is signed or unsigned, if it is an integer or float value, and so forth. Other languages simplify this by just going with one data type for all numbers.

So when it comes to python it would seem that there is dynamic typing, and there are many data types for numbers. In addition there are many other additional built in types when it comes to objects. In this post I will be going over the basics of data types in python as I have come to understand it thus far.

Read More

Lists in Python

In python Lists are a mutable kind of sequence data type. These lists might be somewhat similar to Arrays in javaScript, but with at least a few note worthy differences such as being a dense rather than sparse kind of array. Lists are not the only option when it comes to arrays in python there is a standard library called array that might prove to be a better option in some cases. However the thing about lists is that it is a type that is built into python itself, and it is just one kind of sever other kinds of sequence types to work with.

In this post I will be going over the basics of lists, how to create them to begin with, how to add and remove elements from them, and also how to sort them. However in the process of doing so I will also be touching base on sequences in general. For example when it comes to built in functions in python there is the list built in function that can be used to create a list, but there is also the range built in function that can be used as a way to create another kind of sequence that is not mutable.

Read More

The fileinput Standard Library in Python

When learning a new programing language such as Python one thing that comes to mind that I like to learn about right away os how to go about reading from the standard input. When it comes to Python there is the fileinput library that can be used to read from the standard input, but can also be used as a way to read a collection of files also. There is one main function of interest in this library when it comes to reading standard input and that would be the input method, by default it will read from the standard input if no file list is given.

There are some additional features of the fileinput library also though, on top of reading from the standard input the fileinput library can be used as a way to read a collection of files. Also there are some related topics that come to mind when using the fileinput library such as piping in a posix system, the open built in function when it comes to reading just one file, and also the subprocess library when it comes to getting a collection of file names. So in this post I will of course be going over a basic example of reading from the standard input with the fileinput library, but will also be going over some more examples that touch base on other related python topics.

Read More

The Threading Standard Library in Python

This month I wanted to start learning python, and I have went threw the basics of learning the language pretty fast. However now I am starting to scratch the surface when it comes to the wide range of standard libraries that there are to work with. One library that I think I should at least write a few quick examples with at least would be the threading library.

In javaScript there are methods like setInterval, and setTimeout that can be used as a way to delay the calling of a function. These methods however will not result is a new event loop though, however in client side javaScript there is Webworker, and in node there is the cluster module that can be used as ways to go about creating a whole other event loop to work in. In python there must be ways of doing the same things, that is just delaying the calling of a function in the same thread, and also to create a whole separate thread. This it would seem is what the threading standard library is all about when it comes to doing the same things in a python environment.

Read More