Python CSV Module Oddity

A Python Oddity

I was using Python to encode a CSV file using a custom dialect recently when I noticed something odd. I noticed that the csv writer class takes an optional argument that enables you to change the line terminator.  That’s ok, however, the csv reader class does not honor the argument. So, through the default api, you can create CSV that you cannot read back in with the default api. According to the documentation, this applies to Python 2.7 through 3.7.  It also probably applies to versions < 2.7 but that documentation is no longer online.

Python.org Documentation

A Simple Script

I wrote the following simple script to illustrate this oddity.  Basically it has a list of lists that it converts to CSV and back using various line terminators, if the output differs from the source, the difference is displayed.

Results

As you can see from the results here; with the exception of ‘\r\n’, all the various line terminators  failed.

Closing Thoughts

So, why would you want to specify the line terminators with the CSV module? There are probably only a handful of reasons, my only reason would be a custom dialect where I wanted to ensure that there were no carriage returns or line feeds in.  99.9% of the time, you want ‘\r\n’.

Posted by Chad Dotson in Programming, Software Engineering, 0 comments

Solar Eclipse 2017 From Sparta, TN

The August 21, 2017 Solar Eclipse as photographed from Sparta, TN (35.9727° N, 85.5638° W).   This was about 3.2 miles from the center of Totality!  These images do not convey the magnitude of the experience.  Knowing what to expect in general does not prepare you.  If I tried to find a single word to describe it, I would pick astonishing.

 

Location Sparta, TN (35.9725° N, 85.5638° W)
Duration of Totality 2m38.8s
Magnitude 1.014
Obscuration 100.00%
Event Date Time (UT) Alt Azi
Start of partial eclipse (C1) 2017/08/21 17:01:17 63.9° 154.8°
Start of total eclipse (C2) 2017/08/21 18:29:50.1 63.9° 205.4°
Maximum eclipse 2017/08/21 18:31:09.6 63.8° 206.1°
End of total eclipse (C3) 2017/08/21 18:32:28.9 63.6° 206.8°
End of partial eclipse (C4) 2017/08/21 19:56:17.0 51.9° 239.1°
Posted by Chad Dotson in Photography, 2 comments

Thoughts On Team Communication

Awhile back I had some thoughts on communication. If you’ve ever played World of Tanks Blitz you’d know that basically its a team of tanks against another team of tanks. With the pick up, fast paced nature communication is minimal at best (sometimes limited to a single “<<<<<<<<<” or “>>>>>>>>>” indicating which direction to take the offense). I found that teams that could coordinate with minimal communication, play their tank roles (scouts, mediums, heavies, and destroyers), and move fast could achieve massive overwhelming victories. Something similar is probably true in an agile/teamwork environment. Know your stuff, know your role, take opportunities, work together, succeed.

Posted by Chad Dotson in Doing Things Better, Software Engineering, 0 comments

iPhone 5 / Verizon 4G – No Bars / 3g No Service Fix

Problem:

You’ve got a iPhone 5 that reports that it has 4g LTE service but 0 bars and, if you turn off LTE, it reports  No Service under 3g.

 

Solution:

The fix, turn off all roaming . Settings > Cellular > Cellular Data Options > Roaming – Turn off all settings here.

Posted by Chad Dotson in Technology, Tips, 5 comments

SSLError with Python 3.6.x on macOS Sierra

SSLError

Have you ran into trouble with SSLErrors after upgrading to Python 3.6 on macOS Sierra?  For me, my first encounter was downloading the bokeh sample data (included here).

I finally got a chance to research exactly what was wrong.  Given that Python 3.5 was working on my machine and 3.6 was working on several linux machines, I thought that it could have been an issue with Python 3.6, unlikely as it may be.  After no bug fix version was released I realized that it must be my configuration.

Searching, I found one result related to this in the Python issue tracker: Issue 28150.  One answerer points out that Python on macOS no longer relies on Apple’s version of OpenSSL, instead it is shipped with a new one.  The gotcha: this new one does not have trust certificates installed.  All this is detailed in the Readme.

The Installer Readme

So, as the Python issue tracker mentioned, there is an entry in the installer readme.  Perhaps I should read these closer…

Certificate verification and OpenSSL

**NEW** This variant of Python 3.6 now includes its own private copy of OpenSSL 1.0.2.  Unlike previous releases, the deprecated Apple-supplied OpenSSL libraries are no longer used.  This also means that the trust certificates in system and user keychains managed by the Keychain Access application and the security command line utility are no longer used as defaults by the Python ssl module.  For 3.6.0, a sample command script is included in /Applications/Python 3.6 to install a curated bundle of default root certificates from the third-party certifi package (https://pypi.python.org/pypi/certifi).  If you choose to use certifi, you should consider subscribing to the project’s email update service to be notified when the certificate bundle is updated.

The bundled pip included with the Python 3.6 installer has its own default certificate store for verifying download connections.

Two Solutions

There are two solutions as mentioned:

  • Install the certifi package.
  • Run the download script provided with the installer – /Applications/Python 3.6/Install Certificates.command.

For myself, I ran the bundled script and everything seems to be functioning fine.  It seems more than a little odd that this was not done on installation.

 

 

Posted by Chad Dotson in Programming, Tips, 15 comments

Pip Installs From Github

Pip installs From github

Installing a package from github is fairly simple.  The following are examples of installing packages from github.

requirements.txt

At some point, you will find yourself wanting to list a dependency in the requirements.txt file that resides on github.  This is fairly straight forward If you only plan to use it in requirements.txt (not processed for usage in setup.py).  Note that I’ve specified the master branch of repo and given it a version id.

setup.py and requirements.txt

Some people will process their requirements.txt files to generate the install_requires parameter for the setup function called in setup.py.  This works fine until you have a repository on github.  Setup will fail to find your dependencies if your requirements.txt has a line like the one above.  To remedy this we must do two things.

  1. Parse the line to create a named python dependency for install requires. Given the file above, install_requires would equal ["repo==0.0.1"] .
  2. Specify the dependency_links argument to setup.  ["https://github.com/chaddotson/repo/tarball/master#egg=repo-0.1.1"]  for this example.

An Example

This is an example of a setup.py that properly processes requirements.txt dependencies that are located on github.  It’s probably not complete, but it works for what I need.  Feel free to take and adapt.  See the repo here (python3).

 

 

 

 

Posted by Chad Dotson in Programming, Tips, 0 comments

July 8, 2016 Lightning

These are the first lightning photos in several months.  It was a good electrical storm but the lightning wasn’t so photogenic.

Posted by Chad Dotson in Misc, Photography, 0 comments