It is currently Thu Apr 17, 2014 4:38 am




Post new topic Reply to topic  [ 6 posts ] 
 Strange digit appears on list from PyDataSet 
Author Message
Colonel
Colonel

Joined: Mon Nov 15, 2010 4:17 am
Posts: 139
Post Strange digit appears on list from PyDataSet
I had this code on the click of a button which produced a list?? of column names, it has just been noticed that the results of this have changed in that every column name in the list is preceeded by a "u", i.e. [u'Mains_Water', u'Hotwell_Water', u'Hotwell_Steam', u'Energy_parasitic']. The "u" never used to be there. Did upgrade to 7.4 a couple of weeks ago, other than that I am baffled?? :scratch:
if I add "print value" into the loop the values are correct, if I add "print search" then the "u"'s appear in the console.

Code:
event.source.parent.start = 1
event.source.parent.end = 5

search = []
columns = system.dataset.toPyDataSet(event.source.parent.column_names)
for row in columns:
   for value in row:
      search.append(value)
      
event.source.parent.search = search[event.source.parent.start:event.source.parent.end]


Fri Apr 27, 2012 4:51 am
Profile
Moderator
Moderator

Joined: Mon Oct 27, 2008 4:10 pm
Posts: 1901
Location: Folsom, CA
Post Re: Strange digit appears on list from PyDataSet
Those u's are indicating that it's a Python unicode string. When printing the list as a whole you should see them; this is the correct behavior.

_________________
Kevin Herron
Software Developer
Inductive Automation


Fri Apr 27, 2012 5:54 am
Profile WWW
Colonel
Colonel

Joined: Mon Nov 15, 2010 4:17 am
Posts: 139
Post Re: Strange digit appears on list from PyDataSet
Oops! posted this in wrong Forum! - But how come this used to work (no "U"'s) and now errors with a fault that indicates the SQL query is wrong! When I added an extra expression to "replace" the "U"'s with "" the code then worked like it did originally!! Something has changed??? :scratch:


Fri Apr 27, 2012 1:03 pm
Profile
Moderator
Moderator

Joined: Mon Oct 27, 2008 4:10 pm
Posts: 1901
Location: Folsom, CA
Post Re: Strange digit appears on list from PyDataSet
Hmm, not sure what you're doing that would cause those u's to get in the way of something. Can you post your whole script?

The change is because for 7.4 we upgraded from Jython 2.1 to Jython 2.5.

_________________
Kevin Herron
Software Developer
Inductive Automation


Fri Apr 27, 2012 1:24 pm
Profile WWW
Colonel
Colonel

Joined: Mon Nov 15, 2010 4:17 am
Posts: 139
Post Re: Strange digit appears on list from PyDataSet
Basically the result of the code originally posted goes to a custom property type 'string' which I then filter using three more custom properties (all expressions using the replace function to get rid of all [] and , the end result is used in a SQL query to populate a tables data. This SQL query was where the error came as no columns were called u'Mains', u'water' ..........etc, hence the need to suddenly add a fourth replace expression to get rid of the newly appearing U's.

I guess my whole method is too basic and the sort of thing a beginner would do but I just wanted to understand why a 3 month old screen suddendly went bad so as to avoid the same in future work.


Fri Apr 27, 2012 11:13 pm
Profile
Moderator
Moderator

Joined: Mon Oct 27, 2008 4:10 pm
Posts: 1901
Location: Folsom, CA
Post Re: Strange digit appears on list from PyDataSet
Right, basically what's happening is your relying Python's __str__ implementation for a list of strings. This changed between Python 2.1 and Python 2.5.

The __str__ (toString() in Java) is not something that should be relied upon in the way you're using it.

_________________
Kevin Herron
Software Developer
Inductive Automation


Sat Apr 28, 2012 6:47 am
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: