473,472 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

isdigit( ) not supported in PythonWin?

13 New Member
Hi people!

I'm working with a Telit gsm module and am using PythonWin. I am trying to use the function isdigit( ) to check if a string contains only digits. However, PythonWin doesn't seem to support this function.

Does anyone know what I can do to work around this problem? I really need this function and cannot find other alternatives...

Thanks in advance!

Cheers, Samantha
Jan 5 '09 #1
5 6238
bvdet
2,851 Recognized Expert Moderator Specialist
Samantha,

isdigit() is a string method and is available in PythonWin.
Expand|Select|Wrap|Line Numbers
  1. >>> s = '1234567890'
  2. >>> s.isdigit()
  3. True
  4. >>> s1 = '1234567890a'
  5. >>> s1.isdigit()
  6. False
  7. >>> 
-BV
Jan 5 '09 #2
yueying53
13 New Member
Hi BV,

Am I supposed to import any particular module to be able to use isdigit()? Because Telit's Easy Script in Python document suggests that this function is not supported. Also, I checked the library for string and isdigit() is not in there either.

I was thinking if I could write the function manually myself and put it in the string module. But how should this function be written?

Thanks a million

Cheers, Samantha
Jan 7 '09 #3
bvdet
2,851 Recognized Expert Moderator Specialist
Samantha,

isdigit() is a string method and is built into Python (I am using 2.3). Following are a couple of functions that return True of all the characters in a string are digits and False if not.
Expand|Select|Wrap|Line Numbers
  1. def isdigit(s):
  2.     for c in s:
  3.         if not (48 <= ord(c) <= 57):
  4.             return False
  5.     return True
  6.  
  7. print isdigit('123456789a')
  8. print isdigit('1234567890')
  9. print isdigit('Z1994.dhh5')
  10.  
  11. print
  12.  
  13. def isdigit(s):
  14.     try:
  15.         int(s)
  16.     except:
  17.         return False
  18.     return True
Example usage:
Expand|Select|Wrap|Line Numbers
  1. >>> isdigit('123456789a')
  2. False
  3. >>> isdigit('1234567890')
  4. True
  5. >>> 
Jan 7 '09 #4
yueying53
13 New Member
BV,

Thank you so much for your help. I'm quite new to Python so pardon me for being unable to distinguish between string 'methods' and functions. Thank you for your corrections.

Anyhows, I do realise that isdigit( ) is supposed to be inbuilt into Python. That's why I was surprised that an error returned when I ran that part of the code. Not sure why that happens to the Python that I'm using. But I got around the problem by manually writing the function that you provided above. It works as expected now.

Thanks a million once again! =)

Cheers, Samantha
Jan 8 '09 #5
Smygis
126 New Member
When you start python you will get a message containing youre python version. Like this:
Expand|Select|Wrap|Line Numbers
  1. Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49) 
  2. [GCC 4.3.2] on linux2
  3. Type "help", "copyright", "credits" or "license" for more information.
  4. >>> >>> dir("")
  5. ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
  6.  
  7.  
Jan 8 '09 #6

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

Similar topics

18
by: pete | last post by:
On my system, the following five expressions are true: (HUGE_VAL == HUGE_VAL / 2) (1 / HUGE_VAL == 0) (sqrt(HUGE_VAL) == HUGE_VAL) (sqrt(-1) == HUGE_VAL) (sqrt(-HUGE_VAL) == HUGE_VAL) and
2
FTP
by: Tony | last post by:
How do you put/get a file via ftp from a C# Windows App? I can't seem to find any classes that can do this. Tahnk You,
7
by: Per Rollvang | last post by:
Hi All! I have a problem with hex strings when using Char.IsDigit(). The hex strings(i.e. a CRC32 checksum) get a false result for letters A-F... MSDN tell me that: Indicates whether a...
9
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
0
by: gaurav tyagi | last post by:
i am trying to downlosd frles from a local ftp server in my network . here i am able to connect to server but to get file list from server i send "PASV" command it retuns some value which is not...
162
by: Richard Heathfield | last post by:
I found something interesting on the Web today, purely by chance. It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm not sure which. ...
45
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.