从python写一组文件到一个文件 [英] to write set of values to a file from python

查看:61
本文介绍了从python写一组文件到一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧


i希望从python中为一个文件写一组值。

对于ex :: the fields name将comp name ;,ip addr,mac addr等等。
在所有这些字段之下,我将获得这些字段的值。


看起来应该是这样的。


comp name ipaddr macaddr

jdasfhjashd 234.347.23.12

334.12.354.43.232

dfdsfusdaufisa 234.533。 45.12 89.234.234.2343

sfdidsfoui 234.45.23.56

89.343.23.45.233


类似这样的东西。


所以这是最好的方法。

我的意思是哪种文件格式最好选择,转储所有

这些值来自我的python脚本。


它是一个.ini吗?文件格式?或.xls或或.txt这将是

更好的一个。

所以以后我会很容易阅读这个文件。


谢谢提前帮助


问候

yogi

解决方案

< blockquote> mu*******@yahoo.com schrieb:

hi大家好我想写一组来自python文件的值。
对于ex ::字段名称将是comp name,ip addr,mac地址"
在所有这些领域下面我会得到这些领域的价值。

看起来应该是这样的。

comp name ipaddr macaddr

jdasfhjashd 234.347.23.12
334.12.354.43.232
dfdsfusdaufisa 234.533.45.12 89.234.234.2343
sfdidsfoui 234.45.23.56
89.343.23.45.233

像这样的东西。

这是最好的方法。
我的意思是哪种文件格式最好选择,转储所有
我的python脚本中的这些值。

它是否是一个.ini。文件格式?或.xls或或.txt这将是更好的一个。
以便以后我很容易阅读这个文件。

提前感谢您的帮助

>问候
yogi



我会使用逗号分隔值(CSV)文件。

看看csv模块

< http://www.python.org/doc/2.4.2/lib/module-csv.html>。


再见,

Dennis


hi dennis,

感谢您的帮助,看来它的好方法。

i试了一下,我喜欢这个主意,但是它有一个问题。


它在一个单独的行中打印每个字符,其中

i想要每个字符串在一个单独的栏目中?


所以我该怎么做?对此有任何帮助。


感谢和问候

yogi


mu ******* @ yahoo.com schrieb:

[...]
它将每个字符打印在一个单独的行中,我希望每个字符串在一个单独的列中?

所以我该怎么做?对此有任何帮助。
[...]




你能在这里发布你的代码吗?或者解释一下你到底做了什么。


再见,

丹尼斯


hi everybody

i want to write a set of values to a file from python.
For ex:: the fields name will "comp name", "ip addr", "mac addr" etc.
And below all these fields i ll have the values for these fields.

it should look some what like this.

comp name ipaddr macaddr

jdasfhjashd 234.347.23.12
334.12.354.43.232
dfdsfusdaufisa 234.533.45.12 89.234.234.2343
sfdidsfoui 234.45.23.56
89.343.23.45.233

something like thiss.

so which is the best way to do this.
I mean which file format would be the best to choose , to dump all
these values from my python script.

Will it be a ".ini" file format? or ".xls" or ".txt" which will be the
better one.
so that later it will be easy for me to read this file.

thanks in advance for the help

regards
yogi

解决方案

mu*******@yahoo.com schrieb:

hi everybody

i want to write a set of values to a file from python.
For ex:: the fields name will "comp name", "ip addr", "mac addr" etc.
And below all these fields i ll have the values for these fields.

it should look some what like this.

comp name ipaddr macaddr

jdasfhjashd 234.347.23.12
334.12.354.43.232
dfdsfusdaufisa 234.533.45.12 89.234.234.2343
sfdidsfoui 234.45.23.56
89.343.23.45.233

something like thiss.

so which is the best way to do this.
I mean which file format would be the best to choose , to dump all
these values from my python script.

Will it be a ".ini" file format? or ".xls" or ".txt" which will be the
better one.
so that later it will be easy for me to read this file.

thanks in advance for the help

regards
yogi


I would use a comma separated values (CSV) file.
Have a look at the csv module
<http://www.python.org/doc/2.4.2/lib/module-csv.html>.

Bye,
Dennis


hi dennis,
thanks for the help, itseems its good way to go.
i tried it, and i liked the idea, but there is one problem with it.

its printing each character in a seperate row where as
i want each string in a seperate column?

so how can i do that?? Any help for this.

thanks and regards
yogi


mu*******@yahoo.com schrieb:

[...]
its printing each character in a seperate row where as
i want each string in a seperate column?

so how can i do that?? Any help for this.
[...]



Could you post your code here? Or explain what you did exactly.

Bye,
Dennis


这篇关于从python写一组文件到一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