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
#4
The extremely dangerous way to do it is the exec() function. You are opening up your machine to the user, but here's an example
cmd = input('What do you want to do?')
print(f'You want to {cmd}')
exec(cmd)
Output:
What do you want to do?print('foo bar') You want to print('foo bar') foo bar
Reply


Messages In This Thread
RE: calling a function and argument in an input - by jefsummers - Oct-25-2020, 02:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,006 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  mutable argument in function definition akbarza 1 464 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  calling external function with arguments Wimpy_Wellington 7 1,419 Jul-05-2023, 06:33 PM
Last Post: deanhystad
  Calling a function (which accesses a library) from another file mouse9095 4 806 Jun-07-2023, 08:55 PM
Last Post: deanhystad
  pyscript index error while calling input from html form pyscript_dude 2 968 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,070 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 1,831 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  Showing an empty chart, then input data via function kgall89 0 972 Jun-02-2022, 01:53 AM
Last Post: kgall89
Sad Iterate randint() multiple times when calling a function Jake123 2 2,033 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  input function question barryjo 12 2,701 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