hehe, só vendo o ['Arquivo de configuracao da arquitetura'] da pra ver que é brasileiro =)
I didn't undestand, what didn't worked? I've tryied this, and all went ok:
list1 = ['name', 'value'] list2 = ['path', 'c:\some\path'] list3 = [list1, list2] print str(list3).replace('\\\\','\\')
[['name', 'value'], ['path', 'c:\some\path']] On 3/12/07, Fabio Gomes <[EMAIL PROTECTED]> wrote:
It didn't work. I decided to submit the code in the list. It is a script running with Jython to modify some configurations in the Websphere Application Server that has a Java like command line that interprets jython or jacl. I decided to use Jython. All the properties in that server are stored in hierarchy in the form of lists into lists. An exemple of one of the properties follows: ['systemProperties', [[['description', 'Arquivo de configuracao da arquitetura'], ['name', 'A_INI'], ['required', 'false'], ['value', '/xml/a_ini.xml']], [['description', 'Raiz do Ambiente'], ['name', 'A_ROOT'], ['required', 'false'], ['value', 'file://D:\\A\\D9']]]] All above in a single string. To make the things easier to me and the other people who will read that script, I decided to declare each subset of lists separatly. Something like that: list1 = ['name', 'value'] list2 = ['path', 'c:\some\path'] list3 = [list1, list2] But doing that, list2 will be parsed by repr() and will receive an extra '\' when inserted int list3, messing up with the path information. I need some aproach to build that string without have to write it in one long and confuse string. Maybe hash tables will be the answer. I need to read about it. The entire code follows, remembering you that AdminConfig is an object present only in the WebSphere: # # Creates the JVM custom properties A_INI and A_ROOT # # Custom Properties attr1_desc = ['description', 'Arquivo de configuracao da arquitetura'] attr1_name = ['name', 'A_INI'] attr1_required = ['required', 'false'] attr1_value = ['value', '/xml/a_ini.xml'] attr1_List = [attr1_desc, attr1_name, attr1_required, attr1_value] attr2_desc = ['description', 'Raiz do Ambiente'] attr2_name = ['name', 'A_ROOT'] attr2_required = ['required', 'false'] # ID of all application servers allServers = AdminConfig.getid('/Server:/') import java lineSeparator = java.lang.System.getProperty('line.separator') arrayAllServers = allServers.split(lineSeparator) # processing for each server for serverID in arrayAllServers: # bypass if it isn't an (real) application server if AdminConfig.showAttribute(serverID, 'name') == 'dmgr': continue if AdminConfig.showAttribute(serverID, 'name') == 'nodeagent': continue if AdminConfig.showAttribute(serverID, 'name') == 'webserver': continue serverName = AdminConfig.showAttribute(serverID, 'name') print 'Atualizando o servidor', serverName, '...' jvm = AdminConfig.list('JavaVirtualMachine', serverID) path = 'file://D:\\A\\' + serverName[5:] attr2_value = ['value', path] attr2_List = [attr2_desc, attr2_name, attr2_required, attr2_value] attr_List = [attr1_List, attr2_List] property = ['systemProperties', attr_List] AdminConfig.modify(jvm, [property]) print 'Salvando configuracoes...' AdminConfig.save() #EOF ------------------------------ Date: Mon, 12 Mar 2007 13:40:58 -0300 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: backslashes in lists CC: python-list@python.org just like the same way, but replace alist -> list: str(list).replace('\\\\','\\') as the time you call str(object) you will have an object of type string, and you can do whatever you want/could do with it... what are you trying?! isn't more interesting use a hash table? On 3/12/07, *Fabio Gomes* <[EMAIL PROTECTED] > wrote: Nice, Lucas. But help me again, please. What about "echoing" the list: >>> str(alist).replace('\\\\','\\') "['a', 'b', 'c:\\some\\path']" Because in my script I'm echoing the list to mount lists into lists, like: >>> list1 = ['name', 'test'] >>> list2 = ['path', 'c:\some\path'] >>> list = [list1, list2] >>> print list [['name', 'test'], ['path', 'c:\\some\\path']] That's how it is coded in my script. What do you think. Is it possible to print "list" without the doubled backslash? Thank again, Lucas. ------------------------------ Date: Mon, 12 Mar 2007 12:15:10 -0300 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: backslashes in lists CC: python-list@python.org I don't know how ugly this look like, but { print str(alist).replace('\\\\', '\\') } works... On 3/12/07, * Fabio Gomes* <[EMAIL PROTECTED]> wrote: Yes, Luca. I noticed that printing the list item will show the string as expected. But I need to print the entire list in the script I'm writing and doing that, the list will will be repr()'ed. Is there any way to print the entire list without being parsed by repr()? ------------------------------ Date: Mon, 12 Mar 2007 12:00:19 -0300 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: backslashes in lists CC: python-list@python.org The backslash is a key to enter especial characters, like breakline: '\n' There is two backslashes cause of this especial condition of this char, but if you try print the specific string you will see that only one backslash remain: print alist[2] On 3/12/07, *Fabio Gomes* <[EMAIL PROTECTED] > wrote: Hi list, I'm trying to use a string with backslashes in a list. But Python parses strings in lists with repr(). >>> alist = ['a', 'b', 'c:\some\path'] >>> alist ['a', 'b', 'c:\\some\\path'] >>> print alist ['a', 'b', 'c:\\some\\path'] I already tried str() and raw (r) but it didn't work. All I want is to keep a single backslash in the string since it is a path information. Can anyone help me, please? Thank you. ------------------------------ O Windows Live Spaces está aqui! Descubra como é fácil criar seu espaço na Web e sua rede amigos. Confira! <http://spaces.live.com/signup.aspx> -- http://mail.python.org/mailman/listinfo/python-list ------------------------------ Busque em qualquer página da Web com alta proteção. Obtenha o Windows Live Toolbar GRATUITO ainda hoje! Experimente agora! <http://toolbar.live.com/> -- http://mail.python.org/mailman/listinfo/python-list ------------------------------ O Windows Live Spaces está aqui! Descubra como é fácil criar seu espaço na Web e sua rede amigos. Confira! <http://spaces.live.com/signup.aspx> -- http://mail.python.org/mailman/listinfo/python-list ------------------------------ Ligue para os seus amigos grátis. Faça chamadas de PC-para-PC pelo messenger-- GRÁTIS Experimente agora!<http://get.live.com/messenger/overview> -- http://mail.python.org/mailman/listinfo/python-list
-- http://mail.python.org/mailman/listinfo/python-list