#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    19
    Rep Power
    0

    How can I restart Python


    How can I restart Python 2.7 (for example 10 times) at the end of my code without wrap the code inside a while True loop?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    2
    Code:
    for i in range(10):
        #code here
    What exactly do you mean, "restart python", and what exactly are you trying to do?

    -Mek
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    19
    Rep Power
    0
    This didn't work.
    It's a lotto program where values in the bpnn file are random changing everytime I restart the program.

    Second problem is if I put 10 times this code after each other then it works but it takes 10 times the first random value.I think the random value must be reset everytime.

    I want to restart this

    import bpnn

    import datetime
    import time

    #number to predict
    lot_num = 1220.0

    # inputs 4 fields, seq number, timestamp
    # outputs magically the winning numbers
    ds = []


    # opens the training data-set file
    input_file = open( 'rms.csv', 'r' )
    print 'creating data-set for training'
    n = 0



    for line in input_file:
    splitted_line = line.split( ';' )
    #converts the date to timestamp
    splitted_line[ 1 ] = time.mktime( datetime.datetime.strptime( splitted_line[ 1 ], '%d/%m/%Y' ).timetuple() )
    seq = [ float( splitted_line[ 0 ] ) / lot_num, ]

    numbers = [ float(data) / 60.0 for data in splitted_line[2:] ]
    numbers.sort( )

    n += 1
    if n % 100 == 0:
    print '%d rows in data-set' % n

    # adds the data to the data-set
    ds.append( [ seq, numbers ])

    print '%d rows in data-set' % n
    print 'Creating neural network'
    # creates the neural network
    # the hidden nodes are calculated by the rule round( ( input + output ) * ( 2 / 3 ) )
    net = bpnn.NN( 1, 5, 6 )


    print 'Training neural network'
    #trains the network
    net.train(patterns = ds, iterations = 100 )
    print 'Training done... now the next result will be:'
    # now shows the result for today!
    print ' '.join( [ '%s' % ( int( r * 60 ) ) for r in net.update( [ 1, ] ) ] )
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    487
    Rep Power
    33
    if I put 10 times this code after each other then it works but it takes 10 times the first random value.I think the random value must be reset everytime
    You have to seed it each time. Generally speaking, the current time, or 10 randint's is good enough to use to seed it within the for ctr in range(10) loop.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    19
    Rep Power
    0
    It's a good idea to seed it and I restart the code with execfile
    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo