Re: howto remove the thousand separator
On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote: On 15/04/2013 02:14, Steven D'Aprano wrote: On Sun, 14 Apr 2013 17:44:28 -0700, Mark Janssen wrote: On Sun, Apr 14, 2013 at 5:29 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote: cleaned='' for c in myStringNumber: if c != ',': cleaned+=c int(cleaned) due to being an O(N**2) algorithm. What on earth makes you think that is an O(n**2) algorithm and not O(n)? Strings are immutable. Consider building up a single string from four substrings: s = '' s += 'fe' s += 'fi' s += 'fo' s += 'fum' Python *might* optimize the first concatenation, '' + 'fe', to just reuse 'fe', (but it might not). Let's assume it does, so that no copying is needed. Then it gets to the second concatenation, and now it has to copy characters, because strings are immutable and cannot be modified in place. Actually, I believe that CPython is optimised to modify strings in place where possible, so that the above would surprisingly turn out to be O(n). See the following thread where I asked about this: I deliberately didn't open that can of worms, mostly because I was in a hurry, but also because it's not an optimization you can rely on. It depends on the version, implementation, operating system, and the exact code running. 1) It only applies to code running under some, but not all, versions of CPython. It does not apply to PyPy, Jython, IronPython, and probably not other implementations. 2) Even under CPython, it can fail. It *will* fail if you have multiple references to the same strings. And it *may* fail depending on the vagaries of the memory management system in place, e.g. code that is optimized on Linux may fail to optimize under Windows, leading to slow code. As far as I'm concerned, the best advice regarding this optimization is: - always program as if it doesn't exist; - but be glad it does when you're writing quick and dirty code in the interactive interpreter, where the convenience of string concatenation may be just too darn convenient to bother doing the right thing. http://groups.google.com/group/comp.lang.python/browse_thread/ thread/990a695fe2d85c52 (Sorry for linking to Google Groups. Does anyone know of a better c.l.p. web archive?) The canonical (although possibly not the best) archive for c.l.p. is the python-list mailing list archive: http://mail.python.org/mailman/listinfo/python-list -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: howto remove the thousand separator
On Sun, 14 Apr 2013 22:35:42 -0400, Roy Smith wrote: In article kkfodv$f5m$1...@news.albasani.net, Walter Hurry walterhu...@lavabit.com wrote: On Mon, 15 Apr 2013 11:29:17 +1000, Chris Angelico wrote: There are actually a lot of optimizations done, so it might turn out to be O(n) in practice. But strictly in the Python code, yes, this is definitely O(n*n). In any event, Janssen should cease and desist offering advice here if he can't do better than that. That's a little harsh. Sure, it was a sub-optimal way to write the code (for all the reasons people mentioned), but it engendered a good discussion. Agreed. I'd rather people come out with poor code, and LEARN from the answers, than feel that they dare not reply until they're an expert. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: classes and sub classes?
Jason Friedman wrote: NwInvDb = NetworkInventoryDatabase, yes you are correct, it creates the database handle and makes it ready for use. I am interested in opinions. I for one dislike abbreviations on the theory that programs are read more than they are written. I would probably use this variable name: network_inventory_db_connection = ... And yes, I'm aware that db is an abbreviation. I believe I am following a few Zen principles: Beautiful is better than ugly. Explicit is better than implicit. Readability counts. Special cases aren't special enough to break the rules, Although practicality beats purity. What would others use? inventory_db The rest should be clear from the context. -- http://mail.python.org/mailman/listinfo/python-list
Re: howto remove the thousand separator
On Mon, Apr 15, 2013 at 5:03 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote: On 15/04/2013 02:14, Steven D'Aprano wrote: Strings are immutable. Consider building up a single string from four substrings: Actually, I believe that CPython is optimised to modify strings in place where possible, so that the above would surprisingly turn out to be O(n). See the following thread where I asked about this: I deliberately didn't open that can of worms, mostly because I was in a hurry, but also because it's not an optimization you can rely on. It depends on the version, implementation, operating system, and the exact code running. As far as I'm concerned, the best advice regarding this optimization is: - always program as if it doesn't exist; - but be glad it does when you're writing quick and dirty code in the interactive interpreter, where the convenience of string concatenation may be just too darn convenient to bother doing the right thing. Agreed; that's why, in my reply, I emphasized that the pure Python code IS quadratic, even though the actual implementation might turn out linear. (I love that word might. Covers myriad possibilities on both sides.) Same goes for all sorts of other possibilities. I wouldn't test string equality with 'is' without explicit interning, even if I'm testing a constant against another constant in the same module - but I might get a big performance boost if the system's interned all its constants for me. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages
Mark Janssen writes: After the 2001 type/class unification , it went towards Alan Kay's ideal of everything is an object As a contrast, this is very distinct from C++, where everything is concretely rooted in the language's type model which in *itself* is rooted (from it's long history) in the CPU architecture. ... My question is: Is there something in the Computer Science literature that has noticed this distinction/development in programming language design and history? In programming language theory, there is no law to the effect that everything should be of one kind or another. So, we would not go with Alan Kay's ideal. Having said that, theorists do want to unify concepts wherever possible and wherever they make sense. Imperative programming types, which I will call storage types, are semantically the same as classes. Bare storage types have predefined operations for 'getting' and 'setting' whereas classes allow user-defined operations. So, the distinction made between them in typical programming languages is artificial and implementation-focused. C and C++ are especially prone to this problem because they were designed for writing compilers and operating systems where proximity to the machine architecture seems quite necessary. The higher-level languages such as Java are moving towards abolishing the distinction. Scala might be the best model in this respect, though I do not know its type system fully. Here are a couple of references in theoretical work that might be helpful in understanding these connections: - John Reynolds, The Essence of Algol, in de Bakker and van Vliet (eds) Algorithmic Languages, 1981. Also published in O'Hearn and Tennent (eds) Algol-like Languages, Vol. A, 1997. - Uday Reddy, Objects and Classes in Algol-like Languages, Information and Computation, 172:63-97, 2002. (previously in FOOL workshop 1998.) http://www.cs.bham.ac.uk/~udr/papers/classes.pdf However, there are properties that are special to storage types, which are not shared by all class types. Sometimes, they simplify some theoretical aspects. It is not uncommon for authors to make a distinction between storage types and general types. An example is one of our own papers: - Swarup, Reddy and Ireland: Assignments for applicative languages, FPCA 1991. http://www.cs.bham.ac.uk/~udr/papers/assign.pdf Cheers, Uday Reddy -- http://mail.python.org/mailman/listinfo/python-list
RE: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages
Date: Sun, 14 Apr 2013 22:55:59 -0700 From: deles...@gmail.com To: dreamingforw...@gmail.com CC: types-l...@lists.seas.upenn.edu; python-list@python.org Subject: Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list ] I'm not quite sure I understand your question, but I'll give it a shot. :-) I'm in this same camp too :) The C/C++ model, in which the types are anchored to the machine hardware, in the exception, not the rule. In the academic literature, type theory is almost entirely focused on studying abstract models of computation that are purely mathematical, and bear no resemblance to the underlying hardware. The lambda calculus is the most general, and most commonly used formalism, but there are many others; e.g. Featherweight Java provides a formal model of objects and classes as they are used in Java. Types and Programming Languages, by Benjamin Pierce, is an excellent introductory textbook which describes how various language features, including objects, can be formalized. If you are interested in OOP, Abadi and Cardelli's Theory of Objects is the obvious place to start, although I'd recommend reading Pierce's book first if you want to understand it. :-) Abadi and Cardelli discuss both class-based languages, and pure object languages. If you are interested in the type/object distinction in particular, then I'll shamelessly plug my own thesis: Pure Subtype Systems (available online), which describes a formal model in which types are objects, and objects are types. If you are familiar with the Self language, then you can think of it as a type system for Self. Offering a different view, I'd like to (also, shamelessly) plug my own thesis: NOOP: A Mathematical Model of OOP (available online) in which I denotationally model nominally-typed (ie, statically-typed class-based) OO languages such as Java, C#, C++ and Scala (but not Python). In agreement with the most common tradition in PL research, types in NOOP are modeled abstractly as (certain) sets (of objects). NOOP largely mimics, for nominally-typed OO languages, what Cardelli, Cook, and others earlier did for structurally-typed OO languages. Regards, -Moez Once you have a type system in place, it's usually fairly straightforward to compile a language down to actual hardware. An interpreter, like that used in Python, is generally needed only for untyped or dynamic languages. There are various practical considerations -- memory layout, boxed or unboxed data types, garbage collection, etc. -- but the basic techniques are described in any compiler textbook. Research in the areas of typed assembly languages and proof carrying code are concerned with ensuring that the translation from high-level language to assembly language is sound, and well-typed at all stages. -DeLesley On Sun, Apr 14, 2013 at 8:48 PM, Mark Janssen dreamingforw...@gmail.comwrote: [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list] Hello, I'm new to the list and hoping this might be the right place to introduce something that has provoked a bit of an argument in my programming community. I'm from the Python programming community. Python is an interpreted language. Since 2001, Python's has migrated towards a pure Object model (ref: http://www.python.org/download/releases/2.2/descrintro/). Prior to then, it had both types and classes and these types were anchored to the underlying C code and the machine/hardware architecture itself. After the 2001 type/class unification , it went towards Alan Kay's ideal of everything is an object. From then, every user-defined class inherited from the abstract Object, rooted in nothing but a pure abstract ideal. The parser, lexer, and such spin these abstrations into something that can be run on the actual hardware. As a contrast, this is very distinct from C++, where everything is concretely rooted in the language's type model which in *itself* is rooted (from it's long history) in the CPU architecture. The STL, for example, has many Container types, but each of them requires using a single concrete type for homogenous containers or uses machine pointers to hold arbitrary items in heterogeneous containers (caveat: I haven't programmed in C++ for a long time, so it's possible this might not be correct anymore). My question is: Is there something in the Computer Science literature that has noticed this distinction/development in programming language design and history? It's very significant to me, because as languages went higher and higher to this pure OOP model, the programmer+data ecosystem tended towards very personal object hierarchies because now the hardware no longer formed a common basis of interaction (note also, OOPs
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
On Sun, 14 Apr 2013 20:48:05 -0700, Mark Janssen wrote: Hello, I'm new to the list and hoping this might be the right place to introduce something that has provoked a bit of an argument in my programming community. I'm from the Python programming community. Python is an interpreted language. Since 2001, Python's has migrated towards a pure Object model (ref: http://www.python.org/download/releases/2.2/descrintro/). Prior to then, it had both types and classes and these types were anchored to the underlying C code and the machine/hardware architecture itself. Incorrect. Python's data model has always been 100% object oriented. Prior to the class/type unification, it simply had *two distinct* implementations of objects: types, which were written in C, and classes, which were written in Python. After unification, the two kinds of object were no longer entirely distinct -- you could then subclass types in Python code, using the same class keyword as you would use for a pure-Python class. And starting with Python 3, the last vestiges of the distinction have disappeared. Now, class and type are mere synonyms. Both built-in types and custom classes use the same mechanism. After the 2001 type/class unification , it went towards Alan Kay's ideal of everything is an object. From then, every user-defined class inherited from the abstract Object, rooted in nothing but a pure abstract ideal. Incorrect. In Python 2.7: py class AClass: ... pass ... py issubclass(AClass, object) False -- Steven -- http://mail.python.org/mailman/listinfo/python-list
RE: Iterating dictionary items + if statement results in problems
hello Team, I have this fairly simple script to iterate the dictionary items and check if the items match certain values; dictionary={'1234567890':001, '0987654321':002} for k, v in dictionary.iteritems(): . . #suds client statements; if (k == '1234567890' and v == 001): criteria='Test' elif (k == '0987654321' and v == 002): criteria='Running' client.service.methodcall(value1,value2,criteria) During the first run of the dictionary items, the client.service.methodcall is called only once as expected; and a success initiation response is received from server. However, during the second run, the client.service.methodcall is called twice - when i check the log files, i see the client send request is done twice. Duplicate send requests of the same parameters results in a error in inititating a connection. Someone please show me why my second run results in the client.service.methodcall() running twice. I can't seem to get a hang on it. Saludos Ombongi Moraa Faith -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating dictionary items + if statement results in problems
On 15/04/2013 11:50, Ombongi Moraa Fe wrote: hello Team, I have this fairly simple script to iterate the dictionary items and check if the items match certain values; dictionary={'1234567890':001, '0987654321':002} for k, v in dictionary.iteritems(): . . #suds client statements; if (k == '1234567890' and v == 001): criteria='Test' elif (k == '0987654321' and v == 002): criteria='Running' client.service.methodcall(value1,value2,criteria) During the first run of the dictionary items, the client.service.methodcall is called only once as expected; and a success initiation response is received from server. However, during the second run, the client.service.methodcall is called twice - when i check the log files, i see the client send request is done twice. Duplicate send requests of the same parameters results in a error in inititating a connection. What makes you think there should be one call given the code above? client.service.methodcall must be called for every loop iteration, so there's one call with criteria 'test' and one with 'Running'. Note there's no guarantee that the calls will always take place in the same order. Slight aside there's no need for the round brackets in the if and elif above. Someone please show me why my second run results in the client.service.methodcall() running twice. I can't seem to get a hang on it. Saludos Ombongi Moraa Faith -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
RE: Iterating dictionary items + if statement results in problems
Ombongi Moraa Fe wrote: hello Team, I have this fairly simple script to iterate the dictionary items and check if the items match certain values; dictionary={'1234567890':001, '0987654321':002} for k, v in dictionary.iteritems(): . . #suds client statements; if (k == '1234567890' and v == 001): criteria='Test' elif (k == '0987654321' and v == 002): criteria='Running' client.service.methodcall(value1,value2,criteria) During the first run of the dictionary items, the client.service.methodcall is called only once as expected; and a success initiation response is received from server. However, during the second run, the client.service.methodcall is called twice - when i check the log files, i see the client send request is done twice. Duplicate send requests of the same parameters results in a error in inititating a connection. Someone please show me why my second run results in the client.service.methodcall() running twice. I can't seem to get a hang on it. methodcall() is inside the for-loop and will be repeated on every iteration. In your example code the dictionary has two entries -- therefore methodcall() will be invoked twice. If the length of the dictionary changes from 1 to 2 while your programm is running you will see the behaviour you described. One way to avoid the problem is to omit the loop: criteria = None if dictionary.get(1234567890) == 1: criteria = Test elif dictionary.get(0987654321) == 2: criteria = Running else: raise Exception(undefined criteria) # for example client.service.methodcall(value1, value2, criteria) Note that leading zeros are usually not a good idea as they mark integer constants as octal: 001 1 010 8 008 File stdin, line 1 008 ^ SyntaxError: invalid token -- http://mail.python.org/mailman/listinfo/python-list
Re: python-noob - which container is appropriate for later exporting into mySql + matplotlib ?
I am trying to understand your points Chris. On the one hand you say: On Apr 14, 6:22 pm, Chris Angelico ros...@gmail.com wrote: No, no, a thousand times no! If I am doing financial transactions, even if I'm alone on my machine, I will demand full ACID compliance. On the other you describe a bookmark storage scheme (which it seems you are recommending); to wit Suppose bookmarks are stored like this: rSome-Browser-Name web bookmarks file - edit with care url:http://www.google.com/ title: Search engine icon: whatever-format-you-want-to-use url:http://www.duckduckgo.com/ title: Another search engine url:http://www.python.org/ url:ftp://192.168.0.12/ title: My FTP Server desc: Photos are in photos/, videos are in videos/ Everything else is in other/ user: root pass: secret The parsing of this file is pretty simple. Blank line marks end of entry;… So are you saying that if one switches from the non-ACID compliant sqlite to your simple-text data-format, the new 'database' (note the quote marks) will now become ACID compliant? -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating dictionary items + if statement results in problems
On 04/15/2013 06:50 AM, Ombongi Moraa Fe wrote: hello Team, I have this fairly simple script to iterate the dictionary items and check if the items match certain values; dictionary={'1234567890':001, '0987654321':002} for k, v in dictionary.iteritems(): . . #suds client statements; if (k == '1234567890' and v == 001): criteria='Test' elif (k == '0987654321' and v == 002): criteria='Running' client.service.methodcall(value1,value2,criteria) That's not the whole script, since at the least, you need some code to import or create client, value1 and value2. During the first run of the dictionary items, What do you mean by that, exactly? Do you mean the first time around the loop? Or the first time the script is run? Or what? the client.service.methodcall is called only once as expected; and a success initiation response is received from server. However, during the second run, the client.service.methodcall is called twice - when i check the log files, i see the client send request is done twice. Duplicate send requests of the same parameters results in a error in inititating a connection. Someone please show me why my second run results in the client.service.methodcall() running twice. I can't seem to get a hang on it. Why not take out the middleman, and just add some prints in the loop? I don't see any point in the loop; if you're sure there are exactly two items in the dict, just process those two items. If you're not sure, what do you want to happen when you encounter something that doesn't match either the if or the elif. Currently, you'll just repeat the last methodcall. One final thing, a dict's order is not promised. So you may process these items in either as Test and Running, or in the reverse order. My guess is that this is not your actual code at all, and you're trying to simplify it for us. You probably have more than two items in the dict, and one of them is NOT matching any of the if/elif tests. Possibly it's not matching because of your mistaken use of octal. Octal won't hurt for ints below 8, but you probably don't restrict it in the real code. For example, v = 030 will not match equal in the following: elif v == 30: -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: classes and sub classes?
On 2013-04-15, Peter Otten __pete...@web.de wrote: Jason Friedman wrote: NwInvDb = NetworkInventoryDatabase, yes you are correct, it creates the database handle and makes it ready for use. I am interested in opinions. I for one dislike abbreviations on the theory that programs are read more than they are written. I would probably use this variable name: network_inventory_db_connection = ... And yes, I'm aware that db is an abbreviation. I believe I am following a few Zen principles: Beautiful is better than ugly. Explicit is better than implicit. Readability counts. Special cases aren't special enough to break the rules, Although practicality beats purity. What would others use? inventory_db The rest should be clear from the context. How long and descriptive a name is ought to depend on the wideness of its visibility. n might be acceptable in a short comprehension, while network_inventory_db_connection might be apposite for a module-level name. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: python-noob - which container is appropriate for later exporting into mySql + matplotlib ?
On Mon, Apr 15, 2013 at 9:45 PM, rusi rustompm...@gmail.com wrote: I am trying to understand your points Chris. On the one hand you say: On Apr 14, 6:22 pm, Chris Angelico ros...@gmail.com wrote: No, no, a thousand times no! If I am doing financial transactions, even if I'm alone on my machine, I will demand full ACID compliance. On the other you describe a bookmark storage scheme (which it seems you are recommending); to wit ... So are you saying that if one switches from the non-ACID compliant sqlite to your simple-text data-format, the new 'database' (note the quote marks) will now become ACID compliant? Unlikely. It theoretically could be made ACID compliant (all it needs is an OS-guaranteed atomic move/rename operation), but my point is that some things don't _need_ full-on databases. Financial work *does* (if I'm accepting money from people, I'd better make pretty sure I know who's paid me and how much); bookmarks usually don't. Also, bookmarks are the exclusive property of the person who creates them, so it's helpful to store them in a way that can be edited; with money movements, you often want some kind of indelibility guarantee, too (you can't go back and edit a previous transaction, you have to put in a correcting transaction). Different tasks demand different storage schemes. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Grammar question: Englisn and Python: qualified names
On 2013-04-15 07:50, Chris Angelico wrote: Quirky question time! ... or possibly a collections.OrderedDict... ... or possibly an collections.OrderedDict... If you're smart enough to elide the collections [dot] from your pronunciation, you're smart enough to adjust the a/an accordingly. Use the first one :-) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Making ETL from Access 97 to Access 2003
Hi, I need to take data from 5 differents (but similar) database in MS Access 97 and merge them into one MS Access 2003 database. Is some packages exist to do this task? Thank -- http://mail.python.org/mailman/listinfo/python-list
Re: Grammar question: Englisn and Python: qualified names
On Mon, Apr 15, 2013 at 10:28 PM, Tim Chase python.l...@tim.thechases.com wrote: On 2013-04-15 07:50, Chris Angelico wrote: Quirky question time! ... or possibly a collections.OrderedDict... ... or possibly an collections.OrderedDict... If you're smart enough to elide the collections [dot] from your pronunciation, you're smart enough to adjust the a/an accordingly. Use the first one :-) I like that reasoning. :) Thanks, all! ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Making ETL from Access 97 to Access 2003
On Apr 15, 5:27 pm, Steeve steeve.h...@gmail.com wrote: Hi, I need to take data from 5 differents (but similar) database in MS Access 97 and merge them into one MS Access 2003 database. Not sure what this had to do with python. However… You could write out the five as csvs and then read in those csvs. This is assuming that access 2003 cannot read in access 97. [Seems a bit surprising though] Is some packages exist to do this task? Dunno… Have you seen http://allenbrowne.com/ser-48.html ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating dictionary items + if statement results in problems
Hello Team, Thanks for your input. |Possibly it's not matching because of your mistaken use of octal. Octal won't hurt for ints below 8, but you probably don't restrict it in the real code. For example, v = 030 will not match equal in the following: I've changed the key,value pairs in the dictionary because of privacy commitment with my provider; |My guess is that this is not your actual code at all, and you're trying to simplify it for us. You probably have more than |two items in the dict, and one of them is NOT matching any of the if/elif tests. Currently, I only have 2 items in the dictionary. However, this is a test environment and in the product environ, my items will be as many as the number of services created on server for my connection. Currently, the production has 10 services (key,value pairs) I will only have a set number of key,value pairs and I cannot use other items outside this range. The connection to providerr wouldn't be establish for anything out of the allowed item ranges; |That's not the whole script, since at the least, you need some code to import or create client, value1 and value2. The other portion of script to import the client and get values of parameters value1 and value2 works well. I have tested the script without using dictionaries by manually changing the items within the dictionary, inside the code and it works successfully, establishing a connection for both items; Now I need to iterate this for the sake of numerous items in the production environment. And that's where I thought to bring in the if statement. |What makes you think there should be one call given the code above? client.service.methodcall must be called for every |loop iteration, so there's one call with criteria 'test' and one with 'Running'. Note there's no guarantee that the calls will |always take place in the same order. Yes, I do understand that the items in the dictionary are not ordered. And what I expect is one call with criteria 'Test' and one with 'Running'. From my logs file, the duplicate call always occurs at the last iteration of the dictionary items. In short, my problem arises after I include the if statement inside the loop. I am new to python but I am pretty sure my program syntax is correct here. If I run a print statement instead of the client.service.methodcall(value1, value2), my output is just Test Running 2 of the services in the production environment will require the criteria value. For the rest of the services, the method call will simply be client.service.methodcall(value1, value2) I need this criteria value in order to establish a service specific connection for these 2 matching key,value pairs; instead of a generalised connection as will be the case for any additional keys.this is where the else default statement will come in later on. Right now I need to be able to resolve the problem with my script as-it-is (with 2 dictionary items) Thanks in advance. Saludos Ombongi Moraa Faith -- http://mail.python.org/mailman/listinfo/python-list
Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages
On Apr 14, 2013, at 11:48 PM, Mark Janssen wrote: After the 2001 type/class unification , it went towards Alan Kay's ideal Are you sure? Remember Kay's two motivations [*], which he so elegantly describes with [the] large scale one was to find a better module scheme for complex systems involving hiding of details, and the small scale one was to find a more flexible version of assignment, and then to try to eliminate it altogether. At least for me, this quote sends a signal to language designers that is still looking for a receiver -- Matthias [*] http://gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html -- http://mail.python.org/mailman/listinfo/python-list
Cross-compiling Python for ARM?
Hello I tried running uWSGI on an ARM-based appliance, but it fails. Apparently, it could be due to the official Python 2.6.6 interpreter in the depot not being compiled the way uWSGI expects it to be: ./configure --enable-shared; make; make install; www.raspberrypi.org/phpBB3/viewtopic.php?f=32t=15370 I see Python mentioned in /usr/lib and /usr/share, and was wondering if all it'd take to solve this issue, is just to cross-compile the interpreter and the rest is just CPU-agnostic Python scripts. Just in case, here's the output: www.pastebin.com/wJHjBrfn Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Making ETL from Access 97 to Access 2003
rusi rustompm...@gmail.com wrote in message news:ff550c58-58b0-4bf2-bf12-08986ab2b...@ka6g2000pbb.googlegroups.com... On Apr 15, 5:27 pm, Steeve steeve.h...@gmail.com wrote: Hi, I need to take data from 5 differents (but similar) database in MS Access 97 and merge them into one MS Access 2003 database. Not sure what this had to do with python. However You could write out the five as csvs and then read in those csvs. This is assuming that access 2003 cannot read in access 97. [Seems a bit surprising though] Is some packages exist to do this task? Dunno Have you seen http://allenbrowne.com/ser-48.html ? If there are indices and especially linked primary and foreign keys its much more complicated than that. One has to delve into Access container structures etc. As far as I know it has to be done from Access. Paul Simon -- http://mail.python.org/mailman/listinfo/python-list
Re: Making ETL from Access 97 to Access 2003
Its hard to distinguish what you are saying from what I said because you've lost the quotes. On Apr 15, 9:01 pm, Paul Simon psi...@sonic.net wrote: rusi rustompm...@gmail.com wrote in message news:ff550c58-58b0-4bf2-bf12-08986ab2b...@ka6g2000pbb.googlegroups.com... On Apr 15, 5:27 pm, Steeve steeve.h...@gmail.com wrote: Hi, I need to take data from 5 differents (but similar) database in MS Access 97 and merge them into one MS Access 2003 database. Not sure what this had to do with python. However… You could write out the five as csvs and then read in those csvs. This is assuming that access 2003 cannot read in access 97. [Seems a bit surprising though] Is some packages exist to do this task? Dunno… Have you seenhttp://allenbrowne.com/ser-48.html? If there are indices and especially linked primary and foreign keys its much more complicated than that. One has to delve into Access container structures etc. As far as I know it has to be done from Access. I assume you are saying this for my csv suggestion? Yes of course. I gave this as the last resort if direct import and other such attempts dont work out. -- http://mail.python.org/mailman/listinfo/python-list
Re: Threadpool item mailboxes design problem
On 04/14/2013 07:32 PM, Chris Rebert wrote: On Apr 14, 2013 4:27 PM, Charles Hixson charleshi...@earthlink.net mailto:charleshi...@earthlink.net wrote: What is the best approach to implementing actors that accept and post messages (and have no other external contacts). You might look at how some of the existing Python actor libraries are implemented (perhaps one of these might even save you from reinventing the wheel): http://www.pykka.org/en/latest/ http://www.kamaelia.org/Docs/Axon/Axon.html https://pypi.python.org/pypi/pulsar Kinda old: http://candygram.sourceforge.net/contents.html http://osl.cs.uiuc.edu/parley/ Candygram looks interesting. I'd forgotten about it. The others look either a bit limited (in different ways), or overly general, with the costs that that brings. I'll need to study Candygram a bit more. However, even Candygram seems to have a RAM centric model that I'd need to work around. (Well, the mailbox synchronization must clearly be RAM centric, but the storage shouldn't be.) So far what I've come up with is something like: actors = {} mailboxs = {} Stuff actors with actor instances, mailboxes with multiprocessing.queue instances. (Actors and mailboxes will have identical keys, which are id#, but it's got to be a dict rather than a list, because too many are rolled out to disk.) And I'm planning of having the actors running simultaneously and continually in a threadpool that just loops through the actors that are assigned to each thread of the pool. snip It would, however, be better if the mailbox could be specific to the threadpool instance, so less space would be wasted. Or if the queues could dynamically resize. Or if there was a threadsafe dict. Or... But I don't know that any of these are feasible. (I mean, yes, I could write all the mail to a database, but is that a better answer, or even a good one?) My recollection is that the built-in collection types are threadsafe at least to the limited extent that the operations exposed by their APIs (e.g. dict.setdefault) are atomic. Perhaps someone will be able to chime in with more details. If list operations were threadsafe, why would multiprocessing.queue have been created? I don't recall any claim that they were. Still, I've found an assertion on StackOverflow that they are...at least for simple assignment and reading. And the same would appear to be true of dicts from that post. This *does* require that either the index be constant, and the stored value be constant, or that the code section be locked during the access. Fortunately I'm intending to have id#s be unchangable, and the messages to be tuples, and thus constant. OTOH, to use this approach I'll need to find some way to guarantee that removing messages and posting messages don't occur at the same time. So that still means I'll need to lock each access. The answer that seems best is for each thread to have a mailbox that cells within the thread post and read messages from. This will automatically deal with internal to thread synchronization. Then I'll need a mailman thread that... This seems a promising approach, that avoids the problem of fixed length queues, but I'll still need to do a lot of synchronization. Still, it's a lot less, and each thread would be locked for shorter amounts of time. -- Charles Hixson -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating dictionary items + if statement results in problems
On 04/15/2013 09:37 AM, Ombongi Moraa Fe wrote: Hello Team, Thanks for your input. |Possibly it's not matching because of your mistaken use of octal. Octal won't hurt for ints below 8, but you probably don't restrict it in the real code. For example, v = 030 will not match equal in the following: I've changed the key,value pairs in the dictionary because of privacy commitment with my provider; |My guess is that this is not your actual code at all, and you're trying to simplify it for us. You probably have more than |two items in the dict, and one of them is NOT matching any of the if/elif tests. Currently, I only have 2 items in the dictionary. However, this is a test environment and in the product environ, my items will be as many as the number of services created on server for my connection. Currently, the production has 10 services (key,value pairs) I will only have a set number of key,value pairs and I cannot use other items outside this range. The connection to providerr wouldn't be establish for anything out of the allowed item ranges; |That's not the whole script, since at the least, you need some code to import or create client, value1 and value2. The other portion of script to import the client and get values of parameters value1 and value2 works well. I have tested the script without using dictionaries by manually changing the items within the dictionary, inside the code and it works successfully, establishing a connection for both items; Now I need to iterate this for the sake of numerous items in the production environment. And that's where I thought to bring in the if statement. |What makes you think there should be one call given the code above? client.service.methodcall must be called for every |loop iteration, so there's one call with criteria 'test' and one with 'Running'. Note there's no guarantee that the calls will |always take place in the same order. Yes, I do understand that the items in the dictionary are not ordered. And what I expect is one call with criteria 'Test' and one with 'Running'. From my logs file, the duplicate call always occurs at the last iteration of the dictionary items. Do you mean there are 3 calls to that method, with only two items in the dictionary?? More likely, there's some logic inside the method that's faking an extra log entry. In short, my problem arises after I include the if statement inside the loop. I am new to python but I am pretty sure my program syntax is correct here. If I run a print statement instead of the client.service.methodcall(value1, value2), my output is just Test Running 2 of the services in the production environment will require the criteria value. For the rest of the services, the method call will simply be client.service.methodcall(value1, value2) I need this criteria value in order to establish a service specific connection for these 2 matching key,value pairs; instead of a generalised connection as will be the case for any additional keys.this is where the else default statement will come in later on. Right now I need to be able to resolve the problem with my script as-it-is (with 2 dictionary items) As far as I can see, there's no problem with the script, as far as it goes. If you replace the method call with a print statement, and it suddenly starts working, then by definition, there's something wrong with the method. We cannot help there. Many times, we can play detective, and guess what's going on without running a program. Since we've told you what we each have found, and you haven't posted any new version of the code, that's about all we can do. Perhaps someone else who hasn't chimed in can help. But if I were you, I'd post a self-contained program that demonstrates the problem. Or maybe it's because you're posting in html, rather than the expected text, and you have some indent problem that doesn't show up after converting round trip. Please tell your email program to use text message format when posting here. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
Op 15-04-13 12:11, Steven D'Aprano schreef: Python's data model has always been 100% object oriented. Prior to the class/type unification, it simply had *two distinct* implementations of objects: types, which were written in C, and classes, which were written in Python. After unification, the two kinds of object were no longer entirely distinct -- you could then subclass types in Python code, using the same class keyword as you would use for a pure-Python class. And starting with Python 3, the last vestiges of the distinction have disappeared. Now, class and type are mere synonyms. Both built-in types and custom classes use the same mechanism. I had gotten my hopes up after reading this but then I tried: $ python3 Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. class vslice (slice): ... pass ... Traceback (most recent call last): File stdin, line 1, in module TypeError: type 'slice' is not an acceptable base type It seems types and classes are still not mere synonyms. -- http://mail.python.org/mailman/listinfo/python-list
Process tuple contents on the fly
Say I have a tuple I want to expand assigning to variables: tup = *func() var = tup[0] lst.append(tup[1]) Or could I do it in one line? var, lst.append() = *func() So I want to append one variable to a list on the fly, is it possible? -- Gnarlie http://gnarlodious.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode issue with Python v3.3
Hello, can you still help me please? -- http://mail.python.org/mailman/listinfo/python-list
Re: Process tuple contents on the fly
On 2013-04-15 11:25, Gnarlodious wrote: Say I have a tuple I want to expand assigning to variables: tup = *func() var = tup[0] lst.append(tup[1]) Or could I do it in one line? var, lst.append() = *func() So I want to append one variable to a list on the fly, is it possible? I stumbled across this atrocity[*], which if you chose to use it, you'd deserve a kick in the pants: lst.append(Value I don't care about and will overwrite) var, lst[-1] = *func() It's not quite one step, but at least the *assignment* is one step :-) -tkc [*] my original discovery was d = {} for key, d[key] in ((this,18), (that,17), (other,38)): print key do_something(d) but the same applies to a plain ol' assignment statement as to an assignment in a for loop. -- http://mail.python.org/mailman/listinfo/python-list
Re: Process tuple contents on the fly
d = {} for key, d[key] in ((this,18), (that,17), (other,38)): print key do_something(d) Why not use a dict comprehension? d = {k:v for k,v in ((this,18), (that,17), (other,38))} I feel this is more straightforward and easier to read. the results are the same however. -- http://mail.python.org/mailman/listinfo/python-list
Re: Process tuple contents on the fly
Tim Chase wrote: On 2013-04-15 11:25, Gnarlodious wrote: Say I have a tuple I want to expand assigning to variables: tup = *func() var = tup[0] lst.append(tup[1]) Or could I do it in one line? var, lst.append() = *func() So I want to append one variable to a list on the fly, is it possible? I stumbled across this atrocity[*], which if you chose to use it, you'd deserve a kick in the pants: lst.append(Value I don't care about and will overwrite) var, lst[-1] = *func() It's not quite one step, but at least the *assignment* is one step :-) I think the star is on the wrong side. So: items = [a, b, c] def f(result=(4, 5, 6)): return result ... var, *items[len(items):] = f() var 4 items ['a', 'b', 'c', 5, 6] -- http://mail.python.org/mailman/listinfo/python-list
Re: Process tuple contents on the fly
On 2013-04-15 12:05, Barrett Lewis wrote: d = {} for key, d[key] in ((this,18), (that,17), (other,38)): print key do_something(d) Why not use a dict comprehension? d = {k:v for k,v in ((this,18), (that,17), (other,38))} I feel this is more straightforward and easier to read. the results are the same however. In the particular case I did it in, I needed the incremental results passed to a function, not just the final result. I don't think this made it into the final code, rather it was expanded to be more readable. But the discovery made me feel a disturbance in the Pythonic force of the universe. :*) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Making ETL from Access 97 to Access 2003
rusi rustompm...@gmail.com wrote in message news:92551c63-1347-4f1a-9dca-d1bbd5e4d...@ys5g2000pbc.googlegroups.com... Its hard to distinguish what you are saying from what I said because you've lost the quotes. On Apr 15, 9:01 pm, Paul Simon psi...@sonic.net wrote: rusi rustompm...@gmail.com wrote in message news:ff550c58-58b0-4bf2-bf12-08986ab2b...@ka6g2000pbb.googlegroups.com... On Apr 15, 5:27 pm, Steeve steeve.h...@gmail.com wrote: Hi, I need to take data from 5 differents (but similar) database in MS Access 97 and merge them into one MS Access 2003 database. Not sure what this had to do with python. However You could write out the five as csvs and then read in those csvs. This is assuming that access 2003 cannot read in access 97. [Seems a bit surprising though] Is some packages exist to do this task? Dunno Have you seenhttp://allenbrowne.com/ser-48.html? If there are indices and especially linked primary and foreign keys its much more complicated than that. One has to delve into Access container structures etc. As far as I know it has to be done from Access. I assume you are saying this for my csv suggestion? Yes of course. I gave this as the last resort if direct import and other such attempts dont work out. Could you please append your comments instead of splitting them? Let me try to be clearer. If one only wants to merge tables, csv will work fine, exporting them from Access. Reconstucting keys and relationships can be done with some difficulty using Access' container model. See the Developer's Handbook by Getz, Litwin and Gilbert. Paul Simon -- http://mail.python.org/mailman/listinfo/python-list
Re: Process tuple contents on the fly
In the particular case I did it in, I needed the incremental results passed to a function, not just the final result. I don't think this made it into the final code, rather it was expanded to be more readable. But the discovery made me feel a disturbance in the Pythonic force of the universe. :*) -tkc I see what you are saying, but I agree that is a disturbance I didn't even know you could do for key, d[key], that just feels like bad news. however for what you are saying it makes sense. TIL that you can use an unpacked value during unpacking! -- http://mail.python.org/mailman/listinfo/python-list
Re: Process tuple contents on the fly
On 15/04/2013 20:05, Barrett Lewis wrote: d = {} for key, d[key] in ((this,18), (that,17), (other,38)): print key do_something(d) Why not use a dict comprehension? d = {k:v for k,v in ((this,18), (that,17), (other,38))} I feel this is more straightforward and easier to read. the results are the same however. Why use a dict comprehension? :-) d = dict(((this,18), (that,17), (other,38))} -- http://mail.python.org/mailman/listinfo/python-list
Re: Process tuple contents on the fly
On 04/15/2013 11:25 AM, Gnarlodious wrote: Say I have a tuple I want to expand assigning to variables: tup = *func() What is the asterisk for? I assume it's a python 3 thing, because I get a syntax error, but I'm having trouble Googling it. Thanks, Tobiah -- http://mail.python.org/mailman/listinfo/python-list
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
On 04/15/2013 01:43 PM, Antoon Pardon wrote: Op 15-04-13 12:11, Steven D'Aprano schreef: Python's data model has always been 100% object oriented. Prior to the class/type unification, it simply had *two distinct* implementations of objects: types, which were written in C, and classes, which were written in Python. After unification, the two kinds of object were no longer entirely distinct -- you could then subclass types in Python code, using the same class keyword as you would use for a pure-Python class. And starting with Python 3, the last vestiges of the distinction have disappeared. Now, class and type are mere synonyms. Both built-in types and custom classes use the same mechanism. I had gotten my hopes up after reading this but then I tried: $ python3 Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. class vslice (slice): ... pass ... Traceback (most recent call last): File stdin, line 1, in module TypeError: type 'slice' is not an acceptable base type It seems types and classes are still not mere synonyms. No, it seems you're trying to use an internal detail as though it were a supported feature. From page: http://docs.python.org/3.3/reference/datamodel.html#types Internal types A few types used internally by the interpreter are exposed to the user. Their definitions may change with future versions of the interpreter, but they are mentioned here for completeness. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Process tuple contents on the fly
On 04/15/2013 02:35 PM, Tobiah wrote: On 04/15/2013 11:25 AM, Gnarlodious wrote: Say I have a tuple I want to expand assigning to variables: tup = *func() What is the asterisk for? I assume it's a python 3 thing, because I get a syntax error, but I'm having trouble Googling it. No it's not. It's a tuple unpack operator. It's commonly used in this context: def func1(*args, **kwargs): #func1 can take variable args # do stuff func2( *args ) #unpack the variable args and pass them to func2 func3( *args ) func4( *args, **kwargs) def func2( a, b, c): d = a + b + c def func3 ( *args ): pass def func4 ( *args, **kwargs): pass func1(1,2,3) -- http://mail.python.org/mailman/listinfo/python-list
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
On 15/04/2013 22:13, Dave Angel wrote: On 04/15/2013 01:43 PM, Antoon Pardon wrote: [...] I had gotten my hopes up after reading this but then I tried: $ python3 Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. class vslice (slice): ... pass ... Traceback (most recent call last): File stdin, line 1, in module TypeError: type 'slice' is not an acceptable base type It seems types and classes are still not mere synonyms. No, it seems you're trying to use an internal detail as though it were a supported feature. From page: http://docs.python.org/3.3/reference/datamodel.html#types Internal types A few types used internally by the interpreter are exposed to the user. Their definitions may change with future versions of the interpreter, but they are mentioned here for completeness. To be fair, one can't do this either: Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32 Type copyright, credits or license() for more information. class C(type(lambda: None)): pass Traceback (most recent call last): File pyshell#2, line 1, in module class C(type(lambda: None)): TypeError: type 'function' is not an acceptable base type and I don't think that FunctionType would be considered an internal detail, would it? Not that I'd cite the fact that not all types can be inherited from as evidence that types and classes are not synonyms, mind. -- http://mail.python.org/mailman/listinfo/python-list
Re: howto remove the thousand separator
On 15/04/2013 08:03, Steven D'Aprano wrote: On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote: [...] (Sorry for linking to Google Groups. Does anyone know of a better c.l.p. web archive?) The canonical (although possibly not the best) archive for c.l.p. is the python-list mailing list archive: http://mail.python.org/mailman/listinfo/python-list Thanks to both you and Ned. -- http://mail.python.org/mailman/listinfo/python-list
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
On Tue, Apr 16, 2013 at 8:12 AM, Rotwang sg...@hotmail.co.uk wrote: Traceback (most recent call last): File pyshell#2, line 1, in module class C(type(lambda: None)): TypeError: type 'function' is not an acceptable base type and I don't think that FunctionType would be considered an internal detail, would it? Not that I'd cite the fact that not all types can be inherited from as evidence that types and classes are not synonyms, mind. Actually, I'm not sure how you'd go about inheriting from a function. Why not just create a bare class, then assign its __call__ to be the function you're inheriting from? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
On 15/04/2013 23:32, Chris Angelico wrote: On Tue, Apr 16, 2013 at 8:12 AM, Rotwang sg...@hotmail.co.uk wrote: Traceback (most recent call last): File pyshell#2, line 1, in module class C(type(lambda: None)): TypeError: type 'function' is not an acceptable base type and I don't think that FunctionType would be considered an internal detail, would it? Not that I'd cite the fact that not all types can be inherited from as evidence that types and classes are not synonyms, mind. Actually, I'm not sure how you'd go about inheriting from a function. Why not just create a bare class, then assign its __call__ to be the function you're inheriting from? No idea. I wasn't suggesting that trying to inherit from FunctionType was a sensible thing to do; I was merely pointing out that slice's status as an internal feature was not IMO relevant to the point that Antoon was making. -- http://mail.python.org/mailman/listinfo/python-list
Re: Process tuple contents on the fly
On Monday, April 15, 2013 2:35:10 PM UTC-6, Tobiah wrote: tup = *func() What is the asterisk for? I assume it's a python 3 Not Python 3, pseudocode. I should have said as such, sorry. Supposed to indicate an expanded tuple. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross-compiling Python for ARM?
On 4/15/2013 11:20 AM, Gilles wrote: Hello I tried running uWSGI on an ARM-based appliance, but it fails. Apparently, it could be due to the official Python 2.6.6 interpreter in the depot not being compiled the way uWSGI expects it to be: ./configure --enable-shared; make; make install; www.raspberrypi.org/phpBB3/viewtopic.php?f=32t=15370 I see Python mentioned in /usr/lib and /usr/share, and was wondering if all it'd take to solve this issue, is just to cross-compile the interpreter and the rest is just CPU-agnostic Python scripts. Just in case, here's the output: www.pastebin.com/wJHjBrfn I believe some cross-compile support was added to 2.7.4 but I do not know the exact nature. -- http://mail.python.org/mailman/listinfo/python-list
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
On 4/15/2013 1:43 PM, Antoon Pardon wrote: $ python3 Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. class vslice (slice): ... pass ... Traceback (most recent call last): File stdin, line 1, in module TypeError: type 'slice' is not an acceptable base type It seems types and classes are still not mere synonyms. Some builtin classes cannot be subclassed. There is an issue to document which better. That does not mean that it is not a class. -- http://mail.python.org/mailman/listinfo/python-list
Re: Threadpool item mailboxes design problem
On 04/15/2013 10:14 AM, Charles Hixson wrote: On 04/14/2013 07:32 PM, Chris Rebert wrote: On Apr 14, 2013 4:27 PM, Charles Hixson charleshi...@earthlink.net mailto:charleshi...@earthlink.net wrote: What is the best approach to implementing actors that accept and post messages (and have no other external contacts). You might look at how some of the existing Python actor libraries are implemented (perhaps one of these might even save you from reinventing the wheel): http://www.pykka.org/en/latest/ http://www.kamaelia.org/Docs/Axon/Axon.html https://pypi.python.org/pypi/pulsar Kinda old: http://candygram.sourceforge.net/contents.html http://osl.cs.uiuc.edu/parley/ Candygram looks interesting. I'd forgotten about it. The others look either a bit limited (in different ways), or overly general, with the costs that that brings. I'll need to study Candygram a bit more. However, even Candygram seems to have a RAM centric model that I'd need to work around. (Well, the mailbox synchronization must clearly be RAM centric, but the storage shouldn't be.) So far what I've come up with is something like: actors = {} mailboxs = {} Stuff actors with actor instances, mailboxes with multiprocessing.queue instances. (Actors and mailboxes will have identical keys, which are id#, but it's got to be a dict rather than a list, because too many are rolled out to disk.) And I'm planning of having the actors running simultaneously and continually in a threadpool that just loops through the actors that are assigned to each thread of the pool. snip It would, however, be better if the mailbox could be specific to the threadpool instance, so less space would be wasted. Or if the queues could dynamically resize. Or if there was a threadsafe dict. Or... But I don't know that any of these are feasible. (I mean, yes, I could write all the mail to a database, but is that a better answer, or even a good one?) My recollection is that the built-in collection types are threadsafe at least to the limited extent that the operations exposed by their APIs (e.g. dict.setdefault) are atomic. Perhaps someone will be able to chime in with more details. If list operations were threadsafe, why would multiprocessing.queue have been created? I don't recall any claim that they were. Still, I've found an assertion on StackOverflow that they are...at least for simple assignment and reading. And the same would appear to be true of dicts from that post. This *does* require that either the index be constant, and the stored value be constant, or that the code section be locked during the access. Fortunately I'm intending to have id#s be unchangable, and the messages to be tuples, and thus constant. OTOH, to use this approach I'll need to find some way to guarantee that removing messages and posting messages don't occur at the same time. So that still means I'll need to lock each access. The answer that seems best is for each thread to have a mailbox that cells within the thread post and read messages from. This will automatically deal with internal to thread synchronization. Then I'll need a mailman thread that... This seems a promising approach, that avoids the problem of fixed length queues, but I'll still need to do a lot of synchronization. Still, it's a lot less, and each thread would be locked for shorter amounts of time. -- Charles Hixson Currently it looks as if Pyro is the best option. It appears that Python threads are very contentious, so I'll need to run in processes rather than in threads, but I'll still need to transfer messages back and forth. I'll probably use UnixSockets rather than IP, but this could change...and using Pyro would make changing it easy. Still, pickle is used in code transmission, and that makes IP a questionable choice. -- Charles Hixson -- http://mail.python.org/mailman/listinfo/python-list
Python with Apache
I am trying to execute cgi101.py: #!/usr/bin/python import cgi form = cgi.FieldStorage() # parse form data print('Content-type: text/html\n')# hdr plus blank line print('titleReply Page/title')# html reply page if not 'user' in form: print('h1Who are you?/h1') else: print('h1Hello i%s/i!/h1' % cgi.escape(form['user'].value)) I have installed mod_python do apache2 and created one entry in /etc/apache2/sites-available/default: DocumentRoot /var/www Directory /var/www/py/ AddHandler mod_python .py PythonHandler cgi101 PythonDebug On /Directory What. happen is: when i call this file on browser I have the following error: Can someone help? MOD_PYTHON ERROR ProcessId: 2742 Interpreter:'127.0.1.1' ServerName: '127.0.1.1' DocumentRoot: '/var/www' URI:'/py/cgi101.py' Location: None Directory: '/var/www/py/' Filename: '/var/www/py/cgi101.py' PathInfo: '' Phase: 'PythonHandler' Handler:'cgi101' Traceback (most recent call last): File /usr/lib/python2.7/dist-packages/mod_python/importer.py, line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File /usr/lib/python2.7/dist-packages/mod_python/importer.py, line 1206, in _process_target object = apache.resolve_object(module, object_str, arg, silent=silent) File /usr/lib/python2.7/dist-packages/mod_python/apache.py, line 696, in resolve_object raise AttributeError, s AttributeError: module '/var/www/py/cgi101.py' contains no 'handler' MODULE CACHE DETAILS Accessed: Mon Apr 15 22:02:42 2013 Generation: 0 _mp_63ea7b6576c7d3a5f48ef8741e8048b0 { FileName: '/var/www/py/cgi101.py' Instance: 1 [IMPORT] Generation: 1 Modified: Mon Apr 15 21:52:27 2013 Imported: Mon Apr 15 22:02:42 2013 } -- http://mail.python.org/mailman/listinfo/python-list
Re: Python with Apache
On 16/04/2013 03:02, Renato Barbosa Pim Pereira wrote: I am trying to execute cgi101.py: #!/usr/bin/python import cgi form = cgi.FieldStorage() # parse form data print('Content-type: text/html\n')# hdr plus blank line print('titleReply Page/title')# html reply page if not 'user' in form: print('h1Who are you?/h1') else: print('h1Hello i%s/i!/h1' % cgi.escape(form['user'].value)) I have installed mod_python do apache2 and created one entry in /etc/apache2/sites-available/default: DocumentRoot /var/www Directory /var/www/py/ AddHandler mod_python .py PythonHandler cgi101 PythonDebug On /Directory What. happen is: when i call this file on browser I have the following error: Can someone help? MOD_PYTHON ERROR ProcessId: 2742 Interpreter:'127.0.1.1' ServerName: '127.0.1.1' DocumentRoot: '/var/www' URI:'/py/cgi101.py' Location: None Directory: '/var/www/py/' Filename: '/var/www/py/cgi101.py' PathInfo: '' Phase: 'PythonHandler' Handler:'cgi101' Traceback (most recent call last): File /usr/lib/python2.7/dist-packages/mod_python/importer.py, line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File /usr/lib/python2.7/dist-packages/mod_python/importer.py, line 1206, in _process_target object = apache.resolve_object(module, object_str, arg, silent=silent) File /usr/lib/python2.7/dist-packages/mod_python/apache.py, line 696, in resolve_object raise AttributeError, s AttributeError: module '/var/www/py/cgi101.py' contains no 'handler' MODULE CACHE DETAILS Accessed: Mon Apr 15 22:02:42 2013 Generation: 0 _mp_63ea7b6576c7d3a5f48ef8741e8048b0 { FileName: '/var/www/py/cgi101.py' Instance: 1 [IMPORT] Generation: 1 Modified: Mon Apr 15 21:52:27 2013 Imported: Mon Apr 15 22:02:42 2013 } I think it's looking for a function called 'handler' in the module 'cgi101.py'. This might help you: http://www.modpython.org/live/mod_python-2.7.8/doc-html/tut-overview.html -- http://mail.python.org/mailman/listinfo/python-list
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
On Mon, 15 Apr 2013 20:52:58 -0400, Terry Jan Reedy wrote: On 4/15/2013 1:43 PM, Antoon Pardon wrote: $ python3 Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. class vslice (slice): ... pass ... Traceback (most recent call last): File stdin, line 1, in module TypeError: type 'slice' is not an acceptable base type It seems types and classes are still not mere synonyms. Some builtin classes cannot be subclassed. There is an issue to document which better. That does not mean that it is not a class. I think it is also important to document whether that is a language feature, or a mere restriction of the implementation. There is an important distinction to be made between: In CPython, you cannot subclass slice or FunctionType. Other Pythons may have more, or fewer, restrictions. and: No language that calls itself Python is permitted to allow slice and FunctionType to be subclassable. If I had a say in this, I would vote for the first case, with the possible exception of documented singleton types like NoneType and bool. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
On Mon, 15 Apr 2013 19:43:32 +0200, Antoon Pardon wrote: Op 15-04-13 12:11, Steven D'Aprano schreef: Python's data model has always been 100% object oriented. Prior to the class/type unification, it simply had *two distinct* implementations of objects: types, which were written in C, and classes, which were written in Python. After unification, the two kinds of object were no longer entirely distinct -- you could then subclass types in Python code, using the same class keyword as you would use for a pure-Python class. And starting with Python 3, the last vestiges of the distinction have disappeared. Now, class and type are mere synonyms. Both built-in types and custom classes use the same mechanism. I had gotten my hopes up after reading this but then I tried: $ python3 Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. class vslice (slice): ... pass ... Traceback (most recent call last): File stdin, line 1, in module TypeError: type 'slice' is not an acceptable base type It seems types and classes are still not mere synonyms. You are misinterpreting what you are reading. The mere fact that something cannot be subclassed doesn't mean anything. That's just a restriction put on the class by the implementation. It's not even clear that it is a guaranteed language restriction or a mere accident of implementation. With a bit of metaclass trickery, I could equally create a pure-Python class that cannot be easily subclassed. The proof that types and classes are the same in Python 3 is simple: py class C: ... pass ... py type(C) is type(int) is type(type) is type True The type of the pure-Python class is type itself. However, even this can be bypassed, using a metaclass! py class D(metaclass=Meta): ... pass ... py type(D) is type False py issubclass(type(D), type) True So when using a metaclass, the type of the class is not necessarily type itself, but it will be a subclass of type. This does not hold in Python 2.x, not for old-style classic classes. Classic classes are in a world of their own, distinct from types: # Python 2 py class C: ... pass ... py type(C) type 'classobj' py issubclass(type(C), type) False In Python 3, we can expect these two conditions to always hold: * all instances are instances of object; * all classes are instances of type. Notice that this implies that type and object are circularly defined: object, being a class, is an instance of type, but type, being an object, is an instance of object: py isinstance(type, object) True py isinstance(object, type) True These two conditions even apply to unsubclassable objects like slice: py isinstance(slice(1, 5, 2), object) True py isinstance(slice, type) True -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Grammar question: Englisn and Python: qualified names
On 15Apr2013 07:50, Chris Angelico ros...@gmail.com wrote: | Quirky question time! | | When you read out a qualified name, eg collections.OrderedDict, do you | read the qualifier (collections dot ordered dict), or do you elide | it (ordered dict)? I ask because it makes a difference to talking | about just one of them: | | ... or possibly a collections.OrderedDict... | ... or possibly an collections.OrderedDict... | | Written, the latter looks completely wrong; but if the name is read in | its short form, with the collections part being implicit, then an | is clearly correct! What do you think, experts and others? I do the former. -- Cameron Simpson c...@zip.com.au Nothing is so smiple that it can't get screwed up. -- http://mail.python.org/mailman/listinfo/python-list
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
On 4/15/2013 10:32 PM, Steven D'Aprano wrote: On Mon, 15 Apr 2013 20:52:58 -0400, Terry Jan Reedy wrote: Some builtin classes cannot be subclassed. There is an issue to document which better. That does not mean that it is not a class. I think it is also important to document whether that is a language feature, or a mere restriction of the implementation. There is an important distinction to be made between: In CPython, you cannot subclass slice or FunctionType. Other Pythons may have more, or fewer, restrictions. and: No language that calls itself Python is permitted to allow slice and FunctionType to be subclassable. If I had a say in this, I would vote for the first case, with the possible exception of documented singleton types like NoneType and bool. I will keep the above in mind if I write or review a patch. here are 4 non-subclassable builtin classes. Two are already documented. Bool in one, forget which other. I believe it was recently decided to leave the other two as is given the absence of any practical use case. -- http://mail.python.org/mailman/listinfo/python-list
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
On Mon, Apr 15, 2013 at 9:17 PM, Terry Jan Reedy tjre...@udel.edu wrote: I will keep the above in mind if I write or review a patch. here are 4 non-subclassable builtin classes. Two are already documented. Bool in one, forget which other. I believe it was recently decided to leave the other two as is given the absence of any practical use case. The four are bool, NoneType, slice and ellipsis, I believe. -- http://mail.python.org/mailman/listinfo/python-list
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages
On Apr 16, 7:32 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: If I had a say in this, I would vote for the first case, with the possible exception of documented singleton types like NoneType and bool. How is bool a singleton type? -- http://mail.python.org/mailman/listinfo/python-list
[issue15281] pyvenv --symlinks option is a no-op?
Vinay Sajip added the comment: In this case couldn't symlinks be automatically used on Windows Vista or newer? It seems simpler if the default behaviour is the same on all Windows flavours - you can specify --symlinks if you're on Windows Vista or later. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15281 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15301] os.chown: OverflowError: Python int too large to convert to C long
Larry Hastings added the comment: Okay, I got inspired and (in the words of Barry Warsaw) JFDI. Attached is my revised patch. I took Serhiy's patch and reworked it quite a bit: * I think it's now easier to follow. In particular: * The most common case (no overflow) is now first. In Serhiy's patch the most common case is buried in the middle of the second if. * I removed some extraneous tests. * I changed the error messages to call the values uid and gid, to match the names of the parameters. * I noticed that _fd_converter had the same bad-idea PyFloat_Check, so I changed it to use PyNumber_Index instead. In the process I also noticed that Serhiy's approach had a resource leak: it never decref'd the result of PyNumber_Index() when successful. To make sure I duplicated Serhiy's semantics, I had a test harness that ran both his and mine and ensured they returned the same thing (or both threw an error). Obviously I removed all that before cutting the patch. -- Added file: http://bugs.python.org/file29860/larry.chown.unsigned.uid.gid.2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15301 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17731] test_iter_importers intermittent failure in test_pkgutil
Changes by Nick Coghlan ncogh...@gmail.com: -- assignee: - ncoghlan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17731 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15301] os.chown: OverflowError: Python int too large to convert to C long
Mark Dickinson added the comment: To answer Serhiy's question: I'd say that this level of cleanup is probably only appropriate for 3.4. Larry? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15301 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17713] test_logging fails in test_compute_rollover_weekly_attime
Roundup Robot added the comment: New changeset 193e7ad92900 by Vinay Sajip in branch 'default': Issue #17713: Added failure diagnostics to test. http://hg.python.org/cpython/rev/193e7ad92900 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17713 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17732] distutils.cfg Can Break venv
Vinay Sajip added the comment: This looks to me as if it will need a patch in distutils. Unlike virtualenv, which contains a patched copy of distutils (and hence allows having a .cfg adjacent to it), pyvenv does not create patched modules in the venv. It does not make sense to change this behaviour. The correct solution would appear to be for distutils to ignore certain configuration options (install-lib, but also equivalent options for headers and scripts) when running in a venv. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17732 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15301] os.chown: OverflowError: Python int too large to convert to C long
Larry Hastings added the comment: See my comment above (dated 2013-04-14 04:30). I'm passing the buck. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15301 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17703] Trash can mechanism segfault during interpreter finalization in Python 2.7.4
Marc-Andre Lemburg added the comment: Checked the patch: it fixes the problem. Thanks. Will this go into Python 2.7.5 ? I'm asking because we need to issue a patch level release of egenix-mx-base and if Python 2.7.5 will fix the problem, we'll just add the work-around for Python 2.7.4. Regarding a better cleanup logic: This is available in Python 3.x with the new module init logic and we'll use it there. PS: The approach with doing the cleanup at module startup time won't work, because the still existing objects will reference parts of the already cleaned up interpreter instance. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17703 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17707] Multiprocessing queue get method does not block for short timeouts
Giampaolo Rodola' added the comment: Maybe I'm misinterpreting what you wrote but the test fails before the patch and succeeds after it so what's the point in adding multiple tests with different timeouts? Also, rathr than using an harcoded delta, we could maybe use a fudger factor, like what's done for threading lock tests. Not sure what you refer to here. Feel free to submit a patch if you want. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17707 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17731] test_iter_importers intermittent failure in test_pkgutil
Nick Coghlan added the comment: spam is a fairly generic name, so I'm guessing something else is leaving a spam module around in sys.modules - when I run the tests with the order given in RDM's original report, I get the same error. I also get a failure in test_builtin though, which is a little weird. With the attached file, test_builtin fails (so one of the uncommented tests appears to be interfering with that), while test_pkgutil passes (suggesting that the problem there is one the tests flagged with #TEMP# -- Added file: http://bugs.python.org/file29861/test_order_issue17731.txt ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17731 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17708] sys.flags.hash_randomization doesn't return correct value
Changes by Christian Heimes li...@cheimes.de: -- nosy: +christian.heimes ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17708 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17732] distutils.cfg Can Break venv
Nick Sloan added the comment: That's along the lines of what I've been thinking as I dig into this. I'd love to take a stab at a patch for this if no one else has done so already. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17732 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17734] Failure when running test_builtin after test_genexps
New submission from Nick Coghlan: I'm getting a failure in test_builtin when running the following: ./python -m test -w test_genexps test_builtin == FAIL: test_input_tty_non_ascii (test.test_builtin.BuiltinTest) -- Traceback (most recent call last): File /home/ncoghlan/devel/py3k/Lib/test/test_builtin.py, line 1176, in test_input_tty_non_ascii self.check_input_tty(prompté, bquux\xe9, utf-8) File /home/ncoghlan/devel/py3k/Lib/test/test_builtin.py, line 1167, in check_input_tty self.assertEqual(input_result, expected) AssertionError: 'quux' != 'quux\udce9' - quux + quux\udce9 ? + == FAIL: test_input_tty_non_ascii_unicode_errors (test.test_builtin.BuiltinTest) -- Traceback (most recent call last): File /home/ncoghlan/devel/py3k/Lib/test/test_builtin.py, line 1180, in test_input_tty_non_ascii_unicode_errors self.check_input_tty(prompté, bquux\xe9, ascii) File /home/ncoghlan/devel/py3k/Lib/test/test_builtin.py, line 1167, in check_input_tty self.assertEqual(input_result, expected) AssertionError: 'quux' != 'quux\udce9' - quux + quux\udce9 ? + The problem persists after a make clean and rebuild. -- messages: 186979 nosy: haypo, ncoghlan priority: normal severity: normal stage: test needed status: open title: Failure when running test_builtin after test_genexps type: behavior versions: Python 3.3, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17734 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17731] test_iter_importers intermittent failure in test_pkgutil
Nick Coghlan added the comment: Created #17734 for the weird interference between test_genexps and test_builtin -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17731 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17636] Modify IMPORT_FROM to fallback on sys.modules
Changes by Pascal Chambon chambon.pas...@gmail.com: -- nosy: +Pascal.Chambon ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17636 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17353] Plistlib outputs empty data tags when deeply nested
Ronald Oussoren added the comment: I agree that plistlib shouldn't raise an exception for data that can represented as a valid plist file. I've checked that the Cocoa class for generating plist files will happily create a plist file when the data is nested 100 levels deep. In that case NSData values generate lines of 12 characters long. An unrelated issue: PlistWriter.writeValue should treat bytes instances the same as Data instances in Python 3. That would be a (small) feature enhencement, and hence can only be done for Python 3.4. -- Added file: http://bugs.python.org/file29862/deeply-nested-plist.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17353 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17353] Plistlib outputs empty data tags when deeply nested
Ronald Oussoren added the comment: The attach patch should fix the issue (but there needs to be a unittest as well). -- Added file: http://bugs.python.org/file29863/issue-17353.txt ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17353 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17735] inspect.findsource throws IndexError
New submission from Kyle Simpson: Here is one way to reproduce this bug: 1. Create a module file (bug.py in this example) def func(): pass 2. Run Python import bug help(bug) 3. Edit bug.py def func(): pass def newfunc(): pass 4. Use the same Python interpreter as in step 2 reload(bug) help(bug) 5. Observe traceback [..snip..] File C:\Python27\lib\inspect.py, line 578, in findsource if pat.match(lines[lnum]): break IndexError: list index out of range Note: A related but different issue is http://bugs.python.org/issue1218234. -- components: Library (Lib) messages: 186983 nosy: Kyle.Simpson priority: normal severity: normal status: open title: inspect.findsource throws IndexError type: behavior versions: Python 2.7, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17735 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17731] test_iter_importers intermittent failure in test_pkgutil
Roundup Robot added the comment: New changeset 73c79022977b by Nick Coghlan in branch '3.3': Close #17731: Clean up properly in test_import http://hg.python.org/cpython/rev/73c79022977b New changeset 5d4001e32a31 by Nick Coghlan in branch 'default': Merge fix for #17731 from 3.3 http://hg.python.org/cpython/rev/5d4001e32a31 -- nosy: +python-dev resolution: - fixed stage: needs patch - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17731 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17736] Misleading method comment in _elementtree.c : get_attrib_from_keywords
New submission from Jonas Wagner: The attached patch corrects a wrong method comment in _elementtree.c. It happened to be at Line 316, and was thus discovered by random sampling. [1] [1] http://www-cs-faculty.stanford.edu/~uno/316.html -- components: Extension Modules files: elementtree_get_attrib_from_keywords.patch keywords: patch messages: 186985 nosy: Sjlver priority: normal severity: normal status: open title: Misleading method comment in _elementtree.c : get_attrib_from_keywords type: enhancement versions: Python 3.2, Python 3.3, Python 3.4, Python 3.5 Added file: http://bugs.python.org/file29864/elementtree_get_attrib_from_keywords.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17736 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17716] From ... import fails when parent package failed but child module succeeded, yet works in std import case
Pascal Chambon added the comment: (sorry for the long post, but it's a complex issue I guess) I forgot to precise that I have this behaviour with the latest python2.7, as well as python3.3 (I guess other versions behave the same). I agree that having side effects in script imports looks dangerous, but on the other hand it's incredibly handy to use the script behaviour of module so that each one initializes/checks himself, rather than relying on the calling of initialization methods from somewhere else (many web frameworks don't even plan such setup scripts actually, I have a django ticket running on that subject just at the moment). Loads of python modules perform such inits (registration of atexit handlers, setup of loggers, of working/temp directories, or even modifying process-level settings.), so even though we're currently adding protection via exception handlers (and checking the idempotency of our imports, crucial points!), I could not guarantee that none of the modules/packages we use won't have such temporary failures (failures that can't be fixed by the web server, because module trees become forever unimportable). With the video and the importlib code, I'm beginning to have a better understanding on the from..import, and I noticed that actually both import mypkg.module_a and from mypkg import module_a get broken when mypkg raised an exception after successfully loading module_a. It's just that the second form breaks loudly, whereas the first one remains silently corrupted (i.e the variable mypkg.module_a does NOT exist in both cases, so theer are pending AttributeErrors anyway). All comes from the fact that - to talk with importlib/_bootstrap.py terms - _gcd_import() assumes everything is loaded and bound when a chain of modules (eg. mypkg.module_a) is in sys.modules, whereas intermediary bindings (setattr(mypkg, module_a, module_a)) might have been lost due to an import failure (and the removal of the mypkg module). Hum I wonder, could we just recheck all bindings inside that _gcd_import() ? I guess there would be annoying corner cases with circular imports, i.e we could end up creating these bindings whereas they are just pending to be done in parent frames... Issue 17636 might provide a workaround for some cases, but it doesn't fix the root problem of the rolled back import (eg. here the absence of binding between mypkg and module_a, whatever the import form that was used). Imagine a tree mypkg/mypkg2/module.py, if module.py gets well loaded but mypkg and mypkg2 fail, then later, somewhere else in the code, it seems an import mypkg.mypkg2.module will SUCCEED even though the module tree is broken, and AttributeErrors are pending. I guess Nick was right (and me wrong), the cleanest solution seems to enforce an invariant saying that a submodule can NOT fully be in sys.modules if his parent is not either loaded or in the process of loading it (thus if a binding between parent and child is missing, we're simply in the case of circular dependencies). Said another way, the import system should delete all children modules from sys.modules when aborting the import of a parent package. What do you think about it ? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17716 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17737] test_gdb fails on armv7hl
New submission from Bohuslav Slavek Kabrda: Hi, it seems that test_gdb fails on armv7hl on Fedora 19 and 20 [1] (I'm also tracking my notes of the bug there). Basically, the problem seems to come down to PyObjectPtr.subclass_from_type (file python-gdb.py) returning different values for members of the stack trace (compared to successful builds - see [3] for x86_64 successful build and [4] for armv7hl failed build). The two failed tests fail with: == FAIL: test_up_at_top (test.test_gdb.StackNavigationTests) Verify handling of py-up at the top of the stack -- Traceback (most recent call last): File /builddir/build/BUILD/Python-3.3.1/Lib/test/test_gdb.py, line 678, in test_up_at_top cmds_after_breakpoint=['py-up'] * 4) File /builddir/build/BUILD/Python-3.3.1/Lib/test/test_gdb.py, line 213, in get_stack_trace self.assertEqual(err, '') AssertionError: Python Exception class '__main__.NullPyObjectPtr' __main__.PyFrameObjectPtr [truncated]... != '' - Python Exception class '__main__.NullPyObjectPtr' __main__.PyFrameObjectPtr object at 0x23a6db0: - Error occurred in Python command: __main__.PyFrameObjectPtr object at 0x23a6db0 == FAIL: test_threads (test.test_gdb.PyBtTests) Verify that py-bt indicates threads that are waiting for the GIL -- Traceback (most recent call last): File /builddir/build/BUILD/Python-3.3.1/Lib/test/test_gdb.py, line 759, in test_threads cmds_after_breakpoint=['thread apply all py-bt']) File /builddir/build/BUILD/Python-3.3.1/Lib/test/test_gdb.py, line 213, in get_stack_trace self.assertEqual(err, '') AssertionError: Python Exception class 'gdb.error' There is no member named co_name.: \nError [truncated]... != '' - Python Exception class 'gdb.error' There is no member named co_name.: - Error occurred in Python command: There is no member named co_name. -- The whole build log is accessible at [2]. Any clues would be appreciated. Thanks. [1] https://bugzilla.redhat.com/show_bug.cgi?id=951802 [2] http://arm.koji.fedoraproject.org//work/tasks/2722/1712722/build.log [3] https://gist.github.com/bkabrda/5387906 [4] https://gist.github.com/bkabrda/5387908 -- components: Tests messages: 186987 nosy: bkabrda priority: normal severity: normal status: open title: test_gdb fails on armv7hl versions: Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17737 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17708] sys.flags.hash_randomization doesn't return correct value
Changes by Benjamin Peterson benja...@python.org: -- nosy: +dmalcolm ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17708 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17530] pprint could use line continuation for long bytes literals
Pam McA'Nulty added the comment: Here's a patch. I needed to handle the fact that the repr of a single byte can be 1, 2 or 4 characters long and did not want to wrap in the middle of a byte representation. Note also that bytes literals require a continuation character. In the pathological case where the wrap size is smaller than the representation of a single byte, I chose to always print at least one byte per line. As an aside, I also replaced the str wrapping code's calls to len with the cached _len used in the rest of pprint.py -- keywords: +patch nosy: +Pam.McANulty Added file: http://bugs.python.org/file29865/bytes_pprint.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17530 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17530] pprint could use line continuation for long bytes literals
Pam McA'Nulty added the comment: oops, forgot to add some samples: pprint.pprint(b\n\n\n\n\n\n, width=5) b'\n'\ b'\n'\ b'\n'\ b'\n'\ b'\n'\ b'\n' pprint.pprint({a: b\x00\xff * 20}) {'a': b'\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00'\ b'\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff'\ b'\x00\xff\x00\xff\x00\xff'} pprint.pprint({a: b\x00\xff * 20}, width=20) {'a': b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'\ b'\x00\xff'} pprint.pprint(b'a\x00\n\\x00', width=20) b'a\x00\n\\x00' -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17530 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17728] format() default precisions undocumented
Roundup Robot added the comment: New changeset 725d6347ac7e by Eric V. Smith in branch '2.7': Issue #17728: Specify default precision for float.format for presentation types e, f, and g. http://hg.python.org/cpython/rev/725d6347ac7e New changeset ad481c95a1d4 by Eric V. Smith in branch '3.3': Issue #17728: Specify default precision for float.format for presentation types e, f, and g. http://hg.python.org/cpython/rev/ad481c95a1d4 New changeset 413c0b0a105f by Eric V. Smith in branch 'default': Issue #17728: Merge with 3.3. http://hg.python.org/cpython/rev/413c0b0a105f -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17728 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17728] format() default precisions undocumented
Changes by Eric V. Smith e...@trueblade.com: -- resolution: - fixed stage: - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17728 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17737] test_gdb fails on armv7hl
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +dmalcolm ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17737 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17735] inspect.findsource throws IndexError
R. David Murray added the comment: Can you explain what makes this one a different problem? It looks like the same one to me. Or is your intent in this issue just to avoid the exception? In that case it seems to me it would better to fix issue 1218234 if we can. -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17735 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17738] Unnecessary if in SHA1_copy
New submission from Jonas Wagner: I'm puzzled by the following code in SHA1_copy (at python/Modules/sha1module.c:320 if (Py_TYPE(self) == SHA1type) { if ( (newobj = newSHA1object())==NULL) return NULL; } else { if ( (newobj = newSHA1object())==NULL) return NULL; } Both branches of the if-statement are identical; it would seem that the if is unnecessary. Its condition does not have any side effect. Attached is a patch that simplifies the code. This code happened to be at Line 316, and was thus discovered by random sampling. [1] [1] http://www-cs-faculty.stanford.edu/~uno/316.html -- components: Extension Modules files: sha1copy.patch keywords: patch messages: 186992 nosy: Sjlver priority: normal severity: normal status: open title: Unnecessary if in SHA1_copy versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5 Added file: http://bugs.python.org/file29866/sha1copy.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17738 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17530] pprint could use line continuation for long bytes literals
Antoine Pitrou added the comment: I don't understand why you say that bytes literals require a continuation character: (bx ... by) b'xy' [bx ... by] [b'xy'] I think the len caching is a misoptimization, it's useless here (most CPU time will be sent creating and wrapping the representation). Also perhaps it would be nice to refactor things a bit, since we have both _str_parts and _bytes_parts used in exactly the same way (but that can also be done later). As for the doc, the example would probably deserve to be a bit more meaningful :-) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17530 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8876] distutils should not assume that hardlinks will work
sorin added the comment: Can we have this merged, it prevents us form using distutil, especially in a continuous integration environment where you do not have control over the build server. See: https://drone.io/github.com/pycontribs/tendo/1 -- nosy: +sorin ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8876 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17530] pprint could use line continuation for long bytes literals
Pam McA'Nulty added the comment: - eval expects bytes to have a continuation character and test_str_wrap did an eval check so I figured test_bytes_wrap should as well: # repr some bytes: b = b\x00\xff * 5 b b'\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff' r = repr(b) r b'\\x00\\xff\\x00\\xff\\x00\\xff\\x00\\xff\\x00\\xff' eval(r) b'\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff' # hand-wrap it without the continuation character and it fails to eval (stuck the s = b'\\x00\\xff\\x00\\xff\\x00'\nb'\\xff\\x00\\xff\\x00\\xff' print(s) b'\x00\xff\x00\xff\x00' b'\xff\x00\xff\x00\xff' eval(s) Traceback (most recent call last): File stdin, line 1, in module File string, line 2 b'\xff\x00\xff\x00\xff' ^ SyntaxError: invalid syntax # stick the continuation character in, and it evals properly s = s.replace(\n, \\\n) print(s) b'\x00\xff\x00\xff\x00'\ b'\xff\x00\xff\x00\xff' eval(s) b'\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff' - I agree about the len v _len, but figured this wasn't all that foolish a consistency issue (i.e. the rest of pprint.py used _len) - I also wanted to refactor _str_parts and _bytes_parts, but couldn't decide on the best course. I was favoring a helper function to run the common loop since the two if issubclass... calls were so different and parameterizing the differences felt like it would obfuscate things too much. - I also agree on the doc. I figured I'd see if there weren't any hidden surprises with the patch before I worked on better doc. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17530 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8876] distutils should not assume that hardlinks will work
Éric Araujo added the comment: I’ll get this in the next bugfix releases. -- keywords: -needs review nosy: +benjamin.peterson, georg.brandl, larry priority: normal - release blocker versions: +Python 3.4 -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8876 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17707] Multiprocessing queue get method does not block for short timeouts
Charles-François Natali added the comment: Maybe I'm misinterpreting what you wrote but the test fails before the patch and succeeds after it so what's the point in adding multiple tests with different timeouts? Well, the test you added tests explicitely for a value 1s because this specific bug was due to a rounding error, but I think it could be interesting to check a couple more values, within a reasonable range (not too long). It's just a matter of calling it in a loop, but if you don't deem it necessary, that's fine with me. Not sure what you refer to here. Feel free to submit a patch if you want. See e.g. : http://hg.python.org/cpython/file/413c0b0a105f/Lib/test/lock_tests.py#l65 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17707 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17530] pprint could use line continuation for long bytes literals
Antoine Pitrou added the comment: Well, but eval works if you put parentheses as required by the grammar: s = (b'xy'\nb'za') eval(s) b'xyza' Yes, _str_parts and _bytes_parts should probably remain separate. It's the higher-level routine that would deserve sharing. Also, perhaps the other wrapping routines (for dict, list...) could get the same treatment. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17530 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17739] ssl.SSLSocket.getpeercert does not return client certificate
New submission from David D Lowe: The documentation for ssl.SSLSocket.getpeercert states: If the binary_form parameter is True, and a certificate was provided, this method returns the DER-encoded form of the entire certificate as a sequence of bytes, or None if the peer did not provide a certificate. This return value is independent of validation; if validation was required (CERT_OPTIONAL or CERT_REQUIRED), it will have been validated, but if CERT_NONE was used to establish the connection, the certificate, if present, will not have been validated. However, in the case that validation is not required, getpeercert does not return a certificate, even when binary_form is set to True. -- components: Library (Lib) files: test.tar.gz messages: 186999 nosy: Flimm priority: normal severity: normal status: open title: ssl.SSLSocket.getpeercert does not return client certificate type: behavior versions: Python 2.7, Python 3.2 Added file: http://bugs.python.org/file29867/test.tar.gz ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17739 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17673] add `copy_from` argument to temporaryfile
Kyle Roberts added the comment: I think `copy_from` should be included for mkstemp as well. It provides similar functionality to TemporaryFile and NamedTemporaryFile, but it doesn't delete the temp file on close as the other two do by default. Thoughts? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17673 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17734] Failure when running test_builtin after test_genexps
Ezio Melotti added the comment: Isn't this the same as #13886? -- nosy: +ezio.melotti ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17734 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13510] Clarify that readlines() is not needed to iterate over a file
Dan Riti added the comment: Agreed Ezio, I've updated the patch to include the change to Doc/library/io.rst:readlines. -- Added file: http://bugs.python.org/file29868/demote-readlines-v3.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13510 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16694] Add pure Python operator module
Zachary Ware added the comment: Here's another new version of the patch, addressing Ezio's review comments and a few things I found after giving operator.py a closer look myself. Things changed in operator.py in this version: - all ``__func__ = func`` assignments are moved to the end, after importing * from _operator. With the assignments after each func, __func__ was still the Python version after importing from _operator. I suspect this means that _operator.c could be changed to not mess with creating each __func__ and just let operator.py do it, but not being a native C speaker, I don't know how to do it. Also, there is an added test case to test whether __func__ is func. It passes with the rest of the patch, but would fail on current operator.c; it seems that operator.c actually creates separate __func__ and func functions (that do the same thing). - If importing from _operator succeeds, import __doc__ from _operator as well. The Python implementation has an extra note at the end of __doc__ advertising that it is a Python implementation. Also, after submitting this patch, I'm going to try to clean up the files list on this issue a bit. I'll clear the nosy list while I do so to avoid spamming everybody with messages about it. (At least, I assume I can do so, I haven't tried this before :). If I can't clear the nosy list, I won't bother with cleaning up the files, again to avoid spamming) -- Added file: http://bugs.python.org/file29869/py_operator.v12.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16694 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16694] Add pure Python operator module
Changes by Zachary Ware zachary.w...@gmail.com: -- nosy: -Arfrever, brett.cannon, eric.araujo, ezio.melotti, jcea, meador.inge, pitrou, serhiy.storchaka, zach.ware ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16694 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16694] Add pure Python operator module
Changes by Zachary Ware zachary.w...@gmail.com: Removed file: http://bugs.python.org/file28327/operator.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16694 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16694] Add pure Python operator module
Changes by Zachary Ware zachary.w...@gmail.com: Removed file: http://bugs.python.org/file28328/py_operator.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16694 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16694] Add pure Python operator module
Changes by Zachary Ware zachary.w...@gmail.com: Removed file: http://bugs.python.org/file28374/py_operator.v3.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16694 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16694] Add pure Python operator module
Changes by Zachary Ware zachary.w...@gmail.com: Removed file: http://bugs.python.org/file28388/py_operator.v5.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16694 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com