By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,275 Members | 1,745 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,275 IT Pros & Developers. It's quick & easy.

os.path and manipulating the records within the list

P: 1
I have around 100 ASCII files in a folder. I will apply some processing on each ASCII file and save them as raster files.
In order to work with each ASCII file I have created the following access:
workspace = "C:\\ASCII\\1950"
foldername = join(workspace,'*.asc')
AsciiFiles = glob.glob(foldername)

The result is a list like :
['C: \\1950-1.asc', 'C: \\1950-2.asc', 'C\1950-3.asc']
I would like to create a new list which will include the path and file name of the outputs, and that list should look like this
['C: \\1950-1.tiff, 'C: \\1950-2.tiff', 'C\\1950-3.tiff']
Thank you for your help.
Dec 8 '10 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 622
Look at string.replace and replace ".asc" with ".tiff".
Dec 8 '10 #2

P: 3
This is not the only way, but I had a similiar situation and this is how I solved it. It iterates through the list of files, chops the last three digits off, and adds 'tiff'. Then it adds that to a new list.

Expand|Select|Wrap|Line Numbers
  1. asclist = ['C: \\1950-1.asc', 'C: \\1950-2.asc', 'C\\1950-3.asc']
  2. tifflist=[]
  3. for asc_file in asclist:
  4.     tifflist.append(asc_file[:-3]+'tiff')
Dec 8 '10 #3

Expert 100+
P: 622
I always use the dot, ".asc", [:-4], in my paranoid world when replacing, globbing, etc. because it eliminates files that end with just asc.
Dec 9 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.