0

When I try a script to import CSVs into MonetDB databases as suggested by its author, it runs fine on my mac (Python 2.7.6 from the Anaconda distro) but it raises an error: too few arguments on Windows 2012 Server (Python 2.7.5 from Anaconda).

I think all flags but --database should be optional, plus you need to specify a filename — this is exactly working on my mac, not on Windows.

What is the way to bugfix this? Is this a known issue with argparse for Windows?

Or if I should escape \ characters in the filename, why doesn't Python complain about the file not existing, why about too few arguments? (And in any case, as I specify the files in a Windows batch file, I cannot escape \ there easily.)

I repeat the argument parsing part of the script for convenience:

parser = argparse.ArgumentParser(description='A "smarter" CSV loader for MonetDB, v.0.3, hannes@cwi.nl, 2014-05')
parser.add_argument('--database', help='Database name to connect to', default='')
parser.add_argument('--port', help='MonetDB TCP port, defaults to 50000', default='50000')
parser.add_argument('--user', help='MonetDB username, defaults to "monetdb"', default='monetdb')
parser.add_argument('--password', help='MonetDB password, defaults to "monetdb"', default='monetdb')
parser.add_argument('--header',action='store_true', help='set if given CSV file has a header in the first line')
parser.add_argument('--yes',action='store_true', help='if set, assume Yes on all questions')
parser.add_argument('files', nargs='+', help='One or many CSV files to be imported')

args = parser.parse_args()
Community
  • 1
  • 1
László
  • 3,914
  • 8
  • 34
  • 49

1 Answers1

0

The Windows installation is incomplete for Python, having it in the PATH is not enough. The problem is resolved if one types out python importer.py properly, and not only importer.py, on the command line. Also see this answer: https://stackoverflow.com/a/12421946/938408

Strange that a parsing problem was the red flag, but that's what it is.

Community
  • 1
  • 1
László
  • 3,914
  • 8
  • 34
  • 49
  • As suggested in that other SO thread, I'd print `sys.argv` to see what `argparse` has to work with. By default it parses `sys.argv[1:]`. If that is empty, `argparse` would give your error, since it can't find a value to use for `files`. – hpaulj May 17 '14 at 19:03