Solved

Working with Python

Posted on 2007-11-20
4
715 Views
Last Modified: 2008-02-01
Hello All,

I am running CentOS 5 on my machine and want to lern Python.  When I open a terminal and type python at the prompt it puts me in interactive mode.  My question is how do I enter edit mode from the command line in bash.  I don't see the Python program anywhere in CentOS where I can open ISLE.

Thanks,
palazzini
0
Comment
Question by:palazzini
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 350 total points
ID: 20321909
You just use your favorite editor to write a Python script and then run it using the python command

> python myscript.py

If you add the full path to python as the first line of the script (and give it execute permissions) bash will know where to find the python interpreter so you don't need to specify it

#!/usr/bin/python
print "hello world"

> ./myscript
0
 
LVL 17

Assisted Solution

by:ramrom
ramrom earned 150 total points
ID: 20325281
I wonder if the author wants to use IDLE? If so how does he get there?
0
 
LVL 29

Expert Comment

by:pepr
ID: 20325989
I do not know CentOS, but IDLE is part of your Python distribution and it should be located in your Python directory -- the name of the script should be like  /python/Lib/idlelib/idle.py. In my case (Windows) I can find there also the script idle.pyw and the batch file idle.bat. The idle.bat runs the idle.pyw directly via association of the .pyw extension with pythonw.exe.

Search for your Python executable (the one that you run from console) to discover what is the python root directory. Then search for the idle.py in the above mentioned subdirectories.

In Windows, pythonw.exe is the window-variant of the interpreter (i.e. not the command line) that does not cause popping up the console window first. It is used when launching a Python program that implements its own GUI. But I do not know how it is in CentOS.
0
 
LVL 29

Expert Comment

by:pepr
ID: 20326009
In my case (MS Windows) the idle.py and idle.pyw are exactly the same with the content shown below. Depending on the situation, the core command of launching IDLE is:

    idlelib.PyShell.main()

or

    PyShell.main()
try:
    import idlelib.PyShell
except ImportError:
    # IDLE is not installed, but maybe PyShell is on sys.path:
    try:
        import PyShell
    except ImportError:
        raise
    else:
        import os
        idledir = os.path.dirname(os.path.abspath(PyShell.__file__))
        if idledir != os.getcwd():
            # We're not in the IDLE directory, help the subprocess find run.py
            pypath = os.environ.get('PYTHONPATH', '')
            if pypath:
                os.environ['PYTHONPATH'] = pypath + ':' + idledir
            else:
                os.environ['PYTHONPATH'] = idledir
        PyShell.main()
else:
    idlelib.PyShell.main()

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question