Re: [Tutor] stupid Q

Magnus Lycka magnus at thinkware.se
Wed Dec 3 14:33:19 EST 2003


Az wrote:
> hi all
> i am using python 2.2  on freebsd , the thing is  i dont have GUI and use
> only command line interface  , so
> how do i save a file from cli in the python's

As Kalle said, you should normally (whether you use
an IDE or not) write your code in an editor, and save
it as a file.

You can save any command line session in unix though.
(This has nothing to do with python.) For this, you use 
the unix script command. Just as with Python, you end 
the script session by pressing Ctrl-D.

www5:~> script x.txt
Script started, file is x.txt
> python
Python 2.2.2 (#2, Feb 10 2003, 00:03:01)
[GCC 2.95.3 20010315 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "Hello"
Hello
>>> [Ctrl-D]
> [Ctrl-D]Script done, file is x.txt
www5:~> more x.txt
[This will show the same as you see above...]

Naturally, you will have to edit out the leading 
'>>>' and extra lines of text to be able to run your 
interactive python code as a program.

A more normal unix/linux/bsd command line session
with code editing consists of either suspending
your editor to run code, or to use several (virtual)
terminal sessions. Unix is a multitasking OS after
all, whether you use a GUI or not.

You suspend your editor with Ctrl-Z and revive it
with the 'fg' command. Like this:

$ vi test.py
[do some code editing, and save without quitting]
Ctrl-Z
Suspended (signal)
$ python ./test.py
[Your bugs become evident...]
$ fg
[you're back in the editor, fix and save, don't quit]
Ctrl-Z
Suspended (signal)
$ python ./test.py

Repeat until ready... (remember to use 'fg' to get back
to your editor. If you start the editor again the normal
way, after you left it with Ctrl-Z, you'll end up with
several editor sessions running in parallel. Of course,
you should exit the editor properly when you are done.
If you try to log out with suspended jobs, the OS will
tell you.)

With Linux, you normally have several virtual consoles,
that you switch between with Alt-Fx. Then you can edit 
(don't forget to save) in one console and run the code in 
another. That way you don't need to bother with suspending
the editor session to run code.

If you are not by the console, you can use something like
the "screen" utility. Use "man screen" to figure out how.

Of course, if you use a good editor, such as vi (or better:
vim), you can run your python script from within the editor.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus at thinkware.se



More information about the Tutor mailing list