Python Forum
calling a function and argument in an input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calling a function and argument in an input
#3
Some extra thoughts on this:
If you are considering to use the split() function,
you might be better off reformatting the input string to "rotate,5"
It's less work, and you will need some extra logic, assuming that there are more commands than just rotate.

There is however another possibility, that does what you want, but it will probably require some rethinking of the function.
Consider this:
def add(x):
    print(x + x)
z = input('??? ')
eval(z)
So, if you input 'add(10) ', it will print "20".
This is a potentially dangerous thing, as you allow the user to execute all kinds of commands
that may not be desirable Rolleyes
Paul
Reply


Messages In This Thread
RE: calling a function and argument in an input - by DPaul - Oct-25-2020, 07:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,048 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  mutable argument in function definition akbarza 1 494 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  calling external function with arguments Wimpy_Wellington 7 1,462 Jul-05-2023, 06:33 PM
Last Post: deanhystad
  Calling a function (which accesses a library) from another file mouse9095 4 835 Jun-07-2023, 08:55 PM
Last Post: deanhystad
  pyscript index error while calling input from html form pyscript_dude 2 999 May-21-2023, 08:17 AM
Last Post: snippsat
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,109 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 1,913 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  Showing an empty chart, then input data via function kgall89 0 986 Jun-02-2022, 01:53 AM
Last Post: kgall89
Sad Iterate randint() multiple times when calling a function Jake123 2 2,067 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  input function question barryjo 12 2,743 Jan-18-2022, 12:11 AM
Last Post: barryjo

Forum Jump:

User Panel Messages

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