ode
that you expect inside the " "
a=map(float, a)
print a
[1,2,3,4,5,6,7]
--
From: "Steven D'Aprano"
Sent: Friday, October 15, 2010 9:37 PM
To: "Python Tutor"
Subject: Re: [Tutor] Converting from unicode to n
On Fri, 15 Oct 2010 09:26:48 pm David Hutto wrote:
> Ok, Let me restate and hopefully further clarify.
>
> 1. I have a field for a wxpython app using matplotlib to display
> 2. I have a sqlite3 db which I'm retrieving information from
Both of those points are irrelevant.
> 3. The sqlitle data is
On 2:59 PM, David Hutto wrote:
Ok, Let me restate and hopefully further clarify.
1. I have a field for a wxpython app using matplotlib to display
2. I have a sqlite3 db which I'm retrieving information from
3. The sqlitle data is returned as unicode: u'field'
4. The portion of the matplotlib
David Hutto wrote:
> Hey Buddy Pals,
?
> I receive the following output from a sqlite db
>
> (u'graph1', u'Line', u'222', u'BLUE', u'1,2,3,4', u'True', u'0,5,0,10')
How did the string u"1,2,3,4" get into the database in the first place?
The sqlite3 module offers a mechanism to convert data fro
On Fri, Oct 15, 2010 at 6:26 AM, David Hutto wrote:
> Ok, Let me restate and hopefully further clarify.
>
> 1. I have a field for a wxpython app using matplotlib to display
>
> 2. I have a sqlite3 db which I'm retrieving information from
>
> 3. The sqlitle data is returned as unicode: u'field'
>
On Thu, Oct 14, 2010 at 10:09 PM, Steven D'Aprano wrote:
> On Fri, 15 Oct 2010 04:43:46 am David Hutto wrote:
>
>> Fixed with:
>>
>> self.lines = self.newplot.plot(eval(self.plot))
>
> Anytime you use eval, chances are that it isn't fixed at all, but just
> badly and dangerously papered over.
>
>
On Thu, Oct 14, 2010 at 7:00 PM, Alan Gauld wrote:
>
> "David Hutto" wrote
>
>> it's not necessary to worry about insertion of data other than my own
>> inputs.
>
> But can you be sure that you won't accidentally mistype something
> that eval can read as valid code but that does something unexpec
On Thu, Oct 14, 2010 at 6:56 PM, Alan Gauld wrote:
>
> "David Hutto" wrote
>
>> In other words I needed (1,2,3,4) not u'(1,2,3,4)' to be inserted
>> for variable self.plot
>
> You appear to be making this much more difficult than it needs to be.
> The values you retrieve from the database are str
> In which case the code Sanders sent you is a much more sensible way of
> recovering your data. Evalling the string u'plot' still doesn't make much
> sense to me though.
But it's the only thing working correctly though, so until I have a
better solution, I'm forced to deal with any bugs in interp
On Thu, Oct 14, 2010 at 2:58 PM, Adam Bark wrote:
> On 14/10/10 19:29, David Hutto wrote:
>>
>> On Thu, Oct 14, 2010 at 2:19 PM, Sander Sweers
>> wrote:
>>
>>>
>>> On 14 October 2010 16:14, David Hutto wrote:
>>>
(u'graph1', u'Line', u'222', u'BLUE', u'1,2,3,4', u'True', u'0,5,0,10')
>
On Thu, Oct 14, 2010 at 3:02 PM, Sander Sweers wrote:
> On 14 October 2010 20:29, David Hutto wrote:
>> Actually, I needed it to be converted to something without a string
>> attached to it. See a post above, and it was fixed by eval(),
>
> Using eval is a big security risk and is generally not r
Ok, Let me restate and hopefully further clarify.
1. I have a field for a wxpython app using matplotlib to display
2. I have a sqlite3 db which I'm retrieving information from
3. The sqlitle data is returned as unicode: u'field'
4. The portion of the matplotlib code is filled in, in a for x in
On Fri, 15 Oct 2010 05:19:57 am Sander Sweers wrote:
> So you want convert string u'1,2,3,4' to a list of ints [1,2,3,4]?
> Then the below will work.
>
> [int(n) for n in u'1,2,3,4'.replace(',', '')]
That will break if you have u'100,2,3,4'.
Better is:
>>> s = '1, 200 , -3,4' # or whatever
>>
On Fri, 15 Oct 2010 04:43:46 am David Hutto wrote:
> Fixed with:
>
> self.lines = self.newplot.plot(eval(self.plot))
Anytime you use eval, chances are that it isn't fixed at all, but just
badly and dangerously papered over.
I really, really wish that eval and exec weren't built-ins. They're
po
"David Hutto" wrote
it's not necessary to worry about insertion of data other than my
own
inputs.
But can you be sure that you won't accidentally mistype something
that eval can read as valid code but that does something unexpected
- even if its only throw an apparently bizarre error dump a
"David Hutto" wrote
In other words I needed (1,2,3,4) not u'(1,2,3,4)' to be inserted
for variable self.plot
You appear to be making this much more difficult than it needs to be.
The values you retrieve from the database are strings (forget about
the unicode aspect its not really relevant he
On 14/10/10 20:33, David Hutto wrote:
On Thu, Oct 14, 2010 at 3:31 PM, David Hutto wrote:
On Thu, Oct 14, 2010 at 3:24 PM, Adam Bark wrote:
On 14/10/10 20:21, David Hutto wrote:
On Thu, Oct 14, 2010 at 2:58 PM, Adam Barkwrote:
Actually, I needed
On Thu, Oct 14, 2010 at 3:31 PM, David Hutto wrote:
> On Thu, Oct 14, 2010 at 3:24 PM, Adam Bark wrote:
>> On 14/10/10 20:21, David Hutto wrote:
>>>
>>> On Thu, Oct 14, 2010 at 2:58 PM, Adam Bark wrote:
>>>
> Actually, I needed it to be converted to something without a string
> atta
On Thu, Oct 14, 2010 at 3:24 PM, Adam Bark wrote:
> On 14/10/10 20:21, David Hutto wrote:
>>
>> On Thu, Oct 14, 2010 at 2:58 PM, Adam Bark wrote:
>>
>>>
Actually, I needed it to be converted to something without a string
attached to it. See a post above, and it was fixed by eval(),
To take a string of comma separated integers and convert to a list of
floats:
>>> x = u'1,2,3,4'
>>> y = x.split(',')
>>> z = [float(f) for f in y]
>>> z
[1.0, 2.0, 3.0, 4.0]
>>>
--
Joel Goldstick
___
Tutor maillist - Tutor@python.org
To unsubscribe
On Thu, Oct 14, 2010 at 3:02 PM, Sander Sweers wrote:
> On 14 October 2010 20:29, David Hutto wrote:
>> Actually, I needed it to be converted to something without a string
>> attached to it. See a post above, and it was fixed by eval(),
>
> Using eval is a big security risk and is generally not r
On 14/10/10 20:21, David Hutto wrote:
On Thu, Oct 14, 2010 at 2:58 PM, Adam Bark wrote:
Actually, I needed it to be converted to something without a string
attached to it. See a post above, and it was fixed by eval(),
Thanks though. And I'm sure at some point this morning in a moment of
On Thu, Oct 14, 2010 at 2:58 PM, Adam Bark wrote:
> On 14/10/10 19:29, David Hutto wrote:
>>
>> On Thu, Oct 14, 2010 at 2:19 PM, Sander Sweers
>> wrote:
>>
>>>
>>> On 14 October 2010 16:14, David Hutto wrote:
>>>
(u'graph1', u'Line', u'222', u'BLUE', u'1,2,3,4', u'True', u'0,5,0,10')
>
On 14 October 2010 21:02, Sander Sweers wrote:
> If you really want (you really don't) to use eval() then at least use
Oops, hit send to soon. "(you really don't)" should have been "(you
really don't need to use it)".
Greets
Sander
___
Tutor maillist
On 14 October 2010 20:29, David Hutto wrote:
> Actually, I needed it to be converted to something without a string
> attached to it. See a post above, and it was fixed by eval(),
Using eval is a big security risk and is generally not recommended for
any production code. What do you think eval() r
On 14/10/10 19:29, David Hutto wrote:
On Thu, Oct 14, 2010 at 2:19 PM, Sander Sweers wrote:
On 14 October 2010 16:14, David Hutto wrote:
(u'graph1', u'Line', u'222', u'BLUE', u'1,2,3,4', u'True', u'0,5,0,10')
Which is a tuple of unicode strings. From this I
need to place portions o
On Thu, Oct 14, 2010 at 2:19 PM, Sander Sweers wrote:
> On 14 October 2010 16:14, David Hutto wrote:
>> (u'graph1', u'Line', u'222', u'BLUE', u'1,2,3,4', u'True', u'0,5,0,10')
>>
>> Which is a tuple of unicode strings. From this I
>> need to place portions of the tuple into other fields,
>> but n
On 14 October 2010 16:14, David Hutto wrote:
> (u'graph1', u'Line', u'222', u'BLUE', u'1,2,3,4', u'True', u'0,5,0,10')
>
> Which is a tuple of unicode strings. From this I
> need to place portions of the tuple into other fields,
> but not as unicode strings, but literals no ''.
>
> For example if
On Thu, Oct 14, 2010 at 11:16 AM, David Hutto wrote:
> On Thu, Oct 14, 2010 at 10:14 AM, David Hutto wrote:
>> Hey Buddy Pals,
>>
>> I receive the following output from a sqlite db
>>
>> (u'graph1', u'Line', u'222', u'BLUE', u'1,2,3,4', u'True', u'0,5,0,10')
>>
>> Which is a tuple of unicode stri
On Thu, Oct 14, 2010 at 10:14 AM, David Hutto wrote:
> Hey Buddy Pals,
>
> I receive the following output from a sqlite db
>
> (u'graph1', u'Line', u'222', u'BLUE', u'1,2,3,4', u'True', u'0,5,0,10')
>
> Which is a tuple of unicode strings. From this I
> need to place portions of the tuple into oth
Hey Buddy Pals,
I receive the following output from a sqlite db
(u'graph1', u'Line', u'222', u'BLUE', u'1,2,3,4', u'True', u'0,5,0,10')
Which is a tuple of unicode strings. From this I
need to place portions of the tuple into other fields,
but not as unicode strings, but literals no ''.
For exa
31 matches
Mail list logo