try and convert the first value in the split list to a int (or float), if 
that works then post the value.
if it throws an exception (ValueError) then catch that and pass, or do 
whatever else needs doing with the listing.

def postData(inputData):
    fields=inputData.split("-")
    try:
        numberfield=int(fields[0])
        #do whatever voodoo needed
        print "%s posted" %inputData
    except ValueError:
        print "%s not posted" %inputData
        pass
    #move on to other fields
 
inputValue=["12-Foo-Fee","Bla-Ble-blu"]

for entry in inputValue:
    postData(entry)




"Spencer Parker" <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED]
09/04/2008 04:56 PM

To
tutor@python.org
cc

Subject
[Tutor] Help with checking for a data type






I have a script that is taking a directory list, the script then splits 
the name up by the hyphens in the name.  The first part of the name should 
be a number, but it isn't always a number.  Is there a way to say: if its 
a number then post this data....if not discard?

-- 
Spencer Parker
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to