Generalized integer casting in Python Background

I have a string in Python which I want to convert to an integer. Normally, I would just use int:

&gt;&gt;&gt; int("123")
123


Unfortunately, this method is not very robust, as it only accepts strings that match -?[0-9]+ (after removing any leading or trailing whitespace). For example, it can't handle input with a decimal point:

&gt;&gt;&gt; int("123.45")
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ValueError: invalid literal for int() with base 10: '123.45'


And it certainly can't handle this:

&gt;&gt;&gt; int("123abc?!")


On the other hand, exactly this behavior can be had without any fuss in Perl, PHP, and even the humble QBasic:

INT(VAL("123abc"))   ' 123


Question

Here's my shortest effort at this "generalized int" in Python. It's 50 bytes, assuming that the original string is in s and the result should end up in i:

n="";i=0
for c in s:
 n+=c
 try:i=int(n)
 except:0


Fairly straightforward, but the try/except bit is ugly and long. Is there any way to shorten it?

Details

Answers need to do all of the following:


Start with a string in s; end with its integer value in i.
The integer is the first run of digits in the string. Everything after that is ignored, including other digits if they come after non-digits.
Leading zeros in the input are valid.
Any string that does not start with a valid integer has a value of 0.


The following features are preferred, though not required:


A single - sign immediately before the digits makes the integer negative.
Ignores whitespace before and after the number.
Works equally well in Python 2 or 3.


(Note: my code above meets all of these criteria.)

Test cases

"0123"   -&gt; 123
"123abc" -&gt; 123
"123.45" -&gt; 123
"abc123" -&gt; 0
"-123"   -&gt; -123 (or 0 if negatives not handled)
"-1-2"   -&gt; -1 (or 0 if negatives not handled)
"--1"    -&gt; 0
""       -&gt; 0
Python 2, 47, 46
It's not as short as using regex, but I thought it was entertainingly obscure.
i=int(('0%sx'%s)[:~len(s.lstrip(str(1&lt;&lt;68)))])

-1 due to KSab – str with some large integer works better than the repr operator since it does not put an L on the end.