Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Determine if variable is numeric

Determine if variable is numeric

Determine if variable is numeric


Hi all, on a scale of 1 to 100, 100 being a Python expert, I am a 1.
I inherited a bunch of Python scripts and now I have to change one.

This is the current code. It checks the length of the PropID and if it is 10, then it is a good ID.

CODE --> python

if len(str(self.propid)) == 10:
    self.is_valid_sungard_id = True
    self.is_valid_sungard_id = False 
However the ID needs to start with a numeric for it to be truly valid.

Can anyone help?

CODE --> pseudo

if Left 1 is numeric and the length is 10 then it is a good PropID 

Thanks in advance!

RE: Determine if variable is numeric

1st of all you want to check each condition separately (this will make it easier to maintain & add attitional check of modify existing ones.

the following is some very curde code that may need a little cleaning up


#new method to add to your class
def check_id(self):
valid_first_chars=[str(x) for x in range(10)] id=str(self.propid) # isnt this a string anyway? if len(id)!=0:
return False
if id[0] not in valid_first_chars:
return False
#add additional checks here if req return True
#using the new method self.is_valid_sungard_id=self.check_id(self)

A Maintenance contract is essential, not a Luxury.
Do things on the cheap & it will cost you dear

RE: Determine if variable is numeric


Quote (IPGuru)


if len(id)!=0:
  return False 
Few identifiers will pass so strict validation...

Why not use str.isdigit() ?

CODE --> python

>>> 'bad'[0].isdigit()

>>> '5good'[0].isdigit()


RE: Determine if variable is numeric

if len(id) !=0:

Deliberate typo to check everyone was watching (thats my story & i am sticking to it smile )


I forgot about that, although my solution of checking members of a list does give some scope for amending the valid lead character

Hey I said it was quick & dirty code.

A Maintenance contract is essential, not a Luxury.
Do things on the cheap & it will cost you dear

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close