lundi 23 mars 2015

Python: Looping a certain amount of time in order different process

I made a script which is suppose to use Tkinter to allow to choose and load files and store their content in different objects and then process each of these documents. I would like to make the script able to process only a certain amount of documents determined by a question (the value is stored under "File_number") For exemple: if at the question "how many files do you want to compare?" the user enter 3 I would like the tkinter openfile window to ask only for 3 files then keep going


I am using the If Else statement like below but it doesn't seem to work well and the code is really not pythonic. Is there a better/shorter way to perform the same?


Thanks


My script look like this



import pandas as pd
from pandas import *
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
import seaborn as sns
import pylab
import pandas.io.data
import os
import Tkinter
from Tkinter import *
import tkFileDialog
import tkSimpleDialog
from tkFileDialog import askopenfilename
import sys

# Set up GUI
root = Tkinter.Tk(); root.withdraw()

# Prompt for user info
File_number = tkSimpleDialog.askinteger("File number", "How many files do you want to compare?")


# Prompt for file explorer
# Also extract the file_name

process_a = 0

if process_a = File_number:
break
else:
process_a = process_a + 1
fileloc1 = tkFileDialog.askopenfilename(parent=root, title='Choose file 1')
fileloc1_name_clean = os.path.splitext(fileloc1)[0]
fileloc1_name = os.path.basename(fileloc1_name_clean)

if process_a = File_number:
break
else:
process_a = process_a + 1
fileloc2 = tkFileDialog.askopenfilename(parent=root, title='Choose file 2')
fileloc2_name_clean = os.path.splitext(fileloc2)[0]
fileloc2_name = os.path.basename(fileloc2_name_clean)

if process_a = File_number:
break
else:
process_a = process_a + 1
fileloc3 = tkFileDialog.askopenfilename(parent=root, title='Choose file 3')
fileloc3_name_clean = os.path.splitext(fileloc3)[0]
fileloc3_name = os.path.basename(fileloc3_name_clean)

Aucun commentaire:

Enregistrer un commentaire