[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



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

-- 
Best Regards
Emil S. Hansen - sslug@sslug - ESH14-DK
UNIX Administrator, Berlingske IT - www.bit.dk
PGP: 109375FA/ABEB 1EFA A764 529E 82B5  0943 AD3B 1FC2 1093 75FA

"tjaa men ville disse lister ikke være kedelige hvis vi altid gav
hinanden ret med det samme :o)" - Kim Schulz på SSLUG.PROG


 
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] *