Weird thoughts from a techie brain...

August 2017

Sun

Mon

Tue

Wed

Thu

Fri

Sat

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

About

This site is an effort to share some of the base knowledge I have gathered through all this years working with Linux, FreeBSD, OpenBSD, Python or Zope, among others. So, take a look around and I hope you will find the contents useful.

Autocompletion for your python shell|console|interpreter

One of the nice features of the django shell (that is, the python shell you get when you call ./manage.py shell inside a django project) is that it has tab autocompletion, that is, you can import a module and use tab-completion to see all the modules within it.

A lot of people are using iPython these days because of the lack of this feature on the default Python shell, but this is only by default, and if you are using iPython only because of the tab completion, forget about installing extra stuff, you only have to do this little trick:

In this example, after importing smtplib I just wrote smtplib. in the shell and hit tab twice, to get all the available options in that module.

Nice, isn't it?

Ok, now it would be even nicer if we do not have to set tab completion each time we run the python shell, but this is an easy one.

Each time you run the python shell|console|interpreter, it will search for a variable in your environment called PYTHONSTARTUP, where you can set a file that will be executed after starting the shell (the perfect place to put some init-lines).

So, all you have to do is, first, add this two lines to a file, for example, called .pythonrc in your home:

IPython allows non-blocking interaction with Tkinter, GTK, Qt and WX. The standard Python shell only allows interaction with Tkinter. IPython can interactively manage parallel computing clusters using asynchronous status callbacks and/or MPI. IPython can be used as a system shell replacement, especially on Windows, which has a minimally capable shell. Its default behavior is largely familiar from Unix shells, but it allows customization and the flexibility of executing in a live Python environment