Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

my task is to execute multiple buffers with the list-loop!

import arcpy

arcpy.env.overwriteOutput = 1  
arcpy.env.workspace="C:\\salzburg.gdb"  
sbgRivers="sbg_rivers"
buff_name=raw_input("Please insert a file name:")  
for buffer_size in [100,200,300,450]:  
outfile="C:\\salzburg.gdb\\buffer_output"
arcpy.Buffer_analysis(sbgRivers,buff_name+str(buffer_size),buffer_size)  
print "Buffer ready"

So the next step is: If the file name already exists(raw_input), the user is asked to enter a new data set name until a name is found, which doesn´t exist yet!

I thought about a while loop, but i´m not sure how to integrate it in the code above

while arcpy.Exists(buff_name)==True:      
buff_name=raw_input("Please enter a new data set name")    
else:
for buffer_size in [100,200,300,450]:    
 outfile:....    
 arcPyBuffer_analysis(....)

Any help is welcome and really appreciated!

share|improve this question

closed as off-topic by Jason Scheirer, Simbamangu, PolyGeo, Fezter, BradHards Apr 20 '14 at 23:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development are off-topic here unless they relate directly to Geographical Information Systems, but they can be asked on Stack Overflow." – Jason Scheirer, Simbamangu, PolyGeo, Fezter, BradHards
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Like I said in my answer: the way you're posing this question right now is not a GIS question so much as a general programming question. Additionally, is there any reason you're doing this as a stand-alone Python script and not as a geoprocessing script tool? You'd get this kind of validation for free if you made it a script tool. –  Jason Scheirer Apr 20 '14 at 18:14

2 Answers 2

up vote 1 down vote accepted
buff_name = "name_to_test_first" # or =raw_input("Please enter a new data set name")
while arcpy.Exists(buff_name + "*"):    # I use a wild card because the new FC include the buffer size, so this is the name you don't want to exist   
    buff_name=raw_input("Please enter a new data set name")  #don"t forget to indent  
#else: this else has nothing to do here
for buffer_size in [100,200,300,450]:    
 #outfile:.... not necessary, but not wrong to use it
    arcpy.Buffer_analysis(sbgRivers,buff_name+str(buffer_size),buffer_size) 
share|improve this answer

This is more a Python logic problem than a GIS problem, I'd recommend asking questions like these on Stack Overflow.

Try this:

import arcpy

arcpy.env.overwriteOutput = 1  
arcpy.env.workspace = "C:\\salzburg.gdb"  
sbgRivers = "sbg_rivers"
buff_name = raw_input("Please insert a file name:")
while arcpy.Exists(buff_name):
    for buffer_size in [100,200,300,450]:  
        outfile="C:\\salzburg.gdb\\buffer_output"
        arcpy.Buffer_analysis(sbgRivers,buff_name+str(buffer_size),buffer_size)  
        print "Buffer ready"
    buff_name = raw_input("Please insert a file name:")
share|improve this answer
    
you will only enter the loop if the filename exists. I don't think that this is what the OP wants. –  radouxju Apr 20 '14 at 18:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.