user2581350
user2581350

Reputation: 115

What replaces the asterisk in Python?

I'm using psycopg2 to copy csvs into postgres. all my csvs will always have the same suffix, such as competitors or customers, along with a unique number each time i generate them. therefore I want a python script that can run to use COPY and I can just have 'dir/customers*.csv'

is there an easy way to do this, does asterisk exist as some other character in python?

Thanks in advance!

Ok so what I currently have is a geoprocessing model in ArcGIS that will generate a bunch of CSVs into C:\Data\Sheltered BLPUs\CSVs such as competitors and customers, but attaches a unique ID for each location onto the end of the filename e.g. customers17.csv. I then want a python script to copy all of these into postgres. All the tables exist as 'customers' or 'competitors' - this is what I wanted to write:

cur.execute("COPY competitors FROM 'C:/Data/Sheltered BLPUs/CSVs/competitors*.csv' DELIMITER ',' CSV;")

Upvotes: 0

Views: 230

Answers (1)

Joran Beasley
Joran Beasley

Reputation: 113940

import glob
print glob.glob('dir/customers*.csv')

Upvotes: 3

Related Questions