Syntax error in python. Error with an = sign - python

def InitialiseSudoku(): # this function is for initialisation of the sudoku function
cols = '0123456789ABCDEF'
rows = 'ABCDEFGHIJKLMNOP'
global coordinates
coordinates = represent(rows, cols)
global subgridlist
subgridlist = ([represent(rows, c) for c in cols] + [represent(r, cols) for r in rows] + [represent(rs, cs) for rs in
subgrids = dict((s, [u for u in subgridlist if s in u]) for s in coordinates)
global constraintpartners
constraintpartners = dict((s, set(sum(subgrids[s], [])) - set([s])) for s in coordinates)
global dictionary
global value
i = 0
for s in coordinates:
dictionary[s] = ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1']
value[s] = input_list[i]
prune_domain[s] = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
i = i + 1
this produces a syntax error on the line:
subgrids = dict((s, [u for u in subgridlist if s in u]) for s in coordinates)
the specific error is the = sign

In general errors often are on the line before the error lists (this is because the line before is valid up to expecting a particular syntax construction.
This seems to be an instance of that case, on line 9 you state
for rs in
But that's not complete, it should be
for rs in <iterable/variable>
Where iterable/variableis whatever you are iterating over.

Related

Use a captured value as row identifier

I need to parse this raw data in order to process it:
Port Align-Err FCS-Err Xmit-Err Rcv-Err UnderSize OutDiscards
Gi0/1 1 2 3 4 5 6
Gi0/2 11 12 13 14 15 16
Port Single-Col Multi-Col Late-Col Excess-Col Carri-Sen Runts Giants
Gi0/1 1 2 3 4 5 6 7
Gi0/2 111 122 133 144 155 166 177
To do this, I'm using TextFSM.
I would want this output:
['Gi0/1', '1', '2', '3', '4', '5', '6', '1', '2', '3', '4', '5', '6', '7']
['Gi0/2', '11', '12', '13', '14', '15', '16', '111', '112', '113', '114', '115', '116', '117']
The first template I wrote is this one:
Value PORT (\S+(/\d+)?)
Value ALIGNERR (\d+)
Value FCSERR (\d+)
Value XMITERR (\d+)
Value RCVERR (\d+)
Value UNDERSIZE (\d+)
Value OUTDISCARDS (\d+)
Value SINGLECOL (\d+)
Value MULTICOL (\d+)
Value LATECOL (\d+)
Value EXCESSCOL (\d+)
Value CARRISEN (\d+)
Value RUNTS (\d+)
Value GIANTS (\d+)
Start
^Port\s+Align-Err.* -> FIRST
^Port\s+Single-Col.* -> SECOND
FIRST
^${PORT}\s+${ALIGNERR}\s+${FCSERR}\s+${XMITERR}\s+${RCVERR}\s+${UNDERSIZE}\s+${OUTDISCARDS} -> Continue.Record
SECOND
^${PORT}\s+${SINGLECOL}\s+${MULTICOL}\s+${LATECOL}\s+${EXCESSCOL}\s+${CARRISEN}\s+${RUNTS}\s+${GIANTS} -> Record
However, the output is not right:
['Gi0/1', '1', '2', '3', '4', '5', '6', '', '', '', '', '', '', '']
['Gi0/2', '11', '12', '13', '14', '15', '16', '', '', '', '', '', '', '']
['Gi0/1', '1', '2', '3', '4', '5', '6', '', '', '', '', '', '', '']
['Gi0/2', '111', '122', '133', '144', '155', '166', '', '', '', '', '', '', '']
I found a post on the forum giving a solution in pure Regex: TextFSM logic - Avoid capturing same data twice
When I adapt it to my needs, I have a match for what I need: https://regex101.com/r/DY0Meb/6
However, I'm unable to translate it in a TextFSM template, it fails.
Here is my template:
Value PORT (\S+(/\d+)?)
Value ALIGNERR (\d+)
Value FCSERR (\d+)
Value XMITERR (\d+)
Value RCVERR (\d+)
Value UNDERSIZE (\d+)
Value OUTDISCARDS (\d+)
Value SINGLECOL (\d+)
Value MULTICOL (\d+)
Value LATECOL (\d+)
Value EXCESSCOL (\d+)
Value CARRISEN (\d+)
Value RUNTS (\d+)
Value GIANTS (\d+)
Start
^${PORT}\s+${ALIGNERR}\s+${FCSERR}\s+${XMITERR}\s+${RCVERR}\s+${UNDERSIZE}\s+${OUTDISCARDS}(?=.*\1\s+${SINGLECOL}\s+${MULTICOL}\s+${LATECOL}\s+${EXCESSCOL}\s+${CARRISEN}\s+${RUNTS}\s+${GIANTS}) -> Record
Any clue about why I don't have any matches?
I'm a beginner in Regex, and I can't seem to find the solution...
Any help would be very welcome :).
Thanks in advance!
There is a bit simpler way exists:
from ttp import ttp
import pprint
data = """
Port Align-Err FCS-Err Xmit-Err Rcv-Err UnderSize OutDiscards
Gi0/1 1 2 3 4 5 6
Gi0/2 11 12 13 14 15 16
Port Single-Col Multi-Col Late-Col Excess-Col Carri-Sen Runts Giants
Gi0/1 1 2 3 4 5 6 7
Gi0/2 111 122 133 144 155 166 177
"""
template = """
<group name="{{ interface }}*">
{{ interface | exclude("Port") }} {{ counters | ROW | resub("\s+", ",", 200) | split(",") }}
</group>
"""
parser = ttp(data, template)
parser.parse()
res = parser.result()[0][0]
# res is this now:
# {'Gi0/1': [{'counters': ['1', '2', '3', '4', '5', '6']},
# {'counters': ['1', '2', '3', '4', '5', '6', '7']}],
# 'Gi0/2': [{'counters': ['11', '12', '13', '14', '15', '16']},
# {'counters': ['111', '122', '133', '144', '155', '166', '177']}]}
ret = []
for interface, counters in res.items():
ret.append([interface])
for i in counters:
ret[-1] += list(i.values())[0]
pprint.pprint(ret, width=100)
# will print:
# [['Gi0/1', '1', '2', '3', '4', '5', '6', '1', '2', '3', '4', '5', '6', '7'],
# ['Gi0/2', '11', '12', '13', '14', '15', '16', '111', '122', '133', '144', '155', '166', '177']]
TTP - is a library I created to make solutions for above tasks to look simpler.
I finally managed to do what I want.
My team wished to use Ansible for the formatting, so I had to improvise a bit.
I used ntc-ansible for that.
With the help of members of the NTC Slack, I finally got it working. Here's what I came up with:
A functionality that is very poorly documented on the TextFSM repo is that you can, in an index file, combine two templates that share a common "Key" attribute.
So I created two templates:
Value Key PORT (\S+(/\d+)+)
Value ALIGNERR (\d+)
Value FCSERR (\d+)
Value XMITERR (\d+)
Value RCVERR (\d+)
Value UNDERSIZE (\d+)
Value OUTDISCARDS (\d+)
Start
^Port\s+Align-Err.* -> Begin
Begin
^${PORT}\s+${ALIGNERR}\s+${FCSERR}\s+${XMITERR}\s+${RCVERR}\s+${UNDERSIZE}\s+${OUTDISCARDS} -> Record
^Port\s+Single-Col.* -> End
And:
Value Key PORT (\S+(/\d+)+)
Value SINGLECOL (\d+)
Value MULTICOL (\d+)
Value LATECOL (\d+)
Value EXCESSCOL (\d+)
Value CARRISEN (\d+)
Value RUNTS (\d+)
Value GIANTS (\d+)
Start
^Port\s+Single-Col.* -> Begin
Begin
^${PORT}\s+${SINGLECOL}\s+${MULTICOL}\s+${LATECOL}\s+${EXCESSCOL}\s+${CARRISEN}\s+${RUNTS}\s+${GIANTS} -> Record
Then, I created an index file containing this:
Template, Hostname, Vendor, Command
show_int_counter_errors1.template:show_int_counter_errors2.template, .*, cisco_ios, sh[[ow]] int[[erfaces]] cou[[nter]] er[[rors]]
You can test it in Python with this little script:
import textfsm
import sys
from textfsm import clitable
# Define Input Data
input_data = sys.stdin.read()
# Initialise CliTable with the content of the 'index' file.
cli_table = clitable.CliTable('index', '.')
# Firstly we will use attributes to match a 'show version' command on a Cisco device.
attributes = {'Command': sys.argv[1], 'Vendor': 'cisco_ios'}
# Parse Data
cli_table.ParseCmd(input_data, attributes)
print(cli_table)
To launch it, just use this command:
python3 test_table.py 'show interface counter errors' < show_int_counter_errors.txt
To use it in Ansible, after installing ntc-ansible, create a 'templates' directory, put the index file and the template files in it, and specify the directory path in the playbook:
- hosts: all
connection: local
gather_facts: no
tasks:
- name: Formatting the errors
ntc_show_command:
connection: ssh
platform: cisco_ios
command: 'show interfaces counter errors'
use_templates: True
template_dir: 'PATH/TO/TEMPLATES/DIRECTORY'
host: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
register: interface_errors
- name: Display the registered variable
debug:
var: interface_errors
Hope this can help anybody :).

How to save the list in to .txt?

I have to save 'Record' into text file. So I have tried to use name_error_record.write( record[0]+" "+record[1]+" "+record[2]+" "+record[3]) but it doesn't work...
I have to align as 'No Menu_name Num Total' and save it into text file. please help..
The list that I have to save is [['No.', 'Menu_name', 'Num', 'Total'], ['4', 'Smoothie_queen', '4', '12000'], ['10', 'Amorparty', '2', '4000'], ['24', 'Plane_yougurt', '14', '49000'], ['36', 'Cofe_latte', '18', '45000'], ['51', 'Cofe_latte', '16', '40000'], ['53', 'Berry_smudie', '17', '51000'], ['54', 'American_air', '4', '8000']]
and also it has to be aligned by columns as 'No Menu name Num Total'.
I think I am missing something but I can't find them.. help T.T
def error_check(date):
#========= STEP 3 ==========
Record = []
errormenu = []
recordfile = open("ledger_"+date+".txt","r")
errormenufile = open("menu.txt", "r")
for error in errormenufile:
menu = error.split()
errormenu.append(menu[0])
errormenufile.close()
for line in recordfile:
record = line.split()
Record.append(record)
Record = [x for x in Record if errormenu[0] not in x]
Record = [x for x in Record if errormenu[1] not in x]
Record = [x for x in Record if errormenu[2] not in x]
Record = [x for x in Record if errormenu[3] not in x]
Record = [x for x in Record if errormenu[4] not in x]
name_error_record = open("ledger_"+date+"_name_error.txt","r")
for record in Record:
name_error_record.write( record[0]+" "+record[1]+" "+record[2]+" "+record[3])
name_error_record.close()
#========= STEP 3 ==========
Simply change 'r' to 'w' in:
open("ledger_"+date+"_name_error.txt","r")
open("ledger_"+date+"_name_error.txt","w")
by setting 'w' you open file for writing
you can add '\n' at the end of saved line in:
name_error_record.write( record[0]+" "+record[1]+" "+record[2]+" "+record[3]+'\n')
to save data line by line
l=[['No.', 'Menu_name', 'Num', 'Total'], ['4', 'Smoothie_queen', '4', '12000'], ['10', 'Amorparty', '2', '4000'], ['24', 'Plane_yougurt', '14', '49000'], ['36', 'Cofe_latte', '18', '45000'], ['51', 'Cofe_latte', '16', '40000'], ['53', 'Berry_smudie', '17', '51000'], ['54', 'American_air', '4', '8000']]
filename='' # add filenmae
with open(filename, 'w+') as file:
for i in l:
file.write('{} {} {} {}\n'.format(*i))

Change the value for multiple items in list python

I have a nested list:
Table=[['','','','',''],
['','','','',''],
['','','','',''],
['','','','',''],
['','','','',''],
['','','','','']]
I have randomly placed some values in Table and now I want to place other things in the 2D neighbours of those values. E.g.:
Table=[['','','','',''],
['','','','',''],
['','','','',''],
['','','value','',''],
['','','','',''],
['','','','','']]
Then i want to add:
Table=[['','','','',''],
['','','','',''],
['','','1','',''],
['','1','value','1',''],
['','','1','',''],
['','','','','']]
Under is all my code i don't know why but it would accept it in any other format sorry :/
def add_nukes():
pos=j.index('nuke')
if "nuke" not in j[0]:j[pos+1]='1'
if "nuke" not in j[-1]:
j[pos-1] = "1"
board[pos][i-1]="1"
board[i+1][pos]="1"
import random
size=150
if size%2==1:
size+=1
board = [[" "]*size for i in range(size)]
bombs = 25
all_cells = ["nuke"] * bombs + [" "] * (size - bombs)
random.shuffle(all_cells)
board = [all_cells[i:i+10] for i in range(0, size, 10)]
count=0
for j in board:
for i in range(len(j)):
count+=1
if "nuke" in j[i]:
add_nukes()
elif "nuke" in j[i]:
add_nukes()
for item in board:
print item
Any value in Table is identified uniquely by its x and y coordinates, i.e. the element in the 2nd column (x == 1 because 0-indexed) and 3rd row (y == 2) is Table[y][x] == Table[2][1].
The four immediate neighbours of any cell A are the cells with x one away from A OR with y one away from A. If A is Table[y][x], then the neighbours are [Table[y - 1][x], Table[y + 1][x], Table[y, x - 1], Table[y, x + 1]].
Just like #Aurel Bílý mentioned, there are four neighbouring coordinates in which you need to add value for the specific case: [Table[y - 1][x], Table[y + 1][x], Table[y, x - 1], Table[y, x + 1]].
In order to do that, you must first ensure that these coordinates are valid and do not throw an IndexError exception. After you make sure that this coordinates are valid, you can safely add them in your table.
The code below demonstrates this:
Table=[['','','','',''],
['','','','',''],
['','','','',''],
['','','value','',''],
['','','','',''],
['','','','','']]
def isInBounds(Table,x,y):
return 0 <= x < len(Table) and 0 <= y < len(Table[0])
def addValue(Table,x,y,value):
if isInBounds(Table,x,y):
Table[x][y] = value
def addValuesAround(Table,x,y,value):
addValue(Table,x-1,y,value)
addValue(Table,x,y-1,value)
addValue(Table,x+1,y,value)
addValue(Table,x,y+1,value)
addValuesAround(Table,3,2,1)
for elem in Table:
print(elem)
This will return:
['', '', '', '', '']
['', '', '', '', '']
['', '', 1, '', '']
['', 1, 'value', 1, '']
['', '', 1, '', '']
['', '', '', '', '']
EDIT:
I think I got it, using both of our codes. Just be sure to change the syntax of the print function, because you're using Python 2.7 and I use Python 3.6:
import random
def isInBounds(Table,x,y):
return 0 <= x < len(Table) and 0 <= y < len(Table[0])
def addValue(Table,x,y,value):
if isInBounds(Table,x,y):
Table[x][y] = value
def addValuesAround(Table,x,y,value):
addValue(Table,x-1,y,value)
addValue(Table,x,y-1,value)
addValue(Table,x+1,y,value)
addValue(Table,x,y+1,value)
size=150
if size%2==1:
size+=1
board = [[" " for i in range(size)] for i in range(size)]
bombs = 25
all_cells = ["nuke"] * bombs + [" "] * (size - bombs)
random.shuffle(all_cells)
board = [all_cells[i:i+10] for i in range(0, size, 10)]
count=0
for i in range(len(board)):
for j in range(len(board[i])):
if board[i][j] == 'nuke':
addValuesAround(board,i,j,"1")
for item in board:
print(item)
This will give an instance of a board like this:
[' ', ' ', ' ', ' ', '1', ' ', '1', ' ', '1', ' ']
[' ', ' ', ' ', '1', 'nuke', '1', 'nuke', '1', 'nuke', '1']
['1', ' ', ' ', ' ', '1', ' ', '1', ' ', '1', '1']
['nuke', '1', '1', '1', 'nuke', '1', ' ', ' ', '1', 'nuke']
['1', '1', 'nuke', '1', '1', ' ', '1', ' ', ' ', '1']
[' ', ' ', '1', ' ', ' ', '1', 'nuke', '1', ' ', ' ']
[' ', ' ', '1', ' ', ' ', '1', '1', ' ', ' ', ' ']
[' ', '1', 'nuke', '1', '1', 'nuke', '1', ' ', ' ', ' ']
['1', 'nuke', '1', ' ', '1', '1', '1', ' ', '1', ' ']
[' ', '1', 'nuke', '1', 'nuke', '1', 'nuke', '1', 'nuke', '1']
['1', 'nuke', '1', ' ', '1', ' ', '1', ' ', '1', ' ']
[' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
[' ', '1', 'nuke', '1', ' ', '1', ' ', '1', ' ', ' ']
[' ', ' ', '1', ' ', '1', 'nuke', '1', 'nuke', '1', ' ']

Making QComboBox widgets distinguishable in a for loop using PyQt5

I'm having trouble with an application that creates a grid of QComboBox widgets (see picture below). I use a for loop to create the elements of the grid.
QComboBox grid layout
I would like to be able to treat each QComboBox separately. Here is the code without attempts to do so:
grid = QGridLayout()
combos = [
'1', '1', '1', '', '1',
'1', '1', '1', '', '1',
'1', '1', '1', '', '1',
'1', '1', '1', '', '1']
positions = [(i,j) for i in range(5) for j in range(5)]
for position, dcombo in zip(positions, combos):
if dcombo == '':
continue
combo = QComboBox()
for x in range(0, 30):
combo.addItem(QIcon("/icons/%d.PNG" % x),"")
combo.setFixedSize(120,100)
combo.setIconSize(QSize(100,100))
grid.addWidget(combo, *position)
comboList['combo{0}'.format(position)] = position
Here is my attempt, and the point at which I am currently stuck:
grid = QGridLayout()
combos = [
'1', '1', '1', '', '1',
'1', '1', '1', '', '1',
'1', '1', '1', '', '1',
'1', '1', '1', '', '1']
comboList = {}
positions = [(i,j) for i in range(5) for j in range(5)]
for position, drawcombo in zip(positions, combos):
if drawcombo == '':
continue
combo = QComboBox()
for x in range(0, 30): #
combo.addItem(QIcon("absolver deck reviewer/icons/%d.PNG" % x),"")
combo.setFixedSize(120,100)
combo.setIconSize(QSize(100,100))
grid.addWidget(combo, *position)
comboList['combo{0}'.format(position)] = position
combo.currentIndexChanged.connect(lambda: self.logChange(comboList['combo{0}'.format(position)]))
def logChange(self, currentCombo):
sender = self.sender()
print(str(currentCombo) + ' was changed')
The print() method only ever returns the last position in the list (in this case, the (3, 4) tuple.
As the position variable changes this is overwritten by it only prints the last one, if you want it not to be overwritten you must pass it as an argument to the lambda function, besides. And for this you must also pass as an argument the variable that sends the signal, in your case use the following:
combo.currentIndexChanged.connect(
lambda ix, p=position: self.logChange(comboList['combo{0}'.format(p)]))

How to read this file,with skipping some lines using Python?

I need to skip 47 lines of the file(header and so on),then read this
4.163186002791e+04 3.578830331359e+04 3.076496349687e+04 2.644671278966e+04 2.273458304119e+04
1.954349752908e+04 1.680032112209e+04 1.444218412726e+04 1.241504140604e+04 1.067243373686e+04
9.174423035938e+03 7.886677033340e+03 6.779682426302e+03 5.828068476394e+03 5.010025548360e+03
1.737988920100e+03 1.284332855871e+03 1.104060538508e+03 8.158747205330e+02 7.013564117662e+02
6.029121922103e+02 5.182858606802e+02 4.455379022877e+02 2.433020871700e+02 2.091515701348e+02
1.797945089525e+02 1.545580816278e+02 1.328639052196e+02 9.818329499070e+01 7.255514128762e+01
5.361653963401e+01 4.609078195788e+01 3.962135930423e+01 3.406000172766e+01 2.927925083995e+01
2.516953864546e+01 2.163667639887e+01 1.859969593339e+01 1.598899398582e+01 1.374473698894e+01
1.181548977143e+01 1.015703673713e+01 8.731368506527e+00 7.505810795983e+00 6.452275569743e+00
5.546617302183e+00 4.768079596776e+00 4.098819479081e+00 3.523498461194e+00 3.028931005477e+00
2.603782330822e+00 2.238308635635e+00 1.924133783786e+00 1.654057335509e+00 1.421889523591e+00
1.222309392724e+00 1.050742850800e+00 9.032578372386e-01 7.764742057598e-01 6.674862562538e-01
5.737961402745e-01 4.932566139141e-01 3.133421372728e-01 2.315524554696e-01 1.990511474577e-01
1.711118080085e-01 1.470941072881e-01 1.264475938317e-01 1.086990789815e-01 9.344179207682e-02
8.032605785014e-02 6.905128236880e-02 5.935906385039e-02 5.102727046220e-02
possibly as list,and then again skip 21 lines and read the part of the file in same format as presented above.
Firstly my idea was something like this:
from itertools import islice
n=15
with open('91_FULLMERGED.edi') as f:
lines_after_48 = f.readlines()[48:]
while True:
next_15_lines = list(islice(lines_after_48, n))
if not next_15_lines:
break
But that is not working.
milenko#milenko-HP-Compaq-6830s:~/EDIs$ python k1.py
It is just standing still in terminal.
How to solve this?
Code
I use the csv reader cause the format is csv with delimiter ' '. At first I just skipped 47 lines by just next(f,None). Afterwards the csv module is making the trick. If you want to output as a file you can just use the csv writer. You can uncomment the code if you want to remove the empty strings from the output list. But then the output to the file is not similar to the input. It depends on how you wanna use the data.
import csv
with open('input.txt', 'rb') as f:
for i in range(47):
next(f, None)
reader = csv.reader(f,delimiter=' ')
values = list(reader)
# if you want to remove the ''
#for idx, val in enumerate(values):
# values[idx] = [x for x in values[idx] if x != '']
print values
with open('output.txt', 'wb') as f:
writer = csv.writer(f, delimiter=' ', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for line in values:
writer.writerow(line)
Output to screen
[['4.163186002791e+04', '', '3.578830331359e+04', '', '3.076496349687e+04', '', '2.644671278966e+04', '', '2.273458304119e+04'],
['1.954349752908e+04', '', '1.680032112209e+04', '', '1.444218412726e+04', '', '1.241504140604e+04', '', '1.067243373686e+04'],
['9.174423035938e+03', '', '7.886677033340e+03', '', '6.779682426302e+03', '', '5.828068476394e+03', '', '5.010025548360e+03'],
['1.737988920100e+03', '', '1.284332855871e+03', '', '1.104060538508e+03', '', '8.158747205330e+02', '', '7.013564117662e+02'],
['6.029121922103e+02', '', '5.182858606802e+02', '', '4.455379022877e+02', '', '2.433020871700e+02', '', '2.091515701348e+02'],
['1.797945089525e+02', '', '1.545580816278e+02', '', '1.328639052196e+02', '', '9.818329499070e+01', '', '7.255514128762e+01'],
['5.361653963401e+01', '', '4.609078195788e+01', '', '3.962135930423e+01', '', '3.406000172766e+01', '', '2.927925083995e+01'],
['2.516953864546e+01', '', '2.163667639887e+01', '', '1.859969593339e+01', '', '1.598899398582e+01', '', '1.374473698894e+01'],
['1.181548977143e+01', '', '1.015703673713e+01', '', '8.731368506527e+00', '', '7.505810795983e+00', '', '6.452275569743e+00'],
['5.546617302183e+00', '', '4.768079596776e+00', '', '4.098819479081e+00', '', '3.523498461194e+00', '', '3.028931005477e+00'],
['2.603782330822e+00', '', '2.238308635635e+00', '', '1.924133783786e+00', '', '1.654057335509e+00', '', '1.421889523591e+00'],
['1.222309392724e+00', '', '1.050742850800e+00', '', '9.032578372386e-01', '', '7.764742057598e-01', '', '6.674862562538e-01'],
['5.737961402745e-01', '', '4.932566139141e-01', '', '3.133421372728e-01', '', '2.315524554696e-01', '', '1.990511474577e-01'],
['1.711118080085e-01', '', '1.470941072881e-01', '', '1.264475938317e-01', '', '1.086990789815e-01', '', '9.344179207682e-02'],
['8.032605785014e-02', '', '6.905128236880e-02', '', '5.935906385039e-02', '', '5.102727046220e-02']]
Output to file output.txt
4.163186002791e+04 3.578830331359e+04 3.076496349687e+04 2.644671278966e+04 2.273458304119e+04
1.954349752908e+04 1.680032112209e+04 1.444218412726e+04 1.241504140604e+04 1.067243373686e+04
9.174423035938e+03 7.886677033340e+03 6.779682426302e+03 5.828068476394e+03 5.010025548360e+03
1.737988920100e+03 1.284332855871e+03 1.104060538508e+03 8.158747205330e+02 7.013564117662e+02
6.029121922103e+02 5.182858606802e+02 4.455379022877e+02 2.433020871700e+02 2.091515701348e+02
1.797945089525e+02 1.545580816278e+02 1.328639052196e+02 9.818329499070e+01 7.255514128762e+01
5.361653963401e+01 4.609078195788e+01 3.962135930423e+01 3.406000172766e+01 2.927925083995e+01
2.516953864546e+01 2.163667639887e+01 1.859969593339e+01 1.598899398582e+01 1.374473698894e+01
1.181548977143e+01 1.015703673713e+01 8.731368506527e+00 7.505810795983e+00 6.452275569743e+00
5.546617302183e+00 4.768079596776e+00 4.098819479081e+00 3.523498461194e+00 3.028931005477e+00
2.603782330822e+00 2.238308635635e+00 1.924133783786e+00 1.654057335509e+00 1.421889523591e+00
1.222309392724e+00 1.050742850800e+00 9.032578372386e-01 7.764742057598e-01 6.674862562538e-01
5.737961402745e-01 4.932566139141e-01 3.133421372728e-01 2.315524554696e-01 1.990511474577e-01
1.711118080085e-01 1.470941072881e-01 1.264475938317e-01 1.086990789815e-01 9.344179207682e-02
8.032605785014e-02 6.905128236880e-02 5.935906385039e-02 5.102727046220e-02
My Input Values I used
SKIP (for line 1 ... removed 45 Lines for better readablity
SKIP to line 47)
4.163186002791e+04 3.578830331359e+04 3.076496349687e+04 2.644671278966e+04 2.273458304119e+04
1.954349752908e+04 1.680032112209e+04 1.444218412726e+04 1.241504140604e+04 1.067243373686e+04
9.174423035938e+03 7.886677033340e+03 6.779682426302e+03 5.828068476394e+03 5.010025548360e+03
1.737988920100e+03 1.284332855871e+03 1.104060538508e+03 8.158747205330e+02 7.013564117662e+02
6.029121922103e+02 5.182858606802e+02 4.455379022877e+02 2.433020871700e+02 2.091515701348e+02
1.797945089525e+02 1.545580816278e+02 1.328639052196e+02 9.818329499070e+01 7.255514128762e+01
5.361653963401e+01 4.609078195788e+01 3.962135930423e+01 3.406000172766e+01 2.927925083995e+01
2.516953864546e+01 2.163667639887e+01 1.859969593339e+01 1.598899398582e+01 1.374473698894e+01
1.181548977143e+01 1.015703673713e+01 8.731368506527e+00 7.505810795983e+00 6.452275569743e+00
5.546617302183e+00 4.768079596776e+00 4.098819479081e+00 3.523498461194e+00 3.028931005477e+00
2.603782330822e+00 2.238308635635e+00 1.924133783786e+00 1.654057335509e+00 1.421889523591e+00
1.222309392724e+00 1.050742850800e+00 9.032578372386e-01 7.764742057598e-01 6.674862562538e-01
5.737961402745e-01 4.932566139141e-01 3.133421372728e-01 2.315524554696e-01 1.990511474577e-01
1.711118080085e-01 1.470941072881e-01 1.264475938317e-01 1.086990789815e-01 9.344179207682e-02
8.032605785014e-02 6.905128236880e-02 5.935906385039e-02 5.102727046220e-02
give a chance to linecache. and in case of large files, try generators.
import linecache
from sys import argv
def get_specific_lines(f, start, stop):
for i in range(start, stop):
yield linecache.getline(f, i)
script, f, s, e = argv
# check code if (f)ile exists, (s)tart and (e)nd are numeric.
for line in get_specific_lines(f, int(s), int(e)):
print line
$ wc -l asbc.txt
197310 asbc.txt
$ python read.py asbc.txt 144322 144325
Bu yarım dəqiqə ərzində Qleb qabaqcadan dəqiq hesablanmış ləng hərəkətlə əlini qəbulediciyə uzatdı, diktora xırıldamağa imkan vermədən boynunu bururmuş kimi açarın dəstəyini burdu.
Onun azca bundan əvvəlki canlı sifəti yorğun, bozumtul rəng almışdı.
Pryançikovun başı isə başqa problemə qarışmışdı. Hansı gücləndirici kaskadı qoymaq lazım olduğu haqda fikirləşə-fikirləşə o, qayğısız zümzümə edirdi:

Categories