[python-win32] problem in looping

Ahmed, Shakir shahmed at sfwmd.gov
Fri Oct 20 18:27:26 CEST 2006


HI All,

 

Good Afternoon. 

 

I am trying to use if, elif in python script to work on each county. But
it works only when the condition is else and jump to the point where I
need to work but not for case one or two.

 

Any help or idea is highly appreciated.

 

Thanks in advance.

 

 

 

 

 

 

# script as follows:

# Import system modules

import sys

import string

import os

import win32com.client

import odbc

import shutil

from win32com.client import Dispatch

gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

 

gp.SetProduct("ArcInfo")

gp.workspace = "c:/mydata"

 

try:

    cycle = open('c:/mydata/county_cycle.txt', 'r')

    for countyid in cycle.readlines():

        # for countyid = one, two, thr

        x = countyid.rstrip()

        print x

     

 

        if x=='one':

            county_name = open('c:/mydata/county1.txt', 'r')

            for county in county_name.readlines():

                county = county.rstrip()

                print county

 

        elif x=='two':

            county_name = open('c:/mydata/county2.txt', 'r')

            for county in county_name.readlines():

                county = county.rstrip() 

                print county

 

        else:

            county_name = open('c:/mydata/county3.txt', 'r')

            for county in county_name.readlines():

                      

                county = county.rstrip() 

                print county

                    

            # the loop come to the next line if the case is else but not
for case one or two                 

                gp.copy("%smydata1"%county,"%smydata2"%county) 

except Exception, ErrDesc:

    print ErrorDesc

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20061020/2cf4f217/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Script1.py
Type: application/octet-stream
Size: 1292 bytes
Desc: Script1.py
Url : http://mail.python.org/pipermail/python-win32/attachments/20061020/2cf4f217/attachment.obj 


More information about the Python-win32 mailing list