Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to read numbers from a text file in python

with open('file') as f:
    w, h = [int(x) for x in next(f).split()] # read first line
    array = []
    for line in f: # read rest of lines
        array.append([int(x) for x in line.split()])
Comment

PREVIOUS NEXT
Code Example
Python :: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable 
Python :: integer colomn to datetime 
Python :: godot setget 
Python :: remove specific word from string using python 
Python :: python print percent sign 
Python :: convert string to integer in dictionary python 
Python :: ValueError: `logits` and `labels` must have the same shape, received ((None, 2) vs (None, 1)). 
Python :: install python 3.6 on centos 
Python :: how to hide a widget in tkinter python 
Python :: instabot python 
Python :: pandas Unnamed: 0 
Python :: django group by 
Python :: time.sleep() faster 
Python :: keras linear regression 
Python :: remove extra spaces python 
Python :: Plot regression line from sklearn 
Python :: if list of columns exist pandas 
Python :: pandas backfill 
Python :: pygame.rect 
Python :: import spacy nlp = spacy.load("ar_core_web_sm") 
Python :: how to resize tkinter window 
Python :: elif in django template 
Python :: python - remove columns with same name and keep first 
Python :: list of numbers 
Python :: python sort dictionary by key 
Python :: python find intersection of two lists 
Python :: how do i convert a list to a string in python 
Python :: how to sort a dictionary py 
Python :: django.db.utils.ProgrammingError: relation "users" does not exist in django 3.0 
Python :: creating base models django 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =