Re: Beginner Question: 3D Models
Am 19.06.13 04:47, schrieb andrewblun...@gmail.com: However, for one part of the program I'd like to be able to create a 3D model based on the user input. The model would be very basic consisting of a number of lines and objects. We have 3D models of each component within our CAD system so it would be great if we could utilize those models. Have a look at vtk http://www.vtk.org/ Using VTK you can import CAD models and visualize them, combine to scenes and export. VTK has Python bindings. It is a real big library, but focused on polygonal models, i.e. it will happily import STL and OBJ, but not IGES and the like ith real curves. Then the question is how you'd want to export your model. VTK can export to VRML and X3D, but if you want to CREATE a real model by CSG of the exisiting parts, you would need a true CAD system. There is not much useful free stuff out there, you could try BRL-CAD or OpenCascade. The latter also has python bindings. http://www.pythonocc.org/ Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: python-django for dynamic web survey?
On 19-Jun-13 7:04 AM, Jason Friedman wrote: How random do the questions need to be? Is a handful or two different combinations sufficient? Can you manually create these different surveys using, for example, surveymonkey, and distribute them? There are a lot possible combinations and questions so I would have to create a large number of them, so I guess automatic generation is a better way. Thanks for the idea anyway! -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On Wed, Jun 19, 2013 at 1:49 PM, ru...@yahoo.com wrote: On 06/18/2013 01:21 AM, Chris Angelico wrote: On Tue, Jun 18, 2013 at 2:39 PM, alex23 wuwe...@gmail.com wrote: tl;dr Stop acting like a troll and we'll stop perceiving you as such. This being Python-list, we duck-type. You don't have to declare that you're a troll, like you would in C; you just react like a troll and we'll treat you as one. We never ask are you a troll, we just ask do you quack like a troll. People are much more complex than Python objects. While duck-typing is a useful heuristic it does not guarantee accurate results. And keep in mind that stereotyping and racial profiling are forms of duck typing. You need to be careful when duck-typing people. On the contrary, stereotyping is You are-a quality, therefore you will behave in manner. This is the opposite: You behave like a troll, therefore you are equivalent to a troll. Imagine if we treated all those with green skin who live under bridges as trolls, no matter how good their contributions... ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On Wed, Jun 19, 2013 at 3:42 PM, Dave Angel da...@davea.name wrote: Names are *one of* the ways we specify which objects are to be used. (We can also specify objects via an container and a subscript or slice, or via an attribute of another object. And probably another way or two.) But you always have to bootstrap it with either a name. Or a literal. So those are the only two ways to specify which objects are to be used. (Anyone fanatically devoted to nice red uniforms?) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On Wed, 19 Jun 2013 17:07:28 +1000, Chris Angelico wrote: On the contrary, stereotyping is You are-a quality, therefore you will behave in manner. I don't think that's how stereotypes usually work. He wears a turban, therefore he's an Arab terrorist. He's wearing black, has pale skin, listens to that weird goth music I don't like, therefore he's a school-shooter. She's good looking and wears short skirts, therefore she's a slut. He's wearing a police uniform, therefore he's a policeman. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: decorator to fetch arguments from global objects
andrea crotti andrea.crotti.0 at gmail.com writes: 2013/6/18 Terry Reedy tjreedy at udel.edu On 6/18/2013 5:47 AM, andrea crotti wrote: Using a CouchDB server we have a different database object potentially for every request. We already set that db in the request object to make it easy to pass it around form our django app, however it would be nice if I could set it once in the API and automatically fetch it from there. Basically I have something like class Entity: def save_doc(db) If save_doc does not use an instance of Entity (self) or Entity itself (cls), it need not be put in the class. I missed a self it's a method actually.. ... I would like basically to decorate this function in such a way that: - if I pass a db object use it - if I don't pass it in try to fetch it from a global object - if both don't exist raise an exception Decorators are only worthwhile if used repeatedly. What you specified can easily be written, for instance, as def save_doc(db=None): if db is None: db = fetch_from_global() if isinstance(db, dbclass): save_it() else: raise ValueError('need dbobject') Yes that's exactly why I want a decorator, to avoid all this boilerplate for every function method that uses a db object.. The standard way of avoiding boilerplate like this is not to use a decorator, but a regular function/method that you call from within your code. Just encapsulate Terry's code into a module-level function (or a static class method): def guarantee_dbobject(db): if db is None: db = fetch_from_global() elif not isinstance(db, dbclass): raise TypeError('need dbobject') return db Then use it as a simple one-liner like this: def save_doc(self, db=None): db = guarantee_dbobject(db) ... It's as much effort to use this as decorating the method, but I think it's clearer and it avoids the potential problems that a decorator causes with introspection (which might not be a problem now, but could turn into one at some point). Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Writing Extensions for Python 3 in C
Hi. This is the last place where I want to ask a question. I have searched for lots of tutorials and documentation on the web but, didn't find a decent one to develop extensions for Python 3 using a custom compiler (mingw32, nvcc). Please help me. PS: Don't point me to Python Documentation. It is not good for beginners. It doesn't elaborate about calls and implementation. -- Aditya Avinash Atluri -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On Wed, Jun 19, 2013 at 5:27 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 19 Jun 2013 17:07:28 +1000, Chris Angelico wrote: On the contrary, stereotyping is You are-a quality, therefore you will behave in manner. I don't think that's how stereotypes usually work. He wears a turban, therefore he's an Arab terrorist. Right, my terminology was a little sloppy but I was thinking more in terms of one of the most common forms of stereotyping: racism. You have skin of this colour, therefore you are inferior or a criminal or whatever. The quality is something visible, and the expectation/assumption is utterly unrelated to it. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
Στις 19/6/2013 8:08 πμ, ο/η Tim Roberts έγραψε: Nick the Gr33k supp...@superhost.gr wrote: On 16/6/2013 4:55 ??, Tim Roberts wrote: Nick the Gr33k supp...@superhost.gr wrote: Because Python lets you use arbitrary values in a Boolean context, the net result is exactly the same. What is an arbitrary value? don even knwo what arbitrary means literally in English. Basically, it means any. In Python, you can use ANY value where a Boolean is expected. All types have a Boolean meaning. For integers, 0 is false, anything else is true. For strings, an empty string is false, anything else is true. For lists, an empty list [] is false, anything else is true. For tuples, an empty tuple () is false, anything else is true. For dicts, an empty dict {} is false, anything else is true. The argument being returned in an and or or expression is the one that *determined' the evaluation of the expression. That's not exactly how I'd put it, but the statement is correct. The last thing it had to evaulate is the result of the expression. And actually what's being returned is not the argument itself but the argument's value. But this is no different than any other programming language. Expressions always use the value of their operands, and they always return a value. The name vs value thing is critical to understanding Python, in my opinion, and it can be a stumbling block when you're coming from another language. Here's how I think about it. Python had two distinct spaces: there is a space for names, and there is a space for objects (which are values). Objects live in a nameless, faceless object cloud. A name is always bound to some object (which might be the None object). A name always knows its object, but an object never knows what names it is bound to. The only things that can be used in expressions and function arguments are objects. Names are merely the way we specify which objects to be used. a = [3] That creates a nameless list containing a single integer object with the value 3. It then binds the name a to that list. Note that the list has no clue that it is bound to any names. b = a That binds b to the same list. b and a are not related in any way, except that they happen to be bound to the same object. Note that there is still only one list. a.append(4) That modifies the list so that it now contains [3,4]. b is bound to the same list, so if you print(b) you'll see [3,4] Now, let's say I do this: a = [5] Here's where people get tripped up. This does not change our original list. Instead, it creates a new nameless list containing 5, and binds the name a to that list. a and b are no longer bound to the same object. Thank you very much Tim for the simply and detailed put explanation. -- What is now proved was at first only imagined! -- http://mail.python.org/mailman/listinfo/python-list
Re: decorator to fetch arguments from global objects
Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de writes: andrea crotti andrea.crotti.0 at gmail.com writes: 2013/6/18 Terry Reedy tjreedy at udel.edu Decorators are only worthwhile if used repeatedly. What you specified can easily be written, for instance, as def save_doc(db=None): if db is None: db = fetch_from_global() if isinstance(db, dbclass): save_it() else: raise ValueError('need dbobject') Another suggestion, without knowing too much about your code's architecture: why not *initialize* your Entity instance with a db_out attribute, so you do Terry's db checking only in one central place - Entity's __init__ method? Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On 06/19/2013 03:14 AM, Chris Angelico wrote: On Wed, Jun 19, 2013 at 3:42 PM, Dave Angel da...@davea.name wrote: Names are *one of* the ways we specify which objects are to be used. (We can also specify objects via an container and a subscript or slice, or via an attribute of another object. And probably another way or two.) But you always have to bootstrap it with either a name. Whatever bootstrap really means in this context. But if you have myname[3] + myname[5], the two objects being added are identified by a subscript operation, not just a name. Or a literal. A literal is used to create an object, and acts like a temporary name for that object, but once again the object being operated on isn't necessarily that one. You can subscript and get attributes from a literal as well. So those are the only two ways to specify which objects are to be used. That would be a pretty weak language, and it wouldn't be python. Now if you considered . and [ as operators, then I could understand your point. But http://docs.python.org/3/reference/lexical_analysis.html#operators seems to say differently. Also see http://docs.python.org/3/reference/expressions.html#primaries -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On Wed, Jun 19, 2013 at 6:06 PM, Dave Angel da...@davea.name wrote: On 06/19/2013 03:14 AM, Chris Angelico wrote: On Wed, Jun 19, 2013 at 3:42 PM, Dave Angel da...@davea.name wrote: Names are *one of* the ways we specify which objects are to be used. (We can also specify objects via an container and a subscript or slice, or via an attribute of another object. And probably another way or two.) But you always have to bootstrap it with either a name. Whatever bootstrap really means in this context. But if you have myname[3] + myname[5], the two objects being added are identified by a subscript operation, not just a name. Or a literal. A literal is used to create an object, and acts like a temporary name for that object, but once again the object being operated on isn't necessarily that one. You can subscript and get attributes from a literal as well. So those are the only two ways to specify which objects are to be used. That would be a pretty weak language, and it wouldn't be python. Now if you considered . and [ as operators, then I could understand your point. But http://docs.python.org/3/reference/lexical_analysis.html#operators seems to say differently. Also see http://docs.python.org/3/reference/expressions.html#primaries They may not quite be operators per se, but the fact is that they're composites built of primitives. You can't reference an object without somewhere having either a name or a literal to start it off. Your example starts with the object identified by the name 'myname', and the objects referenced by the literals 3 and 5, and builds up from there. Rebinding 'myname' would change that expression, as would changing the meanings of 3 or 5, though I don't know of any way to do the latter :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is regex so slow?
On 18.06.2013 22:30, Grant Edwards wrote: All the O() tells you is the general shape of the line. Nitpick: it only gives an *upper bound* for the complexity. Any function that is within O(n) is also within O(n^2). Usually when people say O() they actually mean capital Thetha (which is the correct term). It's perfectly feasible that for the range of values of n that you care about in a particular application, there's an O(n^2) algorithm that's way faster than another O(log(n)) algorithm. [Though that becomes a lot less likely as n gets large.] Since O() only gives upper bounds it's also possible for an algorithm within O(n^2) to always be faster than another algorithm within O(logn). The O(n^2) algorithm could be Thetha(1). Regards, Johannes -- Wo hattest Du das Beben nochmal GENAU vorhergesagt? Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere großen Kosmologen: Die Geheim-Vorhersage. - Karl Kaos über Rüdiger Thomas in dsa hidbv3$om2$1...@speranza.aioe.org -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On Wed, 19 Jun 2013 18:21:40 +1000, Chris Angelico wrote: You can't reference an object without somewhere having either a name or a literal to start it off. True, but not necessarily a name bound to the object you are thinking of: some_function() gives you an object, but it's not a literal, and some_function is not the name of the object you end up with. In a sense, you're making a fairly uninteresting claim: You cannot refer to an object without referring to something which is obviously correct. The ways to refer to something are more interesting: * you can refer to a thing directly by referring to it as a literal; * you can refer to a thing bound to a name by referring to the name; * you can refer to a thing in a namespace by referring to the namespace in some fashion, followed by a dot, followed by the name in that namespace, e.g. some_object.attribute, __import__('math').pi; * you can refer to a thing in a sequence by referring to the sequence in some fashion, followed by an index number in square brackets, e.g. seq[3]; * you can refer to a thing that is returned by a callable (function, method, type, etc.) by referring in some fashion to that callable object, followed by calling it, e.g. functions[9](arg) gives you a reference to some object which may not be any of `functions`, `9`, or `arg`. Have I missed any? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing Extensions for Python 3 in C
On 18/06/2013 11:24, Aditya Avinash wrote: Hi. This is the last place where I want to ask a question. I have searched for lots of tutorials and documentation on the web but, didn't find a decent one to develop extensions for Python 3 using a custom compiler (mingw32, nvcc). Please help me. PS: Don't point me to Python Documentation. It is not good for beginners. It doesn't elaborate about calls and implementation. Try getting the source code for the Python you intend to build for. Then look in the Modules directory for the sample extensions xxlimited.c, xxmodule.c xxsubtype.c. They may give you some idea of how to proceed. Of course all the other .c codes in there are the actual extensions that Python uses so they are also good examples. I started with Extending and Embedding the Python Interpreter from the python documentation though. -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On Wed, Jun 19, 2013 at 6:55 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 19 Jun 2013 18:21:40 +1000, Chris Angelico wrote: You can't reference an object without somewhere having either a name or a literal to start it off. True, but not necessarily a name bound to the object you are thinking of: some_function() gives you an object, but it's not a literal, and some_function is not the name of the object you end up with. You start with the object identified by some_function, then you call it. Same thing. Okay, so according to the Python grammar some of these things I've been treating as operators aren't classified as them; but there are still operations done to existing objects to derive other objects: The ways to refer to something are more interesting: * you can refer to a thing directly by referring to it as a literal; * you can refer to a thing bound to a name by referring to the name; The two I started with * you can refer to a thing in a namespace by referring to the namespace in some fashion, followed by a dot, followed by the name in that namespace, e.g. some_object.attribute, __import__('math').pi; Retrieving an attribute of an object, whether that object be referenced by name or by function call. * you can refer to a thing in a sequence by referring to the sequence in some fashion, followed by an index number in square brackets, e.g. seq[3]; Ditto. These can call magic methods; as far as I'm concerned, they're equivalent to operators. You can apply them to anything. * you can refer to a thing that is returned by a callable (function, method, type, etc.) by referring in some fashion to that callable object, followed by calling it, e.g. functions[9](arg) gives you a reference to some object which may not be any of `functions`, `9`, or `arg`. And same again. You start with functions, 9, and arg, look up two of them as names, traverse the series of operations, and get back a result. Or maybe you throw an exception. class Foo: def __call__(self): print(Hello, world!) foo=Foo() foo() Hello, world! Is foo a function? Kinda. Sorta. We don't care. Is the function call notation () an operator? Ditto - we don't care. It works like one. There's little fundamental difference between: asdf %d qwer%5 'asdf 5 qwer' and asdf %d qwer[5] '%' but one of them is called an operator and one's not. Would you say that percent notation there is another way to reference an object? Is it a different type of string literal? No. It's a string literal and an operation done to it. Same with the subscripting, even though that's not technically an operator. It's not a different way to get an object. It's an operation on an object. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing Extensions for Python 3 in C
Am 18.06.2013 12:24, schrieb Aditya Avinash: Hi. This is the last place where I want to ask a question. You are probably not saying what you mean here. The meaning of your sentence is more like Here is the forum that I dislike more than any other forum, but still I have to ask a question here (even though I don't like you). :^) I have searched for lots of tutorials and documentation on the web but, didn't find a decent one to develop extensions for Python 3 using a custom compiler (mingw32, nvcc). There is even a tutorial here: http://docs.python.org/3/extending/index.html Have you tried that yet? Doing it with a different compiler is something I would save for a second step. Maybe if you described your problems with a bit more detail would help. Uli -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
Op 19-06-13 05:46, ru...@yahoo.com schreef: On 06/18/2013 02:22 AM, Antoon Pardon wrote: Op 17-06-13 19:56, ru...@yahoo.com schreef: I was using the photodetector/light system as a emotion-free analog of the troll/troll-feeders positive feedback system for which you claimed it was clearly the troll's fault for initiating the feedback condition. My intent was to point out that cause and effect are intertwined in feedback systems and it is equally valid to blame those responding to the troll for the end result as to blame the troll. And, since occasional trolls are to be expected, one is even justified in putting the preponderance of blame on the responders. I don't remember making such a claim. What I do remember is you among others claiming that the problem was not (so much) the troll (Nikos) but the others. I only made the remark that you can't claim the troll is not a problem if he provokes behaviour you find problematic. And your last conclusion is unsound. You forget to include the fact that once a troll appeared, people reacting badly to the troll is also to be expected. So with regards to this aspect there is no difference between the troll and the responders, both being expected and so no ground to put the preponderance of blame on the responders. I don't care whether he has trouble developping debuging skills or not. Just as I don't care if someone has trouble learning to swim or not. If it is reasonable to expect those skill in a specific environment, you are just rude if you enter without those skill and expect others to get you out of the troubles you probably will fall victim to. *Drowning: I can understand your feeling but being realistic (whether you care about that or not) it happens all the time and other aspects of society accept that. Around where I live we have mountain rescue units to retrieve both competent people who have had bad luck and total idiots who shouldn't be outside without a guardian. There are places the penalize the idiots in various ways but both the practice and the line between acceptable and unacceptable risk are controversial. I don't accept you drawing the line for me, especially when I have my own line formed by my own experience. Well others don't appreciate you drawing the lines for them either. If you think others have no business drawing the line for what is acceptable on this mailinglist/newsgroup then you have no business drawing such a line yourself. Those who are annoyed excessively by Nikos can (relatively) easily ignore him by filtering him and his threads and continue to participate in the group as it was before Nikos. However, those who aren't bothered (as much) by him and are willing to read or participate in his threads can not easily ignore anti-Nikos hate posts because they can't easily filter out those while leaving the non-hate ones and without also filtering non-Nikos threads. (Perhaps there are newsgroup readers that allow one to killfile an individual but only in certain threads but I doubt they are common.) I find this a very one-sided view. Those annoyed excessively by Nikos can't easily ignore him without a cost. There may be people involved in such a tread they value and like to read. They can't easily filter the valuable contributions in such a thread from the nth repeated answer to the same question either. You ask of others they should tolerate this cost Nikos brings on for them but you protest when you have to take on this kind of cost yourself. As far as I see you have just the same options as those bothered by Nikos. Make some kind of cost benefit analysis and decide on that basis whether you consider it worth your while to continue reading/contributing to a particular thread. Now its pretty clear that (in general) such hate-posts do not serve to drive away their target and often increase the volume and prolong the miscreant's stay. So their main utility is to drive away those who wish to participate in Nikos' threads. I don't know it is that clear. I have the impression it can be rather effective in cases where the whole community makes it clear trolls are not welcome. Of course if part of the community is more bothered by those making trolls feel unwelcome than by the trolls themselves, such strive will of course attract them. While you may consider that a good thing, I consider it coercion and an attempt to forcibly restrict my free choice. It is also the same behavior you accuse Nikos of -- being offensive to force others to do what you want. If you want me to go along with your proposal then convince me with rational arguments. No I don't particularly consider that a good thing. I just find your view one-sided. Yes indeed it is in some way the same behaviour I accuse Nikos of. What they are doing is upping the cost for you in participating in some threads, just as Nikos is upping the cost for them in participating in some threads. The main
Re: Beginner Question: 3D Models
On Wednesday, June 19, 2013 12:50:52 AM UTC-2:30, Steven D'Aprano wrote: On Tue, 18 Jun 2013 19:47:34 -0700, andrewblundon wrote: However, for one part of the program I'd like to be able to create a 3D model based on the user input. The model would be very basic consisting of a number of lines and objects. We have 3D models of each component within our CAD system so it would be great if we could utilize those models. [...] Is this possible? Is Python the right language? Is Blender the sort of thing you are looking for? https://duckduckgo.com/html/?q=blender%20python -- Steven I've seen some information on Blender. Is it possible to have the entire program contained within a single exe (or exe and some other files) so that it can be passed around and used by others without having to install blender? -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Question: 3D Models
On Wednesday, June 19, 2013 3:30:41 AM UTC-2:30, Christian Gollwitzer wrote: Am 19.06.13 04:47, schrieb andrewblun...@gmail.com: However, for one part of the program I'd like to be able to create a 3D model based on the user input. The model would be very basic consisting of a number of lines and objects. We have 3D models of each component within our CAD system so it would be great if we could utilize those models. Have a look at vtk http://www.vtk.org/ Using VTK you can import CAD models and visualize them, combine to scenes and export. VTK has Python bindings. It is a real big library, but focused on polygonal models, i.e. it will happily import STL and OBJ, but not IGES and the like ith real curves. Then the question is how you'd want to export your model. VTK can export to VRML and X3D, but if you want to CREATE a real model by CSG of the exisiting parts, you would need a true CAD system. There is not much useful free stuff out there, you could try BRL-CAD or OpenCascade. The latter also has python bindings. http://www.pythonocc.org/ Christian I don't need to create and export the model. I just want to be able to view it within the application I'm creating (without any other programs). -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Question: 3D Models
On 19 June 2013 12:13, andrewblun...@gmail.com wrote: I've seen some information on Blender. Is it possible to have the entire program contained within a single exe (or exe and some other files) so that it can be passed around and used by others without having to install blender? I don't know if Blender would cause problems for that but it's not hard to install Blender generally; apparently there is a portable version that can be simply unzipped on the target computer. More generally, though, there are some legal issues relating to packaging standard MSVC-compiled Python with all of its dependencies in a single .exe file for Windows. The particular problem is the Microsoft C runtime library. py2exe has some information about this here: http://www.py2exe.org/index.cgi/Tutorial Generally Python is not designed with the intention that applications would be packaged into a standalone executable file although a number of projects exist to make that possible. Is it so hard for your users to install Python and Blender if you tell them which files to download and install? Oscar -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Question: 3D Models
On 19 Jun 2013 12:56, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 19 June 2013 12:13, andrewblun...@gmail.com wrote: I've seen some information on Blender. Is it possible to have the entire program contained within a single exe (or exe and some other files) so that it can be passed around and used by others without having to install blender? I don't know if Blender would cause problems for that but it's not hard to install Blender generally; apparently there is a portable version that can be simply unzipped on the target computer. More generally, though, there are some legal issues relating to packaging standard MSVC-compiled Python with all of its dependencies in a single .exe file for Windows. The particular problem is the Microsoft C runtime library. py2exe has some information about this here: http://www.py2exe.org/index.cgi/Tutorial Generally Python is not designed with the intention that applications would be packaged into a standalone executable file although a number of projects exist to make that possible. Is it so hard for your users to install Python and Blender if you tell them which files to download and install? Oscar I don't know about the legality of it, but I've used blender in the past to make executable (exe) files with small games and distributed them without problems. The exe files were standalone (except for a few DLLs which I would place in the same folder) and it worked rather well. -- http://mail.python.org/mailman/listinfo/python-list
Re: weird behavior. bug perhaps?
On Jun 18, 8:31 pm, zoom z...@yahoo.com wrote: yes, that's the hing. thanks a lot FYI this happens because shape(mean(m,1)) (4, 1) shape(mean(array(m),1)) (4,) thanks again And thank you for the 'Thank you' !! Given the noob-questions the list is currently dealing with, your question was a relief and a pleasure. You have (unwittingly maybe??) followed http://sscce.org/ Thats great. Also the 'Thanks' at end helps not just to tickle the ego of the responder but also to confirm the answer which is often not sure. The only small suggestion I would make is next time please spend a minute on choosing a pointed subject line. -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Question: 3D Models
As I've said, I'm a fairly novice. I've compiled simple VB programs previously into exe files for use but nothing with pyton and nothing of this complexity. This application could potentially be distributed to hundreds of people throughout the world as our company is worldwide. Asking these people to install other software is really not realistic. I'd like to have it all contained in one project. I stated one exe but it could be a number of files packaged into one distribution if that it's the right term. -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Question: 3D Models
This sounds similar to what I might want. So you know of any online tutorials for this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is regex so slow?
Roy Smith r...@panix.com wrote: Except that the complexity in regexes is compiling the pattern down to a FSM. Once you've got the FSM built, the inner loop should be pretty quick. In C, the inner loop for executing a FSM should be something like: for(char* p = input; p; ++p) { next_state = current_state[*p]; if (next_state == MATCH) { break; } } which should compile down to a couple of machine instructions which run entirely in the instruction pipeline cache. But I'm probably simplifying it more than I should :-) I'd just like to point out that your simple loop is looking at every character of the input string. The simple 'ENQ' not in line test can look at the third character of the string and if it's none of 'E', 'N' or 'Q' skip to checking the 6th and then the 9th. It doesn't have to touch the intervening characters at all. Or as the source puts it: it's a mix between Boyer-Moore and Horspool, with a few more bells and whistles on the top. Also the regex library has to do a whole lot more than just figuring out if it got a match, so you have massively over-simplified it. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: another language with classes?
R Kantas r...@online.de writes: [Cross-posting to news:comp.lang.python, news:comp.lang.scheme, looking for more first-hand experience with these. Sadly, there's no news:comp.lang.go as of yet.] I came into first contact with objects and classes programming under Visual Basic 5/6 (VB classic) and found theese capabilities were useful for efficient programming. Now, as this VB is no longer supported by Microsoft I'm going to switch to another language, and my question is which other of the popular programming lnguages has such a construct like VB's classes where code and data can be completely separated from the rest of the program, so that very handy reusable code components can be created. I've had only a passing experience with VB, and even then, it dates back to the mid-1990'es, so I may not understand what exactly you're asking for, but my understanding is that most of the contemporary high-level languages, both compiled and not, offer comparable facilities. In particular, Go [1] appears to offer a simple yet powerful OO system, and even though it's still a very new language (introduced in 2009), it already has an extensive library, and offers the compiled code's performance comparable to that of C. The other popular choice is Python [2], and the one I'd like to investigate myself is Racket [3] (which is a dialect of Scheme, which in turn is a dialect of Lisp.) [1] https://en.wikipedia.org/wiki/Go_(programming_language) [2] https://en.wikipedia.org/wiki/Python_(programming_language) [3] https://en.wikipedia.org/wiki/Racket_(programming_language) [...] -- FSF associate member #7257 np. hcss.mod -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Question: 3D Models
On 19 June 2013 14:14, andrewblun...@gmail.com wrote: This sounds similar to what I might want. So you know of any online tutorials for this? It's hard to tell what you're referring to since you haven't included any quoted context in your message (like I have above). I'll assume you're referring to what Fábio said. I've already posted the link to the py2exe tutorial (I assume Fábio used py2exe since nothing else was specified). The legal issue I mentioned is precisely about the .dll files that Fábio referred to. The reason that py2exe (and similar projects) do not bundle these into the .exe is because it normally isn't legal to distribute these files. From the tutorial: ''' you need to check redist.txt within your Visual Studio installation to see whether you have the legal right to redistribute this DLL. If you do have these rights, then you have the option to bundle the C runtime DLL with you application. ''' Oscar -- http://mail.python.org/mailman/listinfo/python-list
A Beginner's Doubt
Hello! This is my first post in this group and the reason why I came across here is that, despite my complete lack of knowledge in the programming area, I received an order from my teacher to develop a visually interactive program, until 20th July, so we can participate in a kind of contest. My goal is to learn and program it by myself, as good as the time allows me. That said, what I seek here is advice from people who definitively have more experience than me on topics like: is it possible to develop this kind of program in such a short amount of time? What kinds of aspects of Python should I focus on learning? What tutorials and websites are out there that can help me? What kind of already done packages are out there that I can freely use, so I do not need to create all the aspects of the program froms scratch? It would be wise to give an abstract of the program. I made an information flux kind of graphic, but I do not know how to post it in here, so I'll use only words: Full screen window - Title and brief introductory text - 3 Buttons (Credits) (Instructions) and (Start) (Credits) - Just plain text and a return button (Instructions) - Just plain text and a return button (Start) - Changes the screen so it displays a side-menu and a Canvas. Side menu - X number of buttons (maybe 4 or 5) Buttons - Clicked - Submenu opens - List of images - Return button - Back to side menu Image in List of images - When clicked AND hold mouse button - Make copy - if: dragged to canvas - paste the copy in place - if: dragged anywhere else - delete copy and nothing happens On canvas: Image - On click and drag can be moved - Double click - Opens menu - Resize, Deform, Rotate, Color, Brigthness, Contrast, Color Curve, Saturation Then, somewhere in cavas: Save option - Prompt for file and user's name - Prompt if users want printed copy or not - Print - After saved, display random slideshow in other monitor, device or screen with the users' creations. Thats basically the whole program. I've been studying Python for a week and half now, through: How to think like a Computer Scientist and Invent with Python and Pygame. I'm still at the very beggining, though, and I can't make much more than make some images appear on a Pygame screen in a menu-like style, with a patterned gap between them. No mouse interactions up to now. I really appreciate your suggestions and help. Thank you! Augusto -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Question: 3D Models
On Wed, Jun 19, 2013 at 2:57 PM, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 19 June 2013 14:14, andrewblun...@gmail.com wrote: This sounds similar to what I might want. So you know of any online tutorials for this? It's hard to tell what you're referring to since you haven't included any quoted context in your message (like I have above). I'll assume you're referring to what Fábio said. I've already posted the link to the py2exe tutorial (I assume Fábio used py2exe since nothing else was specified). It's a blender game engine thing. (it may very well internally use py2exe). Here's a resource on how you do it: http://www.blender.org/forum/viewtopic.php?t=17838sid=5fa212f30833199dab4950e70d311490 Blender's game engine can probably be used to create a 3D model viewer, since the game engine is not specifically oriented towards games. It's more of a rudimentary interactive 3D framework, offering simple visual programming capabilities, and an awesome 3D editor, which is Blender itself. The greatest advantage to it is that it is couped with a 3D program. So you can create your physics bodies, entities, lights, etc., place them wherever you want and run the simulation. You can very likely import your CAD models into Blender using the many importers it has. It can import .3DS, .OBJ, etc. files with ease, provided you find (or write!) the plugins for them. -- Fábio Santos -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Question: 3D Models
On Tuesday, June 18, 2013 9:47:34 PM UTC-5, andrew...@gmail.com wrote: I'm looking at developing a program for work that can be distributed to others (i.e. and exe file). The application would open various dialogue boxes and ask the user for input and eventually perform mathematical calculations on the input. Tkinter sucks for GUI (at least as it stands today) however it IS part of the stdlib and you can get going fairly quickly with it -- although Tkinter does not supply a native 3dcanvas widget so you'll have to use togl, which is very old and poorly written, but it works! ;-) Alternatively, WxPython is a full featured GUI library which has a glCanvas waiting for you. But like anything there is a trade-off -- will take a bit more time to understand Wx than Tkinter. From what I've read Python would have no trouble with this. However, for one part of the program I'd like to be able to create a 3D model based on the user input. The model would be very basic consisting of a number of lines and objects. [...] Are there any capabilities to import existing CAD geometry, arrange the components in particular 3D coordinates in space and then view the results in some sort of 3D viewer? Ideally the user would then be able to zoom in and orbit around looking at the model. Is this possible? Is Python the right language? Sounds like OpenGL is what you need. Others have mentioned Blender, however i would say that is a bad idea. Sure, all the zoom and orbit code is written for you but then your users are going to be overwhelmed by the Blender interface. Blender is overkill for what you want! Suggesting Blender for this problem is like suggesting you rent a semi-truck to ship a toaster one block. Adding lines and faces (or even geometric primitives) in OpenGL is so easy you'd have to be a complete moron not to understand it. There's a little bit of complication when handling concave faces (or faces containing holes), but nothing impossible about it. Importing data from outside programs is pure Python (easy stuff). PS: Be aware that you'll most likely want to use the latest version of Python 2.x if you go the OpenGL route. You need the following. Python2.x + (Tkinter Togl or WxPython) + OpenGL -- http://mail.python.org/mailman/listinfo/python-list
Re: A Beginner's Doubt
On Wed, Jun 19, 2013 at 11:58 PM, augusto...@gmail.com wrote: My goal is to learn and program it by myself, as good as the time allows me. That said, what I seek here is advice from people who definitively have more experience than me on topics like: is it possible to develop this kind of program in such a short amount of time? What kinds of aspects of Python should I focus on learning? What tutorials and websites are out there that can help me? What kind of already done packages are out there that I can freely use, so I do not need to create all the aspects of the program froms scratch? One month to develop a program in Python? Absolutely possible, but you WILL have your work cut out for you :) You seem to have a fairly readable spec there. It'll be reasonably straight-forward to turn that into code. Spend some time writing other little tests, though. One way or another, you will probably spend the next week writing code you throw away; if you try to tackle the primary project immediately, you'll have to rewrite parts of it as you learn. It's easier to throw away a toy Hello world program than hunks of what you thought would be your final code. You may want to start with console programs, since they're ever so much easier to write. But mainly, start writing. You have one month; the best way to learn is to read stuff and pump stuff out. Make a whole PILE of rubbishy code, watch what it does, learn from it. You'll be amazed how much you can achieve in a week, much less a month. And you'll love Python. :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: A Beginner's Doubt
On 2013-06-19, augusto...@gmail.com augusto...@gmail.com wrote: This is my first post in this group and the reason why I came across here is that, despite my complete lack of knowledge in the programming area, I received an order from my teacher to develop a visually interactive program, until 20th July, so we can participate in a kind of contest. My goal is to learn and program it by myself, as good as the time allows me. That said, what I seek here is advice from people who definitively have more experience than me on topics like: is it possible to develop this kind of program in such a short amount of time? What kinds of aspects of Python should I focus on learning? What tutorials and websites are out there that can help me? What kind of already done packages are out there that I can freely use, so I do not need to create all the aspects of the program froms scratch? It would be wise to give an abstract of the program. I made an information flux kind of graphic, but I do not know how to post it in here, so I'll use only words: Full screen window - Title and brief introductory text - 3 Buttons (Credits) (Instructions) and (Start) (Credits) - Just plain text and a return button (Instructions) - Just plain text and a return button (Start) - Changes the screen so it displays a side-menu and a Canvas. Side menu - X number of buttons (maybe 4 or 5) Buttons - Clicked - Submenu opens - List of images - Return button - Back to side menu Image in List of images - When clicked AND hold mouse button - Make copy - if: dragged to canvas - paste the copy in place - if: dragged anywhere else - delete copy and nothing happens On canvas: Image - On click and drag can be moved - Double click - Opens menu - Resize, Deform, Rotate, Color, Brigthness, Contrast, Color Curve, Saturation Then, somewhere in cavas: Save option - Prompt for file and user's name - Prompt if users want printed copy or not - Print - After saved, display random slideshow in other monitor, device or screen with the users' creations. Thats basically the whole program. I've been studying Python for a week and half now, through: How to think like a Computer Scientist and Invent with Python and Pygame. I'm still at the very beggining, though, and I can't make much more than make some images appear on a Pygame screen in a menu-like style, with a patterned gap between them. No mouse interactions up to now. I really appreciate your suggestions and help. First off, this is extremely ambitious for one month with no programming experience. But it sounds like you've made some significant progress. For a new programmer, mastering the mechanical aspects of programming can be a huge hurdle, and you've done that already. Finally, my advice is to use tkinter combined with PIL for this project, instead of PyGame. I have not personally used PyGame, but my guess is it will be much harder to create a reasonable GUI with PyGame than with tkinter. But I do not know how difficult this project will be will be even using the libraries of least resistance. The GUI you propose is very simple, except possibly for the dragging and dropping, which I've not tried and might be hairy. Moreover, I have not seriously used PIL and I don't even know if it supports Python 3. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: A Beginner's Doubt
On Wednesday, June 19, 2013 8:58:19 AM UTC-5, augus...@gmail.com wrote: This is my first post in this group and the reason why I came across here is that, despite my complete lack of knowledge in the programming area, I received an order from my teacher to develop a visually interactive program, Ah teachers, you gotta love them! High on a power trip. Drunk on tenure. Most of which are overpaid and under-worked. Can't work with them, can't fire them! HAY, TEACH-AH! Leave them kids alone! until 20th July, so we can participate in a kind of contest. My goal is to learn and program it by myself, as good as the time allows me. That said, what I seek here is advice from people who definitively have more experience than me on topics like: is it possible to develop this kind of program in such a short amount of time? Develop what kind of program exactly? You see, usually you want to explain the details of your problem *before* you ask a question in relation to that problem, *ESPECIALLY* in the case of a generic question! How do you expect us to provide an answer? I mean, heck, even when faced with a post more riddled with more expletives than a prostitute has STD's, we can usually deduce the context of it, however, in this case your just plain obfuscating! What's the frequency Kenneth? What kinds of aspects of Python should I focus on learning? What tutorials and websites are out there that can help me? What kind of already done packages are out there that I can freely use, so I do not need to create all the aspects of the program froms scratch? It would be wise to give an abstract of the program. Yes, and wiser if you had given it at post.index[0]! Somethings happin' here (at c.l.py) What it is ain't exactly clear There's a post without context there! Tellin' me, i got to beware! Full screen window - Title and brief introductory text - 3 Buttons (Credits) (Instructions) and (Start) (Credits) - Just plain text and a return button (Instructions) - Just plain text and a return button (Start) - Changes the screen so it displays a side-menu and a Canvas. Side menu - X number of buttons (maybe 4 or 5) Buttons - Clicked - Submenu opens - List of images - Return button - Back to side menu Image in List of images - When clicked AND hold mouse button - Make copy - if: dragged to canvas - paste the copy in place - if: dragged anywhere else - delete copy and nothing happens On canvas: Image - On click and drag can be moved - Double click - Opens menu - Resize, Deform, Rotate, Color, Brigthness, Contrast, Color Curve, Saturation Then, somewhere in cavas: Save option - Prompt for file and user's name - Prompt if users want printed copy or not - Print - After saved, display random slideshow in other monitor, device or screen with the users' creations. Easy. Pick up Tkinter and learn how to: 1. Display a window. 2. Display a button and associate a block of code to be called when the button is pressed. 3. Learn how to create a menu and attach it to a topwindow. Then add command and associate actions with those commands. 4. Display a canvas, then insert images in the canvas, then manipulate them. Manipulation will require input from the user, which involves either dialogs(easy) or interactive modifications(difficult) PS: What the hell is a side menu? PPS: Good luck ;^) -- http://mail.python.org/mailman/listinfo/python-list
Question about using dictionaries and QTableWidget
I have a table that gets new entries added to it in real time. Each entry has an ID and I am storing the ID in a dictionary. What I am trying to do is to have each ID in its own row and update within that row instead of adding a new one each time. What I've done is store the ID in a dictionary and only added a new ID to the dictionary if it is not equal to any previous IDs. I would like to assign the row number for each key in the dictionary to its value. This is what I have: ID = int(epc[86:100],2) idEntry = self.idEntry if ID not in idEntry.keys(): idEntry[ID] = self.nextRow self.nextRow += 1 lastRow = self.table.rowCount() self.table.setRowCount(self.nextRow) for entryPos in range(0, self.nextRow): for fieldPos in range(6): entryPos = idEntry.get(ID) item = QtGui.QTableWidgetItem(str(data[entryPos][fieldPos])) self.table.setItem(entryPos, fieldPos, item) ''' for k in idEntry.keys(): key = str(k) value = idEntry.get(ID) for v in idEntry.values(): if data[value][1] == key: self.table.setItem(value, fieldPos, item) ''' -- http://mail.python.org/mailman/listinfo/python-list
How much memory does Django consume compared to Rails?
I have deployed two Ruby on Rails sites on WebFaction, and Passenger Rack takes up around 60 MB of memory apiece. I was planning on replacing my Drupal web sites with Rails, but I'm now considering replacing these Drupal sites with Django. Given that the baseline memory consumption for a Rails site is around 60 MB, how would a Django site compare? -- http://mail.python.org/mailman/listinfo/python-list
Idea for key parameter in all() builting, would it be feasible?
I was mucking around, trying to code a prime sieve in one line. I don't know about filters and bit shifting and stuff like that but I thought I could do it with builtins, albeit a very long one line. This is the part of my stupid trick in question that got me wondering about a key parameter for all() and the why is below that. [n for n in xrange(3, int(pow(upper, 0.5) + 1), 2) if all(map(lambda d: n%d!=0, xrange(2, int(pow(n, 0.5) + 1] Where upper is the upper bound for the sieve. That list comprehension will provide a list of prime numbers up to the square root of upper using trial division. Then that list was going to be used for the rest of the sieve using the set.difference method to remove multiples of all those primes. That's when I realized that all() doesn't necessarily go through every item in the alterable. It's stops the moment it finds a false value. You can test that that's true with. all(xrange(10**9)) It's instant because 0 is the false value and so it stops and returns false after only checking the first value. Also because we're using xrange the generator function cousin of range. The following on the other hand should take a while. all(xrange(1, 10**9)) And the following, although the same thing really as all(xrange(10**9)), is not as instant and will take even longer than the above. all(map(lambda x: bool(x), xrange(10**9))) However if all by some chance (I don't know how this stuff works underneath) has a key parameter then we could do something like. all(xrange(10**9), key=lambda x: bool(x)) Which would return False instantly (ideally). -- http://mail.python.org/mailman/listinfo/python-list
Re: Idea for key parameter in all() builting, would it be feasible?
On Thu, Jun 20, 2013 at 2:14 AM, russ.po...@gmail.com wrote: And the following, although the same thing really as all(xrange(10**9)), is not as instant and will take even longer than the above. all(map(lambda x: bool(x), xrange(10**9))) However if all by some chance (I don't know how this stuff works underneath) has a key parameter then we could do something like. all(xrange(10**9), key=lambda x: bool(x)) Which would return False instantly (ideally). All you need is the iterator version of map(). In Python 3, that's the normal map(); in Python 2, use this: from itertools import imap all(imap(lambda x: bool(x), xrange(10**9))) False It's roughly instant, like you would expect. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Question: 3D Models
On Wednesday, June 19, 2013 11:47:36 AM UTC-2:30, Rick Johnson wrote: On Tuesday, June 18, 2013 9:47:34 PM UTC-5, andrew...@gmail.com wrote: I'm looking at developing a program for work that can be distributed to others (i.e. and exe file). The application would open various dialogue boxes and ask the user for input and eventually perform mathematical calculations on the input. Tkinter sucks for GUI (at least as it stands today) however it IS part of the stdlib and you can get going fairly quickly with it -- although Tkinter does not supply a native 3dcanvas widget so you'll have to use togl, which is very old and poorly written, but it works! ;-) Alternatively, WxPython is a full featured GUI library which has a glCanvas waiting for you. But like anything there is a trade-off -- will take a bit more time to understand Wx than Tkinter. From what I've read Python would have no trouble with this. However, for one part of the program I'd like to be able to create a 3D model based on the user input. The model would be very basic consisting of a number of lines and objects. [...] Are there any capabilities to import existing CAD geometry, arrange the components in particular 3D coordinates in space and then view the results in some sort of 3D viewer? Ideally the user would then be able to zoom in and orbit around looking at the model. Is this possible? Is Python the right language? Sounds like OpenGL is what you need. Others have mentioned Blender, however i would say that is a bad idea. Sure, all the zoom and orbit code is written for you but then your users are going to be overwhelmed by the Blender interface. Blender is overkill for what you want! Suggesting Blender for this problem is like suggesting you rent a semi-truck to ship a toaster one block. Adding lines and faces (or even geometric primitives) in OpenGL is so easy you'd have to be a complete moron not to understand it. There's a little bit of complication when handling concave faces (or faces containing holes), but nothing impossible about it. Importing data from outside programs is pure Python (easy stuff). PS: Be aware that you'll most likely want to use the latest version of Python 2.x if you go the OpenGL route. You need the following. Python2.x + (Tkinter Togl or WxPython) + OpenGL Excellent.. Thank you for your response. I'll start looking at OpenGL. I've looked into Blender previously for simply animations and having an average user use that for any sort of interface would indeed be overwhelming. I simply need a viewer that you could zoom and orbit. It would also be nice if you could import an existing 3D CAD geometry for viewing. I think I need to start downloading Python with a few of the libraries and start playing around. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Idea for key parameter in all() builting, would it be feasible?
On Thu, Jun 20, 2013 at 2:32 AM, russ.po...@gmail.com wrote: All you need is the iterator version of map(). In Python 3, that's the normal map(); in Python 2, use this: from itertools import imap all(imap(lambda x: bool(x), xrange(10**9))) False It's roughly instant, like you would expect. ChrisA This probably isn't the way to post a reply on your own thread (I added an angle bracket to every line above :P) but last time clicked reply to author not knowing that is email. Anyways... If you're getting this via the mailing list, just hit Reply, and then change the To: address to python-list@python.org - that's the simplest (assuming you don't have a Reply To List feature, but you wouldn't be saying the above if you had one). That way, you get a citation line, quoted text is marked, and it's taken a minimum of effort. Thanks, I like itertools but had no idea imap. Although I did suspect Python3 would have something to say about this just to make me envious :D It works like a charm! Awesome! Hey, if you *can* switch to Py3, do try to. It has heaps of improvements, and it has a future. :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Idea for key parameter in all() builting, would it be feasible?
All you need is the iterator version of map(). In Python 3, that's the normal map(); in Python 2, use this: from itertools import imap all(imap(lambda x: bool(x), xrange(10**9))) False It's roughly instant, like you would expect. ChrisA This probably isn't the way to post a reply on your own thread (I added an angle bracket to every line above :P) but last time clicked reply to author not knowing that is email. Anyways... Thanks, I like itertools but had no idea imap. Although I did suspect Python3 would have something to say about this just to make me envious :D It works like a charm! -- http://mail.python.org/mailman/listinfo/python-list
Re: A Beginner's Doubt
On Wed, Jun 19, 2013 at 11:31 AM, Rick Johnson rantingrickjohn...@gmail.com wrote: On Wednesday, June 19, 2013 8:58:19 AM UTC-5, augus...@gmail.com wrote: This is my first post in this group and the reason why I came across here is that, despite my complete lack of knowledge in the programming area, I received an order from my teacher to develop a visually interactive program, Ah teachers, you gotta love them! High on a power trip. Drunk on tenure. Most of which are overpaid and under-worked. Can't work with them, can't fire them! HAY, TEACH-AH! Leave them kids alone! until 20th July, so we can participate in a kind of contest. My goal is to learn and program it by myself, as good as the time allows me. That said, what I seek here is advice from people who definitively have more experience than me on topics like: is it possible to develop this kind of program in such a short amount of time? What kinds of aspects of Python should I focus on learning? What tutorials and websites are out there that can help me? DO you have access to google? What kind of already done packages are out there that I can freely use, so I do not need to create all the aspects of the program froms scratch? It would be wise to give an abstract of the program. Full screen window - Title and brief introductory text - 3 Buttons (Credits) (Instructions) and (Start) (Credits) - Just plain text and a return button (Instructions) - Just plain text and a return button (Start) - Changes the screen so it displays a side-menu and a Canvas. Side menu - X number of buttons (maybe 4 or 5) Buttons - Clicked - Submenu opens - List of images - Return button - Back to side menu Image in List of images - When clicked AND hold mouse button - Make copy - if: dragged to canvas - paste the copy in place - if: dragged anywhere else - delete copy and nothing happens On canvas: Image - On click and drag can be moved - Double click - Opens menu - Resize, Deform, Rotate, Color, Brigthness, Contrast, Color Curve, Saturation Then, somewhere in cavas: Save option - Prompt for file and user's name - Prompt if users want printed copy or not - Print - After saved, display random slideshow in other monitor, device or screen with the users' creations. THis looks like a description of a program that is already completed -- http://mail.python.org/mailman/listinfo/python-list This post seems so unlikely to me. What is the subject that this teacher of yours teaches? Do you know anyone who has every done any programming? Why python? One of your problems is that you are being asked to pick a framework, understand how to use it without having any basic knowledge of how to write a computer program. I'm not a teacher, but personally this seems like a really idiotic way to teach a student to learn how programming works. I think that you should write a text on first term calculus in french, or maybe in chinese. Its a similar problem. You need to learn your topic (calculus, some unknown framework), and then you need to exercise your topic in a foreign language. Anyway, here's a book that might be useful: http://inventwithpython.com/ When (if) you get this done, come back and let us see your program -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing Extensions for Python 3 in C
On 6/18/2013 6:24 AM, Aditya Avinash wrote: Hi. This is the last place where I want to ask a question. I have searched for lots of tutorials and documentation on the web but, didn't find a decent one to develop extensions for Python 3 using a custom compiler (mingw32, nvcc). Please help me. I would call those 'alternate compilers' ;-). On Windows, you must either use MSVC (best, the same version as used for Python) or restrict what you do to avoid runtime incompatibilities. PS: Don't point me to Python Documentation. It is not good for beginners. It doesn't elaborate about calls and implementation. Let Cython take care of the 'calls and implementation' while you write in extended Python. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: decorator to fetch arguments from global objects
On 6/19/2013 4:03 AM, Wolfgang Maier wrote: Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de writes: andrea crotti andrea.crotti.0 at gmail.com writes: 2013/6/18 Terry Reedy tjreedy at udel.edu Decorators are only worthwhile if used repeatedly. What you specified can easily be written, for instance, as def save_doc(db=None): if db is None: db = fetch_from_global() if isinstance(db, dbclass): save_it() else: raise ValueError('need dbobject') Another suggestion, without knowing too much about your code's architecture: why not *initialize* your Entity instance with a db_out attribute, so you do Terry's db checking only in one central place - Entity's __init__ method? Your pair of posts pretty much say what I was trying to get at. If Entity does not prepresent anything, it should not exist, and the 'methods' should be functions with boilerplate factored out. If entity does represent anything, it should be the parameter common to all methods, the db. I had not really cognized before that an advantage of defining a class is to setup and validate the central object just once. It is still not clear to me why db should ever by bound to None. That must have something to do with the undisclosed context. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
RE: How much memory does Django consume compared to Rails?
A memory consumption by python web frameworks is relatively low. A `typical` web site developed using wheezy.web (a lightweight full-featured web framework) consumes about 14-23 Mb per worker on x86 platform. The django is not far from there. A minimal django hello world application hosted in uWSGI application server: 11Mb master + N * 9.4Mb per worker Andriy Date: Wed, 19 Jun 2013 09:18:11 -0700 Subject: How much memory does Django consume compared to Rails? From: jhsu802...@gmail.com To: python-list@python.org I have deployed two Ruby on Rails sites on WebFaction, and Passenger Rack takes up around 60 MB of memory apiece. I was planning on replacing my Drupal web sites with Rails, but I'm now considering replacing these Drupal sites with Django. Given that the baseline memory consumption for a Rails site is around 60 MB, how would a Django site compare? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: A Beginner's Doubt
Please be aware, Augusto, that Rick is known to be a bit... OTT. Don't take him too seriously (but he's not an idiot either). On 19 June 2013 14:58, augusto...@gmail.com wrote: Hello! This is my first post in this group and the reason why I came across here is that, despite my complete lack of knowledge in the programming area, I received an order from my teacher to develop a visually interactive program, until 20th July, so we can participate in a kind of contest. My goal is to learn and program it by myself, as good as the time allows me. That said, what I seek here is advice from people who definitively have more experience than me on topics like: is it possible to develop this kind of program in such a short amount of time? Possible? Yes. It'll be well'ard to get much done with too limited a knowledge base, but it should be possible even then. What kinds of aspects of Python should I focus on learning? What tutorials and websites are out there that can help me? What kind of already done packages are out there that I can freely use, so I do not need to create all the aspects of the program froms scratch? Neil Cerutti suggested Tkinter. Choosing a good simple GUI toolkit is a good idea over Pygame for something like this. I've used Pygame and I guarantee you it's not the hammer you want. (I don't know much about GUI's to be honest, though.) It would be wise to give an abstract of the program. I made an information flux kind of graphic, but I do not know how to post it in here, so I'll use only words: STUFF Thats basically the whole program. I've been studying Python for a week and half now, through: How to think like a Computer Scientist and Invent with Python and Pygame. I'm still at the very beggining, though, and I can't make much more than make some images appear on a Pygame screen in a menu-like style, with a patterned gap between them. No mouse interactions up to now. In regards to this, I really would recommend just taking Rick's suggestion: Tkinter; canvas; menu; etc. Now, as I'm probably the most new programmer here I'll point out that I don't agree with Chris when he says that: One way or another, you will probably spend the next week writing code you throw away; if you try to tackle the primary project immediately, you'll have to rewrite parts of it as you learn. It's easier to throw away a toy Hello world program than hunks of what you thought would be your final code. As a new programmer, you will throw away code whether or not you practice beforehand. Beware of that. If anything, it's the best thing you can do*. Other than that, he's spot on. Personally, I'd start on the big project sooner rather than later, but not be afraid to dump all the code every now and again. *Anecdote time; a friend of mine who learned VB as his first language wrote as one of his earlier scripts a 2075 line program with no indentation - I still have a copy of that gem tucked away in a very dark corner. Last point; DRY. Look it up and breathe it. People might wonder why I'm making that big a deal about it (it's not the be-all and end-all of anything) but as a new programmer most of your random bits of not-nice-looking code will probably just be a breach of DRY. If you've written the same thing 5 times you've *probably* done it in a not-too efficient manner and the real solution will be the next ladder up in the hierarchy of programming. As someone new, paying a fair bit of attention to this will probably make what you learn some important higher-level concepts faster. Best of luck, I hope I added something helpful. -- http://mail.python.org/mailman/listinfo/python-list
Re: A Beginner's Doubt
On Thu, Jun 20, 2013 at 2:53 AM, Joshua Landau joshua.landau...@gmail.com wrote: Now, as I'm probably the most new programmer here I'll point out that I don't agree with Chris when he says that: One way or another, you will probably spend the next week writing code you throw away; if you try to tackle the primary project immediately, you'll have to rewrite parts of it as you learn. It's easier to throw away a toy Hello world program than hunks of what you thought would be your final code. As a new programmer, you will throw away code whether or not you practice beforehand. Beware of that. If anything, it's the best thing you can do*. Yes, you will throw code away; but you'll throw away less of your finished product if you write code that isn't destined to be part of your finished product. But you're absolutely right; code should never be treated like children, to be preserved at all costs. It's okay to change your mind and scrap something. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Timsort in Cpython
On Sunday, June 16, 2013 1:16:02 PM UTC-7, Dennis Lee Bieber wrote: On Sun, 16 Jun 2013 09:15:11 -0700 (PDT), alphons...@gmail.com declaimed the following: sorry about that. I'm new to google groups. I'm trying to make sense of python's implementation of timsort through cpython: http://hg.python.org/cpython/file/default/Objects/listobject.c Since you are new to GoogleGroups, if you can, run away from it as fast as possible. While material may look okay on their system, it is practically trashed when getting out into the real world. (Paragraphs either come in as long lines with no wrapping [Usenet/Email convention is for 80 character lines, and to allow for quotes original text should wrap around 72-75], or they end up double-spacing stuff that comes in following the 80 character line length (GG is treating hard end-of-line as a paragraph marker, and on quoting, adding a blank line between these paragraphs) Either subscribe to the mailing list (and use a real mail client rather than web-mail) or use a news reader; if your ISP doesn't provide an NNTP server carrying comp.lang.python, it is available from Gmane as gmane.comp.python.general (the mailing list and comp.lang.python are cross linked, and Gmane shows the mailing list as if it were a Usenet news group) And just another comment: preference on the group is trim quoted material and comment below the quote (or interspersed with the quotes)... The style created with M$ Outlook (Outlook goes out of its way to make it impossible to trim/intersperse -- it considers quoted material as a photocopy attached to the back of a new letter) in which one comments at the top of the quoted material, and never trims to relevant material is frowned upon. Understood. I just subscribed to the news group, though I'm using gmail. hopefully it will work better than google groups. I'll keep all the advice here in mind whenever I post. -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing Extensions for Python 3 in C
On Jun 18, 3:24 pm, Aditya Avinash adityaavinash...@gmail.com wrote: Hi. This is the last place where I want to ask a question. I have searched for lots of tutorials and documentation on the web but, didn't find a decent one to develop extensions for Python 3 using a custom compiler (mingw32, nvcc). Please help me. PS: Don't point me to Python Documentation. It is not good for beginners. It doesn't elaborate about calls and implementation. You need to tell what youve read, what youve tried, where stuck. Yes the extending and embedding stuff http://docs.python.org/2/extending/ and http://docs.python.org/2/c-api/index.html is more difficult than much other than other python docs. That is intrinsic to the problem -- you are not in the python world but the C world and C is a much harder and headachey-er than python. And building the python infrastructure on top of that is still harder. If you have to use it, you really need to get the data-structure invariants right: eg http://docs.python.org/2/c-api/intro.html#objects-types-and-reference-counts. However as Terry suggests, using something like Cython to avoid this should always be first explored. Heres a list 1. 'Classic' extending/embedding 2. SCXX 3. PyCXX 4. Boost 5. Ctypes 6. Swig 7. Sip 8. cython Explore in reverse order! -- http://mail.python.org/mailman/listinfo/python-list
Re: Timsort in Cpython
On Sunday, June 16, 2013 1:33:17 PM UTC-7, Ian wrote: On Sat, Jun 15, 2013 at 10:05 PM, alphons...@gmail.com wrote: Yes I've read it. Very interesting read. There are other resources too online that make it very clear, for instance the wikipedia articles is pretty good. Though, if anyone would be interested in helping me out further -- though by all means, I'm not lazy, I can figure it myself. But, I wanted to pass in variables into listsort and watch timsort work line by line in gdb. listsort(PyListObject *self, PyObject *args, PyObject *kwds) I've never worked with Cpython source before, but it looks like PyObject is just some type of general strut.. I think anyway. How does python represent a list of ints in source? and what are the two second arguments for, assuming the first is the list strut. A PyObject* generally references any Python object. The subtype PyListObject* more specifically references a Python list. The above signature corresponds to this Python function signature: def listsort(self, *args, **kwds): The first argument self is the list object to be operated on. The second argument args is a Python tuple containing any other positional arguments that were passed into the method. The third argument kwds is a Python dict containing any keyword arguments that were passed into the method. The second argument takes the tuple which determines which varialble(key) to use the comparator on. And the third determines whether to return the list in ascending or descending order. But how do these PyObject* look in C? How does a PyListObject* look declared in CPython. How would something like this list = [2, 1, 5, 6, 10] look in CPython. Or what about something more complicated -- mlist = [('A',1),('B',2),('C',3)]. Thanks for the help. -- http://mail.python.org/mailman/listinfo/python-list
Re: A Beginner's Doubt
On Jun 19, 9:53 pm, Joshua Landau joshua.landau...@gmail.com wrote: Please be aware, Augusto, that Rick is known to be a bit... OTT. Don't take him too seriously (but he's not an idiot either). On 19 June 2013 14:58, augusto...@gmail.com wrote: Hello! This is my first post in this group and the reason why I came across here is that, despite my complete lack of knowledge in the programming area, I received an order from my teacher to develop a visually interactive program, until 20th July, so we can participate in a kind of contest. My goal is to learn and program it by myself, as good as the time allows me. That said, what I seek here is advice from people who definitively have more experience than me on topics like: is it possible to develop this kind of program in such a short amount of time? Possible? Yes. It'll be well'ard to get much done with too limited a knowledge base, but it should be possible even then. What kinds of aspects of Python should I focus on learning? What tutorials and websites are out there that can help me? What kind of already done packages are out there that I can freely use, so I do not need to create all the aspects of the program froms scratch? Neil Cerutti suggested Tkinter. Choosing a good simple GUI toolkit is a good idea over Pygame for something like this. I've used Pygame and I guarantee you it's not the hammer you want. (I don't know much about GUI's to be honest, though.) It would be wise to give an abstract of the program. I made an information flux kind of graphic, but I do not know how to post it in here, so I'll use only words: STUFF Thats basically the whole program. I've been studying Python for a week and half now, through: How to think like a Computer Scientist and Invent with Python and Pygame. I'm still at the very beggining, though, and I can't make much more than make some images appear on a Pygame screen in a menu-like style, with a patterned gap between them. No mouse interactions up to now. In regards to this, I really would recommend just taking Rick's suggestion: Tkinter; canvas; menu; etc. Now, as I'm probably the most new programmer here I'll point out that I don't agree with Chris when he says that: One way or another, you will probably spend the next week writing code you throw away; if you try to tackle the primary project immediately, you'll have to rewrite parts of it as you learn. It's easier to throw away a toy Hello world program than hunks of what you thought would be your final code. As a new programmer, you will throw away code whether or not you practice beforehand. Beware of that. If anything, it's the best thing you can do*. Speaking with the prejudice of teaching programming for 25 years :-) heres my take on this difference-of-opinion: Imagine your program as a final finished product of say 2000 lines of python. So you have to log-up that 2000 lines one by one. Do you prefer to use an adder or a multiplier? If you only do 'add-1' youve to take two thousand steps, if you allow mul-2 and mul-5 you can reach in 7. Chris solution -- get good before you start your actual work -- amounts to the second, Joshua's -- just start! -- to the first. Clearly the second is preferable right?? WRONG! You could get stuck in a multiply-by-zero loop! So you need the right combo of plodding along (Joshua) and self- improvement (Chris). -- http://mail.python.org/mailman/listinfo/python-list
Re: A Beginner's Doubt
On 6/19/2013 9:58 AM, augusto...@gmail.com wrote: Hello! This is my first post in this group and the reason why I came across here is that, despite my complete lack of knowledge in the programming area, I received an order from my teacher to develop a visually interactive program, until 20th July, so we can participate in a kind of contest. My goal is to learn and program it by myself, as good as the time allows me. That said, what I seek here is advice from people who definitively have more experience than me on topics like: is it possible to develop this kind of program in such a short amount of time? What kinds of aspects of Python should I focus on learning? What tutorials and websites are out there that can help me? What kind of already done packages are out there that I can freely use, so I do not need to create all the aspects of the program froms scratch? It would be wise to give an abstract of the program. I made an information flux kind of graphic, but I do not know how to post it in here, so I'll use only words: Full screen window Do you literally mean a full screen *window*, like a browser maximized, with frame and title bar with Minimize, Restore/Maximize, and Close buttons? or a full-screen app without the frame, like full-screen games? Tkinter, Wx, etc, are meant for the former, Pygame, etc, for the latter. - Title and brief introductory text - 3 Buttons (Credits) (Instructions) and (Start) (Credits) - Just plain text and a return button (Instructions) - Just plain text and a return button (Start) - Changes the screen so it displays a side-menu and a Canvas. If you open Idle and click Help / About IDLE, you will see a dialog box with title, text, and two groups of 3 buttons that open plain text, including Credits, in a separate window with a close (return) button. It you decide to use tkinter, this would give you a start. The code is in Lib/idlelib/aboutDialog.py. I do not know how to make the 'dialog' be a main window instead, nor how to replace a main window with a new set of widgets (as opposed to opening a new window), but I presume its possible. If so, I am sure Rick could tell us how. Side menu - X number of buttons (maybe 4 or 5) Is this really required, as opposed to a normal top menu? Buttons - Clicked - Submenu opens - List of images - Return button - Back to side menu Image in List of images - When clicked AND hold mouse button - Make copy I am not sure what you mean by 'copy'. Make an internal image object from the disk file? - if: dragged to canvas - paste the copy in place - if: dragged anywhere else - delete copy and nothing happens It sounds like the intention is to have multiple images on the canvas at once. On canvas: Image - On click and drag can be moved This could be a problem if images overlap. - Double click - Opens menu - Resize, Deform, Rotate, Color, Brigthness, Contrast, Color Curve, Saturation Image operations are what are usually placed on a size menu or floating menu box. Neil mentioned PIL (Python Image Library) because Tk's image support is anemic, and does not have any built-in transformations. Pillow, at https://pypi.python.org/pypi/Pillow/2.0.0 is a friendly fork that include patches to run on Python 3.3, which I would otherwise recommend that you use. Then, somewhere in cavas: This should be a button on the side menu. Save option - Prompt for file and user's name - Prompt if users want printed copy or not - Print - After saved, display random slideshow in other monitor, device or screen with the users' creations. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Timsort in Cpython
On Wed, Jun 19, 2013 at 11:18 AM, sean.westf...@gmail.com wrote: The second argument takes the tuple which determines which varialble(key) to use the comparator on. And the third determines whether to return the list in ascending or descending order. That's not exactly correct. The arguments are listed in that order, but in fact the arguments to list.sort are keyword-only and cannot be supplied positionally. So the args argument is expected to be an empty tuple, and the kwds argument is a dict that contains both the key and reverse arguments, if they were supplied. But how do these PyObject* look in C? It's a pointer to a struct that contains information like the class and reference count of the object. How does a PyListObject* look declared in CPython. That's a pointer to a larger struct that shares the same header as the PyObject* struct (which is basically how you do inheritance in C). It adds information like the length and capacity of the list, plus a pointer to an array of PyObject* that stores the contents of the list. How would something like this list = [2, 1, 5, 6, 10] look in CPython. Or what about something more complicated -- mlist = [('A',1),('B',2),('C',3)]. To answer that question, you should really delve into the source and see what these structs actually look like. But the first is going to contain an array of five PyObject* values, each of which references an int, while the second is going to contain an array of three PyObject* values, each of which references a tuple. I also recommend that you read the sections of the Python docs that cover the C API, as those should help you understand how these structs are normally handled. -- http://mail.python.org/mailman/listinfo/python-list
Re: A Beginner's Doubt
On 19 June 2013 17:39, Joel Goldstick joel.goldst...@gmail.com wrote: What is the subject that this teacher of yours teaches? Do you know anyone who has every done any programming? Why python? One of those questions is too easy :P. But, no, I'd actually point out that Python might *not* be the best language for the job! *GASP!* *HERETIC* *I'M TELLING!* If you just want a GUI interface program, I'd recommend JavaScript. Heck, if you don't mind the compiler troubles I'd use CoffeeScript. Why?! You scream! Well, it's definitely not the language. The GUI toolkit, HTML, however, is ace for really small compatibility-don't-really-matter scripts. A couple old examples from before I went Python are attached, not to show off the somewhat lame code but just to point out that even as a new programmer these things were *concise*. That made them so many billions of times easier. Beside the Point Be careful not to mistake the libraries I used for the code I wrote, too. The amount of code *I* wrote for each numbers very few lines (just the main two html files). About half in total was HTML/CSS, so doesn't even count as code. I wrote these for me, so pretend they're licensed strictly. Anything I can give away I do, but it's best to check the licences anyway. Please note that if you don't run these in a modern Chrome/Chromium browser you'll have a bad time - I never bothered with compatibility. Also, apologies for snatching the coffeescript.org coffeescript - but I didn't want to mail a 60KB attachment. Instructions: Guessing the rules is part of the game. They're both thinking games, by the way. For Z-Rox clone, the inspiration is from http://www.kongregate.com/games/evildog/z-rox. End Beside the Point How is this relevant to you? Well, JQuery will make what you've written probably just couple of hundred lines. Forget about 2000! This isn't relevant if any of: 1) You have to use python 2) You don't want a silly web interface 3) Any other good reason See http://jqueryui.com/draggable/ for little examples. Examples.tar.gz Description: GNU Zip compressed data -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On Wed, Jun 19, 2013 at 4:57 AM, Antoon Pardon antoon.par...@rece.vub.ac.be wrote: I don't remember making such a claim. What I do remember is you among others claiming that the problem was not (so much) the troll (Nikos) but the others. Count me among those who feel this way. And your last conclusion is unsound. You forget to include the fact that once a troll appeared, people reacting badly to the troll is also to be expected. So with regards to this aspect there is no difference between the troll and the responders, both being expected and so no ground to put the preponderance of blame on the responders. No, I don't agree with that at all. Trolls are to be expected because there will always be those out in the world who want to have a little fun and have no regard for either the list or those who use it. There is nothing to be done about that. On the other hand, the flamers responding to the trolls are regular contributers to the list who presumably do care about keeping the list courteous, respectful, welcoming and enjoyable to participate in. Toward that end, I do not think it is at all unreasonable to expect posters not to throw those principles out the window just because a troll showed up. Well others don't appreciate you drawing the lines for them either. If you think others have no business drawing the line for what is acceptable on this mailinglist/newsgroup then you have no business drawing such a line yourself. Ultimately there is no enforcement on this list, and all of us must draw our own lines. The question then is: will one draw the line somewhere that is respectful of the list and promotes positive contributions, or somewhere that will push others toward kill-filing one and/or giving up on the list altogether? I find this a very one-sided view. Those annoyed excessively by Nikos can't easily ignore him without a cost. There may be people involved in such a tread they value and like to read. They can't easily filter the valuable contributions in such a thread from the nth repeated answer to the same question either. So their ideal solution is to flame him until he goes away, with the result being that the threads don't exist to begin with? If it's difficult to filter valuable contributions from a thread while trying to ignore every other post, think how much harder it will be to got those same valuable contributions from a thread that doesn't exist in the first place. Finding anything of value here is clearly not the goal of the flamers, and they might as well just kill the threads at their end -- it's the same net effect for a lot less work, and it doesn't impact the ability of anyone else to interact with those threads if they might wish to. You ask of others they should tolerate this cost Nikos brings on for them but you protest when you have to take on this kind of cost yourself. It's a lot easier to ignore a thread than it is to ignore specific posters within specific threads. And per my response above, your argument that the flamers might not want to just ignore the thread doesn't fly. I don't know it is that clear. I have the impression it can be rather effective in cases where the whole community makes it clear trolls are not welcome. Of course if part of the community is more bothered by those making trolls feel unwelcome than by the trolls themselves, such strive will of course attract them. I don't think you understand the troll mindset. They don't care whether the community does or does not welcome them, because they don't view themselves as part of the community. They just want affirmation and attention, which is exactly what they get when somebody flames them. They may even find it amusing that somebody can get so worked up over their disingenuous posts, which then spurs them on to continue trying to get the same reaction. -- http://mail.python.org/mailman/listinfo/python-list
Default Value
I'm reading the Python.org tutorial right now, and I found this part rather strange and incomprehensible to me Important warning: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes def f(a, L=[]): L.append(a) return L print(f(1)) print(f(2)) print(f(3)) This will print [1] [1, 2] [1, 2, 3] How the list is retained between successive calls? And why? -- http://mail.python.org/mailman/listinfo/python-list
Re: A Beginner's Doubt
On Wednesday, June 19, 2013 12:57:06 PM UTC-5, Terry Reedy wrote: Terry (speaking to OP) said: Do you literally mean a full screen *window*, like a browser maximized, with frame and title bar with Minimize, Restore/Maximize, and Close buttons? or a full-screen app without the frame, like full-screen games? Tkinter, Wx, etc, are meant for the former, Pygame, etc, for the latter. Actually Terry, a GUI window is a GUI window -- whether or not the window displays user window management controls is irrelevant. Consider this example using Tkinter: ## BEGIN SCRIPT ## import Tkinter as tk MSG = \ Your Screwed: Muhahahaha! Well, not really, you can destroy the window since i provided a secret exit. But you cannot maximize or minimize!!! Muhahahahaha! ...Oh just get out of here already! class App(tk.Tk): def __init__(self): tk.Tk.__init__(self) self._createWidgets() def _createWidgets(self): _ = 'Create User Controllable Window' w = tk.Button(self, text=_, command=self._cb1) w.pack(padx=5, pady=5) _ = 'Create User Pwned Window' w = tk.Button(self, text=_, command=self._cb2) w.pack(padx=5, pady=5) def _cb1(self): win = tk.Toplevel(self) win.title('User Controllable') win.geometry('500x500+20+20') self.wait_window(win) def _cb2(self): win = tk.Toplevel(self) win.overrideredirect(True) win.geometry('500x500+20+20') tk.Label(win, text=MSG).pack(fill=tk.X) tk.Button(win, text='X', command=win.destroy).pack() if __name__ == '__main__': app = App() app.mainloop() ## END SCRIPT ## If you open Idle and click Help / About IDLE, you will see a dialog box with title, text, and two groups of 3 buttons that open plain text, including Credits, in a separate window with a close (return) button. I guess that depends on which version of Python you are using. I don't have that dialog in my 2.7 version, although i did confirm your advice is True for v3.2.2 It you decide to use tkinter, this would give you a start. The code is in Lib/idlelib/aboutDialog.py. I do not know how to make the 'dialog' be a main window instead, nor how to replace a main window with a new set of widgets (as opposed to opening a new window), but I presume its possible. If so, I am sure Rick could tell us how. Oh yes, Senior Rick has a virtual cornucopia of knowledge locked away in his huge cranium just waiting for the opportunity to propagate out into this dark and illogical world. And Rick CAN tell you many things, the only question is: will you listen? When clicked AND hold mouse button - Make copy I am not sure what you mean by 'copy'. Make an internal image object from the disk file? Sounds like he wants to allow the user to make some interactive manipulations on canvas image objects. In this particular case a copy operation. On canvas: Image - On click and drag can be moved This could be a problem if images overlap. Not necessarily. You can pick the image that is currently under the mouse pointer by querying certain tags, reguardless of any overlap. Image operations are what are usually placed on a size menu or floating menu box. Unfortunately Tkinter does not provide interactive sizers for canvas items. You can create one yourself fairly easily however this is probably out of the range of a one month project for a complete Python noob. But you don't even need them really. Granted interactive manipulations are more powerful in some situations, you could simply prompt the user for values. For sizing operations a percentage of width and height or an absolute width and height values are all you need. For Rotations a degree of rotation, and possibly a rotational point(could default to centroid!) is all you need. For color you could wield the tkColorChooser. For Brightness you could either prompt for a value in range MIN to MAX or use a Tkinter::Slider. Simplistic deformations could also use a dialog. My recommendation would be to forget about interactive manipulations. First, get acquainted with the Tkinter widgets, then start drawing things on canvas, then figure out how to manipulate canvas items programically, then prompt the user for manipulations values, and only then, and only IF you still have time, try your hand at interactive manipulations. This is the path of a wise problem solver... THIS, is the path of the Rick neophytes. Go forth my young disciples. Be fruitful and multiply. The future of this gawd forsaken planet depends on your success! @OP: Here are two good resources for Tkinter learning: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/canvas-methods.html http://effbot.org/tkinterbook/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Default Value
Ahmed Abdulshafy abdulsh...@gmail.com writes: I'm reading the Python.org tutorial right now, and I found this part rather strange and incomprehensible to me Important warning: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes def f(a, L=[]): L.append(a) return L print(f(1)) print(f(2)) print(f(3)) This will print [1] [1, 2] [1, 2, 3] How the list is retained between successive calls? And why? Functions are objects with their own attributes. The default values are computed and stored when the def statement is executed. dir(f) will show the attributes of f. Their names start and end with a double underscore, __. This indicates that they are not usually used explicitly. Still, f.__defaults__ seems to be where the default value is kept between (and during) calls. -- http://mail.python.org/mailman/listinfo/python-list
Re: Default Value
On Wednesday, June 19, 2013 2:17:35 PM UTC-5, Ahmed Abdulshafy wrote: I'm reading the Python.org tutorial right now, and I found this part rather strange and incomprehensible to me Important warning: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes def f(a, L=[]): L.append(a) return L print(f(1)) print(f(2)) print(f(3)) This will print [1] [1, 2] [1, 2, 3] How the list is retained between successive calls? And why? By the evil hands of an illogical consistency. Have you ever heard the old adage: The road to hell is paved in good intentions? Well, apparently the original designers of the language called in sick the day that class was taught. It's unfortunate because the same functionality that this intention claims to solve can be reproduced easily, and in a less astonishing manner, by the programmer himself. http://en.wikipedia.org/wiki/Principle_of_least_astonishment -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is regex so slow?
On Wednesday, June 19, 2013 9:21:43 AM UTC-4, Duncan Booth wrote: I'd just like to point out that your simple loop is looking at every character of the input string. The simple 'ENQ' not in line test can look at the third character of the string and if it's none of 'E', 'N' or 'Q' skip to checking the 6th and then the 9th. It doesn't have to touch the intervening characters at all. It's been a while since I looked at boyer-moore in detail. Looking at Objects/stringlib/fastsearch.h from the 2.7.4 source, it occurs to me that: /* create compressed boyer-moore delta 1 table */ /* process pattern[:-1] */ for (i = 0; i mlast; i++) { STRINGLIB_BLOOM_ADD(mask, p[i]); if (p[i] == p[mlast]) skip = mlast - i - 1; } /* process pattern[-1] outside the loop */ STRINGLIB_BLOOM_ADD(mask, p[mlast]); is essentially (well, sort-if) the same as the compile() step of a regex. For the (presumably) common use case of searching many strings for the same substring (which is what we're doing here), it seems like it would be a win to cache the mask and reuse it if the search string id is the same as the last search string id. The overhead on cache misses would be a single pointer comparison. Has anybody looked at doing that? -- http://mail.python.org/mailman/listinfo/python-list
Re: Default Value
On 06/19/2013 12:17 PM, Ahmed Abdulshafy wrote: I'm reading the Python.org tutorial right now, and I found this part rather strange and incomprehensible to me Important warning: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes This code: def f(a, L=[]): L.append(a) return L does the same as this code: M=[] def f(a, L=M): L.append(a) return L where it's slightly more obvious that the list is created once, and modified with each call to the function (or rather with each call to the function that does not supply its own value for L). Gary Herron print(f(1)) print(f(2)) print(f(3)) This will print [1] [1, 2] [1, 2, 3] How the list is retained between successive calls? And why? -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- http://mail.python.org/mailman/listinfo/python-list
python game
I made this game where you move a player over bears, but the bears keep loading over the plaeyer making it hard to see it, also when i move down the player goes down to the right here is my code: import pygame, sys, random from pygame.locals import * from threading import Timer #set up pygame pygame.init() mainClock = pygame.time.Clock() #set up the window WINDOW_WIDTH = 400 WINDOW_HEIGHT = 400 windowSurface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT),0) pygame.display.set_caption('Get the Bears') #set up color constants BLACK = (0,0,0) BLUE = (0, 0, 255) #set winning text textFont = pygame.font.SysFont(impact, 60) text = textFont.render(YOU WIN!, True, (193, 0, 0)) #set up the player and bear data structures bearCounter = 0 NEW_BEAR = 40 BEAR_SIZE = 64 playerImage = pygame.image.load('hunter.png') bearImage = pygame.image.load('bear.png') player = pygame.Rect(300, 100, 40, 40) bears = [] for i in range(20): bears.append(pygame.Rect(random.randint(0, WINDOW_WIDTH - BEAR_SIZE), random.randint(0, WINDOW_HEIGHT - BEAR_SIZE), BEAR_SIZE, BEAR_SIZE)) #movement variables moveLeft = False moveRight = False moveDown = False moveUp = False MOVE_SPEED = 15 #run the game loop startGame = True while startGame == True: #check for quit for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: #keyboard variables if event.key == K_LEFT: moveRight = False moveLeft = True if event.key == K_RIGHT: moveRight = True moveLeft = False if event.key == K_UP: moveUp = True moveDown = False if event.key == K_DOWN: moveUp = False moveDown = True if event.type == KEYUP: if event.key == K_ESCAPE: pygame.quit() sys.exit() if event.key == K_LEFT: moveLeft = False; if event.key == K_RIGHT: moveRight = False; if event.key == K_UP: moveUp = False; if event.key == K_DOWN: moveDown = False; bearCounter += 1 if bearCounter = NEW_BEAR: #clear bear array and add new bears bearCounter = 0 bears.append(pygame.Rect(random.randint(0, WINDOW_WIDTH - BEAR_SIZE), random.randint(0, WINDOW_HEIGHT - BEAR_SIZE), BEAR_SIZE, BEAR_SIZE)) #draw black background windowSurface.fill(BLACK) #move player if moveDown and player.bottom WINDOW_HEIGHT: player.top += MOVE_SPEED if moveUp and player.top 0: player.top -= MOVE_SPEED if moveLeft and player.left 0: player.left -= MOVE_SPEED if moveDown and player.right WINDOW_WIDTH: player.right += MOVE_SPEED windowSurface.blit(playerImage, player) for bear in bears: windowSurface.blit(bearImage, bear) #check if player has intersected with bear for bear in bears[:]: def explosion(): for bear in bears: if player.colliderect(bear) and (moveLeft == False and moveRight == False and moveUp == False and moveDown == False): bears.remove(bear) if player.colliderect(bear) and (moveLeft == False and moveRight == False and moveUp == False and moveDown == False): t = Timer(1, explosion) t.start() if len(bears) == 0: bearCounter = 0 windowSurface.blit(text, (90, 104)) startGame = False #draw the window pygame.display.update() mainClock.tick(40) while startGame == False: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() -- http://mail.python.org/mailman/listinfo/python-list
Re: python game
On Wed, 19 Jun 2013 13:18:49 -0700, jacksonkemp1234 wrote: windowSurface.blit(playerImage, player) for bear in bears: windowSurface.blit(bearImage, bear) Try changing this to draw the bears first, then the player. -- Denis McMahon, denismfmcma...@gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: The philosophy behind list indexes
Thanks everyone for taking the time to offer some very insightful replies. Learning a new language is so much more fun with a group of friendly and helpful people around! -- http://mail.python.org/mailman/listinfo/python-list
Re: python game
On Wed, 19 Jun 2013 13:18:49 -0700, jacksonkemp1234 wrote: if moveDown and player.right WINDOW_WIDTH: player.right += MOVE_SPEED Should this be moveRight instead of moveDown? -- Denis McMahon, denismfmcma...@gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On 06/19/2013 04:57 AM, Antoon Pardon wrote: Op 19-06-13 05:46, ru...@yahoo.com schreef: On 06/18/2013 02:22 AM, Antoon Pardon wrote: Op 17-06-13 19:56, ru...@yahoo.com schreef: I was using the photodetector/light system as a emotion-free analog of the troll/troll-feeders positive feedback system for which you claimed it was clearly the troll's fault for initiating the feedback condition. My intent was to point out that cause and effect are intertwined in feedback systems and it is equally valid to blame those responding to the troll for the end result as to blame the troll. And, since occasional trolls are to be expected, one is even justified in putting the preponderance of blame on the responders. I don't remember making such a claim. What I do remember is you among others claiming that the problem was not (so much) the troll (Nikos) but the others. I only made the remark that you can't claim the troll is not a problem if he provokes behaviour you find problematic. And your last conclusion is unsound. You forget to include the fact that once a troll appeared, people reacting badly to the troll is also to be expected. So with regards to this aspect there is no difference between the troll and the responders, both being expected and so no ground to put the preponderance of blame on the responders. No, blame implies assumption of a particular point of view. From a troll's viewpoint, newsgroup participants that *don't* respond are to blame because they deprive the troll of his fun. Our viewpoint is that of newsgroup participants. We assume they have volition, else this whole thread is pointless. Since they have a choice of how to respond, then if they chose to respond in a way that produces an undesirable outcome, then it is fair blame them. The troll is outside the volition of the group and so his appearance is effectively an act of nature. I don't care whether he has trouble developping debuging skills or not. Just as I don't care if someone has trouble learning to swim or not. If it is reasonable to expect those skill in a specific environment, you are just rude if you enter without those skill and expect others to get you out of the troubles you probably will fall victim to. *Drowning: I can understand your feeling but being realistic (whether you care about that or not) it happens all the time and other aspects of society accept that. Around where I live we have mountain rescue units to retrieve both competent people who have had bad luck and total idiots who shouldn't be outside without a guardian. There are places the penalize the idiots in various ways but both the practice and the line between acceptable and unacceptable risk are controversial. I don't accept you drawing the line for me, especially when I have my own line formed by my own experience. Well others don't appreciate you drawing the lines for them either. If you think others have no business drawing the line for what is acceptable on this mailinglist/newsgroup then you have no business drawing such a line yourself. I am not drawing the line for them, I am drawing it for me. I think you see a non-existent conflict because you are assume there is only one line. I do not make that assumption. If you think Nikos has crossed your line, then I acknowledge your right not to help him. I even acknowledge your right to flame him and encourage others to do so. My argument is that if you exercise your right (the flamage part) the results on the newsgroup, when considered on a best outcome for the most people basis, will be less good than if you choose not to exercise your right. Those who are annoyed excessively by Nikos can (relatively) easily ignore him by filtering him and his threads and continue to participate in the group as it was before Nikos. However, those who aren't bothered (as much) by him and are willing to read or participate in his threads can not easily ignore anti-Nikos hate posts because they can't easily filter out those while leaving the non-hate ones and without also filtering non-Nikos threads. (Perhaps there are newsgroup readers that allow one to killfile an individual but only in certain threads but I doubt they are common.) I find this a very one-sided view. Those annoyed excessively by Nikos can't easily ignore him without a cost. There may be people involved in such a tread they value and like to read. They can't easily filter the valuable contributions in such a thread from the nth repeated answer to the same question either. You ask of others they should tolerate this cost Nikos brings on for them but you protest when you have to take on this kind of cost yourself. The costs are different in magnitude. Roughly: 1.People willing to read and possibly respond helpfully to Nikos. 2.People annoyed by Nikos who want him gone and don't want to see anything by him or in his threads. (and if people find
Problem with the for loop syntax
Hello guys... I´m a begginer in Python, I'm doing a Hangman game, but I'm having trouble with this blank space. I would be greatful if you help me. :) Here's my code: http://snipplr.com/view/71581/hangman/ When I run the code it says: Invalid Syntax and this is the error: http://i.imgur.com/jKYOPMY.png http://i.imgur.com/ySoOZFR.png Thank you guys :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with the for loop syntax
On 06/19/2013 05:14 PM, arturo balbuena wrote: Hello guys... I´m a begginer in Python, I'm doing a Hangman game, but I'm having trouble with this blank space. I would be greatful if you help me. :) Here's my code: http://snipplr.com/view/71581/hangman/ When I run the code it says: Invalid Syntax and this is the error: http://i.imgur.com/jKYOPMY.png http://i.imgur.com/ySoOZFR.png If you want us to read it, put it in your message. Show at least a few lines before and after the syntax error, and show the error itself, as text of course. Use copy/paste. Of course that assumes you're using a proper console/shell, and know how to use it. So if you have to ask about that, start there. In addition, specify the python version, and if appropriate, the OS and its version. Generally, you can find your own problem. Syntax errors that seem confusing are frequently really on the line before the line in which they're discovered. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with the for loop syntax
In 18f427ef-7a9a-413d-a824-65c9df430...@googlegroups.com arturo balbuena a7xrturo...@gmail.com writes: Hello guys... I=B4m a begginer in Python, I'm doing a Hangman game, but I'm having troubl= e with this blank space. I would be greatful if you help me. :) Here's my code: http://snipplr.com/view/71581/hangman/ Snipplr says that link doesn't exist. When I run the code it says: Invalid Syntax and this is the error: http://i.imgur.com/jKYOPMY.png http://i.imgur.com/ySoOZFR.png I don't see anything obviously wrong with that code. Are you sure that's a real blank space, and not some weird character that *looks* like a space? -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with the for loop syntax
On Wed, Jun 19, 2013 at 3:14 PM, arturo balbuena a7xrturo...@gmail.com wrote: Hello guys... I´m a begginer in Python, I'm doing a Hangman game, but I'm having trouble with this blank space. I would be greatful if you help me. :) Here's my code: http://snipplr.com/view/71581/hangman/ When I run the code it says: Invalid Syntax and this is the error: http://i.imgur.com/jKYOPMY.png http://i.imgur.com/ySoOZFR.png Are you running this in Python 2 or Python 3? In Python 2, print is a statement, not a function, and the end='' arguments would cause a SyntaxError if you're not using the necessary __future__ import. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with the for loop syntax
Mmmm Ok guys, thank you I'm really sure that isn't a weird character, it is a space. My Python version is 3.3.2, I've runed this code in Python 2.7.5, but it stills the same. I've done what you said but it doesn't work. Please Check it again here is better explained: http://snipplr.com/view/71581/hangman/ -- http://mail.python.org/mailman/listinfo/python-list
Popen in Python3
I am trying to invoke a binary that requires dll's in two places all of which are included in the path env variable in windows. When running this binary with popen it can not find either, passing env=os.environ to open made no difference. Anyone know what might cause this or how to work around this? Thanks, jlc -- http://mail.python.org/mailman/listinfo/python-list
Re: python game
This is prob'ly the freakiest thing I've ever run... Anyhoo, I recommend that when you post slabs of code to a mailing list you at least make it runnable for us. We don't have the images. I fixed it by doing: | playerImage = pygame.Surface((40, 40)) | bearImage = pygame.Surface((64, 64)) | | playerImage.fill(pygame.Color(red)) | bearImage.fill(pygame.Color(blue)) I'll not just give you answers, here, but try and make you understand what you need to do to make your code shiny. I'll answer your questions on the way, though. On 19 June 2013 21:18, jacksonkemp1...@gmail.com wrote: I made this game where you move a player over bears, but the bears keep loading over the plaeyer making it hard to see it, also when i move down the player goes down to the right here is my code: import pygame, sys, random from pygame.locals import * from threading import Timer You probably want to split up these lines; all the cool kids do: | import sys | import random | import pygame | | from pygame.locals import * | from threading import Timer This is just style; you might wonder why people do this but it's something I've found makes sense in the long run for some reason, and it's recommended as such. #set up pygame pygame.init() mainClock = pygame.time.Clock() #set up the window WINDOW_WIDTH = 400 WINDOW_HEIGHT = 400 windowSurface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT),0) pygame.display.set_caption('Get the Bears') #set up color constants BLACK = (0,0,0) BLUE = (0, 0, 255) Ah! Pygame has a color module. For example, instead of: | windowsurface.fill(BLACK) it's better to do: | windowsurface.fill(pygame.Color(black)) #set winning text textFont = pygame.font.SysFont(impact, 60) text = textFont.render(YOU WIN!, True, (193, 0, 0)) Just a niggle here; it'd be better to call this win_text or some other more descriptive name. It's also better to use under_score_names; they're more readable. It took me about a year to realise this, but it's true. It's also recommended. #set up the player and bear data structures bearCounter = 0 NEW_BEAR = 40 BEAR_SIZE = 64 I'll come back to this later. playerImage = pygame.image.load('hunter.png') bearImage = pygame.image.load('bear.png') I replaced this with: | player_image = pygame.Surface((40, 40)) | bear_image = pygame.Surface((64, 64)) | | player_image.fill(pygame.Color(red)) | bear_image.fill(pygame.Color(blue)) Note that I'm changing things like the naming scheme as I go. player = pygame.Rect(300, 100, 40, 40) Although it's OK to use pygame.Rect as a player now, it's not a player and you really shouldn't let this be a habit. It'd be better to call this player_rect, or some more useful name. bears = [] for i in range(20): bears.append(pygame.Rect(random.randint(0, WINDOW_WIDTH - BEAR_SIZE), random.randint(0, WINDOW_HEIGHT - BEAR_SIZE), BEAR_SIZE, BEAR_SIZE)) Split this up, damnit! | for i in range(10): | x = random.randint(0, WINDOW_WIDTH - BEAR_SIZE) | y = random.randint(0, WINDOW_HEIGHT - BEAR_SIZE) | | bears.append((x, y), (BEAR_SIZE, BEAR_SIZE)) See how this way it's more obvious what it all means, there's no silly line-wrapping *and* it's easier to read. #movement variables moveLeft = False moveRight = False moveDown = False moveUp = False MOVE_SPEED = 15 ER MER GERD Think about what you're doing here. If I ask you what direction an object on the screen is going in, do you say: 1) Left, about 15 pixels a frame 2) West at 5 klicks per hour 3) Left=True, Right=False, Up=False, Down=False, Speed=15 ? Well, it's not (3). So let us think about this. A good classical newbie method, which works for non-newbie stuff too, is just | directions = {left, right, up, down} | movement_direction = left However, it's not the best. In programming terms you'd want variable speed in *both* directions. My preferred method is: | velocity = [the_value_of_x, the_value_of_y] so you'd write above: | velocity = [0, 0] See how nice that is? We'll come back to this later. #run the game loop startGame = True while startGame == True: N! Not you too! START PERSONAL OPINION, NOT SHARED BY EVERYONE You have here a (really weird - I'll come to that later) infinite loop. This is best described like so: | while True: | stuff() | if finished(): | break That's what break is for, after all. Even better (I think) you can do: | while game is running: | stuff() | if finished(): | break which explains what you're doing concisely without changing the meaning of the code. A second advantage of this method END Plus, if you *insist* on while FLAG, choose a good name. startGame is wrong, because it's not only running during the start of the game. You mean: | while game_running: #check for quit This is a misplaced comment. for event in pygame.event.get(): if event.type == QUIT:
Re: Problem with the for loop syntax
On 19 June 2013 23:53, Arturo B a7xrturo...@gmail.com wrote: Mmmm Ok guys, thank you I'm really sure that isn't a weird character, it is a space. My Python version is 3.3.2, I've runed this code in Python 2.7.5, but it stills the same. I've done what you said but it doesn't work. Please Check it again here is better explained: http://snipplr.com/view/71581/hangman/ Listen; 1) Post the code in the EMail, not an external link. 2) Don't Top Post. 3) That link doesn't exist. There are so many good hosting sites; why use one that doesn't work? 4) Give us a minimal example. This should be easy; just remove the code above and the code below. This is also a valid debugging technique. 5) Images? Really? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with the for loop syntax
Sorry, I'm new in here So, if you want to see the complete code I've fixed it: http://www.smipple.net/snippet/a7xrturo/Hangman%21%20%3A%29 And here is the part of code that doesn't work: #The error is marked in the whitespace between letter and in def displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord): print (HANGMANPICS[len(missedLetters)]) print() print('Missed letters: ', end='') #Starts problem for letter in missedLetters: #Finishes problem print(letter, end=' ') print() blanks = '_' * len(secretWord) for i in range(len(secretWord)): if secretWord[i] in correctLetters: blanks = blanks[:i] + secretWord[i] + blanks[i+1:] for letter in blanks: print(letter, end=' ') print() When I press F5 (Run) I get a window that says: 'Invalid Syntax' and the whitespace between letter and in is in color red -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On Wed, 19 Jun 2013 12:40:15 -0600, Ian Kelly wrote: On the other hand, the flamers responding to the trolls are regular contributers to the list who presumably do care about keeping the list courteous, respectful, welcoming and enjoyable to participate in. Toward that end, I do not think it is at all unreasonable to expect posters not to throw those principles out the window just because a troll showed up. +1000 -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with the for loop syntax
Fixed, the problem was in HANGMANPICS I didn't open the brackets. Thank you guys :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with the for loop syntax
On Thu, Jun 20, 2013 at 11:02 AM, Arturo B a7xrturo...@gmail.com wrote: Fixed, the problem was in HANGMANPICS I didn't open the brackets. Thank you guys :) General debugging tip: Syntax errors are sometimes discovered quite some way below the actual cause. The easiest way to figure out what's the real cause is to start cutting away unnecessary code until all that's left is the tiniest part that still has the error. This is also very helpful as a prerequisite to posting on a list like this, so even if you can't find the problem yourself by this method (you often will, though), it's well worth doing. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Default Value
On Wed, 19 Jun 2013 12:17:35 -0700, Ahmed Abdulshafy wrote: I'm reading the Python.org tutorial right now, and I found this part rather strange and incomprehensible to me Important warning: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes def f(a, L=[]): L.append(a) return L print(f(1)) print(f(2)) print(f(3)) This will print [1] [1, 2] [1, 2, 3] How the list is retained between successive calls? And why? How is easy: it is stored inside the function object, where the code can get to it. To be precise, in the function object's __defaults__ attribute: py def f(a=1, b=5, c=hello world): ... pass ... py f.__defaults__ (1, 5, 'hello world') Why is even easier: because the creator of Python decided to do it this way. This is called early binding -- the default value is bound (assigned) to the parameter early in the process, when the function is created. This has a few advantages: - It is the most efficient: the cost of evaluating the defaults only happens once, when the function is created, not over and over again, every time the function is called. - It is usually what people expect. If you have a function with a default, you normally expect the default to be set once, and not re-evaluated each time. - If you start with early binding, it is trivial to get late binding semantics instead; but if you start with late binding, it's less convenient to get early binding semantics. The usual way to get the effect of late binding in Python is with a sentinel value to trigger the re-evaluation of the default. Normally, we would use None and a call-time check: def function(arg, value=None): if value is None: # Re-calculate the default. value = ... # rest of code -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questiosn about encoding
On Thursday, June 13, 2013 2:11:08 AM UTC-5, Steven D'Aprano wrote: Gah! That's twice I've screwed that up. Sorry about that! Yeah, and your difficulty explaining the Unicode implementation reminds me of a passage from the Python zen: If the implementation is hard to explain, it's a bad idea. -- http://mail.python.org/mailman/listinfo/python-list
Re: python game
Thankyou this was very helpful -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with the for loop syntax
On 20Jun2013 11:09, Chris Angelico ros...@gmail.com wrote: | On Thu, Jun 20, 2013 at 11:02 AM, Arturo B a7xrturo...@gmail.com wrote: | Fixed, the problem was in | HANGMANPICS | | I didn't open the brackets. | Thank you guys :) | | General debugging tip: Syntax errors are sometimes discovered quite | some way below the actual cause. The easiest way to figure out what's | the real cause is to start cutting away unnecessary code until all | that's left is the tiniest part that still has the error. This is also | very helpful as a prerequisite to posting on a list like this, so even | if you can't find the problem yourself by this method (you often will, | though), it's well worth doing. Also, opening-and-not-closing a set of brackets is almost the only way in Python to make this kind of error (syntax at one line, actual mistake far before). See if your editor has a show-the-matching-bracket mode. I use vi/vim and it both shows the matching bracket when the cursor is on one and also have a keystroke to bounce the curser between this bracket and the matching one. If you suspect you failed to close a bracket, one approach is to go _below_ the syntax error (or right on it) and type a closing bracket. Then see where the editor thinks the opening one is. If you have a syntax highlighting editor (highlights keywords, colours quoted text differently, etc) it can also be useful for finding errors; the text will be the wrong colour at some point. Just a few suggestions to aid finding this kind of thing without outside help. Cheers, -- Cameron Simpson c...@zip.com.au Are you experiencing more Windows95 crashes than the norm? How on earth would you _know_? - John Brook jo...@research.canon.com.au reporting about a new virus -- http://mail.python.org/mailman/listinfo/python-list
Re: Popen in Python3
On Wed, 19 Jun 2013 23:03:05 +, Joseph L. Casale wrote: I am trying to invoke a binary that requires dll's in two places all of which are included in the path env variable in windows. When running this binary with popen it can not find either, passing env=os.environ to open made no difference. Anyone know what might cause this or how to work around this? Do any of the DLLs have dependencies of their own which need to be found? Do DLLs with the same name exist in directories which are searched before %PATH%? Directories listed in %PATH% are searched after all other options have failed. The relevant MSDN page appears to be: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586%28v=vs.85%29.aspx -- http://mail.python.org/mailman/listinfo/python-list
About GIL Questions!
Hey everyone! Recently I see the python source code, but i still not understand about gil. first, why single core quicker multi-core ? who can explan this in bottom layery ? second, what the different between the mult-core and the single core to schecule threads? thanks! Forgive me bad english! -- http://mail.python.org/mailman/listinfo/python-list
Re: About GIL Questions!
On Thu, Jun 20, 2013 at 2:13 PM, Thanatos xiao yanxiaopei...@gmail.com wrote: Hey everyone! Recently I see the python source code, but i still not understand about gil. first, why single core quicker multi-core ? who can explan this in bottom layery ? second, what the different between the mult-core and the single core to schecule threads? thanks! Forgive me bad english! The GIL, massively simplified: One thread at a time can be accessing Python objects. That means that Python threads are good for I/O-bound operations (you can have three threads all waiting on the network at once), but not for CPU-bound operations, unless you're calling on a library that deliberately releases the GIL. But if you want to run Python code across multiple cores, you can use the multiprocessing module, which runs separate Python instances, so they have separate GILs. You then can share data between them in a few ways, but they're mostly separate. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 06/18/2013 03:51 AM, Νίκος wrote: Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε: Names are *always* linked to objects, not to other names. a = [] b = a # Now a and b refer to the same list a = {} # Now a refers to a dict, and b refers to the same list as before I see, thank you Steven. But since this is a fact how do you create complicated data structures that rely on various variables pointing one to another liek we did in C++(cannot recall their names) ? As Steve said Python provides all manner of data structures and the means to create data structures. Any data structure (trees, lists, etc) can all be made easily in Python using Python's basic data structures, if the built-in data structures are not sufficient. It turns out that lists, hashes (dicts), and classes can pretty much do anything with having to much about with C-style pointers and such. Do yourself a favor and forget about the low-level stuff in Python for now. You'll be more frustrated if you don't. The real power and expressivity of Python comes from embracing the abstractions that Python provides to your advantage. There's a certain elegance and beauty that comes from such things, which I believe really comes from the elegance and beauty of LISP, some of which manages to shine forth in Python, despite its deficiencies. When I first learned Python, I was impressed that some of the elegance that I remember from Scheme (how to use lists as a basic type for example) was there, but in a form that appealed to me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 06/19/2013 11:16 PM, Michael Torrie wrote: It turns out that lists, hashes (dicts), and classes can pretty much do anything with having to much about with C-style pointers and such. Oh wow. Parse error. should read, pretty much do anything without having to muck about with C-style pointers and such. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On Wed, 19 Jun 2013 23:16:51 -0600, Michael Torrie wrote: The real power and expressivity of Python comes from embracing the abstractions that Python provides to your advantage. There's a certain elegance and beauty that comes from such things, which I believe really comes from the elegance and beauty of LISP, some of which manages to shine forth in Python, despite its deficiencies. When I first learned Python, I was impressed that some of the elegance that I remember from Scheme (how to use lists as a basic type for example) was there, but in a form that appealed to me. Well said! -- Steven -- http://mail.python.org/mailman/listinfo/python-list
[issue18261] Confusing description in Minimal DOM implementation
Ned Deily added the comment: No, the intent really is to suggest using the ElementTree module rather than either minidom or any of the other XML modules in the standard library. Many people find the ElementTree API easier to understand and to use. -- nosy: +ned.deily resolution: - rejected stage: - committed/rejected status: open - closed type: resource usage - ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18261 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18262] ZipInfo.external_attr are not documented
New submission from anatoly techtonik: zipfile doesn't restore file attributes when extracting. Documentation should at least contain example how to do this manually, because the ony way to do this - through ZipInfo.external_attr is too cryptic. -- assignee: docs@python components: Documentation messages: 191447 nosy: docs@python, techtonik priority: normal severity: normal status: open title: ZipInfo.external_attr are not documented versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18262 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18078] threading.Condition to allow notify on a specific waiter
João Bernardo added the comment: (ping) It would be nice to have the feature on 3.4. What changes should I do to the patch? Is anyone else working on that? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18078 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum() functional API
Ethan Furman added the comment: Enum members have two pieces of easily accessible information: `name` and `value`. The name is taken from the attribute the value is assigned to; the value, obviously, is the value assigned. The question, then, is what should happen when the function syntax is used, and values are not explicitly given? - use `int`s starting from one - use `int`s starting from zero - use the key name itself - use no value at all Working from the bottom up: - no value: if the enum member has no actual value, the user cannot retrieve the member using the class call syntax (e.g. Color(???) ) - the key name as value: if we go this route, then instead of two pieces of info, our enum member has only one piece in two places - `int`s from zero: falls in line with normal Python counting, but is the zeroth member False? - `int`s from one: avoids the False question, and it's what flufl.enum does. No value is obviously a no-go as it causes more problems than it solves. `str` value is also a no-go as the key name is already available as `name`. `int`s starting from zero or starting from one? Personally, I have no problem with a zero-value enum member that is True -- not every zero should be False. This is the only change I would be willing to make. To sum up: the name is already available in the name, no need to have it be the value as well. I am open to changing the start value to zero instead of one (which is what I do in my customization of Enum in my personal modules ;) . -- assignee: - ethan.furman nosy: +eli.bendersky title: Use enum names as values in enum.Enum convenience API - Use enum names as values in enum.Enum() functional API ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18042] Provide enum.unique class decorator
Ethan Furman added the comment: I haven't seen any discouraging words regarding the decorator. If no one has any compelling reasons why it shouldn't be added, I'll craft a version and put it in (only real difference with Nick's would be catching all the duplicates at once instead of one at a time). -- assignee: - ethan.furman ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18042 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18262] ZipInfo.external_attr are not documented
anatoly techtonik added the comment: Here is the doc - http://stackoverflow.com/questions/434641/how-do-i-set-permissions-attributes-on-a-file-in-a-zip-file-using-pythons-zip/6297838#6297838 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18262 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18202] Minor fixes for test_coding
Roundup Robot added the comment: New changeset 410ea970866e by Serhiy Storchaka in branch '3.3': Issue #18202: Fix minor bugs and cleanup test_coding.py. http://hg.python.org/cpython/rev/410ea970866e New changeset 959f4ce4d590 by Serhiy Storchaka in branch 'default': Issue #18202: Fix minor bugs and cleanup test_source_encoding.py. http://hg.python.org/cpython/rev/959f4ce4d590 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18202 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18202] Minor fixes for test_coding
Serhiy Storchaka added the comment: Not all other changes are cleanups and enhancements. Some of them also fix minor bugs. Thank you for review Victor. -- assignee: - serhiy.storchaka resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18202 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1159] os.getenv() not updated after external module uses C putenv()
Amaury Forgeot d'Arc added the comment: FYI, PyPy recently got bitten by this: https://bugs.pypy.org/issue1518 A posix.libc_getenv() function could be a solution. -- nosy: +amaury.forgeotdarc ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1159 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18244] singledispatch: When virtual-inheriting ABCs at distinct points in MRO, composed MRO is dependent on haystack ordering
Edward Catmur added the comment: Łukasz, thanks. When the most-derived class virtual-inherits two related ABCs U, V: object / | \ A W V | .` .` B` U` | .` C` The secondary `for` loop is necessary to ensure U and V are ordered correctly. I'll upload a patch with an improved test that covers this case. -- Added file: http://bugs.python.org/file30646/singledispatch-mro-composition.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18244 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18262] ZipInfo.external_attr are not documented
Ronald Oussoren added the comment: I'd be +1 on extending the zipfile API in 3.4 (with a documentation update in older releases as suggested by anatoly): * Add a method or property to ZipInfo for (un)packing the external_attr field * Add an keyword argument to Zipfile.extract and Zipfile.extractall that toggles restoring file permissions. This should be off by default for backward compatibility. The code that restores the file permissions should be careful to avoid security problems, IMHO it should by default ignore the SUID en SGID bits. -- components: +Library (Lib) nosy: +ronaldoussoren stage: - needs patch type: - enhancement versions: -Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18262 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18262] ZipInfo.external_attr are not documented
Ronald Oussoren added the comment: See also #15795 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18262 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com