[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROG] python string til int



Emil S. Hansen wrote:

> On Fri, Aug 09, 2002 at 12:04:46AM +0200, Daniel Udsen wrote:
>> hvordan er det nu lige man finder ud af om en string kan
>> konverteres til int uden at man rejser en fejl.
>> Det jeg egentligt vil er at lave en funktion der istedet for at
>> afslutte med en fejl fortæller brugeren at den altså skal bruge et
>> tal og spørge igen.
> 
> Prøv med lidt Exception handling:
> <SNIP>
> try:
> x = int(y)
> execpt ValueError:
> print "y is not a number, try again"
> </SNIP>
> 
> Se evt. et mere færdigt eksempel på
> 
http://www.python.org/doc/current/tut/node10.html#SECTION0010300000000000000000
> 

Det var lige netop det jeg troede man ikke kunne, jeg var igang med 
at teste for type og den slags.
Mange tak for hjelpen 
-- 
Daniel Udsen
I'm not tense, just terribly, terribly alert!


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 19:58 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *