Solved

Working with Python

Posted on 2007-11-20
4
689 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now