Is it possible to change defs without total rewrite them, with a sort of notepad or something?
Note that I'm beginning just, maybe it comes later or it is a stupid question...
> Is it possible to get an old command line back, like doskey or
> something that you press arrow_up, and you get old command lines
> then... Is it possible?
On Windows, it's done by the OS: in other words, it works on NT and
not on 95. On Unix, you just uncomment readline in Modules/Setup when
you build.
> Is it possible to change defs without total rewrite them, with a
> sort of notepad or something?
You can use notepad. Or vim. Or whatever. If you work this way, keep
dos box / shell window open in the same directory. Use "python -i
<scriptname>.py". This will execute the script, then put you at an
interactive prompt, just like you'd entered the script interactively.
On Windows, Pythonwin makes a better environment (follow the windows
links from the homepage). PTUI is a cross platform environment - you
can find it from the Contributed link.
As you've discovered, you'll quickly get frustrated trying to develop
interactively. But it's very valuable for poking at what you're
developing. Typically, I don't write more than a dozen lines or so
before trying it out.
> Note that I'm beginning just, maybe it comes later or it is a stupid
> question...
It will change your style of working :-).
- Gordon
Sure. It works that way under NT, or if you're using Unix and have
enabled readline support. It doesn't work under Win95, for the
moment. So I suppose that's what you're using.
> Is it possible to change defs without total rewrite them, with
> a sort of notepad or something?
With any kind of editor that's able to write good old text files.
Edit, Notepad, ..., vim, emacs, you name it.
Just save your program as a ".py" file (e.g. myprog.py), and run
it as:
python myprog.py
Or get pythonwin or PTUI or NT-emacs with python-mode.el,
or any other Python-aware environment. You'll find them via
www.python.org.
Cheers /F
fre...@pythonware.com
http://www.pythonware.com
Gordon McMillan wrote:
> Gerrit Holl asks:
>
> > Is it possible to get an old command line back, like doskey or
> > something that you press arrow_up, and you get old command lines
> > then... Is it possible?
>
> On Windows, it's done by the OS: in other words, it works on NT and
> not on 95. On Unix, you just uncomment readline in Modules/Setup when
> you build.
I have Windows 95... So do I really have to retype it all?
>
>
> > Is it possible to change defs without total rewrite them, with a
> > sort of notepad or something?
>
> You can use notepad. Or vim. Or whatever. If you work this way, keep
> dos box / shell window open in the same directory. Use "python -i
> <scriptname>.py". This will execute the script, then put you at an
> interactive prompt, just like you'd entered the script interactively.
>
> On Windows, Pythonwin makes a better environment (follow the windows
> links from the homepage). PTUI is a cross platform environment - you
> can find it from the Contributed link.
>
> As you've discovered, you'll quickly get frustrated trying to develop
> interactively. But it's very valuable for poking at what you're
> developing. Typically, I don't write more than a dozen lines or so
> before trying it out.
so... if I made a def. in the prompt on the "normal" way, I can't change
it with notepad, and if I type it in notepad, i can only run it with
python - i etc.? Or is there a way to run that defs IN python? Do you have
to put the defs in another dir.? Do you have to change the path of python?
how? isn't it possible that way?
As was previously mentioned, check out Ptui or PythonWin (I use Ptui
myself). Ptui has an interactive shell that acts like the command line
interpreter except that it keeps a history of previous commands ala readline
and cut and paste works correctly. It also features an editor with syntax
highlighting and smart indentation among other things. I believe PythonWin
has a similar feature set, but it's been a while since I've used it.
Unfortunately, I don't have the URL for PTUI or PythonWin handy, but I'm
sure that the search engine at www.python.org would turn them up.
[...]
-tim
Tim Hochberg wrote:
What is Ptui or Pythonwin?I have still one question: If I defined a def in
Python, I can't find a file. Is it right that I can't edit defs defined in
python "Itself"?
And how do I run the defs defined with an editor? Ok, with that command line,
but I mean, when I'm just starting python? Or is
the python prompt only meaned for testing things, trying if things are possible?
If I make a def like:
def hello(name):
print "Good morning, dear", name, "It's nice to meet you!"
How does it look in a file then, because the filename is the def. name?
Or do I understand it wrong now? If so, can someone please explane me how a
file/def/program etc works, or show me a link
I haven't found?
Please?
Gerrit,
Rietzanger weg 29,
1111 VG Diemen
The Netherlands
> [...]
>
> -tim
>so... if I made a def. in the prompt on the "normal" way, I can't change
>it with notepad, and if I type it in notepad, i can only run it with
>python - i etc.? Or is there a way to run that defs IN python?
Yes. Cut and paste from Notepad to Python (and sometimes vice versa, using
the buttons at the top of the window rather than cntl-V). I have had great
success with writing from 1 to about 20 lines of code, running the block, and
either revising and going on to the next depending on the result.
Open Python (I still use 1.4 DOS version for reason given below) in maximized
DOS/console window (they are *almost* same thing). Open Notepad sized to
full width but with top down to expose Python window paste button.
In 1.3 and 1.4 win95/nt versions of python -- in console mode -- paste only
works if one clicks properties, then the other tab (far right), then unchecks
'fast paste' in the Other box. But then paste works slowly -- at the speed
of a fast human, instead of 'instantaneously' -- so slowly that it usually
take more time than python takes to execute the fragment pasted in (for the
fragments I tend to write.) I have not checked Windows 1.5.x yet for better
behaviour in this regard.
Terry J. Reedy
With just the standard python interpreter, no you can't. I believe you
can with Ptui, and I'm not sure about Pythonwin. Ptui is a debugging
environment for python--it should be in the contributed software listed
at python.org.
> And how do I run the defs defined with an editor? Ok, with that command line,
> but I mean, when I'm just starting python? Or is
> the python prompt only meaned for testing things, trying if things are
possible?
>
> If I make a def like:
> def hello(name):
> print "Good morning, dear", name, "It's nice to meet you!"
>
> How does it look in a file then, because the filename is the def. name?
> Or do I understand it wrong now? If so, can someone please explane me how a
> file/def/program etc works, or show me a link
> I haven't found?
If you just enter the definition for hello at the interpreter prompt,
you run it with:
hello("Gerrit")
because you have made "hello" a global--it doesn't belong to a module.
(python files are called modules.) You can also put it in a file, say
myjunk.py, and run it in the interpreter like this:
import myjunk
myjunk.hello("Gerrit")
Then you can edit the file. (If you make a change and want to run the
new code in the same interpreter session, you must do:
reload(myjunk)
before you rerun myjunk.hello.)
Sorry if this is not what you were asking. I think these things are
covered in the tutorial and Reference Manual.
Most of the tutorial is meant to be run from the interpreter (for
more complex examples you have to type rather well.... :-| This is
the advantage of using Ptui.)
I've only used Ptui a bit, and never Pythonwin, so I can't contribute
much on how you do things in those environments.
sue
This is right. What you type into Python is executed but not stored
anywhere, really. For serious Python programs you should use a file.
> And how do I run the defs defined with an editor?
Suppose you have a file called "stuff.py" that has your hello function
inside. Run python, then do this:
>>> import stuff
>>> stuff.hello('jason')
Good morning, jason!
The hello() function is found in the module "stuff". Typically,
"stuff.py" will have to be in your current directory or the Python
lib directory. (actually one of the directories in your PYTHONPATH)
Maybe you'd prefer to use your function without typing "stuff.hello".
Try this:
>>> from stuff import *
>>> hello('jason')
Good morning, jason!
...although when you really sit down to implement it, this function
should check the system clock and determine the proper greeting for
the time of day.
> Or is the python prompt only meaned for testing things,
> trying if things are possible?
Exactly!
--
Jason