Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Working with Python

Posted on 2007-11-20
4
Medium Priority
?
741 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 1400 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 600 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

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…
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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
Course of the Month13 days, 12 hours left to enroll

963 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