English 中文(简体)
字典和书面文件的使用价值
原标题:appending value in python and writing to a file

我在Sharma做了一个班子,并做了罚款。 现在,我需要把结果变成一个文本文件,我也可以这样做。 问题在于,我需要把结果和结果本身包括在内。 我是新来的,现在仍在利用这个辛子,因此将非常感激任何帮助。

    printedRow =  {id1},{result1} .format(id1=id , result1 = result)
    print("~~~~~RESULT~~~~~")

    for k in range(0,len(pans)):
         pans.append(row[0] +  , + p.classify(row))

    print (pans)
    print(pans, file=outfile)

在指数行[0]中,我需要列入班级结果的补贴。 当我管理该守则时,该笔补助金将按每次结果印制。 这些结果正在印刷中,我只需要能够与结果相匹配。

这两份文件都列入清单,每个清单中约有2000年数值。

问题回答

I am not sure what you are trying to do because you don t define what row or pans are. Consider using more Pythonic source code. If an object is a collection of any type, then use some sort of iterator. Enumerate is useful to give each loop an index number.

for n, p in enumerate(pans):
    print "pan %d is %s" % (n, p)

您似乎也正在读到<代码>pans,其大小取决于<代码>pan。 这可以永远继续下去。

如果你想在清单中添加,仅增加:

newpans = pans + [x.classify(row) for x in oldpans]

而不是建立记忆结构,然后将其印成档案,直接写到档案中。 这将大大降低记忆。 如果你想要加快速度,请电脑将档案存放给你,例如。

f = open("output.txt", "w")
for n, p in enumerate(pans):
    f.write("%s,%s
" % (n, classify(p)))
f.close()




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签