How to save a tuple in a Textfile and access it with this code in Python

时间:2016-02-12 21:24:14

标签: python

I really want to finish my personal vocabulary trainer. It works fine, but I am having problems with saving the list into a text file and access it, after exiting the program.

Please note that I am a beginner in Python, so it would be great, if I could have an explanation for the solution. Thanks

Here´s my code so far:

Group by

I am grateful for any help.

2 个答案:

答案 0 :(得分:1)

Try to implement _ str _ method in your Entry class:

In [12]:
df.drop(pd.to_datetime('2000-01-06'))

Out[12]:
                   A         B         C
Date                                    
2000-01-01 -0.401531 -1.076727  0.519324
2000-01-02  0.022450  0.655763 -0.592045
2000-01-03  0.579927  1.358475  0.803414
2000-01-04  0.346246 -0.252332 -1.347014
2000-01-05  0.101308  0.912279  0.020754
2000-01-07  0.869264  0.699575  0.385521
2000-01-08  0.098829 -0.237605  1.112033

and then use it as follows:

def __str__(self):
    return '%s - %s' % (self.deutsch, self.englisch)

答案 1 :(得分:1)

You are outputting the wrong data. Instead of

_get_formatter

you want:

eintraege.append(Entry(deutsch, englisch))

or just:

eintraege.append( Entry(deutsch, englisch).toString() )

Python does not recognize the "Entry" type and will not automatically convert it to a string, so you need to fill you list with strings, NOT Entry objects.