Re: [ANN] vim patch to support python3 interface

2009-05-25 Thread Roland Puntaier
vim_...@googlegroups.com schrieb am 21.05.2009 14:27:13:

> 
> On 12/05/09 18:35, Roland Puntaier wrote:
> > Hello,
> >
> > I have ported vim's python interface (if_python.c) to the python3 
C-API.
> >
> > The changed files are:
> > - Makefile (for linux)
> > - Make_mvc.mak (for windows)
> > - if_python3.c is a new file for the python3 related sources. it is 
based
> > on if_python.c.
> >
> > All of them are in the ``src`` subdirectory.
> [...]
> 
> Make_mvc.mak is not, and by far, the only makefile used by people who 
> build Vim on Windows.
> [...]

My solution regarding the build process is rather provisionary.
I'll work out a solution that encompasses all makefiles.

I'll send a follow-up.

Best regards,
Roland

-- 
http://mail.python.org/mailman/listinfo/python-list


strange list comprehension on generator

2007-08-29 Thread Roland Puntaier
def changeOne(aa,idx):
  aa[idx]=not aa[idx]
  yield aa
  for i in range(idx):
for x in changeOne(aa,i):
  yield x

def changeOneOrder(aa):
  yield aa
  for i in range(len(aa)): 
for x in changeOne(aa,i):
  yield x

a=[False]*3
og=changeOneOrder(a)
#this does not return the way I would expect. why?
list(og)
#returns
#[[False, False, True], [False, False, True], [False, False, True], 
[False, False, True], [False, False, True], [False, False, True], [False, 
False, True], [False, False, True]]


#this works as expected
a=[False]*3
og=changeOneOrder(a)
og.next()
og.next()
...

#this works as expected
def ty():
  yield 1
  yield 2
  yield 3

tg=ty()
list(tg)

cheers, Roland

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE

2007-06-20 Thread Roland Puntaier
Hi,

With a python-enabled VIM it's possible to execute and thus test the 
python code. I have the following lines in my vimrc.
F2 prints the result of a line evaluation on the bottom or in a window 
named pyout if there. I open pyout with ":vert rightb new pyout" mapped to 
F1.
F4 does the same on the selected part of a line
F3 evaluates without printing


py import vim

py << EOL
def PyOutput(): 
  iPy=-1
  for i in range(len(vim.buffers)):
if vim.buffers[i].name and vim.buffers[i].name.find("pyout")!=-1:
  iPy=i
  return iPy
EOL

"pyout if present must be right below
"r replaces, p prints, symb sets the start
py << EOL 
def PrintCurrentLine(*args): 
  cur_str = vim.current.line 
  action, symb = None, None 
  for i in args: 
if i in ["r","p"]: action = i 
else:  symb   = i 
  try:start = cur_str.rindex(symb)+len(symb) 
  except: start = 0 
  eval(compile("pyoutres="+cur_str[start:],'','exec'),globals()) 
  result = eval("pyoutres",globals()) 
  if action == "r": 
vim.current.line = cur_str[:start]+str(result) 
  else: 
iPy=PyOutput()
if iPy != -1:
  resS=">>> "+cur_str+":"+'\n'+str(result)+'\n'
  resL=resS.split('\n')
  vim.buffers[iPy].range(0,0).append(resL)
  vim.command("wincmd b")
  vim.command("normal gg")
  vim.command("wincmd p")
  vim.command("wincmd j")
else:
  print result
EOL 
command -narg=* Pyl python PrintCurrentLine() 

map  :py PrintCurrentLine()

"this evaluates selected region with 
map  "tyo^["tpu
map  :vert rightb new pyout


python << EOL 
def EvaluateCurrentRange(): 
  c_r=vim.current.range
  i=0
  while c_r[0].startswith(' '*(i+1)):
i+=1
  rngstr='\n'.join([ln[i:] for ln in c_r])
  eval(compile(rngstr,'','exec'),globals()) 
EOL 
map  :py EvaluateCurrentRange()




[EMAIL PROTECTED] schrieb 
am 19.06.2007 17:20:08:

