Week 7


I was writing python code all this week. I was rewriting files again and again. It is a very important role to write a tutorial with code examples. When I did homework at university I wanted to have a working file. I often wrote it without comments! But now these files can be used as an example. Users can modify it, add new features but the base will be the same. I want to have clear and readable code.

Firstly I have written a working example. It had the logic that I wanted. Then I understood that I can do it simpler. I have rewritten it. Then I discussed the logic with my mentor and we decided to change something. I have rewritten it again. In the next tutorial I can use this file but I should modify it. What do you think? Yes, I have rewritten it again. At the end my mentor approved it, but mentioned that I can update it later :).

Also I have changed one existing file and created one more. I have realized that python it is a very convenient language for parsing file. I have an yaml file with input data.  Yaml format is a standard format for saving settings. My yaml file looks like this:

- {filename: 'table.png', position: { x: 1, y: 2}, quaternion: {r1: 0, r2: 0, r3: -0.628, r4: 0.778}}
- {filename: 'bookshelf.png', position: { x: -3, y: 1}, quaternion: {r1: 0, r2: 0, r3: 0.936, r4: 0.353}}

It has a good structure. User can easily read and modify it. You can find more information and yaml examples here.

You can read data from yaml in python with two lines:

with open("route.yaml", 'r') as stream:
   dataMap = yaml.load(stream)

Previously I worked only with C++ language. I used python only in my private goal (to do something quickly). Now I think that it is interesting to write in python too.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s