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 8092677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:20:12+00:00 2026-06-05T20:20:12+00:00

I have many many files in a folder, and I want to process them

  • 0

I have many many files in a folder, and I want to process them one after another, I need to have a global dictionary to record the user identifier and the flowcount, but if my code is like this, when the second or third file is processed, the user_dict for last file will lose.

Because if an user id in the second file is as same as in the first file, then if should be assigned the same flowcount instead of a new one, how can I make one dictionary keep growing when open files one by one?

 for line in fd.readlines():
    obj = json.loads(line)
    user = obj["host_dst"]["addr"] + '_' + str(obj["host_dst"]["port"])
    if user not in user_dict:
       user_dict[user] = []
    user_dict[user].append(obj["params"]["flowcount"])

Since the size of each file is very big, I merged them all into one file, then ran the script to process, the computer will kill the process after a while, I have to process them one by one instead

  • 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-05T20:20:13+00:00Added an answer on June 5, 2026 at 8:20 pm

    You can open multiple files in your python script, and use your for loop to take care each of them

    for filename in os.listdir(folderpath):
        filepath = os.path.join(folderpath, filename)
        fd = open(filepath, 'r')
    
        # here is your code
        for line in fd.readlines():
            ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many directories with files in them. I want to create a comma
I have a folder with far too many files in, and I want to
I have many different NSArray 's stored in .dat files, in the Documents folder
I have a folder that contains many different files: folder1: somthing.php somthingelse.php blah.php ect
I have many text files containing bank transactions in the middle of them. Each
I have a folder with many LaTeX files that all use the same custom
I have many .mp3 files stored in res/raw folder. I am getting URI of
I have a folder called Client which contains many subfolders. I want to create
I accidentally added many files (test files) which I do not want them to
I want to copy a folder from server which contains many files but without

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.