Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:17:09+00:00 2026-06-04T20:17:09+00:00

In my code I am trying to extract some data from a file. I

  • 0

In my code I am trying to extract some data from a file. I am getting this error when I am trying to run my code on line 61. My code here:

from datetime import date
from math import floor;
from adjset_builder import adjset_builder
def check_and_update(d,start,end,log):    
#    print start,end;
    if start in d:
        if end in d[start]:
            log.write("{0}-{1}\n".format(start, end))
            if d[start][end] == 1:
                print "one found"
            d[start][end] += 1

def build_dictionary(my_adjset,my_list,factor,outfile,log):
    log.write("building dictionary:\n");

    window_size = int(floor(len(my_list)*factor));
    if window_size<2:
        log.write("too small\n")
        return;   
    log.write('Total:{0},windowsize:{1}\n'.format(len(my_list),window_size));
    log.write("Window at place: 0,")
    for i in xrange(window_size):
        j = i+1;
        while j<window_size:
            check_and_update(my_adjset, my_list[i][1], my_list[j][1],log);
            j=j+1

    i=1;
    while i<=len(my_list)-window_size:
        log.write("{0},".format(i)) 
        j=i;
        k=i+window_size-1;
        while j<k:
            check_and_update(my_adjset, my_list[i][1], my_list[j][1],log);  
            j+=1
        i += 1  
    log.write("\nDictionary building done\n")        

def make_movie_list(infilename,factor):
    log=open('log.txt','w');
    outfile=open(infilename.split('.')[0]+"_plot_"+str(factor)+".txt",'w');
    f=open(infilename,'r');
    my_adjset=dict()
    adjset_builder('friends.txt', my_adjset);

    count =1
    while True:        
        string = f.readline();
        if string=='':
            break;        
        log.write("count:{0}\n".format(count))
        count += 1

        [movie,freunde] = string.split('=');
        freunde = freunde.split(';')
        mylist=[]
        for i in freunde:
            [user_id,date] = i.split(' ');
            [yy,mm,dd] = date.split('-');  
#            l=list((date(int(yy),int(mm),int(dd)),user_id))
            mylist.append([date(int(yy),int(mm),int(dd)),user_id]); ## line 61         
        log.write("list built");   
        print mylist         
        break;    
#        build_dictionary(my_adjset, mylist, factor,outfile,log) 
        del(mylist);   

    print 'Done'

    log.close();
    outfile.close();
    f.close();
    print count 


if __name__ == '__main__':    
    make_movie_list('grades_processed.txt',.5)

However when I tried to simulate the same thing in ‘Console’ I do not get any error:

dd='12'
mm='2'
yy='1991'
user_id='98807'  
from datetime import date
from datetime import date
l=list((date(int(yy),int(mm),int(dd)),user_id))
l [datetime.date(1991, 2, 12), '98807']

Might be something very silly but I am a beginner so can not seem to notice the mistake. Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:17:12+00:00Added an answer on June 4, 2026 at 8:17 pm

    This makes date a function:

    from datetime import date
    

    This makes date a string:

            [user_id,date] = i.split(' ');
    

    You get a TypeError now, since date is no longer a function:

    mylist.append([date(int(yy),int(mm),int(dd)),user_id]); 
    

    One way to avoid this error is to import modules instead of functions:

    import datetime as dt
    mylist.append([dt.date(int(yy),int(mm),int(dd)),user_id])
    

    or more succinctly,

    mylist.append([dt.date(*date.split('-')), user_id])
    

    PS: Remove all those unnecessary semicolons!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to extract some textual data from a PDF file. To do this,
I'm trying to extract functions and function headers from some source code files. Here's
I'm trying to extract data from an xml file. A sample of my code
I'm trying to write a code to extract some form data from a HTML
I'm trying to write some code to extract Exif information from a JPG. Exif
I'm getting an error in my python code when trying to import one of
I'm trying to extract some data from XML using Linq to XML, and I
I'm trying to use ruby and mongoid in order to extract some data from
I am trying to extract some data from XML but when I execute the
I'm trying to extract some certain data from a website using JSoup and Java.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.