Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Phasing a tabbed file?
#4
(Dec-13-2017, 09:51 PM)j.crater Wrote: What in particular is the trouble you are having? Post the code of your attempt of tackling the problem in Python code tags, and potential error messages in error code tags, and we will look into it.

Hi there, here's my current code:
f = open("Categories List.txt", "r")
cList = f.read()
f.close()

cList = cList.split("\n")
array = {}
lastR = ""

for r in cList:    
    if r[0] == "\t":
        array[lastR].append(r[1:])
    else:
        lastR = r
        array[lastR] = []
    
print(array)
As you can see, it works fine with only one level of indentation, however, once there are multiple tabs prefixing a line, it will not correctly insert that into the correct array position. I am just not sure how to store the data in such a way you can dynamically add to any depth of the array.
Reply


Messages In This Thread
Phasing a tabbed file? - by Joseph_f2 - Dec-13-2017, 09:35 PM
RE: Phasing a tabbed file? - by j.crater - Dec-13-2017, 09:51 PM
RE: Phasing a tabbed file? - by Joseph_f2 - Dec-14-2017, 01:43 PM
RE: Phasing a tabbed file? - by ODIS - Dec-14-2017, 12:44 AM
RE: Phasing a tabbed file? - by Joseph_f2 - Dec-14-2017, 11:44 PM
RE: Phasing a tabbed file? - by ODIS - Dec-15-2017, 03:53 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020