Re: attaching names to subexpressions
On Sun, 28 Oct 2012 01:57:45 -0400, Devin Jeanpierre wrote: > We have a problem, and two solutions. Solution 1 has downside A, and > solution 2 has downside B. If he complains about downside A, you say, > well, use solution 2. If he complains about downside B, you say, well, > use solution 1. > > What if he wants to avoid both downsides A and B? What solution does he > use then? "I want to have my cake, and eat it too." Every solution has some downside. Just because no other solution is perfect (whatever that means!) doesn't mean we must keep adding more and more ways to solve the same problem into a language. The proposed solution, assignment as an expression, has multiple downsides: * Since it doesn't actually exist yet, you can't use it. It's not a solution until *at least* Python 3.4. The first alpha is scheduled in August 2013, the first stable release is not due until end of Feb 2014. So you have to wait 16 months before you can use this in production code. * If you support multiple versions of Python, you can't use this. Assuming, conservatively, that you need to support the current version of Python plus two older versions, that means you can't use this until Python 3.6, which is probably due out in 2017. "Wait five years" is hardly a solution for code you are writing today. * You can't just wave a magic wand and have Python support this new syntax. Somebody has to write a PEP and get it approved; somebody has to modify the parser, write documentation for it, write tests, ensure it doesn't break anything. * And once it does exist, it adds to the complexity of Python the language. People learning the language have one more feature to learn. Every time you write a loop, you have one more decision to make -- should I write this loop using A, or B, or C? * Like all features, it is open to abuse. Does the benefit from the good uses outweigh the cost of the abuses? Given that I think the benefit is at best minor, I doubt that it will outweigh the harm to readability and maintainability when it is abused. * What unexpected problems is this going to cause? I don't know -- but that's the point, if they exist they will be *unexpected*. Python 3 introduced the literal ... as an alias for Ellipsis. Nobody realised that this would have consequences for doctests until somebody reported a problem, by which time it was too late. All these downsides make the barrier to entry for new syntax very high. Python is a 20 year old mature language. Most, perhaps all, of the low- hanging fruit syntax-wise has been picked. Don't be surprised when there is opposition to adding new syntax. With very few exceptions, new syntax has real costs and little or questionable benefit. Adding syntax is not free, it costs somebody time and effort. Unless the syntax is a big win, that time and effort is probably better put into fixing bugs. There is a great shortage of time and manpower for the Python developers, there is a list of open bugs half a mile long. Every minute spent adding new syntax for some minor benefit is time that could be fixing bugs that cause actual problems with real-world code, not just to satisfy some minor concern about DRY purity. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: attaching names to subexpressions
On 10/28/2012 06:57 AM, Devin Jeanpierre wrote: line = function(x, y, z) >while line: > do something with(line) > line = function(x, y, z) How about: line = True while line: line = function(x, y, z) do something with(line) ? Frederic -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with xml parsing (python 3.3)
janni...@gmail.com writes: > I am new to Python and have a problem with the behaviour of the xml parser. > Assume we have this xml document: > > > > > Title of the first book. > > > > Title of the second book. > > > > > If I now check for the text of all 'entry' nodes, the text for the node with > the empty element isn't shown > > > > import xml.etree.ElementTree as ET > tree = ET.ElementTree(file='test.xml') > root = tree.getroot() > resultSet = root.findall(".//entry") > for r in resultSet: > print (r.text) I do not know about "xml.etree" but the (said) quite compatible "lxml.etree" handles text nodes in a quite different way from that of "DOM": they are *not* considered children of the parent element but are attached as attributes "text" and "tail" to either the container element (if the first DOM node is a text node) or the preceeding element, otherwise. Your code snippet suggests that "xml.etree" behaves identically in this respect. In this case, you would find "Title of the second book" as the "tail" attribute of the element "coauthored". -- http://mail.python.org/mailman/listinfo/python-list
fastest data / database format for reading large files
I am working with a series of large files with sizes 4 to 10GB and may need to read these files repeated. What data format (i.e. pickle, json, csv, etc.) is considered the fastest for reading via python? Thanks This communication is for informational purposes only. It is not intended to be, nor should it be construed or used as, financial, legal, tax or investment advice or an offer to sell, or a solicitation of any offer to buy, an interest in any fund advised by Ada Investment Management LP, the Investment advisor. Any offer or solicitation of an investment in any of the Funds may be made only by delivery of such Funds confidential offering materials to authorized prospective investors. An investment in any of the Funds is not suitable for all investors. No representation is made that the Funds will or are likely to achieve their objectives, or that any investor will or is likely to achieve results comparable to those shown, or will make any profit at all or will be able to avoid incurring substantial losses. Performance results are net of applicable fees, are unaudited and reflect reinvestment of income and profits. Past performance is no guarantee of future results. All financial data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of Ada Investment Management LP and its affiliates. This transmission may contain information that is confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is strictly prohibited. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. -- http://mail.python.org/mailman/listinfo/python-list
Re: notmm is dead!
On 10/05/2012 12:37 PM, Prasad, Ramit wrote: I might be misunderstanding, but I think Etienne wants money in exchange for letting someone else take over. Not to stir up the hornet's nest any more, but it also sounds like now he wants money for people to license things as well: "The license fee is simply because I'm shifting into commercial license for new releases" Wait, new releases? I thought the project was "dead" ? So, Etienne, are you continuing to maintain the project, or aren't you? In your original "this project is dead" message, you said you had "been bitten by its failure to encourage a free market over one dictated by profit" ... yet now your desire is to be making money (presumably profit?) by selling us a license, so how does that differentiate from those you claim use "cheap tricks to compete" if you hijack a mailing list for several days by claiming you're shutting down the project then say you're charing for licenses which may lead people to believe you're going to KEEP maintaining it? Why on earth would I pay for a license to use code that is not being maintained? Seems like very strange logic to me. Or by having someone pay you some quantity of money to take over as maintainer? I can think of no better way to just kill off a project than expect someone to pay money to take over as a maintainer. I don't recall ever hearing of such a thing in my experience with open-source projects... I'm all about supporting open source projects when I gain value from them (I've donated thousands of dollars and countless hours), but Etienne's back-and-forth on this has me turned off from even wanting to try his project, much less support him. There are so many free places to host code/documentation these days, asking people to donate extra funds to maintain a custom domain name and hosting when free alternatives exist seems as unnecessary as having to pay money to become the next maintainer. -id -- http://mail.python.org/mailman/listinfo/python-list
Re: Aggressive language on python-list
On Wed, Oct 17, 2012 at 10:21 PM, wu wei wrote: >> You don't know me > > No, I really do. Then tell me more about myself...doc. Your behaviour isn't as clever or as masking as you think > it is. It's intended to be involved, witty, and as informed as I can be on a topic by someone I'm conversing with. And to knw when I don't know, or remember something. You're a sad, lonely, desperate person No, I'm fine a s a monk until recently, when medical, and faith issues arose, and for your information, I've been laid quite a few times, and won't have a problem doing so again. I've been out here 6-7 years getting my life together without chasing pussy. who I would genuinely feel > sorry for if you could stop acting like a self-righteous cunt for long > enough. Not self righteous, again wrong. I've been the bad guy, and now I have to watch out for them, which seems self righteous, but it's merely the fact that I have to have a good public persona now. > > But that's never going to happen; you've convinced yourself that arrogant > superiority Go get to know a real few arrogant individuals, with superiority complexes before you comment. If anything, I have an inferiority complex that comes out when I'm downed by someone. is how to succeed in this world, so you better prepare yourself > now for the shitty, sad life that's going to give you. It's been that way in my socioeconomic upbringing I'm trying to overcome, so you're preaching to the choir. > > Spoiler alert: you're going to die alone and unloved. Doubt it. After 6-7 years of leaving sluts, and whores alone, I've realized I need to be secure emotionally, physically, financially, and spiritually. Go insult a troll, because I like to fish off the top of the bridge. Well above trash such as yourself who like to bring people down for fun due to their own superiority complexes. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 24-Oct-2012 01:46, Paul Rubin wrote: Virgil Stokes writes: Yes, I do wish to inverse the order, but the "forward in time" file will be in binary. I really think it will be simplest to just write the file in forward order, then use mmap to read it one record at a time. It might be possible to squeeze out a little more performance with reordering tricks but that's the first thing to try. Thanks Paul, I am working on this approach now... -- http://mail.python.org/mailman/listinfo/python-list
fastest data / database format for reading large files
I am working with a series of large files with sizes 4 to 10GB and may need to read these files repeated. What data format (i.e. pickle, json, csv, etc.) is considered the fastest for reading via python? Thanks This communication is for informational purposes only. It is not intended to be, nor should it be construed or used as, financial, legal, tax or investment advice or an offer to sell, or a solicitation of any offer to buy, an interest in any fund advised by Ada Investment Management LP, the Investment advisor. Any offer or solicitation of an investment in any of the Funds may be made only by delivery of such Funds confidential offering materials to authorized prospective investors. An investment in any of the Funds is not suitable for all investors. No representation is made that the Funds will or are likely to achieve their objectives, or that any investor will or is likely to achieve results comparable to those shown, or will make any profit at all or will be able to avoid incurring substantial losses. Performance results are net of applicable fees, are unaudited and reflect reinvestment of income and profits. Past performance is no guarantee of future results. All financial data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of Ada Investment Management LP and its affiliates. This transmission may contain information that is confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is strictly prohibited. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. -- http://mail.python.org/mailman/listinfo/python-list
Re: OT Questions
> > You haven't been on lists long enough then to have seen some real > flame warts...no offense. No offense taken, it's why I said it in the first place ;) Having said that, generally engaging in flame wars solves nothing and sheds a negative light on the individuals who take part in it. > It's in a design phase, and I'm asking the local experts to critique > it, and even be harsh. You're not a designer. There's nothing at all wrong with that (I'm not either for the record). Most aren't good at both left *and* right-brained functions. My sincere suggestion is pick which aspect of development piques your interest the most and follow that. Delegate the other aspects to others who are good at what they do. Remember.. You're asking for feedback here :) > It was meant as more of a commercial to show a little more umph in my > site presentation, and I'm working on reducing the size through > several different means. It's a bad way of advertising your business. In this day and age, there will likely be less people looking for potential contractors on desktop systems than on mobile devices. As such, you want to make sure that your site has very little in the way of heavy graphics (unless there's a version that the user gets redirected to that's mobile-friendly). Take advantage of client-side rendering where possible. > I know this, and I'm trying to reduce it, but show something that's appealing. My point was that it shouldn't be there *at all*. Automatically playing music is widely thought of as being annoying and does absolutely nothing at all for your business. You're not selling games, you're not selling DJ services. I can guarantee that you will turn away more prospective business by having the music there in the first place than not having any at all. > I kind of like my designs, and they're being refined through these > conversations. I like my designs too. However, I realized *long* ago that I'm not good at them. I even grew to dislike even doing design work because of how much extra time and effort it took to develop something decent rather than just concentrating on what I was good at. My designs wouldn't hold up compared to other professional entities and unless there are remarkable improvements, yours won't either. > I like w3schools.com, and I know that it's a rough draft, and so > should my critics. w3schools is generally thought of as being a bad resource. Take a read through http://w3fools.com (there are many other resources, that was just the first one that popped up on Google search). Udacity has a high powered academic faculty. Coursera is another great resource. Both have content that you'll never get from resources like w3schools. Open higher learning is where it's at. > I like to work alone, and his is an attempt to get others in the OS > community to comment. Working alone is almost always the worst thing that you can do if you're new (or newer) to development, design, user experience or any combination thereof. Surrounding yourself with people smarter than you is the best way to learn and grow. Sure, you can attempt to get some of that over mailing lists and the like, but nothing will *ever* beat in-person environments. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with ThreadingTCPServer Handler
Tanks a lot, it was really helpful El 23/10/12 16:51, Miki Tebeka escribió: According to the docs (http://docs.python.org/library/socketserver.html#requesthandler-objects) there's self.server available. 10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS INFORMATICAS... CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION http://www.uci.cu http://www.facebook.com/universidad.uci http://www.flickr.com/photos/universidad_uci -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
> Data files have some sort of parsing, unless it's one huge dict, or > list, so there has to be an average size to the parse. > Not meaning the dict, or list isn't parsed, but that the file should be have parsable areas. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Urwid 1.1.0 - Usability and Documentation
- Original Message - > Announcing Urwid 1.1.0 > -- > > Urwid home page: > http://excess.org/urwid/ > > Manual: > http://excess.org/urwid/docs/ > > Package: > http://pypi.python.org/pypi/urwid/1.1.0 > > [snip] Hi, I just had a look at it. Amazing job. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: fastest data / database format for reading large files
On Tue, Oct 16, 2012 at 11:35 AM, Pradipto Banerjee wrote: > I am working with a series of large files with sizes 4 to 10GB and may need > to read these files repeated. What data format (i.e. pickle, json, csv, etc.) > is considered the fastest for reading via python? Pickle /ought/ to be fastest, since it's binary (unless you use the oldest protocol version) and native to Python. Be sure to specify HIGHEST_PROTOCOL and use cPickle. http://docs.python.org/2/library/pickle.html#module-cPickle http://docs.python.org/2/library/pickle.html#pickle.HIGHEST_PROTOCOL You might consider using SQLite (or some other database) if you will be doing queries over the data that would be amenable to SQL or similar. http://docs.python.org/2/library/sqlite3.html Cheers, Chris P.S. The verbose disclaimer at the end of your emails is kinda annoying... -- http://mail.python.org/mailman/listinfo/python-list
Re: attaching names to subexpressions
On Sun, Oct 28, 2012 at 6:12 PM, F.R. wrote: > > How about: > > line = True > while line: > > line = function(x, y, z) > do something with(line) > > ? That's going to go through the body of the loop with a false line before breaking out. In some situations that's not a problem, but it's distinctly different, so it's not a drop-in replacement for the others. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 10/24/2012 03:14 AM, Virgil Stokes wrote: > On 24-Oct-2012 01:46, Paul Rubin wrote: >> Virgil Stokes writes: >>> Yes, I do wish to inverse the order, but the "forward in time" file >>> will be in binary. >> I really think it will be simplest to just write the file in forward >> order, then use mmap to read it one record at a time. It might be >> possible to squeeze out a little more performance with reordering tricks >> but that's the first thing to try. > Thanks Paul, > I am working on this approach now... If you're using mmap to map the whole file, you'll need 64bit Windows to start with. I'd be interested to know if Windows will allow you to mmap 100gb at one stroke. Have you tried it, or are you starting by figuring how to access the data from the mmap? -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Urwid 1.1.0 - Usability and Documentation
+1 great library. I suppose it will never be in the standard library? :p On Wed, Oct 24, 2012 at 5:08 AM, Jean-Michel Pichavant < jeanmic...@sequans.com> wrote: > - Original Message - > > Announcing Urwid 1.1.0 > > -- > > > > Urwid home page: > > http://excess.org/urwid/ > > > > Manual: > > http://excess.org/urwid/docs/ > > > > Package: > > http://pypi.python.org/pypi/urwid/1.1.0 > > > > > > [snip] > > Hi, > > I just had a look at it. Amazing job. > > > JM > > > > -- IMPORTANT NOTICE: > > The contents of this email and any attachments are confidential and may > also be privileged. If you are not the intended recipient, please notify > the sender immediately and do not disclose the contents to any other > person, use it for any purpose, or store or copy the information in any > medium. Thank you. > -- > http://mail.python.org/mailman/listinfo/python-list > -- --- Get your facts first, then you can distort them as you please.-- -- http://mail.python.org/mailman/listinfo/python-list
Re: a.index(float('nan')) fails
Steven D'Aprano wrote: The list.index method tests for the item with equality. Since NANs are mandated to compare unequal to anything, including themselves, index cannot match them. This is incorrect. .index() uses identity first, then equality, and will match the same NaN in a list. The OP's problem was in using a different NaN. Having said that, your find_nan() solution is probably the one to use anyway. from math import isnan def find_nan(seq): """Return the index of the first NAN in seq, otherwise None.""" for i, x in enumerate(seq): if isnan(x): return i For old versions of Python that don't provide an isnan function, you can do this: def isnan(x): return x != x -- http://mail.python.org/mailman/listinfo/python-list
Re: Style help for a Smalltalk-hack
Travis Griggs wrote: I'm writing some code that does a structured read from formatted binary file. The code I came up with looks like: # get the first four bytes, the first gap field chunk = byteStream.read(4) while chunk: # interpret the gap bytes gap, = struct.unpack('>I', chunk) # suck off the valveCount valveCount, = struct.unpack('>I', byteStream.read(4)) # collect the next valveCount signatures signatures = [struct.unpack('>I', byteStream.read(4))[0] for _ in range(valveCount)] self.script.append(ScriptSpan(gap=gap, valveSet=signatures)) # now get the next 4 bytes for the gap of the next iteration, it'll be empty if we're at end chunk = byteStream.read(4) I can't help but thinking that there's some better way (i.e. more pythonic) to do this that doesn't involve having to use another module (Construct) or exploring generators or something like that. What bugs me about it is that there is two different styles for reading/decoding values from the byte stream. valveCount and signatures are both paired invocations of unpack() and read(). But to detect the end of the stream (file), I have to split the read() and unpack() of the gap value across 3 different lines of the code, and they don't even sit adjacent to each other. What do you have against generators? ;) How about an iterator approach: 8<--- class Gap_Valve_Reader(object): # untested def __init__(self, filename): self.byteStream = open(filename) def __iter__(self): return self def __next__(self): # python 3 name chunk = self.byteStream.read(8) if not chunk: self.byteStream.close() raise StopIteration gap, valveCount = struct.unpack('>II', chunk) signatures = struct.unpack('>%sI' % valveCount, self.byteStream.read(4 * valueCount)) return gap, signatures next = __next__ # python 2 name 8<--- then your main code can look like: 8<--- gvr = Gap_Valve_Reader('binary_file.bin') for gap, signatures in gvr: self.script.append(ScriptSpan(gap=gap, valveSet=signatures)) 8<--- Don't forget to add error checking where appropriate. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 28-Oct-2012 12:18, Dave Angel wrote: On 10/24/2012 03:14 AM, Virgil Stokes wrote: On 24-Oct-2012 01:46, Paul Rubin wrote: Virgil Stokes writes: Yes, I do wish to inverse the order, but the "forward in time" file will be in binary. I really think it will be simplest to just write the file in forward order, then use mmap to read it one record at a time. It might be possible to squeeze out a little more performance with reordering tricks but that's the first thing to try. Thanks Paul, I am working on this approach now... If you're using mmap to map the whole file, you'll need 64bit Windows to start with. I'd be interested to know if Windows will allow you to mmap 100gb at one stroke. Have you tried it, or are you starting by figuring how to access the data from the mmap? Thanks very much for pursuing my query, Dave. I have not tried it yet --- temporarily side-tracked; but, I will post my findings on this issue. -- http://mail.python.org/mailman/listinfo/python-list
Re: Error compiling python3.2.3: architecture of input file is incompatible
Am 28.10.2012 03:00, schrieb python-list-requ...@python.org: It looks like you've copied *.o files from your 64 bit build to your 32 bit box. If that's your problem, then the easiest solution is to delete everything and start over. Alternatively, you could run "make distclean"; that will delete a lot of generated files and then re-run configure. After that, running "make" should work. Hope this helps, -- HansM I was pretty sure I didn't copy the files from the 64 build. Anyway, "make distclean" solved the problem. Thank you! Tobias -- http://mail.python.org/mailman/listinfo/python-list
Re: OT Questions
On 16 October 2012 18:23, Ian Kelly wrote: > On Tue, Oct 16, 2012 at 9:21 AM, Demian Brecht > wrote: > > There's a small light somewhere deep down that says maybe this is just > > someone quite misdirected. A brief search shows that he has multiple > > domains, all with the same type of design. I would be hard pressed to > think > > that someone would go to that extent just to troll a list. > > > > Meh, maybe it's my good nature :P > > My theory for a while now has been that Mr. Hutto is probably an > enterprising teenager. His desire to build a web development company > is sincere and should be encouraged, but his lack of experience is > readily apparent, as is his rather crude behavior on list. > I feel necessity to argue against this point. It is a common thing to stereotype teens in this way - but, being teen myself, I feel one should try to avoid it. It's painful to watch every time someone claims "he can't be a teenager - his spelling/grammar is too good" or any derivation of it, as with the inverse concept that the uneducated are always teenagers. i have techers who type lke this, and I have teachers who type very professionally. I have peers of my age group who meticulously craft their online conversations, n i no BFFs who dun b like that. How someone speaks on the internet seems to me proportional almost entirely to their intelligence*, not to their wisdom. Sure, there is an age where one, no matter how bright, will speak like trash, but this normally coincides with an inability to speak well, too. Most older teenagers have as good a grasp on language as they will ever learn, so it hardly applies to them. * Note that I speak not of IQ or problem-solving ability, but more of a general social intelligence that can be seen in almost any poster on this list. -- http://mail.python.org/mailman/listinfo/python-list
Re: Where are documentation for Gnome
On 13/10/2012 18:49, Santosh Kumar wrote: Try your local garden centre. -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 28 October 2012 14:20, Virgil Stokes wrote: > On 28-Oct-2012 12:18, Dave Angel wrote: >> >> On 10/24/2012 03:14 AM, Virgil Stokes wrote: >>> >>> On 24-Oct-2012 01:46, Paul Rubin wrote: Virgil Stokes writes: > > Yes, I do wish to inverse the order, but the "forward in time" file > will be in binary. I really think it will be simplest to just write the file in forward order, then use mmap to read it one record at a time. It might be possible to squeeze out a little more performance with reordering tricks but that's the first thing to try. >>> >>> Thanks Paul, >>> I am working on this approach now... >> >> If you're using mmap to map the whole file, you'll need 64bit Windows to >> start with. I'd be interested to know if Windows will allow you to mmap >> 100gb at one stroke. Have you tried it, or are you starting by figuring >> how to access the data from the mmap? > > Thanks very much for pursuing my query, Dave. > > I have not tried it yet --- temporarily side-tracked; but, I will post my > findings on this issue. If you are going to use mmap then look at the numpy.memmap function. This wraps pythons mmap so that you can access the contents of the mapped binary file as if it was a numpy array. This means that you don't need to handle the bytes -> float conversions yourself. >>> import numpy >>> a = numpy.array([4,5,6], numpy.float64) >>> a array([ 4., 5., 6.]) >>> with open('tmp.bin', 'wb') as f: # write forwards ... a.tofile(f) ... a.tofile(f) ... >>> a2 = numpy.memmap('tmp.bin', numpy.float64) >>> a2 memmap([ 4., 5., 6., 4., 5., 6.]) >>> a2[3] 4.0 >>> a2[5:2:-1] # read backwards memmap([ 6., 5., 4.]) Oscar -- http://mail.python.org/mailman/listinfo/python-list
Re: Where are documentation for Gnome
On Sun, 28 Oct 2012 16:29:07 +, Mark Lawrence wrote: > On 13/10/2012 18:49, Santosh Kumar wrote: >> >> > Try your local garden centre. I inquired at the local garden centre, Just got strange looks Are you sure that is the correct place? ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: SSH Connection with Python
On 10/28/2012 02:35 AM, Cameron Simpson wrote: On 27Oct2012 14:18, Gelonida N wrote: | On 10/27/2012 02:21 AM, Roy Smith wrote: | > In article , | > Gelonida N wrote: | > | >> Another problem is, that paramiko depends on pycrypto 2.1+ | >> which doesn't exist as binary release for python 2.7 | > | > I'm running paramiko-1.7.6 with python 2.7.3 on my Ubunto Precise box. | > I'm reasonably sure all I did was "pip install paramiko". | | Apologies. I failed to mention, that I was talking about Windows not Linux. | | I use Python for applications, that should work under Linux and under | Windows. | | > But, keep in mind that fabric depends on paramiko. If you can't get | > paramiko installed, you probably can't get fabric either. | > | Thanks, that's good to know, so I don't have to bother looking at farbic | (at least not as solution on windows python 2.7 without having to try to | recompile pycrypto myself) Many years ago we ran an ssh executable on Windows; it was a tiny standalone kit consisting, IIRC, of the Cygwin libc and ssh. Or you could just install Cygwin... That would let you use Python's subprocess module to invoke ssh and dispatch your command. On all my work PCs cygwin is installed. However when packaging something with py2exe I'd really prefer to not have to install additional .exe / .dll files just for the ssh client. This is why I like the idea of Paramiko. which requires the crypto .dll, but that's it. The only thing I'm concerned about paramiko is, that I don't see any activity on the paramiko site and that one library it depends on is not available is windows binary package for newer versions of python. For the time being I stick with paramiko as I'm still on py2.6, but I wanted to have some feedback, whether this path can easily be followed in the mid term future or whther I ahd to fall back to a minimalist set of ssh executables / dlls and a subprocess wrapper. -- http://mail.python.org/mailman/listinfo/python-list
Re: SSH Connection with Python
On 10/26/2012 05:22 AM, Jason Friedman wrote: how can i create a SSH-Connection with python? I have to send some commands to the remote host and parse their answers. Consider also the sh module: http://amoffat.github.com/sh/tutorials/2-interacting_with_processes.html. Just a minor comment: The sh module looks intersting, but it's not supported for Windows platforms. Please note: I'm not the original poster, so perhaps this is no issue for him. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast forward-backward (write-read)
On 2012-10-28 19:21, Oscar Benjamin wrote: On 28 October 2012 14:20, Virgil Stokes wrote: On 28-Oct-2012 12:18, Dave Angel wrote: On 10/24/2012 03:14 AM, Virgil Stokes wrote: On 24-Oct-2012 01:46, Paul Rubin wrote: Virgil Stokes writes: Yes, I do wish to inverse the order, but the "forward in time" file will be in binary. I really think it will be simplest to just write the file in forward order, then use mmap to read it one record at a time. It might be possible to squeeze out a little more performance with reordering tricks but that's the first thing to try. Thanks Paul, I am working on this approach now... If you're using mmap to map the whole file, you'll need 64bit Windows to start with. I'd be interested to know if Windows will allow you to mmap 100gb at one stroke. Have you tried it, or are you starting by figuring how to access the data from the mmap? Thanks very much for pursuing my query, Dave. I have not tried it yet --- temporarily side-tracked; but, I will post my findings on this issue. If you are going to use mmap then look at the numpy.memmap function. This wraps pythons mmap so that you can access the contents of the mapped binary file as if it was a numpy array. This means that you don't need to handle the bytes -> float conversions yourself. import numpy a = numpy.array([4,5,6], numpy.float64) a array([ 4., 5., 6.]) with open('tmp.bin', 'wb') as f: # write forwards ... a.tofile(f) ... a.tofile(f) ... a2 = numpy.memmap('tmp.bin', numpy.float64) a2 memmap([ 4., 5., 6., 4., 5., 6.]) a2[3] 4.0 a2[5:2:-1] # read backwards memmap([ 6., 5., 4.]) Oscar Thanks Oscar! -- http://mail.python.org/mailman/listinfo/python-list
Help understanding an Object Oriented Program example
Hi, Trying to learn Python OOP. An example from a book, may not be formated after sending post but: class Contact: all_contacts = [] def __init__(self, name, email): self.name = name self.email = email Contact.all_contacts.append(self) OK, no I do this: >>> c = Contact('aaa','bbb') >>> c = Contact('ccc','ddd') >>> c = Contact('eee','fff') >>> for i in Contact.all_contacts: print i.name + ' ' + i.email aaa bbb ccc ddd eee fff >>> >>> c.name 'eee' So wouldn't be good to add a check that the var (in this case c) does not point to any object before creating an object to keep the list correct? Also all_contacts is a class variable. I think the author is hinting that this would be a good idea for a contact list, But I don't fully see the usage of it. How would each object use a class variable like this? What would be the dot notation? I realize this is a code fragment and is no way implementable code. Any help appreciated. BTW, it's from "Python3 Object Oriented Programming..." by D. Philips - very clearly written and enjoying it...Thanks -- http://mail.python.org/mailman/listinfo/python-list
Simple Python question for some
I have what I think should be a relatively simple question for someone who is knowledgeable about Python. At the IDLE prompt, when I enter "b" > 99, it responds True. In fact, it doesn't matter which number is entered here, "b" is always greater (e.g. "b" > 1 == True; "b" > 10 == True, or "b" < 99 = False). Why is this true? If I use ord("b") it returns 98, so Python cannot be using the ASCII or Unicode value when interpreting "b" > 99. When I sort a mixed list using Python, and the list contains "b" among a series of numeric values, "b" is always sorted as last, indicating that it has a value greater than the highest number? How do I prove that "b" is greater than any number? Or is it something very simple, and Python simply orders characters after numbers, or perhaps Python only interprets numbers like 99 as a 9 (i.e. ord("9") == 57)? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help understanding an Object Oriented Program example
On Sun, Oct 28, 2012 at 4:30 PM, goldtech wrote: > Hi, > > Trying to learn Python OOP. An example from a book, may not be > formated after sending post but: > > class Contact: > all_contacts = [] > def __init__(self, name, email): > self.name = name > self.email = email > Contact.all_contacts.append(self) > > OK, no I do this: > c = Contact('aaa','bbb') c = Contact('ccc','ddd') c = Contact('eee','fff') for i in Contact.all_contacts: > print i.name + ' ' + i.email > > > aaa bbb > ccc ddd > eee fff c.name > 'eee' > > So wouldn't be good to add a check that the var (in this case c) does > not point to any object before creating an object to keep the list > correct? I'm unclear on how the list would become "incorrect" or exactly what sort of check you're thinking of. Please explain what you mean in greater detail. Keep in mind that checking for the "definedness" of variables in Python is generally considered bad and is often infeasible. > Also all_contacts is a class variable. I think the author is hinting > that this would be a good idea for a contact list, But I don't fully > see the usage of it. I would think he just wants to demonstrate the use of class variables as opposed to instance variables. It's probably not a good idea for a serious contact list implementation. But the general technique to allow a class to keep track of all its instances can sometimes be useful (e.g. for caching). > How would each object use a class variable like > this? What would be the dot notation? All of the following would work: Contact.all_contacts # as in the example self.__class__.all_contacts self.all_contacts # probably not advisable Which one you ought to use becomes complicated when you consider the general case where there may be sub/superclasses, where you may want to rebind the variable, and where there may be an instance variable of the same name. Class variables are generally used quite infrequently compared to regular instance variables. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Help understanding an Object Oriented Program example
On Mon, Oct 29, 2012 at 10:30 AM, goldtech wrote: > Hi, > > Trying to learn Python OOP. An example from a book, may not be > formated after sending post but: > > class Contact: > all_contacts = [] > def __init__(self, name, email): > self.name = name > self.email = email > Contact.all_contacts.append(self) > > OK, no I do this: > c = Contact('aaa','bbb') c = Contact('ccc','ddd') c = Contact('eee','fff') for i in Contact.all_contacts: > print i.name + ' ' + i.email > > > aaa bbb > ccc ddd > eee fff c.name > 'eee' Hi! Side point before we begin: You appear to be using Python 2.something (since print is a statement, not a function), but your book (as you mention further down) refers to Python3. I recommend you get an interpreter that corresponds to your book, or you'll end up tripping over a triviality :) If the book doesn't specify a particular version, get 3.3 - it's the latest released Python, and a significant improvement over its predecessors. > So wouldn't be good to add a check that the var (in this case c) does > not point to any object before creating an object to keep the list > correct? Depends what you mean by "correct" there. If you're expecting the list to contain only those objects that are referenced somewhere else, you'll have to play around with weak references and such; normally, what's expected of code like this is that it will retain all objects created, even if there are no other references. So in that sense, the list's already correct. > Also all_contacts is a class variable. I think the author is hinting > that this would be a good idea for a contact list, But I don't fully > see the usage of it. How would each object use a class variable like > this? What would be the dot notation? Exactly the way you currently are, as Contact.all_contacts - but there's also some magic that lets you reference it from any instance: >>> Contact("foo","foo@foo") <__main__.Contact instance at 0x011B5030> >>> Contact("a","a@a") <__main__.Contact instance at 0x011BC828> >>> c=Contact("quux","q...@example.com") >>> c.all_contacts [<__main__.Contact instance at 0x011B5030>, <__main__.Contact instance at 0x011BC828>, <__main__.Contact instance at 0x011BC5D0>] Note how all three instances are listed in one instance's all_contacts member. (Note also that I didn't have to assign the other two to anything - the objects still get retained in all_contacts.) A common way to do this sort of thing is to simply use self: class Contact: all_contacts = [] def __init__(self, name, email): self.name = name self.email = email self.all_contacts.append(self) As long as you don't rebind that name (eg "self.all_contacts = []"), this will work just fine. > I realize this is a code fragment and is no way implementable code. Actually, it's quite workable. It's enough to paste into the interactive interpreter and play with. That's one of Python's best features - it's really easy to play with. And if you put parentheses around your print argument, it'll be fully Python 3 compatible (though when you run it in Python 2, you get an old-style class - but since the book's assuming Py3, new-style is what you want anyway). >>> for i in Contact.all_contacts: print(i.name + ' ' + i.email) Hope that helps! Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python question for some
On 28/10/2012 23:51, Mark L. Hotz wrote: I have what I think should be a relatively simple question for someone who is knowledgeable about Python. Sorry you've come to the wrong place :) At the IDLE prompt, when I enter "b" > 99, it responds True. In fact, it doesn't matter which number is entered here, "b" is always greater (e.g. "b" 1 == True; "b" > 10 == True, or "b" < 99 = False). Why is this true? If I use ord("b") it returns 98, so Python cannot be using the ASCII or Unicode value when interpreting "b" > 99. When I sort a mixed list using Python, and the list contains "b" among a series of numeric values, "b" is always sorted as last, indicating that it has a value greater than the highest number? How do I prove that "b" is greater than any number? Or is it something very simple, and Python simply orders characters after numbers, or perhaps Python only interprets numbers like 99 as a 9 (i.e. ord("9") == 57)? Thank you. The behaviour of Python between version 2 and 3 has been changed hence. Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 'b' > 99 True Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 'b' > 99 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: str() > int() -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python question for some
On Sun, Oct 28, 2012 at 4:51 PM, Mark L. Hotz wrote: > I have what I think should be a relatively simple question for someone who > is knowledgeable about Python. > > At the IDLE prompt, when I enter “b” > 99, it responds True. In fact, it > doesn’t matter which number is entered here, “b” is always greater (e.g. “b” >> 1 == True; “b” > 10 == True, or “b” < 99 = False). > > Why is this true? Per http://docs.python.org/2/library/stdtypes.html#comparisons : "Objects of different types, except different numeric types and different string types, […] are ordered consistently but arbitrarily (so that sorting a heterogeneous array yields a consistent result)." Note that the "except" part just means that, e.g. floats and ints can be compared with each other, and Unicode and byte strings can be compared with each other. It does NOT mean that numbers and strings can be meaningfully compared with each other. This is fixed in Python 3, where such nonsensical comparisons will instead raise TypeError. > If I use ord(“b”) it returns 98, so Python cannot be > using the ASCII or Unicode value when interpreting “b” > 99. It has nothing to do with implicit casting between strings and numbers (which, as a general rule, Python does not do). From the same linked section as before: "CPython implementation detail: Objects of [incompatible types] are ordered by their type names" So ints come before strs because "int" comes before "str" lexicographically. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python question for some
On Mon, Oct 29, 2012 at 10:51 AM, Mark L. Hotz wrote: > At the IDLE prompt, when I enter “b” > 99, it responds True. In fact, it > doesn’t matter which number is entered here, “b” is always greater (e.g. “b” >> 1 == True; “b” > 10 == True, or “b” < 99 = False). To Python, different object types are completely different. Incidentally, with issues like this, it's worth mentioning which version of Python you're using - though in this case, it's clear you're using Python 2. As of version 3, behaviour is different: Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> "b" > 99 Traceback (most recent call last): File "", line 1, in "b" > 99 TypeError: unorderable types: str() > int() As of Python 2, there's a slightly esoteric rule as described here: http://docs.python.org/2/library/stdtypes.html#comparisons "CPython implementation detail: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison are ordered by their address." So since "str" is greater than "int", "b" is greater than 99. Fortunately, Python does NOT have arcane rules for comparing numbers as though they were strings. Notably: >>> "100" == 100 False Which means that strings will ALWAYS be compared as strings, and numbers will ALWAYS be compared as numbers, and ne'er the twain shall conflict. I can trust Python to compare MD5 hashes reliably: >>> "912128034267498495410681495015e0" != "00912128034267498495410681495015" True Of course, I'm not pointing fingers at any other languages here, but this is a known security hole in one rather widely-used one. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Where are documentation for Gnome
On Sun, 28 Oct 2012 16:29:07 +, Mark Lawrence wrote: > On 13/10/2012 18:49, Santosh Kumar wrote: >> >> > Try your local garden centre. Or: The Burrow, Ottery St. Catchpole, Devon, England -- http://mail.python.org/mailman/listinfo/python-list
question on subprogram parameter
Hi, I'm studying python now and I saw a piece of code like this: def storeDbase(db, dbfilename=dbfilename): . dbfile=open(dbfilename,'w') for key in db: print(key, file=dbfile) can anybody help me to understand what does this "file=dbfile" mean and what is its function? thanks. -- http://mail.python.org/mailman/listinfo/python-list
Negative array indicies and slice()
The slice operator does not give any way (I can find!) to take slices from negative to positive indexes, although the range is not empty, nor the expected indexes out of range that I am supplying. Many programs that I write would require introducing variables and logical statements to correct the problem which is very lengthy and error prone unless there is a simple work around. I *hate* replicating code every time I need to do this! I also don't understand why slice() is not equivalent to an iterator, but can replace an integer in __getitem__() whereas xrange() can't. Here's an example for Linux shell, otherwise remove /bin/env... {{{#!/bin/env python a=[1,2,3,4,5,6,7,8,9,10] print a[-4:3] # I am interested in getting [7,8,9,10,1,2] but I get []. }}} -- http://mail.python.org/mailman/listinfo/python-list
Re: question on subprogram parameter
On 2012-10-29 03:03, skyworld wrote: Hi, I'm studying python now and I saw a piece of code like this: def storeDbase(db, dbfilename=dbfilename): . dbfile=open(dbfilename,'w') for key in db: print(key, file=dbfile) can anybody help me to understand what does this "file=dbfile" mean and what is its function? thanks. It's a keyword parameter. Normally 'print' sends its output to the standard output (usually it's the screen). Adding 'file=dbfile' tells it to send its output to the file referred to by 'dbfile' instead. It's all in the documentation! -- http://mail.python.org/mailman/listinfo/python-list
Re: Negative array indicies and slice()
On Sun, Oct 28, 2012 at 9:12 PM, wrote: > The slice operator does not give any way (I can find!) to take slices from > negative to positive indexes, although the range is not empty, nor the > expected indexes out of range that I am supplying. > > Many programs that I write would require introducing variables and logical > statements to correct the problem which is very lengthy and error prone > unless there is a simple work around. > > I *hate* replicating code every time I need to do this! > > I also don't understand why slice() is not equivalent to an iterator, but can > replace an integer in __getitem__() whereas xrange() can't. > > > Here's an example for Linux shell, otherwise remove /bin/env... > {{{#!/bin/env python > a=[1,2,3,4,5,6,7,8,9,10] > print a[-4:3] # I am interested in getting [7,8,9,10,1,2] but I get []. > }}} For a sequence of length 10, "a[-4:3]" is equivalent to "a[6:3]", which is an empty slice since index 6 is after index 3. If you want it to wrap around, then take two slices and concatenate them with "a[-4:] + a[:3]". -- http://mail.python.org/mailman/listinfo/python-list
Re: Negative array indicies and slice()
On 2012-10-29 03:12, andrewr3m...@gmail.com wrote: The slice operator does not give any way (I can find!) to take slices from negative to positive indexes, although the range is not empty, nor the expected indexes out of range that I am supplying. Many programs that I write would require introducing variables and logical statements to correct the problem which is very lengthy and error prone unless there is a simple work around. I *hate* replicating code every time I need to do this! I also don't understand why slice() is not equivalent to an iterator, but can replace an integer in __getitem__() whereas xrange() can't. Here's an example for Linux shell, otherwise remove /bin/env... {{{#!/bin/env python a=[1,2,3,4,5,6,7,8,9,10] print a[-4:3] # I am interested in getting [7,8,9,10,1,2] but I get []. }}} If the stride is positive (if omitted it defaults to 1), the slice is from the start index to one before the end index, and a negative index counts from the end. a[-4:3] is equivalent to a[len(a)-4:3], which is an empty list if len(a)-4 >= 3. It doesn't wrap around. -- http://mail.python.org/mailman/listinfo/python-list
Re: Negative array indicies and slice()
On Sunday, October 28, 2012 8:43:30 PM UTC-7, Ian wrote: > On Sun, Oct 28, 2012 at 9:12 PM, andrew wrote: > > > The slice operator does not give any way (I can find!) to take slices from > > negative to positive indexes, although the range is not empty, nor the > > expected indexes out of range that I am supplying. > > > > > > Many programs that I write would require introducing variables and logical > > statements to correct the problem which is very lengthy and error prone > > unless there is a simple work around. > > > > > > I *hate* replicating code every time I need to do this! > > > > > > I also don't understand why slice() is not equivalent to an iterator, but > > can replace an integer in __getitem__() whereas xrange() can't. > > > > > > > > > Here's an example for Linux shell, otherwise remove /bin/env... > > > {{{#!/bin/env python > > > a=[1,2,3,4,5,6,7,8,9,10] > > > print a[-4:3] # I am interested in getting [7,8,9,10,1,2] but I get []. > > > }}} > > > > > > For a sequence of length 10, "a[-4:3]" is equivalent to "a[6:3]", > > which is an empty slice since index 6 is after index 3. > > > > If you want it to wrap around, then take two slices and concatenate > > them with "a[-4:] + a[:3]". Hi Ian, Well, no it really isn't equivalent. Consider a programmer who writes: xrange(-4,3) *wants* [-4,-3,-2,-1,0,1,2] That is the "idea" of a range; for what reason would anyone *EVER* want -4 to +3 to be 6:3??? I do agree that the data held in -4 is equivalent to the data in 6, but the index is not the same. So: Why does python choose to convert them to positive indexes, and have slice operate differently than xrange -- for the slice() object can't possibly know the size of the array when it is passed in to __getitem__; They are totally separate classes. I realize I can concat. two slice ranges, BUT, the ranges do not always span from negative to positive. eg: a line in my program reads: a[x-5:x] if x is 7, then this is a positive index to a positive index. So, there is no logic to using two slices concatd ! I use this arbitrary range code *often* so I need a general purpose solution. I looked up slice() but the help is of no use, I don't even know how I might overload it to embed some logic to concatenate ranges of data; nor even if it is possible. -- http://mail.python.org/mailman/listinfo/python-list
Re: Negative array indicies and slice()
On Sunday, October 28, 2012 8:43:30 PM UTC-7, Ian wrote: > On Sun, Oct 28, 2012 at 9:12 PM, wrote: > > > The slice operator does not give any way (I can find!) to take slices from > > negative to positive indexes, although the range is not empty, nor the > > expected indexes out of range that I am supplying. > > > > > > Many programs that I write would require introducing variables and logical > > statements to correct the problem which is very lengthy and error prone > > unless there is a simple work around. > > > > > > I *hate* replicating code every time I need to do this! > > > > > > I also don't understand why slice() is not equivalent to an iterator, but > > can replace an integer in __getitem__() whereas xrange() can't. > > > > > > > > > Here's an example for Linux shell, otherwise remove /bin/env... > > > {{{#!/bin/env python > > > a=[1,2,3,4,5,6,7,8,9,10] > > > print a[-4:3] # I am interested in getting [7,8,9,10,1,2] but I get []. > > > }}} > > > > > > For a sequence of length 10, "a[-4:3]" is equivalent to "a[6:3]", > > which is an empty slice since index 6 is after index 3. > > > > If you want it to wrap around, then take two slices and concatenate > > them with "a[-4:] + a[:3]". Hi Ian, Well, no it really isn't equivalent; although Python implements it as equivalent. Consider a programmer who writes: xrange(-4,3) They clearly *want* [-4,-3,-2,-1,0,1,2] That is the "idea" of a range; So, for what reason would anyone want -4 to +3 to be 6:3??? Can you show me some code where this is desirable?? I do agree that the data held in -4 is equivalent to the data in 6, but the index is not the same. So: Why does python choose to convert them to positive indexes, and have slice operate differently than xrange -- for the slice() object can't possibly know the size of the array when it is passed in to __getitem__; They are totally separate classes. I realize I can concat. two slice ranges, BUT, the ranges do not always span from negative to positive. eg: a line in my program reads: a[x-5:x] if x is 7, then this is a positive index to a positive index. So, there is no logic to using two slices concatd ! I use this arbitrary range code *often* so I need a general purpose solution. I looked up slice() but the help is of no use, I don't even know how I might overload it to embed some logic to concatenate ranges of data; nor even if it is possible. -- http://mail.python.org/mailman/listinfo/python-list
Re: Negative array indicies and slice()
On Sun, Oct 28, 2012 at 10:00 PM, wrote: > Hi Ian, > Well, no it really isn't equivalent. > Consider a programmer who writes: > xrange(-4,3) *wants* [-4,-3,-2,-1,0,1,2] > > That is the "idea" of a range; for what reason would anyone *EVER* want -4 to > +3 to be 6:3??? That is what ranges do, but your question was about slices, not ranges. > So: Why does python choose to convert them to positive indexes, and have > slice operate differently than xrange -- for the slice() object can't > possibly know the size of the array when it is passed in to __getitem__; > They are totally separate classes. Ranges can contain negative integers. However, sequences do not have negative indices. Therefore, negative indices in slices are used to count from the end instead of from the start. As stated in the language docs, "If either bound is negative, the sequence’s length is added to it." Therefore, "a[-4:3]" does not wrap around the end of the sequence because "a[6:3]" does not wrap around the end of the sequence. > I realize I can concat. two slice ranges, BUT, the ranges do not always span > from negative to positive. def wrapping_slice(seq, start, stop): start, stop, _ = slice(start, stop).indices(len(seq)) if start <= stop: return seq[start:stop] else: return seq[start:] + seq[:stop] You'll have to decide for yourself whether you want it to return an empty list or the entire list if start == stop. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Simple Python question for some
On 10/28/2012 7:18 PM, Chris Rebert wrote: > This is fixed in Python 3, where such nonsensical comparisons will > instead raise TypeError. It's worth pointing out that at least one kind of inequality comparison which some people (e.g. me) would consider nonsensical is still allowed in Python 3, which is between Boolean values and numbers: >>> True < 1 False >>> False < 1 True which is probably because >>> True == 1 True >>> False == 0 True Many people (probably most people, to be honest) disagree with me that this is wrong, but regardless of whether you like it or not you need to know what happens in such cases. On 10/28/2012 7:18 PM, Chris Angelico wrote: > Which means that strings will ALWAYS be compared as strings, and > numbers will ALWAYS be compared as numbers, and ne'er the twain shall > conflict. I can trust Python to compare MD5 hashes reliably: > "912128034267498495410681495015e0" !=00912128034267498495410681495015" > True > > Of course, I'm not pointing fingers at any other languages here, but > this is a known security hole in one rather widely-used one. If you are PerHaPs talking about the language I think you are, my favorite fact about that is I'm that I think a while back I saw a bug entry about something like that and they weren't sure how or even if it should be fixed. Evan -- http://mail.python.org/mailman/listinfo/python-list
Re: Negative array indicies and slice()
On Oct 29, 2:09 pm, Andrew wrote: > I use this arbitrary range code *often* so I need a general purpose solution. > I looked up slice() but the help is of no use, I don't even know how I might > overload it to embed some logic to concatenate ranges of data; nor even if > it is possible. Slices are passed in if provided to __getitem__/__setitem__/ __delitem__, so you'd need to override it at the list level: class RangedSlicer(list): def __getitem__(self, item): # map item.start, .stop and .step to your own semantics Then wrap your lists with your RangedSlicer class as needed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Simple Python question for some
On Mon, Oct 29, 2012 at 3:30 PM, Evan Driscoll wrote: > On 10/28/2012 7:18 PM, Chris Angelico wrote: >> Which means that strings will ALWAYS be compared as strings, and >> numbers will ALWAYS be compared as numbers, and ne'er the twain shall >> conflict. I can trust Python to compare MD5 hashes reliably: >> > "912128034267498495410681495015e0" !=00912128034267498495410681495015" >> True >> >> Of course, I'm not pointing fingers at any other languages here, but >> this is a known security hole in one rather widely-used one. > > If you are PerHaPs talking about the language I think you are, my > favorite fact about that is I'm that I think a while back I saw a bug > entry about something like that and they weren't sure how or even if it > should be fixed. Indeed. So it's an issue unlikely to go away any time soon. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Negative array indicies and slice()
Andrew writes: > So: Why does python choose to convert them to positive indexes, and > have slice operate differently than xrange There was a thread a few years back, I think started by Bryan Olson, that made the case that slice indexing is a Python wart for further reasons than the above, and suggesting a notation like x[$-5] to denote what we now call x[-5] (i.e. $ is the length of the string). So your example x[$-4:3] would clearly be the same thing as x[6:3] and not give any suggestion that it might wrap around. -- http://mail.python.org/mailman/listinfo/python-list
Numpy module
Hello to the group! I've learned a lot about Ubuntu just trying to install numpy for Python 3.2.3. I've finally managed to put it in the Python3.2 directory but when I try to import it, I still get there's "no module named numpy." There are other modules in the same directory, like 'email' and it imports fine. Does Numpy 1.6.2 not run with Python 3.2.3? Can anybody help? Thank you in advance. Peter Farrell -- http://mail.python.org/mailman/listinfo/python-list
Re: Numpy module
On Sun, Oct 28, 2012 at 10:40 PM, wrote: > I've learned a lot about Ubuntu just trying to install numpy for Python > 3.2.3. I've finally managed to put it in the Python3.2 directory but when I > try to import it, I still get there's "no module named numpy." There are > other modules in the same directory, like 'email' and it imports fine. A. It properly belongs under "site-packages" B. You ought to just install it using pip (http://www.pip-installer.org ) or apt-get, rather than manually. > Does Numpy 1.6.2 not run with Python 3.2.3? They are compatible. http://scipy.github.com/faq.html#do-numpy-and-scipy-support-python-3-x : "The first release of NumPy to support Python 3 was NumPy 1.5.0." Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list