A question about python and xml
Hello everyone I heard this was a good community to go too for help and advice. I want to make a web site that uses the python programming language which I am VERY new at. This website would store simple data such as names in a form. At first I wanted to use mysql to store the data but I want to export the data using xml. So say if a user logged in they would be able to store there basic information in an xml file and download it whenever. Is that possible using XML and Python. I am sorry if this post doesn't make much sense but any advice would be greatly appreciated. You can also e-mail me if you need further information or clarification. Thanks Holden -- http://mail.python.org/mailman/listinfo/python-list
DjangoCon US 2012
Pythonistas: We are happy to remind all Django users that DjangoCon US is in DC this year, from September 3-8 (main conference September 4-6). Early bird pricing is available until August 3, and the schedule will be published shortly after this announcement is made. http://djangocon.us/ Since this is DjangoCon's first ever visit to the East coast we are hoping for good attendance from up and down the East coast, but some delegates will come from as far away as Australia, so Americans have no excuse! regards Steve -- The Open Bastion is the Holden Web http://TheOpenBastion.com/ subsidiary responsible forhttp://holdenweb.com/ technical events such as DjangoCon http://djangocon.us/ -- http://mail.python.org/mailman/listinfo/python-list
Community Involvement
[Ccs appreciated] After some three years labor I (@holdenweb) at last find myself approaching the completion of the Python Certificate Series with O'Reilly School of Technology (@OReillySchool). At OSCON last week the team fell to talking about the final assignment (although the Certificate is not a certification, students only progress by answering real quiz questions, not the usual multiple-choice task). Success also requires that they complete a project at the end of each (of the ~60) lesson(s). We would ideally like the last project to to be something that demonstrates at least some minimal involvement with the Python community. Something like "get a Python answer upvoted on StackOverflow", for example, or getting a question answered on c.l.p. At the same time it shouldn't be anything that places a burden on the community (otherwise the hundredth student would be abused and the thousandth murdered). So I wondered if anyone had any good ideas. regards Steve -- Steve Holden [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Community Involvement
Haven't had much Cc input so far, but this one is definitely worth following up on. Thanks! regards Steve On Aug 4, 2011, at 5:42 PM, Eric Snow wrote: > On Wed, Aug 3, 2011 at 9:14 PM, Steve Holden wrote: >> [Ccs appreciated] >> After some three years labor I (@holdenweb) at last find myself approaching >> the completion of the Python Certificate Series with O'Reilly School of >> Technology (@OReillySchool). >> At OSCON last week the team fell to talking about the final assignment >> (although the Certificate is not a certification, students only progress by >> answering real quiz questions, not the usual multiple-choice task). Success >> also requires that they complete a project at the end of each (of the ~60) >> lesson(s). >> We would ideally like the last project to to be something that demonstrates >> at least some minimal involvement with the Python community. Something like >> "get a Python answer upvoted on StackOverflow", for example, or getting a >> question answered on c.l.p. At the same time it shouldn't be anything that >> places a burden on the community (otherwise the hundredth student would be >> abused and the thousandth murdered). >> So I wondered if anyone had any good ideas. > > While not as "community" as the mailing lists, perhaps they could post > a recipe to the activestate. > > -eric > >> regards >> Steve >> -- >> Steve Holden >> [email protected] >> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> -- Steve Holden [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] [RELEASE] Python 3.6.4rc1 and 3.7.0a3 now available for testing
Ned, In your role as a representative of the many fine release managers Python has had over the years I'd like to thank you for continuing to make high-quality software available to a large and growing community. And thanks to everyone who contributes to Python so the majority just get to enjoy it. Seasons greetings Steve Steve Holden On Wed, Dec 6, 2017 at 2:29 AM, Ned Deily wrote: > Announcing the immediate availability of Python 3.6.4 release candidate 1 > and of Python 3.7.0 alpha 3! > > Python 3.6.4rc1 is the first release candidate for Python 3.6.4, the next > maintenance release of Python 3.6. While 3.6.4rc1 is a preview release > and, > thus, not intended for production environments, we encourage you to explore > it and provide feedback via the Python bug tracker ( > https://bugs.python.org). > 3.6.4 is planned for final release on 2017-12-18 with the next maintenance > release expected to follow in about 3 months. You can find Python 3.6.4rc1 > and more information here: > https://www.python.org/downloads/release/python-364rc1/ > > Python 3.7.0a3 is the third of four planned alpha releases of Python 3.7, > the next feature release of Python. During the alpha phase, Python 3.7 > remains under heavy development: additional features will be added > and existing features may be modified or deleted. Please keep in mind > that this is a preview release and its use is not recommended for > production environments. The next preview release, 3.7.0a4, is planned > for 2018-01-08. You can find Python 3.7.0a3 and more information here: > https://www.python.org/downloads/release/python-370a3/ > > -- > Ned Deily > [email protected] -- [] > > ___ > Python-Dev mailing list > [email protected] > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/ > steve%40holdenweb.com > -- https://mail.python.org/mailman/listinfo/python-list
Re: Question About Logic In Python
Terry Reedy wrote: > "Steve Holden" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>Which is yet another reason why it makes absolutely no sense to apply >>arithmetic operations to Boolean values. > > > Except for counting the number of true values. This and other legitimate > uses of False/True as 0/1 (indexing, for instance) were explicitly > considered as *features* of the current design when it was entered. The > design was not merely based on backwards compatibility, but also on > actually use cases which Guido did not want to disable. There was lots of > discussion on c.l.p. > Sure. Perhaps I should have said it makes absolutely no sense "to expect the results of aritmetic operations on bools to themselves be bools". Sheesh, you have to be so careful nowadays ... :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl's documentation come of age
Mike wrote: > "Steve Holden" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>Jim Hugunin's keynote speech at this year's PyCon was accompanied by a >>projection if his interactive interpreter session, and I know I wasn't >>alone in finding this a convincing example of Microsoft's (well, Jim's, >>really) full integration of Python into the .net framework. >>Steve Holden +44 150 684 7255 +1 800 494 3119 >>Holden Web LLC www.holdenweb.com >>PyCon TX 2006 www.pycon.org > > > Which .Net integreation technology are you speaking of? > BTW, PyCon.org seems to be down (at least not reachable from here at the > moment.) > > thanks > > I spoke of IronPython, which generates CLR code. I believe pycon.org will shortly re-emerge as a redirect to a subdirectory of the python.org domain, but I'm no longer in charge, so this may not be accurate. RSN ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: How to show percentage
Sen-Lung Chen wrote: > Dear All: > I have a question of show percentage. > For example ,I want to show the percentage of 1/3 = 33.33% > > I use the 1*100/3 = 33 > it is 33 not 33.33 , how to show the 33.33 % > Thanks > You should by now know enough answers. The easiest way to ensure that the result is floating point is to cast it as pct = 100.0 * v) / N This is guaranteed to work in all past and future Python versions without setting any options. Then you can format is using the % operator. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Anyone else getting posts back as email undeliverable bounces?
I've even tried communicating with postmaster at all relevant domains, but such messages are either bounced or ignored, so I've just filtered that domain out. regards Steve Bengt Richter wrote: > It seems lately all my posts have been coming back to me as bounced emails, > and I haven't emailed them ;-( > > I've been getting bounce messages like (excerpt): > ... > ___ > > This is the Postfix program at host deimos.liage.net. > > I'm sorry to have to inform you that your message could not be > be delivered to one or more recipients. It's attached below. > > For further assistance, please send mail to > > If you do so, please include this problem report. You can > delete your own text from the attached returned message. > > The Postfix program > > <[EMAIL PROTECTED]>: Host or domain name not found. Name service error for > name=lindensys.net type=A: Host not found > Reporting-MTA: dns; deimos.liage.net > X-Postfix-Queue-ID: DC5264161 > X-Postfix-Sender: rfc822; [EMAIL PROTECTED] > Arrival-Date: Thu, 22 Sep 2005 19:50:13 -0400 (EDT) > > Final-Recipient: rfc822; [EMAIL PROTECTED] > Action: failed > Status: 5.0.0 > Diagnostic-Code: X-Postfix; Host or domain name not found. Name service error > for name=lindensys.net type=A: Host not found > Received: by deimos.liage.net (Postfix, from userid 126) > id DC5264161; Thu, 22 Sep 2005 19:50:13 -0400 (EDT) > Received: from smtp-vbr5.xs4all.nl (smtp-vbr5.xs4all.nl [194.109.24.25]) > by deimos.liage.net (Postfix) with ESMTP id 79D8340AA > for <[EMAIL PROTECTED]>; Thu, 22 Sep 2005 19:50:13 -0400 (EDT) > Received: from bag.python.org (bag.python.org [194.109.207.14]) > by smtp-vbr5.xs4all.nl (8.13.3/8.13.3) with ESMTP id j8MNoClb072177 > for <[EMAIL PROTECTED]>; Fri, 23 Sep 2005 01:50:12 +0200 (CEST) > (envelope-from [EMAIL PROTECTED]) > Received: from bag.python.org (bag [127.0.0.1]) > by bag.python.org (Postfix) with ESMTP id 8C4871E4013 > for <[EMAIL PROTECTED]>; Fri, 23 Sep 2005 01:50:10 +0200 (CEST) > _ > ... > > > Regards, > Bengt Richter -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: How to show percentage
Steve Holden wrote: > Sen-Lung Chen wrote: > >>Dear All: >> I have a question of show percentage. >>For example ,I want to show the percentage of 1/3 = 33.33% >> >> I use the 1*100/3 = 33 >>it is 33 not 33.33 , how to show the 33.33 % >> Thanks >> > > You should by now know enough answers. The easiest way to ensure that > the result is floating point is to cast it as > >pct = 100.0 * v) / N > > This is guaranteed to work in all past and future Python versions > without setting any options. Then you can format is using the % operator. > > regards > Steve ... apart from the obvious syntax error, that is. Sigh. pct = (100.0 * v) / N regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: how to implement propertyPage using wxPyhton?
James Hu wrote: > Hi, gurus, > > > > I would like to implement something like propertyPage (VC++ term) > > Ie. There are a few tabs in the top, clicking any tab will display a > different panel. > > I searched on the Internet, couldn’t get any clue. > I think you're looking for the wx.Notebook control. Search for "notebook" in http://wiki.wxpython.org/index.cgi/Getting_20Started regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Dialogs
Grant Edwards wrote:
> On 2005-09-26, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>>James Stroud wrote:
>>
>>>from tkMessageBox import showerror
>>>showerror('Problem','Program Crashed before Starting')
>>
>>Here's a faster method, though not cross-platform:
>>
>>import ctypes
>>ctypes.windll.user32.MessageBoxA(0, "Hello World", "Title", 0x00)
>
>
> Another easy way to do a dialog box:
>
> import os
> os.system('Xdialog --msgbox "Hello World" 0 0')
>
Doesn't seem to work on my Winodws system at all ;-)
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.pycon.org
--
http://mail.python.org/mailman/listinfo/python-list
Re: The ^ operator
Tuvas wrote: > What exactly does the ^ operator do? I've seen, for example, that > 3^4=7, 3^5=8. but 3^3=0. Is it just adding them together if they are > not equal, and if they are equal, outputs 0, or what? Thanks! > ^ is the "bit XOR" operation. It treats its left and right operands as binary numbers: the result has a one-bit in those bit positions where one operand has a zero and the other has a one. A B | A XOR B + 0 0 |0 0 1 |1 1 0 |1 1 1 |0 If you want exponentiation, try **. >>> 3**4 81 >>> 3**5 243 >>> 3**6 729 >>> 3**7 2187 >>> regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Other Implementations [was: Re: Perl's documentation come of age]
Mike wrote: > "Mike" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>Looks like I'm having a bad week w/these URLs, because now I'm not able to >>access http://lists.ironpython.com/listinfo.cgi/users-ironpython.com . >>I was hoping to get at the archives to see if I can glean more info before >>I asked too many questions... > > > It's back up... > > Speaking of other implementations, I am reminded that Jython has been receiving some [PSF-sponsored] attention recently, and wanted to persuade as many as possible to give it a try. It's a couple of months since Brian Zimmer made the release, but I am pretty sure that the developers on Jython would be grateful for more feedback. http://sourceforge.net/projects/jython/ regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: sorting tuples...
Dan Sommers wrote:
> On 27 Sep 2005 19:01:38 -0700,
> [EMAIL PROTECTED] wrote:
>
>
>>with the binary stuff out of the way, what i have is this string data:
>
>
>>20050922 # date line
>>mike
>>mike's message...
>>20040825 # date line
>>jeremy
>>jeremy's message...
>>...
>
>
>>what i want to do is to use the date line as the first data in a tuple
>>and the succeeding lines goes into the tuple, like:
>
>
>>(20050922, mike, mike's message)
>
>
>>then when it matches another date line it makes another new tuple with
>>that date line as the header data and the succeeding data, etc..
>
>
>>(20050922, mike, mike's message)
>>(20040825, jeremy, jeremy's message)
>>...
>
>
>>then i would sort the tuples according to the date.
>
>
>>is there an easier/proper way of doing this without generating alot of
>>tuples?
>
>
> You want a dictionary. Python dictionaries map keys to values (in other
> languages, these data structures are known as hashes, maps, or
> associative arrays). The keys will be the dates; the values will depend
> on whether or not you have multiple messages for one date.
>
> If the dates are unique (which, looking at your data, is probably not
> true), then each item in the dictionary can be just one (who, message)
> tuple.
>
> If the dates are not unique, then you'll have to manage each item of the
> dictionary as a list of (who, message) tuples.
>
> And before you ask: no, dictionaries are *not* sorted; you'll have to
> sort a separate list of the keys or the items at the appropriate time.
>
I'm not sure this advice is entirely helpful, since it introduces
complexities not really required by the simplistic tuple notation the OP
seems to be struggling for.
Following the old adage "First, make it work; then (if it doesn't work
fast enough) make it faster)", and making the *dangerous* assumption
that each message genuinely is exactly three lines, we might write:
msglist = []
f = open("theDataFile.txt", "r")
for date in f:
who = f.next() # pulls a line from the file
msg = f.next() # pulls a line from the file
msglist,append((date, who, msg))
# now have list of messages as tuples
msglist.sort()
After this, msglist should be date-sorted list of messages. Though who
knows what needs to happen to them next ...
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.pycon.org
--
http://mail.python.org/mailman/listinfo/python-list
Re: PEP 350: Codetags
Terry Hancock wrote: > On Monday 26 September 2005 05:35 pm, Micah Elliott wrote: > >>Please read/comment/vote. This circulated as a pre-PEP proposal >>submitted to c.l.py on August 10, but has changed quite a bit since >>then. I'm reposting this since it is now "Open (under consideration)" >>at <http://www.python.org/peps/pep-0350.html>. > > > Overall, it looks good, but my objection would be: > > >>:Objection: I aesthetically dislike for the comment to be terminated >>with <> in the empty field case. >> >>:Defense: It is necessary to have a terminator since codetags may be >>followed by non-codetag comments. Or codetags could be limited to >>a single line, but that's prohibitive. I can't think of any >>single-character terminator that is appropriate and significantly >>better than <>. Maybe [EMAIL PROTECTED] could be a terminator, but then >> most >>codetags will have an unnecessary @. > > > The <> terminator is evil. People will hate that. If there are no fields, > you should just be able to leave it off. This will have an additional > advantage in that many will already have compliant codetags if you leave > off this requirement. > > You worry over the need to detect the end of the block, but wouldn't '\n\n' > be a much more natural delimiter? I.e.: > > # TODO: This is a multi-line todo tag. > # You see how I've gone to the next line. > > # This, on the other hand is an unrelated comment. You can tell it's not > # related, because there is an intervening blank line. I think people > # do this naturally when writing comments (I know I do -- I'm fairly > # certain I've seen other people do it). > # > # Whereas, as you can see, a mere paragraph break can be represented by > # a blank comment line. > # > # Whitespace formatting, after all, is VERY PYTHONIC. ;-) > # Delimiters on the other hand -- well, we prefer not to mention > # the sort of languages that use those, right? ;-) > +1 > Another possibility is to recognize lines like: > > #--- > #*** > #=== > > I.e. a comment mark followed by a line composed of repeating characters > as an alternative separator. These are also pretty in pretty common > use. > -0 regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Overhead of individual python apps
Paul Rubin wrote: > "Fredrik Lundh" <[EMAIL PROTECTED]> writes: > >>>That is bogus reasoning. >> >>not if you're a professional software developer and someone's paying you >>to develop an application that is to be run on a platform that they control. > > > An awful lot of Python targeted users are not in that situation, so if > Python's usability suffers for them when it doesn't have to, then > something is wrong with Python. If a useful subset of Python can be crammed into a Nokia cell phone then I really don't think there's much to complain about (except that "it hasn't been done for *my* machine"). Even embedded systems are much larger now than the minicomputers of yesteryear. Everything's relative. Just wait three years! i-remember-when-we-'ad-ter-code-seven-kilobytes-of-assembly-language-wi'-nowt-bu'-a-teletype-ter-edit-t'-paper-tape-wi'-ly y'rs - steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Will python never intend to support private, protected and public?
could ildg wrote: > Python is wonderful except that it has no real private and protected > properties and methods. > Every py object has dict so that you can easily find what fields and > methods an obj has, > this is very convenient, but because of this, py is very hard to support > real private and > protected? > If private and protected is supported, python will be perfect. > You only say that because you assume private and protected give you a security that they actually don't. They certainly make it more difficult to *spot* the security errors. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Searching unittest for dictionaries.
Antoon Pardon wrote: > I'm writing a class with a lot of dictionary like behaviour. > I was wondering whether a unittest for dictionaries already > exists somewhere so that I could use it as a start for > a unittest for my class. > Strangely enough my 2.4 source distribution appears to contain Lib/test/test_dict.py Perhaps this might serve as a starting point. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Overhead of individual python apps
Paul Boddie wrote: > Steve Holden wrote: > >>Even embedded systems are much larger now than the minicomputers of >>yesteryear. Everything's relative. Just wait three years! > > > Had you placed such a bet in 2000, you'd have cleaned up at the > "Moore's Law Casino", but there are various factors at work now which > complicate the once-inevitable trends of hardware performance and the > corresponding advice to people wishing to speed up or slim down their > software: the flattening out of the CPU frequency curve and the > tendency of CPU manufacturers to choose multiple core strategies are > two things which prevent applications from speeding up all by > themselves; whilst storage density is still increasing, as far as I > know, I'd imagine other strategies being adopted in system architecture > which could make performance tradeoffs more pronounced in accessing all > that storage. > > In other words, expect many more threads about global interpreter locks > in the coming three years than we've seen in the last three or even six > years. ;-) > I seem to remember blogging about this a while ago, or perhaps just ranting at c.l.py ... anyway, bottom line is that most people have more than adequate power for their current needs in a present-day single-processor computer. Expect also to see computational methods focus more on memory-intensive techniques impractical in the past. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonwin crashes
Lucas Raab wrote: > accolades wrote: > >>Does anyone else have a problem with Pythonwin crashing after running a >>python script with graphics libraries? Whenever I use Pythonwin to run >>a PyGame or PyOgre script, Pythonwin crashes when the script exits. >> >>I know it's probably because the Pythonwin interpreter can't read from >>the console once the graphics mode has been changed, but has anyone >>discovered a workaround? I'd like to know if this problem is specific >>to my machine, or if others have witnessed this. >> >>Thanks >>Tim >> > > > I think it's pretty much universal. Pythonwin crashes when you run > programs with Tk in them. > The problem is that PythonWin uses MFC-based windowing, and runs programs as a part of the same process that the IDE itself runs in. This means that there are conflicting requirements for windowing, and this can lead to PythonWin getting confused enough to crash and die. To avoid this you need a development system that uses a remote debugging technique - WingIDE, for example, can successfully debug programs based on Tkinter, wxPython and other graphical toolkits, because the programs it runs are run as separate processes. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Will python never intend to support private, protected and public?
[EMAIL PROTECTED] wrote: > On Wed, 28 Sep 2005 08:14:50 -0500 > Chris Gonnerman wrote: > > >>There are two philosophies about programming: >> >>-- Make it hard to do wrong. >> >>-- Make it easy to do right. >> >>What you are promoting is the first philosophy: Tie the programmer's >>hands so he can't do wrong. Python for the most part follows the >>second philosophy, > > > So it is for the very this reason there is no assignment operator in the > Python? > If you are really asking whether assignment was deliberately designed as a statement rather than an operator, the answer is "yes". http://www.python.org/doc/faq/general.html#why-can-t-i-use-an-assignment-in-an-expression Note also that the Python alternative is now rather out of date: rather than writing while True: line = f.readline() if not line: break ...do something with line... We would nowadays write for line in f: ...do something with line... which seems to feel quite natural to most Python programmers. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Will python never intend to support private, protected and public?
Paul Rubin wrote: > Gregor Horvath <[EMAIL PROTECTED]> writes: > >>>If you don't want the compiler to make sure your private instance >>>variables stay private, then don't declare them that way. You're the >>>one asking for less flexibility. >> >>I want to declare them as private, but want to give the flexibilty to >>access them at the users own risk. > > > What else do you want to let users do at their own risk? Treat > integers as pointers, like in C? Both are violations of type safety. > > >>Declaring everything as public is nonsene, because there should be a >>garanteed stable interface. > > > You could have a "friend" declaration like in C++, if you want to let > some class see the private instance variables of another class. > > I can't think of a single time that I've ever seen a legitimate use of > name mangling to reach from one class into another in a Python > application (I don't count something like a debugger). If you're got > some concrete examples I wouldn't mind looking. [psst ... do you think they've stopped now?] -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: duplicate entries
jackie chang wrote: > Dear Python Gurus: > > > > I am a very new Python user, would really appreciate your help. > > > > I used Python to write a web form for users to enter. The underlined > database is Oracle. One validation needs to enforce to eliminate > duplicates entries. For example: one customer ID can only be entered > only one time from the website, if a duplicate customer ID is attempted > to enter, a message should pop back to inform the user about the invalid > entry. I am enforcing primary key in the underlined Oracle table > > > > How can I code in python make this happen and get the message posted? > > > > Your assistance is highly appreciated. > There are many web frameworks and tools for interacting with databases on the web. Try a look through the just over eight million hits in http://www.google.com/search?hl=en&lr=&q=python+web+database (hint: the first two or three pages will be the best. Look for books by people whose names seem familiar :-). Some of those links will contain real examples of code and give you a useful idea of how some things can be done. Others will doubtless post more specific advice, so I am trying to provide a little background in case it should be needed. More specific (Google) searches will also give insights into different aspects of this problem. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Will Python Be Good For This Type Of Project?
Hal Vaughan wrote: > I'm self taught and most of what I've been working on for the past several > years has been entirely in Perl and Java. I've noticed that I can code > about 5 times faster in Perl than Java, in part because I feel like > whenever I want to do something in Java, I have to create an object, do a > few preperatory things, then do what I need, but in Perl, I just call the > routine. > > Java, however, does much better at cross platform apps, especially if I need > a GUI (I find Swing easy to use). I need to write a setting editor which > basically consists of a GUI with a lot of checkboxes, radio buttons, and > option select lists. I originally had something to do this in Javascript, > but Javascript was not strong enough to let me create data structures to > keep track of the data. I had to store it in 3d arrays, which was hard to > keep up with. > If you find Swing interfaces easy to build ans use then Jython should be a natural: you can do all the GUI stuff in Java and control it from Jython, thereby neatly avoiding yet another potential "What's the best GUI toolkit" [answer: same place as the world's best hamburger]. > I was planning on writing the new setting editor in Java for several > reasons, including the ability to create my own objects to store groups of > settings. I also can write it so it'll run on a computer by itself, or as > an applet with very little extra work. That's a benefit, since it means it > can be run from anywhere through a Java enabled browser and a username and > password. It can also be run on a system where it's been installed without > using a browser (either way, it reads and writes the settings from a URL). > Java does have the advantage when it comes to dynamic clients right now, given that the Python virtual machine can't be assumed to be available in the browser environment. > Someone on a mailing list I'm on has suggested that I look into Python, and > use Jython to compile it. I see that I can write applications and applets > in Python (but I haven't seen references to being able to write one > application just once and have it work as both). I also know Python is a > higher level than Java (a few people I know say it's almost like writing > pseudo code). > I have been known to provoke people by calling Java "object-oriented COBOL", but if you're happy with Java you might find Python a bit terse, and be a bit nervous about it's apparently happy-go-lucky attitude to namespace protection. If you like to be able to easily mix procedural and object-oriented approaches then I think you might want to give Python a try. > At this time I don't know Python (I've looked at some sample code and I'm > still getting used to loops and if statements without closing braces!). > What I'm trying to determine is 1) if it's relatively easy to write a > program to work as an application AND an applet (depending on how it's > called), 2) If it'll handle the networking to read what amounts to web > pages full of setting info and write that back in POST statements without > problems from the user's point of view and easily from the programmer's > point of view, 3) What coding time and difficulty is like in Python > compared to, most specifically, Java and Perl, 4) Is it easy for me to > interface Java and Python classes seamlessly, and 5) (I realize only I can > answer this for sure, but opinions and experience of others would be a > help!) Is Python easy enough and fast enough to code in that it'd be worth > me taking time to learn it and doing the project Python instead of Java? > 1) You'll need advice about "applet" from someone more versed in Jython than I. 2) Definitely no problems in the networking department 3) Not as terse as Perl, somewhat faster than Java would be my opinion, but I'm only one data point. I found the verbiage of common Java idioms irritating, there's nothing like that with Python. 4) Yes. 5) You should learn a new language now and then just to stay in practice and get in touch with newer ideas. Python isn't that hard for a Java programmer to learn, though naturally there are differences. The two languages in combination should give everyone what they want (though of course there are always some people who just want to complain about he way things are). > Any help, thoughts, comments, and such are appreciated! > > Thank you! > > Hal Some of each to get you going. I hope this has helped. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: A quick c.l.p netiquette question
Richie Hindle wrote: > [Peter] > >>Does it really have to be 158 lines to demonstrate these few issues? > > > I think you missed the other Peter's second post, where he points to his > program: http://www.pick.ucam.org/~ptc24/yvfc.html > > I didn't read every one of his 158 lines, but his code is pure poetry, or > possibly triple-distilled evil, depending on your point of view. 158 lines > very well spent either way! > I particularly like the warranty: > # NO WARRANTY: If you use this for anything important, you're mad! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Will python never intend to support private, protected and public?
Paul Rubin wrote:
> Dennis Lee Bieber <[EMAIL PROTECTED]> writes:
>
>> Ah, but in the way of your code -- it is not "your car"... It is the
>>car you supplied to someone "hundreds of miles away"... And they are
>>perfectly free to open the hood... tamper with the engine programming, etc.
>
>
> I don't understand what you're getting at. If they're free to edit
> the code, then why should they complain about private variables? They
> can change the declaration if they need to.
Similarly they can rewrite it in Perl if they don't like it being in
Python. So what? Most people have *zero* interest in looking behind the
interface of the code they use, whether it's an API or a GUI.
Effectively this whole thread seems to have become an argument about
what kind of boxes you can have around namespaces. For the vast majority
who don't care the discussion will seem a little academic.
Should namespaces be protected? The lazy Pythonista's answer to that
question is:
>>> import os; f = os.popen("python -m this")
>>> for l in f:
... if "namespaces" in l.lower().split(): print l[:-1]
...
Namespaces are one honking great idea -- let's do more of those!
>>>
[note that my laziness extends to the gratuitous introduction of a
separate process to produce the source data. Can I claim extra points
for that?]
So it should come as no surprise to anyone that namespaces appear in
many contexts in Python. So, why this sudden urge (you may wonder, if
you don't think much about code purity) to have "private" and its
buddies. The security police have arrived, and you can be pretty sure
nothing much is going to be fun from here on in.
Think about it: we have a language that has an eval() function and an
exec statement, and people are concerned that some service consumer
shouldn't be allowed to go poking around inside namespaces? What do we
have to do, put up signs saying "do not stab yourself with a knife"? If
people want control without discipline (which is effectively what
private and the like purport to do) then Python just may not be your
language ...
Access to another object's namespace is almost invariably all-or-nothing
in Python, which (it should not be overlooked) has introspection
capabilities. With this ability to poke around in the bowels of the
system to perform deep magic comes a corresponding responsibility: don't
abuse the privilege, and behave in a disciplined (sort of) way.
To avoid naming conflicts, Python provides a mechanism (name mangling)
which pretty much guarantees that your names won't conflict with anybody
else's, *even if you subclass a class whose methods use the same name*.
This was a thoughtful addition, widely ignored by experienced
programmers. It was never intended to stop people from poking around
under the hood - simply to ensure that you wouldn't *accidentally* start
poking around under the hood of a parent class's implementation because
of a name clash.
C++ and cronies are not introspective languages (Java is and, like
Python, can mess about with its own workings; because of Java's many
constraints this turns out to be much less fun than in Python, but of
course Jython will give you access to many useful Java resources in a
much saner context) and non-introspective programmers frequently recoil
in horror when faced with the prospect of losing the training wheels :-)
Given the denizens of this particular list/newsgroup I am sure I will be
bombarded by a host of ways I could have produced the output of "import
this" without creating a new process. So, to try and forestall various
further expansions of this thread, let me produce a FAQ (which is
clearly quite bogus, since I am still writing it) for this post.
Q: It's inefficient to start another process.
A: When I need to do it six million times a second I'll remember that.
This was a one-off example. I have already wasted more time
discussing this issue than I would have saved in the first
thousand runs of a rewrite.
Q: It isn't cross-platform.
A: Well it runs on Windows, Cygwin and Linux, so it doesn't do badly.
Q: You could have done it some other way.
A: Please get over this obsession. There will always be more than
one way to do most things despite the output from a simpler (but
non-portable) solution
$ python -m this | grep way
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Note that word "obvious": nobody says you *have* to do things the
obvious way.
Q: Are you Dutch or something?
A: No such luck. But I'm not Belgian either :-)
a-voice-said-smile-things-could-be-worse-so-i-smiled
Re: Will python never intend to support private, protected and public?
Fredrik Lundh wrote: > Steve Holden wrote: > > >>To avoid naming conflicts, Python provides a mechanism (name mangling) >>which pretty much guarantees that your names won't conflict with anybody >>else's, *even if you subclass a class whose methods use the same name*. > > > as long as you don't cheat, that is: > > # your code > > class Secret: > def __init__(self): > self.__hidden = "very secret value" > > # my code > > from yourcode import Secret > > class Secret(Secret): > def gethidden(self): > return self.__hidden > > s = Secret() > print s.gethidden() > I thought you'd know me well enough to know I'd *never* cheat :-) Nice way to point out that Pythin is indeed a "consenting adults" language. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: attribute error
Mike Meyer wrote: > In <[EMAIL PROTECTED]>, M.N.A.Smadi <[EMAIL PROTECTED]> typed: > >>This has nothing to do with how the argument is passed. It is prob >>something wrong with str.pop in my python because when i run python and type >>import os >>import string >>x = '1 2 3' >>x.pop() >> >>i get the following error >>Traceback (most recent call last): >> File "", line 1, in ? >>AttributeError: 'str' object has no attribute 'pop' > > > The only thing wrong with str.pop is that you're trying to invoke > it. The interpreter is telling you that string doesn't *have* a pop > method. The interpreter is right. Strings are immutable, so "pop" > doesn't make any sense for them. > >[...] Just to hammer the point home: Python 2.4.1 (#1, May 27 2005, 18:02:40) [GCC 3.3.3 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> x = '1 2 3' >>> x.pop() Traceback (most recent call last): File "", line 1, in ? AttributeError: 'str' object has no attribute 'pop' >>> x = [1, 2, 3] >>> x.pop() 3 >>> x.pop() 2 >>> x [1] >>> So if you genuinely have a string containing the values, split it onto a list first using something like x = x.split() regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: RELEASED Python 2.4.2 (final)
Delaney, Timothy (Tim) wrote: > Bugs wrote: > > >>It says ActivePython 2.4.1 but I downloaded the 2.4.2 binary installer >>from python.org and the python.exe executable I'm running is >>timestamped 9/28/2005 12:41PM... Any ideas what I'm doing wrong? > > > Visit this site: > http://www.catb.org/~esr/faqs/smart-questions.html > > Then try running the installer you downloaded (note any errors). Also, > since the packages are produced by different groups (ActiveState vs. > Python.org) perhaps you should uninstall the ActiveState package first > (in which case you may need to install the pywin packages). > > Tim Delaney While that's often good advice, in this particular case I believe the OP's question was quite smart enough. It certainly got him the right answer in quick time! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: A quick c.l.p netiquette question
Peter Hansen wrote: > Fredrik Lundh wrote: > >>Peter Hansen wrote: >> >>>Does it really have to be 158 lines to demonstrate these few issues? I >>>for one almost never take the time to dig through 158 lines of someone >>>else's code, partly on the assumption that almost any interesting issue >>>can be covered (using Python, specifically) in about a dozen lines of >>>code. > > >>did you click on the link he posted a little later? > > > What link? I see only two posts from him in this thread, one at 5:09 > and the other at 6:14, and neither contains links. I suppose I should > start to distrust my ISP's news feed, because that was how it was this > morning and how it still is now. There are a grand total of 10 posts to > that thread as I'm about to post this reply. > > Sorry, but I can't click on links that don't exist. > > >>>YMMV >> >>no, YVFC. > > > ?? you've lost me there too. Your Very Fucked Computer? I'll agree > that some computer around here is fucked if I can't see a post that > everyone else can see. > > -Peter > > (Well now... I just realized that it wasn't in the same thread after > all, and yes, I did see the post, then noticed a reply from someone > talking about Greenspun's law, quickly hit "k" to move on to more > interesting topics, and never gave it a second thought. Certainly > didn't notice it was also Peter who had posted that one, nor realized > the connection (probably because I'd already sent my reply and thus > flushed the whole affair from my memory). So, in summary, yes I did > click on the link he posted, but that was after I'd already replied so I > don't think it's particularly useful for us to be discussing it. YMMV > again. :-) ) > > (And I do see the YVFC part now... what was really bizarre was trying to > do a search on the web for what that acronym means. Try it... strange > stuff. I was thinking there was some weird conspiracy to make people > think there was this acronym that was well known but had no online > definition.) Reminds me of the old one about them missing the world "gullible" from [name dictionary of your choice]. Always nice to be able to ask someone to read the definition once you've got them to prove you wrong. Peter, perhaps you are getting too old to be posting on c.l.py ;-) that'll-teach-you-to-be-rude-about-*me*-ly y'rs - steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Will python never intend to support private, protected and public?
[EMAIL PROTECTED] wrote: > On Fri, 30 Sep 2005 06:31:44 +0200 > Fredrik Lundh wrote: > > >>[EMAIL PROTECTED] wrote: >> >> >>>Looks like you must know every one of the base classes of the NotSoSecret, >>>whether there is some base class named Secret? And, if so, you must also >>>know these classes _implementation_ >> >>that information isn't hidden, so there's nothing "you must know". finding >>out >>is a matter of writing a very small program, or tinkering at the interactive >>prompt >>for a couple of seconds. are you even aware that you're posting to a Python >>group ? > > > So you have read every line of the python std library, I guess? (Not to > mention libc or kernel32.exe or whatever.) > The effbot is actually probably about the worst opponent you could have taken on with a feeble argument like that being, as he (it) is, the author of the O'Reilly standard on the Python Standard Library. So Fredrik is probably *much* more likely than any other regular poster to be intimately familiar with the standard library. All of which misses his point, however. Python easily allows you to access the information you are saying you "must know" - for non-extension classes it will even decompile the code if you ask it. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Will python never intend to support private, protected and public?
Antoon Pardon wrote: > Op 2005-09-29, Bill Mill schreef <[EMAIL PROTECTED]>: > >>But, if your users can't figure out that they shouldn't be changing >>the variable called t._test__i without expecting side effects, what do >>you think of the users of your class? >> >>Python is for consenting adults. > > > No it is not. Consenting means you had the choice. Python doesn't > give you the choice not to consent. Unless of course you write > it as a C-extension, then you can hide all you want. > Good grief, the ultimate choice is to use Python because you like it, or not to use it because you don't. Enough with the picking every available nit, please. Consent or stop complaining :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: scope of socket.setdefaulttimeout?
Russell Warren wrote: > Does anyone know the scope of the socket.setdefaulttimeout call? Is it > a cross-process/system setting or does it stay local in the application > in which it is called? > > I've been testing this and it seems to stay in the application scope, > but the paranoid side of me thinks I may be missing something... any > confirmation would be helpful. > Yes, it's an application setting, you aren't changing things for anyone else. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Will python never intend to support private, protected and public?
Antoon Pardon wrote: > Op 2005-09-29, Steve Holden schreef <[EMAIL PROTECTED]>: > > >>Think about it: we have a language that has an eval() function and an >>exec statement, and people are concerned that some service consumer >>shouldn't be allowed to go poking around inside namespaces? What do we >>have to do, put up signs saying "do not stab yourself with a knife"? If >>people want control without discipline (which is effectively what >>private and the like purport to do) then Python just may not be your >>language ... > > > Well I have the following reasons not to like the current python way: > > 1) Beginning all your private variables with an underscore is like > starting all your integers with an 'i' or all your dictionary with > a 'd' etc. > Well, surely anyone who's ever used Fortran knows that god is real unless explicitly declared to be integer. The convention wasn't meant for people who can't be safely allowed outside on their own. > 2) The editor and font I use make it hard to see underscores. They > usually seem to belong more to the line below than to the actual > lines. > So use a different editor and/or font, for Pete's sake. > My idea as somekind of compromise between what happens in languages > like C++ and currently in python would be the following: > > 1) Allow keywords like private (or implemetation) to mark certain > variables, functions or classes as an implementation detail. > Personnally I would prefer the opposite such as a interface > to mark objects which are not private, but that would break too > much code. > > 2) Allow the client access to these private variables, through > a special construct. Maybe instead of "from ... import ..." > "from ... spy ...". > > Just an idea. > Just an off-hand rejection. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Will python never intend to support private, protected and public?
Paul Rubin wrote: > Steve Holden <[EMAIL PROTECTED]> writes: > >>Good grief, the ultimate choice is to use Python because you like it, >>or not to use it because you don't. Enough with the picking every >>available nit, please. Consent or stop complaining :-) > > > Riiight. "If she was walking in that neighborhood she must have > wanted it". This is about the most specious argument imaginable. There's plenty of room for discussion, heaven knows, without having to instigate a semantic examination of the word "consenting". Some days you can't say anything without the nit police trampling your toes. Some days that gets on my nerves. Other days I'm out there picking nits myself. What can I tell you, I'm human. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: RELEASED Python 2.4.2 (final)
Fuzzyman wrote: > On Thu, 29 Sep 2005 17:53:47 -0700, Bugs <[EMAIL PROTECTED]> wrote: > > >>I downloaded the 2.4.2 Windows Binary Installer from python.org but when >>I try to run python.exe I get the following in the console: >> >>ActivePython 2.4.1 Build 247 (ActiveState Corp.) based on >>Python 2.4.1 (#65, Jun 20 2005, 17:01:55) [MSC v.1310 32 bit (Intel)] on >>win32 >>Type "help", "copyright", "credits" or "license" for more information. >> >> >>It says ActivePython 2.4.1 but I downloaded the 2.4.2 binary installer > >>from python.org and the python.exe executable I'm running is timestamped > >>9/28/2005 12:41PM... Any ideas what I'm doing wrong? >> > > > I had problems updating from activestate 2.4 to activestate 2.4.1 > > I think it was caused by not uninstalling the original. This does mean > that even a *minor* version upgrade is a PITA. To do it cleanly all > extension modules have to be uninstalled and re-installed. > > *sigh* > Not necessarily so. You should find the uninstall leaves all your local additions in place in site-packages, immediately available when a new minor version is installed. Until 2.5, of course, *then* you'll need to reinstall. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Will python never intend to support private, protected and public?
Antoon Pardon wrote: > Op 2005-09-30, Steve Holden schreef <[EMAIL PROTECTED]>: > >>Antoon Pardon wrote: >> >>>Op 2005-09-29, Bill Mill schreef <[EMAIL PROTECTED]>: >>> >>> >>>>But, if your users can't figure out that they shouldn't be changing >>>>the variable called t._test__i without expecting side effects, what do >>>>you think of the users of your class? >>>> >>>>Python is for consenting adults. >>> >>> >>>No it is not. Consenting means you had the choice. Python doesn't >>>give you the choice not to consent. Unless of course you write >>>it as a C-extension, then you can hide all you want. >>> >> >>Good grief, the ultimate choice is to use Python because you like it, or >>not to use it because you don't. Enough with the picking every available >>nit, please. Consent or stop complaining :-) > > > This is IMO not a nit. IMO people are redefining words. We are also > talking within a certain context. When people use this slogan, they > don't mean that people have the choice to not use python. > Quite true, but people do none the less have that choice. Some days I wish a few more would exercise it. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: A Moronicity of Guido van Rossum
[off-list] Peter Hansen wrote: > Gerrit Holl wrote: > >>True. However, most mail to this mailinglist has less than 0.001 spam >>probability. As you can see, this one had 0.048 - a vast score, almost >>enough to put it in my unsure box. It seems to be just not hammy enough. >>It's interesting to see that no none of the foul language words used by >>Xah Lee ever occurs in any spam I receive - spam is not that stupid. > > > "Xah Lee: stupider than spam." (?) > > -neologism-intentional-ly y'rs, > Peter I'm responding off-list so's not to give this loony's threads any more visibility. Please do not feed the troll (I am passing on a message that was delivered to me, and I too should have known better). FWIW I really like the slogan. Maybe you should register "stupiderthanspam.com" and make a million? Amused me no end. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: how to stop info output on screen
[EMAIL PROTECTED] wrote:
> Hi,
>
> Does someone know how to stop "the information output on screen"? Now
> when I run my code, it outputs a lot of message when calling other
> libraries, together with the info with the print command I used.
>
> How can I mask these info on screen when calling other libraries and
> how I can mask the info output produced by the print command? Is there
> a way to mask them separately.
>
> Thanks a lot if anyone knows it.
>
> Kind regards of your help
> Midday
>
Since you appear to be adding your own code, with your own print
statements, to an existing Python program the easiest thing to do is
make sure your own code writes to a place of your choice. This is most
easily done with
myFile = open("myfile.txt", "w")
...
print >> myFile, this, that, the other
...
print >> myFile, moreStuff(things)
...
myFile.close()
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Google Not Universal Panacea [was: Re: Where to find python c-sources]
are taken up by responses to their inanities). As time goes by I find myself more and more likely, getting to the end of a possibly sharp or vindictive response, to simply kill the post and take what pleasure I can from not having shared that particular piece of small-mindedness with the group. In the end our most valuable contributions to groups like this can be the gift of being able to walk away from a fight simply to keep the noise level down. so-now-thank-me-for-not-saying-all-that-crap-ly y'rs - steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Will python never intend to support private, protected and public?
Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: > >>>2) Allow the client access to these private variables, through >>>a special construct. Maybe instead of "from ... import ..." >>>"from ... spy ...". >> >>What you are suggesting is that you have private variables that are only >>private by convention, since anyone can simply call use spy to treat >>them as public. > > > This notion isn't so bad, if there's way for modules to notice when > they're spied on, like an import hook, e.g.: > > def __spy__(othermodule, symbol_list): > # this gets called when another module spies on symbols > > It's like a runtime version of C++'s "friend" declaration. Well, not > quite as good, it's like having some stranger slide over to you in a > bar and say "I wanna be your friend". But at least it's better than > not finding out at all where the external references are. Oh, great, so now I have to code my classes so they know what to do when someone starts spying on them. Don't you have work to do? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Overloading __init__ & Function overloading
Iyer, Prasad C wrote: > I am new to python. > I have few questions > a. Is there something like function overloading in python? Not in the same way as Java: you can't write several functions and have the compiler or run-rime system work out which one to call according to argument types. Don't forget that Python is so dynamic that the types of a function's arguments may vary between successive iterations of the same statement. > b. Can I overload __init__ method > The normal way to do this is to have the subclass's __init__ call the superclass's __init__, usually right at the start. When you get deeply into Python you will learn that you even call a function to determine the right superclass on which to call __init__. What is "super()"? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Will python never intend to support private, protected and public?
Rocco Moretti wrote: > Antoon Pardon wrote: [...] >>It helps, just as locks wont save you from burglars if they really >>want to rob you, but the locks do help. > > > Right, but like doors that automatically lock when they close, items > which are there to protect you can be a nusaince, especially when you've > left your keys on the dining room table. That would make a good Onion (www.TheOnion.com) headline: "Users Discover Computer Security Conflicts with Desire for Convenience" regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Google Not Universal Panacea [was: Re: Where to find python c-sources]
Erik Max Francis wrote: > Steve Holden wrote: > > >>While a snappish "go and look it up on Google" might suffice for a >>mouthy apprentice who's just asked their thirteenth question in the last >>half hour, it's (shall we say) a little on the brusque side for someone >>who only appears on the group last February, and has a history of asking >>reasonably pertinent though sometimes beginner-level questions. > > > I told him exactly where it was. I just also pointed out that he could > have trivially found out the answer on his own by using Google for > fifteen seconds. It would be one thing if I (and nobody else) answered > his question and just rudely pointed him to Google. But since I > actually answered his question, looks to me like someone just wanted to > stand on his soapbox today. > I don't think "The source tarball on python.org" could claim to be telling him "exactly where it was" given that my copy of the web site has 341 MB of stuff in it. Just that same, if you are saying that your behaviour didn't really merit my response then I'd probably agree. Your post was the straw that broke the camel's back rather than an egregious example of bad manners. So I'm sorry if it looked as though the soapboxing was directed primarily at you, which it wasn't. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python CGI Script
Efrat Regev wrote: > Hello, > > I'm a data-structures course TA trying to write a python CGI script > for automatically compiling and testing students' projects. > Unfortunately, I've run into some questions while writing this, which I > couldn't solve with the various (and helpful) python-CGI documentation. > (It's possible that I'm posting to the wrong group; if so, I'd > appreciate suggestions for the appropriate group.) > > > 1. In my HTML page, I have the following: > > enctype="multipart/form-data"> > ... > > > In the above, submission_processor.py is the python CGI script. I > didn't write a URL in the action field, since I'm first testing > everyting on a local machine (running FC4). The first line of > submission_processor.py is > > #!/usr/bin/python > > and I've done > > chmod +x submission_processor.py > > When I hit the "submit" button, my browser (Firefox on FC4) doesn't > run the script; it asks me whether it should open > submission_processor.py or save it to disk. I couldn't figure out why. > You also have to have the executable script inside a directory that is recognised as being a script directory (usually achieved with an Apache ScriptAlias directive), or have the server otherwise recognise .py files as executable (just setting the +x mode bit isn't enough). In the absence of such knowledge the server just returns the content of the file rather than the content produced by *executing* the file. > 2. My HTML page has the option for an instructor to list the various > submissions and scores. Obviously, this should be inaccessible to > students. The instructor has a password for doing this, therefore. > Suppose I place the password inside a python script, and give this > script only +x permission for others. Is this adequate as far as security? > That depends on whether you wanted to use HTTP security (provided automatically by the web server) or application security (provided by your code). In the case of a script which is for general running but where some of the script's functionality shouldn't be generally available you are stuck with the latter. It's OK to have passwords in your script as long as you are sure that the script isn;t going to be served up as content like it currently is! > > Thanks in advance for answering these questions. > > > Efrat regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems posting with urlencode
Fredrik Lundh wrote: > Joseph Chase wrote: > > >>When I go and view the inserted record, the record exists, but the field >>values are null. It is my thinking that the backend needs the "id" value >>for each input value; how do I add that data to the urlencode() call? > > > since the id isn't part of the form data set: > > http://www.w3.org/TR/REC-html40/interact/forms.html#form-data-set > > that's a bit unlikely. > > printing the params string might help you figure out what's > missing. > If there's no chance of putting any debug statements into the processing script you might consider using a proxy or submitting to a local server to ensure that you are submitting what you think. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding the Process Path
Peck, Jon wrote: > Thanks, but this doesn't tell me what I am looking for. > > I am looking for the path for the current process (which will not be the > Python interpreter). > Actually the core image will be that of the Python interpreter. > I see, though, that this is available as sys.executable > The interpreter? That's correct. What you probably want is import os, sys print os.path.abspath(sys.argv[0]) this will give you the path to the Python script the interpreter is running. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: "no variable or argument declarations are necessary."
[EMAIL PROTECTED] wrote: > On 3 Oct 2005 13:58:33 GMT > Antoon Pardon wrote: > > >>People often promote unittesting here. Writing all those unittest is >>an added burden too. But people think this burden is worth it. >> >>I think writing declaration is also worth it. The gain is not as >>much as with unittesting but neither is the burden, so that >>balances out IMO > > > +1 > > Some people just don't get the simple fact that declarations are > essentially kind of unit test you get for free (almost), and the compiler > is a testing framework for them. > Hmm. Presumably introspection via getattr() is way too dangerous, then? Might as well throw the function away ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: question about smtplib
[EMAIL PROTECTED] wrote: > Hey there, > > i am using the smtplib module in python 2.3 > > my question is, this works: > > server = smtplib.SMTP(localhost) > > then server.sendmail(to address, from address, message) > > > what i want to know is, how does the connection work? > > when i do server.sendmail, does it connect then ? or did it connect > when > i made the object ? > > the reason i need to know is i need to send several emails out at once > and would be best to only connect once, i think. > > i know that i can call server.close(), i just dont know when it was > opened. > thanks > If you provide the host name the server is connected immediately. You can use that connection to send several emails, terminating the connection when you call the object's quit() method. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamical loading of modules
Carsten Haese wrote: > On Mon, 2005-10-03 at 16:41, Carsten Haese wrote: > >>On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote: >> >>>Hi, I'm having some problems with implementing dynamical module loading. >>>First let me >>>describe the scenario with an example: >>> >>>modules/ >>>fruit/ >>>__init__.py >>>apple.py >>>banana.py >>> >>>apple.py defines a class 'Apple', banana defines a class 'Banana'. The >>>problem lies in the >>>fact that I want to be able to just drop a new .py-file, for instance >>>peach.py, and not change >>>__init__.py, and it should automatically pickup the new file in >>>__init__.py. I've come halfway >>>by using some imp module magic in __init__.py, but the problem I have is >>>that the instantiated >>>objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild >>>I want it to be >>>fruit.Apple/fruit.Banana. >>> >>>Is there a smarter way of accomplishing what I am trying to do ? >>>If someone could give me a small example of how to achieve this I would >>>be very grateful. >> >>How about something like this in fruit/__init__.py: >> >>import os >> >>fruit_dir = os.path.dirname(__file__) >>fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and >>x!='__init__.py')] >>for fruit_file in fruit_files: >> module_name = fruit_files[:-3] > > ^^^ This should be fruit_file, of course. > > >> exec "from %s import *" % module_name >> Wouldn't __import__(module_name) be better. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Debug Build
Celine & Dave wrote: > Hi, > > What happens if I build Python with debug option > (--with-pydebug)? Do I see any changes in my program > output? What is --with-pydebug good for? > It's used for debugging the Python interpreter itself. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Reply-To header
Roel Schroeven wrote: > Mike Meyer wrote: > >>Peter Decker <[EMAIL PROTECTED]> writes: >> >> >>>Setting the default Reply-To: to the list means that 'Reply' sends >>>just to the list (the desired behavior most of the time), and 'Reply >>>to all' sends 2 copies. >> >> >>No, it sends one copy to the list, and one copy to the original >>author. This is the behavior you want. The author may not be >>subscribed to the list. Such people are most in need of help, and you >>want the default to be that they get help. > > > Is that really the desired behaviour? IMO the least you can do if you're > searching for help is subscribing to the mailing list on which you're > looking for help. Me and many others don't like to receive replies > directly instead of via the mailing list; it's of no use, since we're > subscribed to the mailing list anyway. > > Just reply to the mailing list, and subscribe to it if you want to > receive replies. Avoids duplicates without all kinds mail filters. Only > disadvantage is that by subscribing to the mailing list, you receive all > posts to the list, not just the replies to your own post. But that's not > a big disadvantage. On the contrary; one can easily learn something from > them. > ... if one has time to do anything but curse and delete them ! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Reply-To header
Steven D'Aprano wrote: > Mike Meyer wrote: > > >>When I notice that a list is broken (RFC 2822 says that >>reply-to is for the *author* of the message; anyone else setting it is >>doing so in violation of the RFC, and hence broken, no matter how >>useful it may be), > > > Since when did obeying the RFC become important in and > of itself? If there was a RFC that said that passwords > should be limited to one alphanumeric character, would > we slavishly follow it? > The day such an RFC is published will be the day RFCs stop being useful. Until that time the RFCs are pretty much the guide to desired behaviour on the Internet, and anyone willfully disobeying them is asking for trouble. If an RFC was published saying you should give yourself a kick in the head for such inanity would you do it? ;-) > I have been known to change the reply-to address from > the address I am sending from ([EMAIL PROTECTED] for example) to > the address I want the reply to go to ([EMAIL PROTECTED]). There > are many times I'm emailing people I know can't cope > with the complicated task of changing the To address of > their reply, so I change the reply-to header so that > their reply goes where I want it to go to (which might > be another email address of mine, or a different > person, or a mailing list). > This is an entirely sensible use of the Reply-To address, and indeed many mail clients nowadays will allow you to set a Reply-To for each of the accounts you create. Having in the past used accounts where the Reply-To was different from the originating address I am only too well aware, though, that there are several email clients and mailing systems that *don't* correctly action Reply-To, and instead respond to the originating address directly. > That's what reply to means, surely? What is the point > of a reply-to header that must be the sender, since you > already have a header that gives you the sender. > Quite. > If the RFC says that the reply-to header doesn't > actually mean the address the reply should go to, but > only the sender, then the RFC is broken. "Where the > reply goes to" is a *human* decision, not a technical > one. If I send you an email saying "Please reply to > [EMAIL PROTECTED]" then your mailer should > honour that (although, since we are all adults, you > should have the freedom to ignore my request and make a > nuisance of yourself by emailing your reply to a > different address). > Of course, few users actually bother to even check whether the address their mailer generates corresponds to anything in the original message, instead blindly relying on their software's behaviour for correctness (see above). > Likewise, if I set the reply address to the list, then > your mailer should reply to the list. Perhaps you can > argue that *my decision* to have replies go to the list > is a bad one, but that's a social issue, not a > technical one. > Most mailers will indeed do this. Except the ones that don't (see above ...). > > >>I tell my mailer to ignore reply-to on mail from >>that list. Similarly, I no longer try and explain to people how long >>lines violate RFCs and are a pain to read in well-behave mail readers, > [...] Having a mailer that can vary its behaviour from one list to another is something that's way beyond 90% of Internet mail users nowadays. Sadly we are talking about a problem that the majority of users don't even understand, happily sending their rich-text and HTML emails to mailing lists/newsgroups as well as individuals. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: "no variable or argument declarations are necessary."
Paul Rubin wrote: > Antoon Pardon <[EMAIL PROTECTED]> writes: > >>>Or you just code without declaring, intending to go >>>back and do it later, and invariably forget. >> >>What's the problem, the compilor will allert you >>to your forgetfullness and you can then correct >>them all at once. > > > Thiat in fact happens to me all the time and is an annoying aspect of > Python. If I forget to declare several variables in C, the compiler > gives me several warning messages and I fix them in one edit. If I > forget to initialize several variables in Python, I need a separate > test-edit cycle to hit the runtime error for each one. Well I hope you aren't suggesting that declaring variables makes it impossible to forget to initalise them. So I don;t really see the relevance of this remark, since you simply add an extra run to fix up the "forgot to declare" problem. After that you get precisely one runtime error per "forgot to initialize". regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: What is executed when in a generator
Jerzy Karczmarczuk wrote: > I thought that the following sequence > > gl=0 > def gen(x): > global gl > gl=x > yield x > > s=gen(1) > > suspends the generator just before the yield, so after the > assignment of s gl becomes 1. > > Well, no. It is still zero. If I put > > print "something" > > before the yield, this doesn't get executed either. *EVERYTHING* > from the beginning until the yield gets executed only upon s.next(). > > Could you tell me please where can I read something in depth about the > semantics of generators? I feel a bit lost. > Thank you. > The first hing you need to realise is that s is a generator, and it needs to be used in an iterative context to see the (sequence of) yielded results: >>> s = gen(1) >>> s The easiest way to do this is to use the generator in a loop - though of course in this case the sequence of yielded results is going to be of length 1 ... >>> for o in s: ... print o ... 1 >>> It's easier to see the power of this when the generator yields several results, either from a loop or otherwise: >>> def shg(n): ... for i in range(n): ... if i % 2: ... yield i ... >>> s = shg(6) >>> s >>> for i in s: ... print i ... 1 3 5 >>> The reason for this is so you can create multiple (parameterised) generators using different calls: >>> s1 = shg(3) >>> s2 = shg(7) >>> print [i for i in s1] [1] >>> print [i for i in s2] [1, 3, 5] >>> Fredrik Lundh has already pointed you to the full description, so I'll content myself with adding that you can, if you want to you can call the generator's next() method to access the next in its sequence of results: >>> s1 = shg(3) >>> s2 = shg(7) >>> print [(i, s2.next()) for i in s1] [(1, 1)] >>> print [i for i in s2] [3, 5] Hope this makes things a little clearer. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamical loading of modules
Carsten Haese wrote: > On Mon, 2005-10-03 at 17:37, Steve Holden wrote: > >>Carsten Haese wrote: >> >>>On Mon, 2005-10-03 at 16:41, Carsten Haese wrote: >>> >>> >>>>On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote: >>>> >>>> >>>>>Hi, I'm having some problems with implementing dynamical module loading. >>>>>First let me >>>>>describe the scenario with an example: >>>>> >>>>>modules/ >>>>> fruit/ >>>>> __init__.py >>>>> apple.py >>>>> banana.py >>>>> >>>>>apple.py defines a class 'Apple', banana defines a class 'Banana'. The >>>>>problem lies in the >>>>>fact that I want to be able to just drop a new .py-file, for instance >>>>>peach.py, and not change >>>>>__init__.py, and it should automatically pickup the new file in >>>>>__init__.py. I've come halfway >>>>>by using some imp module magic in __init__.py, but the problem I have is >>>>>that the instantiated >>>>>objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild >>>>>I want it to be >>>>>fruit.Apple/fruit.Banana. >>>>> >>>>>Is there a smarter way of accomplishing what I am trying to do ? >>>>>If someone could give me a small example of how to achieve this I would >>>>>be very grateful. >>>> >>>>How about something like this in fruit/__init__.py: >>>> >>>>import os >>>> >>>>fruit_dir = os.path.dirname(__file__) >>>>fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and >>>>x!='__init__.py')] >>>>for fruit_file in fruit_files: >>>> module_name = fruit_files[:-3] >>> >>> ^^^ This should be fruit_file, of course. >>> >>> >>> >>>> exec "from %s import *" % module_name >>>> >> >>Wouldn't >> >> __import__(module_name) >> >>be better. > > > I don't see how a working example that meets the OP's requirements can > be constructed using __import__, but that may easily be due to my lack > of imagination. How would you do it? > I was simply suggesting that you replace the exec statement with a call to __import__(). Wouldn't that work? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamical loading of modules
Carsten Haese wrote: > On Tue, 2005-10-04 at 08:32, Steve Holden wrote: > >>Carsten Haese wrote: >> >>>On Mon, 2005-10-03 at 17:37, Steve Holden wrote: >>> >>> >>>>Carsten Haese wrote: >>>> >>>> >>>>>On Mon, 2005-10-03 at 16:41, Carsten Haese wrote: >>>>> >>>>> >>>>> >>>>>>On Mon, 2005-10-03 at 15:52, Jacob Kroon wrote: >>>>>> >>>>>> >>>>>> >>>>>>>Hi, I'm having some problems with implementing dynamical module loading. >>>>>>>First let me >>>>>>>describe the scenario with an example: >>>>>>> >>>>>>>modules/ >>>>>>> fruit/ >>>>>>> __init__.py >>>>>>> apple.py >>>>>>> banana.py >>>>>>> >>>>>>>apple.py defines a class 'Apple', banana defines a class 'Banana'. The >>>>>>>problem lies in the >>>>>>>fact that I want to be able to just drop a new .py-file, for instance >>>>>>>peach.py, and not change >>>>>>>__init__.py, and it should automatically pickup the new file in >>>>>>>__init__.py. I've come halfway >>>>>>>by using some imp module magic in __init__.py, but the problem I have is >>>>>>>that the instantiated >>>>>>>objects class-names becomes fruit.apple.Apple/fruit.banana.Banana, whild >>>>>>>I want it to be >>>>>>>fruit.Apple/fruit.Banana. >>>>>>> >>>>>>>Is there a smarter way of accomplishing what I am trying to do ? >>>>>>>If someone could give me a small example of how to achieve this I would >>>>>>>be very grateful. >>>>>> >>>>>>How about something like this in fruit/__init__.py: >>>>>> >>>>>>import os >>>>>> >>>>>>fruit_dir = os.path.dirname(__file__) >>>>>>fruit_files = [x for x in os.listdir(fruit_dir) if (x[-3:]=='.py' and >>>>>>x!='__init__.py')] >>>>>>for fruit_file in fruit_files: >>>>>>module_name = fruit_files[:-3] >>>>> >>>>> ^^^^^^^ This should be fruit_file, of course. >>>>> >>>>> >>>>> >>>>> >>>>>>exec "from %s import *" % module_name >>>>>> >>>> >>>>Wouldn't >>>> >>>>__import__(module_name) >>>> >>>>be better. >>> >>> >>>I don't see how a working example that meets the OP's requirements can >>>be constructed using __import__, but that may easily be due to my lack >>>of imagination. How would you do it? >>> >> >>I was simply suggesting that you replace the exec statement with a call >>to __import__(). Wouldn't that work? > > > Not the way I tried it by simply replacing my line with your line. (If > it matters, I'm on python 2.2 here.) First of all, the __import__ > variant doesn't see the submodules unless I add fruit_dir to sys.path. > Secondly, the OP's requirements are that the classes that the submodules > implement be imported into fruit's namespace, and I don't see how to > make __import__ do that. > Please ignore my brainfart and proceed as per your plan :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: cgi relay for python cgi script
Amir Michail wrote: > Fredrik Lundh wrote: > >>Amir Michail wrote: >> >> >>>Is there an easy way to do this without modifying the configuration of >>>the cgi server and without running a cgi server on the other machine >>>where the script will actually run? >>> >>>Perhaps someone wrote a simple server that provides the required >>>environment for the cgi script to run? >>> >>>I'm looking for something simple that does not require root access. >> >>you could of course use something like >> >>http://docs.python.org/lib/module-CGIHTTPServer.html >> >>or some other light-weight web server, but you should probably have in mind >>that doing things like this without coordinating with your server >>administrators >>and security architects *before* you start tinkering can be a excellent way to >>get fired... >> >> > > > I would like to do this to improve performance by avoiding nfs. (The > required data is not on the cgi server.) > > The advice I got was to use something like MySQL with a client/server > architecture. > > However, I thought it would be easier to simply run the core part of > the script off the cgi server, thereby avoiding nfs for data lookups. > > So I guess the point is that such a solution is more likely to be a > security risk than MySQL? > > Amir > You are hardly likely to improve performance by substituting a fairly high-level application like CGI or MySQL for NFS. But later you suggest that security is the issue rather than performance. I'm confused. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Exception raising, and performance implications.
leo wrote: >>However, I think the functionality you're asking for is available as >>inspect.currentframe(), and if the implementation is in "C" it may have a tiny >>performance advantage over the Python version. > > > You're absolutely right, in fact the code snippet from my OP was taken > directly from inspect.currentframe. We're intending on using this in > production, and I'm trying to gauge what the implications may be. > > >>Python uses exceptions internally, using StopIteration to terminate the >>iterator in a for: loop. > > > Wow, I was unaware of this. If Python internally uses exceptions, maybe > they aren't as detrimental as I thought. > > That said, I will be judiciously profiling my code and measuring as > much as possible, I just wanted to throw this question out to the NG in > case anyone had done this before (and so I can put off learning the > profiler a little bit longer :) ) > > Thanks all for the replies. > Do note, however, that detecting an exception inside the C framework of the interpreter carries less overhead than detecting an exception in Python itself. That said, exceptions are probably rather more "lightweight" than you might imagine, so benchmarking (the profiler may not be best - have you come across "timeit.py"?) is the best way to go. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie regular expression ?
len wrote:
> I have the following statement and it works fine;
>
> list1 = glob.glob('*.dat')
>
> however I now have an additional requirement the the string must begin
> with
> any form of "UNQ,Unq,unq,..."
>
> as an example if I had the following four files in the directory:
>
> unq123abc.dat
> xy4223.dat
> myfile.dat
> UNQxyc123489-24.dat
>
> only unq123abc.dat and UNQxyc123489-24.dat would be selected
>
> I have read through the documentation and I am now so
> confussedd!!
>
You don't need regular expressions. You want
list1 = glob.glob("[Uu][Nn][Qq]*.dat")
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: how to get any available port
[EMAIL PROTECTED] wrote:
> Apparently, calling bind() with a zero "port" will choose some available port
> number, as demonstrated by this program:
>
> import socket
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.bind(("", 0))
> print s.getsockname()
>
> Here's how it behaved over several runs:
> $ python soc.py
> ('0.0.0.0', 34205)
> $ python soc.py
> ('0.0.0.0', 34206)
> $ python soc.py
> ('0.0.0.0', 34207)
>
> I don't know for sure whether this is standard behavior for sockets, or
> whether
> it's a special behavior of linux.
>
It's been standard behaviour ever since the Berkeley socket interface
was defined, as far as I know.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: dictionary interface
Antoon Pardon wrote:
> Op 2005-10-05, Tom Anderson schreef <[EMAIL PROTECTED]>:
>
>>On Tue, 4 Oct 2005, Robert Kern wrote:
>>
>>
>>>Antoon Pardon wrote:
>>>
>>>
>>>> class Tree:
>>>>
>>>>def __lt__(self, term):
>>>> return set(self.iteritems()) < set(term.iteritems())
>>>>
>>>>def __eq__(self, term):
>>>> return set(self.iteritems()) == set(term.iteritems())
>>>>
>>>>Would this be a correct definition of the desired behaviour?
>>>
>>>No.
>>>
>>>In [1]: {1:2} < {3:4}
>>>Out[1]: True
>>>
>>>In [2]: set({1:2}.iteritems()) < set({3:4}.iteritems())
>>>Out[2]: False
>>>
>>>
>>>>Anyone a reference?
>>>
>>>The function dict_compare in dictobject.c .
>>
>>Well there's a really helpful answer. I'm intrigued, Robert - since you
>>know the real answer to this question, why did you choose to tell the
>>Antoon that he was wrong, not tell him in what way he was wrong, certainly
>>not tell him how to be right, but just tell him to read the source, rather
>>than simply telling him what you knew? Still, at least you told him which
>>file to look in. And if he knows python but not C, or gets lost in the
>>byzantine workings of the interpreter, well, that's his own fault, i
>>guess.
>>
>>So, Antoon, firstly, your implementation of __eq__ is, i believe, correct.
>>
>>Your implementation of __lt__ is, sadly, not. While sets take "<" to mean
>>"is a proper subset of", for dicts, it's a more conventional comparison
>>operation, which constitutes a total ordering over all dicts (so you can
>>sort with it, for example). However, since dicts don't really have a
>>natural total ordering, it is ever so slightly arbitrary.
>>
>>The rules for ordering on dicts are, AFAICT:
>>
>>- If one dict has fewer elements than the other, it's the lesser
>>- If not, find the smallest key for which the two dicts have different
>>values (counting 'not present' as a value)
>>-- If there is no such key, the dicts are equal
>>-- If the key is present in one dict but not the other, the dict in which
>>it is present is the lesser
>>-- Otherwise, the dict in which the value is lesser is itself the lesser
>>
>>In code:
>>
>>def dict_cmp(a, b):
>> diff = cmp(len(a), len(b))
>> if (diff != 0):
>> return diff
>> for key in sorted(set(a.keys() + b.keys())):
>> if (key not in a):
>> return 1
>> if (key not in b):
>> return -1
>> diff = cmp(a[key], b[key])
>> if (diff != 0):
>> return diff
>> return 0
>>
>
>
> Thanks for the explanation, but you somehow give me too much.
>
> I have been searching some more and finally stumbled on this:
>
> http://docs.python.org/ref/comparisons.html
>
> Mappings (dictionaries) compare equal if and only if their sorted
> (key, value) lists compare equal. Outcomes other than equality are
> resolved consistently, but are not otherwise defined.
>
> This seems to imply that the specific method to sort the dictionaries
> is unimported (as long as it is a total ordering). So I can use whatever
> method I want as long as it is achieves this.
>
> But that is contradicted by the unittest. If you have a unittest for
> comparing dictionaries, that means comparing dictionaries has a
> testable characteristic and thus is further defined.
>
> So I don't need a full implementation of dictionary comparison,
> I need to know in how far such a comparison is defined and
> what I can choose.
>
The dict unit tests are probably trying to ensure that the dictionary
ordering doesn't change from version to version, which is probably a
good idea in case someone (foolishly?) deciess to rely on it.
I can't help wondering, though, under what conditions it actually makes
sense to compare two dictionaries for anything other than equality.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Confused with module and .py files
Iyer, Prasad C wrote: > Actually I am bit confused between the modules and .py file > How do I differentiate between the 2. > > For example > I have a file import1.py, import2.py file > Which has few functions and classes > And if I have a class with same name "BaseClass" in both the file > > How would I use it if I declare it as given below in my 3rd class > > from import1.py import * > from import2.py import * > You can't do that. The "from module import *" mechanism explicitly defines names in the importing module's namespace, so if you use this technique to import two modules that define the same name you will inevitably find that the second import overwrites the duplicate name imported by the first import. Note also that the ".py" should not be included in the import statement - the interpreter finds the appropriate code from the module name, so you should anyway be doing something like from import2 import * from import2 import * It would be much better, though, to write: import import1 import import2 Then you can refer to import1.BaseClass and import2.baseClass without getting any naming conflicts. In general the "from module import *" form should only be used under specific conditions, which we needn't discuss here now. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: "no variable or argument declarations are necessary."
Brian Quinlan wrote: > Paul Rubin wrote: > >>Brian Quinlan <[EMAIL PROTECTED]> writes: >> >> >>>Have those of you who think that the lack of required declarations in >>>Python is a huge weakness given any thought to the impact that adding >>>them would have on the rest of the language? I can't imagine how any >>>language with required declarations could even remotely resemble >>>Python. >> >> >>Python already has a "global" declaration; > > > Which is evaluated at runtime, does not require that the actual global > variable be pre-existing, and does not create the global variable if not > actually assigned. I think that is pretty different than your proposal > semantics. > I believe that "global" is the one Python statement that isn't actually executable, and simply conditions the code generated during compilation (to bytecode). Hard to see why someone would want to use a global declaration unless they were intending to assign to it, given the sematnics of access. > [...] regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary interface
Antoon Pardon wrote:
> Op 2005-10-05, Steve Holden schreef <[EMAIL PROTECTED]>:
[...]
>
> Anyway, I have searched the source of the test for all testing
> with regards to < and after some browsing back and fore it seems
> it all boils down to the following two tests.
>
>self.assert_(not {} < {})
>self.assert_(not {1: 2} < {1L: 2L})
>
So there isn't much to do, then! That's good. Seems you can pretty much
choose your own ordering.
It would seem sensible to test a third case, namely
self.assert_(not {1L: 2L} < {1: 2})
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: bug or feature?
beza1e1 wrote:
> Coming back from a bug hunt, i am not sure what to think of this python
> behaviour. Here is a demo program:
>
> class A:
>def __init__(self, lst=[]):
> self.lst = lst
>
> a = A()
> b = A()
> b.lst.append("hallo")
> print a.lst # output: ["hallo"]
>
> The point seems to be, that lst=[] creates a class attribute (correct
> name?), which is shared by all instances of A. So a.lst ist the same
> object as b.lst, despite the fact, that object a is different to object
> b.
>
Interestingly I couldn't find this in the FAQ, though it *is* a
frequently-asked question [note: my not finding it doesn't guarantee
it's not there]. The nearest I could get was in
http://www.python.org/doc/faq/programming.html#my-program-is-too-slow-how-do-i-speed-it-up
which says:
"""Default arguments can be used to determine values once, at compile
time instead of at run time."""
The point is that the value of the keyword argument is determined when
the def statement is executed (which is to say when the function body is
being bound to its name).
If the default argument is (a reference to) a mutable object (such as a
list instance) then if one call to the function modifies that mutable
object, subsequent calls see the mutated instance as the default value.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python, Mysql, insert NULL
Python_it wrote:
> I know how to insert values in a database.
> That's not my problem!
> My problem is how i insert NULL values in de mysql-database.
So you *don't* know how to insert values in a database: as Laszlo wrote,
you might be best using parameterized queries.
> None is een object in Python and NULL not.
> None is not converted to NULL?
> Table shows None and not NULL!
>
If that's the case then perhaps the field isn't nullable? Or perhaps you
mader a mistake ...
Pay careful attention to the difference between
curs.execute(sql, data)
and
curs.execute(sql % data)
Let's suppose I create a MySQL table:
mysql> create table t1(
-> f1 varchar(10) primary key,
-> f2 varchar(20)
-> );
Query OK, 0 rows affected (0.44 sec)
Let's try and create a few records in Python:
>>> conn = db.connect("localhost", db="temp", user="root")
>>> curs = conn.cursor()
There's the obvious way:
>>> curs.execute("INSERT INTO t1 (f1, f2) VALUES ('row1', NULL)")
1L
Then there's the parameterised way:
>>> curs.execute("INSERT INTO t1 (f1, f2) VALUES (%s, %s)", ("row2", None))
1L
This is to be preferred because the data tuple can contain general
expressions, so you just have to ensure that the name bound to the
column value contains None rather than some string.
Then there's the wrong way"
>>> curs.execute("INSERT INTO t1 (f1, f2) VALUES ('%s', '%s')" %
("row3", None))
1L
>>>
This really executes
INSERT INTO t1 (f1, f2) VALUES ('row3', 'None')
What does MySQL have to say about all this?
mysql> select * from t1;
+--+--+
| f1 | f2 |
+--+--+
| row1 | NULL |
| row2 | NULL |
| row3 | None |
+--+--+
3 rows in set (0.00 sec)
And the moral of the story is to believe someone is actually trying to
help you unless you have definite evidence to the contrary. Otherwise
people will pretty soon stop trying to help you ...
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: bug or feature?
beza1e1:
> Coming back from a bug hunt, i am not sure what to think of this python
> behaviour. Here is a demo program:
>
> class A:
>def __init__(self, lst=[]):
> self.lst = lst
>
> a = A()
> b = A()
> b.lst.append("hallo")
> print a.lst # output: ["hallo"]
>
> The point seems to be, that lst=[] creates a class attribute (correct
> name?), which is shared by all instances of A. So a.lst ist the same
> object as b.lst, despite the fact, that object a is different to object
> b.
>
Fredrik Lundh wrote:
> Steve Holden wrote:
>
>
>>Interestingly I couldn't find this in the FAQ, though it *is* a
>>frequently-asked question [note: my not finding it doesn't guarantee
>>it's not there].
>
>
> it's there:
>
>
> http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects
>
> (maybe "default values" should be changed to "default argument values")
>
I couldn't believe it wasn't, but you're right: it should be easier to
find, and a change of wording may do that.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: bug or feature?
Ben Sizer wrote: > Fredrik Lundh wrote: > > >>it's also mentioned in chapter 4 of the tutorial: >> >>http://docs.python.org/tut/node6.html#SECTION00671 >> >> "*Important warning*: The default value is evaluated only once. This >>makes a difference when the default is a mutable object such as a list, >>dictionary, or instances of most classes. " > > > Perhaps it would be a good idea if Python actually raised a warning > (SyntaxWarning?) if you use an unnamed list or dict as a default > argument. This would doubtless help quite a few beginners. And for > people who really do want that behaviour, working around the warning > should involve minimal extra code, with extra clarity thrown in for > free. > This would have to be extended to any mutable object. How does the compiler know which objects are mutable? This would not be a good change. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: change a value to NULL?
Brett Hoerner wrote: > I'm not sure what you mean, really, do you need an official Python > "Null" value? Try None? > > In [6]: myCells = ['Mary', 'Bob', None, 'Joe'] > > In [7]: for cell in myCells: >...: if cell: >...: print cell >...: else: >...: print "NULL VALUE" >...: > Mary > Bob > NULL VALUE > Joe > > -- > > As far as having a Null value to put into the DB, most (SQL) DB's I've > used have a specific SQL command like "INSERT INTO ROW VALUE NULL()", > kind of like the SQL DATE(), etc. I'm really rusty on my syntax etc > right now btw so don't copy and paste that. :P > And besides that, Excel is a spreadsheet not a database :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: updating local()
Flavio wrote:
> Hi,
>
> I heard time and again that you are not _supposed_ to update the
> locals dictionary.
>
> Can anyone tell me why, if the following code works, I should not do
> this?
>
> #
> # Extending Local namespace
> #
>
> def fun(a=1,b=2,**args):
>
> print 'locals:',locals()
> locals().update(args)
> print locals()
>
> e = {'s':3,'e':4}
> fun(k=10,v=32,**e)
>
Because it depends on the current implementation and isn't guaranteeed
to work in the future.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Replacing utf-8 characters
Unknown wrote:
> For example this is what I am trying to do that is not working.
>
> The contents of link is the reuters web page, containing
>
> "/news/newsArticle.aspx?type=businessNews&storyID=2005-10-05T151245Z_01_HO548006_RTRUKOC_0_UK-AIRLINES-BA.xml"
>
> link = link.replace('&','&')
>
> But if I now view the the contents link it shows it the same as when it
> was assigned.
>
>
>
>
> Richard Brodie wrote:
>
>>"Mike" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
>>
>>
>>
>>>However when I pull it into python the URL ends up looking like this
>>>(notice the & instead of just & in the URL)
>>>
>>>Any ideas?
>>
>>
>>Some code would be helpful: the "&" is in the page source to start
>>with (which is as it ought to be). What are you using to parse the HTML?
>>
>>
You must be doing *something* wrong:
>>> link =
"/news/newsArticle.aspx?type=businessNews&storyID=2005-10-05T151245Z_01_HO548006_RTRUKOC_0_UK-AIRLINES-BA.xml"
>>> link = link.replace('&','&')
>>> link
'/news/newsArticle.aspx?type=businessNews&storyID=2005-10-05T151245Z_01_HO548006_RTRUKOC_0_UK-AIRLINES-BA.xml'
>>>
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Class methods
Gerrit Holl wrote: > Laszlo Zsolt Nagy wrote: > >>>Oh man, it has been a long time I have read such an disturbing question. >>> >>>RTMF here: http://docs.python.org/lib/built-in-funcs.html#l2h-14 >>> >>> >> >>I feel I was a bit harsh. > > > Of course, those posts do keep the Google count for the famous > four-letter-abbreviation down (-; > > Gerrit. > I'd been thinking it was about time the mucking fanual was updated. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python, Mysql, insert NULL
Thomas Bartkus wrote: [...] > > Others here have pointed out that the Python keyword "None" is converted to > "Null" when passed to MySQL. I don't quite understand this and don't really > care. If I have a Python variable that has a value None, and I want to > transmit this to MySQL as Null - I would: > >if somevar == None: >StrToConcatenateIntoSqlStatement = "Null" >else: >StrToConcatenateIntoSqlStatement = somevar > > All of which assumes, of course, that the field you are targeting will > accept a Null value. > Thomas Bartkus > > If you don't understand parameterized SQL queries you would do well to refrain from offering database advice :-) Presumably you always check whether StrToConcatenateIntoSqlStatement contains no apostrophes before you actually construct the SQL? Can we say "SQL injection exploit"? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: updating local()
Richard Brodie wrote: > "Flavio" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > >>Now what would you do if you wanted to pass a lot of variables (like a >>thousand) to a function and did not wanted the declare them in the >>function header? > > > I'd lie down until I felt better. > > Or alternatively put them in a 1,000-element list. Just as a matter of interest, what on *earth* is the use case for a function with a thousand arguments? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with chaos math extensions.
Brandon K wrote: > In case you missed it, I said I have windows XP. Windows XP > pre-compiled python binaries are built on VS .NET 2003. In order to > build extensions, you need the compiler the interpreter was built on, or > at least that is what is reported to me by calling setup.py. If I was > using linux, which I currently am not, it'd be a different story. > Additionally, GCC isn't available for windows XP, only MinGW, the port, > and I don't know that much about it to use it running on a Windows > platform. Furthermore, I was asking for help on an extension, not an > economical question about my programming environment. > > Thanks > >> >>On Oct 4, 2005, at 10:25 PM, Brandon Keown wrote: >> >>> I have programmed a fractal generator (Julia Set/Mandelbrot Set) >>>in python in the past, and have had good success, but it would run so >>>slowly because of the overhead involved with the calculation. I >>>recently purchased VS .NET 2003 (Win XP, precomp binary of python >>>2.4.2rc1) to make my own extensions. >> >>Why did you need to purchase anything when gcc is available for free? >> Since gcc isn't an option, the logical way to proceed would be to do what others have done and install the Microsoft Toolkit compiler, available from their web site for the outrageous price of nothing. I can vouch that it really does compile extensions for Python 2.4 on Windows, having done that myself. See http://www.vrplumber.com/programming/mstoolkit/ regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: "no variable or argument declarations are necessary."
Ron Adam wrote: > Fredrik Lundh wrote: > > >>Ron Adam wrote: >> >> >> >>>Is there a way to conditionally decorate? For example if __debug__ is >>>True, but not if it's False? I think I've asked this question before. (?) >> >> >>the decorator is a callable, so you can simply do, say >> >>from somewhere import debugdecorator >> >>if not __debug__: >>debugdecorator = lambda x: x > > > Ah... thanks. > > I suppose after(if) lambda is removed it would need to be. > > def nulldecorator(f): > return f > > if not __debug__: >debugdecorator = nulldecorator > It would be easier to write if not __debug__: def debugdecorator(f): return f regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: where to find information about errors/exceptions in socket.py
[EMAIL PROTECTED] wrote: > Version of python: 2.4 > O/S: Win2K > > I will be writing some python scripts to do some client-side > programming that involves socket.py. I expect that I will be making > calls to the following methods/functions: > > connect_ex() > setsockopt() > sendall() > recv() > close() > > Where can one find information about whether the functions/methods > above return error codes that provide some indication as to whether the > function/method succeeded? Is there an exception class for handling > exceptions raised in socket.py? If so, where can one find information > about it? > > I consulted the docstrings and didn't find much about return codes or > exception classes. Also looked at the Lutz "Programming Python" > text...it devotes several pages to socket programming, but I didn't > observe much with regard to error/exception handling. > I'd suggest reading the documentation myself: http://docs.python.org/lib/module-socket.html regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: non descriptive error
Timothy Smith wrote: > i try to run my app and i get this > > %python DutyShift.py > error > > > thats it. thats the error. mya pp was previously working, and i did make > some fairly large changes to it, but i'd expect a more descriptive > message then just "error". anyidea where i need to start looking? I would look inside *your* program! I don't ever remember Python producing any message so terse and unhelpful. A way to check this would be to run python interactively and enter the statement import DutyShift though this won't necessarily run all the logic that gets run by your command. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: "no variable or argument declarations are necessary."
Antoon Pardon wrote: > Op 2005-10-06, Diez B. Roggisch schreef <[EMAIL PROTECTED]>: > >>>Suppose we have a typesystem which has the type ANY, which would mean >>>such an object could be any type. You could then have homogenous lists >>>in the sense that all elements should be of the same declared type and >>>at the same time mix all kind of type in a particular list, just >>>as python does. >> >>The you have JAVA Object or C void*. Which cause all kinds of runtime >>troubles because they essentially circumvene the typechecking! > > > Why do you call this a JAVA Object or C void*? Why don't you call > it a PYTHON object. It is this kind of reaction that IMO tells most > opponents can't think outside the typesystems they have already > seen and project the problems with those type systems on what > would happen with python should it acquire a type system. > [sigh]. No, it's just you being you. Diez' intention seemed fairly clear to me: he is pointing out that strongly-typed systems invariably fall back on generic declarations when they want to allow objects of any type (which, it seems to me, is what you were proposing as well). In other words, you want Python to be strongly-typed, but sometimes you want to allow a reference to be to any object whatsoever. In which case you can't possibly do any sensible type-checking on it, so this new Python+ or whatever you want to call it will suffer from the same shortcomings that C++ and java do, which is to say type checking can't possibly do anything useful when the acceptable type of a reference is specified as ANY. > >>>So how would this limit python. >> >>The limitation is that in static languages I must _know_ what type to >>cast such an ANY, before calling anything on it. Otherwise its useless. >> >> >>>>even though ususally the contents of a list >>>>share some common behaviour. And that exactly is the key point here: in >>>>a statically typed world, that common behaviour must have been extracted >>>>and made explicit. >>> >>> >>>Would my suggestion be classified as a statically typed world? >> >>See above. > > > Your answer tells more about you then about my suggestion. > Damn, I've been keeping away from this thread lest my exasperation lead me to inappropriate behaviour. Is there any statement that you *won't* argue about? leaving-the-(hopefully)-last-word-to-you-ly y'rs - steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: When someone from Britain speaks, Americans hear a "British accent"...
DaveM wrote: > On Fri, 07 Oct 2005 00:33:43 -, Grant Edwards <[EMAIL PROTECTED]> wrote: [...] > >>For example: In British English one uses a plural verb when the >>subject consists of more than one person. Sports teams, >>government departments, states, corporations etc. are >>grammatically plural. In American, the verb agrees with the >>word that is the subject, not how many people are denoted by >>that word. >> >>In sports (thats "sport" for you Brits): > OK, so how do you account for the execresence "That will give you a savings of 20%", which usage is common in America? There aren't any universal rules, except possibly "British people speak English while Americans don't". Nowadays relatively few people on either side of the Atlantic even know the difference between a collective noun and a plural, so there's little hope of them being able to correctly apply any rule there might be (and yes, I split that infinitive just to annoy any pedants who may be reading). > > Yes. > > >>American: Minnesota is behind 7-0. The Vikings are behind 7-0. >> British: Minnesota are behind 7-0. The Vikings are behind 7-0. > > > True. > > >>In politics: > > >> American: The war department has decided to cancel the program. >> British: The war department have decided to cancel the program. > > > Not sure about this one. They may be used interchangeably as neither strikes > me as sounding "odd". > Then again, there's room for infinite disagreement about these topics. I mentioned a while ago that I disliked the English on a bumper sticker I liked, which read "Some village in Texas is missing their idiot". Several people defended this, saying that a village could use the plural possessive "their". I personally found it odd (and essentially non-grammatical) not because either the singular or plural forms should be mandated but because this one manages to mix them up. So "Some village in Texas are missing their idiot" would be better (though it sounds like the kind of thing only the idiot alluded to would say), while my preferred choice would be "Some village in Texas is missing its idiot". Then again, what can you expect from a country whose leader pronounces "nuclear" as though it were spelled "nucular"? I suppose it's only a matter of time before they change the spelling just like they did with "aluminium". tongue-in-cheek-ly y'rs - steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: "no variable or argument declarations are necessary."
Paul Rubin wrote: > Steve Holden <[EMAIL PROTECTED]> writes: > >>In other words, you want Python to be strongly-typed, but sometimes >>you want to allow a reference to be to any object whatsoever. In which >>case you can't possibly do any sensible type-checking on it, so this >>new Python+ or whatever you want to call it will suffer from the same >>shortcomings that C++ and java do, which is to say type checking can't >>possibly do anything useful when the acceptable type of a reference is >>specified as ANY. > > > Let's see if I understand what you're saying: > > C and Java: you get useful type checking except when you declare > a reference as type ANY. This is a shortcoming compared to: > > Python: where you get no useful type checking at all. > > That is not very convincing logic. As we say in Yorkshire, "There's none as thick as them that wants to be". Let's try to get this in context. Antoon: > Suppose we have a typesystem which has the type ANY, which would mean > such an object could be any type. You could then have homogenous lists > in the sense that all elements should be of the same declared type and > at the same time mix all kind of type in a particular list, just > as python does. Diez: > The you have JAVA Object or C void*. Which cause all kinds of runtime > troubles because they essentially circumvene the typechecking! Antoon: > Why do you call this a JAVA Object or C void*? Why don't you call > it a PYTHON object. It is this kind of reaction that IMO tells most > opponents can't think outside the typesystems they have already > seen and project the problems with those type systems on what > would happen with python should it acquire a type system. Me: > Diez' intention seemed fairly clear > to me: he is pointing out that strongly-typed systems invariably fall > back on generic declarations when they want to allow objects of any type > (which, it seems to me, is what you were proposing as well). You: > C and Java: you get useful type checking except when you declare > a reference as type ANY. This is a shortcoming compared to: > > Python: where you get no useful type checking at all. > The points that have repeatedly been made are: 1. That even the strict typings required by languages like Java and C++ actually end up getting in the way when the pragmatic requirements of real-world problems have to be taken into account. 2. That the benefits of declarations are overstated by many of their proponents. 3. That Python as it is today allows the dynamic creation of names, which are therefore inherently not available for declaration. On existing evidence it's extremely unlikely that this post will end the thread, but I certainly wish *something* would. Unfortunately I seem to have become part of the problem in that respect :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: When someone from Britain speaks, Americans hear a "British accent"...
Richie Hindle wrote: > [Steve] > >>and yes, I split that infinitive just to >>annoy any pedants who may be reading > > > [Steven] > >>*Real* pedants will know that English is not Latin, does not follow the >>grammatical rules of Latin, and that just because split infinitives are >>impossible -- not forbidden, impossible -- in Latin is no reason to forbid >>them in English. > > > Your previous post to this thread was chock-full of split nominatives: "The > Hollywood voice", "the specific regional accent", "the English-speaking > world", "the original French". And you call yourself a grammarian. > I am presuming this post was meant to be a joke? No smileys, though, so you force us to make up our own minds. Or is "the green tomato" also unacceptable? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: "no variable or argument declarations are necessary."
Christophe wrote: > Fredrik Lundh a écrit : > >>"Christophe" wrote: >> >> >> >>>It's more of a "Nearly too late" type checking I would say. Not that I >>>complain but it would be great if there were also some automatic type >>>checking to catch a few errors as soon as possible. >> >> >>use assert as the soonest possible point. implementing "type gates" is >>trivial, if you think you need them. > > > Still, it would be great if there were also some automatic type checking > in place. Using assert is hardly automatic and non intrusive. > > I mean, why not ? Why does the compiler let me do that when you know > perfectly that that code is incorrect : > def f(): > return "a" + 5 > > Of course the system can't be perfect but it doesn't need to be. It > doesn't need to constrain us in any way but if it can detect some errors > early, then it is worth it. While this is a perfectly acceptable feature request, we should remember that Python is developed and maintained by a volunteer team. Do we *really* want them spending their time adding "features" like this? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python interpreter bug
[EMAIL PROTECTED] wrote: > Hello, > > I came accross what i think is a serious bug in the python interpreter. > > Membership testing seems not to work for list of objects when these > objects have a user-defined __cmp__ method. > It is present in Python 2.3 and 2.4. I don't know about other versions. > The following code illustrates the bug: > from random import choice > class OBJ: > def __init__(self,identifier): > self.id=identifier > self.allocated=0 > def __cmp__(self,other): > return cmp(other.allocated,self.allocated) > mylist=[OBJ(i) for i in range(20)] > excluded=[obj for obj in mylist if obj.id>choice(range(20))] > for obj in mylist: > if obj in excluded: > assert obj.id in [objt.id for objt in excluded] > continue > I presume you just put the "continue" in there for fun? >>> for obj in mylist: ... print obj in excluded ... True True True True True True True True True True True True True True True True True True True True >>> OBJ(0) == OBJ(1) True > Running the above snippet will trigger the assert. The culprit seems to > be the __cmp__ method which sorts on a key with constant value. Well indeed. As far as I can see your objects will all test equal. Did you mean the __cmp__ method to return cmp(other.id, self.id)? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python interpreter bug
[EMAIL PROTECTED] wrote: > Sorry Fredrik but I don't understand. Just comment out the assert and > you have different results depending on whether an unrelated sort > function is defined. > This seems weird to me ! > Perhaps you don't understand what's going on. The test obj in excluded is succeeding for all your objects because all instances of the OBJ class compare equal, and so the assert is failing for the ones that don;t actually appear in the "excluded" list. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: When someone from Britain speaks, Americans hear a "British accent"...
Grant Edwards wrote: > On 2005-10-07, Steve Holden <[EMAIL PROTECTED]> wrote: [...] >>Then again, what can you expect from a country whose leader >>pronounces "nuclear" as though it were spelled "nucular"? > > > Don't get me started on _that_ one. I found it particularly > horrifying that Jimmy Carter pronounced it "nucular" -- he had > studied nuclear engineering at the naval acadamy, and should at > least be able pronounce the word. > > >>I suppose it's only a matter of time before they change the >>spelling just like they did with "aluminium". > > > :) > One can only hope that Bush has been control of the nuclear weapons rather than the nuclear ones. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python interpreter bug
[EMAIL PROTECTED] wrote:
> I understand this, Steve.
> I thought the _cmp_ method was a helper for sorting purposes. Why is it
> that a membership test needs to call the __cmp__ method?
Can you suggest another way to test for set membership, given that
instances aren't singletons? The only way to do so is to iterate over
the list, asking "are these the same instance", followed (in the case of
a "no" answer) by "are these two instances equal?".
Consider:
>>> a = {1:'one'}
>>> b = {2:'two'}
>>> c = {1:'one'}
>>> a is c
False
>>> a in [b, c]
True
>>>
What would you have Python do differently in these circumstances?
> If this isn't a bug, it is at least unexpected in my eyes.
Ah, right. So it's your eyes that need fixing! :-)
> Maybe a candidate for inclusion in the FAQ?
> Thank you for answering
A pleasure.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python interpreter bug
[EMAIL PROTECTED] wrote:
>>Steve Holden wrote:
>>Consider:
>
>
> >>> a = {1:'one'}
> >>> b = {2:'two'}
> >>> c = {1:'one'}
> >>> a is c
> False
> >>> a in [b, c]
> True
> >>>
>
>
>>What would you have Python do differently in these circumstances?
>
>
> You mean: What i would do i if i was the benevolent dictator ?
> I would make a distinction between mutables and immutables. Immutables
> would test for equality and mutables would test for identity.
Which is exactly the wrong way round.
> Membership testing for objects is a very common use case which is
> totally unrelated to their being sorted according to a key.
> I am no expert on languages so i could be wrong. Don't hesitate to
> correct me.
> Alain
>
It's not worth bothering - just work with Python how it is, and enjoy
the language!
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: When someone from Britain speaks, Americans hear a "British accent"...
Terry Hancock wrote: > On Friday 07 October 2005 03:01 am, Steve Holden wrote: > >>OK, so how do you account for the execresence "That will give you a >>savings of 20%", which usage is common in America? > > > In America, anyway, "savings" is a collective abstract noun > (like "physics" or "mechanics"), there's no such > noun as "saving" (that's present participle of "to save" > only). How did you expect that sentence to be rendered? > Why is it an "execresence"? > Precisely because there *is* such a thing as a saving. If I buy a $100 gumball for $80 I have achieved a saving of 20%. > By the way, dict.org doesn't think "execresence" is a word, > although I interpret the neologism as meaning something like > "execrable utterance": > > dict.org said: > >>No definitions found for 'execresence'! > > Nonetheless, Google finds 369 hits for "execrescence" and 67 for "execresence". My Complete Oxford is still packed in a cardboard box, so I can't offer any more convincing evidence. If there isn't such a word, all I can say is there *ought* to be :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: When someone from Britain speaks, Americans hear a "British accent"...
Terry Hancock wrote: > On Friday 07 October 2005 03:44 pm, Steve Holden wrote: > >>Precisely because there *is* such a thing as a saving. If I buy a $100 >>gumball for $80 I have achieved a saving of 20%. > > > Nope, that's incorrect American. ;-) > > You can say "I bought a $100 gumball for $80, saving 20%," or > "If I buy a $100 gumball for $80, I have achieved a savings of 20%." > > (Although, you lose points for style with "achieved", and those > are awfully expensive gumballs). ;-) > I must have been working at NASA at the time; they are well known for embiggening prices. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: When someone from Britain speaks, Americans hear a "Britishaccent"...
Duncan Smith wrote: > Rocco Moretti wrote: [...] > > So English is spoken only in the South East of England, except London? > I think you should also disbar the queen (unless she's already > classified as a Londoner), due to her apparent confusion between the 1st > person singular and 1st person plural :-). > There are special rules for the monarchs, who are expected to refer to themselves in the first person plural. Oscar Wilde understood this. When he boasted that he could speak extempore for a minute on any subject of a challenger's choosing someone shouted "The Queen", to which he replied "The Queen, sir, is not a subject". regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: When someone from Britain speaks, Americans hear a "British accent"...
Steve Horsley wrote: [...] > > The one that always makes me grit my teeth is "You have got to, > don't you?". Well no, I do NOT got to, actually. Shudder! > Shouldn't that be "I don't have to got to"? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: What about letting x.( ... ? ... ) be equivalent to ( ... x ... )
al wrote: > Fredrik Lundh a écrit : > >>if you have a fear of introducing new local variables, you have problems >>that cannot be solved by syntax. > > > Dear Fredrik, > > I have read the original messages on fr.comp.lang.python, and I don't > understand your answer. > > It is not about a fear of introducing new local variables, but for me it > is an elegant solution to a common problem, to avoid creation of useless > variables (what in french we call "variables muettes", like indexes in > loops who are just there because some langages level is too low). > > It also avoid the increase of parenthesis depth, and so the readability > is enhanced. > > And it solve a problem that in all object oriented langages, a method > that process 2 or more different classes of objets belongs just to one > of those classes. > > All this kind of problems appears often to me (and in different > langages), and contrarily to you, I'm very impressed by the compacity > and elegance of the solution. I think it would be nice if implemented in > different langages (because it breaks nothing), and firstly Python. > > Best regards, > Al > > PS : sorry for my approximative english, but my natural langage is french. It seems to me that what you proposed was a "solution", that seems obvious only to you, to a problem perceived only by you. I am afraid you would have to work rather harder to persuade me that there is a problem, let alone that you have found the solution to it. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about StringIO
Frank Millman wrote: > Hi all > > I understand that StringIO creates a file-like object in memory. > > Is it possible to invoke another program, using os.system() or > os.popen(), and use the < redirect operator, so that the other program > reads my StringIO object as its input? > > I will provide more details if required, but hopefully this is enough > for a simple yes or no answer, and if so, how. > > BTW, I have tried using popen2() and passing my data via stdin, but the > other program (psql) does not react well to this - again, I will give > more info if necessary. > Unfortunately the StringIO module only creates instances inside the process they are called: these objects have no existence to the operating system or to other processes, and so can't be used for inter-process communication. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python on the Power PC
Peter Milliken wrote:
> Hi,
>
> I (think I have :-)) installed Python on my Pocket PC (obtained from
> http://fore.validus.com/~kashtan/).
>
> There were Tkinter binaries with it so I installed those as well. When I
> attempt to run the most simplistic of python programs using Tkinter, I get
> an error message stating that Python can't find any tkinter module.
>
> Any ideas what I have done wrong anybody?
>
> Thanks
> Peter
>
> import Tkinter
>
> if __name__ == '__main__':
> root = Tkinter.Tk()
>
> root.title('Hello World?')
>
> root.mainloop()
>
>
Are you sure it didn't say "_tkinter" was what it couldn't find?
On my Windows system the Tkinter.py file tries to import an extension
(compiled C) module called _tkinter (provided as _tkinter.dll) that
provides the low-level Tkinter functionality. It's likely that that's
missing.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: One last thing about SocketServer
rbt wrote: > I've read more about sockets and now, I have a better understanding of > them. However, I still have a few SocketServer module questions: > > When used with SocketServer how exactly does socket.setdefaulttimeout() > work? Does it timeout the initial connect request to the socket server > or does it timeout the session between the connecting client socket and > the client socket the server generated to handle the incoming request? > setdefaulttimeout() simply sets the default timeout for all sockets created thereafter. This timeout applies to any socket operation, I believe (though I am unsure about "accept()"). > Also, since the *only* thing a 'socket server' does is to create 'client > sockets' to handle requests, how do I use socket object features on > these generated clients to manage and/or monitor them? > When the accept() call on a socket returns a tuple(socket, address): the first element of the returned tuple is the socket you use to communicate with that particular client (in other words, it represents the server end of the connection that's just been accept()ed). So you can read and write that socket to communicate with that client over that specific connection. Of course, if you don't use either the ThreadingMixIn or the ForkingMixIn then communication with one client will effectively stop you form accept()ing any more connections, hence the need for the mix-in classes. > The SocketServer module is great, but it seems to hide too many details > of what it's up to! > Well, of course, that is what abstractions are for! You should bear in mind that SocketServer isn't necessarily the most efficient or effective way to handle multiple clients concurrently, but it's very convenient when you are just getting started. Later you might want to consider an asyncore-based approach, or perhaps using the Twisted package. Both of these solutions are a little more robust for production code. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Default argument to __init__
[EMAIL PROTECTED] wrote:
> Hi All:
>
> Here's a piece of Python code and it's output. The output that Python
> shows is not as per my expectation. Hope someone can explain to me this
> behaviour:
>
> [code]
> class MyClass:
> def __init__(self, myarr=[]):
> self.myarr = myarr
>
> myobj1 = MyClass()
> myobj2 = MyClass()
>
> myobj1.myarr += [1,2,3]
>
> myobj2.myarr += [4,5,6]
>
> print myobj1.myarr
> print myobj2.myarr
> [/code]
>
> The output is:
> [1, 2, 3, 4, 5, 6]
> [1, 2, 3, 4, 5, 6]
>
> Why do myobj1.myarr and myobj2.myarr point to the same list? The
> default value to __init__ for the myarr argument is [], so I expect
> that every time an object of MyClass is created, a new empty list is
> created and assigned to myarr, but it seems that the same empty list
> object is assigned to myarr on every invocation of MyClass.__init__
>
> It this behaviour by design? If so, what is the reason, as the
> behaviour I expect seems pretty logical.
>
The default value of the keyword argument is evaluated once, at function
declaration time. The idiom usually used to avoid this gotcha is:
def __init__(self, myarr=None):
if myarr is None:
myarr = []
This ensures each call with the default myarr gets its own list.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Comparing lists
Christian Stapfer wrote: > "George Sakkis" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>"Christian Stapfer" <[EMAIL PROTECTED]> wrote: >> >> >>><[EMAIL PROTECTED]> wrote: >>> >>>>try to use set. >>> >>>Sorting the two lists and then extracting >>>A-B, B-A, A|B, A & B and A ^ B in one single >>>pass seems to me very likely to be much faster >>>for large lists. >> >>Why don't you implement it, test it and time it >>to be more convincing about your intuition ? > > > The problem is in the generation of the test data. > Even merely generating a set of (suitably "average", > "random", and suitably "worst case") datasets might > turn out to be a major undertaking. > If the documentation stated the order-of-magnitude > behavior of those basic operations up front, then > I (and *anyone* else who ever wanted to use those > operations on large lists / large sets) could do > a quick order-of-magnitude estimation of how > a certain program design will behave, performance > wise. > *Experimenting* is not necessarily as easy to > do as you seem to believe. How do you, for example, > hit upon the worst-case behavior with your test > data? - Without knowing *anything* about the > implementation it might a matter sheer luck. > If you *know* something about the implementation > then, of course, you might be able to figure it > out. (But note that if you know *that* much about > the implementation, you usually have an order-of- > magnitude estimate anyway and don't need to do > *any* experimenting in order to answer my question.) > You are, of course, either assuming that there's a single implementation of Python, or that all implementations have the same behaviour. Or alternatively you are asking all implementers to do what you seem to consider so difficult (i.e. identify worst-case scenarios and then estimate order-of-magnitude behaviour for them). Test results with known test data are relatively easy to extrapolate from, and if your test data are reasonably representative of live data then so will your performance estimates. Anyway, aren't you more interested in average behaviour than worst-case? Most people are. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
