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
5 6238 bvdet 2,851
Recognized Expert Moderator Specialist
Samantha, isdigit() is a string method and is available in PythonWin. - >>> s = '1234567890'
-
>>> s.isdigit()
-
True
-
>>> s1 = '1234567890a'
-
>>> s1.isdigit()
-
False
-
>>>
-BV
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
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. - def isdigit(s):
-
for c in s:
-
if not (48 <= ord(c) <= 57):
-
return False
-
return True
-
-
print isdigit('123456789a')
-
print isdigit('1234567890')
-
print isdigit('Z1994.dhh5')
-
-
print
-
-
def isdigit(s):
-
try:
-
int(s)
-
except:
-
return False
-
return True
Example usage: - >>> isdigit('123456789a')
-
False
-
>>> isdigit('1234567890')
-
True
-
>>>
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
When you start python you will get a message containing youre python version. Like this: -
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
-
[GCC 4.3.2] on linux2
-
Type "help", "copyright", "credits" or "license" for more information.
-
>>> >>> dir("")
-
['__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']
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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,
|
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...
|
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...
|
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,...
|
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) :...
|
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...
|
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.
...
|
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
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |