Re: lambda in list comprehension acting funny
> funcs = [ lambda x: x**i for i in range( 5 ) ] > print funcs[0]( 2 ) > print funcs[1]( 2 ) > print funcs[2]( 2 ) > > This gives me > > 16 > 16 > 16 > > When I was excepting > > 1 > 2 > 4 > > Does anyone know why? And more importantly, what's the simplest way to achieve the latter? :) -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
lambda in list comprehension acting funny
funcs = [ lambda x: x**i for i in range( 5 ) ] print funcs[0]( 2 ) print funcs[1]( 2 ) print funcs[2]( 2 ) This gives me 16 16 16 When I was excepting 1 2 4 Does anyone know why? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Opening multiple Files in Different Encoding
On Tue, 10 Jul 2012 10:46:08 -0700, Subhabrata wrote: > Dear Group, > > I kept a good number of files in a folder. Now I want to read all of > them. They are in different formats and different encoding. Using > listdir/glob.glob I am able to find the list but how to open/read or > process them for different encodings? open('first file', encoding='uft-8') open('second file', encoding='latin1') How you decide which encoding to use is up to you. Perhaps you can keep a mapping of {filename: encoding} somewhere. Or perhaps you can try auto-detecting the encodings. The chardet module should help you there. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
Mark Lawrence, 10.07.2012 11:42: > I recall reading in a book in the local library > of a manager that wouldn't employ people unless they were wearing a new > pair of shoes. Guess they didn't take many people on. Managers tend to like wasting resources. Buying a new pair of shoes for each job interview sounds reasonable once you have a salary well beyond your own capabilities. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Jul 10, 4:29 am, Jean-Michel Pichavant wrote: > Why would you want to hire someone that knows something pointless as the > version where feature X has been introduced ? Just tell him that feature > X has been introducted in version Y, costless 2.5sec training. Don't you > want to hire someone that knows things you don't and benefit from each > others abilities, learning from each others, improving the company > global skill range ? > > JM Ha! Intelligent people are scary to bosses. They want robots Jean. Robots that are *just* intelligent enough to reduce their own work load whist NOT intelligent enough to render them obsolete. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Tue, Jul 10, 2012 at 1:02 PM, Ethan Furman wrote: ... > > Reminds me of a job posting a few years ago where the prospective employer > wanted three plus years experience in some language, and that language had > only been created a year and a half before. I saw several of those when Java was new. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter.event.widget: handler gets name instead of widget.
Also: Q3: Why are you explicitly setting the name of your "subFrame" widgets instead of allowing Tkinter to assign a unique name?...AND are you aware of the conflicts that can arise from such changes[1]? Q4: Are you aware of the built-in function "enumerate"[2]? I see you are passing around indexes to iterables AND simultaneously needing the obj reference itself. I prefer to keep indexing to a minimum. If there is no bleeding edge performance issue to worry about (and there almost *always* never is) why not use enumerate? [1] http://www.pythonware.com/library/tkinter/introduction/x147-more-on-widget-names.htm [2] http://docs.python.org/release/3.0.1/library/functions.html#enumerate -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Tue, Jul 10, 2012 at 4:26 PM, Dennis Lee Bieber wrote: > On Tue, 10 Jul 2012 09:05:50 -0700, Ethan Furman > declaimed the following in gmane.comp.python.general: > >> As an example from today, if someone claimed to have 5+ years of Python >> experience, but didn't know that 'with' was standard in 2.6 (or at least >> the end of the 2.x cycle) I would be suspicious that they actually had >> the experience they claimed. >> > > >From the 2.5 help file: > """ > 3.4.9 With Statement Context Managers > New in version 2.5. > """ In 2.5 the with statement requires a __future__ import, so can't be considered "standard". -- http://mail.python.org/mailman/listinfo/python-list
RE: how to interact with Windows cmd?
> what I want to do is > 1.open cmd > 2.waiting for user's typing > 3.when I type "dir" > 4.print the result of "dir" > 5.then I type some other commands, printing the result until I type > 'exit' > > I used > p=subprocess.Popen('cmd',stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=s > ubprocess.PIPE,shell=True) > p=communicate('dir') > > it shows the first result but the problem is > 1. it's too long so the cmd split the result with "more?", so result > is not perfect > 2. after this, I typed like "cd .." but I/O is already closed so I > can't do another things.. > > Is there any good way? Not much experience with subprocess, but from what I have read on here shell=True is usually bad. If you are trying to use Python as a sort of bash replacement, you may want to take a look at iPython http://en.wikipedia.org/wiki/Ipython. Not Apple related! Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter.event.widget: handler gets name instead of widget.
I've tried to condense your code using the very limited info you have provided. I have removed unnecessarily configuring of widgets and exaggerated the widget borders to make debugging easier. Read below for Q&A. ## START CONDENSED CODE ## records = range(4) CNF_SUBFRAME = { 'bd':5, # rowFrame boder width. 'relief':RIDGE, } CNF_LABEL = { 'anchor':W, 'width':10, 'bg':'gray', } class FooFrame(tk.Frame): def __init__(self, master, **kw): tk.Frame.__init__(self, master, **kw) self.build_records() def build_records(self): # Should this method be called by __init__??? # Not sure if "records" is passed-in or global??? for n in range(len(records)): record = records[n] rowFrame = tk.Frame(self, name='-%d-'%n, **CNF_SUBFRAME) rowFrame.bind ('', self.evtEnter) rowFrame.bind ('', self.evtLeave) rowFrame.bind ('', self.evtButtonOneRelease) rowFrame.bind ('', self.evtButtonThreeRelease) rowFrame.grid (row=n+2, column=1, padx=5, pady=5) for i in range(4): lbtext = 'Label_'+str(i) label = tk.Label(rowFrame, text=lbtext, **CNF_LABEL) label.grid (row=0, column=i, sticky=NW) def evtEnter(self, event): w = event.widget print 'evtEnter', w.winfo_class() w.config(bg='magenta') def evtLeave(self, event): w = event.widget print 'evtLeave', w.winfo_class() w.config(bg='SystemButtonFace') def evtButtonOneRelease(self, event): w = event.widget print 'evtButtonOneRelease', w.winfo_class() w.config(bg='Green') def evtButtonThreeRelease(self, event): w = event.widget print 'evtButtonThreeRelease', w.winfo_class() w.config(bg='Blue') if __name__ == '__main__': root = tk.Tk() frame = FooFrame(root, width=100, height=100, bg='red', bd=1) frame.pack(padx=5, pady=5) root.mainloop() ## END CONDENSED CODE ## In the code sample provided, you will see that the label widgets stacked on each row will block "click" events on the containing "rowFrames" below them. You can get a click event (on the sub frames) to work by clicking the exaggerated border on the frames. All the events work properly for me, although this GUI interface seems unintuitive even with proper borders and colors. Fredric, I can't help but feel that you are not attacking the problem correctly. Please explain the following questions in detail so that i may be able to provide help: Q1. You have subclassed a Tkinter.Frame and you are building "rows" of sub-frames into this toplevel frame; with each row holding horizontally stacked label widgets. Okay, I can see a need to wrap up a "RowFrame" object, but i don't see a need to create a "RowFrameFactory". Can you explain this design decision? Q2. It seems odd to me that you want to engage the "rowFrame" widgets via events but NOT the Label widgets. Can you explain this design decision? -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding to a List and displaying quantity in the list
else: > print("%8.3f %s: Waited too long %6.3f" % (now()/60, self.name, > wait) + " time units have passed - Customer has left") > leavelist.append(self.acquired) Yeah, I should have changed that back to : leavelist.append(self.name) -- my thinking was that it would append the name of each item to the list.? -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding to a List and displaying quantity in the list
In Shamefaced writes: > else: > print("%8.3f %s: Waited too long %6.3f" % (now()/60, self.name, > wait) + " time units have passed - Customer has left") > leavelist.append(self.acquired) What is self.acquired? Judging from earlier code it appears to be a function, but here you're appending it to leavelist. Did you really mean to append a function object to leavelist? -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" -- http://mail.python.org/mailman/listinfo/python-list
Re: Opening multiple Files in Different Encoding
On 10/07/2012 18:46, Subhabrata wrote: Dear Group, I kept a good number of files in a folder. Now I want to read all of them. They are in different formats and different encoding. Using listdir/glob.glob I am able to find the list but how to open/read or process them for different encodings? If any one can help me out.I am using Python3.2 on Windows. You could try different encodings. If it raises a UnicodeDecodeError, then it's the wrong encoding, Otherwise just look at the decoding result and see whether it "looks" OK. I believe that one method is to look at the frequency distribution of characters compared with sample texts. -- http://mail.python.org/mailman/listinfo/python-list
Adding to a List and displaying quantity in the list
Hi I have coded a program whihc outputs what I like, but I am trying to modify it to add specific result info to a list and then display the number of items in the list. This is easy for me with basic code, but seems difficult when trying to adapt my program. My code and explanation is as follows: class Source(Process): """ Source generates customers randomly """ def generate(self, number, meanTBA, resource): for i in range(number): c = Customer(name="Customer%02d" % (i+1,)) activate(c, c.visit(b=resource)) #t = expovariate(1.0 / meanTBA) t = 10.0 yield hold, self, t class Customer(Process): """ Customer arrives, is served and leaves """ def visit(self, b): leavelist = [] /* Name of List defined */ arrive = now() #tib = expovariate(1.0 / timeInBank) tib = timeInBank /* Console Output results start here */ print("%8.3f %s: Here I am" % (now()/60, self.name)) yield (request, self, b), (hold, self,maxWaitTime) wait = now() - arrive if self.acquired(b): print("%8.3f %s: Waited %6.3f" % (now()/60, self.name, wait)) yield hold, self, tib yield release, self, b print("%8.3f %s: Finished" % (now()/60, self.name)) else: print("%8.3f %s: Waited too long %6.3f" % (now()/60, self.name, wait) + " time units have passed - Customer has left") leavelist.append(self.acquired) print len(leavelist) What I am looking to do is the "customers" who have "Waited too long" get added to my leavelist() as they occur. Does this make sense? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Intro+Intermediate Python, San Francisco, Aug 1-3
hello everyone, hope some of you enjoyed #EuroPython this past week/end, and perhaps i'll see some of you at OSCON next week! as promised, here's the one and only FINAL REMINDER of the hardcore intro+intermediate Python course i'm offering 2012 Aug 1-3 near the San Francisco airport. reach out to me directly with any questions and let other folks know who may be interested. best regards, --wesley On Thu, May 10, 2012 at 2:07 PM, wesley chun wrote: > Greetings! > > I'll be doing another hardcore Python course this summer in the San > Francisco area. If you're somewhat new to Python or have tinkered but > want to fill-in the holes, this course is for you. It's somewhat true > you can learn Python online, watching videos, or reading books, but it > still takes time and experience to master... I help accelerate this > process. The course is based on my bestselling "Core Python" books and > is made up of 3 full days complete with lectures and three hands-on > coding labs per day. > > Please pass on this message to your colleagues who also need to learn > Python. It's also a great excuse to coming to beautiful Northern > California for a summer vacation! More details at http://goo.gl/uW4oF > as well as the links in my .signature below. -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "A computer never does what you want... only what you tell it." +wesley chun : wescpy at gmail : @wescpy Python training & consulting : http://CyberwebConsulting.com "Core Python" books : http://CorePython.com Python blog: http://wescpy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
I also judge candidates on their beards (http://www.wired.com/wiredenterprise/2012/06/beard-gallery/). If the beard's awesome enough, no questions needed. They're pro. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On 10/07/2012 18:12, Dennis Lee Bieber wrote: On 10 Jul 2012 07:33:59 GMT, Steven D'Aprano declaimed the following in gmane.comp.python.general: may not be capable of telling the difference between a cheese sandwich and a box of hair -- and even the *good* interviewers are probably making They are both containers holding samples of protein Does the hair contain much more roughage? -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Opening multiple Files in Different Encoding
Dear Group, I kept a good number of files in a folder. Now I want to read all of them. They are in different formats and different encoding. Using listdir/glob.glob I am able to find the list but how to open/read or process them for different encodings? If any one can help me out.I am using Python3.2 on Windows. Regards, Subhabrata Banerjee. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Wed, 11 Jul 2012 02:59:15 +1000, Chris Angelico wrote: > On Wed, Jul 11, 2012 at 2:51 AM, Steven D'Aprano > wrote: >> If only that were true. I know quite a few people who looked the >> interviewer straight in the eye and told the most bare-faced lies >> without a trace of shame, and got the job. Ten years on, at least one >> of them is making something around $300,000 a year, based entirely on >> his ability to smile and tell customers plausible lies. > > So he's either a politician, a salesman, a lawyer, a counselor, a > manager, a thespian, or a venture capitalist. And maybe a few other > possibilities. Professional liars, all. :) Actually, he's a senior software developer for a major international software company whose name Might Seem familiar to you. To be honest, I can't tell you too much more about his job, as I've made it a practice not to learn too many details. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
Steven D'Aprano wrote: On Tue, 10 Jul 2012 11:29:24 +0200, Jean-Michel Pichavant wrote: Why would you want to hire someone that knows something pointless as the version where feature X has been introduced ? Just tell him that feature X has been introducted in version Y, costless 2.5sec training. Don't you want to hire someone that knows things you don't and benefit from each others abilities, learning from each others, improving the company global skill range ? The reason for the question is to get some idea of how well the candidate actually knows Python. If you ask them questions that you don't know the answer to, how will you tell if they're right? I certainly wouldn't disqualify a candidate if they didn't know what version introduced (say) decorators. If they said "what's a decorator?" or "version 10", that would be a hint that they don't actually know much about Python. If they said "I don't know, I'm still stuck on Python 2.3", they would get a point for honesty and lose a point for being way out of date. If they said version 2.3 or 2.5 (it's actually 2.4), well, that's close enough. Of course, an acceptable answer would be "buggered if I know, but if you give me a minute, I'll google it for you". Must be a cultural thing. We don't question people experience that much here. They'll be challenged anyway during the trial period (6 months during which the contract can be cancelled anytime without any reason). Actually I think it would be considered quite rude to challenge someone with questions right after he told you he worked 5 years as technical leader on a software developped in python for instance. I've never been asked nor did I asked to go into such technical details. Interviews are more about years of experience, projects, working with teams, carreer expectations, distance between home and workplace, willingness to work weekends when required. I'm no saying one way is better than another. I'm making an observation on how different can be an interview from one location to another. JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Wed, Jul 11, 2012 at 2:51 AM, Steven D'Aprano wrote: > If only that were true. I know quite a few people who looked the > interviewer straight in the eye and told the most bare-faced lies without > a trace of shame, and got the job. Ten years on, at least one of them is > making something around $300,000 a year, based entirely on his ability to > smile and tell customers plausible lies. So he's either a politician, a salesman, a lawyer, a counselor, a manager, a thespian, or a venture capitalist. And maybe a few other possibilities. Professional liars, all. :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
Chris Angelico wrote: On Wed, Jul 11, 2012 at 2:34 AM, Steven D'Aprano wrote: Of course, if they try to sell themselves as having five years experience with Python 3.2... ... then they've been borrowing Guido's time machine for personal purposes. Reminds me of a job posting a few years ago where the prospective employer wanted three plus years experience in some language, and that language had only been created a year and a half before. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Wing IDE 4.1.7 released
Hi, Wingware has released version 4.1.7 of Wing IDE, our integrated development environment designed specifically for the Python programming language. Wing IDE provides a professional quality code editor with vi, emacs, and other key bindings, auto-completion, call tips, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ This minor release includes: Support for Stackless Python 3.2 Support for Maya 2013 Support for Visual Studio 2010 builds of Python 2.6 and 2.7 Update Python 3.3 support to the beta1 release Pretty Print option in Python Shell and Debug Probe How-To for using Wing IDE with Pyramid (thanks to Eric Ongerth) Implemented vi mode :delm to delete marks Added open-url-from-editor and open-clicked-url-from-editor commands Ability to set options sent to Python while debugging Toolbar icon for viewing and changing the Python configuration Improved tab key action in Eclipse key binding Preference to disable editor scrolling past the last line Several auto-editing improvements Improved experimental Turbo completion mode Improved heuristic for auto-indent after paste Support _thread module under Python 3.x About 30 other minor improvements and bug fixes For a complete change log see http://wingware.com/pub/wingide/4.1.7/CHANGELOG.txt Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature matrix: http://wingware.com/wingide/features More information: http://wingware.com/ Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at sa...@wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE Advancing Software Development www.wingware.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Tue, 10 Jul 2012 10:11:22 +0200, Christian Heimes wrote: > Am 10.07.2012 09:33, schrieb Steven D'Aprano: >> This is why I hate job interviews. You have like 30 minutes, or even as >> little as 30 seconds, to make a good impression on somebody who may or >> may not be capable of telling the difference between a cheese sandwich >> and a box of hair -- and even the *good* interviewers are probably >> making their judgement on the basis of subjective factors with no right >> or wrong answers. > > IMHO one category of answers is always wrong: lies. You may oversell > yourself a bit, you can (and should) keep private matters to yourself > but don't lie. If only that were true. I know quite a few people who looked the interviewer straight in the eye and told the most bare-faced lies without a trace of shame, and got the job. Ten years on, at least one of them is making something around $300,000 a year, based entirely on his ability to smile and tell customers plausible lies. I can't lie to save my life, which is why I have trouble in interviews. But of course all good liars would say the same thing. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Tue, 10 Jul 2012 11:29:24 +0200, Jean-Michel Pichavant wrote: > Why would you want to hire someone that knows something pointless as the > version where feature X has been introduced ? Just tell him that feature > X has been introducted in version Y, costless 2.5sec training. Don't you > want to hire someone that knows things you don't and benefit from each > others abilities, learning from each others, improving the company > global skill range ? The reason for the question is to get some idea of how well the candidate actually knows Python. If you ask them questions that you don't know the answer to, how will you tell if they're right? I certainly wouldn't disqualify a candidate if they didn't know what version introduced (say) decorators. If they said "what's a decorator?" or "version 10", that would be a hint that they don't actually know much about Python. If they said "I don't know, I'm still stuck on Python 2.3", they would get a point for honesty and lose a point for being way out of date. If they said version 2.3 or 2.5 (it's actually 2.4), well, that's close enough. Of course, an acceptable answer would be "buggered if I know, but if you give me a minute, I'll google it for you". -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Wed, Jul 11, 2012 at 2:34 AM, Steven D'Aprano wrote: > Of course, if they try to sell themselves as having > five years experience with Python 3.2... ... then they've been borrowing Guido's time machine for personal purposes. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Tue, 10 Jul 2012 09:05:50 -0700, Ethan Furman wrote: > Jean-Michel Pichavant wrote: >> Why would you want to hire someone that knows something pointless as >> the version where feature X has been introduced ? > > As an example from today, if someone claimed to have 5+ years of Python > experience, but didn't know that 'with' was standard in 2.6 (or at least > the end of the 2.x cycle) I would be suspicious that they actually had > the experience they claimed. Be careful of jumping to conclusions though. Perhaps they have five years experience with Python 1.5, 2.3 and 2.4 on Centos systems. Of course, if they try to sell themselves as having five years experience with Python 3.2 and they don't know anything about the with statement, that tells you everything you need to know. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Wed, Jul 11, 2012 at 1:55 AM, BartC wrote: > There's also the risk of mixing up software created at home, with that done > at work, with all the intellectual property issues that might arise. You just make the matter clear from the beginning, for instance: what's done at work stays at work, and copyright is assigned by the act of pushing to the repository. I've lifted oddments of code from my home projects to use at work; it's no different from using skills learned at home, which is exactly what a programmer is being paid for. This is another good reason to make license terms clear and explicit on every project you ever put a hand to. Doesn't matter who's lifting code from where to where, it's easy to work out whether it's permissible or not. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
"Peter" wrote in message news:35e7a860-fd41-4018-82f6-aabc32610...@googlegroups.com... One of my favourite questions when interviewing - and it was 100% reliable :-) - "what are your hobbies?" If the answer included programming then they were hired, if not, then they went to the "B" list. In my experience, anybody who is really interested in programming will have it as a hobby (and is keen to learn even if they don't currently have the knowledge you require) - otherwise it is "just a job". Won't they be tempted to work on their pet project instead of what they're being paid for? There's also the risk of mixing up software created at home, with that done at work, with all the intellectual property issues that might arise. -- Bartc -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
Jean-Michel Pichavant wrote: Why would you want to hire someone that knows something pointless as the version where feature X has been introduced ? As an example from today, if someone claimed to have 5+ years of Python experience, but didn't know that 'with' was standard in 2.6 (or at least the end of the 2.x cycle) I would be suspicious that they actually had the experience they claimed. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the effect of cmp here?
On 10/07/2012 16:01, levi nie wrote: aList=[3,2,5,4] bList=aList[:] bList.sort() print "bList is",bList cList=aList[:] cList.sort(cmp) print "cList is",cList Why don't you tell us, you have the same documentatation avaialable as everybody else. -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the effect of cmp here?
On 07/10/2012 11:01 AM, levi nie wrote: > what's the effect of cmp here? The bList and cList is the same at last. > > code: > aList=[3,2,5,4] > > bList=aList[:] > bList.sort() > print "bList is",bList > > cList=aList[:] > cList.sort(cmp) > print "cList is",cList > > The main effect is for the reader of the code. When you supply your own callback to sort(), you're being explicit about how you want the items to be compared. If the default works for you, then you can omit supplying a function. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Issues with `codecs.register` and `codecs.CodecInfo` objects
On 07.07.12 04:56, Steven D'Aprano wrote: On Fri, 06 Jul 2012 12:55:31 -0400, Karl Knechtel wrote: Hello all, While attempting to make a wrapper for opening multiple types of UTF-encoded files (more on that later, in a separate post, I guess), I ran into some oddities with the `codecs` module, specifically to do with `.register` ing `CodecInfo` objects. I'd like to report a bug or something, but there are several intertangled issues here and I'm not really sure how to report it so I thought I'd open the discussion. Apologies in advance if I get a bit rant-y, and a warning that this is fairly long. [...] Yes, it's a strangely indirect API, and yes it looks like you have identified a whole bucket full of problems with it. And no, I don't know why that API was chosen. This API was chosen for backwards compatibility reasons when incremental encoders/decoders were introduced (in 2006). And yes: We missed the opportunity to clean that up to always use CodecInfo. Changing to a cleaner, more direct (sensible?) API would be a fairly big step. If you want to pursue this, the steps I recommend you take are: 1) understanding the reason for the old API (search the Internet and particularly the python-...@python.org archives); See e.g. http://mail.python.org/pipermail/patches/2006-March/019122.html 2) have a plan for how to avoid breaking code that relies on the existing API; 3) raise the issue on python-id...@python.org to gather feedback and see how much opposition or support it is likely to get; they'll suggest whether a bug report is sufficient or if you'll need a PEP; http://www.python.org/dev/peps/ If you can provide a patch and a test suite, you will have a much better chance of pushing it through. If not, you are reliant on somebody else who can being interested enough to do the work. And one last thing: any new functionality will simply *not* be considered for Python 2.x. Aim for Python 3.4, since the 2.x series is now in bug- fix only maintenance mode and the 3.3 beta is no longer accepting new functionality, only bug fixes. Servus, Walter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Jul 10, 12:33 pm, Steven D'Aprano wrote: > This is why I hate job interviews. You have like 30 minutes, or even as > little as 30 seconds, to make a good impression on somebody who may or > may not be capable of telling the difference between a cheese sandwich > and a box of hair -- and even the *good* interviewers are probably making > their judgement on the basis of subjective factors with no right or wrong > answers. You make it sound terrible... But just think which is worse: jobs decided in 30 minutes or marriages decided in 30 seconds? -- http://mail.python.org/mailman/listinfo/python-list
what's the effect of cmp here?
what's the effect of cmp here? The bList and cList is the same at last. code: aList=[3,2,5,4] bList=aList[:] bList.sort() print "bList is",bList cList=aList[:] cList.sort(cmp) print "cList is",cList -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter.event.widget: handler gets name instead of widget.
On Mon, 2012-07-09 at 10:49 -0700, Rick Johnson wrote: > On Jul 9, 12:58 am, Terry Reedy wrote: > > When posting problem code, you should post a minimal, self-contained > > example that people can try on other systems and versions. Can you > > create the problem with one record, which you could give, and one > > binding? Do you need 4 fields, or would 1 'work'? > > I'll firmly back that sentiment. Fredric, if you cannot get the > following simple code events to work properly, then how do you think > you can get events working properly on something more complex? > > ## START CODE ARTISTRY ## > import Tkinter as tk > from Tkconstants import * > > class MyFrame(tk.Frame): > def __init__(self, master, **kw): > tk.Frame.__init__(self, master, **kw) > self.bind('', self.evtMouseEnter) > self.bind('', self.evtMouseLeave) > self.bind('', self.evtButtonOneClick) > > def evtMouseEnter(self, event): > event.widget.config(bg='magenta') > > def evtMouseLeave(self, event): > event.widget.config(bg='SystemButtonFace') > > def evtButtonOneClick(self, event): > event.widget.config(bg='green') > > if __name__ == '__main__': > root = tk.Tk() > for x in range(10): > f = MyFrame(root, height=20, bd=1, relief=SOLID) > f.pack(fill=X, expand=YES, padx=5, pady=5) > root.mainloop() > ## END CODE ARTISTRY ## > This works perfectly well! What makes the case difficult is an exceptional misbehavior for no apparent reason. If I manage to strip the critical section of environmental details in the interest of concision and legibility and still reproduce the error I shall post it. So far I have failed: the stripped model I distilled yesterday worked fine. > --- > More points to ponder: > --- > 1. Just because the Tkinter designers decided to use idiotic names for > event sequences does not mean you are required to blindly follow their > bad example (the whole: "if johnny jumps off a cliff...", thing comes > to mind) > > 2. I would strongly recommend you invest more thought into your event > handler identifiers. ALL event handlers should marked as *event > handlers* using a prefix. I like to use the prefix "evt". Some people > prefer other prefixes. In any case, just remember to be consistent. > Also, event handler names should reflect WHAT event they are > processing, not some esoteric functionality of the application like > "pick_record" or "info_profile". However if you like, simply have the > event handler CALL an outside func/meth. This type of consistency is > what separates the men from the boys. > > 3. The Python Style Guide[1] frowns on superfluous white space (be it > horizontal OR vertical!) I would strongly recommend you read and adapt > as much of this style as you possibly can bear. Even if we don't all > get along, it IS *very* important that we structure our code in a > similar style. > > [1] http://www.python.org/dev/peps/pep-0008/ Excellent suggestions. Frederic -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On 10/07/2012 09:11, Christian Heimes wrote: Almost everybody can garden under ideal conditions. I grow about 15 herbs, strawberries, tomatoes, chillies and flowers on a small balcony in the middle of the city. This year I'm going to harvest at least 200 tomatoes from two plants in a 1m * 40cm * 40cm box of soil. I even have a calabash plant that grows like crazy. See? :) Christian Big 'ead :) -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On 10/07/2012 09:03, Chris Angelico wrote: On Tue, Jul 10, 2012 at 3:08 PM, Shambhu Rajak wrote: I agree with Christian, a developer should have hobbies other than computer stuffs. Versatile environment give more Ability to think differently. I like playing guitar :-) Music and programming do go VERY well together. My hobbies include online roleplaying (Dungeons & Dragons, etc), writing/managing a MUD, playing the church organ, and arranging 19th-century music. It's not at all an uncommon pairing. But would a job interviewer REALLY care that I spend my Sunday mornings up front, hiding behind two manuals and a set of faulty pedals? Or would it be of interest that I play the odd video game (and believe you me, some of the games I play are VERY odd)? If so, I hereby resign all hope of comprehending job interviews, and will fall back on Mr Hall Pycroft's notion[1] that there's absolutely no logic to them at all. ChrisA [1] cf Sherlock Holmes: The Adventure of the Stock-Broker's Clerk Surely the purpose of asking questions about hobbies or similar is to establish whether or not the person is likely to fit in? Slightly different tack, you have to get into the interview, i.e. pass the first thirty seconds test. I recall reading in a book in the local library of a manager that wouldn't employ people unless they were wearing a new pair of shoes. Guess they didn't take many people on. -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
Tim Chase wrote: On 07/09/12 19:27, Roy Smith wrote: prefer folks that know which features to check availability for deployment. Heh. Tell me, when did strings get methods? :-) IIRC, ~2.0? I'm cognizant of the shift happening from the string module to string methods, but I wouldn't expect deep history knowledge--last I checked, RedHat still supports a RHEL version that ships with 2.4, so that's about as far back as I'd probe these days (so I'd drop the decorators question now). Certainly not a deal-breaker either way. Just more data points. -tkc Why would you want to hire someone that knows something pointless as the version where feature X has been introduced ? Just tell him that feature X has been introducted in version Y, costless 2.5sec training. Don't you want to hire someone that knows things you don't and benefit from each others abilities, learning from each others, improving the company global skill range ? JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
Am 10.07.2012 09:33, schrieb Steven D'Aprano: > This is why I hate job interviews. You have like 30 minutes, or even as > little as 30 seconds, to make a good impression on somebody who may or > may not be capable of telling the difference between a cheese sandwich > and a box of hair -- and even the *good* interviewers are probably making > their judgement on the basis of subjective factors with no right or wrong > answers. IMHO one category of answers is always wrong: lies. You may oversell yourself a bit, you can (and should) keep private matters to yourself but don't lie. > And live in a house in the suburbs with enough room for a garden, good > soil, and not in the shadow of buildings. And work hours where you are > home during daylight hours. Almost everybody can garden under ideal conditions. I grow about 15 herbs, strawberries, tomatoes, chillies and flowers on a small balcony in the middle of the city. This year I'm going to harvest at least 200 tomatoes from two plants in a 1m * 40cm * 40cm box of soil. I even have a calabash plant that grows like crazy. See? :) Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Interview Questions
On Tue, Jul 10, 2012 at 3:08 PM, Shambhu Rajak wrote: > I agree with Christian, a developer should have hobbies other than computer > stuffs. Versatile environment give more > Ability to think differently. > I like playing guitar :-) Music and programming do go VERY well together. My hobbies include online roleplaying (Dungeons & Dragons, etc), writing/managing a MUD, playing the church organ, and arranging 19th-century music. It's not at all an uncommon pairing. But would a job interviewer REALLY care that I spend my Sunday mornings up front, hiding behind two manuals and a set of faulty pedals? Or would it be of interest that I play the odd video game (and believe you me, some of the games I play are VERY odd)? If so, I hereby resign all hope of comprehending job interviews, and will fall back on Mr Hall Pycroft's notion[1] that there's absolutely no logic to them at all. ChrisA [1] cf Sherlock Holmes: The Adventure of the Stock-Broker's Clerk -- http://mail.python.org/mailman/listinfo/python-list
Re: tiffany 0.6.1 released
Am 09.07.2012 17:51, schrieb Christian Tismer: > It turns out to be a problem with multiple strips in a tiff file. > PIL does not support that. Maybe I can find an easy solution, > maybe I'm better off using > > smc.freeimage > > as suggested by Christian Heimes, > > we will see. Right now I'm pretty exhaused after EuroPython... Yes, TIFF is a complex format. Even baseline TIFF has several ways to store data (e.g. chunky or planar configuration, different settings for stripes). PIL didn't support several features as well as bitonal compression (G3, G4). I'll clean up the code of smc.freeimage and release it on bitbucket over the next couple of days. Christian -- http://mail.python.org/mailman/listinfo/python-list