> Bjoern Schliessmann wrote:
> > BartlebyScrivener wrote:
> >> VIM
> > 
> > *clap-clap*
> > 
> > BTW, are there tutorials on the more arcane vim functions that come
> > in handy with Python?
> > 
> > Regards,
> > 
> > 
> > Bj?rn
> > 
> Not a tutorial, but I found this little snippet:
> 
> http://www.ibiblio.org/obp/pyBiblio/tips/elkner/vim4python.php
> 
> I thought the last line was especially neat.
> 
> Will
> -- 
> http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: c[:]()

2007-06-04 Thread Roland Puntaier
Hi,

I have started to look into the last postings. It is funny and sad how 
people talking the same language cannot understand each other.
I have become curious on what exactly you mean.

Warren, can you please restate your point. 
When doing so, please define every identifier or non-plain english word 
before you use it and be concise.

e.g.
You cannot use b if it is not clear what it means. 
When writing "c[:]()" there is no "b". So where does "b" come from?
You told us that "b" is a container (*), but where should the python 
interpreter or the people take it from.

People start to guess, as I did:
  (1) - Might you mean: "b() for b in c". (I use python syntax here)
This means c is a container, an undertanding that is supported 
also by the used slicing ("[:]").
  (2) - Let's suppose that by (*) you mean that, in addition to "c", "b" 
is a container, too.
  (3) - Now for a standard container "b()" does not make sense. Maybe you 
mean "b[:]()" according to the guessed interpretation (1).
This would then be a recursive evaluation of all functions with no 
parameters in a tree ("tree" in the informatics sense).
  (end of my guess)
 

I think somehow it should be possible to convey an idea so that others can 
grasp it.
If it does not work the first time, it is good to clarify the points that 
one found others to misunderstand.
Otherwise one risks to be regarded as esoteric.

Thanks, Roland

-- 
http://mail.python.org/mailman/listinfo/python-list


Antwort: How to calculate definite integral with python

2007-05-15 Thread Roland Puntaier
Searching the web I have found:

