paul,
@paul@fedi.nlpagan.net avatar

I'm working on removing an important spreadsheet from Google Docs, and maintain that in LibreOffice.
Thing: In G Docs I wrote a few macros to sort the file in various ways, using 4 and 5 fields.
Libre Calc only allows 3 sort fields, and the G-Doc macros don't work in Libre Calc.

I've written a #Python program to convert a CSV to a file with fixed length, and writing a #COBOL program to do the sorting for me.

Sorting multiple columns in Python is a PITA. In COBOL it's laughably simple.

I wish something like the IBM S/34 #GSORT would exist for Linux. That would make this even simpler.

wtm,

@paul
I don't know about COBOL, but I wouldn't consider multisorting very difficult/PITA in python. Of course it's totally subjective.

Do you have code which you've been trying in Python and how the same thing looks in COBOL?

paul,
@paul@fedi.nlpagan.net avatar

@wtm I've only looked at the options for Python.

In COBOL it's simply
SORT LIB-WORK
ON ASCENDING KEY S_GENRE, S_SORTNAAM, S_VN, S_TITEL
USING LIB-IN
GIVING LIB-OUT1.

SORT LIB-WORK
ON ASCENDING KEY S_SORTNAAM, S_VN, S_TITEL
USING LIB-IN
GIVING LIB-OUT2.

paul,
@paul@fedi.nlpagan.net avatar

@wtm I want to sort a 23 column list/array in 2 different ways.

tshirtman,
@tshirtman@mas.to avatar

@paul @wtm if you have your csv loaded as a list of dicts, you can do file_out = sorted(file_in, key=lambda x: (x["key1"], x["key3"]))

paul,
@paul@fedi.nlpagan.net avatar

@tshirtman I load the CSV simply using readlines(). I found that sorted-option, but the loaded CSV misses those 'key' thingies. (I'm still puzzled about that, I'm an old-fashioned programmer, as COBOL may indicate ;-)

@wtm

tshirtman,
@tshirtman@mas.to avatar

@paul @wtm yeah. readlines read text, doesn't try to convert to anything smart, that's on purpose, you can use CSVDictReader to get that.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • Durango
  • magazineikmin
  • mdbf
  • thenastyranch
  • khanakhh
  • rosin
  • Youngstown
  • ethstaker
  • slotface
  • modclub
  • kavyap
  • DreamBathrooms
  • everett
  • ngwrru68w68
  • JUstTest
  • InstantRegret
  • tacticalgear
  • GTA5RPClips
  • cubers
  • normalnudes
  • osvaldo12
  • tester
  • anitta
  • cisconetworking
  • megavids
  • Leos
  • provamag3
  • lostlight
  • All magazines