tuple in dict is unusable in it's current state.

Hey gang, maybe I’m in over my head…

Correct me please…

someVariable = 1

someVariable is an int. It’s value is 1… correct?

anotherVariable = 'Brian likes his steak rare."

anotherVariable is a string of text. It’s value is “Brian likes his steak rare.”

With that being said…

(0,0,0) is a tuple of 3 ints.

Python knows this. How come when I put a tuple in a dictionary as a value

to a key, Python changes it? It did the same thing to a string but I corrected

it by slicing the [’ and '] off of both ends.

Well when I pickle dump the data, and then pickle load the data at a later time

the tuple is no longer a tuptle, it’s worthless as is.

So it prints like this when I save it --> [[’(0, 0, 0)’]]

It prints likes this when I load it --> [[[’(0, 0, 0)’]]]

If I don’t redefine the color data, and make a chage some where else and

save the data, the same value now looks like this --> [[[[’(255, 255, 255)’]]]]

You can see a pattern I imagine. Evertime the value gets put into an instance

of a dictionary another set of brackets gets slapped on.

But because it has brackets wrapped around it, is it now a string, and no longer a tuple?

Obviously again I’ve messed something up :stuck_out_tongue:

Thanks,

Steve

Not sure what's going on the [(0,0,0)] means you have a list of one
item a tuple.

A tuple should have no problem being used as a dictionary key.

It looks like you're somehow creating a list inside a list inside a list.

Try "print type(<varname>)" to see what it is you're getting.

···

On Mon, Aug 4, 2008 at 8:24 PM, Steve Freedenburg <stevefreedenburg@charter.net> wrote:

Hey gang, maybe I'm in over my head...

Correct me please...

someVariable = 1

someVariable is an int. It's value is 1... correct?

anotherVariable = 'Brian likes his steak rare."

anotherVariable is a string of text. It's value is "Brian likes his steak
rare."

With that being said...

(0,0,0) is a tuple of 3 ints.

Python knows this. How come when I put a tuple in a dictionary as a value
to a key, Python changes it? It did the same thing to a string but I
corrected
it by slicing the [' and '] off of both ends.

Well when I pickle dump the data, and then pickle load the data at a later
time
the tuple is no longer a tuptle, it's worthless as is.

So it prints like this when I save it --> [['(0, 0, 0)']]
It prints likes this when I load it --> [[['(0, 0, 0)']]]
If I don't redefine the color data, and make a chage some where else and
save the data, the same value now looks like this --> [[[['(255, 255,
255)']]]]

You can see a pattern I imagine. Evertime the value gets put into an
instance
of a dictionary another set of brackets gets slapped on.

But because it has brackets wrapped around it, is it now a string, and no
longer a tuple?

Obviously again I've messed something up :stuck_out_tongue:

Thanks,

Steve

--
Stand Fast,
tjg. [Timothy Grant]

As soon as I get back from work I'm going to check this out.
It's cool to know you can get the type of variable. Thanks man!

···

----- Original Message ----- From: "Timothy Grant" <timothy.grant@gmail.com>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Monday, 04 August, 2008 23:55
Subject: Re: [wxpython-users] tuple in dict is unusable in it's current state.

On Mon, Aug 4, 2008 at 8:24 PM, Steve Freedenburg > <stevefreedenburg@charter.net> wrote:

Hey gang, maybe I'm in over my head...

Correct me please...

someVariable = 1

someVariable is an int. It's value is 1... correct?

anotherVariable = 'Brian likes his steak rare."

anotherVariable is a string of text. It's value is "Brian likes his steak
rare."

With that being said...

(0,0,0) is a tuple of 3 ints.

Python knows this. How come when I put a tuple in a dictionary as a value
to a key, Python changes it? It did the same thing to a string but I
corrected
it by slicing the [' and '] off of both ends.

Well when I pickle dump the data, and then pickle load the data at a later
time
the tuple is no longer a tuptle, it's worthless as is.

So it prints like this when I save it --> [['(0, 0, 0)']]
It prints likes this when I load it --> [[['(0, 0, 0)']]]
If I don't redefine the color data, and make a chage some where else and
save the data, the same value now looks like this --> [[[['(255, 255,
255)']]]]

You can see a pattern I imagine. Evertime the value gets put into an
instance
of a dictionary another set of brackets gets slapped on.

But because it has brackets wrapped around it, is it now a string, and no
longer a tuple?

Obviously again I've messed something up :stuck_out_tongue:

Thanks,

Steve

Not sure what's going on the [(0,0,0)] means you have a list of one
item a tuple.

A tuple should have no problem being used as a dictionary key.

It looks like you're somehow creating a list inside a list inside a list.

Try "print type(<varname>)" to see what it is you're getting.

--
Stand Fast,
tjg. [Timothy Grant]
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Steve Freedenburg wrote:

Hey gang, maybe I'm in over my head...
Correct me please...
someVariable = 1
someVariable is an int. It's value is 1... correct?

Not really. someVariable is a name that is bound to an integer object. We just had this discussion last week.

anotherVariable = 'Brian likes his steak rare."
anotherVariable is a string of text. It's value is "Brian likes his steak rare."

anotherVariable is a name that is bound to a string object, yes.

With that being said...
(0,0,0) is a tuple of 3 ints.
Python knows this. How come when I put a tuple in a dictionary as a value
to a key, Python changes it? It did the same thing to a string but I corrected
it by slicing the [' and '] off of both ends.
Well when I pickle dump the data, and then pickle load the data at a later time
the tuple is no longer a tuptle, it's worthless as is.
So it prints like this when I save it --> [['(0, 0, 0)']]
It prints likes this when I load it --> [[['(0, 0, 0)']]]
If I don't redefine the color data, and make a chage some where else and
save the data, the same value now looks like this --> [[[['(255, 255, 255)']]]]
You can see a pattern I imagine. Evertime the value gets put into an instance
of a dictionary another set of brackets gets slapped on.
But because it has brackets wrapped around it, is it now a string, and no longer a tuple?
Obviously again I've messed something up :stuck_out_tongue:

Unfortunately, we cannot read your mind. What you say here suggests that you are using the pickle module incorrectly. Show us your code, along with what you expected, and we can point out where you went wrong. Clearly, pickle CAN handle tuples as dictionary keys and values:

    C:\tmp>python
    Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit
    (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
     >>> x = (0,0,0)
     >>> y = {x: x}
     >>> y
    {(0, 0, 0): (0, 0, 0)}
     >>> import pickle
     >>> pickle.dumps( y )
    '(dp0\n(I0\nI0\nI0\ntp1\ng1\ns.'
     >>> z = pickle.loads( pickle.dumps( y ) )
     >>> z
    {(0, 0, 0): (0, 0, 0)}

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

No Tim, I'm using pickle correctly... I'm just a moron is all...

my earlier post about not being able to update a text control
color was the problem.

My line of code:

BGColor = str(BGColorData.GetColour().Get())

notice I was turning the "tuple" into a string
so it looked like a tuple... but really was a string...

BGColor = BGColorData.GetColour()

This line does what I wanted it to do, updates the
text control and doesn't get mushed up in the dictionary.

I realize what was happening the value of that particular
key gets returned as ['(0,0,0)'] because it was getting
transfered from a dictionary to another dictionary which
added another set of brackets [['(0,0,0)']] and then
loaded from a dictionary in the pickle, to a dictionary
after being loaded added another set of brackets.

no more problem by fixing that line.

Once again you guys are my salvation.

Thanks!

Steve

···

----- Original Message ----- From: "Tim Roberts" <timr@probo.com>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Tuesday, 05 August, 2008 13:04
Subject: Re: [wxpython-users] tuple in dict is unusable in it's current state.

Steve Freedenburg wrote:

Hey gang, maybe I'm in over my head...
Correct me please...
someVariable = 1
someVariable is an int. It's value is 1... correct?

Not really. someVariable is a name that is bound to an integer object. We just had this discussion last week.

anotherVariable = 'Brian likes his steak rare."
anotherVariable is a string of text. It's value is "Brian likes his steak rare."

anotherVariable is a name that is bound to a string object, yes.

With that being said...
(0,0,0) is a tuple of 3 ints.
Python knows this. How come when I put a tuple in a dictionary as a value
to a key, Python changes it? It did the same thing to a string but I corrected
it by slicing the [' and '] off of both ends.
Well when I pickle dump the data, and then pickle load the data at a later time
the tuple is no longer a tuptle, it's worthless as is.
So it prints like this when I save it --> [['(0, 0, 0)']]
It prints likes this when I load it --> [[['(0, 0, 0)']]]
If I don't redefine the color data, and make a chage some where else and
save the data, the same value now looks like this --> [[[['(255, 255, 255)']]]]
You can see a pattern I imagine. Evertime the value gets put into an instance
of a dictionary another set of brackets gets slapped on.
But because it has brackets wrapped around it, is it now a string, and no longer a tuple?
Obviously again I've messed something up :stuck_out_tongue:

Unfortunately, we cannot read your mind. What you say here suggests that you are using the pickle module incorrectly. Show us your code, along with what you expected, and we can point out where you went wrong. Clearly, pickle CAN handle tuples as dictionary keys and values:

   C:\tmp>python
   Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit
   (Intel)] on win32
   Type "help", "copyright", "credits" or "license" for more information.
    >>> x = (0,0,0)
    >>> y = {x: x}
    >>> y
   {(0, 0, 0): (0, 0, 0)}
    >>> import pickle
    >>> pickle.dumps( y )
   '(dp0\n(I0\nI0\nI0\ntp1\ng1\ns.'
    >>> z = pickle.loads( pickle.dumps( y ) )
    >>> z
   {(0, 0, 0): (0, 0, 0)}
    >>>

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hey Timothy,

You were right... I was reading the examples used in a book I have
called "Python Phrasebook". It's pretty much a great book, the down
and dirty, "This is the most common stuff in Python, and the most
common way to do things."

And the section on dictionairies is right after lists, the whole section
is about managing data types.

So the authors examples encororate alot of lists into dictionaries.
so like a lemming ( a non-thinking lemming to boot [or is a lemming
inherantly non-thinking]) I was putting brackets around my variables.

So this worked because it was a "list" of one item:

Label = SomeTextCtrl.GetValue()
self.ContSetting['Label'] = [Label]

I could plug in the "list" with the value of Label and Python
wouldn't complain. It was probably wanting to say to me
"Um... you know you're an idiot right.... Fine, give me the data. <sigh>"

but this didn't:

BGColor = SomeTextCtrl.GetBackgroundColour().Get()
self.ContSetting['BGColor'] = [BGColor]

The upshot, I figured it out.... I was picking everything just fine.
It's what I was pickling that was the problem.

One day I'll look back at all this and get a good chuckle.
Much like the chuckling you guys are doing at my expense now.

···

----- Original Message ----- From: "Timothy Grant" <timothy.grant@gmail.com>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Monday, 04 August, 2008 23:55
Subject: Re: [wxpython-users] tuple in dict is unusable in it's current state.

On Mon, Aug 4, 2008 at 8:24 PM, Steve Freedenburg > <stevefreedenburg@charter.net> wrote:

Hey gang, maybe I'm in over my head...

Correct me please...

someVariable = 1

someVariable is an int. It's value is 1... correct?

anotherVariable = 'Brian likes his steak rare."

anotherVariable is a string of text. It's value is "Brian likes his steak
rare."

With that being said...

(0,0,0) is a tuple of 3 ints.

Python knows this. How come when I put a tuple in a dictionary as a value
to a key, Python changes it? It did the same thing to a string but I
corrected
it by slicing the [' and '] off of both ends.

Well when I pickle dump the data, and then pickle load the data at a later
time
the tuple is no longer a tuptle, it's worthless as is.

So it prints like this when I save it --> [['(0, 0, 0)']]
It prints likes this when I load it --> [[['(0, 0, 0)']]]
If I don't redefine the color data, and make a chage some where else and
save the data, the same value now looks like this --> [[[['(255, 255,
255)']]]]

You can see a pattern I imagine. Evertime the value gets put into an
instance
of a dictionary another set of brackets gets slapped on.

But because it has brackets wrapped around it, is it now a string, and no
longer a tuple?

Obviously again I've messed something up :stuck_out_tongue:

Thanks,

Steve

Not sure what's going on the [(0,0,0)] means you have a list of one
item a tuple.

A tuple should have no problem being used as a dictionary key.

It looks like you're somehow creating a list inside a list inside a list.

Try "print type(<varname>)" to see what it is you're getting.

--
Stand Fast,
tjg. [Timothy Grant]
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hey at least you learned something new. I've seen you talking about
your code a couple of times and thought to myself that you weren't
ascribing the appropriate meaning to the various versions of braces.

Now you know better!

···

On Wed, Aug 6, 2008 at 9:11 PM, Steve Freedenburg <stevefreedenburg@charter.net> wrote:

Hey Timothy,

You were right... I was reading the examples used in a book I have
called "Python Phrasebook". It's pretty much a great book, the down
and dirty, "This is the most common stuff in Python, and the most
common way to do things."

And the section on dictionairies is right after lists, the whole section
is about managing data types.

So the authors examples encororate alot of lists into dictionaries.
so like a lemming ( a non-thinking lemming to boot [or is a lemming
inherantly non-thinking]) I was putting brackets around my variables.

So this worked because it was a "list" of one item:

Label = SomeTextCtrl.GetValue()
self.ContSetting['Label'] = [Label]

I could plug in the "list" with the value of Label and Python
wouldn't complain. It was probably wanting to say to me
"Um... you know you're an idiot right.... Fine, give me the data. <sigh>"

but this didn't:

BGColor = SomeTextCtrl.GetBackgroundColour().Get()
self.ContSetting['BGColor'] = [BGColor]

The upshot, I figured it out.... I was picking everything just fine.
It's what I was pickling that was the problem.

One day I'll look back at all this and get a good chuckle.
Much like the chuckling you guys are doing at my expense now.

----- Original Message ----- From: "Timothy Grant" <timothy.grant@gmail.com>
To: <wxpython-users@lists.wxwidgets.org>
Sent: Monday, 04 August, 2008 23:55
Subject: Re: [wxpython-users] tuple in dict is unusable in it's current
state.

On Mon, Aug 4, 2008 at 8:24 PM, Steve Freedenburg >> <stevefreedenburg@charter.net> wrote:

Hey gang, maybe I'm in over my head...

Correct me please...

someVariable = 1

someVariable is an int. It's value is 1... correct?

anotherVariable = 'Brian likes his steak rare."

anotherVariable is a string of text. It's value is "Brian likes his
steak
rare."

With that being said...

(0,0,0) is a tuple of 3 ints.

Python knows this. How come when I put a tuple in a dictionary as a
value
to a key, Python changes it? It did the same thing to a string but I
corrected
it by slicing the [' and '] off of both ends.

Well when I pickle dump the data, and then pickle load the data at a
later
time
the tuple is no longer a tuptle, it's worthless as is.

So it prints like this when I save it --> [['(0, 0, 0)']]
It prints likes this when I load it --> [[['(0, 0, 0)']]]
If I don't redefine the color data, and make a chage some where else and
save the data, the same value now looks like this --> [[[['(255, 255,
255)']]]]

You can see a pattern I imagine. Evertime the value gets put into an
instance
of a dictionary another set of brackets gets slapped on.

But because it has brackets wrapped around it, is it now a string, and no
longer a tuple?

Obviously again I've messed something up :stuck_out_tongue:

Thanks,

Steve

Not sure what's going on the [(0,0,0)] means you have a list of one
item a tuple.

A tuple should have no problem being used as a dictionary key.

It looks like you're somehow creating a list inside a list inside a list.

Try "print type(<varname>)" to see what it is you're getting.

--
Stand Fast,
tjg. [Timothy Grant]
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

--
Stand Fast,
tjg. [Timothy Grant]