Fwd: Python Signal/Slot + QThred code analysis

MRAB python at mrabarnett.plus.com
Tue Nov 25 13:20:57 EST 2014


On 2014-11-25 15:48, Juan Christian wrote:
> On Tue Nov 25 2014 at 1:42:24 PM MRAB <python at mrabarnett.plus.com
> <mailto:python at mrabarnett.plus.com>> wrote:
> I think that the problem there is that strings don't have an __exit__
> method.
>
> I don't understand what you said, what you mean by that? =/
>
The traceback says:

Traceback (most recent call last):
   File "D:\Documents\PyCharm\Trader\Trader\core\outpost.py", line 18, 
in run
     with soup.select('div.stat_box 
div.value')[0].get_text().replace(',', '') as trades, \
AttributeError: __exit__

As you can see, it does:

     soup.select('div.stat_box div.value')[0].get_text()

which, presumably, returns a string, and then it calls the .replace
method on that string, which returns a string.

That string is then bound to 'trades'.

The problem is that this occurs in the expression part of a 'with'
statement.

If you look at this simpler example:


 >>> with 'some string' as a_name:
...     pass
...
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AttributeError: __exit__


An even simpler example:


 >>> with 'somestring':
...     pass
...
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AttributeError: __exit__




More information about the Python-list mailing list