0

In my script I want to include a path to a file. This path should change according to the argv[1] given. Within this map I want to have the exact path of the .csv file.

So to illustrate of what I want is: x = /local/data/[argv[1]]/[whatever].csv

This is what I tried so far:

name= argv[1] x = '/local/data/predictions/hats/{}/*.csv'.format(name)

The problem is that it does not seem to recognize *.csv as a wildcard.

printing x with argv[1] = foo gives: '/local/data/predictions/hats/foo/*.csv'

Hosty
  • 1
  • 1
  • What function are you passing it to that you're expecting to glob the `*`? Python itself isn't going to do it; it would be truly obnoxious if the language tried to turn *every* `*` in a string into a filename. – Silvio Mayolo Jun 18 '19 at 16:14
  • What are you doing with the string '/local/data/predictions/hats/foo/*.csv' ? It's unclear what "it" is in "it does not seem to recognize *.csv as a wildcard". – dmmfll Jun 18 '19 at 16:14
  • Thank you for your response. So by ' it' I mean that I want this exact path to be printed out. But rather than printing the actual path it literally prints out the '*.csv'. – Hosty Jun 18 '19 at 16:17
  • You're creating a string that has a `*` in it and then getting confused when there's a `*` in your string. There's no magic happening, and it seems to me that you're expecting Python to behave like a shell language (say, Bash) and glob everything, which it decidedly does not do. – Silvio Mayolo Jun 18 '19 at 16:18
  • import sys x = '/local/data/'+sys.argv[1]+'/[whatever].csv' – garlicFrancium Jun 18 '19 at 16:19
  • https://stackoverflow.com/questions/5013532/open-file-by-filename-wildcard Seems the purpose of the question is same here – Lakshmi Swetha G Jun 18 '19 at 16:19
  • I'm not confused about the *. However i thought it would be possible to replace * by the actual file name in that folder that ends with .csv in some way. – Hosty Jun 18 '19 at 16:30

0 Answers0