This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Import sys,getopt is having issue while taking inputs
Type: Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, venkata suresh gummadillli
Priority: normal Keywords:

Created on 2015-06-10 19:42 by venkata suresh gummadillli, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg245142 - (view) Author: venkata suresh gummadillli (venkata suresh gummadillli) Date: 2015-06-10 19:42
[@outsidetried ~]$ python validate_json_adj.py 
[@outsidetried ~]$ python validate_json_adj.py -h
validate_json.py -i <input_file>
[@outsidetried ~]$ python validate_json_adj.py -i hello.txt
Input JSON file provided for verification: hello.txt
[@outsidetried ~]$ python validate_json_adj.py -i firstfile
Input JSON file provided for verification: firstfile
[@outsidetried ~]$ python validate_json_adj.py -i <hello.txt>
-bash: syntax error near unexpected token `newline'
[sureshgv@outsidetried ~]$ python validate_json_adj.py -i ??
Input JSON file provided for verification: ci
[@outsidetried ~]$ python validate_json_adj.py -i ???
Input JSON file provided for verification: bf1
[@outsidetried ~]$ python validate_json_adj.py -i $#@%
Input JSON file provided for verification: 0@%
[@outsidetried ~]$ cat validate_json_adj.py 
#!/usr/bin/python
"""
"""

import sys,getopt


"""
 """

def main(argv):
   inputfile = ''
   try:
      opts, args = getopt.getopt(argv,"hi:",["input_file="])
   except getopt.GetoptError:
      print 'validate_json.py -i <input_file>'
      sys.exit(2)
   for opt, arg in opts:
      if opt == '-h':
         print 'validate_json.py -i <input_file>'
         sys.exit()
      elif opt in ("-i", "--input_file"):
         inputfile = arg
   	 print 'Input JSON file provided for verification:', inputfile 
if __name__ == "__main__":
   main(sys.argv[1:])
msg245143 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2015-06-10 19:47
This is not a problem with python, but rather with how bash interprets your program arguments. Try putting the arguments in single quotes, like:

python validate_json_adj.py -i '$#@%'
History
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68616
2015-06-10 19:47:10eric.smithsetstatus: open -> closed

type: behavior ->

nosy: + eric.smith
messages: + msg245143
resolution: not a bug
stage: resolved
2015-06-10 19:42:08venkata suresh gummadilllicreate