// Journal

Pyculator Redux

Published
Edited
Read
3 min

Pyculator, huh, yeah! What is it good for? Absolutely Linux permissions. People sometimes struggle to use chmod to change the permissions of a Linux file. Remember that everything in Linux is a file, and every file has permissions for its owner, its group and everyone else: read, write, execute or none. Previously, Pyculator was going to be a tool to get and change file permissions. However, I rethought what was being calculated and realized those operations weren’t really “pyculating.” Instead, Pyculator now converts permissions between numeric form (755) and symbolic form (rwxr-xr-x). The trickiest parts of building it were the lists, the regular expressions and the try-except blocks.

My original concept for Pyculator used tuples, but lists worked better. They were simpler to work with when looking up elements by index. My attempts to unpack tuples to retrieve values kept failing with the error “cannot assign to literal.” With lists, I could write less code and just bash out the logic. The code could still use some optimization, but that part was a simple copy and paste.

Regular expressions (regex) definitely helped with validating user input. Python has great built-in string methods, and most people would reach for those, but I thought it would be fun to try regex. At the beginning of the code you’ll see the reHelp and reQuit patterns. I could have simply converted the input to lowercase or UPPERCASE, but regex handles any combination of casing. You’ll also see regex throughout the code in strPattern and in the many calls to re.fullmatch(). Regex can be complicated, but sites like regex101 let you test a pattern against a string. Getting familiar with regex helps in many applications, and in the shell, where you can find or substitute values without writing a script. Relying only on string methods means we never practice this art, and eventually lose it.

Some of the input checks were easy. Checking input against the list values was harder, especially when debugging. Errors were raised, and Pyculator would exit with the error on screen. To handle these errors gracefully and keep Pyculator running, I added try-except blocks. When a ValueError occurs, Pyculator tells the user there’s a problem with the value they entered and sends them back to the start of that prompt. Catching other kinds of errors would take more testing, such as automated tests that feed in unexpected input. Adding logging would also let us record errors while the user keeps working, then review the logs later to improve how the code handles input.

What features would you build into your version of Pyculator? Fork the code and start bashing out improvements on Pyculator on GitHub. I’d love to see what you bring. Pyculator has been fun, and it could use more enhancements, including but not limited to logging, better error handling, a graphical user interface, reading and applying permissions to files, or running on a web page.


Written with Python 3.10.

Edited in October 2026 for grammar and accuracy. The “arrays” in this post are Python lists.

// Signal

Keep reading.

More notes on Python, vim, Git and the shell are waiting in the journal.

// Contact

Send a message

Only used to reply to you.

What's it about?

Up to 5,000 characters. Please don't include passwords or other sensitive details.

Your message is sent to my inbox by email and isn't stored on this site. The site has no analytics and no third-party scripts. Your IP address is used briefly to limit abuse and isn't included in the email.