how to fix python logging to not log to stderr
I am doing this logging.basiConfig(logleve=Logging.Info) then i create a file log handler and attach to it. i also have propagate as True. My logs are going to the stderr as well. How do i fix so that logs don't go to stdout? -- https://mail.python.org/mailman/listinfo/python-list
Re: cmd.exe on WIndows - problem with displaying some Unicode characters
On Tue, 05 Aug 2014 04:51:15 +0400, Akira Li wrote: > Unicode has line drawing characters [1]. win_unicode_console [2] allows > to print Unicode in cmd.exe. win_unicode_console and colorama will > probably conflict. You could look at the source to see how hard to > combine both functionalities. > > [1] http://en.wikipedia.org/wiki/Box-drawing_character > [2] https://pypi.python.org/pypi/win_unicode_console > > btw, blessings [3] provides an easy-to-use interface if you need to add > colors and move text in a terminal. It claims that it also supports > colors on Windows if used with colorama. > > [3] https://pypi.python.org/pypi/blessings/ [2] - indeed does not work with colorconsole/colorama. And I'm not that smart to combine those two functionalities. :-) [3] - maybe it works with colorama (colorama for coloring, and blessing for positioning text), but now I don't even use colorama. I use colorconsole to color AND position text, and I find it very handy. Don't think that blessing+colorama would be more easy-to-use. Thanks, I really appreciate every proposition to fix original problem you all are giving me - I check them all. But you need to understand, that I'm already OK with those cmd.exe limitations, and really not trying to achieve look of frame from first post. I'm OK with those single-only and double-only lines. Now my game would look like this: https://dl.dropboxusercontent.com/u/10544563/kolony_prntscr.png [*] and I think it's very neat. Wiktor *) it's mocup (I don't have 'window manager' yet, so I have to show/ activate/deactivate/etc. every window by hand), but still -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') -- https://mail.python.org/mailman/listinfo/python-list
RE: how to fix python logging to not log to stderr
-Message d'origine- De : Python-list [mailto:python-list-bounces+a.nandagoban=traxens@python.org] De la part de harish.chilk...@gmail.com Envoyé : Tuesday, August 5, 2014 11:18 AM À : python-list@python.org Objet : how to fix python logging to not log to stderr I am doing this logging.basiConfig(logleve=Logging.Info) then i create a file log handler and attach to it. i also have propagate as True. My logs are going to the stderr as well. How do i fix so that logs don't go to stdout? -- https://mail.python.org/mailman/listinfo/python-list hello, remove logging.basiConfig, it won't print log in stdout -- https://mail.python.org/mailman/listinfo/python-list
RE: creating log file with Python logging module
-Message d'origine- De : Python-list [mailto:python-list-bounces+a.nandagoban=traxens@python.org] De la part de Peter Otten Envoyé : Monday, August 4, 2014 4:03 PM À : python-list@python.org Objet : Re: creating log file with Python logging module Peter Otten wrote: > Peter Otten wrote: > >> You won't see a rollover if you restart it. > > Sorry, I tried it and the above statement is wrong. [Arulnambi Nandagoban] > logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - > %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', level = logging.DEBUG, > filename=Ffilename, filemode='w') > > logger = logging.getLogger(__name__) > > hdlr = TimedRotatingFileHandler(Ffilename, when='midnight') My alternative theory about what might be going wrong: you are using the same file in logging.basicConfig() and the TimedRotatingFileHandler. But I cannot replicate the problem on my (linux) system. -- https://mail.python.org/mailman/listinfo/python-list Hello, Thank you for response !!! -- Config.py: import logging from logging.handlers import TimedRotatingFileHandler import os import time logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%a, %d %b %Y %H:%M:%S') logHandler = TimedRotatingFileHandler(Ffilename,when="D") logFormatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%a, %d %b %Y %H:%M:%S') logHandler.setFormatter( logFormatter ) logger = logging.getLogger(__name__ ) logger.addHandler( logHandler ) logger.setLevel( logging.DEBUG ) The above code works according to my need that is, - print log in console as well as save log in a file every day By adding logging.basicConfig, log is printed in both console and saved in log file. -- nambi -- https://mail.python.org/mailman/listinfo/python-list
Re: 3 Suggestions to Make Python Easier For Children
On Sat, Aug 2, 2014 at 2:45 AM, Mark Summerfield wrote: > Last week I spent a couple of days teaching two children (10 and 13 -- too > big an age gap!) how to do some turtle graphics with Python. Neither had > programmed Python before -- one is a Minecraft ace and the other had done > Scratch. When I've taught children (and adults!) with little programming experience, I usually have a single import for all the things I want them to use, something like: from my_defined_functions import * at the beginning of every script, usually named for the class I'm teaching. > > Suggestion #1: Make IDLE start in the user's home directory. I use the iPython Notebook now for these things. > > Suggestion #2: Make all the turtle examples begin "from turtle import *" so > no leading turtle. is needed in the examples. > in my universal import script I have the turtle imports, usually with both from turtle import * and import turtle, so I have a choice. > Suggestion #3: Make object(key=value, ...) legal and equiv of > types.SimpleNamespace(key=value, ...). I also make a data structure, a simple wrapper around dict, which I call Struct, defined as: class Struct(dict): def __getattr__(self,name): try: val=self[name] except KeyError: val=super(Struct,self).__getattribute__(name) return val def __setattr__(self,name,val): self[name]=val then I can do: x=Struct(a=5,b=10) x.c=50 x['this']='that' # or access like a dict bb - bbl...@gmail.com http://web.bryant.edu/~bblais -- https://mail.python.org/mailman/listinfo/python-list
Re: eval [was Re: dict to boolean expression, how to?]
Steven D'Aprano wrote: > Consider the namedtuple implementation in the standard library. > There's a lot of criticism of it, some of it justified. It uses exec > extensively, which means the code is dominated by a giant string > template. This defeats your editor's syntax colouring, makes > refactoring harder, and makes how the namedtuple works rather less > understandable. It seems to me that it's only generating the __new__ > method which genuinely needs to use exec, the rest of the namedtuple > could and should use just an ordinary class object (although I concede > that some of this is just a matter of personal taste). > > Raymond Hettinger's original, using exec for the entire inner class: > > http://code.activestate.com/recipes/500261-named-tuples/ > > > My refactoring, with the bare minimum use of exec necessary: > > https://code.activestate.com/recipes/578918-yet-another-namedtuple/ This may be a silly question, but what would stop you moving the exec inside the class? So: ns = {'_new': tuple.__new__} class Inner(tuple): # Work around for annoyance: type __doc__ is read-only :-( __doc__ = ("%(typename)s(%(argtxt)s)" % {'typename': typename, 'argtxt': argtxt}) __slots__ = () _fields = field_names exec """def __new__(_cls, %(argtxt)s): return _new(_cls, (%(argtxt)s))""" % { 'argtxt': argtxt } in ns, locals() ... and so on ... and remove lines from 'ns = ...' to 'Inner.__new__ = ...' The tests at the end of the file still pass so I'm not sure whether there is any situation that wouldn't work. For that matter I don't understand why tuple.__new__ needs to be pre-bound. Just referring to tuple.__new__ directly in the exec simplifies things even more as there is no need to specify any namespaces. exec """def __new__(_cls, %(argtxt)s): return tuple.__new__(_cls, (%(argtxt)s))""" % { 'argtxt': argtxt } also passes the tests. -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list
Re: 3 Suggestions to Make Python Easier For Children
Brian Blais : > class Struct(dict): > > def __getattr__(self,name): > > try: > val=self[name] > except KeyError: > val=super(Struct,self).__getattribute__(name) > > return val > > def __setattr__(self,name,val): > > self[name]=val Cool. I wonder if that should be built into dict. Why can't I have: >>> d = {} >>> d.x = 3 >>> d {'x': 3} Marko -- https://mail.python.org/mailman/listinfo/python-list
Tkinter menu crash
Ok so the first part of the program(until the start of the menu) worked fine. It ran and did what I wanted it to do. I wanted to then implement a new menu(for practise) and then it crashes. Don't know why but it just crashes. (also tips on the code will be appreciated and I gave just started Tkinter programming) Here is the code: from Tkinter import * import tkMessageBox as tm def submit(): #message box with yes no tm.askyesno(title='Submit Text', message='Are you sure') def info(): tm.showinfo(title='About', message='Just a test Tkinter UI sample') #getting the text from the entrybox and #packs it into a label mtext = text.get() label1 = Label(app, text=mtext) label1.pack() #root window setup root = Tk() root.geometry('480x480+200+200') root.title('Basic Tk UI') #frame set up app = Frame(root) app.pack() #variable and entry box set up text = StringVar() entry = Entry(app, textvariable=text) entry.pack() #button set up button1 = Button(app, text='Submit text', command= submit) button1.pack() #menu construction menubar = Menu(root) filemenu = Menu(menubar) filemenu.add_command(label='About', command= info) filemenu.add_command(label='Quit', command= root.destroy) filemenu.add_cascade(label='TK UI Sample', menu=filemenu) root.config(menu=menubar) #loop to listen for events root.mainloop() -- https://mail.python.org/mailman/listinfo/python-list
How to pack a string variable of length 1 as a char using struct.pack?
Hi, How to pack a string variable of length 1 as a char using struct.pack? The following works fine: p = struct.pack('c', b'1') Whereas this causes an error "char format requires a bytes object of length 1": s = '1' p = struct.pack('c', s) I need to pack a variable rather than a literal. Thanks. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to pack a string variable of length 1 as a char using struct.pack?
danwgr...@gmail.com wrote: > Hi, > How to pack a string variable of length 1 as a char using struct.pack? > The following works fine: > p = struct.pack('c', b'1') Here you use a byte string of length 1, b'1'. > Whereas this causes an error "char format requires a bytes object of > length 1": > s = '1' > p = struct.pack('c', s) Here you use a Unicode string of length 1, '1'. Do this instead: s = b'1' p = struct.pack('c', s) -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: 3 Suggestions to Make Python Easier For Children
On Tue, Aug 5, 2014 at 7:04 AM, Marko Rauhamaa wrote: > > I wonder if that should be built into dict. Short answer, no. I'm sure it's been proposed before. Attributes ≠ keys. When you see something.somethingelse anywhere else in Python, "somethingelse" is an attribute reference. When you see something[somethingelse], "somethingelse" is an index value or key. Why destroy that symmetry in dictionaries? JavaScript objects have that feature. I find it mildly confusing because whenever I see it I have to pause to consider whether the name I am looking at is an attribute or a key. This little JS code I just typed at my console prompt was also mildly surprising: > var x = {}; undefined > x.valueOf(47) Object {} > x["valueOf"] = 12 12 > x.valueOf 12 > x.valueOf(47) TypeError: number is not a function Still, in my own JS code I tend to lapse into that usage, probably because so much other code out in the wild uses dot notation for key references. (Doesn't make it right, just makes me lazy.) Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: How to pack a string variable of length 1 as a char using struct.pack?
On Tue, Aug 5, 2014 at 2:15 PM, wrote: > Hi, > How to pack a string variable of length 1 as a char using struct.pack? > The following works fine: > p = struct.pack('c', b'1') > > Whereas this causes an error "char format requires a bytes object of > length 1": > s = '1' > p = struct.pack('c', s) > > I need to pack a variable rather than a literal. > I assume you are using Python 3. In Python 3, s = '1' is a *unicode string*, not a *bytes object*. You need to convert your string to a bytes object by encoding it. However, be mindful that some characters may actually require multiple bytes to be encoded: struct.pack('c', s.encode('ascii')) (You can of course use e.g. 'utf-8' as the encoding here) -- https://mail.python.org/mailman/listinfo/python-list
RE: Python-list Digest, Vol 131, Issue 6
Sent from my Windows Phone From: python-list-requ...@python.org Sent: 05-08-2014 15:37 To: python-list@python.org Subject: Python-list Digest, Vol 131, Issue 6 Send Python-list mailing list submissions to python-list@python.org To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to python-list-requ...@python.org You can reach the person managing the list at python-list-ow...@python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." -- https://mail.python.org/mailman/listinfo/python-list
Re: 3 Suggestions to Make Python Easier For Children
Marko Rauhamaa wrote: > Why can't I have: > >>>> d = {} >>>> d.x = 3 >>>> d >{'x': 3} Because it's horrible and a bad idea. d = {'this': 23, 'word': 42, 'frog': 2, 'copy': 15, 'lunch': 93} e = d.copy() Traceback (most recent call last): File "", line 1, in ? TypeError: 'int' object is not callable Conflating keys in a database with object attributes is one of the classic blunders, like getting involved in a land war in Asia. It is, *maybe*, barely acceptable as a quick-and-dirty convenience at the interactive interpreter, in a Bunch or Bag class that has very little in the way of methods or behaviour, but not acceptable for a class as fundamental and important as dict. No matter what Javascript thinks. Consider: d['something else'] = 1 d.something else d.something else ^ SyntaxError: invalid syntax -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: 3 Suggestions to Make Python Easier For Children
On Tue, Aug 5, 2014 at 10:31 PM, Skip Montanaro wrote: > JavaScript objects have that feature. I find it mildly confusing > because whenever I see it I have to pause to consider whether the name > I am looking at is an attribute or a key. This little JS code I just > typed at my console prompt was also mildly surprising: > >> var x = {}; > undefined >> x.valueOf(47) > Object {} >> x["valueOf"] = 12 > 12 >> x.valueOf > 12 >> x.valueOf(47) > TypeError: number is not a function This is partly a consequence of prototype-based inheritance; x.valueOf will shadow Object.valueOf. Pike allows a similar "dot or square brackets" notation, but at the expense of not having any methods on the mapping type itself: Pike v8.0 release 3 running Hilfe v3.5 (Incremental Pike Frontend) > mapping a=([]); > a.foo="bar"; (1) Result: "bar" > a.foo; (2) Result: "bar" > a; (3) Result: ([ /* 1 element */ "foo": "bar" ]) Since mappings (broadly equivalent to Python dicts) can't have methods, anything that Python does as a method, Pike has to do as a stand-alone function. (Swings and roundabouts, though, as those functions tend to also accept other types, so they're more akin to Python's len() than dict.pop().) Every design decision has a cost. The convenience of short-handing mapping lookup is pretty handy (especially when you're digging into deeply-nested mappings - imagine parsing an XML or JSON message and then reaching into it for one specific thing), but it means there are functions rather than methods for working with them. Take your pick. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: 3 Suggestions to Make Python Easier For Children
On Tue, Aug 5, 2014 at 10:43 PM, Steven D'Aprano wrote: > Because it's horrible and a bad idea. > > d = {'this': 23, 'word': 42, 'frog': 2, 'copy': 15, 'lunch': 93} > e = d.copy() > > Traceback (most recent call last): > File "", line 1, in ? > TypeError: 'int' object is not callable > > > Conflating keys in a database with object attributes is one of the classic > blunders, like getting involved in a land war in Asia. It is, *maybe*, > barely acceptable as a quick-and-dirty convenience at the interactive > interpreter, in a Bunch or Bag class that has very little in the way of > methods or behaviour, but not acceptable for a class as fundamental and > important as dict. No matter what Javascript thinks. It's not fundamentally bad, just fundamentally incompatible with any other use of methods. Really, what you're pointing out isn't so much a problem with conflating keys and attributes as it is with using attributes for two purposes: key lookup, and method lookup. And that's *always* going to be a bad thing. Imagine this class: class BadDict(dict): def __getitem__(self, key): if key == 'copy': return self.copy return super().__getitem__(key) Now I've just gone the other way - overloading square brackets to sometimes mean key lookup, and sometimes attribute lookup. And it's the two meanings on one notation, not the two notations for one meaning, that's the bad idea. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: 3 Suggestions to Make Python Easier For Children
Skip Montanaro : > On Tue, Aug 5, 2014 at 7:04 AM, Marko Rauhamaa wrote: >> I wonder if that should be built into dict. > > Short answer, no. I'm sure it's been proposed before. Attributes ≠ > keys. When you see something.somethingelse anywhere else in Python, > "somethingelse" is an attribute reference. When you see > something[somethingelse], "somethingelse" is an index value or key. > Why destroy that symmetry in dictionaries? I'm not sure I fully appreciate the dichotomy (which you euphemistically refer to as symmetry). > JavaScript objects have that feature. I find it mildly confusing > because whenever I see it I have to pause to consider whether the name > I am looking at is an attribute or a key. What's the inherent difference between an attribute and a key. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Python and IDEs [was Re: Python 3 is killing Python]
Steven D'Aprano wrote: > Unfortunately, software development on Windows is something of a > ghetto, compared to the wide range of free tools available for Linux. > Outside of a few oases like Microsoft's own commercial development > tools, it's hard to do development on Windows. Hard, but not > impossible, of course, and there are quite a few resources available > for the Windows user willing to download installers from the Internet. > For Python users, the IDEs from Wingware and Activestate are notable: > > https://wingware.com/ > http://komodoide.com/ > > > I missed this thread when it started, so please forgive me if this has been covered, but by dismissing Microsoft you look to have skipped over a very powerful Python IDE for Windows, namely PTVS. Microsoft's PTVS is Windows only :-( and completely free (gratuit), partly free (libre): PTVS itself is Apache licensed and the required Visual Studio is of course closed source but PTVS now runs on the latest free versions of Visual Studio Express 2013 for Web or Visual Studio Express 2013 for Desktop (which includes C++). Some of the features: works with CPython (2.x or 3.x) or IronPython. Full support for virtualenv, packages can be installed directly from PTVS individually or from requirements.txt. Intellisense uses a completion database generated in the background from the standard library and all installed libraries. It offers context sensitive completion which does a pretty good job of inferring the type of local variables based on the types of the values used to call the function. Refactoring (Rename, Extract Method, Add Import, Remove unused imports) Interactive windows for all installed Python versions (can use standard shell or IPython) Debugging locally or remotely including Linux and OS X targets (in fact they claim that anything capable of running Python can be debugged). Mixed mode Python and C++ debugging. Profiling (CPython only). Automatic test discovery for tests using unittest. Support for PyLint. Automatic deployment to Windows Azure. Extensive support for Django (including Intellisense and debugging for templates and various Django specific commands such as sync db and admin shell). -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list
Re: Davis putnam algorithm for satisfiability...
Thank you Cameron. Your post was very helpful. If you don't mind I'd like to ask you the purpose of the final list in the very beginning of the code. It is being updated and then checked for the presence of a literal. If a literal is found it returns not equivalent. Could you brief me the use of a final list? -- https://mail.python.org/mailman/listinfo/python-list
Re: 3 Suggestions to Make Python Easier For Children
On 2014-08-05 14:19, Marko Rauhamaa wrote: Skip Montanaro : On Tue, Aug 5, 2014 at 7:04 AM, Marko Rauhamaa wrote: I wonder if that should be built into dict. Short answer, no. I'm sure it's been proposed before. Attributes ≠ keys. When you see something.somethingelse anywhere else in Python, "somethingelse" is an attribute reference. When you see something[somethingelse], "somethingelse" is an index value or key. Why destroy that symmetry in dictionaries? I'm not sure I fully appreciate the dichotomy (which you euphemistically refer to as symmetry). JavaScript objects have that feature. I find it mildly confusing because whenever I see it I have to pause to consider whether the name I am looking at is an attribute or a key. What's the inherent difference between an attribute and a key. An attribute is part of a container; a key is part of its contents. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Classes
On 8/4/2014 6:44 PM, John Gordon wrote: In Shubham Tomar writes: classes. I understand that you define classes to have re-usable methods and procedures, but, don't functions serve the same purpose. Can someone please explain the idea of classes If a function simply accepts some data, does some calculations on that data and then returns a value, then you don't need classes at all. An example of this might be the square-root function: pass it any number and it calculates and returns the square root with no other data needed. But classes do come in handy for other sorts of uses. One classic example is employees at a company. Each employee has a name, ID number, salary, date of hire, home address, etc. You can create an Employee class to store those data items along with methods to manipulate those data items in interesting ways. The data items are specific to each separate Employee object, and the methods are shared among the entire class. In simple cases like that, functions could do very well by including a little bundle of data (probably a dict) as one of the parameters for each related function. Classes help here by organizing the functions into namespaces, and allowing very convenient and explicit syntax for creating objects and using attributes. In addition, classes provide hooks into almost all of Python's syntax and operations, with special methods like __init__, __add__, etc. If you want your employees to be comparable using the <, >, == you need to use classes. Classes provide a means for objects to be related, substitutable, and interdependent, using inheritance. Properties work only with classes and provide a convenient way to customize attribute retrieval and setting without forcing a change in the syntax required for usage. Classes can be constructed dynamically using metaclasses. Some of these things can be emulated using just functions and mappings--it's what C programmers do--but most of classes in Python can do requires language support. -- Neil Cerutti -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Classes
On Wed, Aug 6, 2014 at 1:37 AM, Neil D. Cerutti wrote: > In simple cases like that, functions could do very well by including a > little bundle of data (probably a dict) as one of the parameters for each > related function. And this is exactly how object orientation is done in C. You just have a structure that holds the object's state, and the (usually) first parameter to each function is a pointer to that structure. Actually, I've done that in high level languages too, specifically to decouple the code from the state (and thus allow me to load new code from the disk while maintaining state via what's already in memory - doing this with classes and objects means importing that state explicitly). The two notations are exactly the same. Compare: list.append(l, 'spam') l.append('spam') One uses namespacing, the other uses object methods. Same thing! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: 3 Suggestions to Make Python Easier For Children
Marko Rauhamaa wrote: > What's the inherent difference between an attribute and a key. Here is my bucket. The handle of the bucket is part of the bucket: bucket.handle The pieces of coal I carry in the bucket is part of its content: bucket['coal'] Of course, we can blur the distinction between part of the object and the object's content, if we so choose. As Lewis Carroll might have written in "Through the Looking Glass" had he been a programmer: ‘When I use syntax,’ Humpty Dumpty said in rather a scornful tone, ‘it means just what I choose it to mean — neither more nor less.’ ’The question is,’ said Alice, ‘whether you can make syntax mean so many different things.’ ’The question is,’ said Humpty Dumpty, ‘which is to be master — that’s all.’ If anyone wants a language where the same syntax means radically different things, or radically different syntax means the same thing, then you know where to find Perl, PHP and Javascript *wink*. But more seriously, as Humpty might have said, of course the designer is the master (and there are good masters and bad masters...), and sometimes there is good reason to use attribute syntax for content. Sometimes it isn't clear what counts as part of the object and what counts as part of the contents, e.g. record or struct like objects exist in that grey area. In that case, it may be a reasonable design choice to use attribute notation, as namedtuple does, for example. But you'll note the cost: namedtuple is forced to use leading underscore method names as *public* parts of the API, so that they don't clash with field names. If Guido was more like Perl's designer, Larry Wall, Python might have grown a "short cut" notation for keys, say mydict$key, but the proliferation of "many ways to do it" (to paraphrase the Perl motto) has costs of its own. It's harder to learn, read and understand Perl code than Python code, simply because there's more syntax to learn, and more special cases to understand. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: eval [was Re: dict to boolean expression, how to?]
Duncan Booth wrote: > Steven D'Aprano wrote: [...] >> My refactoring, with the bare minimum use of exec necessary: >> >> https://code.activestate.com/recipes/578918-yet-another-namedtuple/ > > > This may be a silly question, but what would stop you moving the exec > inside the class? I don't know. I haven't tried it. I didn't think of it at the time. I don't have any specific arguments either against or in favour of your suggestions, except to say that exec is sometimes tricky to get working unless you explicitly specify the namespace to operate in. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Python and IDEs [was Re: Python 3 is killing Python]
Duncan Booth wrote: > Steven D'Aprano wrote: > >> Unfortunately, software development on Windows is something of a >> ghetto, compared to the wide range of free tools available for Linux. I remember writing this. But I don't remember when it was. Presumably some time in the last six months :-) >> Outside of a few oases like Microsoft's own commercial development >> tools, it's hard to do development on Windows. Hard, but not >> impossible, of course, and there are quite a few resources available >> for the Windows user willing to download installers from the Internet. >> For Python users, the IDEs from Wingware and Activestate are notable: >> >> https://wingware.com/ >> http://komodoide.com/ >> >> >> > I missed this thread when it started, so please forgive me if this has > been covered, but by dismissing Microsoft you look to have skipped over > a very powerful Python IDE for Windows, namely PTVS. Never heard of it :-) Which is not surprising, since I'm not a Windows developer. [snip feature list] Nice. How does one get it? If I gave the impression that one cannot do development on Windows, that was not my intent. I tried to indicate that the difference was a matter of degree, not impossibility. One of the reasons why so many of the core developers for Python use Linux is that they got frustrated with the speed humps on Windows, the poor "out of the box" experience for developers (compare what dev tools you get with Windows by default versus what you get on Linux by default), but that might also be somewhat self-selecting: people who are happy with Windows development tend to stick to VB, Java, C, .Net etc. while those who prefer lighter weight more agile environments migrate to Linux. I don't know. But I do know that the existence of good quality Windows development tools for Python is good news for the community, so thank you for mentioning this. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Controlling py.exe launcher on Windows
I am trying to control the default version of the py.exe launcher on Windows. I have the Python 2.7.8 and 3.4.1 installed with both the 32 bit and 64 bit versions, all in different directories. I assume that .py and .pyw files are associated with the py.exe launcher. I am trying to control which version starts through a py.ini file in the same directory as the py.exe file in the 3.4.1 version last installed. If I specify in the [defaults] section of py.ini: python=3.4 then launching py.exe will show: Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AM D64)] on win32 If I specify: python=3.4-32 then launching py.exe will show: Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win 32 Is it really true that I cannot specify the 32 bit version in the .ini file or am I doing something wrong here ? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python and IDEs [was Re: Python 3 is killing Python]
Steven D'Aprano wrote: > Duncan Booth wrote: > >> Steven D'Aprano wrote: >> >>> Unfortunately, software development on Windows is something of a >>> ghetto, compared to the wide range of free tools available for >>> Linux. > > I remember writing this. But I don't remember when it was. Presumably > some time in the last six months :-) > >>> Outside of a few oases like Microsoft's own commercial development >>> tools, it's hard to do development on Windows. Hard, but not >>> impossible, of course, and there are quite a few resources available >>> for the Windows user willing to download installers from the >>> Internet. For Python users, the IDEs from Wingware and Activestate >>> are notable: >>> >>> https://wingware.com/ >>> http://komodoide.com/ >>> >>> >>> >> I missed this thread when it started, so please forgive me if this >> has been covered, but by dismissing Microsoft you look to have >> skipped over a very powerful Python IDE for Windows, namely PTVS. > > Never heard of it :-) > > Which is not surprising, since I'm not a Windows developer. > > [snip feature list] > > Nice. How does one get it? 1) Get a Windows 8.1 VM, or a real PC if that's more convenient. 2) Download and install either "Microsoft Visual Studio Express 2013 with Update 3 for Web" or "Microsoft Visual Studio Express 2013 with Update 3 for Windows Desktop" from http://www.visualstudio.com/downloads/download-visual-studio-vs N.B. If you just download the original versions without update 3 you'll have to apply all updates before proceeding so easier to use the latest versions from the get go. 3) Download and install PTVS 2.1 Beta 2 from https://pytools.codeplex.com/releases Note that you need at least PTVS 2.1 Beta and VS Express 2013 with at least Update 2 to be able to install with just free tools. Earlier versions will refuse to install. There may be more intermediate steps of applying updates, but that's par for the Microsoft course. If you try this out in conjunction with a Microsoft Azure account then be sure to also install the Azure SDK. Documentation is at https://pytools.codeplex.com/documentation There's a Django tutorial at http://pytools.codeplex.com/wikipage? title=Django%20Web%20Site/Cloud%20Service%20Tutorial which gives quite a good walkthrough. > > If I gave the impression that one cannot do development on Windows, > that was not my intent. I tried to indicate that the difference was a > matter of degree, not impossibility. One of the reasons why so many of > the core developers for Python use Linux is that they got frustrated > with the speed humps on Windows, the poor "out of the box" experience > for developers (compare what dev tools you get with Windows by default > versus what you get on Linux by default), but that might also be > somewhat self-selecting: people who are happy with Windows development > tend to stick to VB, Java, C, .Net etc. while those who prefer lighter > weight more agile environments migrate to Linux. I don't know. > > But I do know that the existence of good quality Windows development > tools for Python is good news for the community, so thank you for > mentioning this. > So far they seem to have kept a pretty low profile; I suspect largely because until recently PTVS only worked with the pay versions of Visual Studio. -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list
Python 3.4.1 install does not create a file association for .py files on Windows
I install Python 3.4.1 64-bit on Windows. After the install I type: assoc .py and I get back: File association not found for extension .py Why does not the Python install to associate extension .py with the Python Launcher for Windows ? -- https://mail.python.org/mailman/listinfo/python-list
Pythonic way to iterate through multidimensional space?
I need to evaluate a complicated function over a multidimensional space as part of an optimization problem. This is a somewhat general problem in which the number of dimensions and the function being evaluated can vary from problem to problem. I've got a working version (with loads of conditionals, and it only works to #dimensions <= 10), but I'd like something simpler and clearer and less hard-coded. I've web-searched for some plausible method, but haven't found anything "nice". Any recommendations where I should look, or what technique should be used? TIA! -- https://mail.python.org/mailman/listinfo/python-list
Re: cmd.exe on WIndows - problem with displaying some Unicode characters
On 2014-08-05, Tony the Tiger wrote: > On Mon, 04 Aug 2014 00:52:29 +0200, Wiktor wrote: > >> okumenty\python\kolony\menu.py", line 14, in > > This works for me on Linux: > > ---8<- > # coding:utf-8 > > test = """ > ┌──╖ > │ Construction ║ > │ Production ║ > │ Research ║ > │ Exploration ║ > ├··╢ > │ Next turn║ > ╘══╝ > """ But can you do Polish as well? IIRC, that was the catch: encodings that the windows terminal emulator understood that could do Polish couldn't do double-lines and vice-versa. I was a bit surprised when all that stuff rendered properly in slrn runnnig in a terminal emulator. I must have done a better job with locales and fonts that I thought... -- Grant Edwards grant.b.edwardsYow! Did you move a lot of at KOREAN STEAK KNIVES this gmail.comtrip, Dingy? -- https://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to iterate through multidimensional space?
Frank Miles wrote: > I need to evaluate a complicated function over a multidimensional space > as part of an optimization problem. This is a somewhat general problem > in which the number of dimensions and the function being evaluated can > vary from problem to problem. > > I've got a working version (with loads of conditionals, and it only works > to #dimensions <= 10), but I'd like something simpler and clearer and > less hard-coded. > > I've web-searched for some plausible method, but haven't found anything > "nice". Any recommendations where I should look, or what technique should > be used? Not sure this is what you want, but if you have nested for loops -- these can be replaced with itertools.product(): >>> a = [1, 2] >>> b = [10, 20, 30] >>> c = [100] >>> for x in a: ... for y in b: ... for z in c: ... print(x, y, z) ... 1 10 100 1 20 100 1 30 100 2 10 100 2 20 100 2 30 100 >>> for xyz in product(a, b, c): ... print(*xyz) ... 1 10 100 1 20 100 1 30 100 2 10 100 2 20 100 2 30 100 -- https://mail.python.org/mailman/listinfo/python-list
Making every no-arg method a property?
I have been using python for 4 years now, and I just started learning ruby. I like that in ruby I don't have to type parenthesis at the end of each function call if I don't need to provide extra arguments. I just realized right now that I can do something similar in python, if I make all methods with only the implicitly passed 'self' into properties. Which means I can either do some fancy coding and make a metaclass that does this auto-magically, or I have to have property decorators all over the place :-P . I was wondering what other thought of this, is it an overly fanciful way of coding python, or is it an acceptable thing to do in a real project? Also, would anyone be interested in helping me make this metaclass? -- https://mail.python.org/mailman/listinfo/python-list
Re: Making every no-arg method a property?
On Wed, Aug 6, 2014 at 5:39 AM, Christian Calderon wrote: > I have been using python for 4 years now, and I just started learning ruby. > I like that in ruby I don't have to type parenthesis at the end of each > function call if I don't need to provide extra arguments. I just realized > right now that I can do something similar in python, if I make all methods > with only the implicitly passed 'self' into properties. Which means I can > either do some fancy coding and make a metaclass that does this > auto-magically, or I have to have property decorators all over the place :-P > . I was wondering what other thought of this, is it an overly fanciful way > of coding python, or is it an acceptable thing to do in a real project? > Also, would anyone be interested in helping me make this metaclass? It's not a Pythonic style of coding. A property is generally assumed to be a cheap and simple lookup that cannot change anything - that is, it should be 'safe'. A no-arg method could mutate the object, could be expensive, could do just about anything. The parentheses make it clear that something's now happening - code's being called. Properties should be reserved for those cases where it's conceptually an attribute lookup, but for whatever reason you need a bit of code on it - and that's a pretty unusual case, compared to zero-argument methods. Strong recommendation that you don't do this. Of course, Python's "consenting adults" policy says that you're most welcome to - but you'll find that it's much more friendly to subsequent maintainers to keep attribute lookup and method call different. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to iterate through multidimensional space?
On Tue, 05 Aug 2014 20:06:05 +, Frank Miles wrote: > I need to evaluate a complicated function over a multidimensional space > as part of an optimization problem. This is a somewhat general problem > in which the number of dimensions and the function being evaluated can > vary from problem to problem. > > I've got a working version (with loads of conditionals, and it only works > to #dimensions <= 10), but I'd like something simpler and clearer and > less hard-coded. > > I've web-searched for some plausible method, but haven't found anything > "nice". Any recommendations where I should look, or what technique should > be used? > > TIA! A should have waited. The answer: itertools.product! very nice -- https://mail.python.org/mailman/listinfo/python-list
Re: Making every no-arg method a property?
On Tue, 5 Aug 2014 12:39:18 -0700 Christian Calderon wrote: > I have been using python for 4 years now, and I just started learning ruby. > I like that in ruby I don't have to type parenthesis at the end of each > function call if I don't need to provide extra arguments. I just realized > right now that I can do something similar in python, if I make all methods > with only the implicitly passed 'self' into properties. Which means I can > either do some fancy coding and make a metaclass that does this > auto-magically, or I have to have property decorators all over the place > :-P . I was wondering what other thought of this, is it an overly fanciful > way of coding python, or is it an acceptable thing to do in a real project? > Also, would anyone be interested in helping me make this metaclass? > Overly fanciful to my mind. Also, you'd eliminate the ability to talk about the function itself rather than the value thereof. No more help from the interactive console. No more passing the function as an argument. All to save '()', which is what tells other programmers that you're calling a function. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. -- https://mail.python.org/mailman/listinfo/python-list
Re: Making every no-arg method a property?
On 2014-08-05, Christian Calderon wrote: > I have been using python for 4 years now, and I just started learning > ruby. I like that in ruby I don't have to type parenthesis at the end > of each function call if I don't need to provide extra arguments. Did I miss a news story? Have the parentesis mines all exploded causing the price of parenthesis to skyrocket? > I just realized right now that I can do something similar in python, > if I make all methods with only the implicitly passed 'self' into > properties. Which means I can either do some fancy coding and make a > metaclass that does this auto-magically, or I have to have property > decorators all over the place :-P Here's an idea: when using Python, write Python. Just type the parens. I know it requires hitting the shift key and all, but it's not that hard -- especially if you have two hands. If you want to write Ruby, then use Ruby. > I was wondering what other thought of this, is it an overly fanciful > way of coding python, IMO, it's a huge waste of time and an excellent way to reduce both readability and maintainability of your code. > or is it an acceptable thing to do in a real project? No. It's not acceptable. Not even a tiny bit. > Also, would anyone be interested in helping me make this metaclass? Um... [I have the nagging feeling I've been trolled...] -- Grant Edwards grant.b.edwardsYow! Everywhere I look I at see NEGATIVITY and ASPHALT gmail.com... -- https://mail.python.org/mailman/listinfo/python-list
Re: Python and IDEs [was Re: Python 3 is killing Python]
On Tue, Aug 5, 2014 at 12:25 PM, Duncan Booth wrote: > So far they seem to have kept a pretty low profile; I suspect largely > because until recently PTVS only worked with the pay versions of Visual > Studio. > Not true. When it didn't work with the free express versions of VS, it worked with the free Visual Studio Shell (that people have also not heard about :) So there has always been some free way of running PTVS. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter menu crash
On 8/5/2014 8:15 AM, Nicholas Cannon wrote: Ok so the first part of the program(until the start of the menu) worked fine. It ran and did what I wanted it to do. What x.y.z version of Python. How did you run it, exactly? I wanted to then implement a new menu(for practise) and then it crashes. Don't know why but it just crashes. If you ran from Idle editor on Windows, start Idle with 'python -m idlelib' in Command Prompt to see tk error messages. However, when I pasted code into 3.4.1 Idle Editor, changed first two lines to from tkinter import * from tkinter import messagebox as tm and ran -- no crash, no error message, no menu. I entered text into box, clicked Submit text, and OK on popup, and nothing happens. See below for why no menu. When you ask about a problem, please reduce code to the minimum that exhibits the problem for you. (also tips on the code will be appreciated and I gave just started Tkinter programming) A different issue. Here is the code: from Tkinter import * import tkMessageBox as tm def submit(): #message box with yes no tm.askyesno(title='Submit Text', message='Are you sure') def info(): tm.showinfo(title='About', message='Just a test Tkinter UI sample') #getting the text from the entrybox and #packs it into a label mtext = text.get() label1 = Label(app, text=mtext) label1.pack() #root window setup root = Tk() root.geometry('480x480+200+200') root.title('Basic Tk UI') #frame set up app = Frame(root) app.pack() #variable and entry box set up text = StringVar() entry = Entry(app, textvariable=text) entry.pack() #button set up button1 = Button(app, text='Submit text', command= submit) button1.pack() #menu construction menubar = Menu(root) filemenu = Menu(menubar) filemenu.add_command(label='About', command= info) filemenu.add_command(label='Quit', command= root.destroy) filemenu.add_cascade(label='TK UI Sample', menu=filemenu) Adding filemenu as a submenu of filemenu leads to infinite loop regress. On 3.4.1 with tcl/tk 8.6, this does not crash, but it might on an earlier version of Python and tcl/tk. Since menubar is left empty, it is not displayed. Fix both problems with menubar.add_cascade(label='TK UI Sample', menu=filemenu) root.config(menu=menubar) #loop to listen for events root.mainloop() -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Making every no-arg method a property?
On Tue, Aug 5, 2014 at 1:39 PM, Christian Calderon wrote: > I have been using python for 4 years now, and I just started learning ruby. > I like that in ruby I don't have to type parenthesis at the end of each > function call if I don't need to provide extra arguments. I just realized > right now that I can do something similar in python, if I make all methods > with only the implicitly passed 'self' into properties. Which means I can > either do some fancy coding and make a metaclass that does this > auto-magically, or I have to have property decorators all over the place :-P > . I was wondering what other thought of this, is it an overly fanciful way > of coding python, or is it an acceptable thing to do in a real project? > Also, would anyone be interested in helping me make this metaclass? The metaclass to do this is easy: import inspect import types class autoprop(type): def __init__(cls, name, bases, attrs): for name, value in attrs.items(): if (name.startswith('__') and name.endswith('__') or not isinstance(value, types.FunctionType)): continue argspec = inspect.getfullargspec(value) if (len(argspec.args) == 1 and not any([argspec.varargs, argspec.varkw, argspec.kwonlyargs])): setattr(cls, name, property(value)) But I'm in agreement with the others in this thread that it's not really a good idea. In addition to the arguments made by others, note that this doesn't actually make the parentheses optional; it makes their absence required. That's a fundamental limitation, because it's up to the descriptor to automatically call the method or not, and the descriptor has no way of knowing whether the thing it's returning is about to be called or not. Also, as a consequence of the above, note that this only works for methods that take no arguments at all (except self). If the method has optional arguments, and you replace it with a property, then you no longer have any way to pass those optional arguments. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.4.1 install does not create a file association for .py files on Windows
On 8/5/2014 3:36 PM, Edward Diener wrote: I install Python 3.4.1 64-bit on Windows. After the install I type: I have done the same, on Win 7, but I had previous installs going back 3 years on this machine. assoc .py and I get back: File association not found for extension .py I get C:\Users\Terry>assoc .py .py=Python.File C:\Users\Terry>assoc .pyw .pyw=Python.NoConFile C:\Users\Terry>assoc .pyo .pyo=Python.CompiledFile C:\Users\Terry>assoc .pyc .pyc=Python.CompiledFile None of this specifies the program, which is currently Python Launcher for Windows (console). (See Control Panel / Default Programs / Set Associations.) Why does not the Python install to associate extension .py with the Python Launcher for Windows ? Somewhere during the install, there is a checkbox or something about grabbing file associations or about making the install the default version. I do not remember. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: cmd.exe on WIndows - problem with displaying some Unicode characters
On 05 Aug 2014 20:26:08 GMT, Tony the Tiger wrote: > On Mon, 04 Aug 2014 00:52:29 +0200, Wiktor wrote: > >> okumenty\python\kolony\menu.py", line 14, in > > This works for me on Linux: I believe you, but I use Windows and its cmd.exe (as mentioned in subject). -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.4.1 install does not create a file association for .py files on Windows
On 8/5/2014 6:16 PM, Terry Reedy wrote: On 8/5/2014 3:36 PM, Edward Diener wrote: I install Python 3.4.1 64-bit on Windows. After the install I type: I have done the same, on Win 7, but I had previous installs going back 3 years on this machine. assoc .py and I get back: File association not found for extension .py I get C:\Users\Terry>assoc .py .py=Python.File C:\Users\Terry>assoc .pyw .pyw=Python.NoConFile C:\Users\Terry>assoc .pyo .pyo=Python.CompiledFile C:\Users\Terry>assoc .pyc .pyc=Python.CompiledFile None of this specifies the program, which is currently Python Launcher for Windows (console). (See Control Panel / Default Programs / Set Associations.) Why does not the Python install to associate extension .py with the Python Launcher for Windows ? Somewhere during the install, there is a checkbox or something about grabbing file associations or about making the install the default version. I do not remember. I uninstalled all my Python versions and then re-installed each one. Now the correct file association has been made. Something was fouled up in the installation process which is now fixed. -- https://mail.python.org/mailman/listinfo/python-list
Re: Controlling py.exe launcher on Windows
On 8/5/2014 1:27 PM, Edward Diener wrote: I am trying to control the default version of the py.exe launcher on Windows. I have the Python 2.7.8 and 3.4.1 installed with both the 32 bit and 64 bit versions, all in different directories. I assume that .py and .pyw files are associated with the py.exe launcher. I am trying to control which version starts through a py.ini file in the same directory as the py.exe file in the 3.4.1 version last installed. If I specify in the [defaults] section of py.ini: python=3.4 then launching py.exe will show: Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AM D64)] on win32 If I specify: python=3.4-32 then launching py.exe will show: Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win 32 Is it really true that I cannot specify the 32 bit version in the .ini file or am I doing something wrong here ? After uninstalling my Python versions and re-installing them, everything works properly and I can control the version which py.exe starts from the py.ini file. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter menu crash
Ok so I am on 2.7.8. > What x.y.z version of Python. How did you run it, exactly? > Adding filemenu as a submenu of filemenu leads to infinite loop regress. > > On 3.4.1 with tcl/tk 8.6, this does not crash, but it might on an > > earlier version of Python and tcl/tk. > Since menubar is left empty, it is not displayed. Fix both problems with > >menubar.add_cascade(label='TK UI Sample', menu=filemenu) > > root.config(menu=menubar) Yeah this fixed the problem. So the main menu object needs to be cascade instead of the filemenu. Will this need to be done every I create a new menu? >and ran -- no crash, no error message, no menu. I entered text into box, >clicked Submit text, and OK on popup, and nothing happens. Im not quite sure what is happening here. Oh I just looked at the code and the part that sends the entry box text is in the wrong place or must have been unindented I have fixed this now and it works great. -- https://mail.python.org/mailman/listinfo/python-list
Re: Making every no-arg method a property?
Grant Edwards wrote: Did I miss a news story? Have the parentesis mines all exploded causing the price of parenthesis to skyrocket? The Unicode Consortium has been secretly buying them up for some time now. Pretty soon you won't be able to get cheap ASCII parentheses any more, only the fancy high-priced ones like U+2045/U+2046, U+2772/U+2773 and U+27E6/U+27E7. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Controlling py.exe launcher on Windows
On 8/5/2014 1:27 PM, Edward Diener wrote: I am trying to control the default version of the py.exe launcher on Windows. I have the Python 2.7.8 and 3.4.1 installed with both the 32 bit and 64 bit versions, all in different directories. I assume that .py and .pyw files are associated with the py.exe launcher. I am trying to control which version starts through a py.ini file in the same directory as the py.exe file in the 3.4.1 version last installed. If I specify in the [defaults] section of py.ini: python=3.4 then launching py.exe will show: Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AM D64)] on win32 If I specify: python=3.4-32 This looks correct according to the manual. then launching py.exe will show: Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win 32 Is it really true that I cannot specify the 32 bit version in the .ini file or am I doing something wrong here ? First try > py -3.4-32 on the command line to make sure that py can find and launch that version. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter menu crash
On 8/5/2014 6:28 PM, Nicholas Cannon wrote: Ok so I am on 2.7.8. What x.y.z version of Python. How did you run it, exactly? Adding filemenu as a submenu of filemenu leads to infinite loop regress. On 3.4.1 with tcl/tk 8.6, this does not crash, but it might on an earlier version of Python and tcl/tk. Since menubar is left empty, it is not displayed. Fix both problems with menubar.add_cascade(label='TK UI Sample', menu=filemenu) root.config(menu=menubar) Yeah this fixed the problem. So the main menu object needs to be cascade instead of the filemenu. Will this need to be done every I create a new menu? I am not sure what you mean here. The main menu bar menubar is not a cascade. Added to root as the menu attribute, it displays horizonatally. You add filemenu to menebar as a cascade. It then displays vertically under its label on the main menu. It is fairly conventional that all the entries on the main menu are cascades, but apparently not necessary. It is also fairly conventional that most items on drop down menus are not cascades, but you could add a third menu to filemenu as a cascade. and ran -- no crash, no error message, no menu. I entered text into box, clicked Submit text, and OK on popup, and nothing happens. Im not quite sure what is happening here. Oh I just looked at the code and the part that sends the entry box text is in the wrong place or must have been unindented I have fixed this now and it works great. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Controlling py.exe launcher on Windows
On 8/5/2014 7:02 PM, Terry Reedy wrote: On 8/5/2014 1:27 PM, Edward Diener wrote: I am trying to control the default version of the py.exe launcher on Windows. I have the Python 2.7.8 and 3.4.1 installed with both the 32 bit and 64 bit versions, all in different directories. I assume that .py and .pyw files are associated with the py.exe launcher. I am trying to control which version starts through a py.ini file in the same directory as the py.exe file in the 3.4.1 version last installed. If I specify in the [defaults] section of py.ini: python=3.4 then launching py.exe will show: Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AM D64)] on win32 If I specify: python=3.4-32 This looks correct according to the manual. then launching py.exe will show: Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win 32 Is it really true that I cannot specify the 32 bit version in the .ini file or am I doing something wrong here ? First try > py -3.4-32 on the command line to make sure that py can find and launch that version. I see you already fixed things by reinstalling. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter menu crash
I am confused. When I did menu bar.add_cascade why don't I do filemenu.add_cascade. Is it because I am adding a cascade to the main menubar? -- https://mail.python.org/mailman/listinfo/python-list
Re: Making every no-arg method a property?
Christian Calderon writes: > I like that in ruby I don't have to type parenthesis at the end of > each function call if I don't need to provide extra arguments. Whereas I like the opposite: there is a clear syntactic distinction between “get the value of ‘foo.bar.baz’” versus “get the value returned when calling ‘foo.bar.baz’”. Having the same name sometimes refer to “get this as a value” and other times “call this as a function and get the return value” imposes a cognitive load on the reader, IMO an unnecessary one. -- \“If this is your first visit to the USSR, you are welcome to | `\ it.” —hotel room, Moscow | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Making every no-arg method a property?
Christian Calderon wrote: > I have been using python for 4 years now, and I just started learning > ruby. I like that in ruby I don't have to type parenthesis at the end of > each function call if I don't need to provide extra arguments. That's one of the things which I dislike most about Ruby. Python has a nice, clean design: obj.method returns the method object, x() on any object calls it. (Possibly not successfully, if it is not a type, function or method, but it makes the attempt.) Making the parentheses optional just confuses the two, just for the sake of saving a couple of keystrokes. > I just > realized right now that I can do something similar in python, if I make > all methods with only the implicitly passed 'self' into properties. I wouldn't expect that there should be very many of such methods (except in, say, a type like str, where you have a bunch of transformation methods like str.upper() etc. -- but they shouldn't be treated as properties at all). A plethora of argument-less methods is a code smell -- that doesn't mean it's *necessarily* a bad idea, but the class design really needs a careful review. The problem with argument-less methods is that things which should be temporary arguments are being stored as permanent state instead. E.g. if you're calling methods just for their side-effect of setting up a bunch of attributes, just so you can then do what you really want which is call another method, that's a bad design which should be refactored to pass arguments direct to the method: # Bad class SandwichMaker: def prepare_sandwich_ingredients(self, bread, butter, fillings, openface=False): self._bread = bread self.butter = butter self.fillings = fillings self.openface = openface def make_sandwich(self): base = self.bread if not self.openface: cover = self.bread else: cover = None if self.butter in ('butter', 'margarine', 'mayo'): base += self.butter if cover: cover += self.butter for filling in self.fillings: self.thing_to_get = filling base += self.get_ingredient() if cover: # butter goes on the inside, not the top self.thing_to_flip = cover self.flip_the_thing_that_needs_flipping() base += self.thing_to_flip return base Obviously this is a fanciful example, but I've seen too much real code where too many methods existed solely to stuff data into an attribute so another method could get to it, after which that attribute was unneeded. It's the OOP equivalent of writing functions which communicate only by global variable. > Which > means I can either do some fancy coding and make a metaclass that does > this auto-magically, or I have to have property decorators all over the > place > :-P . I was wondering what other thought of this, is it an overly fanciful > way of coding python, or is it an acceptable thing to do in a real > project? Also, would anyone be interested in helping me make this > metaclass? Personally, I think it's a horrible idea, but if you must do it, I'd suggest doing it with a class decorator, not a metaclass. Something like this: # Untested. def make_zero_arg_methods_into_properties(cls): for name, obj in vars(cls).items(): if inspect.isfunction(obj): if inspect.getargspec(obj) == (['self'], None, None, ()): setattr(cls, name, property(obj)) return cls @make_zero_arg_methods_into_properties class Spam: def eggs(self): ... -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Making every no-arg method a property?
On Wed, Aug 6, 2014 at 10:49 AM, Steven D'Aprano wrote: > A > plethora of argument-less methods is a code smell -- that doesn't mean it's > *necessarily* a bad idea, but the class design really needs a careful > review. There are plenty of no-argument mutator methods, where the name of the method (and the target object, obviously) is all the info you need. You can clear() or copy() something with any more info, reverse() a list, pop() from a list, etc. (Okay, the last one has a default argument, but that raises an even worse point: adding a defaulted argument to a no-argument method suddenly stops it from being a property, which violates the usual rule that you can add a defaulted argument to anything without breaking anything.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter menu crash
On 8/5/2014 7:33 PM, Nicholas Cannon wrote: I am confused. When I did menu bar.add_cascade why don't I do filemenu.add_cascade. Is it because I am adding a cascade to the main menubar? Let us start with a widget, that can 'contain' other widgets (and possibly other things). We create a child widget (which keeps a reference to the parent. Now we want to put it into the parent. How? The generic grid, pack, and place geometry methods are called on the child, with no mention of the parent. (The child reference to the parent is used instead.) Do note, however, that child-independent geometry configure methods, like grid rowconfigure, are called on the parent. Widget-specific geometry methods, however, are (mostly at least) called on the parent, with the child passed as a parameter. Menus can contain both commands, which are not widgets, and submenus, which are. They are packed with add_command and add_cascade. Canvases have add methods that place items, which again may or may not be widgets. I initially found child.pack(args) confusing, because I expected the pattern to be (child.parent).pack(child, args). But now that I think about it, the shortcut is similar to instance.method(args) sometimes meaning (instance.__class__).method(instance, args). The convenience in both cases is about the same. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Making every no-arg method a property?
On 6/08/2014 9:49 AM, Ben Finney wrote: Christian Calderon writes: I like that in ruby I don't have to type parenthesis at the end of each function call if I don't need to provide extra arguments. Having the same name sometimes refer to “get this as a value” and other times “call this as a function and get the return value” imposes a cognitive load on the reader, IMO an unnecessary one. It also makes it impossible to use such methods in dispatch patterns or as callbacks. -- https://mail.python.org/mailman/listinfo/python-list
Re: Making every no-arg method a property?
On 2014-08-05, Gregory Ewing wrote: > Grant Edwards wrote: >> Did I miss a news story? Have the parentesis mines all exploded >> causing the price of parenthesis to skyrocket? > > The Unicode Consortium has been secretly buying them > up for some time now. Pretty soon you won't be able > to get cheap ASCII parentheses any more, only the > fancy high-priced ones like U+2045/U+2046, > U+2772/U+2773 and U+27E6/U+27E7. Damn. Time to buy some options... -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: TypeError: 'bytes' object is not callable error while trying to converting to bytes.
> On Aug 4, 2014, at 22:57, Chris Angelico wrote: > > On Tue, Aug 5, 2014 at 3:47 PM, Satish ML wrote: > bytes = file.read() > > You've just shadowed the built-in type 'bytes' with your own 'bytes'. > Pick a different name for this, and you'll be fine. 'data' would work. Until python4 introduces the 'data' built in. :) -- https://mail.python.org/mailman/listinfo/python-list
Re: TypeError: 'bytes' object is not callable error while trying to converting to bytes.
On Wed, Aug 6, 2014 at 3:31 PM, Travis Griggs wrote: >> On Aug 4, 2014, at 22:57, Chris Angelico wrote: >> >> On Tue, Aug 5, 2014 at 3:47 PM, Satish ML wrote: >> bytes = file.read() >> >> You've just shadowed the built-in type 'bytes' with your own 'bytes'. >> Pick a different name for this, and you'll be fine. 'data' would work. > > Until python4 introduces the 'data' built in. :) Python 3.6 could introduce that, no need to wait for Python 4. :) However, it wouldn't be critical to this code, unless the builtin's meaning is also wanted; it'd be on par with the shadowing of 'file' earlier - given how rarely Python programs actually need 'file' (rather than 'open'), it's not a big deal to shadow that one. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to iterate through multidimensional space?
Dear Peter Below is the code I tried to check if itertools.product() was faster than normal nested loops... they arent! arent they supposed to be...or am i making a mistake? any idea? ** *# -*- coding: utf-8 -*-* *import numpy as np* *import time* *from itertools import product,repeat* *def main():* *# N - size of grid* *# nvel - number of velocities* *# times - number of times to run the functions* *N=256* *times=3* *f=np.random.rand(N,N,N)* *# using loops* *print "normal nested loop"* *python_dot_loop1(f,times,N)* *print "nested loop using itertools.product()"* *python_dot_loop2(f,times,N)* *def python_dot_loop1(f,times,N):* *for t in range(times):* * t1=time.time()* * for i in range(N):* * for j in range(N):* * for k in range(N):* * f[i,j,k] = 0.0* * print "python dot loop " + str(time.time()-t1)* *def python_dot_loop2(f,times,N):* *rangeN=range(N)* *for t in range(times):* * t1=time.time()* * for i,j,k in product(rangeN,repeat=3):* * f[i,j,k]=0.0* * print "python dot loop " + str(time.time()-t1)* *if __name__=='__main__':* *main()* ** -- https://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to iterate through multidimensional space?
On Wed, Aug 6, 2014 at 3:34 PM, Gayathri J wrote: > Below is the code I tried to check if itertools.product() was faster than > normal nested loops... > > they arent! arent they supposed to be...or am i making a mistake? any idea? Don't worry about what's faster. That almost never matters. Worry, instead, about how you would code it if you can't be sure how many dimensions there'll be until run time (which the OP said can happen). With product(), you can give it a variable number of arguments (eg with *args notation), but with loops, you'd need to compile up some code with that many nested loops - or at best, something where you cap the number of loops and thus dimensions, and have a bunch of them iterate over a single iterable. ChrisA -- https://mail.python.org/mailman/listinfo/python-list