-1

I am completely new to python and ubuntu. I am reading a book that has an example to run on python. in windows i used to run in IDLE, but where is that in python ? and if I dont want to get IDLE, then is there any other way i can run in terminal? please instruct me run the program

odbchelper.py:

def buildConnectionString(params):
    """Build a connection string from a dictionary of parameters.

    Returns string."""
    return ";".join(["%s=%s" % (k, v) for k, v in params.items()])

if __name__ == "__main__":
    myParams = {"server":"mpilgrim", \
                "database":"master", \
                "uid":"sa", \
                "pwd":"secret" \
                }
    print buildConnectionString(myParams)

3 Answers3

4

If you really want to do this from terminal, you have the following choices:

  1. use interactive python mode by typing python in the terminal window. This is only useful for testing very short snippets.
  2. use a text editor, such as nano or vi or emacs, save your program to a file mypythontest.py and then run it with python python mypythontest.py

But since you are novice, you probably will do better using an IDE. A decent one is PyCharm, there is a community version and professional version.

EDIT: There are other IDEs available for Python, you can find more by just googling.

EDIT2: Note that for just learning/testing python code, it might be even easier if you used a cloud-based solution, such as ReplIT, Cloud9 IDE, PythonAnywhere.

0

I would suggest you to go old school way. Use gedit and the terminal. You will learn lot of things. And there's always askubuntu and stackoverflow to help you out if you face any trouble.

farasath
  • 191
0
  1. Add #!/usr/bin/env python to the top of the file and save it as script.py.

  2. Open up the terminal.

  3. Set the file's executable bit by running: chmod +x script.py.

  4. Run the script with ./script.py.

    running-a-python-script