10.05.2011 19:08, Jean-Baptiste Marquette kirjoitti:
Hi Pierre,

I got the solution from another Jython user :

        OpenCat.cmd_select('startsWith(StarId, "'+Champ+'")').write(CatChamp, fmt='ascii')

The argument to cmd_select is a python string, and its content must have the Java-like syntax 
required by STILTS's expression language, which is uses double-quotes 
to quote string literals.
Also, I don't know which language you used to write, but in both Java and Python you normally only use capital first letters in class names. This current style you have makes it much more difficult to read your code.

JB Marquette

Le 10 mai 2011 à 18:03, Pierre Thibault a écrit :

2011/5/10 Jean-Baptiste Marquette <marquett@iap.fr>
Hi all,

This is my first attempt to use Jython, I wrote the following code :

#!/usr/bin/env jython

# Construit les catalogues par champ

import sys
import glob
sys.path.append('/star/starjava/etc/ttools')
import stilts

for ChampList in glob.glob('*.chplst'):
   Obj = ChampList[0:2]
   Cat = Obj + '_all.dat'
   OpenCat = stilts.tread(Cat, fmt='ascii')
   OpenList = stilts.tread(ChampList, fmt='ascii')
   for Champ in OpenList.coldata(0):
       CatChamp = Champ + '.dat'
       print Champ, 'processing'
       OpenCat.cmd_select('startsWith(StarId, "Champ")').write(CatChamp, fmt='ascii')


The module stilts contains cmd_select and startsWith. This function searches for the string contained in Champ (for example 'bs300') at the beginning of the string in StarId (for example 'bs3000k7012'). But "Champ" is interpreted as a string itself, so I got empty files CatChamp but the header, because there is no StarId starting with the string 'Champ'.

Thus, what could be the correct syntax to use for the variable Champ ?

Write Champ instead of "Champ" in quote. Or an expression of type String. Or I don't understand....
 

Thanks for your help,

JB Marquette


------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users



--


A+

-------------
Pierre
My blog and profile (http://pierrethibault.posterous.com)
YouTube page (http://www.youtube.com/user/tubetib)
Twitter (http://twitter.com/pierreth2)

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users


------------------------------------------------------------------------------ Achieve unprecedented app performance and reliability What every C/C++ and Fortran developer should know. Learn how Intel has extended the reach of its next-generation tools to help boost performance applications - inlcuding clusters. http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________ Jython-users mailing list Jython-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jython-users