Welcome, Guest
Username: Password: Remember me

TOPIC: Inconstitent variable separator (runSELAFIN.py)

Inconstitent variable separator (runSELAFIN.py) 11 years 8 months ago #7921

  • jeremie
  • jeremie's Avatar
  • OFFLINE
  • Junior Boarder
  • Hydro-Quebec
  • Posts: 39
  • Thank you received: 7
Hello all,

I've been recently automating some tasks on our cluster and have found great use in the different pytel scripts that have been recently ported in python.

My question concerns a tiny detail in the selafin file utility. The runSELAFIN.py script allows the user to specify a list of variables to extract from a *.slf file (option -v). The following help tip is provided for this option :
-v XVARS, --vars=XVARS
specify which variables should remain (','-delimited)

However, delimiting the variables with "," does not return the expected result. I've had a look at the SELAFIN parser and found that the split operation of the variables list (vars) is actually performed on a ";" character. See line 198 of parserSELAFIN.py:
198   v = vars.split(';')

Since I'm planning to provide the vars list automatically to the runSELAFIN.py, I would like to know whether this is just an inconsistency between the help tip and actual behaviour and what is the right separator to use.This will allow me to ensure my code is portable with future versions of the pytel scripts. For the time being, I'm using ";" with success.

Thanks,


j
The administrator has disabled public write access.

Inconstitent variable separator (runSELAFIN.py) 11 years 8 months ago #7931

  • sebourban
  • sebourban's Avatar
  • NOW ONLINE
  • Administrator
  • Principal Scientist
  • Posts: 814
  • Thank you received: 219
Hello Jeremi,

You are right to point this out. We are about to change these all and make them consistent between scripts.

The reason for the mess is that we started on windows with ";" and realised later that ";" on linux would split you command line instead of being interpreted as a character. Hence, with some other developments on Linux it resulted with inconstistency.

It is something we have to fix. It is probable we will use ":" as a separator in the future. ... unless you would like to advise something else ?
The administrator has disabled public write access.

Inconstitent variable separator (runSELAFIN.py) 11 years 8 months ago #7936

  • jeremie
  • jeremie's Avatar
  • OFFLINE
  • Junior Boarder
  • Hydro-Quebec
  • Posts: 39
  • Thank you received: 7
Hello Sebastien,

A simple solution (on linux at least) could be to quote the variable list.
Protecting the list with single or double quotes will escape the ";". Another, less elegant, way would be to escape the ";" directly with a backslash (\).

For example, the following work for me to extract VITESSE UV and HAUTEUR D'EAU:
./runSELAFIN.py scan -v 'VITESSE;HAUTEUR' RES.slf
./runSELAFIN.py scan -v "VITESSE;HAUTEUR" RES.slf
./runSELAFIN.py scan -v VITESSE\;HAUTEUR RES.slf

but not
./runSELAFIN.py scan -v VITESSE;HAUTEUR RES.slf
It will try to split the instructions and complain about command HAUTEUR not being found.

So, if you want to keep the ; separator, you could simply ask the user to quote the variable list. That's really a question of taste. I think, on linux, the general philosophy is to quote separators when they are specified at the command line. For example, the cut and awk utilities can be invoqued like this:
cut -d ';' [.....]
awk -F ';' [....]

I will stay tuned for future updates in you script. They have helped me a lot to understand how to parse an slf, and save us time when transferring results over the network. Keep up the good work.

j
The administrator has disabled public write access.
Moderators: borisb

The open TELEMAC-MASCARET template for Joomla!2.5, the HTML 4 version.