Skip to content
Advertisement

how to send string to python file and display it using terminal

I want to know how can I get the string from terminal or command prompt and make lower case that string and display it on terminal or command prompt
I used this code but it’s not working

// in main.py cmd or terminal

import sys
tdf = sys.argv[1]
print(tdf)

and in terminal

// in cmd or terminal

PS E:PythonProjectAt> python .main.py "Hi"

when I used this in my terminal I got this error

File “C:UsersmiladmAppDataLocalProgramsPythonPython39libencodingscp1256.py”, line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: ‘charmap’ codec can’t encode character ‘u06cc’ in position 13: character maps to

Advertisement

Answer

Code:

import sys

print ("Data from terminal :",sys.argv)

while running the script use:

D:python>python cmdline.py "hello"

Output:

Data from terminal : ['cmdline.py', 'hello']
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement