I have a list of file locations stored as strings. I want to be able to open a separate window for all of the different strings. What would be the best way to do that? Essentially, You click a button, the strings are constructed and they are left in a list. When I was prototyping, I built a small program to display the contents of one static file. It works, but the location is static.I want to add to the clicked button function a program that would iterate over the list and open each one of the contents in a new window. Right now the list is constructed and the window opens with the contents, but I am not sure how to combine the two. As always, any help much appreciated.
1 Answer
for s in mystrings:
open_window_for_string(s)
I'm sure you can supply a definition for open_window_for_string if you know how to open a window with the contents of a file...
Also, it doesn't actually have to be a function of one argument, of course, define it to accept whatever additional arguments are necessary. Or use whatever expression will open the kind of window you'd like to use without wrapping it up in a function.
In fact, just take the code you use to display your static file, replace the filename with a variable -- called filename, perhaps -- then use a for loop to iterate over your list of strings. Simple!
4 Comments
class pathWindow(pathname): ..., in Python, means a declaration of class pathWindow which inherits from class pathname. Presumably you want pathname to be an argument to your class's constructor instead, so define it as such: def __init__(self, pathname): ... (in the body of your class). Also, if you'd really prefer someone to write it out for you, then (1) reconsider and look up the docs instead or, failing that, (2) post the actual code you're using to accumulate the pathnames into a list and to open a single file in a window and I'll try to help you next time I'm on SO.