in Education by
This is my Example list for you wich is stored in a textfile: DEVICE: Test HW-RELEASE: Test SERIAL-NUMBER: Test MAC-ADDRESS: Test IP-ADDRESS: Test IP-NETMASK: Test INTRANET-ADDRESS: Test INTRANETMASK: Test VERSION: Test NAME: Test CONFIG-STATUS: Test FIRMWARE-STATUS: Test HW-MASK: Test FEATUREWORD: Test REGISTERED-WORD: Test FEATURE-LIST: Test FEATURE-LIST: Test FEATURE-LIST: Test FEATURE-LIST: Test FEATURE-LIST: Test FEATURE-LIST: Test FEATURE-LIST: Test FEATURE-LIST: Test FEATURE-LIST: Test TIME: Test HTTP-PORT: Test HTTPS-PORT: Test TELNET-PORT: Test TELNET-SSL-PORT: Test SSH-PORT: Test SNMP-PORT: Test TFTP-PORT: Test LOCATION: Test COUNTRY-CODE: Test COMMENT: Test MYVPN: Test MYVPN-HOSTNAME: Test EXTENDED-NAME: Test So I want to output the data behind the colon but always only one line of it. I want to define this line via a dictionary in the script so that I can for example only enter "Device" and it gives me the name after the colon so that the names in front of the colon should act as a key. As I do the whole instead I only know roughly what I have thought up so far. Unfortunately this code doesn't work as I would like it to: data = {} with open('C:/example/example/example/example/example.txt') as fh: for line in fh: key, value = line.strip().split(':', 1) data[key] = value for x in data: print(x) Output from this code is: ValueError: not enough values to unpack (expected 2, got 1) What i expect is when i difine somthing like: x = data["DEVICE"] it should output its value which is obvoiusly "Test" JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
First, could you try print what is in line? If it is as expected (i.e. contain DEVICE: Test), make sure the whitespace handled correctly as follows. for line in fh: if line.strip(): # Ignore blank lines key, value = [x.strip() for x in line.strip().split(':', 1)] ...

Related questions

0 votes
    This is my Example list for you wich is stored in a textfile: DEVICE: Test HW-RELEASE: Test ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    This is my Example list for you wich is stored in a textfile: DEVICE: Test HW-RELEASE: Test ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    This is my Example list for you wich is stored in a textfile: DEVICE: Test HW-RELEASE: Test ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have the following dictonary: inventory = {'apple':(3, 133), 'banana':(9, 407), 'pear':( ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    I have the following dictonary: inventory = {'apple':(3, 133), 'banana':(9, 407), 'pear':( ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I have the following dictonary: inventory = {'apple':(3, 133), 'banana':(9, 407), 'pear':( ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    How will you get a space-padded string with the original string left-justified to a total of width colon?...
asked Nov 25, 2020 in Technology by JackTerrance
0 votes
    I have an issue where i want to import value from a textfile into my excel-document which it does ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    In my assignment, a series of text files are needed in order for a picross game to occur that the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    In my assignment, a series of text files are needed in order for a picross game to occur that the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    Is it possible to model transitioning data like time-zone or a working directory? State reason behind your answer....
asked Oct 16, 2020 in Technology by JackTerrance
0 votes
    This question already has answers here: When to use ":"(colon) operator in javascript vs "=" operator ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: When to use ":"(colon) operator in javascript vs "=" operator ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    Check out this example code I saw: import * as React from 'react'; const Count: React.FunctionComponent ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    2. Which of the following symbols does the formula usage in Calc start with? a. : (Colon) b. = (Equal to) C. ; (Semi colon) I Select the correct answer from above options...
asked Dec 2, 2021 in Education by JackTerrance
...