I had help on this matter pairing IP Addresses from this site which worked. I tried to amend the same script to use to pair Port numbers but keep getting a float attribute error. I have tried changing it but as a newbie I have failed to make any headway please help.
This is the data
['', '', '', '', '', '', '', 'Pool Member Port', '', 10001.0, 10001.0, '', '', '', '', '', '', '', 11001.0, 11001.0, '', '', '', '', '', '', '', 12001.0, 12001.0, '', '', '', '', '', '', '', 14001.0, 14001.0, '', '', '', '', '', '', '', 14001.0, 14001.0, '', '', '', '', '', '', '', 14001.0, 14001.0, '', '', '', '', '', '', '', 14001.0, 14001.0, '', '', '', '', '', '', '', 14001.0, '', 10001.0, '', '', '', '', '', '', '', '', 11001.0, '', '', '', '', '', '', '', '', 12001.0, '', '', '', '', '', '', '', '', 14001.0, '', '', '', '', '', '', '', '', 22.0, '', '', '', '', '', '', '', '', 22.0, '', 22.0, '', '', '', '', '', '', '', '', 14001.0, '', '', '', '', '', '', '', '', '', '', '', 'Receive string', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
This is my amended script
Pool_Ports = [[]]
for x in PPoData[PPoData.index('Pool Member Port'):]:
if not x:
if Pool_Ports[-1]:
Pool_Ports.append([])
else:
#Pool_Ports[-1].append(x.partition(' ')[0])
print(Pool_Ports)
error message
AttributeError: 'float' object has no attribute 'partition'
Previous link which works for IP addresses
Pair IP addresses in a list pulled from xlrd
The error is simple, really. Your input list has it's ports values (e.g. 11001.0) stored as floats, therefore the code breaks. The instant fix would be casting x to string right before the partition.
Pool_Ports[-1].append(str(x).partition(' ')[0])
However, the output ends up being
[['10001.0', '10001.0'], ['11001.0', '11001.0'], ['12001.0',
'12001.0'], ['14001.0', '14001.0'], ['14001.0', '14001.0'],
['14001.0', '14001.0'], ['14001.0', '14001.0'], ['14001.0'],
['10001.0'], ['11001.0'], ['12001.0'], ['14001.0'], ['22.0'],
['22.0'], ['22.0'], ['14001.0'], ['Receive'], []]
Which is not what you need, beacuse it has ['Receive'] and [], which are not valid pool ports.
So, inspired by #cᴏʟᴅsᴘᴇᴇᴅ 's answer to the previous question, I would recommend you to use regex.
import re
PPoData = ['', '', '', '', '', '', '', 'Pool Member Port', '', 10001.0, 10001.0, '', '', '', '', '', '', '', 11001.0, 11001.0, '', '', '', '', '', '', '', 12001.0, 12001.0, '', '', '', '', '', '', '', 14001.0, 14001.0, '', '', '', '', '', '', '', 14001.0, 14001.0, '', '', '', '', '', '', '', 14001.0, 14001.0, '', '', '', '', '', '', '', 14001.0, 14001.0, '', '', '', '', '', '', '', 14001.0, '', 10001.0, '', '', '', '', '', '', '', '', 11001.0, '', '', '', '', '', '', '', '', 12001.0, '', '', '', '', '', '', '', '', 14001.0, '', '', '', '', '', '', '', '', 22.0, '', '', '', '', '', '', '', '', 22.0, '', 22.0, '', '', '', '', '', '', '', '', 14001.0, '', '', '', '', '', '', '', '', '', '', '', 'Receive string', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
pattern = '\d+\.\d+'
Pool_Ports = [[]]
for x in PPoData:
if not x and Pool_Ports[-1]:
Pool_Ports.append([])
m = re.match(pattern, str(x))
if m:
Pool_Ports[-1].append(str(x))
if [] in Pool_Ports:
Pool_Ports.remove([])
print(Pool_Ports)
# [['10001.0', '10001.0'], ['11001.0', '11001.0'], ['12001.0', '12001.0'], ['14001.0', '14001.0'], ['14001.0', '14001.0'], ['14001.0', '14001.0'], ['14001.0', '14001.0'], ['14001.0'], ['10001.0'], ['11001.0'], ['12001.0'], ['14001.0'], ['22.0'], ['22.0'], ['22.0'], ['14001.0']]
Related
I have this dictionary named element, and a list of dictionaries named l1
l1 = [{"parent_id": "",
"productid": "6x2562",
"sequence_no": "1",
"quantity": "8.000",
"listprice": "",
"discount_percent": "",
"discount_amount": "",
"comment": "new list item 1",
"description": "some text",
"lineitem_id": "1",
"tax4": "",
"id": ""},
{"parent_id": "",
"productid": "6x2562",
"sequence_no": "1",
"quantity": "8.000",
"listprice": "",
"discount_percent": "",
"discount_amount": "",
"comment": "new list item 1",
"description": "some text",
"lineitem_id": "1",
"tax4": "",
"id": ""}]
element = {
"subject": "testtest ",
"potential_id": "",
"quotestage": "Created",
"validtill": "2023-03-11 10:48:10.339414",
"contact_id": "4x540",
"id": "",
"LineItems": []
}
element dictionary contains an empty list as a value to a key named LineItems. I am inserting a list of dictionaries (l1) in place of this empty list using following code:
element['LineItems'].append(l1)
print(element)
The problem I am having is that I am getting the following result which contains two [ ] brackets rather then one.
My current output:
{'subject': 'testtest ', 'potential_id': '', 'quotestage': 'Created', 'validtill': '2023-03-11 10:48:10.339414', 'contact_id': '4x540', 'id': '', 'LineItems': [[{'parent_id': '', 'productid': '6x2562', 'sequence_no': '1', 'quantity': '8.000', 'listprice': '', 'discount_percent': '', 'discount_amount': '', 'comment': 'new list item 1', 'description': 'some text', 'lineitem_id': '1', 'tax4': '', 'id': ''}, {'parent_id': '', 'productid': '6x2562', 'sequence_no': '1', 'quantity': '8.000', 'listprice': '', 'discount_percent': '', 'discount_amount': '', 'comment': 'new list item 1', 'description': 'some text', 'lineitem_id': '1', 'tax4': '', 'id': ''}]]}
Expected Output:
{'subject': 'testtest ', 'potential_id': '', 'quotestage': 'Created', 'validtill': '2023-03-11 10:48:10.339414', 'contact_id': '4x540', 'id': '', 'LineItems': [{'parent_id': '', 'productid': '6x2562', 'sequence_no': '1', 'quantity': '8.000', 'listprice': '', 'discount_percent': '', 'discount_amount': '', 'comment': 'new list item 1', 'description': 'some text', 'lineitem_id': '1', 'tax4': '', 'id': ''}, {'parent_id': '', 'productid': '6x2562', 'sequence_no': '1', 'quantity': '8.000', 'listprice': '', 'discount_percent': '', 'discount_amount': '', 'comment': 'new list item 1', 'description': 'some text', 'lineitem_id': '1', 'tax4': '', 'id': ''}]}
I have no idea how to do this as I have been searching for whole day now.
Any help will be appreciated.
Thanks in advance!
As the example shows the peak of the black line is between 3 and 4, and I don't know how to do it.
The close I can get from w3c school example is:
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<body>
<canvas id="myChart" style="width:100%;max-width:600px"></canvas>
<script>
var xValues = [0,1,2,3,4,5];
new Chart("myChart", {
type: "line",
data: {
labels: xValues,
datasets: [{
data: [80,120,300,40,0,0],
borderColor: "orange",
fill: false
}, {
data: [2,5,20,150,250,50],
borderColor: "black",
fill: false
}]
},
options: {
legend: {display: false}
}
});
</script>
Thanks for reading through.
const labels = [0, '', '', '', 10, '', '', '', 20, '', '', '', 30, '', '', '', 40, '', '', '', 50];
Set the X labels this way; it will work.
I want to write a Sudoku App for which i have a List in a List of Maps to highlight and show the integers in the playfield.
My list looks like this:
List<List<Map<String, dynamic>>> output = [
[
{'integer': '', 'color': Colors.purple},
{'integer': '', 'color': Colors.purple},
{'integer': '', 'color': Colors.purple},
{'integer': '', 'color': Colors.purple},
{'integer': '', 'color': Colors.purple},
{'integer': '', 'color': Colors.purple},
{'integer': '', 'color': Colors.purple},
{'integer': '', 'color': Colors.purple},
{'integer': '', 'color': Colors.purple},
],
[
{'integer': '', 'color': Colors.purple},
{'integer': '', 'color': Colors.purple},
...
So i want to change the color of a specific Area. I have tried some googlin and came up with this and some variations:
selectField(indexBlock, index) {
output[indexBlock][index]['color'] = Colors.white;
output[indexBlock].getRange(0, 8).['color'] = Colors.purpleAccent; // this part with getRange is not working like i want it to
notifyListeners();
}
i have alot of this line
('235753', 'BayEnesYT', '$2y$12$laiU7F7HWJoXuryMTmgb6uKDfiOcxqD/R6Mxjg.KVNn2TK/Ra2Vwq', 'BNnuyZNL', 'zb6WPCvWYDwQmwZJQI7sypkc6oqVjZpSvnlg8gYYztJm6JYmJh', 'm.enesberber2009#gmail.com', '0', '0', '', '', '', '2', '', '0', '', '1560100802', '1560689379', '1560102670', '0', '', '0', '', '', '', '', '', 'all', '', '1', '0', '0', '0', '1', '0', '1', '0', '1', '0', 'linear', '1', '1', '1', '1', '1', '1', '0', '0', '0', '', '', '', '0', '0', '', '', '0', '0', '0', '0', '', '', '', '0', '0', '0', 0x51D69F63, 0x5567522E, '', '1894', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', '', '0', '0.00', '1', '0', '0', '0', '', '1', '1', '2', '0', '0', '0', '0', '[]', '1', null, null, null, '1', '', '', '0', '0', '0', '', '', '', '', '', '0', '', '', '', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '', '0', '', '0', '0', '0', '', '', '', '', '', '', '', '', '', '', '0', '', 'mybb_bcrypt', '0', '');
and i need to remove text before the 5th comma and after the 6th comma
so the result would be m.enesberber2009#gmail.com only
i want to use regex replacement method with notepad++
Replace this expression
^\(?(?:'[^']*',\s*){5}('[^']+').+
with the first captured group, see a demo on regex101.com.
I am not sure why I am having a hard time with this, I have this SQL file:
insert into table_name values ('Danny:2:1429543183', 195621, 'My Stuff', '', 'Fake', '', '', 0, 1429553870, 1429543183, 1429543183, 1429543183, 0, 1, 1, 0, 0, '', 0, 0, 0, 0, '', 0, 0, 0, '', '', 0, 0, '', 0, '', 0, 0, '', 0, 0, '', '', '', '', '', '', '', '', '', 0, 0, '', '', 'P', 195621, '', '', 0, 0, '', 0, 1429543183, 0, '', '', 0, '', '', 0, 0, '', '', 1);
I want to change every thing that starts with 142* to a new value.
sed 's:\(142.*).*\,/\1 93284209348\g' /tmp/1 --> Nope
sed "s/[, 142*,]/ 93284209348,/"g /tmp/1 --> Changes everything to 93284209348
I think I'm getting a headache :)
This should do:
sed 's/\([ :]\)142[0-9]*/\193284209348/g' file
insert into table_name values ('Danny:2:93284209348', 195621, 'My Stuff', '', 'Fake', '', '', 0, 93284209348, 93284209348, 93284209348, 93284209348, 0, 1, 1, 0, 0, '', 0, 0, 0, 0, '', 0, 0, 0, '', '', 0, 0, '', 0, '', 0, 0, '', 0, 0, '', '', '', '', '', '', '', '', '', 0, 0, '', '', 'P', 195621, '', '', 0, 0, '', 0, 93284209348, 0, '', '', 0, '', '', 0, 0, '', '', 1);
Edit: fixed so that the first number has correct start : and other uses space.
This might work for you (GNU sed):
sed 's/\<142[0-9]*/93284209348/g' file