How to loop to make many .csv files?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ronparker
    New Member
    • Aug 2010
    • 27

    How to loop to make many .csv files?

    Hey guy!
    I have a couple questions, which I don't think are too advanced. I created an algorithm called "Best" for simplicity I will not include the mathematical details of it. I ask the user to input 6 values: Stock, min,win,Stop,GO , and end. Looking at the last 5 inputs, they are all integer inputs eg: 1,2,3.
    This code will take my algorithm and spit out a csv file called "boom.csv" with two columns of numbers based on the input values. My questions are as follow:

    -Can a loop be made so i input 3 integers for each user input, then spit out one .csv file for each combination of user input values?
    I know I would need to some how create a way to name the .csv files for each combination of user inputs, but how would I do that?
    Also how would I make a loop that can look at each combination of the user input values?
    So with 3 integers per 5 input values, that should be 3^5 outputs.

    Thank you for any help!
    Ron Parker

    Code:
    #!/usr/bin/python
    import  numpy
    import csv
    
    
    
    def Best(seq):
    	ALGORITHM
    
    Stock=raw_input('Stock Symbol: ' )
    
    min=raw_input('Start time (min away from open) : ' )
    win=raw_input('Window (min): ' )
    Stop=raw_input('SL: ' )
    Go=raw_input('PL: ' )
    end=raw_input('End time (min away from open) : ' )
    
    
    Entry=[ Best(something1[ i:i+120]) for i in range(0, len(something1), 120)]
    Entry2=[float(item[0]) for item in Entry]
    Entry3=[float(item[1]) for item in Entry]
    
    
    
    myFile= open( "Boom.csv", "wb" )
    wtr= csv.writer( myFile )
    for Start, Exit, in zip(Entry2,Entry3):
    	aRow=Start
    	bRow=Exit
    	cRow=[aRow,bRow]
    	wtr.writerow(cRow)
    	
    myFile.close()
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    I think you need a way to calculate all the possible permutations. A function that returns the permutations can be found here.

    If you have a list of letters, a file name can be constructed thus:
    Code:
    >>> ext = "csv"
    >>> seq = ['a','b','c','d','e']
    >>> '.'.join(["".join(seq), ext])
    'abcde.csv'
    >>>
    OR
    Code:
    >>> "%s.%s" % ("".join(seq), ext)
    'abcde.csv'
    >>>

    Comment

    Working...