Python Forum
a form of coded logic in a comand line
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a form of coded logic in a comand line
#1
i am wanting to come up with an easy way to express Python logic in a single line of tokenized text like that which comes from command arguments in sys.argv. the way it can be done, now, is by having each token be a whole code line, preceded by spaces for the indentation. my goal is to come up with another way to express Python logic as tokenized text which is simpler for a human to type in within the constraints of command line arguments. the existing means is simple to convert to use with the "python -c" command. my goal is to shift most of the burden of expression from human to computer. then the new form would be converted for use with the "python -c" command. this new form may well have no indentation at all, such as a C-like form. but it doesn't have to be C-like. this is a form intended for short logic that can fit on a command 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
#2
Why? What is the use case for such a thing?
Gribouillis likes this post
Reply
#3
(Feb-26-2022, 10:22 AM)ndc85430 Wrote: Why? What is the use case for such a thing?
to be able to include logic within a command typed in at a CLI as part of that command's arguments. i've been doing this with a few languages but none are compact enough for quick one-time code. for example, python takes much effort to get the indentation right (in a command 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
#4
Can you show examples of the kind of thing you mean? Why wouldn't you just write the code in a file?
Reply
#5
writing the code in a file is an extra step making the effort more burdensome. this would be code to type in quickly as part of doing a quick command. well, at least i do commands quickly.
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 no examples, yet. if you can't imagine any, you probably don't do commands as much as i do (2000-6000 a day).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
In Bash, if you type Ctrl-x Ctrl-e it starts the editor defined by $EDITOR to edit the command that you want to type. When you close and save the editor, it runs the command. I use jed as $EDITOR for this. Younger people would probably use nano.
Reply
#8
If you're doing quick one liners, I can understand wanting to do that on the command line. I don't get why you need special syntax, though. What about using the Python REPL, then, since you want indentation support and not having to write code in a file?

Also, I find it strange that you can't provide an example of what you want to do - it sounds like you have a need to do this, so surely you're able to come up with something that shows the difficulty you have now and what you'd prefer to do. You're right, I can't think of examples - I don't have a need for this and don't fully understand the problem.
Reply
#9
In Bash, you can also use Here Documents
Output:
$ python3 <<EOF > for i in range(10): > print(i * i) > EOF 0 1 4 9 16 25 36 49 64 81
Reply
#10
(Mar-02-2022, 06:54 AM)Gribouillis Wrote: In Bash, if you type Ctrl-x Ctrl-e it starts the editor defined by $EDITOR to edit the command that you want to type. When you close and save the editor, it runs the command. I use jed as $EDITOR for this. Younger people would probably use nano.

i'm still trying to get this in a command line. it may be entered via sudo and/or ssh, for example.
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
  common form of multi-line text Skaperen 3 2,423 Nov-29-2019, 01:38 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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