简体   繁体   English

Python suds文件

[英]Python suds file

I'm newbie as with python as programming, poor English also... 我是python编程的新手,英语也很差。

I have a doubt, I'm using suds to get methods from a WSDL and then sometimes it returns me type instance or type text, when it returns me instance I could manipulate the object like a list, but like a text I couldn't, so I try to parse it, but it's too big, and the structure of the text there are a lot of "\\n", so I thought, maybe I can read and treat like a file.txt and for each "\\n" I get a list element. 我有一个疑问,我正在使用suds从WSDL中获取方法,然后有时它返回我类型实例或键入文本,当它返回我实例时,我可以像列表一样操作对象,但是像文本一样,我不能,所以我尝试解析它,但是它太大了,并且文本的结构中有很多“ \\ n”,所以我想,也许我可以像对待file.txt一样对待每个“ \\ n “我得到一个列表元素。 But I have no idea how I can turn a string or "Text" in .txt Can you help me? 但是我不知道如何在.txt中转换字符串或“文本”,您能帮我吗?

my python.py: 我的python.py:

#!/usr/bin/python


from suds.client import Client

import xml.etree.ElementTree as ET

url = 'https://gpadev.servicedesk.net.br/dataservices/application/clients/clients.asmx?WSDL'

d = dict(http='******', https='********')

client = Client(url, proxy = d, username= '******', password = '********')

method = client.service.Export('*******')

type (method)

it returns me: 它返回我:

type text

if a print, I get something like: 如果有印刷品,我会得到类似:

CLIENT,FULLNAME,SEX,NICKNAME,BOSS,TITLE,MANAGER,INACTIVE,NETID,EMAILID,EMAILALT,NOTIFYMAIL,PAGERNUMBER,NOTIFYPAGER,PHONELBL1,PHONE1,PHONELBL2,PHONE2,PHONELBL3,PHONE3,ADDRESS,ADDRESS2,ZIP,CITY,STATE,DIVISION,REGION,LOCATION,ORGUNIT,CHARGE,SLEVEL,SKILL,LANGID,TIMEZONE,NOTES,CLIENT_LIST_MANAGELEVEL,ANALYST_LIST_PROFILE **\n** CLIENT,FULLNAME,SEX,NICKNAME,BOSS,TITLE,MANAGER,INACTIVE,NETID,EMAILID,EMAILALT,NOTIFYMAIL,PAGERNUMBER,NOTIFYPAGER,PHONELBL1,PHONE1,PHONELBL2,PHONE2,PHONELBL3,PHONE3,ADDRESS,ADDRESS2,ZIP,CITY,STATE,DIVISION,REGION,LOCATION,ORGUNIT,CHARGE,SLEVEL,SKILL,LANGID,TIMEZONE,NOTES,CLIENT_LIST_MANAGELEVEL,ANALYST_LIST_PROFILE **\n** .......**\n** .......**\n** .......**\n**

thanks for helping me 谢谢你帮我

There are at least two things in your question: 您的问题至少有两件事:

  1. how to split a string into a list of lines 如何将字符串拆分为行列表
  2. how to save a string into an ASCII file (.txt) 如何将字符串保存到ASCII文件(.txt)

For the first thing: it's as easy as calling lines=method.split('\\n') , then you can iterate through the returned lines list. 首先,它就像调用lines=method.split('\\n') ,然后您可以遍历返回的lines列表。

For the second thing: 第二件事:

with open("path to save the file + filename.txt", "w") as f:
  f.write(method)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM