Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 7th, 2013, 11:49 AM
stascrash stascrash is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Location: Chicago
Posts: 11 stascrash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 18 sec
Reputation Power: 0
Send a message via Google Talk to stascrash Send a message via Skype to stascrash
String Formatting Problems

Hi guys,
i am moving along with my development, and i am currently facing another obstacle that cannot figure out, if any of you have an idea, please share. here is my case:
working with SQL DB, Python and 3D max.

1. Get list of file path stored in DB
2. Get list of file path stored in 3D Max
3. Make a match
4. IF match TRUE - say OK
5. IF match FALSE - update 3D max with Path from DB.
----
I return 'unicode' type from DB E:\Textures\box_texture_01.jpg
i return 'str' type from 3D max ['E:\\Textures\\box_texture_01.jpg']

---
when i try to match the two - i get FALSE (however names are same). I am suspecting that this is due to the way of output. I tried converting unicode to str, but no luck.
i tired working out the solution using string formatting, see my test case below:
Code:
Python Code:
Original - Python Code
  1. testStr = str(tex_path[0])
  2. print testStr
  3. testStr = testStr.split("\\")
  4. print testStr
  5. testStr = "\\\\".join(testStr)
  6. print testStr
  7. print maxTexturePathList[0]
  8.  
  9. if testStr == str(maxTexturePathList[0]):
  10.     print "matching"
  11. else:
  12.     print "not matching"


the outputs that i was able to get were:
from DB (original with SINGLE "\") was converted to "\\",
however, visually they match, but when i tested using IF it failed.

any idea how i can make the two file PATH to be match correctly?
Thanks!

Reply With Quote
  #2  
Old March 8th, 2013, 12:22 AM
partoj partoj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 138 partoj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 39 m 41 sec
Reputation Power: 1
Quote:
Originally Posted by stascrash
[...]
when i try to match the two - i get FALSE (however names are same). I am suspecting that this is due to the way of output. I tried converting unicode to str, but no luck.
[...]


Try converting the 3DS Max path to unicode before comparing.

Code:
>>> a = u'E:\\Textures\\box_texture_01.jpg'
>>> b = ['E:\\Textures\\box_texture_01.jpg'] 
>>> a == unicode(b[0])
True

Reply With Quote
  #3  
Old March 8th, 2013, 11:40 AM
stascrash stascrash is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Location: Chicago
Posts: 11 stascrash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 18 sec
Reputation Power: 0
Send a message via Google Talk to stascrash Send a message via Skype to stascrash
Hey, thanks for suggestion, it did not work out, i was able to convert to unicode, by still no go, i tired another alternative, and i think that i am getting close, however i have another problem, here is a more complete code with comments:

Code:
Python Code:
Original - Python Code
  1. maxTexturePathList.sort() #sort array
  2. tex_path.sort() #sort array
  3.  
  4. maxPath = maxTexturePathList[0] #assign new string value( TYPE STRING)rom collected array
  5. maxPath = maxPath.split("\\") #split string to array
  6. maxPath = filter(None, maxPath) # remove ''(empty) from array
  7. #test output
  8. print "Max Path:"
  9. print len(maxPath)
  10. print maxPath
  11.  
  12. tex01 = str(tex_path[0])#assing new UNICODE value from collected array
  13. tex01 = tex01.split("\\")#split unicode to array
  14. #test output
  15. print "Texture path:"
  16. print len(tex01)
  17. print tex01
  18. #The output of LEN is equal, so i skip testing for LEN
  19.  
  20. #test if each array element [0],[1] is a match
  21. for i in range(len(tex01)):
  22.     if maxPath[i] == tex01[i]:
  23.         print "matching"
  24.     else:
  25.         print "not matching"


My output looks like this:
Quote:
Max Path:
6
["['E:", 'sporitskiy', '3dsMaxProjects', 'ProjectDemo', 'Textures', "box_texture_01.jpg']"]
Texture path:
6
['E:', 'sporitskiy', '3dsMaxProjects', 'ProjectDemo', 'Textures', 'box_texture_01.jpg']
not matching
matching
matching
matching
matching
not matching


The first element that is "NOT MATCHING" is the drive letter, for some reason, it created an array element, but it used
'E:" (single quote, Drive letter, double quote) same as for the last element,

any ideas how i can either FIX this during the .split operation or replace it afterwords, and what would be the reason for this to happen?

Thanks!

Reply With Quote
  #4  
Old March 8th, 2013, 12:22 PM
partoj partoj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 138 partoj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 39 m 41 sec
Reputation Power: 1
I think the reason that you're getting the strange array values is that 'maxTexturePathList[0]' has been converted from a list to a string (in an earlier part of the code). This could easily be verified by a simple print statement of that variable just below line 4.

If you see my example below, you will notice that it gets the exact same output.

Code:
>>> maxPath = ['E:\\Textures\\box_texture_01.jpg']
>>> maxPath = str(maxPath)
>>> maxPath
"['E:\\\\Textures\\\\box_texture_01.jpg']"
>>> maxPath.split("\\")
["['E:", '', 'Textures', '', "box_texture_01.jpg']"]


So my suggestion would be that you shouldn't convert the list to a string, but instead read out the string by accessing index 0 of the list.

Reply With Quote
  #5  
Old March 8th, 2013, 01:04 PM
stascrash stascrash is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Location: Chicago
Posts: 11 stascrash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 18 sec
Reputation Power: 0
Send a message via Google Talk to stascrash Send a message via Skype to stascrash
Thumbs up

partoj:

THANK YOU !!! it worked out. took me a little time to read through the code, i have noticed, that WAY on top, the MAX variable is being assigned a STR(var).

as soon as i cleaned that all up:

Quote:
Max Path:
E:\sporitskiy\3dsMaxProjects\ProjectDemo\Textures\box_texture_01.jpg
Texture path:
E:\sporitskiy\3dsMaxProjects\ProjectDemo\Textures\box_texture_01.jpg

matching


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > String Formatting Problems

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap