Pythonic or not Pythonic? That is the question!

So I’ve gotten more and more used to Python as I continue to work on this final project. I am pretty proud with some individual functions considering  they’re pretty Pythonic… I think. You see I’m not 100% sure still what Pythonic means still but I think they’re Pythonic! For an example I wrote a function to edit only one line in a text file, but it requires me to write over the entire text file. Some parts of this function is pretty Pythonic to me, but over all re-writing an entire text file to just edit one line doesn’t seem very.. Pythonic.  Take a look at the function and tell me what you think!


def changeAttr(line, text):
lines = open(“character.txt”, ‘r’).readlines()
if line == 4: #if item is being changed then don’t remove all items…
if lines[4].split()[1] == ‘none’: #no item then remove whole line
lines[line] = listOfAtts[line] + “: ” + text +”\n”
lines[line] = lines[line].rstrip(‘\n’) + ” ” + text + “\n” #adds item
else: #if it’s not item change entire line
lines[line] = listOfAtts[line] + “: ” + text + “\n”
out = open(“character.txt”, ‘w’)


Anyways back to my original point, I feel like you need so much experience with Python to make larger projects Pythonic as a whole. There’s so many things I do in this final project that are sort of messy because I’m not sure and don’t know if Python has slick tools to do it with so I resort back to what I know, ifs, fors, and whiles which get a bit messy, especially when nested.  I think I’m going to sign up for a Python class Junior or Senior year in order to learn more because I’m definitely hooked onto Python now. Hopefully one day I can write a program that’s 100% Pythonic.

Reddit + Python

I didn’t really have any interest in learning Python in depth in the past. However, all of that changed a few days ago when I was playing on reddit, if you don’t already know what reddit is then you shoudln’t google it. It will save you a lot of time to not know what reddit is. Anyways, back to my story, as I was browsing through reddit I stumbled upon their source code. For those who are interested here’s their git hub:

This took me by surprise because I didn’t know Python was that powerful, I mean reddit is entirely written in Python! So I looked through their files, and I was blown away. I also didn’t understand 90% of it but it seemed super interesting. This led me to decide my next independent web development project will be written in Python. I just wanted to share my new interest with everyone!