Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Friday, March 12, 2021

Python Script for Splitting a Delimited File Into Multiple Files

I needed to split a big file delimited by double line breaks into a series of smaller files. Python to the rescue!

Posting this because I didn't find anything on google that put together all the pieces I needed.

def split_file_on_delim(to_split_name, delim, splitted_base, splitted_ext):
    """This function reads a file, splits on delim, and writes each chunk out to its own new file."""   
    fn = open(to_split_name, "r")
    fr = fn.read()
    fs = fr.split(delim)
    for i, chunk in enumerate(fs):
        fw = open(splitted_base + "_%i." %i + splitted_ext,'w')
        fw.write (chunk)
        fw.close() 
#sample usage:  
split_file_on_delim("c:\\tmp\\to_split.txt", "\n\n", "c:\\tmp\\splitted", "txt")

Wednesday, January 15, 2014

Best MOOC for Beginning Programmers

I took An Introduction to Interactive Programming in Python on Coursera.org this fall, and I was amazed by how well it was designed.

This course provides a nice first look at programming in general, and Python specifically.1 While it gives many step-by-step instructions to help beginners through the tasks, it also leaves some intentional small gaps for students to fill in on their own.

Overall, the design and content are the best I've seen in a MOOC. Big-time kudos to Scott Rixner and Joe Warren, the masterminds behind this course. (They had help from a couple of other Rice faculty members, as well.)

I was especially impressed with the fully cloud-based Python Integrated Development Environment, CodeSkulptor, which Dr. Rixner designed for the course. This tool allows you to enter and run Python code using nothing more than an Internet connection and a Web browser.

If you want to poke CodeSkulptor around on your own, you can feel free to. You don't have to be enrolled in the class to use it. It also includes a Graphical User Interface module called SimpleGUI, which allows you to code visual elements without too much fuss.

Coursera is a great MOOC platform, and this course really showcases its flexibility and power. I would love to see more offerings like this in the future, as well as some more advanced courses in Python.

You can read Rixner's and Warren's reflections on creating the course here: MOOCs: Lessons from the front lines.

You can also watch them discuss MOOCs with the president of Rice in this video: The professors behind the first massive online open course at Rice University.


1 If you're a complete novice and you find this course overwhelming, you might try Introduction to Systematic Program Design - Part 1 or Computer Science 101 first. They are both quite good as well, and they provide content tailored for those with little prior exposure to programming.