Python interpreter autocomplete

I’m writing this down for Future Erica because I’ll inevitably have to do it again on other computers. If others find this useful, awesome.

Open the python interpreter1

> python

Type the following in the interpreter

>>> import site
>>> site.getusersitepackages()

Copy the path that gets printed to your screen. For me this path was

/Users/ericajoy/Library/Python/2.7/lib/python/site-packages

Exit the Python interpreter by pressing Ctrl+D

cd to the directory you just copied.

> cd /Users/ericajoy/Library/Python/2.7/lib/python/site-packages

If the directory doesn’t exist, create it, then cd to it.

> mkdir -p /Users/ericajoy/Library/Python/2.7/lib/python/site-packages
> cd /Users/ericajoy/Library/Python/2.7/lib/python/site-packages

Download the usercustomize.py script to the site-packages directory

> curl -o usercustomize.py https://gist.github.com/anonymous/8892856/raw/2d65cabd8aa10cdad77dbf848e0b0b2ecbeb19ff/example.el

Open the Python interpreter

> python

Enjoy the autocomplete goodness.

(Shout out to Chris Biscardi for doing the legwork for this.)

  1. It should be noted that I did all this on OS X. I cannot vouch for the effectiveness of this process on Windows. However, I wish you luck in your future switch to an operating system with a proper shell. []

HB Day 5: InstallFest 2014 (a.k.a. 10 steps to making a Mac ready for hacking)

Typically Fridays at Hackbright are sort of “free” days.

Technically they’re called Study Hall days, where those who need a little extra help can get 1:1 assistance from the instructors or people who may be behind on assignments can catch up. For those who are all caught up and clear on the material covered in the last week, it’s a chance to refresh the knowledge by doing some more advanced problems that cover the same topics.

The first Friday at Hackbright, though, is not typical, for the first Friday is InstallFest.

InstallFest is the fun party where everyone brings in their personal laptops for the first time (we’ve been taking notes using actual dead tree paper notepads and will continue to for lectures) and we get them all set up for hacking shit. Most of the class (24/29) had a Mac laptop of some sort, and these are the steps we did to make our Macs hacking ready.1

  1. Install Xcode
  2. Install Sublime Text
  3. Install the heroku-toolbelt
  4. Install homebrew
  5. Install Xcode command line tools (forced by homebrew)
  6. Install pip (“sudo easy_install pip”)
  7. Generate an ssh key
  8. Add newly generated ssh key to Github
  9. Set up Sublime Text prefs (“tab_size”: 4,¬†”translate_tabs_to_spaces”: true)
  10. Set up the subl -> Sublime Text symlink

Houston, we are ready to get shit done.

Or sleep for the first time this week? Either, really.

Update: Turns out I neither got shit done, nor slept. I had drinks with some of my classmates, which was awesome, because they are.

  1. The Windows people had their own party and I don’t know what steps they did, but it couldn’t have been too much different, save the Xcode and homebrew business. []

HB Day 4: The Memory Talk

So this was me at the end of the day today.

…aaaand there was maybe a little of this.

I was literally cussing Python right out (much to the amusement of my classmates). Why? Well I’m glad you asked.

This is how a list is constructed in Python.

> a = [1,2,3,4,5]

so

> a[:] == a
True

a[:] means a[s:e] where s is the start of the list and e is the end of the list. Since both are blank, this represents the entire list.

Here’s where the fun began. ¬†Since

> a[:] == a
True

I expected that

> a = a + [6]

would be the same as

> a[:] = a + [6]

Turns out, nope. Putting that [:] after a is a signal to Python that we want to edit the list in place, or rather, edit the list that exists in memory.

> a[:] = a + [6]

says hey Python, please change the version of a in memory to include all the current contents of a and then add a 6 to the end of the list.

Meanwhile assigning a without the [:] tells Python to make a new version of a.

> a = a + [6]

says hey Python, please create a new version of a in memory, add all the contents of the old a, then add a 6 to the end of the list, then delete old a.

This was not obvious to me until after we got “the memory talk” and maybe I might have had a, um, spirited discussion about the whole thing. (Dear Sean, I’m sorry for my outburst.)

Please note that I’m probably not explaining it right, but this is how I understand it. Feel free to leave a comment directing me (and others) to proper explanations of how/why this works.