Solved

Working with Python

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
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…
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…
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…

760 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

17 Experts available now in Live!

Get 1:1 Help Now