Long puzzled, but I just can not understand what I'm doing wrong.

There is a file with dates of type:

16 Октября 2014 19:21 16 Октября 2014 18:46 16 Октября 2014 18:41 16 Октября 2014 17:18 

.......

 from DATEspliter import DATE dates=[] o = open('date.txt').readlines() for elem in o: dates.append(elem) d = DATE(elem) if d.Month() == ['Октября']: date = {str(d.Clock()[0]):elem.strip()} Year['okt'][int(d.Day()[0])].update(date) if d.Month() == ['Сентября']: date = {str(d.Clock()[0]):elem.strip()} Year['spt'][int(d.Day()[0])].update(date) 

There is a Year dictionary with the keys 'okt', 'spt' ...
It is necessary to push a certain month in a certain key.
All is good, but my code either shoves one October in both dictionaries, or both October and September in both, as I have not tried. Although if you display an elem in each if, it "sows" them correctly. The print function proves it.

  • one
    @smilemakc, from the description it is not very clear what is happening, give an example of incorrect output to the above input. Most likely, you somewhere in October and September refer to the same object, but it’s hard to say for sure. - etki
  • @Etki if inserting print (d.Month ()) in the first if shows all ['October'], if inserting print (d.Month ()) in the second if shows all ['September']. But in the end print (Year ['okt']) and print (Year ['spt']) give identical conclusions, where there is both October and September. The output is big, the comment does not fit, here is the link to txt: drive.google.com/file/d/0B_cnSxTxOHUud1RHNGhjRDNXTW8/view - smilemakc
  • Where did Year ['spt'] and Year ['okt'] come from? - etki
  • @Etki here from here hashcode.ru/questions/368236/… - smilemakc
  • A small input text (which contains both September and October) and the corresponding formatted example (pprint) of the expected output will help with debugging, and what happens instead. The code is very hard to read. The methods Month, Clock, Day should return the values ​​themselves, not lists, in order not to use [0] everywhere. It is worth mentioning why DATE used instead of datetime from the standard library. Ideally, to bring a small self-contained script that demonstrates the problem and which can be run separately (for example, use datetime.date to avoid dependence on DATESpl - jfs

1 answer 1

Why not do this:

 dic_my={ 1:'январь', 2:'февраль', 3:'март',} 

Is not the solution to the problem?

  • The dictionary is not needed in this case, you can use a simple list: month_names_ru = [None, 'январь', 'февраль', 'март',..] . You can also look at calendar.month_name from the standard library in the Russian locale. - jfs