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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:31:41+00:00 2026-06-06T03:31:41+00:00

Traditionally, to read a file filled with an array in python, I use the

  • 0

Traditionally, to read a file filled with an array in python, I use the following syntax

x, y, z = loadtxt("myfile.txt", unpack=True)

It works well for single-array files.

Now, I have a more complicated file :

1.5 3.5 2.5 1.6
4
3
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
1 2
3 4
5 6

What I want to do is the following thing :

1.5 3.5 2.5 1.6 -> I want to put them in an array of three variables + 1 scalar

4 -> A = 4, Number of lines of my first array

3 -> B = 3, Number of lines of my second array

My first array with A = 4 lines that I want to load in 5 variables (like the command loadtxt(“”, unpack = True)

1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20

My first array with B = 3 lines that I want to load in 2 variables (like the command loadtxt(“”, unpack = True)

1 2
3 4
5 6

Is there any technique to do this kind of things in python ?

Thank you very much.

  • 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-06T03:31:43+00:00Added an answer on June 6, 2026 at 3:31 am

    You are specifying your own file format, which is not very useful. I would suggest using an existing format such as JSON:

    myfile.txt:

    {
        "a" : [
            [1, 2, 3, 4, 5],
            [6, 7, 8, 9, 10],
            [11, 12, 13, 14, 15],
            [16, 17, 18, 19, 20]
        ],
        "b" : [
        ...
        ]
    }
    

    read.py

    import json
    myfile = open("myfile.txt")
    myVars = json.load(myfile)
    myfile.close()
    myVars['a']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Python file that needs to read in several files of
I am using spring. I need to read values from properties file. This is
I am attempting to read and process the contents of a csv file in
Real simple question really. I need to read a Unicode text file in a
I make program to read xml file by using traditional JavaScript. <script type=text/javascript> var
I recently read the the following SO question. What's the best way to store
Traditionally when using a DbCommand when retrieving data from a sproc, something like the
Traditionally, we try to avoid LazyInitializationException s. However, I need to temporarily allow them
I'm traditionally a .NET developer and am spoiled for choice when it comes to
I have a pretty common layout issue that I have traditionally used a table

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.