Example of executing Python program files in IPython

  • 2021-01-19 22:18:42
  • OfStack

After a few quick uses, I decided that if given the chance (the code in my company is extremely free, and it doesn't matter, I don't do data analysis at my company), I would definitely prefer to use IPython as my Python shell environment. A simple touch revealed a number of features I liked. Among them, the ability to call Python files easily in this command mode and the ability to recognize part of the physical disk path information are my favorites.

Several commonly used shell commands are integrated into IPython, which makes it feel much easier to use. On the rare occasions I have had to interact with the operating system, I have always referred to the os module.

Here's a simple example:


In [18]: pwd

Out[18]:u'E:\\WorkSpace\\05_PythonDataAnalysis\\chapter04'

The computer system I use is Windows10. Type pwd into IPython to display the current disk directory. The realistic way is unicode. If directory or file input is used, it can sometimes be completed by the Tab key. Here's another feature that I found good:


In [19]: %rundict.py

{0:-1.756969911912656, 1: -1.4347730975729878, 2: -0.9382762435800732, 3:-0.4516330355346149, 4: -0.13815155454614986, 5: 1.5327376752648885, 6:-0.29408952382792924}

As you can see from the above record, you can call the Python program file directly from %run. Before this, when I use similar functions, I basically use the way of importing modules to achieve, compared with this way is really a lot of practical. As can be seen from the above record, the output is in the default Python format and is not formatted.

The IPython formatted data output should look like this:


{0:-1.756969911912656,

 1: -1.4347730975729878,

 2: -0.9382762435800732,

 3: -0.4516330355346149,

 4: -0.13815155454614986,

 5: 1.5327376752648885,

 6: -0.29408952382792924}

Related articles: