[Tutor] Question about tkFileDialog
m.evanetich at att.net
m.evanetich at att.net
Wed Oct 22 10:49:38 EDT 2003
I am attempting to write a simple data consolidation script that opens files
in subtrees and combines the data into a single file at the root. The script
starts by asking the user to specify a subtree. Currently I am stumped by
the behavior of tkFileDialog. When I try:
>>> import tkFileDialog
>>> projectFolder = tkFileDialog.askdirectory(initialdir='c:/projectDev',
... mustexist=1,
... title='Choose root directory
for the desired project.')
>>> print projectFolder
C:/projectDev/Foo
I get the desired result, but I also get a small application named tk on my
desktop and with a taskbar button that I cannot close as a side effect. It
is disconcerting and I have not found a way to banish it. Can anyone point
me to the relevant documentation or provide advice?
Thank you.
--
Mark Evanetich
> Send Tutor mailing list submissions to
> tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-request at python.org
>
> You can reach the person managing the list at
> tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
> 1. Re: this is ugly (Andrei)
> 2. Request for code critique (Matt Hehman)
> 3. Re: Request for code critique (Clay Shirky)
> 4. Re: Request for code critique (Andrei)
> 5. can someone explain to me how this works (Conrad Koziol)
> 6. Re: can someone explain to me how this works [comparsion
> functions and sort()] (Danny Yoo)
> 7. can someone explain to me how this works (Conrad Koziol)
> 8. Re: 2nd Python Book (Erik Price)
> 9. Nested Lists / Array Module (Harm_Kirchhoff at mail.digital.co.jp)
> 10. Re: Nested Lists / Array Module (Andrei)
> 11. Re: Nested Lists / Array Module (Danny Yoo)
> 12. General construction of alpha lists? (Clay Shirky)
> 13. Timing a loop (Ben Mazer)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 22 Oct 2003 00:05:26 +0200
> From: Andrei <project5 at redrival.net>
> Subject: [Tutor] Re: this is ugly
> To: tutor at python.org
> Message-ID: <bn4an6$b68$1 at sea.gmane.org>
> Content-Type: text/plain; charset=us-ascii; format=flowed
>
> Alan Gauld wrote:
> >>Can line 3 of the following be improved (especially since I might
> >
> > want
> >
> >>to search for even more strings within each line):
> >>
> >>myfile=open(r'F:\logs\myfile.txt', 'r')
> >>for line in myfile.readlines():
> >> if line.find("KeC 923") != -1 or line.find("ZEF 156") != -1 or
> >>line.find("pBX 88347") != -1 or line.find("FZX 17255") != -1:
> >> #code if found
> >
> >
> > Yes use a regular expression. You can combine conditions in one
> > expression and it will only search the string once instead of
> > once per condition.
> >
> > I'll leave it to someone else to explain how to combine the
> > regexs! I'm going to bed and my brain is tired.... :-)
>
> Well, here's a RE which would match any of those things:
>
> KeC 923|ZEF 156|pBX 88347|FZX 17255
>
> I don't know if evaling that regex would be faster/easier than using the
> find methods, especially not with one of the shortcut notations
> mentioned earlier in this thread. Perhaps a more generic RE would be in
> order, e.g.:
>
> \S{3}\s\d{3,5}
>
> which (if compiled with the IGNORECASE flag) matches any sequence of 3
> letters followed by a space and 3 to 5 digits. Of course I don't know
> the type of input, perhaps this would match more than desired.
>
> --
> Yours,
>
> Andrei
>
> =====
> Mail address in header catches spam. Real contact info (decode with rot13):
> cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
> ernq gur yvfg, fb gurer'f ab arrq gb PP.
>
>
>
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 21 Oct 2003 15:10:23 -0700 (PDT)
> From: Matt Hehman <druidmatt at yahoo.com>
> Subject: [Tutor] Request for code critique
> To: tutor at python.org
> Message-ID: <20031021221023.98586.qmail at web10309.mail.yahoo.com>
> Content-Type: text/plain; charset=us-ascii
>
> I've written a program of about 40 lines including
> comments. I am teaching myself to program in my spare
> time, working through the various online tutorials. I
> started with "Instant Hacking" by Hetland and built on
> the example to calculate prime numbers. Basically, I
> looked for better ways to do it, then expanded its
> functionality by throwing code at it and seeing what
> stuck. Before I try to refine it any further, I think
> it would be good to get some feedback before I develop
> any bad habits. Rather than clog your inboxes by way
> of asking for a big favor, any volunteers, please
> e-mail me directly.
>
> Thanks,
> Matt Hehman
>
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
>
>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 21 Oct 2003 18:19:24 -0400
> From: Clay Shirky <clay at shirky.com>
> Subject: Re: [Tutor] Request for code critique
> To: Matt Hehman <druidmatt at yahoo.com>, <tutor at python.org>
> Message-ID: <BBBB292C.10069%clay at shirky.com>
> Content-Type: text/plain; charset="US-ASCII"
>
> > I've written a program of about 40 lines including
> > comments. I am teaching myself to program in my spare
> > time, working through the various online tutorials. I
> > started with "Instant Hacking" by Hetland and built on
> > the example to calculate prime numbers. Basically, I
> > looked for better ways to do it, then expanded its
> > functionality by throwing code at it and seeing what
> > stuck. Before I try to refine it any further, I think
> > it would be good to get some feedback before I develop
> > any bad habits. Rather than clog your inboxes by way
> > of asking for a big favor, any volunteers, please
> > e-mail me directly.
>
> As a fellow newbie, I'd love to see it, and I'm sure it makes more sense to
> post it here than to do it via CC. That sort of thing is what tutor is good
> for.
>
> -clay
>
>
>
>
> ------------------------------
>
> Message: 4
> Date: Wed, 22 Oct 2003 00:21:21 +0200
> From: Andrei <project5 at redrival.net>
> Subject: [Tutor] Re: Request for code critique
> To: tutor at python.org
> Message-ID: <bn4bl1$fu5$1 at sea.gmane.org>
> Content-Type: text/plain; charset=us-ascii; format=flowed
>
> Clay Shirky wrote:
>
> >>I've written a program of about 40 lines including
> >>comments. I am teaching myself to program in my spare
> >>time, working through the various online tutorials. I
> >>started with "Instant Hacking" by Hetland and built on
> >>the example to calculate prime numbers. Basically, I
> >>looked for better ways to do it, then expanded its
> >>functionality by throwing code at it and seeing what
> >>stuck. Before I try to refine it any further, I think
> >>it would be good to get some feedback before I develop
> >>any bad habits. Rather than clog your inboxes by way
> >>of asking for a big favor, any volunteers, please
> >>e-mail me directly.
> >
> >
> > As a fellow newbie, I'd love to see it, and I'm sure it makes more sense to
> > post it here than to do it via CC. That sort of thing is what tutor is good
> > for.
>
> I agree, I can fit more than 50 lines of code on my screen so 40 doesn't
> seem like such a big problem. Make sure your mail interface doesn't
> break the code though.
>
> --
> Yours,
>
> Andrei
>
> =====
> Mail address in header catches spam. Real contact info (decode with rot13):
> cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
> ernq gur yvfg, fb gurer'f ab arrq gb PP.
>
>
>
>
>
> ------------------------------
>
> Message: 5
> Date: Tue, 21 Oct 2003 15:42:42 -0700
> From: Conrad Koziol <arkamir at softhome.net>
> Subject: [Tutor] can someone explain to me how this works
> To: tutor at python.org
> Message-ID: <1066776162.5035.4.camel at quercus>
> Content-Type: text/plain
>
> Hey thanks for the tips !!!
>
> def compare(a,b):
> if a[1]>b[1]: return 0
> else: return -1
>
> i tried this out and it works, but i dont understand the logic behind it
> :(
> can someone help me out
>
> i also dont get how it compares all the tuples in a list. Dont you need to enter
> in two values not just one list?????
>
>
>
> ------------------------------
>
> Message: 6
> Date: Tue, 21 Oct 2003 16:13:22 -0700 (PDT)
> From: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
> Subject: Re: [Tutor] can someone explain to me how this works
> [comparsion functions and sort()]
> To: Conrad Koziol <arkamir at softhome.net>
> Cc: tutor at python.org
> Message-ID:
> <Pine.LNX.4.44.0310211601260.20770-100000 at hkn.eecs.berkeley.edu>
> Content-Type: TEXT/PLAIN; charset=US-ASCII
>
>
>
> On Tue, 21 Oct 2003, Conrad Koziol wrote:
>
> > Hey thanks for the tips !!!
> >
> > def compare(a,b):
> > if a[1]>b[1]: return 0
> > else: return -1
> >
> > i tried this out and it works, but i dont understand the logic behind it
> > :( can someone help me out
>
> Hi Conrad,
>
> A "comparison function" is something that takes two things, and checks to
> see if one is smaller than another. In math notation:
>
> compare(a,b) = { -1 if a < b
> 0 if a == b
> 1 if a > b
> }
>
> The important thing to see is that a comparison function is not meant to
> be a "boolean" true-false thing: it's meant to return either a positive,
> zero, or negative value.
>
> Is this what's confusing, or is it something else? Please feel free to
> ask more questions about this, as it is definitely a confusing topic when
> we first see it.
>
>
>
> > i also dont get how it compares all the tuples in a list. Dont you need
> > to enter in two values not just one list?????
>
> Yes, this would be true if we were directly calling compare() on the list
> itself. However, that's not what's happening: instead, we're calling
> sort, and sort() itself is calling compare() on pairs of elements on our
> list.
>
>
> Here's a concrete toy example of a similar situation:
>
> ###
> >>> def applyOnList(function, L):
> ... """Destructivly applies a 'function' on the list 'L'."""
> ... for index, element in enumerate(L):
> ... L[index] = function(element)
> ...
> >>> def square(x): return x * x
> ...
> >>> numbers = range(10)
> >>> applyOnList(square, numbers)
> >>> numbers
> [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
> ###
>
> In this case, we've written a function called applyOnList() that takes in
> a function, as well as a list of things. Notice that the function we pass
> in isn't being called on the whole list, but only on single elements of
> that list.
>
>
> sort() does something somewhat similar when it takes in that comparison
> function. sort() uses it as a helper toward some greater goal --- sorting
> things --- but doesn't need to try applying it to the whole list at once.
>
>
> Hope that made some sort of sense. *grin* Please feel free to ask more
> questions: if you'd like, we can talk about how comparsion functions
> actually help sort() figure out how to sort.
>
>
>
>
> ------------------------------
>
> Message: 7
> Date: Tue, 21 Oct 2003 15:42:42 -0700
> From: Conrad Koziol <arkamir at softhome.net>
> Subject: [Tutor] can someone explain to me how this works
> To: tutor at python.org
> Message-ID: <1066776162.5035.4.camel at quercus>
> Content-Type: text/plain
>
> Hey thanks for the tips !!!
>
> def compare(a,b):
> if a[1]>b[1]: return 0
> else: return -1
>
> i tried this out and it works, but i dont understand the logic behind it
> :(
> can someone help me out
>
> i also dont get how it compares all the tuples in a list. Dont you need to enter
> in two values not just one list?????
>
>
>
> ------------------------------
>
> Message: 8
> Date: Tue, 21 Oct 2003 20:43:41 -0400
> From: Erik Price <erikprice at mac.com>
> Subject: Re: [Tutor] 2nd Python Book
> To: John Duarte <john at duartedailey.org>
> Cc: tutor at python.org
> Message-ID: <C8614AFE-0428-11D8-ADEC-00039351FE6A at mac.com>
> Content-Type: text/plain; charset=US-ASCII; format=flowed
>
>
> On Monday, October 20, 2003, at 06:37 PM, John Duarte wrote:
>
> > I have seen recommendations for a first Python book, ie Alan Guald's
> > Learn to
> > Program Using Python, and Lutz & Asher's Learning Python. (Which are
> > both
> > terrific books!)
> >
> > I was wondering if anyone could recommend a '2nd book'.
>
> The Python Cookbook. You already know Python, this book teaches you
> how to do specific tasks or sophisticated programming idioms specific
> to Python. It's one of my favorite Python books.
>
> > I was glancing through Deitel & Deitel's How to Program Python, and it
> > looks
> > very thorough. Are their any opinions about this book specifically.
>
> I didn't even know these guys had a Python book. Neat.
>
>
>
> Erik
>
>
>
>
> ------------------------------
>
> Message: 9
> Date: Wed, 22 Oct 2003 09:07:57 +0900
> From: Harm_Kirchhoff at mail.digital.co.jp
> Subject: [Tutor] Nested Lists / Array Module
> To: tutor at python.org
> Message-ID:
>
> <OFD7D369B7.88885204-ON49256DC6.00830C0C-49256DC7.00009D65 at jp.schneider-electric
> .com>
>
> Content-Type: text/plain; charset="us-ascii"
>
> Python supports nested lists, which is very nice and can be used for very
> simple databases.
>
> However, I could not find a way to write nested lists to files & retrieve
> them easily.
> The .writelines() method expects a string as an argument.
>
> Is there a method to dump any list on disk & read it back, or is it
> necessary to code this task ?
>
> The array module seems to have such method, however, I could not find
> sufficient code examples to understand how the array module works. The
> Python Library Reference mentions the .fromfile() and .tofile() methods,
> does anyone have experience with the array module, especially whether it
> allows to write & retrieve nested arrays without problems ? Could you pass
> me some sample code ?
>
>
> Harm
>
>
>
>
> ------------------------------
>
> Message: 10
> Date: Wed, 22 Oct 2003 02:33:27 +0200
> From: Andrei <project5 at redrival.net>
> Subject: [Tutor] Re: Nested Lists / Array Module
> To: tutor at python.org
> Message-ID: <bn4jcm$1jt$1 at sea.gmane.org>
> Content-Type: text/plain; charset=us-ascii; format=flowed
>
> Harm_Kirchhoff at mail.digital.co.jp wrote:
> > Python supports nested lists, which is very nice and can be used for very
> > simple databases.
> >
> > However, I could not find a way to write nested lists to files & retrieve
> > them easily.
> > The .writelines() method expects a string as an argument.
> >
> > Is there a method to dump any list on disk & read it back, or is it
> > necessary to code this task ?
>
> Not too long ago a similar question (or was it the same?) was on the list
> I believe. You can either pickle or convert your list to a string using
> str(),
> e.g. str(MyList). It doesn't matter how deep that list is.
>
> <snip>
>
> --
> Yours,
>
> Andrei
>
> =====
> Mail address in header catches spam. Real contact info (decode with rot13):
> cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
> ernq gur yvfg, fb gurer'f ab arrq gb PP.
>
>
>
>
>
> ------------------------------
>
> Message: 11
> Date: Tue, 21 Oct 2003 17:54:28 -0700 (PDT)
> From: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
> Subject: Re: [Tutor] Nested Lists / Array Module
> To: Harm_Kirchhoff at mail.digital.co.jp
> Cc: tutor at python.org
> Message-ID:
> <Pine.LNX.4.44.0310211749100.27613-100000 at hkn.eecs.berkeley.edu>
> Content-Type: TEXT/PLAIN; charset=US-ASCII
>
>
>
> On Wed, 22 Oct 2003 Harm_Kirchhoff at mail.digital.co.jp wrote:
>
> > Python supports nested lists, which is very nice and can be used for very
> > simple databases.
> >
> > However, I could not find a way to write nested lists to files &
> > retrieve them easily. The .writelines() method expects a string as an
> > argument.
> >
> > Is there a method to dump any list on disk & read it back, or is it
> > necessary to code this task ?
>
>
> Hi Harm,
>
> Yes. For simple cases, the 'shelve' module can help to "serialize"
> these nested structures to and from disk. "Serialization" is a term we
> use to transform arbitrary Python objects to byte strings, and it's pretty
> easy to do in Python.
>
> In fact, we talked about this about a week ago:
>
> http://mail.python.org/pipermail/tutor/2003-October/025741.html
>
> The example at that link uses only a flat list, but 'shelve' should work
> with lists in lists too.
>
>
> If you have more questions, please feel free to ask. Good luck!
>
>
>
>
> ------------------------------
>
> Message: 12
> Date: Tue, 21 Oct 2003 21:42:46 -0400
> From: Clay Shirky <clay at shirky.com>
> Subject: [Tutor] General construction of alpha lists?
> To: <tutor at python.org>
> Message-ID: <BBBB58D6.1009C%clay at shirky.com>
> Content-Type: text/plain; charset="US-ASCII"
>
> So I have this bit of code:
>
> class_groups = [ 'A', 'B', 'C', 'D', 'E' ]
>
> while class_groups:
> next = random.choice( range( len(class_groups) ))
> print class_groups[next]
> class_groups[next:next+1] = []
>
> which will give me some random permutation of the items in the list
> class_groups.
>
> Next stop, making it possible to generate an alphabetical list, based on the
> array number. I'd like to do something like
>
> class_groups = range(12)
>
> and then have it print from A through L. Is there an easy way to specify a
> list that is simply letters in order, or do I have to write out
>
> alpha = [ 'A', 'B', ... 'Z', 'a', 'b', ... 'z' ]
>
> Thanks
>
> -clay
>
>
>
>
> ------------------------------
>
> Message: 13
> Date: Tue, 21 Oct 2003 23:08:05 -0400
> From: Ben Mazer <contrasutra at myrealbox.com>
> Subject: [Tutor] Timing a loop
> To: tutor at python.org
> Message-ID: <3F95F495.4050102 at myrealbox.com>
> Content-Type: text/plain; charset=us-ascii; format=flowed
>
> I have written a small script that creates a bunch of small text files.
> I'm doing this because I want to benchmark file creation/deletion times
> on different file systems.
>
> Im looking right now about how to time how long it takes to create the
> files. I looked at the Timeit() module, and that doesn't seem to work,
> its for small algorithms.
>
> I also looked at time.clock(), but I can't get that to display an
> accurate readout, so I dont think that works (or Im not using it right).
>
> I know I could use the UNIX "time" command, but it would be nice if
> Python had a built in function. They probably do, but I can't find it. :P
>
> Any help you could provide on timing a loop would be really helpful.
>
> OT: How many files can reiserfs hold? I keep hitting "file system full"
> limits when I get into large amounts of files (hundreds of thousands).
>
> Thanks.
> --
> /"\ Ben Mazer <contrasutra at myrealbox.com>
> \ /
> X ASCII RIBBON CAMPAIGN AGAINST HTML MAIL
> / \
>
>
>
>
> ------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 3, Issue 37
> ************************************
More information about the Tutor
mailing list