Python

Moderators: None (Apply to moderate this forum)
Number of threads: 473
Number of posts: 1172

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
tuple of list/tuple pointing to list Posted by sverkerlarson on 17 Dec 2012 at 8:44 AM
  logg = 'c:\\tmp\\Logg\\12-12-13.txt'
  f=open(logg,'r')
  file = f.readlines()
  f.close
  Data={}
  feltypen=()
  
  for line in open(logg):
 
    if len(line)>142:
      grab= (line)
      #dörrpanel
      sekvens = grab[31:38] #last layer put in list
      model= grab[39:47] #this is toplayer
      feltyp= grab[161:] #sorted under the toplayer
      if model in Data:
        if feltyp in Data[model]:
          try:
            (feltyp).append(sekvens)
          except:
            (feltyp)=()
            (feltyp).append(sekvens)
        else:
          Data[model].append(feltyp)
          feltyp)=()
          (feltyp).append(sekvens)


I know my syntax is messed up, but I cant find a way to write this code to get it to work. thanks for all help
Report
Re: tuple of list/tuple pointing to list Posted by sverkerlarson on 17 Dec 2012 at 8:57 AM
  logg = 'c:\\tmp\\Logg\\12-12-13.txt'
  f=open(logg,'r')
  file = f.readlines()
  f.close
  Data={}
  feltypen=()
  
  for line in open(logg):
 
    if len(line)>142:
      grab= (line)
      #dörrpanel
      sekvens = grab[31:38] #last layer put in list
      model= grab[39:47] #this is toplayer
      feltyp= grab[161:] #sorted under the toplayer
      if model in Data:
        if feltyp in Data[model]:
          try:
            (feltyp).append(sekvens)
          except:
            (feltyp)=()
            (feltyp).append(sekvens)
        else:
          Data[model].append(feltyp)
          feltyp=()
          #I know this is way wrong but I want my "sekvens" to drop in                      
          #under the list under the list pointed 
          #to from the tuple
          (feltyp).append(sekvens)
      else:
        Data.append(model:list)
        list=()
        Data[model].append(feltyp)
        (feltyp).append(sekvens)
I know my syntax is messed up, but I cant find a way to write this code to get it to work. thanks for all help


sorry for the dubble messeges but the browser crached the first time I posted and the it dubbleposted the next time.
Report
Re: tuple of list/tuple pointing to list Posted by sverkerlarson on 19 Dec 2012 at 7:14 AM
Okey I managed to solve thisone on my own.
Ended up with 2 list and 1 tupple I think =). om not that good at syntax so bare with me.

I created one list with my fruite
one list with my errormsg
and one list with my sekvens and the index of the fruite from the fruite list and the index of the errormsg from the errormsg list me a list that I later on can sort by index =)...

DataLoop=[]
feltyper=[]
modeltyp=[]

def openfile():
      f=open(logg,'r')
      file = f.readlines()
      f.close
      for line in open(logg):
        if len(line)>142:
          grab= (line)
          sekvens = grab[31:38]
          fruit= grab[39:47]
          errormsg= grab[161:]
          if feltyp in feltyper:
            num=int(feltyper.index(feltyp))
          else:
            feltyper.append(feltyp)
            num=int(feltyper.index(feltyp))
          if model in modeltyp:
            nummod=int(modeltyp.index(model))
          else:
            modeltyp.append(model)
            nummod=int(modeltyp.index(model))
          DataLoop.append((nummod,sekvens,num))


Thers probebly a 100 better ways to solve this, and if you have any pointers on my code. Please dont by scared to critesis it ;).
And yes, it probebly would be easyer to use a class for this, but I dont understand how to use classes even though I have spent more then a couple of hourese reading dummie manuels =S. So if you want to take it as your assaignment to explain class so I understan Id bee more then happy for you to give it a try.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.