On 2006-12-02, Michel Claveau [EMAIL PROTECTED] wrote:
Hi!
Yes.
But...
Try:d = {'a': 1, 'b': 2, 'def': 123}
Ok, I go out...
How to convert a list of strings into a list of integers:
a = ['82', '4', '16']
ai = [int(i) for i in a]
Yes.
But...
Try: a = ['82', '4', '16', 'foo']
On Fri, 01 Dec 2006 17:48:40 -0800, rieh25 wrote:
If I have a dictionary such as:
d = {'a' : 1, 'b' : 2}
is there a way to convert it into an object o, such as:
o.a = 1
o.b = 2
Rather, the question could be asked the other way around: how can you
convert that object into a dict?
The
Neil Cerutti wrote:
On 2006-12-02, Michel Claveau [EMAIL PROTECTED] wrote:
Hi!
Yes.
But...
Try:d = {'a': 1, 'b': 2, 'def': 123}
Ok, I go out...
How to convert a list of strings into a list of integers:
a = ['82', '4', '16']
ai = [int(i) for i in a]
Yes.
But...
John Machin wrote:
Any experiences of keyword-bite?
creating or manipulating CSS-styled (X)HTML using an XML binding that
exposes XML attributes as Python attributes.
(this could be viewed as an unnecessary restriction in the Python
parser; it wouldn't be too hard to allow reserved words for
to converting the dict into object attributes. Why not just
delegate to a saved copy of the dict?
class Spam:
def __init__(self, d):
self._d = d
def __getitem__(self, key):
return self._d[key]
def __setitem__(self, key, value):
self._d[key] = value
s = Spam({a: 1
Steven D'Aprano wrote:
On Sat, 02 Dec 2006 12:16:24 -0800, John Machin wrote:
The OP might consider adding code to the __init__ method to check for
cases where the dictionary key is not a string containing a valid
Python identifier (not a keyword).
[snip]
But if he's doing something
On Sat, 02 Dec 2006 17:00:15 -0800, John Machin wrote:
Steven D'Aprano wrote:
On Sat, 02 Dec 2006 12:16:24 -0800, John Machin wrote:
The OP might consider adding code to the __init__ method to check for
cases where the dictionary key is not a string containing a valid
Python identifier
On 2006-12-02, John Machin [EMAIL PROTECTED] wrote:
Neil Cerutti wrote:
On 2006-12-02, Michel Claveau [EMAIL PROTECTED] wrote:
Hi!
Yes.
But...
Try:d = {'a': 1, 'b': 2, 'def': 123}
Ok, I go out...
How to convert a list of strings into a list of integers:
a = ['82', '4',
Neil Cerutti wrote:
Thanks for the pointer to keyword module. I hadn't noticed it
yet.
Bonus: you got an extremely fresh, scarcely used pointer -- I wasn't
aware of it myself till today :-)
Cheers,
John
--
http://mail.python.org/mailman/listinfo/python-list
If I have a dictionary such as:
d = {'a' : 1, 'b' : 2}
is there a way to convert it into an object o, such as:
o.a = 1
o.b = 2
thanks
--
View this message in context:
http://www.nabble.com/converting-dict-to-object-tf2741429.html#a7649225
Sent from the Python - python-list mailing list
At Friday 1/12/2006 22:48, rieh25 wrote:
If I have a dictionary such as:
d = {'a' : 1, 'b' : 2}
is there a way to convert it into an object o, such as:
o.a = 1
o.b = 2
class X(object):
... def __init__(self, d): self.__dict__.update(d)
...
d = {'a' : 1, 'b' : 2}
o=X(d)
o.a
1
o.b
2
Hi!
Yes.
But...
Try:d = {'a': 1, 'b': 2, 'def': 123}
Ok, I go out...
--
@-salutations
Michel Claveau
--
http://mail.python.org/mailman/listinfo/python-list
12 matches
Mail list logo