0

Shell commands that work in interactive mode do not work when I run them as a script. For example:

#!/usr/bin/env ipython

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

#Ingest the data into a giant DataFrame
cd data/raw/

If I type the above in the interactive shell, everything is working fine. If I run the script ./myScript.py, or I just copy the code above and paste it in my interactive shell (starting at the first import), I get:

    cd data/raw/
          ^
SyntaxError: invalid syntax

I feel I'm missing something obvious here but not sure what?

0

1 Answer 1

0

Why is your script a .sh file while you write python code ?

Try with the .ipy extension

Sign up to request clarification or add additional context in comments.

3 Comments

It's actually .py, I changed the question. I did using .ipy extension and that did not make any difference.
Actually, you were right - I need to precede the call with a % symbol, and use .ipy extension.
Nice to hear you solved the problem :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.