Strings in python

One of the many basic data types of a programing language is the string data type, this post will be just a quick overview of strings in python. A string can often be considered a sequence of characters, so they are often used as a way to store text values, however they can also often be used to store an array of values like that of a list.

On top of the very basics of strings, there are also a number of string methods with the data type. So it would be a good idea to go over some of these methods that there are to work with when it comes to strings, such as uppercase, cont, find and so forth.

Read More

tkinter standard library in python

In python there is the tkinter standard library that is an official interface for the TK GUI tool kit. This library can then be used as a way to create graphical front ends for python projects. The library works by providing a number of widgets that can be used to create various components in a window such as buttons, menus, a canvas, and text. With these widgets it is possible to make a basic yet functional graphical user interface for a python project.

At the time of this writing I do not yet have much experience working with tkinter, and I also only have about a month of experience so far with python as a whole. So for now this will be just a few basic examples of the standard library. In time if I do start creating and maintaining some real projects with python this will likely be how I will want to create a GUI for the project.

Read More

Errors in python

One of the basic things that I still need to read up on a bit more with python is how to handle Errors. The process of doing so is a little different from what I am used to in a javaScript environment, but not by much at least when it comes to the try catch statement. With the try catch statement there I can place some code that might cause an error into the body of a try block, and then if something goes wrong, code in an attached catch block will fire. In this catch block I can access an error object that will contained detailed information about the error that happened.

Just like with javaScript there is a kind of try catch statement in python, however it might be better to call it a try except statement. The try except statement is a little different, but it is more or less the same thing. I can place some code in the ty block, and of something goes wrong code in the except block will fire.

There is maybe a bot more to error handing then just understanding some basic examples of a try block, so in this post I will be going over everything that has come up so far when it comes to errors in python. This will include ways to go about causing them, how to handle them, and how to throw user defined errors, any any other little related things that might pop up in the process. After the basics I think it might be a good idea to work out a few quick use case examples that make use of Error handing when making certain kinds of functions, and basic projects. This is an important part of knowing how to program with python, and any language for that matter actually so lets take a quick look at some examples of Errors in python.

Read More

The Subprocess Library in python

When learning a new programing environment one thing that I like to learn how to do is how to go about launching another script, or command completely in the operating system if I can do so. In just about any language where I am writing a script, or source code that will be compiled into a binary that will be called in the command line, there should be a way to call any and all other commands.

In nodejs there is the child process module for example that provides methods that can be used to run a command, so there should be such a module in python also then. It would seem that the best option for doing so might be the subprocess library that contains such methods. There are some other options when it comes to running external commands, but the other built in options are older solutions that are still there mainly so older code does not break.

For this post then I will be going over some basic examples of the subprocess module when it comes to running external commands in python.

Read More

Tuples in Python

There are a few built in data types in python, and one such type is a tuple which is yet another option when it comes to data structure in python. Like lists a tuple is a kind of sequence type, however one major difference is that a tuple is not mutable. So once a tuple is created, the only way to mutate the tuple is to create a new tuple. However when it comes to nested values in a tuple they can still be mutated assuming that it is a type that allows for that such as a list. So then a tuple might be a good choice for some kind of data that I want to remain fixed, and then I can create additional tuples, and other sequence types from these tuples.

In javaScript I often have a collection of hard coded data in a module, and often I want to create a copy of that collection of that data that is completely separate from it. So when I make a change to the copy of the hard coded data, such a change effects the copy and not the hard coded source. So then I often have a way to go about creating what is called a deep copy of that hard coded data. In python I can use tuples as a way to go about creating that kind of fixed hard coded data. I can have just a single tuple, and nested tuples. Then I just need to have a way to go about creating a nested lists form of that hard coded data in tuple form.

Read More