[Tutor] Python 2.2... os.exec catch stdout

2009-06-04 Thread Chris Mueller
*Hello.

I am relegated to running python 2.2; so I do not have access to subprocess.

In my script; at one point, I need to run a program; interact with the
program; exit the  program; and parse the output printed to stdout.

This would be simple; if I did not need to interact with my sub-program.  I
currently have..

import os
program = "vim"
arguments = ["myFile"]
pid = os.fork()
if not pid:
os.execvp(program, (program,) + tuple(arguments))
os.wait()[0]

This works fine; lets me interact with "vim" fine; and return to the python
script when I am done; but I do not seem to be able to execute read stdout;
and all examples I have found on the net do not allow me to interact with
the called program.

Any pokes int he right direction?

Thanks,
Chris
*
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Best Python Editor

2009-06-15 Thread Chris Mueller
for note; full tag completion and tag support can be used in vim via
omnicompletion and taglists.  Full class support/heiarchy + printing of the
docscrint as you ctrl-n through each completion in the preview window.
Extremly useful when using someone else's library or for remembering what to
pass in; and mostly native to vim.

I have never used a debugger (i usually use break points and prints, with a
quick e to run and examine output); but I would assume it's there if
you want it as I have seen GDB integration (as well as any VCS you would
want, which suprises me that has not come up yet.)

It just comes down to whether you want ot make the learning investment or
not.  After using it for awhile; your workflow just; well; flows. This to me
is the biggest complement to an editor.

Thanks,
Chris

On Sun, Jun 14, 2009 at 10:16 AM, Wayne  wrote:

> On Sun, Jun 14, 2009 at 5:55 AM, Tom Green  wrote:
>
>> Since VIM seems to be the editor of choice and I have been programming in
>> Python for many years using Pyscripter and Eclipse I was wondering how I
>> could transition away from the IDE world to VIM.  My main issue is how do I
>> go about using VIM to debug my code?
>
>
> I usually use print statements and/or raw_input's if you want break points.
>
>
>> With Pyscripter and other IDES its as simple as placing a breakpoint and
>> pressing F7 to step thru the code and you have the ability to see the
>> variable values etc.
>
>
> I know you can do some similar things with the python debugger but I've
> honestly never used it that much (or worked on a project large enough I
> needed to!)
>
>
>> Also, with an IDE such as Pyscripter when calling a function a nice
>> balloon hint appears showing you the number of parameters and their types.
>
>
> It's not precisely the same thing, but you can fold multiple lines, which
> allows you to have only the top line of a function showing. I find that
> rather helpful, and ctrl-n autocompletes the function name. Then you can
> mark the location with m then a-to-z (I use c as a mnemonic for 'current')
> then move on top of the name and push * - that will find the next occurence
> of the word, which is often the function declaration. I just hit "n" (next)
> until I find it, if that's not the case. Then I type ` (the one over the
> tilde) then c which takes me back to my 'current' location. If you really
> wanted, though, you could also have horizontal split of the same file, and
> you could probably write a macro that would move to that window/buffer and
> find the function declaraition (so it would search for def  under cursor>). I don't know precisely how the dropdown autocomplete menu
> works but you could also probably edit your script to add parameters for the
> function call just like an IDE.
>
>
>>   Coming from a Visual Studio background this is great, as I might be
>> calling a function or method and I don't know off hand the values.  Maybe
>> someone could share how they go about programming a good size program with
>> VIM as I would like to use it.  Don't get me wrong for quick programs I will
>> use VIM or notepad, but when it comes to building a OOP program I find
>> Eclipse or Pyscripter much easier to use.
>
>
> I suppose that's probably the case for a few people - and certainly the
> reason those tools exist in the first place. If I were working on a quite
> large program I might consider using an IDE, but in reality I'm probably
> just as comfortable jumping around code to look for the information I need
> as I would be using an IDE.
>
> HTH,
> Wayne
>
>
>> On Sun, Jun 14, 2009 at 12:54 AM, Eddie  wrote:
>>
>>> I downloaded the previous version of PyScripter although couldn't get
>>> it to work and after googling it, I downloaded Python Portable 1.1
>>> (Python 2.6.1 as most sites/books recommend this and not 3) which has
>>> PySCripter included and this then works fine.Ii also downloaded Komod0
>>> 5.1 and after messing around with these, I think I prefer PyScripter
>>> and will use that for the mean time.
>>>
>>> I'll also take a look at VIM as being able to use the same program for
>>> PHP/CSS/HTML (and Basic if it supports it) as well as hopefully Python
>>> (I've only just started learning it) would be an advantage.
>>>
>>> Thanks guys
>>> Eddie
>>>
>>> 2009/6/14 Mike Hoy :
>>> >>
>>> >>
>>> >> I really like using F5 to run my code, so you can put in your .vimrc
>>> so
>>> >> you don't have to type it, or just type it every time:
>>> >>
>>> >> map  :!python %
>>> >>
>>> >> and every time you hit  it will run your current script.
>>> >>
>>> > Thanks for that. It's even better than typing :!python % because it
>>> doesn't
>>> > spawn a shell separate from the Vim window.
>>> >
>>> > ___
>>> > Tutor maillist  -  Tutor@python.org
>>> > http://mail.python.org/mailman/listinfo/tutor
>>> >
>>> >
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> http://mail.python.org/mail

[Tutor] "Snack" python-newt version incompatibilities.. (anaconda kickstart)

2009-11-16 Thread Chris Mueller
Hello all.

I'm working on a CentOS 5.2 kickstart interface; and have been happily using

%pre --interpreter /usr/bin/python

to do my management for awhile now with the snack module.  My problem
comes in when I am attempting to use the snack.EntryWindow function;
and setting default values.

The simplified version of my code is below...

(default1,default2,default3,default4)=('1','2','3','4')
#These are all of my prompts.
prompts = [('Static1',default1), ('Static2',
default2),('Static3',default3),('Static4',default4)]
ok, params = snack.EntryWindow(screen, "This is my title",
   "This is my text at top of box",
   prompts,
   help = "")

On my desktop, I have...
$>python -V
Python 2.5.2
The defualt python in CentOS5.2 is..
$>python -V
Python 2.4.3

The snack window behaves as expected on my desktop (default values all
populate and change values as I want/expect), but when I try and run
on the 2.4 python, i get the following(output cleaned up a little bit
as it splays the entire window)...


File "/usr/lib/python2.4/site-packages/snack.py", line 796, in EntryWindow
sg.setField(e, 1, count, anchorLeft = 1)
File "/usr/lib/python2.4/site-packages/snack.py", line 388, in setField
(what.__dict__.has_key('g')):
AttributeError: 'str' object has no attribute '__dict__' selects

With some googling, I managed to find references to a bug in the
python snack module that was fixed, but I was unable to find a working
format of the "prompts" variable to work in my Python 2.4.3.

I tried the above code, as well the suggestion from the link below of

prompts = [Entry(20, 'ham'), Entry(20, 'egg', hidden=True)]

But to no avail. Any help would be greatly appreciated...

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=340366

Thanks,
Chris
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor