top-level loops

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stefan

    top-level loops

    I am writing a program (code included) and I would like to comment out
    the two top-level loops and run the code that is under it regularly,
    however, because the following code is not indented properly the
    interpreter chokes. Is there a way around this?


    #!/usr/bin/env python

    import string, sys, os

    #for i in range(0,3):
    # for j in range(0,3):

    # filePrefix = '%d_%d' % (i,j)
    # filePrefix = sys.argv[1]
    print 'Run getQ'
    os.system('~/Programs/KineticEnsemble/GetQMod/getq.exe
    /home/reza/Proteins/2ci2/2CI2.contacts ' + filePrefix + '/md\crd 1 100
    1.2 ' + filePrefix + '/q.out')

    print 'Analyze getQ results'
    file=open(fileP refix + '/q.out','r')

    fold=0.
    ufold=0.
    isOpen=1
    #numRuns=0

    for line in file.readlines( ):
    if line != '#NEWFILE\n':
    # if open:
    # numRuns += 1
    if string.atof(lin e[:-1]) < 0.15 and isOpen:
    isOpen = 0
    ufold+=1.
    elif string.atof(lin e[:-1]) > 0.85 and isOpen:
    isOpen = 0
    fold+=1.
    else:
    # print numRuns
    # numRuns = 0
    isOpen = 1

    file.close()

    print filePrefix
    print '\tpFold: %f' % ( fold/(ufold+fold))
    print '\tfold: %d ufold: %d' % (fold,ufold)
  • Karl Scalet

    #2
    Re: top-level loops

    Stefan wrote:
    [color=blue]
    > I am writing a program (code included) and I would like to comment out
    > the two top-level loops and run the code that is under it regularly,
    > however, because the following code is not indented properly the
    > interpreter chokes. Is there a way around this?
    >[/color]

    either follow Camerons suggestion :-) or:


    for x in (1,2,3):
    for y in (4,5,6):
    print 'Run it'

    change to:

    if """
    for x in (1,2,3):
    for y in (4,5,6):
    """:
    print 'Run it'

    But very likely there are other and probably better solutions.

    Karl

    Comment

    • Gerrit Holl

      #3
      Re: top-level loops

      Stefan wrote:[color=blue]
      > #!/usr/bin/env python
      >
      > import string, sys, os
      >
      > #for i in range(0,3):
      > # for j in range(0,3):
      >
      > # filePrefix = '%d_%d' % (i,j)
      > # filePrefix = sys.argv[1][/color]

      You can do:
      if True:
      if True:
      # code here

      Gerrit.

      --
      192. If a son of a paramour or a prostitute say to his adoptive father
      or mother: "You are not my father, or my mother," his tongue shall be cut
      off.
      -- 1780 BC, Hammurabi, Code of Law
      --
      Asperger Syndroom - een persoonlijke benadering:

      Kom in verzet tegen dit kabinet:
      De website van de Socialistische Partij (SP) in Nederland: Informatie, nieuws, agenda en publicaties.


      Comment

      Working...