Python Forum
expressing data in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
expressing data in python
#1
i love how python syntax stays simple through many complicated nestings. that works for code but not for data. lists end with a ] and dictionaries end with a } even if the data is spread over multiple lines. i wish the ending could be made optional in multiline data where nested data is indented.

for example:
modes = {
    'r': 4,
    'w': 2,
    'x': 1,
names = [
    'foo',
    'bar',
and maybe the , is not needed in these cases, too.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
All this was set in stone thirty years ago. It would be a new language...
Reply
#3
it could be an incremental change by being optional. i don't see any cases where leaving out the ending ] or } would present any meaning different than my suggestion. even leaving out the , at the end of a line presents no different meaning. it's either an error (no meaning at all) or it can be understood.

modes = {
    'r': 4
    'w': 2
    'x': 1
names = [
    'foo'
    'bar'
there is no ambiguity. what else can it mean? if we choose to let it have the one and only meaning it could have, how would it still not be python? of course it is a "major" change, so it cannot be part of python 3.x.

i could argue that f-strings should have been done in 4.0.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
Here is the first issue:
>>> [
...     'foo'
...     'bar'
... ]
['foobar']
Reply
#5
so the commas have to be there since this is a case where it ignores end of line.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
I have simple question: why?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#7
I think it'd be easier to make a new file format, that sort of looked like python/json, and you could write a simple parser to convert it into actual python data types.
Reply
#8
(Jan-05-2020, 07:16 PM)perfringo Wrote: I have simple question: why?
why what?

originally i just wanted to make data, in a text-like form, look like python looks by doing nesting through indentation and having unindent be the end of nesting. i have been coding a lot stuff that does cloud API calls with so much similarity that i could express the many different calls by just different dictionaries used a as method keyword indexes. i started having lists of dictionaries and from there even more, all done through the same code making the actual call. while coding all this data, i realized my code was going back to having incremental symbol based unindenting. each list ends with ]. each dictionary ends with }. those have to be somewhere so it meant either a new line or appending everything to the last line of data.

then i noticed so many data lines ending ,. so i thought about removing those. that would have to be a totally new format.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  expressing an 8-bit ASCII code Skaperen 2 1,913 Jan-16-2020, 01:39 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020