-2

When I submit multiple commands at once in IDLE (using v. 3.7), I get an "invalid syntax" error.

For example, I have to first copy, paste, and enter this:

def converter(number, base):
    figures = [int(i) for i in str(number)]
    figures = figures[::-1]
    result = 0
    for i in range(len(figures)):
        result += figures[i]*base**i
    return result

Then I have to copy, paste, and enter this:

print(converter(30, 12))

It's tedious, and be convenient to just enter it all together. Is there a way to do that?

EDIT: Here's a quick video example for clarity: https://www.dropbox.com/s/gh3zxc8qy3jjl7p/python.mp4?dl=0

abcjme
  • 171
  • 7
  • 1
    Once the function is defined you shouldn't have to copy/paste it again unless the definition has changed. There's no mechanism to predict the arguments you want to pass to `converter` but you can provide default values for arguments if you're OK with calling `print(converter())`. – ChiefTwoPencils Jul 01 '18 at 00:08
  • You can hit the `up` arrow key if you want to edit your older functions without having to copy/paste. See [How do I access the command history from IDLE?](https://stackoverflow.com/questions/3132265/how-do-i-access-the-command-history-from-idle) – xyres Jul 01 '18 at 00:13
  • I have no idea what you mean by "entering multiple commands at once". You need to provide a [mcve] – juanpa.arrivillaga Jul 01 '18 at 00:42
  • @juanpa.arrivillaga I mean copying the def and print together, pasting them together, and entering them together, instead of having to do it separately. – abcjme Jul 01 '18 at 00:48
  • @ChiefTwoPencils Still, why should I have to enter def separately from print. If Python reads it sequentially, it should be able to handle them being entered at the same time. – abcjme Jul 01 '18 at 00:51
  • @juanpa.arrivillaga I added a quick video for clarity: https://www.dropbox.com/s/gh3zxc8qy3jjl7p/python.mp4?dl=0 – abcjme Jul 01 '18 at 00:58
  • @ChiefTwoPencils I added a quick video for clarity: https://dropbox.com/s/gh3zxc8qy3jjl7p/python.mp4?dl=0 – abcjme Jul 01 '18 at 00:59
  • @xyres I added a quick video for clarity:http:// dropbox.com/s/gh3zxc8qy3jjl7p/python.mp4?dl=0 – abcjme Jul 01 '18 at 00:59

1 Answers1

0

I figured it out on my own. You just need to embed all commands in an if statement.

if 1:
    def converter(number, base):
        figures = [int(i) for i in str(number)]
        figures = figures[::-1]
        result = 0
        for i in range(len(figures)):
            result += figures[i]*base**i
        return result

    print(converter(30, 12))
abcjme
  • 171
  • 7
  • You don't need to do this. You need to add a new line between independent code blocks. This is a quirk of the interactive interpreter. Fundamentally, the shell isn't supposed to be a development environment. It's for quick and dirty debugging and experimentation. Perhaps you should consider the [ipython](https://ipython.org/install.html) shell, which is more full featured than the default one, and handles copy and pasting more intelligently – juanpa.arrivillaga Jul 01 '18 at 05:01