30 days of Python: 3/30
My study spot today:
I am progressing veeeeery slowly through this challenge, haha. I don’t think I’ve managed two days in a row since I started :X But “slow but steady wins the race”, and I’ve learned by now that sticktoitiveness is more important than glamorous study habits.
The other day, as I approached the end of Step 1 of the tutorial, I ran into a challenge. Lynn suggests going and finding your own data and using the new function you’ve just created to process it as well. So I found some data on real estate transactions in Sacramento (thrills and chills, I know – but the point is to graph it and so on, it doesn’t need to be super interesting), and gave it a shot.
But the command line didn’t like my new file, and spat out this error message at me: “_csv.Error: new-line character seen in unquoted field”
I’ll be the first to admit that I do get intimidated by reading the docs, and I realized the problem here was clearly my lack of understanding of the Python csv module I was working with. There’s no point in just copying out every line of the tutorial by hand if you don’t really understand what you’re doing.
So, I copied the error message and pasted it into Google, found a StackOverflow conversation about that exact error, and one person suggested “opening the file using universal newline mode”. I had no idea what this meant, so I took a deep breath and dove into the docs. After spending a few minutes reading them, I felt much more motivated – it’s not as scary as it looks! I found a description of the exact parameters that the csv.reader() method takes, messed around with a little trial and error – and it worked! I was absolutely thrilled to see my huge ugly flood of real-estate data appear in the command line :D
I still want to try the “extra credit” challenges she mentions at the very end of the page, although they’d be a big step up:
“You can continue to play around; try >>> help(parse.parse) to see our docstring, see what happens if you feed the parse function a different file, delimiter, or just a different variable. Challenge yourself to see if you can create a new file to save the parsed data, rather than just a variable.”












