Solved

Working with Python

Posted on 2007-11-20
4
699 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
  • 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 28

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 28

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

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…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

770 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