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.
A:
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!
Michał Marczyk
2010-01-12 23:14:37
I guess my question is how to get that definition from static. In the standalone, it is just pathname = 'c:\foobar', and it is passed to a window. To have it come from this generate list, what would I do. Pseudo Code: class pathWindow(pathname): windowDisplay(pathname)I just really not sure. When I tried doing something like this, I got pathname not defined.
Kevin
2010-01-13 16:50:30
Well, `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.
Michał Marczyk
2010-01-13 18:03:37
Michal, I have elaborated in another question : http://stackoverflow.com/questions/2059786/opening-multiple-windows-from-a-list-in-wxpython
Kevin
2010-01-13 19:59:22
Good, though you could have edited the new info into this one. Anyway, apparently you've already received some suggestions there, I'll see if I can offer much in the way of improvement over those.
Michał Marczyk
2010-01-13 23:27:45