ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i have this below data from a file :
RxDqLeft RxDqRight RxVLow RxVHigh TxDqLeft TxDqRight TxVLow TxVHigh
--------------------------------------------------------------------------------
N1.C0.D0.R0: -17 15 -23 21 -19 20 -13 14
N1.C0.D0.R1: -17 16 -23 22 -19 19 -15 14
N1.C1.D0.R0: -16 17 -23 23 -12 15 -22 18
N1.C3.D0.R0: -14 14 -23 23 -12 14 -21 18
using python i want to create a script that will check this data whereby, any if any number in line N1.C0.D0.R0 is below then 10, its a failure. i want to the same on all lines. can someone please help me? i have no clue on where to start
file_location = "C:\\users\\20609\\Desktop\\lalala.txt"
with open(file_location) as f :
for line in f :
if "N" in line :
polyshape=[]
var = line.split()
print var
var = [int(i) for i in var]
polyshape.append(var)
this is what i've tried. im trying to read the numbers and make them as a variable so that later i can say : if var < int(10), make it fail
However, your target line has a field that is not an integer (the first field namely, or var[0] in your script). So these line will likely raise an exception. You can fix this by using array slicing to refer to only the fields in the array you actually want to process.
#!/usr/bin/python
with open("simhumcon.txt") as f:
for line in f :
print "-----schneidz: line = " + line
for v in line.split():
print "-----schneidz: v = " + v
if "N1.C0.D0.R0:" in v:
print "-----schneidz: enter if"
for vx in line[12:].split():
print "-----schneidz: for loop vx = " + vx
if int(vx) < 10:
print "error"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.