from numpy import *
def simple_integral(func,a,b,dx = 0.001):
  return sum(map(lambda x:dx*x, func(arange(a,b,dx
simple_integral(sin,0,2*pi)


Or in
http://pylab.sourceforge.net/
quadrature.py

Cheers.

[EMAIL PROTECTED] schrieb 
am 15.05.2007 04:23:00:

> I'm trying to do some integral calculation. I have searched the web, but 

> haven't found any useful information. Will somebody point me to the 
> right resources on the web for this job ?
> 
> Thanks a lot.
> 
> ps. Can numpy be used for this job?*
> *
> -- 
> http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to mimik a main() function to start a program with entry point?

2007-01-19 Thread Roland Puntaier
Hi,

>From a python module you could use subprocess  and start the exe. Normally 
one must leave it to the OS to load a binary module, because there are 
certain things done during loading.
Nevertheless the location of the entry point is coded in the binary file 
format (e.g. PE for windows or ELF for Linux)
Whether it is possible from python to make an import of a python module in 
a python package gone through py2exe, I cannot answer.

But I think you mean how to tell py2exe, where the entry point is. Read: 
http://www.py2exe.org/index.cgi/Tutorial

Roland

[EMAIL PROTECTED] schrieb 
am 19.01.2007 14:30:33:

> hello all.
> I have one simple query and may be that's to stupid to answer but I am
> not finding the answer any ways.
> I have a set of modules in my package and out if which one is my
> actual starting point to my entire program.  say for example I have an
> entire database application ready and I want a main (as in java or c)
> to initiate the program and may be bring up a login screen and then
> pass the control on to the main window.
> if I am giving raw source code that is easy because I will tell user
> to run the command ./xyz.py which has that function.
> but if I freze it into an executable with py2exe for example , how do
> I solve this problem?
> thanks.
> Krishnakant.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


Antwort: Re: SubProcess _make_inheritable

2007-01-11 Thread Roland Puntaier
Thanks for pointing me to the tracker.
I've seen there is already an entry for this:
[ 1603907 ] subprocess: error redirecting i/o from non-console process 

Roland

Gabriel Genellina <[EMAIL PROTECTED]> schrieb am 11.01.2007 05:24:03:

> At Wednesday 10/1/2007 13:10, Roland Puntaier wrote:
> 
> >SubProcess.py needs to be patched - at least in 2.4 -  to work from
> >windows GUIs:
> >
> > def _make_inheritable(self, handle):
> > """Return a duplicate of handle, which is inheritable"""
> > if handle==None: handle=-1
> > return DuplicateHandle(GetCurrentProcess(), handle,
> >GetCurrentProcess(), 0, 1,
> >DUPLICATE_SAME_ACCESS)
> 
> You should submit it to the tracker, not post here and hope someone 
> would notice...
> http://sourceforge.net/tracker/?group_id=5470
> 
> Anyway, I don't see in which case would handle be None.
> 
> 
> -- 
> Gabriel Genellina
> Softlab SRL 
> 
> 
> 
> 
> 
> 
> __ 
> Preguntá. Respondé. Descubrí. 
> Todo lo que querías saber, y lo que ni imaginabas, 
> está en Yahoo! Respuestas (Beta). 
> ¡Probalo ya! 
> http://www.yahoo.com.ar/respuestas 
> 
> 
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


SubProcess _make_inheritable

2007-01-10 Thread Roland Puntaier
SubProcess.py needs to be patched - at least in 2.4 -  to work from 
windows GUIs:

def _make_inheritable(self, handle):
"""Return a duplicate of handle, which is inheritable"""
if handle==None: handle=-1
return DuplicateHandle(GetCurrentProcess(), handle,
   GetCurrentProcess(), 0, 1,
   DUPLICATE_SAME_ACCESS)
-- 
http://mail.python.org/mailman/listinfo/python-list


call graph using python and cscope

2007-01-10 Thread Roland Puntaier
""" 
Sometimes it is nice to have the data used by cscope accessible in a 
programatic way.
The following python script extract the "functions called" information 
from cscope (function: callGraph)
and produced an html file from them.

  from csCallGraph import *
  acg=callGraph(entryFun,workingDir)

entryFun is the function to start with (e.g. main)
workingDir is the directory where cscope.out is located

As a script it can be called like:
  csCallGraph main > myprogram.html
"""

import subprocess , os, sys

def functionsCalled(entryFun,workingDir):
  cmd = "cscope -d -l -L -2%s"%entryFun
  process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, 
cwd=workingDir) 
  csoutput= process.stdout.read() 
  del process
  cslines=[arr.strip().split(' ') for arr in csoutput.split('\n') if 
len(arr.split(' '))>1]
  funsCalled={}
  for fl in cslines:
if funsCalled.has_key(fl[0]):
  funsCalled[fl[0]]|=set([fl[1]])
else:
  funsCalled[fl[0]]=set([fl[1]])
  allFuns=set(map(lambda x:x[1],cslines))
  return (allFuns,funsCalled)

def callGraph(entryFun,workingDir,cg={}):
  if not cg.has_key(entryFun): 
allFuns,funsCalled=functionsCalled(entryFun,workingDir)
cg[entryFun]=funsCalled
for af in allFuns:
  cg=callGraph(af,workingDir,cg)
  return cg

def textCallGraph(acg):
  innerFuns=[(f,d,len(reduce(lambda x,y:x|y,d.values( for f,d in 
acg.items() if len(d)>0 ]
  leafFuns=[(f,d,0) for f,d in acg.items() if not len(d)>0 ]
  innerFuns.sort(lambda x,y: y[2]-x[2])
  innerLen=len(innerFuns)
  leafLen=len(leafFuns)
  title=lambda aFun: '\n' + aFun + '\n' + '-'*len(aFun)
  def ff(aFun,funsCalled):
fileFuns=zip(funsCalled.keys(),[''+',\n '.join(funsCalledInFile) 
for funsCalledInFile in funsCalled.values()])
funIn=lambda f: '\n%s in '%f
return title(aFun) + funIn(aFun) + funIn(aFun).join(map(lambda 
x:'%s:\n%s'%(x[0],x[1]),fileFuns))
  strInner='\n'.join([ff(f[0],f[1]) for f in innerFuns])
  strLeaves='\n'.join(map(lambda x:title(x[0]),leafFuns))
  return strInner+'\n'+strLeaves

def funWeights(acg):
  funWeights=dict([(f,reduce(lambda x,y:x|y,d.values())) for f,d in 
acg.items() if len(d)>0 ]+
  [(f,[]) for f,d in acg.items() if not len(d)>0 ])
  weights={}
  def calcWeights(af):
if not weights.has_key(af):
  subFuns=funWeights[af]
  weights[af]=1
  for f in subFuns:
calcWeights(f)
weights[af]+=weights[f]
  for af in funWeights.keys(): calcWeights(af)
  return weights

def htmlCallGraph(acg):
  funW=funWeights(acg)
  innerFuns=[(f,d,funW[f]) for f,d in acg.items() if len(d)>0 ]
  leafFuns=[(f,d,0) for f,d in acg.items() if not len(d)>0 ]
  #innerFuns.sort(lambda x,y: y[2]-x[2]))
  def cfun(a,b):
if b > a:
  return 1
elif b < a:
  return -1
return 0
  innerFuns.sort(lambda x,y: cfun(x[2],y[2]))
  innerLen=len(innerFuns)
  leafLen=len(leafFuns)
  funDict=dict(zip(map(lambda x:x[0],innerFuns)+map(lambda 
x:x[0],leafFuns),range(innerLen+leafLen)))
  title=lambda aFun: '' + aFun + ' 
(%i)'%funW[aFun] + '\n'
  def ff(aFun,funsCalled):
fun=lambda y:''+y+''
fileFuns=zip(funsCalled.keys(),[',\n'.join(map(fun,funsCalledInFile)) 
for funsCalledInFile in funsCalled.values()])
funIn=lambda f: '%s in '%f
return title(aFun) + funIn(aFun) + funIn(aFun).join(map(lambda 
x:'%s:\n%s'%(x[0],x[1]),fileFuns))
  strInner='\n'.join([ff(f[0],f[1]) for f in innerFuns])
  strLeaves='\n'.join(map(lambda x:title(x[0]),leafFuns))
  return '\n\n'+strInner+'\n'+strLeaves+"\n\n"

if __name__ == '__main__':
  if len(sys.argv) < 2:
  print 'Usage: csGragh.py entryFunction'
  sys.exit()
  entryFun=sys.argv[1]
  workingDir=os.getcwd()
  acg=callGraph(entryFun,workingDir)
  print htmlCallGraph(acg)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: array, a better shell

2006-12-20 Thread Roland Puntaier
>I have also used the shell of Mathematica. It's quite powerful and it
>can show graphics too inlined, but globally I don't like it fully
>because it makes editing small programs a pain (for me)...

I use Vim to edit python code and can execute any selection (F3) or single 
lines (F2) 
whenever I want to (Vim must be built to include the python interpreter).

Here is the according Vimrc code

"pyout if present must be right below
"r replaces, p prints, symb sets the start
py << EOL 
def PrintCurrentLine(*args): 
  cur_str = vim.current.line 
  action, symb = None, None 
  for i in args: 
if i in ["r","p"]: action = i 
else:  symb   = i 
  try:start = cur_str.rindex(symb)+len(symb) 
  except: start = 0 
  eval(compile("pyoutres="+cur_str[start:],'','exec'),globals()) 
  result = eval("pyoutres",globals()) 
  if action == "r": 
vim.current.line = cur_str[:start]+str(result) 
  else: 
iPy=PyOutput()
if iPy != -1:
  resS=cur_str+"=="+'\n'+str(result)+'\n'
  resL=resS.split('\n')
  vim.buffers[iPy].range(0,0).append(resL)
  vim.command("wincmd b")
  vim.command("normal gg")
  vim.command("wincmd p")
else:
  print result
EOL 
command -narg=* Pyl python PrintCurrentLine() 
map  :py PrintCurrentLine()

python << EOL 
def EvaluateCurrentRange(): 
  c_r=vim.current.range
  i=0
  while c_r[0].startswith(' '*(i+1)):
i+=1
  rngstr='\n'.join([ln[i:] for ln in c_r])
  eval(compile(rngstr,'','exec'),globals()) 
EOL 
map  :py EvaluateCurrentRange()
-- 
http://mail.python.org/mailman/listinfo/python-list