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

  • Home
  • SEARCH
  • 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 8490391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:06:10+00:00 2026-06-10T22:06:10+00:00

So like the title says im starting to learn some python and im having

  • 0

So like the title says im starting to learn some python and im having trouble picking up on this technique. What I need to accomplish is to read in some numbers and store them in a list. The text file looks like the following:

0 0 3 50

50 100 4 20

Basically these are coordinates and directions to be used for python’s turtle to make shapes. I got that part down the only problem is getting them in a correct format. So what I can not figure out is how to get those numbers from the file into [ [0, 0, 3, 50], [50, 100, 4, 20] ]
A list, with each four coordinates being a list in that one big list.

Heres my attempt but it as I said I need some help – thank you.

polyShape=[]
infile = open(name,"r")
num = int(infile.readline(2))
while num != "":
    polyShape.append(num)
    num = int(infile.readline(2))
infile.close()
  • 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-10T22:06:12+00:00Added an answer on June 10, 2026 at 10:06 pm
    with open('data.txt') as f:
        polyShape = []
        for line in f:
            line = line.split() # to deal with blank 
            if line:            # lines (ie skip them)
                line = [int(i) for i in line]
                polyShape.append(line)
    

    will give you

    [[0, 0, 3, 50], [50, 100, 4, 20]]
    

    This will work with a file that contains blank lines (or not).

    Using the with construct will close the file for you automatically when you are done, or an exception is encountered.

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

Sidebar

Related Questions

Like the title says I'm having some trouble printing out symbol codes and their
Like the title says, I need a way to detect if the build is
So, just like the title says, I need to create an application that gets
Like the title says, I just need something to migrate a set of tables
Like the title says, we need to set up WCF services between a .NET
Like the title says, my code basically does this: set proxy, test proxy, do
i want to do what the title says like this: int number1; cin>>number1; num1len=log10(number1)+1;
As the title says I have a string like this: $string = "Hello World<br>hello
Like the title says, I need to use php (wordwrap or whatever works) to
Like the title says, I'm looking for an HMAC-SHA1 implementation for C#. This will

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.