From simoncropper at fossworkflowguides.com Fri Jun 1 02:24:45 2012 From: simoncropper at fossworkflowguides.com (Simon Cropper) Date: Fri, 01 Jun 2012 16:24:45 +1000 Subject: wxpython using variable with wx.statictext ignores \n Message-ID: <4FC8602D.5030509@fossworkflowguides.com> Hi, I have some wxPython code created with wxGlade that I am customizing. I have a label created under the def __init__() section of the Frame Class. It states... self.Question = wx.StaticText(self, -1, "My question...") if I insert a new line character in this string like this then the output is placed on two lines as expected. self.Question = wx.StaticText(self, -1, "My \nquestion...") Output My question I am getting the question as an argument using sys.argv[] and putting it in a variable called "question_text". The code is as follows... question_text = "My \nquestion..." self.Question = wx.StaticText(self, -1, question_text) Output My \nquestion How do I get the line text \n recognized so the break is inserted using the variable technique like what happened when I actually used a string? ...in bash you would do "$question_text". Is there comparable macro substitution in python. -- Cheers Simon Simon Cropper - Open Content Creator / Website Administrator Free and Open Source Software Workflow Guides ------------------------------------------------------------ Introduction http://www.fossworkflowguides.com GIS Packages http://www.fossworkflowguides.com/gis bash / Python http://www.fossworkflowguides.com/scripting From ulrich.eckhardt at dominolaser.com Fri Jun 1 03:46:04 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 01 Jun 2012 09:46:04 +0200 Subject: How to suppress exception printing to console? In-Reply-To: References: Message-ID: Am 01.06.2012 05:06, schrieb Qi: > On 2012-5-31 23:01, Ulrich Eckhardt wrote: >> I can only guess what you are doing, maybe you should provide a simple >> piece of code (or, rather, one C++ piece and a Python piece) that >> demonstrates the issue. What I could imagine is that the Python >> interpreter shuts down with something it considers an unhandled >> exception, which it then prints to stdout before exiting. When >> embedding, that shouldn't happen from just calling a Python function in >> a loaded script, those should just make the error available to the C++ >> side via PyErr functions etc. > > > PyRun_SimpleString("SomeCppFunc(1, 2)"); > > SomeCppFunc is C++ function bound to Python, and in SomeCppFunc > it detects the parameter mismatch (such as it expects the first > parameter to be a string), it throws an exception. > Then the C++ binding code catches the exception, and call > PyErr_SetString to propagate it to Python. I think this has nothing to do with the called C++ code, I guess the same happens if you call PyRun_SimpleString("raise Exception()");. > Then Python will print the error message to console. > What I want to do is to suppress the error message printing... Don't use PyRun_SimpleString() or catch the exception there. The point is that it runs the whole string as a module, like running a script from the commandline, and a pending exception on exit is then reported to stdout. What I do here is that I create a module using the C API that I register with Py_InitModule(). It contains the C++ functions exported to Python. I then load a script using PyImport_ImportModule() and use PyObject_GetAttrString(), PyCallable_Check() and PyObject_CallObject() to run the main function of that script. > Can I redirect sys.stdout in C++? Maybe, I haven't tried. Since I require a proper main function in the Python code anyway, I added a few more requirements, i.e. that it uses one of the provided C++ functions for output. I think you can simply assign "sys.stdout.write = log_string", where log_string is the provided C++ function. Uli From matteo at matteolandi.net Fri Jun 1 06:00:02 2012 From: matteo at matteolandi.net (Matteo Landi) Date: Fri, 1 Jun 2012 12:00:02 +0200 Subject: Tkinter deadlock on graceful exit In-Reply-To: References: <20120527222125.GA22965@MARble> <20120530221925.GA12763@MARble> Message-ID: On Thu, May 31, 2012 at 3:02 PM, Matteo Landi wrote: > On Thu, May 31, 2012 at 3:42 AM, Terry Reedy wrote: >> On 5/30/2012 6:19 PM, Matteo Landi wrote: >>> >>> On May/28, Matteo Landi wrote: >>>> >>>> Hi list, >>>> recently I started to work on an application [1] which makes use of the >>>> Tkinter >>>> module to handle interaction with the user. ?Simply put, the app is a >>>> text >>>> widget displaying a file filtered by given criteria, with a handy feature >>>> that >>>> the window is raised each time a new line is added to the widget. >>>> >>>> The application mainly consists of three threads: ?the first one, the >>>> file >>>> processor, reads the file, filters the lines of interest, and pushes them >>>> into >>>> a shared queue (henceforth `lines_queue`); ?the second one, the >>>> gui_updater, >>>> pops elements from `lines_queue`, and schedule GUI updates using the >>>> `after_idle` method of the Tkinter module; ?finally the last one, the >>>> worker >>>> spawner, receives commands by the gui (by means of a shared queue, >>>> `filters_queue`), and drives the application, terminating or spawning new >>>> threads. >>>> >>>> For example, let's see what happens when you start the application, fill >>>> the >>>> filter entry and press Enter button: >>>> 1 the associated even handler is scheduled (we should be inside the >>>> Tkinter >>>> ? mainloop thread), and the filter is pushed into `filters_queue`; >>>> 2 the worker spawner receives the new filter, terminate a possibly >>>> running >>>> ? working thread, and once done, create a new file processor; >>>> 3 the file processor actually processes the file and fills the >>>> `lines_queue` >>>> ? with the lines matching given filter; >>>> 4 the gui updater schedules GUI updates as soon as items are pushed into >>>> ? `lines_queue` >>>> 5 Tkinter mainloop thread updates the gui when idle >>>> >>>> What happens when the main window is closed? ?Here is how I implemented >>>> the >>>> graceful shutdown of the app: >>>> 1 a quit event is scheduled and a _special_ message is pushed into both >>>> ? `filter_queue` and `lines_queue` >>>> 2 the gui updater threads receives the _special_ message, and terminates >>>> 3 the worker spawner receives the message, terminates the working thread >>>> and >>>> ? interrupts her execution. >>>> 4 Tk.quit() is called after the quit event handler, and we finally quit >>>> the >>>> ? mainloop >>>> >>>> Honestly speaking, I see no issues with the algorithm presented above; >>>> ?however, >>>> if I close the window in the middle of updates of the text widget, the >>>> applications hangs indefinitely. ?On the other hand, everything works as >>>> expected if I close the app when the file processor, for example, is >>>> waiting for >>>> new content to filter. >>>> >>>> I put some logging messages to analyze the deadlock (?!), and noticed >>>> that both >>>> the worker spawner and the file processor are terminated correctly. ?The >>>> only >>>> thread still active for some strange reasons, is the gui updater. >>>> >>>> Do you see anything wrong with the description presented above? ?Please >>>> say so, >>>> because I can't figure it out! >> >> >> Since no-one else answered, I will ask some questions based on little >> tkinter experience, no thread experience, and a bit of python-list reading. >> >> 1. Are you only using tkinter in one thread? (It seems like so from the >> above)? > > Yes, provided that `after_idle` queues a job for the gui thread > >> >> 2. Is root.destroy getting called, as in 24.1.2.2. A Simple Hello World >> Program in the most recent docs? (I specify 'most recent' because that >> example has been recently revised because the previous version sometimes >> left tkinter hanging for one of the code paths, perhaps similar to what you >> describe. > > No, I'm not calling the destroy method of the main window but, why > that only happens while doing gui updates? > >> >> 3. Have you tried making the gui thread the master thread? (I somehow expect >> that the gui thread should be the last to shut down.) > > No but, same question as above. > > I'm not home right now, so I will try those solutions as soon as > possible. ?Thanks. > > > Cheers, > Matteo > >> >> -- >> Terry Jan Reedy >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > > > -- > http://www.matteolandi.net/ Doing further investigation, I found this post [1] dated 2005, which probably explains why I'm gatting this strange deadlock. Quoting the linked article: All Tkinter access must be from the main thread (or, more precisely, the thread that called mainloop). Violating this is likely to cause nasty and mysterious symptoms such as freezes or core dumps. Yes this makes combining multi-threading and Tkinter very difficult. The only fully safe technique I have found is polling (e.g. use after from the main loop to poll a threading Queue that your thread writes). I have seen it suggested that a thread can safely use event_create to communicate with the main thread, but have found this is not safe. Well, if this still applies, then I'm invoking `after_idle` from a thread different from the mainloop's one. I'll try to implement the poll/queue fix, and see if this solves the issue. Matteo [1] http://mail.python.org/pipermail/tkinter-discuss/2005-February/000313.html -- http://www.matteolandi.net/ From prakash.stack at gmail.com Fri Jun 1 06:08:58 2012 From: prakash.stack at gmail.com (prakash jp) Date: Fri, 1 Jun 2012 15:38:58 +0530 Subject: get latest from svn Message-ID: Hi All, Can some one suggest me a module to access SVN repository so that i could download any given branch. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From no at no.com Fri Jun 1 10:06:25 2012 From: no at no.com (Qi) Date: Fri, 01 Jun 2012 22:06:25 +0800 Subject: How to suppress exception printing to console? References: Message-ID: On 2012-6-1 15:46, Ulrich Eckhardt wrote: > > Don't use PyRun_SimpleString() or catch the exception there. The point > is that it runs the whole string as a module, like running a script from > the commandline, and a pending exception on exit is then reported to stdout. Good hint, thanks. -- WQ From python at mrabarnett.plus.com Fri Jun 1 10:37:29 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 01 Jun 2012 15:37:29 +0100 Subject: wxpython using variable with wx.statictext ignores \n In-Reply-To: <4FC8602D.5030509@fossworkflowguides.com> References: <4FC8602D.5030509@fossworkflowguides.com> Message-ID: <4FC8D3A9.1020706@mrabarnett.plus.com> On 01/06/2012 07:24, Simon Cropper wrote: > Hi, > > I have some wxPython code created with wxGlade that I am customizing. > > I have a label created under the def __init__() section of the Frame > Class. It states... > > self.Question = wx.StaticText(self, -1, "My question...") > > if I insert a new line character in this string like this then the > output is placed on two lines as expected. > > self.Question = wx.StaticText(self, -1, "My \nquestion...") > > Output My > question > > I am getting the question as an argument using sys.argv[] and putting > it in a variable called "question_text". The code is as follows... > > > question_text = "My \nquestion..." > self.Question = wx.StaticText(self, -1, question_text) > > Output My \nquestion > > How do I get the line text \n recognized so the break is inserted using > the variable technique like what happened when I actually used a string? > > ...in bash you would do "$question_text". Is there comparable macro > substitution in python. > In a Python script, a \n within a plain string literal such as "My \nquestion..." will be treated as a newline character. If you're getting the string from the command line, a \n will be treated as backslash '\' followed by letter 'n', so it's equivalent to the string literal "\\n". In Python 2, you can unescape a string using its .decode method: >>> "My \\nquestion..." 'My \\nquestion...' >>> "My \\nquestion...".decode("string_escape") 'My \nquestion...' From lamialily at cleverpun.com Fri Jun 1 11:23:44 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Fri, 01 Jun 2012 08:23:44 -0700 Subject: CPython 2.7: Weakset data changing size during internal iteration Message-ID: I've got a bit of a problem - my project uses weak sets in multiple areas, the problem case in particular being to indicate what objects are using a particular texture, if any, so that its priority in OpenGL can be adjusted to match at the same time as it being (de)referenced by any explicit calls. Problem is that for certain high-frequency operations, it seems there's too much data going in and out for it to handle - the following traceback is given to me (project path changed to protect the innocent): Traceback (most recent call last): File "C:\foo\bar\game.py", line 279, in update self.player.update() File "C:\foo\bar\player.py", line 87, in update PlayerBullet((self.x + 8, self.y + 9), 0, self.parent) File "C:\foo\bar\player.py", line 96, in __init__ self.sprite = video.Sprite("testbullet", 0) File "C:\foo\bar\video.py", line 95, in __init__ self.opengl_id = reference_texture(self, target) File "C:\foo\bar\video.py", line 310, in reference_texture if not video_handler.textures[target].references: File "C:\Python27\lib\_weakrefset.py", line 66, in __len__ return sum(x() is not None for x in self.data) File "C:\Python27\lib\_weakrefset.py", line 66, in return sum(x() is not None for x in self.data) RuntimeError: Set changed size during iteration I can post the sources relevant to the traceback upon request, but hopefully a traceback is sufficient as the most immediate problem is in Python's libraries. Any suggestions on what to do about this? I can't exactly throw a .copy() in on top of the data iteration and call it good since it's part of the standard Python library. ~Temia -- When on earth, do as the earthlings do. From list at qtrac.plus.com Fri Jun 1 12:34:41 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Fri, 1 Jun 2012 09:34:41 -0700 (PDT) Subject: Use a locally built Tk for Python? Message-ID: <900b402d-c6b0-4e00-beea-a18417764ee8@b26g2000vbt.googlegroups.com> Hi, I have multiple Pythons locally installed so that I can test against different versions. (On a 64-bit Debian stable system.) All of them use the system's Tcl/Tk installation. However, I want to make some of them use a locally build Tcl/Tk that has a small customization. There doesn't seem to be any --with-tk or --with-tcl options for configure that would allow me to say where my local Tcl/Tk is. So I ran ./configure --prefix=/home/mark/opt/py32tkmod And then I tried editing Modules/Setup: I just uncommented and edited the _tkinter line as follows: _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \ -L/home/mark/opt/tcltk85/lib \ -I/home/mark/opt/tcltk85/include \ -I/usr/X11R6/include \ -ltk8.5 -ltcl8.5 \ -L/usr/X11R6/lib \ -lX11 But when I run ~/opt/py32tkmod/bin/python3 tkinter-test.pyw the system tk is being used not my customized one. Can anyone advise? Thanks! From sjbenner at gmail.com Fri Jun 1 12:39:36 2012 From: sjbenner at gmail.com (Josh Benner) Date: Fri, 1 Jun 2012 09:39:36 -0700 Subject: understanding operator overloading Message-ID: Is there a good way to trace what's going on under the hood wrt operator overloading? I am trying to understand what is happening in the code and output listed below. Why doesn't __getitem__ in mylist return the same result as the builtin list object? Does it have something to do with the start and stop arguments to slice? Is the slice object making the call to __len__? ____code___________________________________________________ class mylist(): def __init__(self, data): self.data = data def __len__(self): print('len(self.data) -> self.data = {0}'.format(self.data)) return len(self.data) def __getitem__(self, index): print('__getitem__(index) -> index = {0}'.format(index)) return self.data[index] if __name__ == "__main__": alist = [1, 2, 4] blist = mylist(alist) print('printing alist[-4:]') print(alist[-4:]) print('printing blist[-4:]') print(blist[-4:]) print('printing blist[-2]') print(blist[-2]) ____output_________________________________________________ printing alist[-4:] [1, 2, 4] printing blist[-4:] len(self.data) -> self.data = [1, 2, 4] __getitem__(index) -> index = slice(-1, 9223372036854775807, None) [4] printing blist[-2] __getitem__(index) -> index = -2 2 Best, Josh Benner -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Jun 1 13:50:21 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 01 Jun 2012 10:50:21 -0700 Subject: DBF records API Message-ID: <4FC900DD.5020107@stoneleaf.us> I'm getting towards an actual non-beta release, which means even more tests, polishings, cleaning up of various things, and actual documentation. :) However, I am wondering about my current record API: Currently, one does things like: record.scatter_fields() or record.has_been_deleted or record.record_number The reason those method names are so long is that field names are limited to 10 characters, and long method names means no possibility of name clashes. Unfortunately, Version 7 tables can have much longer field names. So, do I not ever support version 7, do I not worry about it until I get there (which could easily be a long time from now), or do I move all the methods out of the record class and make them module level functions instead? That would like: dbf.scatter_fields(record) dbf.has_been_deleted(record) dbf.record_number(record) although probably with shorter names. Thoughts? ~Ethan~ From davidgshi at yahoo.co.uk Fri Jun 1 13:59:57 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Fri, 1 Jun 2012 18:59:57 +0100 (BST) Subject: While stack: Message-ID: <1338573597.20501.YahooMailNeo@web171601.mail.ir2.yahoo.com> Can any one clarify what "while stack:" mean? Regards, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From corey at octayn.net Fri Jun 1 15:00:46 2012 From: corey at octayn.net (Corey Richardson) Date: Fri, 1 Jun 2012 15:00:46 -0400 Subject: get latest from svn In-Reply-To: References: Message-ID: <20120601150046.41cb5cc9@Ulysses.myhome.westell.com> On Fri, 1 Jun 2012 15:38:58 +0530 prakash jp wrote: > Hi All, > > Can some one suggest me a module to access SVN repository so that i > could download any given branch. > > Thanks Doing some basic googling, I found: http://pysvn.tigris.org/ I imagine you could also shell out. -- Corey Richardson From corey at octayn.net Fri Jun 1 15:04:27 2012 From: corey at octayn.net (Corey Richardson) Date: Fri, 1 Jun 2012 15:04:27 -0400 Subject: While stack: In-Reply-To: <1338573597.20501.YahooMailNeo@web171601.mail.ir2.yahoo.com> References: <1338573597.20501.YahooMailNeo@web171601.mail.ir2.yahoo.com> Message-ID: <20120601150427.37864fc3@Ulysses.myhome.westell.com> On Fri, 1 Jun 2012 18:59:57 +0100 (BST) David Shi wrote: > Can any one clarify what "while stack:" mean? > > Regards, > > David > Formal explanation: http://docs.python.org/reference/compound_stmts.html#while Informal introduction: http://learnpythonthehardway.org/book/ex33.html Simplistic summary: it executes the indented code under the "while" until stack evaluates to non-True. -- Corey Richardson From rosuav at gmail.com Fri Jun 1 15:08:39 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jun 2012 05:08:39 +1000 Subject: While stack: In-Reply-To: <1338573597.20501.YahooMailNeo@web171601.mail.ir2.yahoo.com> References: <1338573597.20501.YahooMailNeo@web171601.mail.ir2.yahoo.com> Message-ID: On Sat, Jun 2, 2012 at 3:59 AM, David Shi wrote: > Can any one clarify what "while stack:" mean? It iterates as long as 'stack' has something that evaluates as true. My guess is that stack is a list, and the loop is removing elements from that list, so it'll keep going as long as there's anything in it. ChrisA From python at mrabarnett.plus.com Fri Jun 1 15:08:47 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 01 Jun 2012 20:08:47 +0100 Subject: While stack: In-Reply-To: <1338573597.20501.YahooMailNeo@web171601.mail.ir2.yahoo.com> References: <1338573597.20501.YahooMailNeo@web171601.mail.ir2.yahoo.com> Message-ID: <4FC9133F.9060207@mrabarnett.plus.com> On 01/06/2012 18:59, David Shi wrote: > Can any one clarify what "while stack:" mean? > By convention, an empty container is considered false and a non-empty container true in Boolean tests. Therefore, assuming that "stack" is a container, it means "while the stack isn't empty". From python at mrabarnett.plus.com Fri Jun 1 15:15:17 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 01 Jun 2012 20:15:17 +0100 Subject: DBF records API In-Reply-To: <4FC900DD.5020107@stoneleaf.us> References: <4FC900DD.5020107@stoneleaf.us> Message-ID: <4FC914C5.6010106@mrabarnett.plus.com> On 01/06/2012 18:50, Ethan Furman wrote: > I'm getting towards an actual non-beta release, which means even more > tests, polishings, cleaning up of various things, and actual > documentation. :) > > However, I am wondering about my current record API: > > Currently, one does things like: > > record.scatter_fields() > > or > > record.has_been_deleted > > or > > record.record_number > > The reason those method names are so long is that field names are > limited to 10 characters, and long method names means no possibility of > name clashes. > > Unfortunately, Version 7 tables can have much longer field names. > > So, do I not ever support version 7, do I not worry about it until I get > there (which could easily be a long time from now), or do I move all the > methods out of the record class and make them module level functions > instead? That would like: > > dbf.scatter_fields(record) > > dbf.has_been_deleted(record) > > dbf.record_number(record) > > although probably with shorter names. > > Thoughts? > I'd probably think of a record as being more like a dict (or an OrderedDict) with the fields accessed by key: record["name"] but: record.deleted From clp2 at rebertia.com Fri Jun 1 15:29:29 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 1 Jun 2012 12:29:29 -0700 Subject: understanding operator overloading In-Reply-To: References: Message-ID: On Fri, Jun 1, 2012 at 9:39 AM, Josh Benner wrote: > > Is there a good way to trace what's going on under the hood wrt operator > overloading? > > I am trying to understand what is happening in the code and output listed > below. > > Why doesn't __getitem__ in mylist return the same result as the builtin list > object? Because your class is old-style rather than new-style since it doesn't subclass the `object` class. See http://docs.python.org/reference/datamodel.html#newstyle . Thus, you're getting the weird, more complicated, old-style semantics for the operator in question. > ____code___________________________________________________ > > class mylist(): The fix is jus to subclass `object`: class mylist(object): Or use Python version 3.x, where all classes are new-style, and old-style classes no longer exist. Note that classes need only indirectly subclass `object` to be new-style; so, if you have an actual class hierarchy, only the root of your hierarchy needs to subclass `object` (this is also why subclassing built-in types like `list` or `tuple` also results in new-style classes: the built-in types themselves are `object` subclasses). Also, as a general point of coding style, one normally omits the parentheses after the class name if one isn't subclassing anything. Cheers, Chris -- http://rebertia.com From ethan at stoneleaf.us Fri Jun 1 16:05:32 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 01 Jun 2012 13:05:32 -0700 Subject: DBF records API In-Reply-To: <4FC914C5.6010106@mrabarnett.plus.com> References: <4FC900DD.5020107@stoneleaf.us> <4FC914C5.6010106@mrabarnett.plus.com> Message-ID: <4FC9208C.4080304@stoneleaf.us> MRAB wrote: > On 01/06/2012 18:50, Ethan Furman wrote: >> I'm getting towards an actual non-beta release, which means even more >> tests, polishings, cleaning up of various things, and actual >> documentation. :) >> >> However, I am wondering about my current record API: >> >> Currently, one does things like: >> >> record.scatter_fields() >> >> or >> >> record.has_been_deleted >> >> or >> >> record.record_number >> >> The reason those method names are so long is that field names are >> limited to 10 characters, and long method names means no possibility of >> name clashes. >> >> Unfortunately, Version 7 tables can have much longer field names. >> >> So, do I not ever support version 7, do I not worry about it until I get >> there (which could easily be a long time from now), or do I move all the >> methods out of the record class and make them module level functions >> instead? That would like: >> >> dbf.scatter_fields(record) >> >> dbf.has_been_deleted(record) >> >> dbf.record_number(record) >> >> although probably with shorter names. >> >> Thoughts? >> > I'd probably think of a record as being more like a dict (or an > OrderedDict) > with the fields accessed by key: > > record["name"] > > but: > > record.deleted Record fields are accessible both by key and by attribute -- by key primarily for those cases when the field name is in a variable: for field in ('full_name','nick_name','pet_name'): print record[field] and since dbf record names cannot start with _ and are at most 10 characters long I've used longer than that method names... but if I want to support dbf version 7 that won't work. I would like to, not sure I will (it's not a need for me at work), but prudence suggests I make the easy preparations now. ~Ethan~ From python.list at tim.thechases.com Fri Jun 1 18:13:10 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 01 Jun 2012 17:13:10 -0500 Subject: DBF records API In-Reply-To: <4FC9208C.4080304@stoneleaf.us> References: <4FC900DD.5020107@stoneleaf.us> <4FC914C5.6010106@mrabarnett.plus.com> <4FC9208C.4080304@stoneleaf.us> Message-ID: <4FC93E76.5010300@tim.thechases.com> On 06/01/12 15:05, Ethan Furman wrote: > MRAB wrote: >> I'd probably think of a record as being more like a dict (or an >> OrderedDict) >> with the fields accessed by key: >> >> record["name"] >> >> but: >> >> record.deleted > > Record fields are accessible both by key and by attribute -- by key > primarily for those cases when the field name is in a variable: > > for field in ('full_name','nick_name','pet_name'): > print record[field] > > and since dbf record names cannot start with _ and are at most 10 > characters long I've used longer than that method names... but if I want > to support dbf version 7 that won't work. It seems to me that, since you provide both the indexing notation and the dotted notation, just ensure that the methods such as dbf.scatter_fields *always* trump and refer to the method. This allows for convenience of using the .field_name notation for the vast majority of cases, but ensures that it's still possible for the user (of your API) to use the indexing method to do things like value = dbf["scatter_fields"] if they have a thusly-named field name and want its value. -tkc From tjreedy at udel.edu Fri Jun 1 18:42:22 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Jun 2012 18:42:22 -0400 Subject: CPython 2.7: Weakset data changing size during internal iteration In-Reply-To: References: Message-ID: On 6/1/2012 11:23 AM, Temia Eszteri wrote: > I've got a bit of a problem - my project uses weak sets in multiple > areas, the problem case in particular being to indicate what objects > are using a particular texture, if any, so that its priority in OpenGL > can be adjusted to match at the same time as it being (de)referenced > by any explicit calls. > > Problem is that for certain high-frequency operations, it seems > there's too much data going in and out for it to handle - the > following traceback is given to me (project path changed to protect > the innocent): > > Traceback (most recent call last): > File "C:\foo\bar\game.py", line 279, in update > self.player.update() > File "C:\foo\bar\player.py", line 87, in update > PlayerBullet((self.x + 8, self.y + 9), 0, self.parent) > File "C:\foo\bar\player.py", line 96, in __init__ > self.sprite = video.Sprite("testbullet", 0) > File "C:\foo\bar\video.py", line 95, in __init__ > self.opengl_id = reference_texture(self, target) > File "C:\foo\bar\video.py", line 310, in reference_texture > if not video_handler.textures[target].references: I gather that the .references attribute is sometimes/always a weakset. To determine its boolean value, it computes its length. For regular sets, this is sensible as .__len__() returns a pre-computed value. > File "C:\Python27\lib\_weakrefset.py", line 66, in __len__ > return sum(x() is not None for x in self.data) Given that len(weakset) is defined (sensibly) as the number of currently active members, it must count. weakset should really have .__bool__ method that uses any() instead of sum(). That might reduce, but not necessarily eliminate your problem. > File "C:\Python27\lib\_weakrefset.py", line 66, in > return sum(x() is not None for x in self.data) > RuntimeError: Set changed size during iteration I can think of two reasons: 1. You are using multiple threads and another thread does something to change the size of the set during the iteration. Solution? put a lock around the if-statement so no other thread can change self.data during the iteration. 2. Weakset members remove themselves from the set before returning None. (Just a thought, in case you are not using threads). -- Terry Jan Reedy From lamialily at cleverpun.com Fri Jun 1 19:40:04 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Fri, 01 Jun 2012 16:40:04 -0700 Subject: CPython 2.7: Weakset data changing size during internal iteration In-Reply-To: References: Message-ID: On Fri, 01 Jun 2012 18:42:22 -0400, Terry Reedy wrote: >I gather that the .references attribute is sometimes/always a weakset. >To determine its boolean value, it computes its length. For regular >sets, this is sensible as .__len__() returns a pre-computed value. Indeed. Back when I was using 2.6 to develop, it was simply an integer counter, but that led to some difficulties in maintaining it in case some sprite objects hadn't been explicitly killed. >Given that len(weakset) is defined (sensibly) as the number of currently >active members, it must count. weakset should really have .__bool__ >method that uses any() instead of sum(). That might reduce, but not >necessarily eliminate your problem. Think it might be worth looking into submitting a patch for the next minor releases for Python if it turns out to solve the problem? Failing that, I might just have to check the truth value of the data attribute inside the weak set manually... >I can think of two reasons: > >1. You are using multiple threads and another thread does something to >change the size of the set during the iteration. Solution? put a lock >around the if-statement so no other thread can change self.data during >the iteration. > >2. Weakset members remove themselves from the set before returning None. >(Just a thought, in case you are not using threads). It's a multithreaded program to a small extent - I offload I/O operations, music handling, and a basic, optional debugger console (which I really wish I could set up to use the real interactive interpreter instead of the shoddy setup I've got now) to seperate threads, while the main logic operates in one thread due to OpenGL's issues with multiple Python threads. Since the sprite object calls to reference a texture in __init__(), that means no other thread could even safely reference the texture due to the potential of making OpenGL calls without the relevant context kept by the main thread (this has made the loading thread kind of useless, but the texture strings themselves can still be loaded into temporary memory, and other data like music still works). If the weak references removing themselves is the case, it seems like a kind of silly problem - one would imagine they'd wrap the data check in _IterationGuard in the _weakrefset.py file like they do for calls to __iter__(). Very strange. Anyway, I truly appreciate your input and suggestions. I'll see if they have any results, and if so, we can work out submitting a patch. If not, at least reading through this gave me the idea to just call the data set inside it, so I can use it as an imperfect but functional solution within the scope of my project. ~Temia -- When on earth, do as the earthlings do. From joncle at googlemail.com Fri Jun 1 20:05:17 2012 From: joncle at googlemail.com (Jon Clements) Date: Sat, 02 Jun 2012 01:05:17 +0100 Subject: DBF records API In-Reply-To: <4FC93E76.5010300@tim.thechases.com> References: <4FC900DD.5020107@stoneleaf.us> <4FC914C5.6010106@mrabarnett.plus.com> <4FC9208C.4080304@stoneleaf.us> <4FC93E76.5010300@tim.thechases.com> Message-ID: On 01/06/12 23:13, Tim Chase wrote: > On 06/01/12 15:05, Ethan Furman wrote: >> MRAB wrote: >>> I'd probably think of a record as being more like a dict (or an >>> OrderedDict) >>> with the fields accessed by key: >>> >>> record["name"] >>> >>> but: >>> >>> record.deleted >> >> Record fields are accessible both by key and by attribute -- by key >> primarily for those cases when the field name is in a variable: >> >> for field in ('full_name','nick_name','pet_name'): >> print record[field] >> >> and since dbf record names cannot start with _ and are at most 10 >> characters long I've used longer than that method names... but if I want >> to support dbf version 7 that won't work. > > It seems to me that, since you provide both the indexing notation > and the dotted notation, just ensure that the methods such as > > dbf.scatter_fields > > *always* trump and refer to the method. This allows for convenience > of using the .field_name notation for the vast majority of cases, > but ensures that it's still possible for the user (of your API) to > use the indexing method to do things like > > value = dbf["scatter_fields"] > > if they have a thusly-named field name and want its value. > > -tkc I did think about *trumping* one way or the other, but both *ugh*. Ethan: I think offering both is over-complicating the design for no gain, and possible complications later. For instance, what if you introduce a method/property called "last" to get the last row of a table, it'll cause some head-scratching as someone will suddenly have to make sure your API changes didn't conflict with their column names (or if they've used yours as a base and introduce methods, doesn't interfere with their users of their version of the library...) To most developers, I think blah["whatever"] is perfectly clear as looking up a value via key is mostly done that way. I suppose you could use __getitem__ to grab certain fields in one go ( as per your example - from any iterable that isn't a basestring? - and users would probably enjoy not keep re-typing "record.xxx" and would save you having to invent another possibly conflicting name) such as: print record['full_name', 'nick_name', 'pet_name'] # looks clean to me In short I totally agree with MRAB here. Just my 2p, Jon. From fabiofz at gmail.com Fri Jun 1 20:27:28 2012 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 1 Jun 2012 21:27:28 -0300 Subject: other languages API to python In-Reply-To: References: Message-ID: On Thu, May 24, 2012 at 9:25 AM, Chris Angelico wrote: > On Thu, May 24, 2012 at 9:58 PM, Rita wrote: >> Hello, >> >> A vendor provided a C, C++ and Java API for a application. They dont support >> python so I would like to create a library for it. My question is, how >> hard/easy would it be to create something like this? Is there a simple HOWTO >> or examples I can follow? Can someone shed home light on this? > > The best way would be to write something in C that exposes the API to > Python. Check out the docs on "Extending and Embedding Python": > > For Python 2.x: http://docs.python.org/extending/ > For Python 3.x: http://docs.python.org/py3k/extending/ > > You'll need to learn Python's own API, of course, but if you're a > competent C programmer, you should find it fairly straightforward. > > There's an alternative, too, though I haven't personally used it. The > ctypes module allows you to directly call a variety of C-provided > functions. > > http://docs.python.org/library/ctypes.html > http://docs.python.org/py3k/library/ctypes.html > > The resulting code isn't nearly as Pythonic as it could be if you > write a proper wrapper, but you save the work of writing C code. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list There are some wrapping libraries that may help in wrapping C/C++ for Python... Take a look at Boost::Python, Swig, Sip and Cython (personally, I like Boost::Python, but the generated code can be a bit bloated -- but not a problem unless it's a really huge library -- Cython seems nice too, but I've only made few things with it, so, I can't comment much). Cheers, Fabio From python.list at tim.thechases.com Fri Jun 1 20:44:28 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 01 Jun 2012 19:44:28 -0500 Subject: DBF records API In-Reply-To: References: <4FC900DD.5020107@stoneleaf.us> <4FC914C5.6010106@mrabarnett.plus.com> <4FC9208C.4080304@stoneleaf.us> <4FC93E76.5010300@tim.thechases.com> Message-ID: <4FC961EC.7040301@tim.thechases.com> On 06/01/12 19:05, Jon Clements wrote: > On 01/06/12 23:13, Tim Chase wrote: >> dbf.scatter_fields >> >> *always* trump and refer to the method. > > I did think about *trumping* one way or the other, but both *ugh*. For the record, it sounded like the OP wanted to be able to use the dot-notation for accessing fields by name, and I think it's a pretty non-pythonic way to do it. I'd much rather just stick to purely using __getitem__ for the fields and attributes/methods for non-fields. -tkc From 1248283536 at qq.com Fri Jun 1 22:14:36 2012 From: 1248283536 at qq.com (=?gb18030?B?y66+ssH3ye4=?=) Date: Sat, 2 Jun 2012 10:14:36 +0800 Subject: why i can't read sda1 with python? Message-ID: tiger at debian:~$ sudo fdisk -l Disk /dev/sda: 120.0 GB, 120034123776 bytes 255 heads, 63 sectors/track, 14593 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x073a3c87 Device Boot Start End Blocks Id System /dev/sda1 * 1 1912 15358108+ c W95 FAT32 (LBA) /dev/sda2 1913 3736 14647296 b W95 FAT32 /dev/sda3 3736 3979 1952768 83 Linux /dev/sda4 3979 14594 85260289 5 Extended /dev/sda5 3979 4040 487424 83 Linux /dev/sda6 4040 4769 5858304 83 Linux /dev/sda7 4770 4891 975872 83 Linux /dev/sda8 4891 5134 1951744 83 Linux /dev/sda9 5134 14374 74217472 83 Linux /dev/sda10 14374 14594 1764352 82 Linux swap / Solaris i want to read sda1 with python: >>> file=open('/dev/sda1','rb') Traceback (most recent call last): File "", line 1, in IOError: [Errno 13] Permission denied: '/dev/sda1' how can i own the access to read sda1? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Jun 1 23:05:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Jun 2012 03:05:01 GMT Subject: CPython 2.7: Weakset data changing size during internal iteration References: Message-ID: <4fc982dd$0$29971$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Jun 2012 08:23:44 -0700, Temia Eszteri wrote: > I've got a bit of a problem - my project uses weak sets in multiple > areas, the problem case in particular being to indicate what objects are > using a particular texture, if any, so that its priority in OpenGL can > be adjusted to match at the same time as it being (de)referenced by any > explicit calls. > > Problem is that for certain high-frequency operations, it seems there's > too much data going in and out for it to handle I doubt that very much. If you are using threads, it is more likely your code has a race condition where you are modifying a weak set at the same time another thread is trying to iterate over it (in this case, to determine it's length), and because it's a race condition, it only happens when conditions are *just right*. Since race conditions hitting are usually rare, you only notice it when there's a lot of data. -- Steven From lamialily at cleverpun.com Fri Jun 1 23:24:30 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Fri, 01 Jun 2012 20:24:30 -0700 Subject: CPython 2.7: Weakset data changing size during internal iteration References: <4fc982dd$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3r1js7lj1jt3h48n2m3l89ppu1cc948eod@4ax.com> On 02 Jun 2012 03:05:01 GMT, Steven D'Aprano wrote: >I doubt that very much. If you are using threads, it is more likely your >code has a race condition where you are modifying a weak set at the same >time another thread is trying to iterate over it (in this case, to >determine it's length), and because it's a race condition, it only >happens when conditions are *just right*. Since race conditions hitting >are usually rare, you only notice it when there's a lot of data. Except that the few threads I use don't modify that data at all because the functions that even touch the references set rely on OpenGL contexts along with it which are thread-bound, ergo, impossible to call without stopping the code in its tracks to begin with unless the context's explicitly shifted (which it very much isn't). And I've done some looking through the weak set's code in the intervening time; it does easily have the potential to cause this kind of problem because the weak references made are set to a callback to remove them from the data set when garbage is collected. See for yourself.: Lines 81-84, _weakrefset.py: def add(self, item): if self._pending_removals: self._commit_removals() self.data.add(ref(item, self._remove)) <-- Lines 38-44, likewise: (for some reason called in __init__ rather than at the class level, but likely to deal with a memory management issue) def _remove(item, selfref=ref(self)): self = selfref() if self is not None: if self._iterating: <-- self._pending_removals.append(item) else: self.data.discard(item) <-- self._remove = _remove The thing is, as Terry pointed out, its truth value is tested based on __len__(), which as shown does NOT set the _iterating protection: def __len__(self): return sum(x() is not None for x in self.data) Don't be so fast to dismiss things when the situation would not have made a race condition possible to begin with. ~Temia -- When on earth, do as the earthlings do. From ethan at stoneleaf.us Sat Jun 2 01:16:35 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 01 Jun 2012 22:16:35 -0700 Subject: DBF records API In-Reply-To: <4FC961EC.7040301@tim.thechases.com> References: <4FC900DD.5020107@stoneleaf.us> <4FC914C5.6010106@mrabarnett.plus.com> <4FC9208C.4080304@stoneleaf.us> <4FC93E76.5010300@tim.thechases.com> <4FC961EC.7040301@tim.thechases.com> Message-ID: <4FC9A1B3.80900@stoneleaf.us> Tim Chase wrote: > On 06/01/12 19:05, Jon Clements wrote: >> On 01/06/12 23:13, Tim Chase wrote: >>> dbf.scatter_fields >>> >>> *always* trump and refer to the method. >> I did think about *trumping* one way or the other, but both *ugh*. > > For the record, it sounded like the OP wanted to be able to use the > dot-notation for accessing fields by name, and I think it's a pretty > non-pythonic way to do it. I'd much rather just stick to purely > using __getitem__ for the fields and attributes/methods for non-fields. It can't be *that* non-Pythonic -- we now have namedtuples which pretty much behave just like my record class (although its indexes are only numbers, not strings as well). ~Ethan~ From tjreedy at udel.edu Sat Jun 2 02:27:56 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 02 Jun 2012 02:27:56 -0400 Subject: CPython 2.7: Weakset data changing size during internal iteration In-Reply-To: References: Message-ID: On 6/1/2012 7:40 PM, Temia Eszteri wrote: >> Given that len(weakset) is defined (sensibly) as the number of currently >> active members, it must count. weakset should really have .__bool__ >> method that uses any() instead of sum(). That might reduce, but not >> necessarily eliminate your problem. > > Think it might be worth looking into submitting a patch for the next > minor releases for Python if it turns out to solve the problem? I think a patch would be worthwhile even if this is not the source of your problem. If bool is defined as 'if any ...', that should be the code. >> I can think of two reasons: >> >> 1. You are using multiple threads and another thread does something to >> change the size of the set during the iteration. Solution? put a lock >> around the if-statement so no other thread can change self.data during >> the iteration. >> >> 2. Weakset members remove themselves from the set before returning None. >> (Just a thought, in case you are not using threads). In other words, it is possible that weakset.__len__ is buggy. Since you are sure that 1) is not your problem, that seems more likely now. > If the weak references removing themselves is the case, it seems like > a kind of silly problem - one would imagine they'd wrap the data check > in _IterationGuard in the _weakrefset.py file like they do for calls > to __iter__(). Very strange. While looking into the weakset code, you might check the tracker for weakset issues. And also check the test code. I have *no* idea how well that class has been exercised and tested. Please do submit a patch if you can if one is needed. -- Terry Jan Reedy From python at mrabarnett.plus.com Sat Jun 2 06:49:12 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 02 Jun 2012 11:49:12 +0100 Subject: DBF records API In-Reply-To: <4FC9A1B3.80900@stoneleaf.us> References: <4FC900DD.5020107@stoneleaf.us> <4FC914C5.6010106@mrabarnett.plus.com> <4FC9208C.4080304@stoneleaf.us> <4FC93E76.5010300@tim.thechases.com> <4FC961EC.7040301@tim.thechases.com> <4FC9A1B3.80900@stoneleaf.us> Message-ID: <4FC9EFA8.6070608@mrabarnett.plus.com> On 02/06/2012 06:16, Ethan Furman wrote: > Tim Chase wrote: >> On 06/01/12 19:05, Jon Clements wrote: >>> On 01/06/12 23:13, Tim Chase wrote: >>>> dbf.scatter_fields >>>> >>>> *always* trump and refer to the method. >>> I did think about *trumping* one way or the other, but both *ugh*. >> >> For the record, it sounded like the OP wanted to be able to use the >> dot-notation for accessing fields by name, and I think it's a pretty >> non-pythonic way to do it. I'd much rather just stick to purely >> using __getitem__ for the fields and attributes/methods for non-fields. > > It can't be *that* non-Pythonic -- we now have namedtuples which pretty > much behave just like my record class (although its indexes are only > numbers, not strings as well). > namedtuple prefixes its methods with "_", so you could just have: record.name and: record._deleted From deets at web.de Sat Jun 2 06:52:04 2012 From: deets at web.de (Diez B. Roggisch) Date: Sat, 02 Jun 2012 12:52:04 +0200 Subject: ctypes callback with char array References: Message-ID: ohlfsen writes: > Hello. > > Hoping that someone can shed some light on a tiny challenge of mine. > > Through ctypes I'm calling a c DLL which requires me to implement a callback in Python/ctypes. > > The signature of the callback is something like > > void foo(int NoOfElements, char Elements[][100]) > > How do I possible implement/process "char Elements[][100]" in Python/ctypes code? I'd try it like this: $ python Python 2.7 (r27:82500, May 2 2011, 22:50:11) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. oWelcome to rlcompleter2 0.98 for nice experiences hit multiple times >>> from ctypes import * >>> callback_type = CFUNCTYPE(None, c_int, POINTER(c_char_p)) >>> def my_callback(int, elements): ... pass ... >>> c_callback = callback_type(my_callback) >>> c_callback No need to know that it's a pointer to char[100] pointers - you can cast that if you want to. Diez From deets at web.de Sat Jun 2 06:53:24 2012 From: deets at web.de (Diez B. Roggisch) Date: Sat, 02 Jun 2012 12:53:24 +0200 Subject: Python 2.7.3, C++ embed memory leak? References: Message-ID: Qi writes: > Hi guys, > > Is there any known memory leak problems, when embed Python 2.7.3 > in C++? > I Googled but only found some old posts. > > I tried to only call Py_Initialize() and Py_Finalize(), nothing else > between those functions, Valgrind still reports memory leaks > on Ubuntu? > > Is that a know problem? Did Python 3.x solve it? > > I want some confirmation. Python does some special things that confuse valgrind. Don't bother. http://svn.python.org/projects/python/trunk/Misc/README.valgrind Diez From no at no.com Sat Jun 2 08:37:34 2012 From: no at no.com (Qi) Date: Sat, 02 Jun 2012 20:37:34 +0800 Subject: Python 2.7.3, C++ embed memory leak? References: Message-ID: On 2012-6-2 18:53, Diez B. Roggisch wrote: > Python does some special things that confuse valgrind. Don't bother. > > http://svn.python.org/projects/python/trunk/Misc/README.valgrind Thanks for the link. It clears a lot of my confusing, such as uninitialized reading... -- WQ From bv8bv8bv8 at gmail.com Sat Jun 2 08:46:23 2012 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sat, 2 Jun 2012 05:46:23 -0700 (PDT) Subject: WHAT DO MUSLIMS THINK ABOUT JESUS ????????? Message-ID: <1c7698b9-4a51-44d0-bd87-0f204f8e314f@a16g2000vby.googlegroups.com> WHAT DO MUSLIMS THINK ABOUT JESUS? I know that my article is not related to this group ,but it might be useful. PLEASE read it What do Muslims think about Jesus? Muslims respect and revere Jesus (SAW) and await his Second Coming. They consider him one of the greatest of God?s messengers to mankind. A Muslim never refers to him simply as ?Jesus?, but always adds the phrase ?upon him be peace?. The Quran confirms his virgin birth (a chapter of the Quran is entitled ?Mary?), and Mary is considered the purest woman in all creation. The Quran describes the Annunciation as follows: ?Behold!? the Angel said, ?God has chosen you, and purified you, and chosen you above the women of all nations. O Mary, God gives you good news of a word from Him, whose name shall be the Messiah, Jesus son of Mary, honored in this world and the Hereafter, and one of those brought near to God. He shall speak to the people from his cradle and in maturity, and shall be of the righteous.? She said: ?O my Lord! How shall I have a son when no man has touched me?? He said: ?Even so; God creates what He will. When He decrees a thing He says to it, "Be!" and it is.? (Quran, 3.42-7) Jesus (SAW) was born miraculously through the same power which had brought Adam (SAW) into being without a father: Truly, the likeness of Jesus with God is as the likeness of Adam. He created him of dust, and then said to him, ?Be!? and he was. (3.59) During his prophetic mission Jesus (SAW) performed many miracles. The Quran tells us that he said: ?I have come to you with a sign from your Lord: I make for you out of clay, as it were, the figure of a bird, and breathe into it and it becomes a bird by God?s leave. And I heal the blind, and the lepers, and I raise the dead by God?s leave.? (3.49) Neither Muhammad (SAW) nor Jesus (SAW) came to change the basic doctrine of the belief in One God, brought by earlier prophets, but to confirm and renew it. In the Quran Jesus (SAW) is reported as saying that he came: ?To attest the law which was before me. And to make lawful to you paff of what was forbidden you; I have come to you with a sign from your Lord, so fear God and obey Me.? (3:5O) The Prophet Muhammad (SAW) said: ?Whoever believes there is no god but God, alone without partner, that Muhammad (SAW) is His messenger, that Jesus is the servant and messenger of God, His word breathed into Mary and a spirit emanating from Him, and that Paradise and Hell are true, shall be received by God into Heaven.? (Hadith from Bukhari) ?????????- For more information about Islam http://www.islam-guide.com http://www.islamhouse.com/s/9661 http://www.thisistruth.org http://www.quran-m.com/firas/en1 http://kaheel7.com/eng http://www.knowmuhammad.com http://www.rasoulallah.net/v2/index.aspx?lang=e http://imanway1.com/eng http://www.todayislam.com http://www.thekeytoislam.com http://www.islamland.com http://www.discoverislam.com http://www.thetruereligion.org http://www.beconvinced.com http://islamtomorrow.com http://www.quranforall.org http://www.quranexplorer.com/quran http://www.prophetmuhammed.org http://chatislamonline.org/en/ From matteo at matteolandi.net Sat Jun 2 08:57:17 2012 From: matteo at matteolandi.net (Matteo Landi) Date: Sat, 2 Jun 2012 14:57:17 +0200 Subject: Tkinter deadlock on graceful exit In-Reply-To: References: <20120527222125.GA22965@MARble> <20120530221925.GA12763@MARble> Message-ID: <20120602125717.GC19504@MARble> On Jun/01, Matteo Landi wrote: > On Thu, May 31, 2012 at 3:02 PM, Matteo Landi wrote: > > On Thu, May 31, 2012 at 3:42 AM, Terry Reedy wrote: > >> On 5/30/2012 6:19 PM, Matteo Landi wrote: > >>> > >>> On May/28, Matteo Landi wrote: > >>>> > >>>> Hi list, > >>>> recently I started to work on an application [1] which makes use of the > >>>> Tkinter > >>>> module to handle interaction with the user. ?Simply put, the app is a > >>>> text > >>>> widget displaying a file filtered by given criteria, with a handy feature > >>>> that > >>>> the window is raised each time a new line is added to the widget. > >>>> > >>>> The application mainly consists of three threads: ?the first one, the > >>>> file > >>>> processor, reads the file, filters the lines of interest, and pushes them > >>>> into > >>>> a shared queue (henceforth `lines_queue`); ?the second one, the > >>>> gui_updater, > >>>> pops elements from `lines_queue`, and schedule GUI updates using the > >>>> `after_idle` method of the Tkinter module; ?finally the last one, the > >>>> worker > >>>> spawner, receives commands by the gui (by means of a shared queue, > >>>> `filters_queue`), and drives the application, terminating or spawning new > >>>> threads. > >>>> > >>>> For example, let's see what happens when you start the application, fill > >>>> the > >>>> filter entry and press Enter button: > >>>> 1 the associated even handler is scheduled (we should be inside the > >>>> Tkinter > >>>> ? mainloop thread), and the filter is pushed into `filters_queue`; > >>>> 2 the worker spawner receives the new filter, terminate a possibly > >>>> running > >>>> ? working thread, and once done, create a new file processor; > >>>> 3 the file processor actually processes the file and fills the > >>>> `lines_queue` > >>>> ? with the lines matching given filter; > >>>> 4 the gui updater schedules GUI updates as soon as items are pushed into > >>>> ? `lines_queue` > >>>> 5 Tkinter mainloop thread updates the gui when idle > >>>> > >>>> What happens when the main window is closed? ?Here is how I implemented > >>>> the > >>>> graceful shutdown of the app: > >>>> 1 a quit event is scheduled and a _special_ message is pushed into both > >>>> ? `filter_queue` and `lines_queue` > >>>> 2 the gui updater threads receives the _special_ message, and terminates > >>>> 3 the worker spawner receives the message, terminates the working thread > >>>> and > >>>> ? interrupts her execution. > >>>> 4 Tk.quit() is called after the quit event handler, and we finally quit > >>>> the > >>>> ? mainloop > >>>> > >>>> Honestly speaking, I see no issues with the algorithm presented above; > >>>> ?however, > >>>> if I close the window in the middle of updates of the text widget, the > >>>> applications hangs indefinitely. ?On the other hand, everything works as > >>>> expected if I close the app when the file processor, for example, is > >>>> waiting for > >>>> new content to filter. > >>>> > >>>> I put some logging messages to analyze the deadlock (?!), and noticed > >>>> that both > >>>> the worker spawner and the file processor are terminated correctly. ?The > >>>> only > >>>> thread still active for some strange reasons, is the gui updater. > >>>> > >>>> Do you see anything wrong with the description presented above? ?Please > >>>> say so, > >>>> because I can't figure it out! > >> > >> > >> Since no-one else answered, I will ask some questions based on little > >> tkinter experience, no thread experience, and a bit of python-list reading. > >> > >> 1. Are you only using tkinter in one thread? (It seems like so from the > >> above)? > > > > Yes, provided that `after_idle` queues a job for the gui thread > > > >> > >> 2. Is root.destroy getting called, as in 24.1.2.2. A Simple Hello World > >> Program in the most recent docs? (I specify 'most recent' because that > >> example has been recently revised because the previous version sometimes > >> left tkinter hanging for one of the code paths, perhaps similar to what you > >> describe. > > > > No, I'm not calling the destroy method of the main window but, why > > that only happens while doing gui updates? > > > >> > >> 3. Have you tried making the gui thread the master thread? (I somehow expect > >> that the gui thread should be the last to shut down.) > > > > No but, same question as above. > > > > I'm not home right now, so I will try those solutions as soon as > > possible. ?Thanks. > > > > > > Cheers, > > Matteo > > > >> > >> -- > >> Terry Jan Reedy > >> > >> -- > >> http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > http://www.matteolandi.net/ > > Doing further investigation, I found this post [1] dated 2005, which > probably explains why I'm gatting this strange deadlock. > > Quoting the linked article: > > All Tkinter access must be from the main thread (or, more precisely, > the thread that called mainloop). Violating this is likely to cause > nasty and mysterious symptoms such as freezes or core dumps. Yes this > makes combining multi-threading and Tkinter very difficult. The only > fully safe technique I have found is polling (e.g. use after from the > main loop to poll a threading Queue that your thread writes). I have > seen it suggested that a thread can safely use event_create to > communicate with the main thread, but have found this is not safe. > > Well, if this still applies, then I'm invoking `after_idle` from a > thread different from the mainloop's one. I'll try to implement the > poll/queue fix, and see if this solves the issue. > > > Matteo > > [1] http://mail.python.org/pipermail/tkinter-discuss/2005-February/000313.html > -- > http://www.matteolandi.net/ I managed to solve the deadlock: it was a threading problem, and the polling job + synchronized queue solution [1] worked like a charm. Lesson learned: never invoke Tkinter functions / methods outside the mainloop thread.. NEVER! Regards, Matteo [1] https://bitbucket.org/iamFIREcracker/logfilter/changeset/9e1b571f90eb -- http://www.matteolandi.net From python.list at tim.thechases.com Sat Jun 2 09:20:31 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 02 Jun 2012 08:20:31 -0500 Subject: DBF records API In-Reply-To: <4FC9A1B3.80900@stoneleaf.us> References: <4FC900DD.5020107@stoneleaf.us> <4FC914C5.6010106@mrabarnett.plus.com> <4FC9208C.4080304@stoneleaf.us> <4FC93E76.5010300@tim.thechases.com> <4FC961EC.7040301@tim.thechases.com> <4FC9A1B3.80900@stoneleaf.us> Message-ID: <4FCA131F.2000805@tim.thechases.com> On 06/02/12 00:16, Ethan Furman wrote: > Tim Chase wrote: >> On 06/01/12 19:05, Jon Clements wrote: >>> On 01/06/12 23:13, Tim Chase wrote: >>>> dbf.scatter_fields >>>> >>>> *always* trump and refer to the method. >>> I did think about *trumping* one way or the other, but both *ugh*. >> >> For the record, it sounded like the OP wanted to be able to use the >> dot-notation for accessing fields by name, and I think it's a pretty >> non-pythonic way to do it. I'd much rather just stick to purely >> using __getitem__ for the fields and attributes/methods for non-fields. > > It can't be *that* non-Pythonic -- we now have namedtuples which pretty > much behave just like my record class (although its indexes are only > numbers, not strings as well). Right, but the contents of the named-tuple are usually static in relation to the code itself, rather than dependent on external factors (such as user-supplied DBF files). In addition, I believe namedtuple has methods prefixed by an underscore to stave off clashing names. -tkc From gelonida at gmail.com Sat Jun 2 13:49:46 2012 From: gelonida at gmail.com (Gelonida N) Date: Sat, 02 Jun 2012 19:49:46 +0200 Subject: how to typecast a ctypes pointer to another one Message-ID: Hi, I have a result from a call to a ctypes function of type c_void_p. Now I'd like to convert it to a pointer to one of the structures, that I defined. result = library.c_function(params) class MyStruct(ctypes.Structure): _fields_ = [ ('fourbytes', ctypes.c_char * 4) ] I know I could (prior to calling) specify what datatype the function should return) However as depending on some other conditions I have to interpret the return value either as pointer to one or another data type or another one. Id' like to perform the casting after having received the value. Thanks in advance for any pointers. From benbaral at gmail.com Sat Jun 2 16:47:41 2012 From: benbaral at gmail.com (boj) Date: Sat, 2 Jun 2012 20:47:41 +0000 (UTC) Subject: Smallest/cheapest possible Python platform? References: Message-ID: There is a 3rd party programmer for the LaunchPad that lets you program it in Python, but I forgot what they were called. It has an m somewhere in it and it's 3 letters. I saw it at MakerFaire. I got their card, but lost it. If I remember the name, I'll post it here. From python at mrabarnett.plus.com Sat Jun 2 17:18:55 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 02 Jun 2012 22:18:55 +0100 Subject: Smallest/cheapest possible Python platform? In-Reply-To: References: Message-ID: <4FCA833F.9090402@mrabarnett.plus.com> On 02/06/2012 21:47, boj wrote: > There is a 3rd party programmer for the LaunchPad > that lets you program it in Python, but I forgot what > they were called. It has an m somewhere in it and it's > 3 letters. I saw it at MakerFaire. I got their card, but > lost it. If I remember the name, I'll post it here. > Putting "LaunchPad", "Python" and "MakerFaire" into Google, plus the "It has an m somewhere in it and it's 3 letters", quickly led me to: http://www.mpyprojects.com From rosuav at gmail.com Sat Jun 2 17:25:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jun 2012 07:25:00 +1000 Subject: Smallest/cheapest possible Python platform? In-Reply-To: <4FCA833F.9090402@mrabarnett.plus.com> References: <4FCA833F.9090402@mrabarnett.plus.com> Message-ID: On Sun, Jun 3, 2012 at 7:18 AM, MRAB wrote: > Putting "LaunchPad", "Python" and "MakerFaire" into Google, plus the > "It has an m somewhere in it and it's 3 letters", quickly led me to: > > http://www.mpyprojects.com > -- Heh, Google's awesome :) I was just thinking "Hm, three letters with an M? That gives you about two thousand possibilities, not too many to brute-force..." That looks rather cool, but I'm minorly concerned by a heading in http://www.mpyprojects.com/mpy-language/ that hints that the mpy language isn't Python exactly, but doesn't have a link to the actual page on which the differences are detailed. It might be trivial differences like the lack of most of the standard library, but then again, it might be more than that. ChrisA From python at mrabarnett.plus.com Sat Jun 2 18:09:12 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 02 Jun 2012 23:09:12 +0100 Subject: Smallest/cheapest possible Python platform? In-Reply-To: References: <4FCA833F.9090402@mrabarnett.plus.com> Message-ID: <4FCA8F08.10704@mrabarnett.plus.com> On 02/06/2012 22:25, Chris Angelico wrote: > On Sun, Jun 3, 2012 at 7:18 AM, MRAB wrote: >> Putting "LaunchPad", "Python" and "MakerFaire" into Google, plus the >> "It has an m somewhere in it and it's 3 letters", quickly led me to: >> >> http://www.mpyprojects.com >> -- > > Heh, Google's awesome :) I was just thinking "Hm, three letters with > an M? That gives you about two thousand possibilities, not too many to > brute-force..." > Well, if it's something to do with Python, there wouldn't been a good chance that 2 of the letters would be "Py". That reduces the number of possibilities somewhat! :-) > That looks rather cool, but I'm minorly concerned by a heading in > http://www.mpyprojects.com/mpy-language/ that hints that the mpy > language isn't Python exactly, but doesn't have a link to the actual > page on which the differences are detailed. It might be trivial > differences like the lack of most of the standard library, but then > again, it might be more than that. > Look at the "Software" page: """We use the mpy language to program the MSP430 microcontroller. MPY is short for Microcontroller PYthon. mpy is based on the Python computer language. In fact to keep things simple it is only a small subset of the Python language.""" From rosuav at gmail.com Sat Jun 2 18:31:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jun 2012 08:31:41 +1000 Subject: Smallest/cheapest possible Python platform? In-Reply-To: <4FCA8F08.10704@mrabarnett.plus.com> References: <4FCA833F.9090402@mrabarnett.plus.com> <4FCA8F08.10704@mrabarnett.plus.com> Message-ID: On Sun, Jun 3, 2012 at 8:09 AM, MRAB wrote: > Look at the "Software" page: > > """We use the mpy language to program the MSP430 microcontroller. MPY is > short for Microcontroller PYthon. ? mpy is based on the Python computer > language. In fact to keep things simple it is only a small subset of the > Python language.""" Ah, yes I missed that. Seems it's Python-like language implemented in Python, which is I think a smart way to do it (assuming that this code isn't going to have trust issues). ChrisA From list at qtrac.plus.com Sun Jun 3 03:55:39 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Sun, 3 Jun 2012 00:55:39 -0700 (PDT) Subject: How to Test GUI Apps for many Python X GUI toolkits Message-ID: <8a5becd9-9cbf-4381-b9c2-f50fd256e86f@n42g2000yqm.googlegroups.com> Hi, There are many options for writing desktop GUI applications with Python and I'd like to explore some of them. However, to do this I need to be able to test various Python 3.x X GUI toolkit y.z combinations. With PyQt4 this is easy. (Example given at the end.) I'd like to be able to do the same with other Python GUI toolkits. - For PyGObject (PyGtk's successor) it seems that you have to do a local build of Gtk+ and the PyGObject. I've tried and failed on this. (And even if I'd succeeded, I don't see how to do this for local Pythons.) - I haven't tried this for wxPython (& anyway they don't seem to have a Python 3 version). - I've also failed to do this for Tcl/Tk (as per my posting "Use a locally built Tk for Python?". It is easy to build local versions of Tcl/Tk using --prefix; but I don't see how to make the Python build process use a locally built Tcl/Tk. - I haven't tried this for PySide. Has anyone else succeeded for any of these? Surely they must have; otherwise how could they test their PyGObject/wxPython/Tkinter applications? I'd appreciate suggestions/links. Thanks! Example: build two Python 3.2s one with Qt 4.7 and one with Qt 4.8: - Build local pythons, e.g., ./configure --prefix=/home/me/opt/py32qt47 ./configure --prefix=/home/me/opt/py32qt48 - Build local Qts, e.g., ./configure --prefix=/home/me/opt/qt47 ./configure --prefix=/home/me/opt/qt48 - Build PyQts specifying which Python & Qt to use, e.g., /home/me/opt/py32qt47/bin/python3 configure.py --qmake=/home/me/opt/ qt47/bin/qmake /home/me/opt/py32qt48/bin/python3 configure.py --qmake=/home/me/opt/ qt48/bin/qmake This makes it easy to test PyQt GUI applications. And, of course, if a user reports a problem with some other combination, it is easy (if time consuming) to create a matching combination to test. From matteo at matteolandi.net Sun Jun 3 04:15:35 2012 From: matteo at matteolandi.net (Matteo Landi) Date: Sun, 3 Jun 2012 10:15:35 +0200 Subject: Tkinter deadlock on graceful exit In-Reply-To: References: <20120527222125.GA22965@MARble> <20120530221925.GA12763@MARble> <20120602125717.GC19504@MARble> Message-ID: <20120603081535.GF19504@MARble> On Jun/02, Dennis Lee Bieber wrote: > On Sat, 2 Jun 2012 14:57:17 +0200, Matteo Landi > declaimed the following in gmane.comp.python.general: > > > > Lesson learned: never invoke Tkinter functions / methods outside the mainloop > > thread.. NEVER! > > > > Typically, that advice would apply to ANY GUI library... > > The exception being operations that /add/ an event to the pending > unprocessed GUI events, thereby signaling the GUI to perform the desired > function. You right, definitely! I made a bit of GTK programming before, and if I remember correctly, there is a *thread-safe* function, `gobject.idle_add`, that let you queue functions to be executed by the main thread. For that reason, I thought it was safe to invoke `tk.after_idle` outside the mainloop's thread, but oviously I was wrong! > > If you want a head-ache... Try coding an application in which the > old GKS is used for the main data display (I needed display-list > capability with identified "segments" so I could "blank"/"show" > different aspects of the data -- without rerunning some 15-minute > process read months of data points) on top of a nearly raw X-Window > systems (xt and DECWindows). AND the graphics commands for the data to > be plotted were coming in as ASCII text over a VMS mailbox. Oh, and no > threading -- the graphics commands had to be processed a few at a time > via an xt idle event handler (if there were no GUI events, call my > handler to read a command from the mailbox, dispatch to the GKS > emulation of the command [the commands mapped to Ramtek 9300 graphics > engine -- the original implementation], and return to check for next > event). This was ca. 1990! > Nice, good job! > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list Cheers, Matteo -- http://www.matteolandi.net From colinh at somewhere.invalid Sun Jun 3 07:59:40 2012 From: colinh at somewhere.invalid (Colin Higwell) Date: Sun, 3 Jun 2012 11:59:40 +0000 (UTC) Subject: usenet reading References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: On Fri, 25 May 2012 15:38:55 -0700, Jon Clements wrote: > > Is there a server out there where I can get my news groups? I use to be > with an ISP that hosted usenet servers, but alas, it's no longer > around... > I use Albasani.net (free and very reliable), as well as gmane.org. Google Groups is an abomination IMHO, and I find it much easier to read mailing lists via a newsreader. I highly recommend Pan, by the way. From mcepl at redhat.com Sun Jun 3 10:25:53 2012 From: mcepl at redhat.com (Matej Cepl) Date: Sun, 03 Jun 2012 16:25:53 +0200 Subject: usenet reading In-Reply-To: References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: On 03/06/12 13:59, Colin Higwell wrote: > Google Groups is an abomination IMHO, and I find it much easier to read > mailing lists via a newsreader. I highly recommend Pan, by the way. I am still surprised how good experience I have with reading news with Thunderbird. Yes, Pan is better, but it used to have some rough edges (e.g., it's offline qualities were a bit elusive), but of course generally it is quite more powerful as a NNTP reader. Mat?j From alec.taylor6 at gmail.com Sun Jun 3 11:25:16 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 3 Jun 2012 08:25:16 -0700 (PDT) Subject: python View Controller for decoupled website architectures? Message-ID: <2bea3ddb-2b72-41ca-8fb5-1426416d8d9d@googlegroups.com> I'm developing a database (Model Controller) in Python (web2py) that exposes APIs in REST (HTTP)[CSV, XML, JSON] and RPC (XML, JSON). The client I'm developing in JavaScript to interface with my remote database via its API. Unfortunately JavaScript is rather troublesome when it comes to managing user-sessions, routing and RBACing templates (e.g.: `if "admin" in user.role:

Caution: you are logged in as admin

`). Is there a Pythonic way of managing the client-side? - E.g.: Skulpt, Pyjamas or some way of getting web2py views to work with remote calls - If so, can you show me some boilerplate for session control, routing and RBAC templates? Thanks, Alec Taylor From steve+comp.lang.python at pearwood.info Sun Jun 3 12:20:11 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Jun 2012 16:20:11 GMT Subject: CPython 2.7: Weakset data changing size during internal iteration References: <4fc982dd$0$29971$c3e8da3$5496439d@news.astraweb.com> <3r1js7lj1jt3h48n2m3l89ppu1cc948eod@4ax.com> Message-ID: <4fcb8ebb$0$29971$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Jun 2012 20:24:30 -0700, Temia Eszteri wrote: > On 02 Jun 2012 03:05:01 GMT, Steven D'Aprano > wrote: > >>I doubt that very much. If you are using threads, it is more likely your >>code has a race condition where you are modifying a weak set at the same >>time another thread is trying to iterate over it (in this case, to >>determine it's length), and because it's a race condition, it only >>happens when conditions are *just right*. Since race conditions hitting >>are usually rare, you only notice it when there's a lot of data. > > Except that the few threads I use don't modify that data at all [...] And should I have known this from your initial post? [...] > Don't be so fast to dismiss things when the situation would not have > made a race condition possible to begin with. If you have been part of this newsgroup and mailing list as long as I have, you should realise that there is no shortage of people who come here and make grand claims that they have discovered a bug in Python (either the language, or the standard library). Nine times out of ten, they have not, and the bug is in their code, or their understanding. Perhaps you are one of the few who has actually found a bug in the standard library rather than one in your own code. But your initial post showed no sign that you had done any investigation beyond reading the traceback and immediately jumping to the conclusion that it was a bug in the standard library. Frankly, I still doubt that your analysis of the problem is correct: [quote] Problem is that for certain high-frequency operations, it seems there's too much data going in and out for it to handle [end quote] I still can't see any way for this bug to occur due to "too much data", as you suggest, or in the absence of one thread modifying the set while another is iterating over it. But I could be wrong. In any case, it appears that this bug has already been reported and fixed: http://bugs.python.org/issue14159 Consider updating to the latest bug fix of 2.7. -- Steven From steve+comp.lang.python at pearwood.info Sun Jun 3 12:28:03 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Jun 2012 16:28:03 GMT Subject: Use a locally built Tk for Python? References: <900b402d-c6b0-4e00-beea-a18417764ee8@b26g2000vbt.googlegroups.com> Message-ID: <4fcb9093$0$29971$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Jun 2012 09:34:41 -0700, Mark Summerfield wrote: > Hi, > > I have multiple Pythons locally installed so that I can test against > different versions. (On a 64-bit Debian stable system.) [...] > But when I run ~/opt/py32tkmod/bin/python3 tkinter-test.pyw the system > tk is being used not my customized one. > > Can anyone advise? I'm not sure if this will help, but it may. I had a similar problem where my Python couldn't see my installed tk/tcl 8.5 in /usr/local/lib. The symptom I got was that "make install" was not building _tkinter and reported this warning: *** WARNING: renaming "_tkinter" since importing it failed: libtk8.5.so: cannot open shared object file: No such file or directory I fixed this by using these commands as root: echo /usr/local/lib > /etc/ld.so.conf.d/python27.conf ldconfig then running "make clean", "make", "sudo make altinstall" again. (I used altinstall instead of install so as to avoid changing the system Python.) This was on a 32-bit Centos system, but I expect it should work just as well on a 64-bit Debian system. -- Steven From dwblas at gmail.com Sun Jun 3 13:23:56 2012 From: dwblas at gmail.com (David) Date: Sun, 3 Jun 2012 10:23:56 -0700 (PDT) Subject: Use a locally built Tk for Python? In-Reply-To: <900b402d-c6b0-4e00-beea-a18417764ee8@b26g2000vbt.googlegroups.com> References: <900b402d-c6b0-4e00-beea-a18417764ee8@b26g2000vbt.googlegroups.com> Message-ID: <134b5743-e7be-47d1-be47-5bb75ef4fe54@googlegroups.com> Python uses the Tkinter wrapper around TCL/TK and it remains the same no matter how may versions of TCL/TK are installed. You will have to build Tkinter against whatever version you like and make sure that it gets installed in the /usr/lib64/python directory that you want. From ndbecker2 at gmail.com Sun Jun 3 13:24:49 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Sun, 03 Jun 2012 13:24:49 -0400 Subject: usenet reading References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: Jon Clements wrote: > Hi All, > > Normally use Google Groups but it's becoming absolutely frustrating - not only > has the interface changed to be frankly impractical, the posts are somewhat > random of what appears, is posted and whatnot. (Ironically posted from GG) > > Is there a server out there where I can get my news groups? I use to be with > an ISP that hosted usenet servers, but alas, it's no longer around... > > Only really interested in Python groups and C++. > > Any advice appreciated, > > Jon. Somewhat unrelated - any good news reader for Android? From lamialily at cleverpun.com Sun Jun 3 13:55:50 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Sun, 03 Jun 2012 10:55:50 -0700 Subject: CPython 2.7: Weakset data changing size during internal iteration References: <4fc982dd$0$29971$c3e8da3$5496439d@news.astraweb.com> <3r1js7lj1jt3h48n2m3l89ppu1cc948eod@4ax.com> <4fcb8ebb$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03 Jun 2012 16:20:11 GMT, Steven D'Aprano wrote: >And should I have known this from your initial post? I did discuss the matter with Terry Reedy, actually, but I guess since the newsgroup-to-mailing list mirror is one-way, there's no actual way you could've known. :/ Sigh, another problem out of my hands to deal with. I do apologize for the snippy attitude, if it means anything. >Frankly, I still doubt that your analysis of the problem is correct: > > [quote] > Problem is that for certain high-frequency operations, it > seems there's too much data going in and out for it to handle > [end quote] > > >I still can't see any way for this bug to occur due to "too much data", >as you suggest, or in the absence of one thread modifying the set while >another is iterating over it. But I could be wrong. Well, in this case, I'd consider it more reasonable to look at it from a different angle, but it was rather poorly-phrased at the beginning. When you've got dozens of objects being garbage-collected from the set every 16 miliseconds or so though, that's certainly high-frequency enough to trigger the bug, is it not? >In any case, it appears that this bug has already been reported and fixed: > >http://bugs.python.org/issue14159 > >Consider updating to the latest bug fix of 2.7. Alas, I'm already on the latest official release, which doesn't have the patch yet. I'll just apply it manually. Though now I'm now curious about how regular sets get their truth value, since weaksets internally performing a length check every time a texture was being referenced or de-referenced, for simple lack of a faster explicit __bool__ value, is going to be rather costly when things'll be flying around and out of the screen area in large quantities. Hoo boy. ~Temia -- The amazing programming device: fuelled entirely by coffee, it codes while awake and tests while asleep! From ppearson at nowhere.invalid Sun Jun 3 15:24:32 2012 From: ppearson at nowhere.invalid (Peter Pearson) Date: 3 Jun 2012 19:24:32 GMT Subject: usenet reading References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: On Sat, 26 May 2012 16:05:23 +0100, duncan smith wrote: > On 25/05/12 23:38, Jon Clements wrote: [snip] >> Is there a server out there where I can get my news groups? > > If you don't mind paying a small fee there are several companies > providing usenet access such as http://www.newsdemon.com. (I didn't have > much joy trying to track down a reliable free service, so now I pay a > few pounds a year.) Also in the pay-a-little category, news.individual.net costs 10 euros per year and filters out spam pretty effectively. I've been happy using it with the slrn news reader for about 4 years. -- To email me, substitute nowhere->spamcop, invalid->net. From janetcatherine.heath at gmail.com Sun Jun 3 17:19:16 2012 From: janetcatherine.heath at gmail.com (Janet Heath) Date: Sun, 3 Jun 2012 14:19:16 -0700 (PDT) Subject: ./configure Message-ID: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> Hi, I am trying to run the ./configure but I keep getting this: configure:2756: checking for --enable-universalsdk configure:2797: result: no configure:2806: checking for --with-universal-archs configure:2823: result: 32-bit configure:2980: checking MACHDEP configure:3129: result: darwin configure:3135: checking EXTRAPLATDIR configure:3150: result: $(PLATMACDIRS) configure:3161: checking machine type as reported by uname -m configure:3164: result: x86_64 configure:3177: checking for --without-gcc configure:3221: result: no configure:3282: checking for gcc configure:3312: result: no configure:3375: checking for cc configure:3422: result: no configure:3478: checking for cl.exe configure:3508: result: no configure:3532: error: in `/usr/bin/Python-2.7.3': configure:3534: error: no acceptable C compiler found in $PATH See `config.log' for more details I can't seem to figure out the 2 errors at the bottom. Any suggestions? Janet From janetcatherine.heath at gmail.com Sun Jun 3 17:20:12 2012 From: janetcatherine.heath at gmail.com (Janet Heath) Date: Sun, 3 Jun 2012 14:20:12 -0700 (PDT) Subject: ./configure In-Reply-To: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> Message-ID: <65d9ee0e-d18c-4383-b770-7f2f1cbed08d@googlegroups.com> On Sunday, June 3, 2012 3:19:16 PM UTC-6, Janet Heath wrote: > Hi, > > I am trying to run the ./configure but I keep getting this: > > > configure:2756: checking for --enable-universalsdk > configure:2797: result: no > configure:2806: checking for --with-universal-archs > configure:2823: result: 32-bit > configure:2980: checking MACHDEP > configure:3129: result: darwin > configure:3135: checking EXTRAPLATDIR > configure:3150: result: $(PLATMACDIRS) > configure:3161: checking machine type as reported by uname -m > configure:3164: result: x86_64 > configure:3177: checking for --without-gcc > configure:3221: result: no > configure:3282: checking for gcc > configure:3312: result: no > configure:3375: checking for cc > configure:3422: result: no > configure:3478: checking for cl.exe > configure:3508: result: no > configure:3532: error: in `/usr/bin/Python-2.7.3': > configure:3534: error: no acceptable C compiler found in $PATH > See `config.log' for more details > > > I can't seem to figure out the 2 errors at the bottom. Any suggestions? > > > Janet I am trying to install Python-2.7.3. From alain at dpt-info.u-strasbg.fr Sun Jun 3 17:28:03 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sun, 03 Jun 2012 23:28:03 +0200 Subject: ./configure References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> Message-ID: <874nqs3x24.fsf@dpt-info.u-strasbg.fr> Janet Heath writes: [...] > configure:3161: checking machine type as reported by uname -m > configure:3164: result: x86_64 > configure:3177: checking for --without-gcc > configure:3221: result: no > configure:3282: checking for gcc > configure:3312: result: no > configure:3375: checking for cc > configure:3422: result: no > configure:3478: checking for cl.exe > configure:3508: result: no > configure:3532: error: in `/usr/bin/Python-2.7.3': > configure:3534: error: no acceptable C compiler found in $PATH > See `config.log' for more details > > I can't seem to figure out the 2 errors at the bottom. Any suggestions? It looks like you have no C compiler (if you have one, configure can't find it in the obvious way). You need a C compiler to compile python. You should first install a C compiler. But are you sure you need to compile python? Isn't there a binary package available for your platform? -- Alain. From martin.schoon at gmail.com Sun Jun 3 17:29:58 2012 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 3 Jun 2012 21:29:58 GMT Subject: usenet reading References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: On 2012-06-03, Peter Pearson wrote: > On Sat, 26 May 2012 16:05:23 +0100, duncan smith wrote: >> On 25/05/12 23:38, Jon Clements wrote: > [snip] >>> Is there a server out there where I can get my news groups? >> >> If you don't mind paying a small fee there are several companies >> providing usenet access such as http://www.newsdemon.com. (I didn't have >> much joy trying to track down a reliable free service, so now I pay a >> few pounds a year.) > > Also in the pay-a-little category, news.individual.net costs 10 > euros per year and filters out spam pretty effectively. I've > been happy using it with the slrn news reader for about 4 years. > Same here. /Martin From rosuav at gmail.com Sun Jun 3 17:34:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jun 2012 07:34:54 +1000 Subject: ./configure In-Reply-To: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> Message-ID: On Mon, Jun 4, 2012 at 7:19 AM, Janet Heath wrote: > configure:3534: error: no acceptable C compiler found in $PATH The configure script is used to build Python from source. To do that, you need a C compiler (such as gcc, which it went looking for a few lines earlier). Perhaps you want a binary distribution instead, which doesn't require compilation. ChrisA From janetcatherine.heath at gmail.com Sun Jun 3 18:01:07 2012 From: janetcatherine.heath at gmail.com (Janet Heath) Date: Sun, 3 Jun 2012 15:01:07 -0700 (PDT) Subject: ./configure In-Reply-To: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> Message-ID: On Sunday, June 3, 2012 3:19:16 PM UTC-6, Janet Heath wrote: > Hi, > > I am trying to run the ./configure but I keep getting this: > > > configure:2756: checking for --enable-universalsdk > configure:2797: result: no > configure:2806: checking for --with-universal-archs > configure:2823: result: 32-bit > configure:2980: checking MACHDEP > configure:3129: result: darwin > configure:3135: checking EXTRAPLATDIR > configure:3150: result: $(PLATMACDIRS) > configure:3161: checking machine type as reported by uname -m > configure:3164: result: x86_64 > configure:3177: checking for --without-gcc > configure:3221: result: no > configure:3282: checking for gcc > configure:3312: result: no > configure:3375: checking for cc > configure:3422: result: no > configure:3478: checking for cl.exe > configure:3508: result: no > configure:3532: error: in `/usr/bin/Python-2.7.3': > configure:3534: error: no acceptable C compiler found in $PATH > See `config.log' for more details > > > I can't seem to figure out the 2 errors at the bottom. Any suggestions? > > > Janet On Sunday, June 3, 2012 3:19:16 PM UTC-6, Janet Heath wrote: > Hi, > > I am trying to run the ./configure but I keep getting this: > > > configure:2756: checking for --enable-universalsdk > configure:2797: result: no > configure:2806: checking for --with-universal-archs > configure:2823: result: 32-bit > configure:2980: checking MACHDEP > configure:3129: result: darwin > configure:3135: checking EXTRAPLATDIR > configure:3150: result: $(PLATMACDIRS) > configure:3161: checking machine type as reported by uname -m > configure:3164: result: x86_64 > configure:3177: checking for --without-gcc > configure:3221: result: no > configure:3282: checking for gcc > configure:3312: result: no > configure:3375: checking for cc > configure:3422: result: no > configure:3478: checking for cl.exe > configure:3508: result: no > configure:3532: error: in `/usr/bin/Python-2.7.3': > configure:3534: error: no acceptable C compiler found in $PATH > See `config.log' for more details > > > I can't seem to figure out the 2 errors at the bottom. Any suggestions? > > > Janet On Sunday, June 3, 2012 3:19:16 PM UTC-6, Janet Heath wrote: > Hi, > > I am trying to run the ./configure but I keep getting this: > > > configure:2756: checking for --enable-universalsdk > configure:2797: result: no > configure:2806: checking for --with-universal-archs > configure:2823: result: 32-bit > configure:2980: checking MACHDEP > configure:3129: result: darwin > configure:3135: checking EXTRAPLATDIR > configure:3150: result: $(PLATMACDIRS) > configure:3161: checking machine type as reported by uname -m > configure:3164: result: x86_64 > configure:3177: checking for --without-gcc > configure:3221: result: no > configure:3282: checking for gcc > configure:3312: result: no > configure:3375: checking for cc > configure:3422: result: no > configure:3478: checking for cl.exe > configure:3508: result: no > configure:3532: error: in `/usr/bin/Python-2.7.3': > configure:3534: error: no acceptable C compiler found in $PATH > See `config.log' for more details > > > I can't seem to figure out the 2 errors at the bottom. Any suggestions? > > > Janet On Sunday, June 3, 2012 3:19:16 PM UTC-6, Janet Heath wrote: > Hi, > > I am trying to run the ./configure but I keep getting this: > > > configure:2756: checking for --enable-universalsdk > configure:2797: result: no > configure:2806: checking for --with-universal-archs > configure:2823: result: 32-bit > configure:2980: checking MACHDEP > configure:3129: result: darwin > configure:3135: checking EXTRAPLATDIR > configure:3150: result: $(PLATMACDIRS) > configure:3161: checking machine type as reported by uname -m > configure:3164: result: x86_64 > configure:3177: checking for --without-gcc > configure:3221: result: no > configure:3282: checking for gcc > configure:3312: result: no > configure:3375: checking for cc > configure:3422: result: no > configure:3478: checking for cl.exe > configure:3508: result: no > configure:3532: error: in `/usr/bin/Python-2.7.3': > configure:3534: error: no acceptable C compiler found in $PATH > See `config.log' for more details > > > I can't seem to figure out the 2 errors at the bottom. Any suggestions? > > > Janet On Sunday, June 3, 2012 3:19:16 PM UTC-6, Janet Heath wrote: > Hi, > > I am trying to run the ./configure but I keep getting this: > > > configure:2756: checking for --enable-universalsdk > configure:2797: result: no > configure:2806: checking for --with-universal-archs > configure:2823: result: 32-bit > configure:2980: checking MACHDEP > configure:3129: result: darwin > configure:3135: checking EXTRAPLATDIR > configure:3150: result: $(PLATMACDIRS) > configure:3161: checking machine type as reported by uname -m > configure:3164: result: x86_64 > configure:3177: checking for --without-gcc > configure:3221: result: no > configure:3282: checking for gcc > configure:3312: result: no > configure:3375: checking for cc > configure:3422: result: no > configure:3478: checking for cl.exe > configure:3508: result: no > configure:3532: error: in `/usr/bin/Python-2.7.3': > configure:3534: error: no acceptable C compiler found in $PATH > See `config.log' for more details > > > I can't seem to figure out the 2 errors at the bottom. Any suggestions? > > > Janet Thanks Alain. I should have a compiler on my Mac OS X Lion. I am thinking that it isn't set in my $PATH variable. I don't know where the $PATH is set at. I will check to see if their is a binary. From benjamin.kaplan at case.edu Sun Jun 3 18:17:44 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 3 Jun 2012 18:17:44 -0400 Subject: ./configure In-Reply-To: References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> Message-ID: > > Thanks Alain. ?I should have a compiler on my Mac OS X Lion. ?I am thinking that it isn't set in my $PATH variable. ?I don't know where the $PATH is set at. ?I will check to see if their is a binary. > -- > http://mail.python.org/mailman/listinfo/python-list You need to install the command line tools package within XCode in order to get them on the path. Or, I guess you could just add XCode's bin directory to the path. It's usually set in ~/.bash_profile Or you could just use the binary installer from http://python.org/download/releases/2.7.3/ From robert.kern at gmail.com Sun Jun 3 18:18:26 2012 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 03 Jun 2012 23:18:26 +0100 Subject: ./configure In-Reply-To: References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> Message-ID: On 6/3/12 11:01 PM, Janet Heath wrote: > > Thanks Alain. I should have a compiler on my Mac OS X Lion. I am thinking that it isn't set in my $PATH variable. I don't know where the $PATH is set at. I will check to see if their is a binary. Lion does not come with a compiler out-of-box. You have to install one. You can either install Xcode using the App Store, or register for an Apple ID and download the "Command Line Tools for Xcode" if you don't want the full Xcode IDE: https://developer.apple.com/downloads/index.action -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From bahamutzero8825 at gmail.com Sun Jun 3 18:23:37 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 03 Jun 2012 17:23:37 -0500 Subject: ./configure In-Reply-To: References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> Message-ID: <4FCBE3E9.9040801@gmail.com> On 6/3/2012 5:01 PM, Janet Heath wrote: > Thanks Alain. I should have a compiler on my Mac OS X Lion. I am thinking that it isn't set in my $PATH variable. I don't know where the $PATH is set at. I will check to see if their is a binary. There are always Windows and OS X binary installers on python.org. I'm not sure how you would get a source package without encountering the installer. Also, IIRC, compiling anything on OS X requires Xcode, which means you wouldn't have a working C compiler without it. http://www.python.org/download/releases/2.7.3/ -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From steve+comp.lang.python at pearwood.info Sun Jun 3 20:31:41 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Jun 2012 00:31:41 GMT Subject: ./configure References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> Message-ID: <4fcc01ed$0$29971$c3e8da3$5496439d@news.astraweb.com> On Sun, 03 Jun 2012 15:01:07 -0700, Janet Heath wrote: > Thanks Alain. I should have a compiler on my Mac OS X Lion. I am > thinking that it isn't set in my $PATH variable. I don't know where the > $PATH is set at. I will check to see if their is a binary. At the command line, run: echo $PATH to see the path. I'm not sure where OS X sets the PATH, but Linux systems normally set them in /etc/profile. User-customisations should go in a shell rc file, e.g. if you are using bash, edit ~/.bashrc. To add additional paths to the PATH: export $PATH=$PATH:/some/directory:/another/directory To replace the system path completely: export $PATH=/some/directory:/another/directory -- Steven From wrw at mac.com Sun Jun 3 22:44:14 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Sun, 03 Jun 2012 22:44:14 -0400 Subject: ./configure In-Reply-To: <4fcc01ed$0$29971$c3e8da3$5496439d@news.astraweb.com> References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> <4fcc01ed$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jun 3, 2012, at 8:31 PM, Steven D'Aprano wrote: > On Sun, 03 Jun 2012 15:01:07 -0700, Janet Heath wrote: > >> Thanks Alain. I should have a compiler on my Mac OS X Lion. I am >> thinking that it isn't set in my $PATH variable. I don't know where the >> $PATH is set at. I will check to see if their is a binary. > > At the command line, run: > > echo $PATH > > to see the path. > > I'm not sure where OS X sets the PATH, but Linux systems normally set > them in /etc/profile. User-customisations should go in a shell rc file, > e.g. if you are using bash, edit ~/.bashrc. > > To add additional paths to the PATH: > > export $PATH=$PATH:/some/directory:/another/directory > > > To replace the system path completely: > > export $PATH=/some/directory:/another/directory > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list Jumping in here in an effort to be helpful? OS-X no longer uses a .bashrc file (although it will recognize it). The python path is set in ~/.profile -Bill From janetcatherine.heath at gmail.com Mon Jun 4 00:01:25 2012 From: janetcatherine.heath at gmail.com (Janet Heath) Date: Sun, 3 Jun 2012 21:01:25 -0700 (PDT) Subject: ./configure References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> <4fcc01ed$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jun 3, 6:31?pm, Steven D'Aprano wrote: > On Sun, 03 Jun 2012 15:01:07 -0700, Janet Heath wrote: > > Thanks Alain. ?I should have a compiler on my Mac OS X Lion. ?I am > > thinking that it isn't set in my $PATH variable. ?I don't know where the > > $PATH is set at. ?I will check to see if their is a binary. > > At the command line, run: > > echo $PATH > > to see the path. > > I'm not sure where OS X sets the PATH, but Linux systems normally set > them in /etc/profile. User-customisations should go in a shell rc file, > e.g. if you are using bash, edit ~/.bashrc. > > To add additional paths to the PATH: > > export $PATH=$PATH:/some/directory:/another/directory > > To replace the system path completely: > > export $PATH=/some/directory:/another/directory > > -- > Steven Thanks Steven! From janetcatherine.heath at gmail.com Mon Jun 4 00:04:37 2012 From: janetcatherine.heath at gmail.com (Janet Heath) Date: Sun, 3 Jun 2012 21:04:37 -0700 (PDT) Subject: Installing Mailman Message-ID: <868c7e4f-4c89-4355-b0c0-f5966f5aaaa9@b5g2000pbm.googlegroups.com> checking for --with-python... no checking for python... /usr/bin/python checking Python interpreter... /usr/bin/python checking Python version... 2.7.1 checking Python's email package... ok checking Japanese codecs... ok checking Korean codecs... ok checking that Python has a working distutils... configure: error: ***** Distutils is not available or is incomplete for /usr/bin/python ***** If you installed Python from RPM (or other package manager) ***** be sure to install the -devel package, or install Python ***** from source. See sec. 15.1 of the Installation Manual for ***** details When I try to check the configuration ./configure for Mailman, I get the above messages. From clp2 at rebertia.com Mon Jun 4 00:49:31 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 3 Jun 2012 21:49:31 -0700 Subject: Installing Mailman In-Reply-To: <868c7e4f-4c89-4355-b0c0-f5966f5aaaa9@b5g2000pbm.googlegroups.com> References: <868c7e4f-4c89-4355-b0c0-f5966f5aaaa9@b5g2000pbm.googlegroups.com> Message-ID: On Sun, Jun 3, 2012 at 9:04 PM, Janet Heath wrote: > checking for --with-python... no > checking for python... /usr/bin/python > checking Python interpreter... /usr/bin/python > checking Python version... 2.7.1 > checking Python's email package... ok > checking Japanese codecs... ok > checking Korean codecs... ok > checking that Python has a working distutils... configure: error: > > ***** Distutils is not available or is incomplete for /usr/bin/python > ***** If you installed Python from RPM (or other package manager) > ***** be sure to install the -devel package, or install Python > ***** from source. ?See sec. 15.1 of the Installation Manual for > ***** details > > When I try to check the configuration ./configure for Mailman, I get > the above messages. What *nix flavor or Linux distro are you running? Cheers, Chris From benjamin.kaplan at case.edu Mon Jun 4 01:08:01 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 4 Jun 2012 01:08:01 -0400 Subject: Installing Mailman In-Reply-To: References: <868c7e4f-4c89-4355-b0c0-f5966f5aaaa9@b5g2000pbm.googlegroups.com> Message-ID: On Mon, Jun 4, 2012 at 12:49 AM, Chris Rebert wrote: > On Sun, Jun 3, 2012 at 9:04 PM, Janet Heath > wrote: >> checking for --with-python... no >> checking for python... /usr/bin/python >> checking Python interpreter... /usr/bin/python >> checking Python version... 2.7.1 >> checking Python's email package... ok >> checking Japanese codecs... ok >> checking Korean codecs... ok >> checking that Python has a working distutils... configure: error: >> >> ***** Distutils is not available or is incomplete for /usr/bin/python >> ***** If you installed Python from RPM (or other package manager) >> ***** be sure to install the -devel package, or install Python >> ***** from source. ?See sec. 15.1 of the Installation Manual for >> ***** details >> >> When I try to check the configuration ./configure for Mailman, I get >> the above messages. > > What *nix flavor or Linux distro are you running? > > Cheers, > Chris Based on the previous post (./configure), I would assume OS X Lion. I would also assume she gave up on compiling 2.7.3 herself because it's only finding the system Python. Janet, did you install the binary from http://www.python.org? If so, look up the --with-python argument it's checking for (./configure --help) and set the Python location accordingly. From list at qtrac.plus.com Mon Jun 4 03:21:33 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Mon, 4 Jun 2012 00:21:33 -0700 (PDT) Subject: Use a locally built Tk for Python? References: <900b402d-c6b0-4e00-beea-a18417764ee8@b26g2000vbt.googlegroups.com> <134b5743-e7be-47d1-be47-5bb75ef4fe54@googlegroups.com> Message-ID: <7b8c02aa-7fa6-4f2f-af49-0a399c00a789@b1g2000vbb.googlegroups.com> Thanks for your thoughtful replies. I don't use altinstall because using --prefix is sufficient to get a locally built Python. Both your suggestions require root (or sudo) and changing the system itself. Whereas I was hoping to just build a local Python and install my own Tcl/Tk in its lib and site-packages (which I believe is what happens on Windows?). Anyway, maybe that isn't possible. I will try installing my patched Tcl/Tk system wide on an old machine and if that works I'll do it to my main machine and rebuild my Pythons to use it. From corey at octayn.net Mon Jun 4 04:08:56 2012 From: corey at octayn.net (Corey Richardson) Date: Mon, 4 Jun 2012 04:08:56 -0400 Subject: why i can't read sda1 with python? In-Reply-To: References: Message-ID: <20120604040856.2d667e63@Ulysses> On Sat, 2 Jun 2012 10:14:36 +0800 "????" <1248283536 at qq.com> <1248283536 at qq.com> wrote: > [snip] > i want to read sda1 with python: > >>> file=open('/dev/sda1','rb') > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 13] Permission denied: '/dev/sda1' > > how can i own the access to read sda1? > You need read privileges. Either change the permissions of /dev/sda1, or run python as root. -- Corey Richardson From zhxia at njnet.edu.cn Mon Jun 4 04:14:53 2012 From: zhxia at njnet.edu.cn (Xia) Date: Mon, 4 Jun 2012 16:14:53 +0800 Subject: why i can't read sda1 with python? In-Reply-To: References: Message-ID: <20120604161453.111ce152.zhxia@njnet.edu.cn> #ls -l /dev/sda1 will print brw-r----- 1 root disk ... so only root or accounts in group disk can access /dev/sda1, you could add the account into group disk with usermod, then re-login. On Sat, 2 Jun 2012 10:14:36 +0800 "????" <1248283536 at qq.com> wrote: > tiger at debian:~$ sudo fdisk -l > > Disk /dev/sda: 120.0 GB, 120034123776 bytes > 255 heads, 63 sectors/track, 14593 cylinders > Units = cylinders of 16065 * 512 = 8225280 bytes > Sector size (logical/physical): 512 bytes / 512 bytes > I/O size (minimum/optimal): 512 bytes / 512 bytes > Disk identifier: 0x073a3c87 > > Device Boot Start End Blocks Id System > /dev/sda1 * 1 1912 15358108+ c W95 FAT32 (LBA) > /dev/sda2 1913 3736 14647296 b W95 FAT32 > /dev/sda3 3736 3979 1952768 83 Linux > /dev/sda4 3979 14594 85260289 5 Extended > /dev/sda5 3979 4040 487424 83 Linux > /dev/sda6 4040 4769 5858304 83 Linux > /dev/sda7 4770 4891 975872 83 Linux > /dev/sda8 4891 5134 1951744 83 Linux > /dev/sda9 5134 14374 74217472 83 Linux > /dev/sda10 14374 14594 1764352 82 Linux swap / Solaris > > i want to read sda1 with python: > >>> file=open('/dev/sda1','rb') > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 13] Permission denied: '/dev/sda1' > > how can i own the access to read sda1? From kushal.kumaran+python at gmail.com Mon Jun 4 05:14:49 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 4 Jun 2012 14:44:49 +0530 Subject: Use a locally built Tk for Python? In-Reply-To: <7b8c02aa-7fa6-4f2f-af49-0a399c00a789@b1g2000vbb.googlegroups.com> References: <900b402d-c6b0-4e00-beea-a18417764ee8@b26g2000vbt.googlegroups.com> <134b5743-e7be-47d1-be47-5bb75ef4fe54@googlegroups.com> <7b8c02aa-7fa6-4f2f-af49-0a399c00a789@b1g2000vbb.googlegroups.com> Message-ID: On Mon, Jun 4, 2012 at 12:51 PM, Mark Summerfield wrote: > Thanks for your thoughtful replies. > > I don't use altinstall because using --prefix is sufficient to get a > locally built Python. > > Both your suggestions require root (or sudo) and changing the system > itself. Whereas I was hoping to just build a local Python and install > my own Tcl/Tk in its lib and site-packages (which I believe is what > happens on Windows?). > > Anyway, maybe that isn't possible. I will try installing my patched > Tcl/Tk system wide on an old machine and if that works I'll do it to > my main machine and rebuild my Pythons to use it. You can try these: - set LD_LIBRARY_PATH to /home/mark/opt/tcltk85/lib when running python, or - configure your python with LDFLAGS set to -Wl,-rpath=/home/mark/opt/tcltk85/lib Both of these are slightly smelly hacks, but might suffice for your needs. -- regards, kushal From pullenjenna10 at gmail.com Mon Jun 4 08:57:14 2012 From: pullenjenna10 at gmail.com (richard) Date: Mon, 4 Jun 2012 05:57:14 -0700 (PDT) Subject: Help needed with nested parsing of file into objects Message-ID: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> Hi guys i am having a bit of dificulty finding the best approach / solution to parsing a file into a list of objects / nested objects any help would be greatly appreciated. #file format to parse .txt [code] An instance of TestArray a=a b=b c=c List of 2 A elements: Instance of A element a=1 b=2 c=3 Instance of A element d=1 e=2 f=3 List of 1 B elements Instance of B element a=1 b=2 c=3 List of 2 C elements Instance of C element a=1 b=2 c=3 Instance of C element a=1 b=2 c=3 An instance of TestArray a=1 b=2 c=3 [/code] expected output list of 2 TestArray objects been the parents the first one having an attribute holding a list of the 2 instance of A objects the parents children, another attribute of the parent holding a list of just the 1 child instance of B object with the child object then containing an attribute holding a list of the 2 Instance of C objects but the nesting could be more this is just an example. The instance of TestArray may or may not have any nesting at all this is illustrated in the second TestArray. Basically just want to create a list of objects with the objects may or may not contain more nested objects as attributes but need a generic way to do it that would work for any amount of depth. #end list of objects with objects printed as dicts [code] parsed = [ { "a":"a", "b":"b", "c":"c", "A_elements":[ { "a":1, "b":2, "c":3 }, { "a":1, "b":2, "c":3 } ], "B_elements":[ { "a":1, "b":2, "c":3, "C_elements":[ { "a":1, "b":2, "c":3 }, { "a":1, "b":2, "c":3 } ] } ] }, { "a":"1", "b":"2", "c":"3", } ] [/code] #this is what i have so far which works with the 2nd instance but cant figure out the best way to handle the multi nested objects. [code] import re def test_parser(filename): parent_stanza = None stanzas = [] class parentStanza: pass fo = open(filename) for line in fo: line = line.strip() if re.search("An instance of TestArray", line): if parent_stanza: stanzas.append(parent_stanza) parent_stanza = parentStanza() if parent_stanza and "=" in line: attr, val = line.split("=") setattr(parent_stanza, attr, val) else: stanzas.append(parent_stanza) return stanzas stanzas = test_parser("test.txt") import pprint for stanza in stanzas: pprint.pprint(stanza.__dict__) n=raw_input("paused") [/code] From roy at panix.com Mon Jun 4 09:13:05 2012 From: roy at panix.com (Roy Smith) Date: Mon, 04 Jun 2012 09:13:05 -0400 Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> Message-ID: In article <6b296278-fd32-45fb-b5c7-6c0fe5ce4967 at q2g2000vbv.googlegroups.com>, richard wrote: > Hi guys i am having a bit of dificulty finding the best approach / > solution to parsing a file into a list of objects / nested objects any > help would be greatly appreciated. The first question is "Why do you want to do this?" Is this some pre-existing file format imposed by an external system that you can't change? Or are you just looking for a generic way to store nested structures in a file? If the later, then I would strongly suggest not rolling your own. Take a look at json or pickle (or even xml) and adopt one of those. From alain at dpt-info.u-strasbg.fr Mon Jun 4 10:14:39 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 04 Jun 2012 16:14:39 +0200 Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> Message-ID: <87wr3n2mgg.fsf@dpt-info.u-strasbg.fr> richard writes: > Hi guys i am having a bit of dificulty finding the best approach / > solution to parsing a file into a list of objects / nested objects any > help would be greatly appreciated. > > #file format to parse .txt > [code] > An instance of TestArray > a=a > b=b > c=c > List of 2 A elements: > Instance of A element [...] Below is a piece of code that seems to work on your data. It builds a raw tree, i leave it to you to adapt and built the objects you want. The assumption is that the number of leading blanks faithfully denotes depth. As noted in another message, you're probably better off using an existing syntax (json, python literals, yaml, xml, ...) -- Alain. #!/usr/bin/env python import sys import re RE = re.compile("( *)(.*)") stack = [("-",[])] # tree nodes are: (head,[children]) for line in sys.stdin: matches = RE.match(line) if len(matches.group(2)) > 0: depth = 1 + len(matches.group(1)) while len(stack) > depth: stack[-2][1].append(stack[-1]) del stack[-1] pass stack.append( (matches.group(2),[]) ) pass pass while len(stack) > 1: stack[-2][1].append(stack[-1]) del stack[-1] pass print(stack) From pullenjenna10 at gmail.com Mon Jun 4 10:20:28 2012 From: pullenjenna10 at gmail.com (richard) Date: Mon, 4 Jun 2012 07:20:28 -0700 (PDT) Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> <87wr3n2mgg.fsf@dpt-info.u-strasbg.fr> Message-ID: On Jun 4, 3:14?pm, Alain Ketterlin wrote: > richard writes: > > Hi guys i am having a bit of dificulty finding the best approach / > > solution to parsing a file into a list of objects / nested objects any > > help would be greatly appreciated. > > > #file format to parse .txt > > [code] > > An instance of TestArray > > ?a=a > > ?b=b > > ?c=c > > ?List of 2 A elements: > > ? Instance of A element > > [...] > > Below is a piece of code that seems to work on your data. It builds a > raw tree, i leave it to you to adapt and built the objects you want. The > assumption is that the number of leading blanks faithfully denotes > depth. > > As noted in another message, you're probably better off using an > existing syntax (json, python literals, yaml, xml, ...) > > -- Alain. > > #!/usr/bin/env python > > import sys > import re > > RE = re.compile("( *)(.*)") > stack = [("-",[])] # tree nodes are: (head,[children]) > for line in sys.stdin: > ? ? matches = RE.match(line) > ? ? if len(matches.group(2)) > 0: > ? ? ? ? depth = 1 + len(matches.group(1)) > ? ? ? ? while len(stack) > depth: > ? ? ? ? ? ? stack[-2][1].append(stack[-1]) > ? ? ? ? ? ? del stack[-1] > ? ? ? ? ? ? pass > ? ? ? ? stack.append( (matches.group(2),[]) ) > ? ? ? ? pass > ? ? pass > while len(stack) > 1: > ? ? stack[-2][1].append(stack[-1]) > ? ? del stack[-1] > ? ? pass > > print(stack) thank you both for your replies. Unfortunately it is a pre-existing file format imposed by an external system that I can't change. Thank you for the code snippet. From davidgshi at yahoo.co.uk Mon Jun 4 10:36:12 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Mon, 4 Jun 2012 15:36:12 +0100 (BST) Subject: Where is the latest step by step guide to use Jython to compile Python into Java? Message-ID: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> Hello, Where is the latest step by step guide to use Jython to compile Python into Java? I found that it was very confusing by reading not updated text. Please help. Regards. David -------------- next part -------------- An HTML attachment was scrubbed... URL: From Mohan.Narayanaswamy-2 at sc.com Mon Jun 4 10:56:36 2012 From: Mohan.Narayanaswamy-2 at sc.com (Narayanaswamy, Mohan) Date: Mon, 4 Jun 2012 22:56:36 +0800 Subject: Where is the latest step by step guide to use Jython to compilePython into Java? In-Reply-To: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> References: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> Message-ID: <6D5B5AE8C592DD4A92D0DA056F1226CF17742D@HKMGAXMB110A.zone1.scb.net> David, As per my knowledge, You can?t find steps to convert python into java anywhere. 1) I am not expert in python, but familiar with Java. Python by default uses python-vm and converts into byte code, which is not compatible with JVM byte-code, Jython/Jruby/Jxxx are supporting languages on top of JVM. Jython is executing python on top of JVM, by doing that, we can make use of java library inside python and/or vice versa. 2) Python is dynanmic programming (but strongly typed), java is static-typed language. Currently it is not possible to convert python into java, since python types are dynamically identified, not identified during compilation. Regards Mohan From: python-list-bounces+mohan.narayanaswamy-2=sc.com at python.org [mailto:python-list-bounces+mohan.narayanaswamy-2=sc.com at python.org] On Behalf Of David Shi Sent: Monday, June 04, 2012 10:36 PM To: python-list at python.org Subject: Where is the latest step by step guide to use Jython to compilePython into Java? Hello, Where is the latest step by step guide to use Jython to compile Python into Java? I found that it was very confusing by reading not updated text. Please help. Regards. David This email and any attachments are confidential and may also be privileged. If you are not the addressee, do not disclose, copy, circulate or in any other way use or rely on the information contained in this email or any attachments. If received in error, notify the sender immediately and delete this email and any attachments from your system. Emails cannot be guaranteed to be secure or error free as the message and any attachments could be intercepted, corrupted, lost, delayed, incomplete or amended. Standard Chartered PLC and its subsidiaries do not accept liability for damage caused by this email or any attachments and may monitor email traffic. Standard Chartered PLC is incorporated in England with limited liability under company number 966425 and has its registered office at 1 Aldermanbury Square, London, EC2V 7SB. Standard Chartered Bank ("SCB") is incorporated in England with limited liability by Royal Charter 1853, under reference ZC18. The Principal Office of SCB is situated in England at 1 Aldermanbury Square, London EC2V 7SB. In the United Kingdom, SCB is authorised and regulated by the Financial Services Authority under FSA register number 114276. If you are receiving this email from SCB outside the UK, please click http://www.standardchartered.com/global/email_disclaimer.html to refer to the information on other jurisdictions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Jun 4 11:00:59 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 04 Jun 2012 17:00:59 +0200 Subject: Where is the latest step by step guide to use Jython to compile Python into Java? In-Reply-To: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> References: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> Message-ID: David Shi, 04.06.2012 16:36: > Where is the latest step by step guide to use Jython to compile Python into Java? I don't think there is such a thing, simply because Jython does not compile Python into Java. > I found that it was very confusing by reading not updated text. It usually helps to provide a pointer to that "not updated text", so that readers know what you are talking about and can more easily provide an alternative. Stefan From stefan_ml at behnel.de Mon Jun 4 11:27:28 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 04 Jun 2012 17:27:28 +0200 Subject: Where is the latest step by step guide to use Jython to compile Python into Java? In-Reply-To: <6D5B5AE8C592DD4A92D0DA056F1226CF17742D@HKMGAXMB110A.zone1.scb.net> References: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> <6D5B5AE8C592DD4A92D0DA056F1226CF17742D@HKMGAXMB110A.zone1.scb.net> Message-ID: Narayanaswamy, Mohan, 04.06.2012 16:56: > Python is dynanmic programming (but strongly typed), java is > static-typed language. Currently it is not possible to convert python > into java, since python types are dynamically identified, not identified > during compilation. That's not entirely true. It's *possible* to translate Python to Java, just like it's possible to translate Python to C or other statically typed languages. That wouldn't be a 1:1 mapping from Python language constructs into similar looking Java language constructs, simply because the Python constructs tend to be more powerful and general, so there is no simple direct mapping. But assuming sufficiently complex Java code, any Python code can be translated to equivalent Java code. Simple prove: Jython can execute Python code, and Jython is (at its basis) written in Java. If you now collect all Java code that Jython executes during the run of a Python program, you get pure Java code that is equivalent to the Python program. Maybe not beautiful code, but definitely Java code. Stefan From davidgshi at yahoo.co.uk Mon Jun 4 11:35:00 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Mon, 4 Jun 2012 16:35:00 +0100 (BST) Subject: Where is the latest step by step guide to use Jython to compilePython into Java? In-Reply-To: <6D5B5AE8C592DD4A92D0DA056F1226CF17742D@HKMGAXMB110A.zone1.scb.net> References: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> <6D5B5AE8C592DD4A92D0DA056F1226CF17742D@HKMGAXMB110A.zone1.scb.net> Message-ID: <1338824100.7053.YahooMailNeo@web171606.mail.ir2.yahoo.com> Mohan, Please see the following link as an example. http://www.ssec.wisc.edu/~tomw/visadtutor/compile.html I just can not make any success with some of these instructions. Compiling your Python code with jythonc I do not know whether I downloaded a wrong version of Jythonc??? Or, got mismatched software or instructions. Please provide assistance, by providing the tested software and instructions. Regards. David ________________________________ From: "Narayanaswamy, Mohan" To: David Shi Cc: python-list at python.org Sent: Monday, 4 June 2012, 15:56 Subject: RE: Where is the latest step by step guide to use Jython to compilePython into Java? David, ? As per my knowledge, You can?t find steps to convert python into java anywhere. ? 1)????? I am not expert in python, but familiar with Java. Python by default uses python-vm and converts into byte code, which is not compatible with JVM byte-code, Jython/Jruby/Jxxx are supporting languages on top of JVM. Jython is executing python on top of JVM, by doing that, we can make use of java library inside python and/or vice versa. 2)????? Python is dynanmic programming (but strongly typed), java is static-typed language. ?Currently it is not possible to convert python into java, since python types are dynamically identified, not identified during compilation. ? Regards Mohan ? From:python-list-bounces+mohan.narayanaswamy-2=sc.com at python.org [mailto:python-list-bounces+mohan.narayanaswamy-2=sc.com at python.org] On Behalf Of David Shi Sent: Monday, June 04, 2012 10:36 PM To: python-list at python.org Subject: Where is the latest step by step guide to use Jython to compilePython into Java? ? Hello, ? Where is the latest step by step guide to use Jython to compile Python into Java? ? I found that it was very confusing by reading not updated text. ? Please help. ? Regards. ? David This email and any attachments are confidential and may also be privileged. If you are not the addressee, do not disclose, copy, circulate or in any other way use or rely on the information contained in this email or any attachments. If received in error, notify the sender immediately and delete this email and any attachments from your system. Emails cannot be guaranteed to be secure or error free as the message and any attachments could be intercepted, corrupted, lost, delayed, incomplete or amended. Standard Chartered PLC and its subsidiaries do not accept liability for damage caused by this email or any attachments and may monitor email traffic. Standard Chartered PLC is incorporated in England with limited liability under company number 966425 and has its registered office at 1 Aldermanbury Square, London, EC2V 7SB. Standard Chartered Bank ("SCB") is incorporated in England with limited liability by Royal Charter 1853, under reference ZC18. The Principal Office of SCB is situated in England at 1 Aldermanbury Square, London EC2V 7SB. In the United Kingdom, SCB is authorised and regulated by the Financial Services Authority under FSA register number 114276. If you are receiving this email from SCB outside the UK, please click http://www.standardchartered.com/global/email_disclaimer.html to refer to the information on other jurisdictions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Mohan.Narayanaswamy-2 at sc.com Mon Jun 4 11:38:03 2012 From: Mohan.Narayanaswamy-2 at sc.com (Narayanaswamy, Mohan) Date: Mon, 4 Jun 2012 23:38:03 +0800 Subject: Where is the latest step by step guide to use Jython to compilePython into Java? In-Reply-To: <1338824100.7053.YahooMailNeo@web171606.mail.ir2.yahoo.com> References: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> <6D5B5AE8C592DD4A92D0DA056F1226CF17742D@HKMGAXMB110A.zone1.scb.net> <1338824100.7053.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: <6D5B5AE8C592DD4A92D0DA056F1226CF177434@HKMGAXMB110A.zone1.scb.net> David, Thanks for the link, here that compilation steps won?t produce java code, but it could create .class file (or jar). Regards Mohan From: David Shi [mailto:davidgshi at yahoo.co.uk] Sent: Monday, June 04, 2012 11:35 PM To: Narayanaswamy, Mohan Cc: python-list at python.org Subject: Re: Where is the latest step by step guide to use Jython to compilePython into Java? Mohan, Please see the following link as an example. http://www.ssec.wisc.edu/~tomw/visadtutor/compile.html I just can not make any success with some of these instructions. Compiling your Python code with jythonc I do not know whether I downloaded a wrong version of Jythonc? Or, got mismatched software or instructions. Please provide assistance, by providing the tested software and instructions. Regards. David ________________________________ From: "Narayanaswamy, Mohan" To: David Shi Cc: python-list at python.org Sent: Monday, 4 June 2012, 15:56 Subject: RE: Where is the latest step by step guide to use Jython to compilePython into Java? David, As per my knowledge, You can?t find steps to convert python into java anywhere. 1) I am not expert in python, but familiar with Java. Python by default uses python-vm and converts into byte code, which is not compatible with JVM byte-code, Jython/Jruby/Jxxx are supporting languages on top of JVM. Jython is executing python on top of JVM, by doing that, we can make use of java library inside python and/or vice versa. 2) Python is dynanmic programming (but strongly typed), java is static-typed language. Currently it is not possible to convert python into java, since python types are dynamically identified, not identified during compilation. Regards Mohan From: python-list-bounces+mohan.narayanaswamy-2=sc.com at python.org [mailto:python-list-bounces+mohan.narayanaswamy-2=sc.com at python.org] On Behalf Of David Shi Sent: Monday, June 04, 2012 10:36 PM To: python-list at python.org Subject: Where is the latest step by step guide to use Jython to compilePython into Java? Hello, Where is the latest step by step guide to use Jython to compile Python into Java? I found that it was very confusing by reading not updated text. Please help. Regards. David This email and any attachments are confidential and may also be privileged. If you are not the addressee, do not disclose, copy, circulate or in any other way use or rely on the information contained in this email or any attachments. If received in error, notify the sender immediately and delete this email and any attachments from your system. Emails cannot be guaranteed to be secure or error free as the message and any attachments could be intercepted, corrupted, lost, delayed, incomplete or amended. Standard Chartered PLC and its subsidiaries do not accept liability for damage caused by this email or any attachments and may monitor email traffic. Standard Chartered PLC is incorporated in England with limited liability under company number 966425 and has its registered office at 1 Aldermanbury Square, London, EC2V 7SB. Standard Chartered Bank ("SCB") is incorporated in England with limited liability by Royal Charter 1853, under reference ZC18. The Principal Office of SCB is situated in England at 1 Aldermanbury Square, London EC2V 7SB. In the United Kingdom, SCB is authorised and regulated by the Financial Services Authority under FSA register number 114276. If you are receiving this email from SCB outside the UK, please click http://www.standardchartered.com/global/email_disclaimer.html to refer to the information on other jurisdictions. This email and any attachments are confidential and may also be privileged. If you are not the addressee, do not disclose, copy, circulate or in any other way use or rely on the information contained in this email or any attachments. If received in error, notify the sender immediately and delete this email and any attachments from your system. Emails cannot be guaranteed to be secure or error free as the message and any attachments could be intercepted, corrupted, lost, delayed, incomplete or amended. Standard Chartered PLC and its subsidiaries do not accept liability for damage caused by this email or any attachments and may monitor email traffic. Standard Chartered PLC is incorporated in England with limited liability under company number 966425 and has its registered office at 1 Aldermanbury Square, London, EC2V 7SB. Standard Chartered Bank ("SCB") is incorporated in England with limited liability by Royal Charter 1853, under reference ZC18. The Principal Office of SCB is situated in England at 1 Aldermanbury Square, London EC2V 7SB. In the United Kingdom, SCB is authorised and regulated by the Financial Services Authority under FSA register number 114276. If you are receiving this email from SCB outside the UK, please click http://www.standardchartered.com/global/email_disclaimer.html to refer to the information on other jurisdictions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidgshi at yahoo.co.uk Mon Jun 4 11:47:57 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Mon, 4 Jun 2012 16:47:57 +0100 (BST) Subject: Where is the latest step by step guide to use Jython to compilePython into Java? In-Reply-To: <6D5B5AE8C592DD4A92D0DA056F1226CF177434@HKMGAXMB110A.zone1.scb.net> References: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> <6D5B5AE8C592DD4A92D0DA056F1226CF17742D@HKMGAXMB110A.zone1.scb.net> <1338824100.7053.YahooMailNeo@web171606.mail.ir2.yahoo.com> <6D5B5AE8C592DD4A92D0DA056F1226CF177434@HKMGAXMB110A.zone1.scb.net> Message-ID: <1338824877.82708.YahooMailNeo@web171603.mail.ir2.yahoo.com> Hello, Mohan, Did you test it?? I am using Windows.? Where are the exact steps for compiling in DOS? Once .class or jar files created, how to use these files? Could you enlighten me with tested/proven step by step instructions? Regards. David ________________________________ From: "Narayanaswamy, Mohan" To: David Shi Cc: python-list at python.org Sent: Monday, 4 June 2012, 16:38 Subject: RE: Where is the latest step by step guide to use Jython to compilePython into Java? David, ? Thanks for the link, here that compilation steps won?t produce ?java code, but it could create .class file (or jar). ? Regards Mohan ? From:David Shi [mailto:davidgshi at yahoo.co.uk] Sent: Monday, June 04, 2012 11:35 PM To: Narayanaswamy, Mohan Cc: python-list at python.org Subject: Re: Where is the latest step by step guide to use Jython to compilePython into Java? ? Mohan, ? Please see the following link as an example. http://www.ssec.wisc.edu/~tomw/visadtutor/compile.html ? I just can not make any success with some of these instructions. Compiling your Python code with jythonc I do not know whether I downloaded a wrong version of Jythonc??? Or, got mismatched software or instructions. ? Please provide assistance, by providing the tested software and instructions. ? Regards. ? David ? ________________________________ From:"Narayanaswamy, Mohan" To: David Shi Cc: python-list at python.org Sent: Monday, 4 June 2012, 15:56 Subject: RE: Where is the latest step by step guide to use Jython to compilePython into Java? ? David, ? As per my knowledge, You can?t find steps to convert python into java anywhere. ? 1)????? I am not expert in python, but familiar with Java. Python by default uses python-vm and converts into byte code, which is not compatible with JVM byte-code, Jython/Jruby/Jxxx are supporting languages on top of JVM. Jython is executing python on top of JVM, by doing that, we can make use of java library inside python and/or vice versa. 2)????? Python is dynanmic programming (but strongly typed), java is static-typed language. ?Currently it is not possible to convert python into java, since python types are dynamically identified, not identified during compilation. ? Regards Mohan ? From:python-list-bounces+mohan.narayanaswamy-2=sc.com at python.org [mailto:python-list-bounces+mohan.narayanaswamy-2=sc.com at python.org] On Behalf Of David Shi Sent: Monday, June 04, 2012 10:36 PM To: python-list at python.org Subject: Where is the latest step by step guide to use Jython to compilePython into Java? ? Hello, ? Where is the latest step by step guide to use Jython to compile Python into Java? ? I found that it was very confusing by reading not updated text. ? Please help. ? Regards. ? David This email and any attachments are confidential and may also be privileged. If you are not the addressee, do not disclose, copy, circulate or in any other way use or rely on the information contained in this email or any attachments. If received in error, notify the sender immediately and delete this email and any attachments from your system. Emails cannot be guaranteed to be secure or error free as the message and any attachments could be intercepted, corrupted, lost, delayed, incomplete or amended. Standard Chartered PLC and its subsidiaries do not accept liability for damage caused by this email or any attachments and may monitor email traffic. Standard Chartered PLC is incorporated in England with limited liability under company number 966425 and has its registered office at 1 Aldermanbury Square, London, EC2V 7SB. Standard Chartered Bank ("SCB") is incorporated in England with limited liability by Royal Charter 1853, under reference ZC18. The Principal Office of SCB is situated in England at 1 Aldermanbury Square, London EC2V 7SB. In the United Kingdom, SCB is authorised and regulated by the Financial Services Authority under FSA register number 114276. If you are receiving this email from SCB outside the UK, please click http://www.standardchartered.com/global/email_disclaimer.html to refer to the information on other jurisdictions. ? This email and any attachments are confidential and may also be privileged. If you are not the addressee, do not disclose, copy, circulate or in any other way use or rely on the information contained in this email or any attachments. If received in error, notify the sender immediately and delete this email and any attachments from your system. Emails cannot be guaranteed to be secure or error free as the message and any attachments could be intercepted, corrupted, lost, delayed, incomplete or amended. Standard Chartered PLC and its subsidiaries do not accept liability for damage caused by this email or any attachments and may monitor email traffic. Standard Chartered PLC is incorporated in England with limited liability under company number 966425 and has its registered office at 1 Aldermanbury Square, London, EC2V 7SB. Standard Chartered Bank ("SCB") is incorporated in England with limited liability by Royal Charter 1853, under reference ZC18. The Principal Office of SCB is situated in England at 1 Aldermanbury Square, London EC2V 7SB. In the United Kingdom, SCB is authorised and regulated by the Financial Services Authority under FSA register number 114276. If you are receiving this email from SCB outside the UK, please click http://www.standardchartered.com/global/email_disclaimer.html to refer to the information on other jurisdictions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Jun 4 11:51:28 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 04 Jun 2012 17:51:28 +0200 Subject: Where is the latest step by step guide to use Jython to compilePython into Java? In-Reply-To: <1338824100.7053.YahooMailNeo@web171606.mail.ir2.yahoo.com> References: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> <6D5B5AE8C592DD4A92D0DA056F1226CF17742D@HKMGAXMB110A.zone1.scb.net> <1338824100.7053.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: David Shi, 04.06.2012 17:35: > Compiling your Python code with jythonc > I do not know whether I downloaded a wrong version of Jythonc? Or, got mismatched software or instructions. Jythonc used to work in Jython 2.2 but is no longer supported in Jyton 2.5. Stefan From benjamin.kaplan at case.edu Mon Jun 4 12:17:27 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 4 Jun 2012 12:17:27 -0400 Subject: Where is the latest step by step guide to use Jython to compilePython into Java? In-Reply-To: <1338824877.82708.YahooMailNeo@web171603.mail.ir2.yahoo.com> References: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> <6D5B5AE8C592DD4A92D0DA056F1226CF17742D@HKMGAXMB110A.zone1.scb.net> <1338824100.7053.YahooMailNeo@web171606.mail.ir2.yahoo.com> <6D5B5AE8C592DD4A92D0DA056F1226CF177434@HKMGAXMB110A.zone1.scb.net> <1338824877.82708.YahooMailNeo@web171603.mail.ir2.yahoo.com> Message-ID: On Mon, Jun 4, 2012 at 11:47 AM, David Shi wrote: > Hello, Mohan, > > Did you test it?? I am using Windows.? Where are the exact steps for > compiling in DOS? > > Once .class or jar files created, how to use these files? > > Could you enlighten me with tested/proven step by step instructions? > > Regards. > > David > > _______ David, Jythonc has been deprecated for years and hasn't been included with Jython since 2.2. Nor does it support any language feature newer than 2.2. I don't think anyone managed to get the python to JVM byte code compiler working either since JVM byte code is notoriously bad for things that don't behave like Java. From tjreedy at udel.edu Mon Jun 4 13:26:04 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 04 Jun 2012 13:26:04 -0400 Subject: Where is the latest step by step guide to use Jython to compilePython into Java? In-Reply-To: <1338824100.7053.YahooMailNeo@web171606.mail.ir2.yahoo.com> References: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> <6D5B5AE8C592DD4A92D0DA056F1226CF17742D@HKMGAXMB110A.zone1.scb.net> <1338824100.7053.YahooMailNeo@web171606.mail.ir2.yahoo.com> Message-ID: On 6/4/2012 11:35 AM, David Shi wrote: Please post plain text rather than html. It just works better and is the convention for this newsgroup and mailing list. -- Terry Jan Reedy From ian.g.kelly at gmail.com Mon Jun 4 13:30:25 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 4 Jun 2012 11:30:25 -0600 Subject: Where is the latest step by step guide to use Jython to compilePython into Java? In-Reply-To: References: <1338820572.64864.YahooMailNeo@web171605.mail.ir2.yahoo.com> <6D5B5AE8C592DD4A92D0DA056F1226CF17742D@HKMGAXMB110A.zone1.scb.net> <1338824100.7053.YahooMailNeo@web171606.mail.ir2.yahoo.com> <6D5B5AE8C592DD4A92D0DA056F1226CF177434@HKMGAXMB110A.zone1.scb.net> <1338824877.82708.YahooMailNeo@web171603.mail.ir2.yahoo.com> Message-ID: On Mon, Jun 4, 2012 at 10:17 AM, Benjamin Kaplan wrote: > On Mon, Jun 4, 2012 at 11:47 AM, David Shi wrote: >> Hello, Mohan, >> >> Did you test it?? I am using Windows.? Where are the exact steps for >> compiling in DOS? >> >> Once .class or jar files created, how to use these files? >> >> Could you enlighten me with tested/proven step by step instructions? >> >> Regards. >> >> David >> >> _______ > > David, > > Jythonc has been deprecated for years and hasn't been included with > Jython since 2.2. Nor does it support any language feature newer than > 2.2. I don't think anyone managed to get the python to JVM byte code > compiler working either since JVM byte code is notoriously bad for > things that don't behave like Java. I don't think that's correct. My recollection is that jythonc was replaced with the py_compile and compileall modules for compatibility with the CPython compilation features. .py files are compiled to .class files. At one point I recollect they were actually compiled to .pyc and then the .pyc was compiled to .class, but the .pyc step may have been phased out. Cheers, Ian From ramit.prasad at jpmorgan.com Mon Jun 4 15:42:24 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Mon, 4 Jun 2012 19:42:24 +0000 Subject: ./configure In-Reply-To: References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D7C8CC@SCACMX008.exchad.jpmchase.net> > > Thanks Alain. I should have a compiler on my Mac OS X Lion. I am > thinking that it isn't set in my $PATH variable. I don't know where the > $PATH is set at. I will check to see if their is a binary. > > You need to install the command line tools package within XCode in > order to get them on the path. Or, I guess you could just add XCode's > bin directory to the path. It's usually set in ~/.bash_profile Once you install the XCode tools, I would recommend installing from something like MacPorts as it will ensure you do not accidentally mess up the system Python and it tends to work auto-magically. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From nad at acm.org Mon Jun 4 15:56:08 2012 From: nad at acm.org (Ned Deily) Date: Mon, 04 Jun 2012 12:56:08 -0700 Subject: Use a locally built Tk for Python? References: <900b402d-c6b0-4e00-beea-a18417764ee8@b26g2000vbt.googlegroups.com> Message-ID: In article <900b402d-c6b0-4e00-beea-a18417764ee8 at b26g2000vbt.googlegroups.com>, > I have multiple Pythons locally installed so that I can test against > different versions. (On a 64-bit Debian stable system.) > > All of them use the system's Tcl/Tk installation. However, I want to > make some of them use a locally build Tcl/Tk that has a small > customization. > > There doesn't seem to be any --with-tk or --with-tcl options for > configure that would allow me to say where my local Tcl/Tk is. > > So I ran ./configure --prefix=/home/mark/opt/py32tkmod > > And then I tried editing Modules/Setup: I just uncommented and edited > the _tkinter line as follows: > > _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \ > -L/home/mark/opt/tcltk85/lib \ > -I/home/mark/opt/tcltk85/include \ > -I/usr/X11R6/include \ > -ltk8.5 -ltcl8.5 \ > -L/usr/X11R6/lib \ > -lX11 > > But when I run ~/opt/py32tkmod/bin/python3 tkinter-test.pyw the system > tk is being used not my customized one. AFAIK, on Unix-y systems Modules/Setup isn't normally used to configure the building of _tkinter anymore. The relevant code is in Python's setup.py. Search there for "_tkinter" and "detect_tkinter". You'll find a lot of platform-specific hacks but you should be able to substitute your own version of Tcl/Tk through the use of ./configure arguments, most likely by adding your Tcl/Tk directories to the INCLUDEDIR and LIBDIR variables; see the beginning of detect_modules() in setup.py. -- Ned Deily, nad at acm.org From irmen.NOSPAM at xs4all.nl Mon Jun 4 16:35:10 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Mon, 04 Jun 2012 22:35:10 +0200 Subject: ./configure In-Reply-To: References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> Message-ID: <4fcd1bff$0$6912$e4fe514c@news2.news.xs4all.nl> On 4-6-2012 0:01, Janet Heath wrote: > > Thanks Alain. I should have a compiler on my Mac OS X Lion. I am thinking that it > isn't set in my $PATH variable. I don't know where the $PATH is set at. I will > check to see if their is a binary. You'll have to have the Apple Developer tools (xcode) installed to get a c-compiler, but maybe that's the case on your mac already. (Weird though, it should add gcc -the compiler- to the PATH by itself, I don't recall having to change that myself.) In any case, there is a .dmg with a binary installer for Python 2.7.3 available for download at python.org [1] so there should not really be a need to compile it yourself. If you really do need to compile it yourself, consider using Homebrew [2] to install it, instead of downloading the source and compiling it manually. With homebrew it's a simple 'brew install python' and a few minutes later it's done. It will be lot easier to install 3rd party library dependencies this way too. Irmen. [1] http://python.org/download/releases/2.7.3/ [2] http://mxcl.github.com/homebrew/ From lee.joosang at gmail.com Mon Jun 4 21:21:20 2012 From: lee.joosang at gmail.com (FSH) Date: Mon, 4 Jun 2012 18:21:20 -0700 (PDT) Subject: file pointer array Message-ID: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> Hello, I have a simple question. I wish to generate an array of file pointers. For example, I have files: data1.txt data2.txt data3.txt .... I wish to generate fine pointer array so that I can read the files at the same time. for index in range(N): fid[index] = open('data%d.txt' % index,'r') I look forward to your advice for this problem. -FSH From ben+python at benfinney.id.au Mon Jun 4 21:38:18 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 05 Jun 2012 11:38:18 +1000 Subject: file pointer array References: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> Message-ID: <877gvm4jxx.fsf@benfinney.id.au> FSH writes: > I have a simple question. I wish to generate an array of file > pointers. Welcome to Python. By your description, I think you want a different type: not an array, but a list. I recommend you become familiar with Python's data model . > I wish to generate fine pointer array so that I can read the files at > the same time. I don't know about reading the files *at the same time*. If you mean you want to have multiple files open simultaneously and read from any of them arbitrarily, you don't need any particular container type; you just need to have references to those open file objects. Any references will do for that; you don't need pointers in Python. > for index in range(N): > fid[index] = open('data%d.txt' % index,'r') Python has iterable types built in, so you rarely need to maintain an index yourself. Further, Python has ?list comprehension?, allowing you to define a list in a single statement by describing how each element is created:: fid = [open('data%d.txt' % count, 'r') for count in range(N)] To learn about this and other useful topics, you should work through Python's tutorial from start to finish, doing each exercise until you understand the concept being explained. -- \ ?We have to go forth and crush every world view that doesn't | `\ believe in tolerance and free speech.? ?David Brin | _o__) | Ben Finney From clp2 at rebertia.com Mon Jun 4 21:43:59 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 4 Jun 2012 18:43:59 -0700 Subject: file pointer array In-Reply-To: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> References: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> Message-ID: On Mon, Jun 4, 2012 at 6:21 PM, FSH wrote: > Hello, > > I have a simple question. I wish to generate an array of file > pointers. For example, I have files: > > data1.txt > data2.txt > data3.txt > .... > > I wish to generate fine pointer array so that I can read the files at > the same time. > > for index in range(N): > ? ? fid[index] = open('data%d.txt' % index,'r') That loop will start at 0, not 1, so so you'll try to open "data0.txt". To rectify that, use range(1, N+1), though you'll then need to use a list comprehension like Ben Finney demonstrated. Cheers, Chris From steve+comp.lang.python at pearwood.info Tue Jun 5 00:46:03 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Jun 2012 04:46:03 GMT Subject: file pointer array References: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> Message-ID: <4fcd8f0b$0$11109$c3e8da3@news.astraweb.com> On Mon, 04 Jun 2012 18:21:20 -0700, FSH wrote: > Hello, > > I have a simple question. I wish to generate an array of file pointers. > For example, I have files: > > data1.txt > data2.txt > data3.txt > .... > > I wish to generate fine pointer array so that I can read the files at > the same time. > > for index in range(N): > fid[index] = open('data%d.txt' % index,'r') See the fileinput module: http://docs.python.org/library/fileinput.html If you prefer to manage it yourself, you can do something like this: fid = [open('data%d.txt' % index, 'r') for index in range(1, N+1)] # Process the files. for fp in fid: print fp.read() # Don't forget to close them when done. for fp in fid: fp.close() You can let the files be closed by the garbage collector, but there is no guarantee that this will happen in a timely manner. Best practice is to close them manually once you are done. -- Steven From mhrivnak at hrivnak.org Tue Jun 5 01:16:21 2012 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Tue, 5 Jun 2012 01:16:21 -0400 Subject: why i can't read sda1 with python? In-Reply-To: <20120604161453.111ce152.zhxia@njnet.edu.cn> References: <20120604161453.111ce152.zhxia@njnet.edu.cn> Message-ID: Which makes total sense. If any user could directly read the entire contents of the disk, filesystem permissions would be useless. Michael On Mon, Jun 4, 2012 at 4:14 AM, Xia wrote: > so only root or accounts in group disk can access /dev/sda1, From steve+comp.lang.python at pearwood.info Tue Jun 5 01:19:06 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Jun 2012 05:19:06 GMT Subject: How do I get the constructor signature for built-in types? Message-ID: <4fcd96ca$0$11109$c3e8da3@news.astraweb.com> The inspect.getargspec and getfullargspec functions allow you to extract the function call signature for Python functions and methods. This allows you to work out the constructor signature for pure-Python classes, by calling inspect.getargspec on the __init__ or __new__ method. >>> import inspect >>> class X: ... def __init__(self, a, b, *args): ... pass ... >>> inspect.getargspec(X.__init__) ArgSpec(args=['self', 'a', 'b'], varargs='args', keywords=None, defaults=None) So far so good. But if the __init__ method is inherited directly from a built-in, getargspec fails: >>> class Y(int): ... pass ... >>> inspect.getargspec(Y.__init__) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.2/inspect.py", line 794, in getargspec getfullargspec(func) File "/usr/local/lib/python3.2/inspect.py", line 821, in getfullargspec raise TypeError('{!r} is not a Python function'.format(func)) TypeError: is not a Python function How do I programmatically get the argument spec of built-in types' __init__ or __new__ methods? -- Steven From ian.g.kelly at gmail.com Tue Jun 5 03:39:51 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Jun 2012 01:39:51 -0600 Subject: How do I get the constructor signature for built-in types? In-Reply-To: <4fcd96ca$0$11109$c3e8da3@news.astraweb.com> References: <4fcd96ca$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Mon, Jun 4, 2012 at 11:19 PM, Steven D'Aprano wrote: > How do I programmatically get the argument spec of built-in types' > __init__ or __new__ methods? I don't think that you can. Methods implemented in C don't really even have established argument specs. They just take tuples and dicts and use the PyArg_Parse* family of functions to unpack them. So effectively, all built-in methods have the argspec (self, *args, **keywords) Cheers, Ian From animator333 at gmail.com Tue Jun 5 04:11:47 2012 From: animator333 at gmail.com (Prashant) Date: Tue, 5 Jun 2012 01:11:47 -0700 (PDT) Subject: stop thread from outside 'run' Message-ID: <32d598a6-c91c-4abe-a1a3-7503fcf0de79@googlegroups.com> Hi, I am using tornado web socket server to communicate between python(server) and browser(client). To mimic the behavior of sending data to client and get results back, I am using threaded approach: class JobThread(threading.Thread): """""" def __init__(self, target): """""" super(JobThread, self).__init__() self.target = target self.res = None self.stoprequest = threading.Event() self.start() self.join() # Execution stops here and wait return self.result() def run(self): """ Start this thread """ self.target() while not self.stoprequest.isSet(): print "running..." def result(self): """""" return self.res def kill(self, result): """ Kill this thread """ self.res = result self.stoprequest.set() def ReceiveData(message): """""" global t print str(message) t.kill(message) def SendData(data_string): """""" sendMessageWS(data_string) result = JobThread(partial(SendData, data_string)) As soon as jobThread instance starts it sends data to websocket and wait for client to response. Client is sending back results but 'ReceiveData' is not getting called because of infinite loop in 'run' method. The only way you can stop the thread is from outside when "ReceiveData" executes and kill the threaded instance 't'. Any pointers? From steve+comp.lang.python at pearwood.info Tue Jun 5 04:48:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Jun 2012 08:48:21 GMT Subject: Metaclass of a metaclass Message-ID: <4fcdc7d5$0$11109$c3e8da3@news.astraweb.com> I was playing around with metaclasses and I wondered what would happen if the metaclass itself had a metaclass. Sort of a metametaclass. Apparently it gives an error. Can anyone explain why this does not work? # Python 3.2 >>> class MyType(type): # A metaclass... ... def __repr__(self): ... s = super().__repr__() ... return s.replace('class', 'metaclass') ... >>> class Meta(metaclass=MyType): # ... of a metaclass. ... pass ... >>> Meta >>> >>> isinstance(Meta, type) True >>> >>> >>> class MyClass(metaclass=Meta): # And now try to use it. ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: object.__new__() takes no parameters What am I doing wrong? -- Steven From __peter__ at web.de Tue Jun 5 05:32:16 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 05 Jun 2012 11:32:16 +0200 Subject: Metaclass of a metaclass References: <4fcdc7d5$0$11109$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I was playing around with metaclasses and I wondered what would happen if > the metaclass itself had a metaclass. Sort of a metametaclass. > > Apparently it gives an error. Can anyone explain why this does not work? > > # Python 3.2 > > > >>>> class MyType(type): # A metaclass... > ... def __repr__(self): > ... s = super().__repr__() > ... return s.replace('class', 'metaclass') > ... >>>> class Meta(metaclass=MyType): # ... of a metaclass. > ... pass > ... >>>> Meta > >>>> >>>> isinstance(Meta, type) > True I think you want isinstance(Meta(), type), and this returns False. >>>> class MyClass(metaclass=Meta): # And now try to use it. > ... pass > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: object.__new__() takes no parameters > > > > What am I doing wrong? class A(metaclass=M): pass is equivalent to A = M(name, bases, classdict) and as the error message suggests B needs a compatible signature. From tjreedy at udel.edu Tue Jun 5 05:41:14 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 05 Jun 2012 05:41:14 -0400 Subject: How do I get the constructor signature for built-in types? In-Reply-To: <4fcd96ca$0$11109$c3e8da3@news.astraweb.com> References: <4fcd96ca$0$11109$c3e8da3@news.astraweb.com> Message-ID: On 6/5/2012 1:19 AM, Steven D'Aprano wrote: > The inspect.getargspec and getfullargspec functions allow you to extract > the function call signature for Python functions and methods. This allows > you to work out the constructor signature for pure-Python classes, by > calling inspect.getargspec on the __init__ or __new__ method. ... > So far so good. But if the __init__ method is inherited directly from a > built-in, getargspec fails: > How do I programmatically get the argument spec of built-in types' > __init__ or __new__ methods? Idle tooltips rely on doc strings for builtins. (And by the way, thanks for the example, as it might crash Idle even after my current patch. I will have to check. See http://bugs.python.org/issue12510 if interested.) -- Terry Jan Reedy From fetchinson at googlemail.com Tue Jun 5 05:41:34 2012 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 5 Jun 2012 11:41:34 +0200 Subject: Namespace hack In-Reply-To: References: <4fbdf673$0$11117$c3e8da3@news.astraweb.com> Message-ID: >> Funny, you got to the last line of "import this" but apparently >> skipped the second line: >> >> Explicit is better than implicit. >> >> And you didn't even post your message on April 1 so no, I can't laugh >> even though I'd like to. > > Can you be less condescending? Of course! :) Anyway, the point I was trying to make is that Steve's example is kinda cool but only as a funny exercise and not something for real life. Let's toy with python kinda thing, which is always welcome but with a big fat asterisk saying "don't try this at home kids". Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From therve at free.fr Tue Jun 5 06:26:05 2012 From: therve at free.fr (=?ISO-8859-1?Q?Thomas_Herv=E9?=) Date: Tue, 05 Jun 2012 12:26:05 +0200 Subject: Twisted 12.1.0 released Message-ID: <4FCDDEBD.2070503@free.fr> On behalf of Twisted Matrix Laboratories, I am pleased to announce the release of Twisted 12.1. 107 tickets are closed by this release, with the following highlights: * The revival of the kqueue reactor for BSD platforms. * epoll is now the default reactor under Linux after a fix to handle files on stdin/stdout. * New reactors supporting GTK3 and GObject-Introspection. * Several enhancements regarding file descriptors passing: systemd support for servers, ability to send and receive file descriptors for IReactorUNIX and an AMP argument using that feature. * Support for IPv6 literals in connectTCP. * Persistent connections support for the new HTTP client. This is the last Twisted release supporting Python 2.5. For more information, see the NEWS file here: http://twistedmatrix.com/Releases/Twisted/12.1/NEWS.txt Download it now from: http://pypi.python.org/packages/source/T/Twisted/Twisted-12.1.0.tar.bz2 or http://pypi.python.org/packages/2.5/T/Twisted/Twisted-12.1.0.win32-py2.5.msi or http://pypi.python.org/packages/2.6/T/Twisted/Twisted-12.1.0.win32-py2.6.msi or http://pypi.python.org/packages/2.7/T/Twisted/Twisted-12.1.0.win32-py2.7.msi Thanks to the supporters of Twisted via the Software Freedom Conservancy and to the many contributors for this release. -- Thomas From ian.g.kelly at gmail.com Tue Jun 5 06:39:49 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Jun 2012 04:39:49 -0600 Subject: Metaclass of a metaclass In-Reply-To: <4fcdc7d5$0$11109$c3e8da3@news.astraweb.com> References: <4fcdc7d5$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Tue, Jun 5, 2012 at 2:48 AM, Steven D'Aprano wrote: > I was playing around with metaclasses and I wondered what would happen if > the metaclass itself had a metaclass. Sort of a metametaclass. > > Apparently it gives an error. Can anyone explain why this does not work? In your example, Meta is not actually a metaclass, as it inherits from object, not type. Here's an example that works: >>> class MetaMeta(type): pass ... >>> class Meta(type, metaclass=MetaMeta): pass ... >>> class MyClass(metaclass=Meta): pass ... Anyway, metaclasses of metaclasses is not that unusual, as type is already its own metaclass. Cheers, Ian From janetcatherine.heath at gmail.com Tue Jun 5 08:46:49 2012 From: janetcatherine.heath at gmail.com (Janet Heath) Date: Tue, 5 Jun 2012 05:46:49 -0700 (PDT) Subject: ./configure References: <65b2615a-533b-4c19-8814-b6d956c60c48@googlegroups.com> <4fcc01ed$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jun 3, 10:01?pm, Janet Heath wrote: > On Jun 3, 6:31?pm, Steven D'Aprano > > > > > > > > > +comp.lang.pyt... at pearwood.info> wrote: > > On Sun, 03 Jun 2012 15:01:07 -0700, Janet Heath wrote: > > > Thanks Alain. ?I should have a compiler on my Mac OS X Lion. ?I am > > > thinking that it isn't set in my $PATH variable. ?I don't know where the > > > $PATH is set at. ?I will check to see if their is a binary. > > > At the command line, run: > > > echo $PATH > > > to see the path. > > > I'm not sure where OS X sets the PATH, but Linux systems normally set > > them in /etc/profile. User-customisations should go in a shell rc file, > > e.g. if you are using bash, edit ~/.bashrc. > > > To add additional paths to the PATH: > > > export $PATH=$PATH:/some/directory:/another/directory > > > To replace the system path completely: > > > export $PATH=/some/directory:/another/directory > > > -- > > Steven > > Thanks Steven! Thanks Irmen! From halnator at gardeniatelco.com Tue Jun 5 09:54:54 2012 From: halnator at gardeniatelco.com (hassan) Date: Tue, 5 Jun 2012 06:54:54 -0700 (PDT) Subject: fputs Message-ID: Dear ALL , what is the equivalent to the php fputs in python regards, From markrrivet at aol.com Tue Jun 5 10:10:17 2012 From: markrrivet at aol.com (Mark R Rivet) Date: Tue, 05 Jun 2012 10:10:17 -0400 Subject: what gui designer is everyone using Message-ID: I want a gui designer that writes the gui code for me. I don't want to write gui code. what is the gui designer that is most popular? I tried boa-constructor, and it works, but I am concerned about how dated it seems to be with no updates in over six years. From vincent.vandevyvre at swing.be Tue Jun 5 10:47:22 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Tue, 05 Jun 2012 16:47:22 +0200 Subject: what gui designer is everyone using In-Reply-To: References: Message-ID: <4FCE1BFA.1000203@swing.be> On 05/06/12 16:10, Mark R Rivet wrote: > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. Try Qt http://qt-project.org/doc/qt-4.8/designer-manual.html -- Vincent V.V. Oqapy . Qarte+7 . PaQager From matteo.boscolo at boscolini.eu Tue Jun 5 10:53:24 2012 From: matteo.boscolo at boscolini.eu (matteo.boscolo at boscolini.eu) Date: Tue, 5 Jun 2012 16:53:24 +0200 Subject: what gui designer is everyone using In-Reply-To: References: Message-ID: you have the qt designer with eric is nice and easy to use for the qt .. Da: python-list-bounces+matteo.boscolo=boscolini.eu at python.org A: python-list at python.org Cc: Data: Tue, 05 Jun 2012 10:10:17 -0400 Oggetto: what gui designer is everyone using > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdsteph at mac.com Tue Jun 5 10:57:21 2012 From: rdsteph at mac.com (rdsteph at mac.com) Date: Tue, 5 Jun 2012 07:57:21 -0700 (PDT) Subject: what gui designer is everyone using References: Message-ID: <2dd2e82d-c64a-4e07-b60f-9afac55f0ae6@f8g2000pbf.googlegroups.com> On Jun 5, 7:10?am, Mark R Rivet wrote: > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. No one size fits all, and many Pythonistas prefer to write GUI code by hand anyway. However, I like PythonCard. Try it, you might like it. From bex.lewis at gmail.com Tue Jun 5 11:01:40 2012 From: bex.lewis at gmail.com (becky_lewis) Date: Tue, 5 Jun 2012 08:01:40 -0700 (PDT) Subject: what gui designer is everyone using References: Message-ID: <50b5d38b-6535-4e5b-80e0-89065ec6d556@w24g2000vby.googlegroups.com> I'm afraid that in my experience, doing things by hand has always ended up being quicker and simpler than relying on a GUI designer when it comes to building python GUI apps. That said, I've not tried any for the past few years so there may be a killer app out there that I've not tried :) But even then, it's likely that you'll still have to get your hands dirty in the code at some point. Also, it would help a little if you'd state which toolkit you were using (I'm assuming wxPython since you mention boa-constructor). On Jun 5, 3:10?pm, Mark R Rivet wrote: > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. From parkerdg at gmail.com Tue Jun 5 11:12:45 2012 From: parkerdg at gmail.com (parkerdg at gmail.com) Date: Tue, 5 Jun 2012 08:12:45 -0700 (PDT) Subject: what gui designer is everyone using In-Reply-To: References: Message-ID: On Tuesday, June 5, 2012 10:10:17 AM UTC-4, Manatee wrote: > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. On Tuesday, June 5, 2012 10:10:17 AM UTC-4, Manatee wrote: > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. On Tuesday, June 5, 2012 10:10:17 AM UTC-4, Manatee wrote: > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. I've used XRCed with wxpython in the past. XRCed is bundled with the wxPython installation. It was very easy to layout the GUI objects and setup the generic event bindings. Recently I've been playing around with using PyQt and QtDesigner because I keep seeing it highly recommened. The capabilities and process seem very similar to using XRCed to me. These are simply GUI designers not IDE's. The basic process for using both is: * Layout the GUI objects, define generic event bindings (wx) or signals/slots (Qt). * Save the GUI layout XML. * Auto-generate a generic Python module that defines the GUI object based on the XML. * Import the and inherit from the generic Python GUI. Override the GUI class and methods as needed. * Write a script or a main function that instantiates the GUI and starts the event loop. I'm biased toward wxPython and XRCed mostly because I've had more experience with it and the documentation seems easier to follow. From bruno.desthuilliers at gmail.com Tue Jun 5 11:30:57 2012 From: bruno.desthuilliers at gmail.com (bruno.desthuilliers at gmail.com) Date: Tue, 5 Jun 2012 08:30:57 -0700 (PDT) Subject: Metaclass of a metaclass References: <4fcdc7d5$0$11109$c3e8da3@news.astraweb.com> Message-ID: On Jun 5, 10:48?am, Steven D'Aprano wrote: > Apparently it gives an error. Can anyone explain why this does not work? > > # Python 3.2 > > >>> class MyType(type): ?# A metaclass... > > ... ? ? def __repr__(self): > ... ? ? ? ? ? ? s = super().__repr__() > ... ? ? ? ? ? ? return s.replace('class', 'metaclass') > > >>> class Meta(metaclass=MyType): ?# ... of a metaclass. > > ... ? ? pass (...) > >>> class MyClass(metaclass=Meta): ?# And now try to use it. > > ... ? ? pass > ... > Traceback (most recent call last): > ? File "", line 1, in > TypeError: object.__new__() takes no parameters > > What am I doing wrong? Meta inherit from object, but being used as a metaclass, Meta.__new__ is called with name, bases, dict etc as arguments. From ulrich.eckhardt at dominolaser.com Tue Jun 5 11:38:51 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 05 Jun 2012 17:38:51 +0200 Subject: fputs In-Reply-To: References: Message-ID: Am 05.06.2012 15:54, schrieb hassan: > what is the equivalent to the php fputs in python If that fputs() is the same as C's fputs(), then write() is pretty similar. Check the documentation for files, you will surely find the equivalent. Uli From jugurtha.hadjar at gmail.com Tue Jun 5 11:43:02 2012 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Tue, 05 Jun 2012 16:43:02 +0100 Subject: fputs In-Reply-To: References: Message-ID: <4FCE2906.6020507@gmail.com> On 06/05/2012 02:54 PM, hassan wrote: > Dear ALL , > > what is the equivalent to the php fputs in python > > > regards, Hello, Have you tried something like this (I'll be passing the filename as an argument): from sys import argv script, dest_file = argv data_to_write = raw_input() output = open(dest_file, 'w') output.write(data_to_write) You can execute it this way: python e.g: python script.py data.txt -- ~Jugurtha Hadjar, From patentsvnc at gmail.com Tue Jun 5 12:05:49 2012 From: patentsvnc at gmail.com (Den) Date: Tue, 5 Jun 2012 09:05:49 -0700 (PDT) Subject: what gui designer is everyone using References: Message-ID: <4dc217ca-108a-4022-939b-a1ba6b9db31c@ra8g2000pbc.googlegroups.com> On Jun 5, 7:10?am, Mark R Rivet wrote: > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. I use wxFormBuilder. It seems to be most up-to-date and is as easy to use as any others. It also covers AUI GUIs. It produces the class, but you have to do a little bit of programming to actually see the GUI. I used wx-glade for a while. It was easy to use, and produced ready- to-run GUIs. But it's old and not well kept up. There's some new work being done on it but it seems to be mostly housekeeping work - how to best package it, etc. Den From rhodri at wildebst.demon.co.uk Tue Jun 5 12:20:24 2012 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 05 Jun 2012 17:20:24 +0100 Subject: fputs References: Message-ID: On Tue, 05 Jun 2012 14:54:54 +0100, hassan wrote: > what is the equivalent to the php fputs in python The write() method of the file object. Though if you're asking the question like that, you need to read this: http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files ...and stop trying to think in terms of PHP. While you can write PHP in any language (I know people who still write FORTRAN, whatever language they might be using), you'll find that getting into the right mindset for whatever language you are using works a lot better. -- Rhodri James *-* Wildebeest Herder to the Masses From deepak.tekwissen at gmail.com Tue Jun 5 12:44:18 2012 From: deepak.tekwissen at gmail.com (deepak tekwissen) Date: Tue, 5 Jun 2012 09:44:18 -0700 (PDT) Subject: Available candidate for Oracle DBA Message-ID: Hi, Hope you are doing good,, Skill Set Current-location Relocation Availability oracal DBA tennessee yes immediately As per your requirement for Oracle DBA position, I?m forwarding you one of my consultant?s resume. Please find the attachment and revert back to me. Let me know who is the client and whether he is your direct client or not? Have a great day ahead? From python at mrabarnett.plus.com Tue Jun 5 12:59:34 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 05 Jun 2012 17:59:34 +0100 Subject: stop thread from outside 'run' In-Reply-To: <32d598a6-c91c-4abe-a1a3-7503fcf0de79@googlegroups.com> References: <32d598a6-c91c-4abe-a1a3-7503fcf0de79@googlegroups.com> Message-ID: <4FCE3AF6.1030303@mrabarnett.plus.com> On 05/06/2012 09:11, Prashant wrote: > Hi, > > I am using tornado web socket server to communicate between python(server) and browser(client). To mimic the behavior of sending data to client and get results back, I am using threaded approach: > > class JobThread(threading.Thread): > """""" > def __init__(self, target): > """""" > super(JobThread, self).__init__() > self.target = target > self.res = None > self.stoprequest = threading.Event() > self.start() > self.join() > # Execution stops here and wait > return self.result() > > def run(self): > """ Start this thread """ > self.target() > while not self.stoprequest.isSet(): > print "running..." > > def result(self): > """""" > return self.res > > def kill(self, result): > """ Kill this thread """ > self.res = result > self.stoprequest.set() > > def ReceiveData(message): > """""" > global t > print str(message) > t.kill(message) > > def SendData(data_string): > """""" > sendMessageWS(data_string) > > result = JobThread(partial(SendData, data_string)) > JobThread is a class, so a statement of the form: result = JobThread(...) will simply create an instance of the JobThread class and then bind it to the name "result". The __init__ method is called to initialise the instance; any value returned the method will be discarded. > As soon as jobThread instance starts it sends data to websocket and wait for client to response. Client is sending back results but 'ReceiveData' is not getting called because of infinite loop in 'run' method. The only way you can stop the thread is from outside when "ReceiveData" executes and kill the threaded instance 't'. > > Any pointers? From laurent.pointal at free.fr Tue Jun 5 13:32:42 2012 From: laurent.pointal at free.fr (Laurent Pointal) Date: Tue, 05 Jun 2012 19:32:42 +0200 Subject: English version for =?UTF-8?B?TcOpbWVudG8=?= Python 3 (draft, readers needed) Message-ID: <4fce42ba$0$2028$426a74cc@news.free.fr> Hello, I started a first translation of my document originally in french. Could some fluent english people read it and indicate errors or bad english expressions. http://perso.limsi.fr/pointal/python:memento Thanks. A+ Laurent. -- Laurent POINTAL - laurent.pointal at laposte.net From davidgshi at yahoo.co.uk Tue Jun 5 13:41:17 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Tue, 5 Jun 2012 18:41:17 +0100 (BST) Subject: Has theHas Python community got Alan Saalfeld et al's algorithm and source code implementation Message-ID: <1338918077.14580.YahooMailNeo@web171604.mail.ir2.yahoo.com> Dear Python community friends, I wonder whether there is such a Python implementation available. Alan Saalfeld et al's algorithm and source codes. http://books.google.ie/books/about/A_Modified_Douglas_Peucker_Simplificatio.html?id=gbQjywAACAAJ&redir_esc=y In Zhiyuan Zhao and Alan Saafeld's paper, LINEAR-TIME SLEEVE-FITTING POLYLINE SIMPLIFICATION ALGORITHMS Zhiyuan Zhao, Alan Saalfeld They mentioned " The results of those experiments and more information on the algorithms themselves, including complete working code, are available to the interested reader at the World Wide Web site http://ra.cfm.ohio-state.edu/grad/zhao/algorithms/linesimp.html." However, this site is no longer alive. If anyone knows, please let me know.?? davidgshi at yahoo.co.uk Regards. David -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Tue Jun 5 14:01:43 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 05 Jun 2012 11:01:43 -0700 Subject: English version for =?utf-8?Q?M=C3=A9mento?= Python 3 (draft, readers needed) References: <4fce42ba$0$2028$426a74cc@news.free.fr> Message-ID: <7x62b54ozc.fsf@ruckus.brouhaha.com> Laurent Pointal writes: > I started a first translation of my document originally in french. Could > some fluent english people read it and indicate errors or bad english > expressions. > > http://perso.limsi.fr/pointal/python:memento It looks nice. It took me a minute to find the English version: http://perso.limsi.fr/pointal/_media/python:cours:mementopython3-english.pdf A few minor things: 1) We would usually call this a "reference card" rather than "memento" 2) In the dictionary example, {"cl?":"valeur"} => {"key":"value"} {1:"un",3:"trois",2:"deux",3.14:""} => {1:"one", etc. } 3) "bloc" in a few places should be "block" 4) On side 2, the part about writing files is still mostly in French There are a few other things like that, and I'll try to look more carefully tonight, I can't spend more time on it right now. Thanks for writing it and sharing it. --Paul From asadb14 at msn.com Tue Jun 5 14:18:28 2012 From: asadb14 at msn.com (o2kcompliant) Date: Tue, 05 Jun 2012 18:18:28 -0000 Subject: Need a Python Developer in Mountain View,CA Message-ID: Hi Guys, I have a need for a Python Developer in Mountain View,CA. Here are the requirements: Solid foundation in computer science with strong competencies in data structures, algorithms and software design with proficiency in object-oriented design principles and extensive experience in Python Java, Ruby, Perl, Groovy or Objective-C. . 2+ yrs professional MySQL experience. . Ability to work end-to-end on all aspects of MVC including UI work. . Experience with Flask, Jinja, Bootstrap, or Solr a plus. . Comfortable with agile dev cycle - we are using advanced scrum methods. . Broad Internet understanding: TCP/IP programming, basics of how HTTP and other major Internet protocols really work. . Experience with web application servers (Tomcat, Jetty, WebLogic, etc) and build and scm systems (ant, gradle, gmake, svn, git, perforce, etc.) Please feel free to contact me if you are interested or have any questions. Thanks! Asad Bawa | Account Executive E: asad at midcom.com M: 714.642.3437 | D : 714.507.3717 | Tel: 800.737.1632 ext. 3717| F: 714.459.7055 MIDCOM Corporation 3995 E. La Palma Ave., Anaheim, CA 92807 From python at mrabarnett.plus.com Tue Jun 5 14:56:12 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 05 Jun 2012 19:56:12 +0100 Subject: English version for =?UTF-8?B?TcOpbWVudG8gUHl0aG9uIDMgKGRyYWY=?= =?UTF-8?B?dCwgcmVhZGVycyBuZWVkZWQp?= In-Reply-To: <4fce42ba$0$2028$426a74cc@news.free.fr> References: <4fce42ba$0$2028$426a74cc@news.free.fr> Message-ID: <4FCE564C.7020008@mrabarnett.plus.com> On 05/06/2012 18:32, Laurent Pointal wrote: > Hello, > > I started a first translation of my document originally in french. Could > some fluent english people read it and indicate errors or bad english > expressions. > > http://perso.limsi.fr/pointal/python:memento > In addition to what Paul wrote: "mot" => "word" min/MAJ case discrimination => case-sensitive Identifiers no longer restricted to ASCII range. Even ? is permitted. litteral => literal see verso => see reverse logial => logical Indexation des s?quences => Indexing of sequences exemple => example nombres flottants => floating-point numbers valeurs approch?es => (not sure) Op?rators => Operators remain => remainder care to inifinite loops => beware of infinite loops (possibly) cpt => cnt (possibly) "trouv?" => "found" modif => ? litt?ral => literal always return => always returns recto => obverse ("obverse" is the "correct" word, although "front" might be clearer for those who don't know what "obverse" means!) reversed copy => reverse iterator (note that it's an _iterator_) d?fault => default parametrs => parameters "coucou" => "cuckoo" fichier texte ? lecture / ?criture de cha?nes uniquement, convertir de/vers le type d?sir? => text file ? reads/writes strings (?) ne pas oublier de refermer le fichier apr?s son utilisation => don't forget to close the file after use tr?s courant : boucle it?rative de lecture des lignes d'un fichier texte => very common : iterative loop reading lines from a text file ligne => line bloc traitement de la ligne => block processing line directives de formatage => format directives valeurs ? formater => Values to format Param?tre de conversion => Conversion parameter cha?ne d'affichage => display string cha?ne de repr?sentation => string representation (or "representation string"?) apparition order by default => in order of appearance by default (?) espace => space ou => or flot => float pourcent => percent From hoogendoorn.eelco at gmail.com Tue Jun 5 15:50:19 2012 From: hoogendoorn.eelco at gmail.com (Eelco) Date: Tue, 5 Jun 2012 12:50:19 -0700 (PDT) Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> <87wr3n2mgg.fsf@dpt-info.u-strasbg.fr> Message-ID: <962e2dce-75e2-4c1b-a5a3-6b5255a0b6d1@z19g2000vbe.googlegroups.com> > thank you both for your replies. Unfortunately it is a pre-existing > file format imposed by an external system that I can't > change. Thank you for the code snippet. Hi Richard, Despite the fact that it is a preexisting format, it is very close indeed to valid YAML code. Writing your own whitespace-aware parser can be a bit of a pain, but since YAML does this for you, I would argue the cleanest solution would be to bootstrap that functionality, rather than roll your own solution, or to resort to hard to maintain regex voodoo. Here is my solution. As a bonus, it directly constructs a custom object hierarchy (obviously you would want to expand on this, but the essentials are there). One caveat: at the moment, the conversion to YAML relies on the appparent convention that instances never directly contain other instances, and lists never directly contain lists. This means all instances are list entries and get a '-' appended, and this just works. If this is not a general rule, youd have to keep track of an enclosing scope stack an emit dashes based on that. Anyway, the idea is there, and I believe it to be one worth looking at. import yaml class A(yaml.YAMLObject): yaml_tag = u'!A' def __init__(self, **kwargs): self.__dict__.update(kwargs) def __repr__(self): return 'A' + str(self.__dict__) class B(yaml.YAMLObject): yaml_tag = u'!B' def __init__(self, **kwargs): self.__dict__.update(kwargs) def __repr__(self): return 'B' + str(self.__dict__) class C(yaml.YAMLObject): yaml_tag = u'!C' def __init__(self, **kwargs): self.__dict__.update(kwargs) def __repr__(self): return 'C' + str(self.__dict__) class TestArray(yaml.YAMLObject): yaml_tag = u'!TestArray' def __init__(self, **kwargs): self.__dict__.update(kwargs) def __repr__(self): return 'TestArray' + str(self.__dict__) class myList(yaml.YAMLObject): yaml_tag = u'!myList' def __init__(self, **kwargs): self.__dict__.update(kwargs) def __repr__(self): return 'myList' + str(self.__dict__) data = \ """ An instance of TestArray a=a b=b c=c List of 2 A elements: Instance of A element a=1 b=2 c=3 Instance of A element d=1 e=2 f=3 List of 1 B elements Instance of B element a=1 b=2 c=3 List of 2 C elements Instance of C element a=1 b=2 c=3 Instance of C element a=1 b=2 c=3 An instance of TestArray a=1 b=2 c=3 """.strip() #remove trailing whitespace and seemingly erronous colon in line 5 lines = [' '+line.rstrip().rstrip(':') for line in data.split('\n')] def transform(lines): """transform text line by line""" for line in lines: #regular mapping lines if line.find('=') > 0: yield line.replace('=', ': ') #instance lines p = line.find('nstance of') if p > 0: s = p + 11 e = line[s:].find(' ') if e == -1: e = len(line[s:]) tag = line[s:s+e] whitespace= line.partition(line.lstrip())[0] yield whitespace[:-2]+' -'+ ' !'+tag #list lines p = line.find('List of') if p > 0: whitespace= line.partition(line.lstrip())[0] yield whitespace[:-2]+' '+ 'myList:' ##transformed = (transform( lines)) ##for i,t in enumerate(transformed): ## print '{:>3}{}'.format(i,t) transformed = '\n'.join(transform( lines)) print transformed res = yaml.load(transformed) print res print yaml.dump(res) From pullenjenna10 at gmail.com Tue Jun 5 15:57:44 2012 From: pullenjenna10 at gmail.com (richard) Date: Tue, 5 Jun 2012 12:57:44 -0700 (PDT) Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> <87wr3n2mgg.fsf@dpt-info.u-strasbg.fr> Message-ID: <0e140ef5-909b-4590-ae52-432e3e6a04ef@f30g2000vbz.googlegroups.com> On Jun 4, 3:20?pm, richard wrote: > On Jun 4, 3:14?pm, Alain Ketterlin > wrote: > > > > > > > > > > > richard writes: > > > Hi guys i am having a bit of dificulty finding the best approach / > > > solution to parsing a file into a list of objects / nested objects any > > > help would be greatly appreciated. > > > > #file format to parse .txt > > > [code] > > > An instance of TestArray > > > ?a=a > > > ?b=b > > > ?c=c > > > ?List of 2 A elements: > > > ? Instance of A element > > > [...] > > > Below is a piece of code that seems to work on your data. It builds a > > raw tree, i leave it to you to adapt and built the objects you want. The > > assumption is that the number of leading blanks faithfully denotes > > depth. > > > As noted in another message, you're probably better off using an > > existing syntax (json, python literals, yaml, xml, ...) > > > -- Alain. > > > #!/usr/bin/env python > > > import sys > > import re > > > RE = re.compile("( *)(.*)") > > stack = [("-",[])] # tree nodes are: (head,[children]) > > for line in sys.stdin: > > ? ? matches = RE.match(line) > > ? ? if len(matches.group(2)) > 0: > > ? ? ? ? depth = 1 + len(matches.group(1)) > > ? ? ? ? while len(stack) > depth: > > ? ? ? ? ? ? stack[-2][1].append(stack[-1]) > > ? ? ? ? ? ? del stack[-1] > > ? ? ? ? ? ? pass > > ? ? ? ? stack.append( (matches.group(2),[]) ) > > ? ? ? ? pass > > ? ? pass > > while len(stack) > 1: > > ? ? stack[-2][1].append(stack[-1]) > > ? ? del stack[-1] > > ? ? pass > > > print(stack) > > thank you both for your replies. Unfortunately it is a pre-existing > file format imposed by an external system that I can't > change. Thank you for the code snippet. Hi guys still struggling to get the code that was posted to me on this forum to work in my favour and get the output in the format shown above. This is what I have so far. Any help will be greatly apprectiated. output trying to achieve parsed = [ { "a":"a", "b":"b", "c":"c", "A_elements":[ { "a":1, "b":2, "c":3 }, { "a":1, "b":2, "c":3 } ], "B_elements":[ { "a":1, "b":2, "c":3, "C_elements":[ { "a":1, "b":2, "c":3 }, { "a":1, "b":2, "c":3 } ] } ] }, { "a":"1", "b":"2", "c":"3", } ] file format unchangeable An instance of TestArray a=a b=b c=c List of 2 A elements: Instance of A element a=1 b=2 c=3 Instance of A element d=1 e=2 f=3 List of 1 B elements Instance of B element a=1 b=2 c=3 List of 2 C elements Instance of C element a=1 b=2 c=3 Instance of C element a=1 b=2 c=3 An instance of TestArray a=1 b=2 c=3 def test_parser(filename): class Stanza: def __init__(self, values): for attr, val in values: setattr(self, attr, val) def build(couple): if "=" in couple[0]: attr, val = couple[0].split("=") return attr,val elif "Instance of" in couple[0]: match = re.search("Instance of (.+) element", couple[0]) return ("attr_%s" % match.group(1),Stanza(couple[1])) elif "List of" in couple[0]: match = re.search("List of \d (.+) elements", couple[0]) return ("%s_elements" % match.group(1),couple[1]) fo = open(filename, "r") RE = re.compile("( *)(.*)") stack = [("-",[])] for line in fo: matches = RE.match(line) if len(matches.group(2)) > 0: depth = 1 + len(matches.group(1)) while len(stack) > depth: stack[-2][1].append(build(stack[-1])) del stack[-1] stack.append( (matches.group(2),[]) ) while len(stack) > 1: stack[-2][1].append(stack[-1]) del stack[-1] return stack stanzas = test_parser("test.txt") From petite.abeille at gmail.com Tue Jun 5 16:01:24 2012 From: petite.abeille at gmail.com (Petite Abeille) Date: Tue, 5 Jun 2012 22:01:24 +0200 Subject: =?iso-8859-1?Q?Re=3A_English_version_for_M=E9mento_Python_3_=28d?= =?iso-8859-1?Q?raft=2C_readers_needed=29?= In-Reply-To: <4FCE564C.7020008@mrabarnett.plus.com> References: <4fce42ba$0$2028$426a74cc@news.free.fr> <4FCE564C.7020008@mrabarnett.plus.com> Message-ID: <72D3A44A-9E44-4A3E-8541-E93EC36D338E@gmail.com> On Jun 5, 2012, at 8:56 PM, MRAB wrote: > valeurs approch?es => (not sure) Approximation? From laurent.pointal at free.fr Tue Jun 5 16:04:44 2012 From: laurent.pointal at free.fr (Laurent Pointal) Date: Tue, 05 Jun 2012 22:04:44 +0200 Subject: English version for =?UTF-8?B?TcOpbWVudG8=?= Python 3 (draft, readers needed) References: <4fce42ba$0$2028$426a74cc@news.free.fr> <7x62b54ozc.fsf@ruckus.brouhaha.com> Message-ID: <4fce665c$0$15486$426a74cc@news.free.fr> Paul Rubin wrote: > Laurent Pointal writes: >> I started a first translation of my document originally in french. Could >> some fluent english people read it and indicate errors or bad english >> expressions. >> >> http://perso.limsi.fr/pointal/python:memento > > It looks nice. It took me a minute to find the English version: > > http://perso.limsi.fr/pointal/_media/python:cours:mementopython3- english.pdf > > A few minor things: > > 1) We would usually call this a "reference card" rather than "memento" > > 2) In the dictionary example, > {"cl?":"valeur"} => {"key":"value"} > {1:"un",3:"trois",2:"deux",3.14:""} => {1:"one", etc. } > > 3) "bloc" in a few places should be "block" > > 4) On side 2, the part about writing files is still mostly in French > > There are a few other things like that, and I'll try to look more > carefully tonight, I can't spend more time on it right now. > > Thanks for writing it and sharing it. > > --Paul Thanks, I updated the document into 1.0.5a (and fix some other errors). A+ Laurent. -- Laurent POINTAL - laurent.pointal at laposte.net From pullenjenna10 at gmail.com Tue Jun 5 16:18:13 2012 From: pullenjenna10 at gmail.com (richard) Date: Tue, 5 Jun 2012 13:18:13 -0700 (PDT) Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> <87wr3n2mgg.fsf@dpt-info.u-strasbg.fr> <962e2dce-75e2-4c1b-a5a3-6b5255a0b6d1@z19g2000vbe.googlegroups.com> Message-ID: <834db2f0-e7db-4bdf-b3aa-bed678489122@b26g2000vbt.googlegroups.com> On Jun 5, 8:50?pm, Eelco wrote: > > thank you both for your replies. Unfortunately it is a pre-existing > > file format imposed by an external system that I can't > > change. Thank you for the code snippet. > > Hi Richard, > > Despite the fact that it is a preexisting format, it is very close > indeed to valid YAML code. > > Writing your own whitespace-aware parser can be a bit of a pain, but > since YAML does this for you, I would argue the cleanest solution > would be to bootstrap that functionality, rather than roll your own > solution, or to resort to hard to maintain regex voodoo. > > Here is my solution. As a bonus, it directly constructs a custom > object hierarchy (obviously you would want to expand on this, but the > essentials are there). One caveat: at the moment, the conversion to > YAML relies on the appparent convention that instances never directly > contain other instances, and lists never directly contain lists. This > means all instances are list entries and get a '-' appended, and this > just works. If this is not a general rule, youd have to keep track of > an enclosing scope stack an emit dashes based on that. Anyway, the > idea is there, and I believe it to be one worth looking at. > > > import yaml > > class A(yaml.YAMLObject): > ? ? yaml_tag = u'!A' > ? ? def __init__(self, **kwargs): > ? ? ? ? self.__dict__.update(kwargs) > ? ? def __repr__(self): > ? ? ? ? return 'A' + str(self.__dict__) > > class B(yaml.YAMLObject): > ? ? yaml_tag = u'!B' > ? ? def __init__(self, **kwargs): > ? ? ? ? self.__dict__.update(kwargs) > ? ? def __repr__(self): > ? ? ? ? return 'B' + str(self.__dict__) > > class C(yaml.YAMLObject): > ? ? yaml_tag = u'!C' > ? ? def __init__(self, **kwargs): > ? ? ? ? self.__dict__.update(kwargs) > ? ? def __repr__(self): > ? ? ? ? return 'C' + str(self.__dict__) > > class TestArray(yaml.YAMLObject): > ? ? yaml_tag = u'!TestArray' > ? ? def __init__(self, **kwargs): > ? ? ? ? self.__dict__.update(kwargs) > ? ? def __repr__(self): > ? ? ? ? return 'TestArray' + str(self.__dict__) > > class myList(yaml.YAMLObject): > ? ? yaml_tag = u'!myList' > ? ? def __init__(self, **kwargs): > ? ? ? ? self.__dict__.update(kwargs) > ? ? def __repr__(self): > ? ? ? ? return 'myList' + str(self.__dict__) > > data = \ > """ > An instance of TestArray > ?a=a > ?b=b > ?c=c > ?List of 2 A elements: > ? Instance of A element > ? ?a=1 > ? ?b=2 > ? ?c=3 > ? Instance of A element > ? ?d=1 > ? ?e=2 > ? ?f=3 > ?List of 1 B elements > ? Instance of B element > ? ?a=1 > ? ?b=2 > ? ?c=3 > ? ?List of 2 C elements > ? ? Instance of C element > ? ? ?a=1 > ? ? ?b=2 > ? ? ?c=3 > ? ? Instance of C element > ? ? ?a=1 > ? ? ?b=2 > ? ? ?c=3 > An instance of TestArray > ?a=1 > ?b=2 > ?c=3 > """.strip() > > #remove trailing whitespace and seemingly erronous colon in line 5 > lines = [' ?'+line.rstrip().rstrip(':') for line in data.split('\n')] > > def transform(lines): > ? ? """transform text line by line""" > ? ? for line in lines: > ? ? ? ? #regular mapping lines > ? ? ? ? if line.find('=') > 0: > ? ? ? ? ? ? yield line.replace('=', ': ') > ? ? ? ? #instance lines > ? ? ? ? p = line.find('nstance of') > ? ? ? ? if p > 0: > ? ? ? ? ? ? s = p + 11 > ? ? ? ? ? ? e = line[s:].find(' ') > ? ? ? ? ? ? if e == -1: e = len(line[s:]) > ? ? ? ? ? ? tag = line[s:s+e] > ? ? ? ? ? ? whitespace= line.partition(line.lstrip())[0] > ? ? ? ? ? ? yield whitespace[:-2]+' -'+ ' !'+tag > ? ? ? ? #list lines > ? ? ? ? p = line.find('List of') > ? ? ? ? if p > 0: > ? ? ? ? ? ? whitespace= line.partition(line.lstrip())[0] > ? ? ? ? ? ? yield whitespace[:-2]+' ?'+ 'myList:' > > ##transformed = (transform( lines)) > ##for i,t in enumerate(transformed): > ## ? ?print '{:>3}{}'.format(i,t) > > transformed = '\n'.join(transform( lines)) > print transformed > > res = yaml.load(transformed) > print res > print yaml.dump(res) > Hi Eelco many thanks for the reply / solution it definitely looks like a clean way to go about it. However installing 3rd party libs like yaml on the server I dont think is on the cards at the moment. From mhagbeng at enib.fr Tue Jun 5 16:31:56 2012 From: mhagbeng at enib.fr (mhagbeng) Date: Tue, 05 Jun 2012 22:31:56 +0200 Subject: Your confirmation is required to leave the Python-list mailing list In-Reply-To: References: Message-ID: Le 05.06.2012 22:29, python-list-confirm+0ddf652b9a76d520bd9945a702f68cbf7a1d2cf0 at python.org a ?crit?: > Mailing list removal confirmation notice for mailing list Python-list > > We have received a request for the removal of your email address, > "mhagbeng at enib.fr" from the python-list at python.org mailing list. To > confirm that you want to be removed from this mailing list, simply > reply to this message, keeping the Subject: header intact. Or visit > this web page: > > > > http://mail.python.org/mailman/confirm/python-list/0ddf652b9a76d520bd9945a702f68cbf7a1d2cf0 > > > Or include the following line -- and only the following line -- in a > message to python-list-request at python.org: > > confirm 0ddf652b9a76d520bd9945a702f68cbf7a1d2cf0 > > Note that simply sending a `reply' to this message should work from > most mail readers, since that usually leaves the Subject: line in the > right form (additional "Re:" text in the Subject: is okay). > > If you do not wish to be removed from this list, please simply > disregard this message. If you think you are being maliciously > removed from the list, or have any other questions, send them to > python-list-owner at python.org. From alain at dpt-info.u-strasbg.fr Tue Jun 5 16:40:31 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 05 Jun 2012 22:40:31 +0200 Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> <87wr3n2mgg.fsf@dpt-info.u-strasbg.fr> <0e140ef5-909b-4590-ae52-432e3e6a04ef@f30g2000vbz.googlegroups.com> Message-ID: <87haup3328.fsf@dpt-info.u-strasbg.fr> richard writes: [I'm leaving the data in the message in case anybody has troubles going up-thread.] > Hi guys still struggling to get the code that was posted to me on this > forum to work in my favour and get the output in the format shown > above. This is what I have so far. Any help will be greatly > apprectiated. > > output trying to achieve > parsed = [ > { > "a":"a", > "b":"b", > "c":"c", > "A_elements":[ > { > "a":1, > "b":2, > "c":3 > }, > { > "a":1, > "b":2, > "c":3 > } > ], > "B_elements":[ > { > "a":1, > "b":2, > "c":3, > "C_elements":[ > { > "a":1, > "b":2, > "c":3 > }, > { > "a":1, > "b":2, > "c":3 > } > ] > } > ] > }, > > { > "a":"1", > "b":"2", > "c":"3", > } > > ] > > file format unchangeable > > An instance of TestArray > a=a > b=b > c=c > List of 2 A elements: > Instance of A element > a=1 > b=2 > c=3 > Instance of A element > d=1 > e=2 > f=3 > List of 1 B elements > Instance of B element > a=1 > b=2 > c=3 > List of 2 C elements > Instance of C element > a=1 > b=2 > c=3 > Instance of C element > a=1 > b=2 > c=3 > > An instance of TestArray > a=1 > b=2 > c=3 > > def test_parser(filename): > class Stanza: > def __init__(self, values): > for attr, val in values: > setattr(self, attr, val) > > def build(couple): > if "=" in couple[0]: > attr, val = couple[0].split("=") > return attr,val > elif "Instance of" in couple[0]: > match = re.search("Instance of (.+) element", couple[0]) > return ("attr_%s" % match.group(1),Stanza(couple[1])) > elif "List of" in couple[0]: > match = re.search("List of \d (.+) elements", couple[0]) > return ("%s_elements" % match.group(1),couple[1]) You forgot one case: def build(couple): if "=" in couple[0]: attr, val = couple[0].split("=") return attr,val elif "Instance of" in couple[0]: #match = re.search("Instance of (.+) element", couple[0]) #return ("attr_%s" % match.group(1),Stanza(couple[1])) return dict(couple[1]) elif "An instance of" in couple[0]: # you forgot that case return dict(couple[1]) elif "List of" in couple[0]: match = re.search("List of \d (.+) elements", couple[0]) return ("%s_elements" % match.group(1),couple[1]) else: pass # put a test here > fo = open(filename, "r") > RE = re.compile("( *)(.*)") > stack = [("-",[])] > for line in fo: > matches = RE.match(line) > if len(matches.group(2)) > 0: > depth = 1 + len(matches.group(1)) > while len(stack) > depth: > stack[-2][1].append(build(stack[-1])) > del stack[-1] > stack.append( (matches.group(2),[]) ) > while len(stack) > 1: > stack[-2][1].append(stack[-1]) Change this to: stack[-2][1].append(build(stack[-1])) # call build() here also > del stack[-1] > return stack Actually the first and only element of stack is a container: all you need is the second element of the only tuple in stack, so: return stack[0][1] and this is your list. If you need it pretty printed, you'll have to work the hierarchy. -- Alain. From pullenjenna10 at gmail.com Tue Jun 5 17:09:58 2012 From: pullenjenna10 at gmail.com (richard) Date: Tue, 5 Jun 2012 14:09:58 -0700 (PDT) Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> <87wr3n2mgg.fsf@dpt-info.u-strasbg.fr> <0e140ef5-909b-4590-ae52-432e3e6a04ef@f30g2000vbz.googlegroups.com> <87haup3328.fsf@dpt-info.u-strasbg.fr> Message-ID: <2a365143-ff73-4cd2-aeac-ee3f85b080d8@j9g2000vbk.googlegroups.com> On Jun 5, 9:40?pm, Alain Ketterlin wrote: > richard writes: > > [I'm leaving the data in the message in case anybody has troubles going > up-thread.] > > > > > > > > > > > Hi guys still struggling to get the code that was posted to me on this > > forum to work in my favour and get the output in the format shown > > above. This is what I have so far. Any help will be greatly > > apprectiated. > > > output trying to achieve > > parsed = [ > > ? ? { > > ? ? ? "a":"a", > > ? ? ? "b":"b", > > ? ? ? "c":"c", > > ? ? ? "A_elements":[ > > ? ? ? ? ? { > > ? ? ? ? ? ? "a":1, > > ? ? ? ? ? ? "b":2, > > ? ? ? ? ? ? "c":3 > > ? ? ? ? ? }, > > ? ? ? ? ? { > > ? ? ? ? ? ? ?"a":1, > > ? ? ? ? ? ? ?"b":2, > > ? ? ? ? ? ? ?"c":3 > > ? ? ? ? ? } > > ? ? ? ?], > > ? ? ? "B_elements":[ > > ? ? ? ? ? { > > ? ? ? ? ? ? "a":1, > > ? ? ? ? ? ? "b":2, > > ? ? ? ? ? ? "c":3, > > ? ? ? ? ? ? "C_elements":[ > > ? ? ? ? ? ? ? ? ?{ > > ? ? ? ? ? ? ? ? ? ? ?"a":1, > > ? ? ? ? ? ? ? ? ? ? ?"b":2, > > ? ? ? ? ? ? ? ? ? ? ?"c":3 > > ? ? ? ? ? ? ? ? ? }, > > ? ? ? ? ? ? ? ? ? { > > ? ? ? ? ? ? ? ? ? ? ? "a":1, > > ? ? ? ? ? ? ? ? ? ? ? "b":2, > > ? ? ? ? ? ? ? ? ? ? ? "c":3 > > ? ? ? ? ? ? ? ? ? } > > ? ? ? ? ? ? ?] > > ? ? ? ? ? } > > ? ? ? ?] > > ? ? }, > > > ? ? { > > ? ? ? "a":"1", > > ? ? ? "b":"2", > > ? ? ? "c":"3", > > ? ? } > > > ] > > > file format unchangeable > > > An instance of TestArray > > ?a=a > > ?b=b > > ?c=c > > ?List of 2 A elements: > > ? Instance of A element > > ? ?a=1 > > ? ?b=2 > > ? ?c=3 > > ? Instance of A element > > ? ?d=1 > > ? ?e=2 > > ? ?f=3 > > ?List of 1 B elements > > ? Instance of B element > > ? ?a=1 > > ? ?b=2 > > ? ?c=3 > > ? ?List of 2 C elements > > ? ? Instance of C element > > ? ? ?a=1 > > ? ? ?b=2 > > ? ? ?c=3 > > ? ? Instance of C element > > ? ? ?a=1 > > ? ? ?b=2 > > ? ? ?c=3 > > > An instance of TestArray > > ?a=1 > > ?b=2 > > ?c=3 > > > def test_parser(filename): > > ? ? class Stanza: > > ? ? ? ? def __init__(self, values): > > ? ? ? ? ? ? for attr, val in values: > > ? ? ? ? ? ? ? ? setattr(self, attr, val) > > > ? ? def build(couple): > > ? ? ? ? if "=" in couple[0]: > > ? ? ? ? ? ? attr, val = couple[0].split("=") > > ? ? ? ? ? ? return attr,val > > ? ? ? ? elif "Instance of" in couple[0]: > > ? ? ? ? ? ? match = re.search("Instance of (.+) element", couple[0]) > > ? ? ? ? ? ? return ("attr_%s" % match.group(1),Stanza(couple[1])) > > ? ? ? ? elif "List of" in couple[0]: > > ? ? ? ? ? ? match = re.search("List of \d (.+) elements", couple[0]) > > ? ? ? ? ? ? return ("%s_elements" % match.group(1),couple[1]) > > You forgot one case: > > ? ? def build(couple): > ? ? ? ? if "=" in couple[0]: > ? ? ? ? ? ? attr, val = couple[0].split("=") > ? ? ? ? ? ? return attr,val > ? ? ? ? elif "Instance of" in couple[0]: > ? ? ? ? ? ? #match = re.search("Instance of (.+) element", couple[0]) > ? ? ? ? ? ? #return ("attr_%s" % match.group(1),Stanza(couple[1])) > ? ? ? ? ? ? return dict(couple[1]) > ? ? ? ? elif "An instance of" in couple[0]: # you forgot that case > ? ? ? ? ? ? return dict(couple[1]) > ? ? ? ? elif "List of" in couple[0]: > ? ? ? ? ? ? match = re.search("List of \d (.+) elements", couple[0]) > ? ? ? ? ? ? return ("%s_elements" % match.group(1),couple[1]) > ? ? ? ? else: > ? ? ? ? ? ? pass # put a test here > > > ? ? fo = open(filename, "r") > > ? ? RE = re.compile("( *)(.*)") > > ? ? stack = [("-",[])] > > ? ? for line in fo: > > ? ? ? ? matches = RE.match(line) > > ? ? ? ? if len(matches.group(2)) > 0: > > ? ? ? ? ? ? depth = 1 + len(matches.group(1)) > > ? ? ? ? ? ? while len(stack) > depth: > > ? ? ? ? ? ? ? ? stack[-2][1].append(build(stack[-1])) > > ? ? ? ? ? ? ? ? del stack[-1] > > ? ? ? ? ? ? stack.append( (matches.group(2),[]) ) > > ? ? while len(stack) > 1: > > ? ? ? ? stack[-2][1].append(stack[-1]) > > Change this to: > > ? ? ? ? ? stack[-2][1].append(build(stack[-1])) # call build() here also > > > ? ? ? ? del stack[-1] > > ? ? return stack > > Actually the first and only element of stack is a container: all you > need is the second element of the only tuple in stack, so: > > ? ? ? return stack[0][1] > > and this is your list. If you need it pretty printed, you'll have to > work the hierarchy. > > -- Alain. Hi Alain thanks for the reply. With regards to the missing case "An Instance of" im not sure where/ how that is working as the case i put in originally "Instance of" is in the file and been handled in the previous case. Also when running the final solution im getting a list of [None, None] as the final stack? just busy debugging it to see whats going wrong. But sorry should have been clearer with regards to the format mentioned above. The objects are been printed out as dicts so where you put in elif "An Instance of" in couple[0]: return dict(couple[1]) should still be ? elif "Instance of" in couple[0]: match = re.search("Instance of (.+) element", couple[0]) return ("attr_%s" % match.group(1),Stanza(couple[1])) # instantiating new stanza object and setting attributes. From pullenjenna10 at gmail.com Tue Jun 5 17:21:11 2012 From: pullenjenna10 at gmail.com (richard) Date: Tue, 5 Jun 2012 14:21:11 -0700 (PDT) Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> <87wr3n2mgg.fsf@dpt-info.u-strasbg.fr> <0e140ef5-909b-4590-ae52-432e3e6a04ef@f30g2000vbz.googlegroups.com> <87haup3328.fsf@dpt-info.u-strasbg.fr> Message-ID: <46c3308a-b112-41bd-8d77-912aa4859e61@l5g2000vbo.googlegroups.com> On Jun 5, 9:40?pm, Alain Ketterlin wrote: > richard writes: > > [I'm leaving the data in the message in case anybody has troubles going > up-thread.] > > > > > > > > > > > Hi guys still struggling to get the code that was posted to me on this > > forum to work in my favour and get the output in the format shown > > above. This is what I have so far. Any help will be greatly > > apprectiated. > > > output trying to achieve > > parsed = [ > > ? ? { > > ? ? ? "a":"a", > > ? ? ? "b":"b", > > ? ? ? "c":"c", > > ? ? ? "A_elements":[ > > ? ? ? ? ? { > > ? ? ? ? ? ? "a":1, > > ? ? ? ? ? ? "b":2, > > ? ? ? ? ? ? "c":3 > > ? ? ? ? ? }, > > ? ? ? ? ? { > > ? ? ? ? ? ? ?"a":1, > > ? ? ? ? ? ? ?"b":2, > > ? ? ? ? ? ? ?"c":3 > > ? ? ? ? ? } > > ? ? ? ?], > > ? ? ? "B_elements":[ > > ? ? ? ? ? { > > ? ? ? ? ? ? "a":1, > > ? ? ? ? ? ? "b":2, > > ? ? ? ? ? ? "c":3, > > ? ? ? ? ? ? "C_elements":[ > > ? ? ? ? ? ? ? ? ?{ > > ? ? ? ? ? ? ? ? ? ? ?"a":1, > > ? ? ? ? ? ? ? ? ? ? ?"b":2, > > ? ? ? ? ? ? ? ? ? ? ?"c":3 > > ? ? ? ? ? ? ? ? ? }, > > ? ? ? ? ? ? ? ? ? { > > ? ? ? ? ? ? ? ? ? ? ? "a":1, > > ? ? ? ? ? ? ? ? ? ? ? "b":2, > > ? ? ? ? ? ? ? ? ? ? ? "c":3 > > ? ? ? ? ? ? ? ? ? } > > ? ? ? ? ? ? ?] > > ? ? ? ? ? } > > ? ? ? ?] > > ? ? }, > > > ? ? { > > ? ? ? "a":"1", > > ? ? ? "b":"2", > > ? ? ? "c":"3", > > ? ? } > > > ] > > > file format unchangeable > > > An instance of TestArray > > ?a=a > > ?b=b > > ?c=c > > ?List of 2 A elements: > > ? Instance of A element > > ? ?a=1 > > ? ?b=2 > > ? ?c=3 > > ? Instance of A element > > ? ?d=1 > > ? ?e=2 > > ? ?f=3 > > ?List of 1 B elements > > ? Instance of B element > > ? ?a=1 > > ? ?b=2 > > ? ?c=3 > > ? ?List of 2 C elements > > ? ? Instance of C element > > ? ? ?a=1 > > ? ? ?b=2 > > ? ? ?c=3 > > ? ? Instance of C element > > ? ? ?a=1 > > ? ? ?b=2 > > ? ? ?c=3 > > > An instance of TestArray > > ?a=1 > > ?b=2 > > ?c=3 > > > def test_parser(filename): > > ? ? class Stanza: > > ? ? ? ? def __init__(self, values): > > ? ? ? ? ? ? for attr, val in values: > > ? ? ? ? ? ? ? ? setattr(self, attr, val) > > > ? ? def build(couple): > > ? ? ? ? if "=" in couple[0]: > > ? ? ? ? ? ? attr, val = couple[0].split("=") > > ? ? ? ? ? ? return attr,val > > ? ? ? ? elif "Instance of" in couple[0]: > > ? ? ? ? ? ? match = re.search("Instance of (.+) element", couple[0]) > > ? ? ? ? ? ? return ("attr_%s" % match.group(1),Stanza(couple[1])) > > ? ? ? ? elif "List of" in couple[0]: > > ? ? ? ? ? ? match = re.search("List of \d (.+) elements", couple[0]) > > ? ? ? ? ? ? return ("%s_elements" % match.group(1),couple[1]) > > You forgot one case: > > ? ? def build(couple): > ? ? ? ? if "=" in couple[0]: > ? ? ? ? ? ? attr, val = couple[0].split("=") > ? ? ? ? ? ? return attr,val > ? ? ? ? elif "Instance of" in couple[0]: > ? ? ? ? ? ? #match = re.search("Instance of (.+) element", couple[0]) > ? ? ? ? ? ? #return ("attr_%s" % match.group(1),Stanza(couple[1])) > ? ? ? ? ? ? return dict(couple[1]) > ? ? ? ? elif "An instance of" in couple[0]: # you forgot that case > ? ? ? ? ? ? return dict(couple[1]) > ? ? ? ? elif "List of" in couple[0]: > ? ? ? ? ? ? match = re.search("List of \d (.+) elements", couple[0]) > ? ? ? ? ? ? return ("%s_elements" % match.group(1),couple[1]) > ? ? ? ? else: > ? ? ? ? ? ? pass # put a test here > > > ? ? fo = open(filename, "r") > > ? ? RE = re.compile("( *)(.*)") > > ? ? stack = [("-",[])] > > ? ? for line in fo: > > ? ? ? ? matches = RE.match(line) > > ? ? ? ? if len(matches.group(2)) > 0: > > ? ? ? ? ? ? depth = 1 + len(matches.group(1)) > > ? ? ? ? ? ? while len(stack) > depth: > > ? ? ? ? ? ? ? ? stack[-2][1].append(build(stack[-1])) > > ? ? ? ? ? ? ? ? del stack[-1] > > ? ? ? ? ? ? stack.append( (matches.group(2),[]) ) > > ? ? while len(stack) > 1: > > ? ? ? ? stack[-2][1].append(stack[-1]) > > Change this to: > > ? ? ? ? ? stack[-2][1].append(build(stack[-1])) # call build() here also > > > ? ? ? ? del stack[-1] > > ? ? return stack > > Actually the first and only element of stack is a container: all you > need is the second element of the only tuple in stack, so: > > ? ? ? return stack[0][1] > > and this is your list. If you need it pretty printed, you'll have to > work the hierarchy. > > -- Alain. Hi Alain, thanks for the reply. Amended the code and just busy debugging but the stack i get back justs return [None, None]. Also should have been clearer when i mentioned the format above the dicts are actually objects instantaited from classes and just printed out as obj.__dict__ just for representation putposes. so where you have replaced the following i presume this was because of my format confusion. Thanks > elif "Instance of" in couple[0]: > match = re.search("Instance of (.+) element", couple[0]) > return ("attr_%s" % match.group(1),Stanza(couple[1])) #instantiating new object and setting attributes > with > elif "Instance of" in couple[0]: > #match = re.search("Instance of (.+) element", couple[0]) > #return ("attr_%s" % match.group(1),Stanza(couple[1])) > return dict(couple[1]) From pullenjenna10 at gmail.com Tue Jun 5 17:30:53 2012 From: pullenjenna10 at gmail.com (richard) Date: Tue, 5 Jun 2012 14:30:53 -0700 (PDT) Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> <87wr3n2mgg.fsf@dpt-info.u-strasbg.fr> <0e140ef5-909b-4590-ae52-432e3e6a04ef@f30g2000vbz.googlegroups.com> <87haup3328.fsf@dpt-info.u-strasbg.fr> <46c3308a-b112-41bd-8d77-912aa4859e61@l5g2000vbo.googlegroups.com> Message-ID: <212fec31-ea6e-43ad-9085-0193d5f16ffb@b26g2000vbt.googlegroups.com> On Jun 5, 10:21?pm, richard wrote: > On Jun 5, 9:40?pm, Alain Ketterlin > wrote: > > > > > > > > > > > richard writes: > > > [I'm leaving the data in the message in case anybody has troubles going > > up-thread.] > > > > Hi guys still struggling to get the code that was posted to me on this > > > forum to work in my favour and get the output in the format shown > > > above. This is what I have so far. Any help will be greatly > > > apprectiated. > > > > output trying to achieve > > > parsed = [ > > > ? ? { > > > ? ? ? "a":"a", > > > ? ? ? "b":"b", > > > ? ? ? "c":"c", > > > ? ? ? "A_elements":[ > > > ? ? ? ? ? { > > > ? ? ? ? ? ? "a":1, > > > ? ? ? ? ? ? "b":2, > > > ? ? ? ? ? ? "c":3 > > > ? ? ? ? ? }, > > > ? ? ? ? ? { > > > ? ? ? ? ? ? ?"a":1, > > > ? ? ? ? ? ? ?"b":2, > > > ? ? ? ? ? ? ?"c":3 > > > ? ? ? ? ? } > > > ? ? ? ?], > > > ? ? ? "B_elements":[ > > > ? ? ? ? ? { > > > ? ? ? ? ? ? "a":1, > > > ? ? ? ? ? ? "b":2, > > > ? ? ? ? ? ? "c":3, > > > ? ? ? ? ? ? "C_elements":[ > > > ? ? ? ? ? ? ? ? ?{ > > > ? ? ? ? ? ? ? ? ? ? ?"a":1, > > > ? ? ? ? ? ? ? ? ? ? ?"b":2, > > > ? ? ? ? ? ? ? ? ? ? ?"c":3 > > > ? ? ? ? ? ? ? ? ? }, > > > ? ? ? ? ? ? ? ? ? { > > > ? ? ? ? ? ? ? ? ? ? ? "a":1, > > > ? ? ? ? ? ? ? ? ? ? ? "b":2, > > > ? ? ? ? ? ? ? ? ? ? ? "c":3 > > > ? ? ? ? ? ? ? ? ? } > > > ? ? ? ? ? ? ?] > > > ? ? ? ? ? } > > > ? ? ? ?] > > > ? ? }, > > > > ? ? { > > > ? ? ? "a":"1", > > > ? ? ? "b":"2", > > > ? ? ? "c":"3", > > > ? ? } > > > > ] > > > > file format unchangeable > > > > An instance of TestArray > > > ?a=a > > > ?b=b > > > ?c=c > > > ?List of 2 A elements: > > > ? Instance of A element > > > ? ?a=1 > > > ? ?b=2 > > > ? ?c=3 > > > ? Instance of A element > > > ? ?d=1 > > > ? ?e=2 > > > ? ?f=3 > > > ?List of 1 B elements > > > ? Instance of B element > > > ? ?a=1 > > > ? ?b=2 > > > ? ?c=3 > > > ? ?List of 2 C elements > > > ? ? Instance of C element > > > ? ? ?a=1 > > > ? ? ?b=2 > > > ? ? ?c=3 > > > ? ? Instance of C element > > > ? ? ?a=1 > > > ? ? ?b=2 > > > ? ? ?c=3 > > > > An instance of TestArray > > > ?a=1 > > > ?b=2 > > > ?c=3 > > > > def test_parser(filename): > > > ? ? class Stanza: > > > ? ? ? ? def __init__(self, values): > > > ? ? ? ? ? ? for attr, val in values: > > > ? ? ? ? ? ? ? ? setattr(self, attr, val) > > > > ? ? def build(couple): > > > ? ? ? ? if "=" in couple[0]: > > > ? ? ? ? ? ? attr, val = couple[0].split("=") > > > ? ? ? ? ? ? return attr,val > > > ? ? ? ? elif "Instance of" in couple[0]: > > > ? ? ? ? ? ? match = re.search("Instance of (.+) element", couple[0]) > > > ? ? ? ? ? ? return ("attr_%s" % match.group(1),Stanza(couple[1])) > > > ? ? ? ? elif "List of" in couple[0]: > > > ? ? ? ? ? ? match = re.search("List of \d (.+) elements", couple[0]) > > > ? ? ? ? ? ? return ("%s_elements" % match.group(1),couple[1]) > > > You forgot one case: > > > ? ? def build(couple): > > ? ? ? ? if "=" in couple[0]: > > ? ? ? ? ? ? attr, val = couple[0].split("=") > > ? ? ? ? ? ? return attr,val > > ? ? ? ? elif "Instance of" in couple[0]: > > ? ? ? ? ? ? #match = re.search("Instance of (.+) element", couple[0]) > > ? ? ? ? ? ? #return ("attr_%s" % match.group(1),Stanza(couple[1])) > > ? ? ? ? ? ? return dict(couple[1]) > > ? ? ? ? elif "An instance of" in couple[0]: # you forgot that case > > ? ? ? ? ? ? return dict(couple[1]) > > ? ? ? ? elif "List of" in couple[0]: > > ? ? ? ? ? ? match = re.search("List of \d (.+) elements", couple[0]) > > ? ? ? ? ? ? return ("%s_elements" % match.group(1),couple[1]) > > ? ? ? ? else: > > ? ? ? ? ? ? pass # put a test here > > > > ? ? fo = open(filename, "r") > > > ? ? RE = re.compile("( *)(.*)") > > > ? ? stack = [("-",[])] > > > ? ? for line in fo: > > > ? ? ? ? matches = RE.match(line) > > > ? ? ? ? if len(matches.group(2)) > 0: > > > ? ? ? ? ? ? depth = 1 + len(matches.group(1)) > > > ? ? ? ? ? ? while len(stack) > depth: > > > ? ? ? ? ? ? ? ? stack[-2][1].append(build(stack[-1])) > > > ? ? ? ? ? ? ? ? del stack[-1] > > > ? ? ? ? ? ? stack.append( (matches.group(2),[]) ) > > > ? ? while len(stack) > 1: > > > ? ? ? ? stack[-2][1].append(stack[-1]) > > > Change this to: > > > ? ? ? ? ? stack[-2][1].append(build(stack[-1])) # call build() here also > > > > ? ? ? ? del stack[-1] > > > ? ? return stack > > > Actually the first and only element of stack is a container: all you > > need is the second element of the only tuple in stack, so: > > > ? ? ? return stack[0][1] > > > and this is your list. If you need it pretty printed, you'll have to > > work the hierarchy. > > > -- Alain. > > Hi Alain, thanks for the reply. Amended the code and just busy > debugging but the stack i get back justs return [None, None]. Also > should have been clearer when i mentioned the format above the dicts > are actually objects instantaited from classes and just printed out as > obj.__dict__ just for representation putposes. so where you have > replaced the following i presume this was because of my format > confusion. Thanks > > > > > > > > > > > ? ? ? ? elif "Instance of" in couple[0]: > > ? ? ? ? ? ? match = re.search("Instance of (.+) element", couple[0]) > > ? ? ? ? ? ? return ("attr_%s" % match.group(1),Stanza(couple[1])) #instantiating new object and setting attributes > > with > > ? ? ? ? elif "Instance of" in couple[0]: > > ? ? ? ? ? ? #match = re.search("Instance of (.+) element", couple[0]) > > ? ? ? ? ? ? #return ("attr_%s" % match.group(1),Stanza(couple[1])) > > ? ? ? ? ? ? return dict(couple[1]) Sorry silly mistake made with "An instance" and "Instance of" code emende below for fix if "=" in couple[0]: attr, val = couple[0].split("=") return attr,val elif re.search("Instance of .+",couple[0]): #match = re.search("Instance of (.+) element", couple[0]) #return ("attr_%s" % match.group(1),Stanza(couple[1])) return dict(couple[1]) elif re.search("An instance of .+", couple[0]): return dict(couple[1]) elif "List of" in couple[0]: match = re.search("List of \d (.+) elements", couple[0]) return ("%s_elements" % match.group(1),couple[1]) else: pass From alain at dpt-info.u-strasbg.fr Tue Jun 5 17:33:03 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 05 Jun 2012 23:33:03 +0200 Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> <87wr3n2mgg.fsf@dpt-info.u-strasbg.fr> <0e140ef5-909b-4590-ae52-432e3e6a04ef@f30g2000vbz.googlegroups.com> <87haup3328.fsf@dpt-info.u-strasbg.fr> <2a365143-ff73-4cd2-aeac-ee3f85b080d8@j9g2000vbk.googlegroups.com> Message-ID: <87d35d30mo.fsf@dpt-info.u-strasbg.fr> richard writes: >> > An instance of TestArray >> > ?a=a >> > ?b=b >> > ?c=c >> > ?List of 2 A elements: >> > ? Instance of A element >> > ? ?a=1 >> > ? ?b=2 >> > ? ?c=3 >> > ? Instance of A element >> > ? ?d=1 >> > ? ?e=2 >> > ? ?f=3 >> > ?List of 1 B elements >> > ? Instance of B element >> > ? ?a=1 >> > ? ?b=2 >> > ? ?c=3 >> > ? ?List of 2 C elements >> > ? ? Instance of C element >> > ? ? ?a=1 >> > ? ? ?b=2 >> > ? ? ?c=3 >> > ? ? Instance of C element >> > ? ? ?a=1 >> > ? ? ?b=2 >> > ? ? ?c=3 [...] > Hi Alain thanks for the reply. With regards to the missing case "An > Instance of" im not sure where/ how that is working as the case i put > in originally "Instance of" is in the file and been handled in the > previous case. Both cases are different in your example above. Top level elements are labeled "An instance ...", whereas "inner" instances are labeled "Instance of ...". > Also when running the final solution im getting a list of [None, None] > as the final stack? There's only one way this can happen: by falling through to the last case of build(). Check the regexps etc. again. > just busy debugging it to see whats going wrong. But sorry should have > been clearer with regards to the format mentioned above. The objects > are been printed out as dicts so where you put in > > elif "An Instance of" in couple[0]: > return dict(couple[1]) > > should still be ? > elif "Instance of" in couple[0]: > match = re.search("Instance of (.+) element", couple[0]) > return ("attr_%s" % match.group(1),Stanza(couple[1])) # > instantiating new stanza object and setting attributes. Your last "Instance of..." case is correct, but "An instance..." is different, because there's no containing object, so it's probably more like: return Stanza(couple[1]). -- Alain. From python at mrabarnett.plus.com Tue Jun 5 17:44:28 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 05 Jun 2012 22:44:28 +0100 Subject: English version for =?windows-1252?Q?M=E9mento_Python_3_?= =?windows-1252?Q?=28draft=2C_readers_needed=29?= In-Reply-To: <72D3A44A-9E44-4A3E-8541-E93EC36D338E@gmail.com> References: <4fce42ba$0$2028$426a74cc@news.free.fr> <4FCE564C.7020008@mrabarnett.plus.com> <72D3A44A-9E44-4A3E-8541-E93EC36D338E@gmail.com> Message-ID: <4FCE7DBC.2010302@mrabarnett.plus.com> On 05/06/2012 21:01, Petite Abeille wrote: > > On Jun 5, 2012, at 8:56 PM, MRAB wrote: > >> valeurs approch?es => (not sure) > > Approximation? > I think I understand now: nombres flottants? valeurs approch?es! => float-point numbers? approximate values! From pullenjenna10 at gmail.com Tue Jun 5 17:53:08 2012 From: pullenjenna10 at gmail.com (richard) Date: Tue, 5 Jun 2012 14:53:08 -0700 (PDT) Subject: Help needed with nested parsing of file into objects References: <6b296278-fd32-45fb-b5c7-6c0fe5ce4967@q2g2000vbv.googlegroups.com> <87wr3n2mgg.fsf@dpt-info.u-strasbg.fr> <0e140ef5-909b-4590-ae52-432e3e6a04ef@f30g2000vbz.googlegroups.com> <87haup3328.fsf@dpt-info.u-strasbg.fr> <2a365143-ff73-4cd2-aeac-ee3f85b080d8@j9g2000vbk.googlegroups.com> <87d35d30mo.fsf@dpt-info.u-strasbg.fr> Message-ID: <8362d484-d380-45aa-aa3e-c7846dc3e361@f30g2000vbz.googlegroups.com> On Jun 5, 10:33?pm, Alain Ketterlin wrote: > richard writes: > >> > An instance of TestArray > >> > ?a=a > >> > ?b=b > >> > ?c=c > >> > ?List of 2 A elements: > >> > ? Instance of A element > >> > ? ?a=1 > >> > ? ?b=2 > >> > ? ?c=3 > >> > ? Instance of A element > >> > ? ?d=1 > >> > ? ?e=2 > >> > ? ?f=3 > >> > ?List of 1 B elements > >> > ? Instance of B element > >> > ? ?a=1 > >> > ? ?b=2 > >> > ? ?c=3 > >> > ? ?List of 2 C elements > >> > ? ? Instance of C element > >> > ? ? ?a=1 > >> > ? ? ?b=2 > >> > ? ? ?c=3 > >> > ? ? Instance of C element > >> > ? ? ?a=1 > >> > ? ? ?b=2 > >> > ? ? ?c=3 > > [...] > > > Hi Alain thanks for the reply. With regards to the missing case "An > > Instance of" im not sure where/ how that is working as the case i put > > in originally "Instance of" is in the file and been handled in the > > previous case. > > Both cases are different in your example above. Top level elements are > labeled "An instance ...", whereas "inner" instances are labeled > "Instance of ...". > > > Also when running the final solution im getting a list of [None, None] > > as the final stack? > > There's only one way this can happen: by falling through to the last > case of build(). Check the regexps etc. again. > > > just busy debugging it to see whats going wrong. But sorry should have > > been clearer with regards to the format mentioned above. The objects > > are been printed out as dicts so where you put in > > > ? ? ? ? elif "An Instance of" in couple[0]: > > ? ? ? ? ? ? return dict(couple[1]) > > > ? ? ? ? should still be ? > > ? ? ? ? elif "Instance of" in couple[0]: > > ? ? ? ? ? ? match = re.search("Instance of (.+) element", couple[0]) > > ? ? ? ? ? ? return ("attr_%s" % match.group(1),Stanza(couple[1])) # > > instantiating new stanza object and setting attributes. > > Your last "Instance of..." case is correct, but "An instance..." is > different, because there's no containing object, so it's probably more > like: return Stanza(couple[1]). > > -- Alain. A big thank you to everyone who has helped me tackle / shed light on this problem it is working great. Much appreciated. From news1234 at free.fr Tue Jun 5 18:12:00 2012 From: news1234 at free.fr (News123) Date: Wed, 06 Jun 2012 00:12:00 +0200 Subject: How to exec() a string like interactive python does? Message-ID: <4fce8430$0$6476$426a74cc@news.free.fr> If I start Python in interactive mode, and I yype the commands, 'a=3', 'a', 'print a' Then the output would look like: >>> a = 3 >>> a 3 >>> print a 3 Now within an application I'd like to achieve exactly this behaviour Meaning, that - for assignments nothing is displayed - for expressions the result of the exprission displayed - and statements like print statements would be executed The only thing, that I came up with is following code and that would even print out results for 'a=3', where the normal interactive python would not echo any result. for cmd in [ 'a=3', 'a', 'print a' ] : try: print('>>> ' + cmd) exec('__rslt = ' + cmd) if __rslt is not None: print repr(__rslt) except SyntaxError: exec(cmd) The result would look like: >>> a=3 3 >>> a 3 >>> print a 3 >>> Is There anything better? From jeanpierreda at gmail.com Tue Jun 5 18:37:51 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 5 Jun 2012 18:37:51 -0400 Subject: How to exec() a string like interactive python does? In-Reply-To: <4fce8430$0$6476$426a74cc@news.free.fr> References: <4fce8430$0$6476$426a74cc@news.free.fr> Message-ID: >>> >>> def myexec(s): ... eval(compile(s, '', 'single')) ... >>> x = 3 >>> myexec('x = 4') >>> myexec('x') 3 >>> myexec('print x') 3 >>> On Tue, Jun 5, 2012 at 6:12 PM, News123 wrote: > If I start Python in interactive mode, > and I yype the commands, > 'a=3', 'a', 'print a' > > > Then the ?output would look like: >>>> a = 3 >>>> a > 3 >>>> ?print a > 3 > > > Now within an application I'd like to achieve exactly this behaviour > Meaning, that > - for assignments nothing is displayed > - for expressions the result of the exprission displayed > - and statements like print statements would be executed > > > The only thing, that I came up with is following code and that would > even print out results for 'a=3', where the normal interactive python would > not echo any result. > > for cmd in [ 'a=3', 'a', 'print a' ] : > ? ?try: > ? ? ? ?print('>>> ' + cmd) > ? ? ? ?exec('__rslt = ' + cmd) > ? ? ? ?if __rslt is not None: > ? ? ? ? ? ?print repr(__rslt) > ? ?except SyntaxError: > ? ? ? ?exec(cmd) > > The result would look like: >>>> a=3 > 3 >>>> a > 3 >>>> print a > 3 >>>> > > > Is There anything better? > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From steve+comp.lang.python at pearwood.info Tue Jun 5 19:31:05 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Jun 2012 23:31:05 GMT Subject: How to exec() a string like interactive python does? References: <4fce8430$0$6476$426a74cc@news.free.fr> Message-ID: <4fce96b9$0$29968$c3e8da3$5496439d@news.astraweb.com> On Wed, 06 Jun 2012 00:12:00 +0200, News123 wrote: > If I start Python in interactive mode, and I yype the commands, > 'a=3', 'a', 'print a' > > > Then the output would look like: > >>> a = 3 > >>> a > 3 > >>> print a > 3 > > > Now within an application I'd like to achieve exactly this behaviour Before you reinvent the wheel, see the cmd and code modules. http://docs.python.org/library/cmd.html http://docs.python.org/library/code.html -- Steven From drsalists at gmail.com Tue Jun 5 20:05:14 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 5 Jun 2012 17:05:14 -0700 Subject: Python Tree datastructure comparison Message-ID: I've put together a comparison of some tree datastructures for Python, with varied runtime and varied workload: http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/ I hope to find time to add heaps to the article at some point, but for now, it only covers trees and the treap. The short version: 1. The 2-3 tree gave incorrect results, so I eliminated it. This may or may not have been my fault. 2. The Red-black tree was performing so slowly that it was making the graphs hard to read, so I eliminated it. It actually seemed to be doing pretty well at first, until I realized that garbage collections were becoming very slow with red-black trees. 3. The top three performers were, under various workloads and with various runtimes: The AVL Tree, The Splay Tree and The Treap. 4. The Treap was consistently either in first or second place. 5. All the datastructures examined were ported to python 3 in such a way that they would continue to work on python 2 - I've at times taken liberties like allowing log(n) range's, which of course are eagerly evaluated in python 2. The modules were also modified to pass pylint. These are all trees (and the treap), for now, with dictionary-like interfaces, that allow you to do things like look up the least (or greatest) value in log(n) time. The need for such a datastructure is uncommon, but does come up from time to time - implementing a cache is foremost in my mind. If you just need fast lookups without any particular ordering, you're almost always going to be better off with a hash table (dictionary). -------------- next part -------------- An HTML attachment was scrubbed... URL: From miriam.gomezrs at udlap.mx Tue Jun 5 21:43:07 2012 From: miriam.gomezrs at udlap.mx (Miriam Gomez Rios) Date: Wed, 6 Jun 2012 01:43:07 +0000 Subject: mistake in python tutorial Message-ID: Hello, I think that the example in section 4.4 in the tutorial for python 2.7X is wrong. http://docs.python.org/tutorial/controlflow.html It will end up printing this if you run the exact code listed in the tutorial. 3 is a prime number 4 equals 2*2 5 is a prime number 5 is a prime number 5 is a prime number 6 equals 2 * 3 7 is a prime number 7 is a prime number 7 is a prime number 7 is a prime number 7 is a prime number 8 equals 2*4 9 is a prime number 9 equals 3*3 I believe it is because the is no break in " else print n is a prime number" and it never prints anything about number 2 because the second for is like range(2,2) which is empty so it does nothing. -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Tue Jun 5 22:00:55 2012 From: d at davea.name (Dave Angel) Date: Tue, 05 Jun 2012 22:00:55 -0400 Subject: mistake in python tutorial In-Reply-To: References: Message-ID: <4FCEB9D7.1080909@davea.name> On 06/05/2012 09:43 PM, Miriam Gomez Rios wrote: > Hello, I think that the example in section 4.4 in the tutorial for python 2.7X is wrong. > > http://docs.python.org/tutorial/controlflow.html > > > > It will end up printing this if you run the exact code listed in the tutorial. > > > > 3 is a prime number > > 4 equals 2*2 > > 5 is a prime number > > 5 is a prime number > > 5 is a prime number > > 6 equals 2 * 3 > > 7 is a prime number > > 7 is a prime number > > 7 is a prime number > > 7 is a prime number > > 7 is a prime number > > 8 equals 2*4 > > 9 is a prime number > > 9 equals 3*3 > > > > I believe it is because the is no break in " else print n is a prime number" and > > it never prints anything about number 2 because the second for is like range(2,2) > > which is empty so it does nothing. > > Hate to tell you, but the example works as it exists on the website. If you got your output, you must have messed up the indentation, which is VERY important in python. In particular, the else clause has to line up with the for statement, NOT with the if statement. If it helps, this is the correct indentation. Paste it into a file, and run it. for n in range(2, 10): for x in range(2, n): if n % x == 0: print n, 'equals', x, '*', n/x break else: # loop fell through without finding a factor print n, 'is a prime number' -- DaveA From python at mrabarnett.plus.com Tue Jun 5 23:04:18 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Jun 2012 04:04:18 +0100 Subject: mistake in python tutorial In-Reply-To: <4FCEB9D7.1080909@davea.name> References: <4FCEB9D7.1080909@davea.name> Message-ID: <4FCEC8B2.2000600@mrabarnett.plus.com> On 06/06/2012 03:00, Dave Angel wrote: > On 06/05/2012 09:43 PM, Miriam Gomez Rios wrote: >> Hello, I think that the example in section 4.4 in the tutorial for python 2.7X is wrong. >> >> http://docs.python.org/tutorial/controlflow.html >> >> >> >> It will end up printing this if you run the exact code listed in the tutorial. >> >> >> >> 3 is a prime number >> >> 4 equals 2*2 >> >> 5 is a prime number >> >> 5 is a prime number >> >> 5 is a prime number >> >> 6 equals 2 * 3 >> >> 7 is a prime number >> >> 7 is a prime number >> >> 7 is a prime number >> >> 7 is a prime number >> >> 7 is a prime number >> >> 8 equals 2*4 >> >> 9 is a prime number >> >> 9 equals 3*3 >> >> >> >> I believe it is because the is no break in " else print n is a prime number" and >> >> it never prints anything about number 2 because the second for is like range(2,2) >> >> which is empty so it does nothing. >> >> > > Hate to tell you, but the example works as it exists on the website. If > you got your output, you must have messed up the indentation, which is > VERY important in python. > > In particular, the else clause has to line up with the for statement, > NOT with the if statement. > > If it helps, this is the correct indentation. Paste it into a file, and > run it. > > for n in range(2, 10): > for x in range(2, n): > if n % x == 0: > print n, 'equals', x, '*', n/x > break > else: > # loop fell through without finding a factor > print n, 'is a prime number' > I can confirm that the OP's output is what you get when the 'else' is indented the same as the 'if'. From no.email at nospam.invalid Wed Jun 6 00:14:09 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 05 Jun 2012 21:14:09 -0700 Subject: English version for =?utf-8?Q?M=C3=A9mento?= Python 3 (draft, readers needed) References: <4fce42ba$0$2028$426a74cc@news.free.fr> <7x62b54ozc.fsf@ruckus.brouhaha.com> <4fce665c$0$15486$426a74cc@news.free.fr> Message-ID: <7x1ult9iwe.fsf@ruckus.brouhaha.com> Laurent Pointal writes: >> There are a few other things like that, and I'll try to look more >> carefully tonight, I can't spend more time on it right now. > I updated the document into 1.0.5a (and fix some other errors). A few more things: In "Base types" section: unmodifiable => immutable (both are correct but immutable is a clearer technical term) In "Container types": unmodifiable => immutable as above dictionnary => dictionary In "Identifiers": min/MAJ case discrimination => lower/UPPER case sensitive In "Conversions": see verso => see other side ("verso" is not wrong, but it's an unusual word in US English) logial => logical In "Sequences indexing": negative index -4 => [the formatting is broken] In "Boolean Logic" twice simultaneously => both simultaneously In "Maths" remain => modulo [page 2] In "Conditional loop statement" care to inifinite loops! => be careful of infinite loops! In "Display / Input" recto => other side (like "verso" further up) litt?ral => literal In "Files" don't miss to close file => don't forget to close the file [but you might mention the "with" statement] In "Function definition" bloc => block (? black box ?) => ("black box") [English speakers may not recognize ? ? symbols] In "Generator of int sequences" You might mention that range makes a generator only in Python 3. In Python 2 it makes an actual list and xrange makes a generator. From cpr.17a at gmail.com Wed Jun 6 02:36:58 2012 From: cpr.17a at gmail.com (Phanindra Ramesh Challa) Date: Wed, 6 Jun 2012 12:06:58 +0530 Subject: KeyError: '13' Message-ID: I am trying to run a python program. It is giving the KeyError: '13'. I have no clue regarding this error. this is the python code relevant to the error: dpi = 100 bold = 0 italic = 0 mono = 0 comment = "" dbname = "font.db" for o, a in opts: if o == '-b': bold = 1 if o == '-i': italic = 1 if o == '-m': mono = 1 if o == '-d': dpi = int (a) if o == '-c': comment = string.join (string.split (a), " ") if o == '-g': dbname = a fontname = args[0] pixel_size = int (args[1]) point_size = int (pixel_size * 72.27 / dpi + 0.5) # Approximate average glyph width. avg_width = pixel_size * 17 / 24 db = anydbm.open (dbname, "r") codes = loads (db [str (pixel_size)]) And the error is : python2 ../../../mk_bdf.py -c "Converted from fonts of Computer Modern family (C) 1979-1985 Donald E. Knuth and others." -b 'TeX Sans' 13 > tex09sb.bdf Traceback (most recent call last): File "../../../mk_bdf.py", line 108, in codes = loads (db [str (pixel_size)]) File "/usr/lib/python2.7/bsddb/__init__.py", line 270, in __getitem__ return _DeadlockWrap(lambda: self.db[key]) # self.db[key] File "/usr/lib/python2.7/bsddb/dbutils.py", line 68, in DeadlockWrap return function(*_args, **_kwargs) File "/usr/lib/python2.7/bsddb/__init__.py", line 270, in return _DeadlockWrap(lambda: self.db[key]) # self.db[key] KeyError: '13' Anybody please help me in running the program. -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Jun 6 03:26:17 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jun 2012 09:26:17 +0200 Subject: KeyError: '13' References: Message-ID: Phanindra Ramesh Challa wrote: > I am trying to run a python program. It is giving the KeyError: '13'. I > have no clue regarding this error. > this is the python code relevant to the error: > > dpi = 100 > bold = 0 > italic = 0 > mono = 0 > comment = "" > dbname = "font.db" > > for o, a in opts: > if o == '-b': bold = 1 > if o == '-i': italic = 1 > if o == '-m': mono = 1 > if o == '-d': dpi = int (a) > if o == '-c': comment = string.join (string.split (a), " ") > if o == '-g': dbname = a > > fontname = args[0] > pixel_size = int (args[1]) pixel_size is now 13 > point_size = int (pixel_size * 72.27 / dpi + 0.5) > > # Approximate average glyph width. > avg_width = pixel_size * 17 / 24 > > db = anydbm.open (dbname, "r") The above line opens a database (a Berkeley DB as the traceback reveals). > codes = loads (db [str (pixel_size)]) str(pixel_size) converts 13 back to the string "13" db[some_key] looks up the record with some_key, "13" in this case. There is no record with the key "13" in the font.db database, and therefore the script fails with the aptly named KeyError. (The database interface is modeled after Python's dictionary, so the handling is similar) > And the error is : > python2 ../../../mk_bdf.py -c "Converted from fonts of Computer Modern > family (C) 1979-1985 Donald E. Knuth and others." -b 'TeX Sans' 13 > > tex09sb.bdf > Traceback (most recent call last): > File "../../../mk_bdf.py", line 108, in > codes = loads (db [str (pixel_size)]) > File "/usr/lib/python2.7/bsddb/__init__.py", line 270, in __getitem__ > return _DeadlockWrap(lambda: self.db[key]) # self.db[key] > File "/usr/lib/python2.7/bsddb/dbutils.py", line 68, in DeadlockWrap > return function(*_args, **_kwargs) > File "/usr/lib/python2.7/bsddb/__init__.py", line 270, in > return _DeadlockWrap(lambda: self.db[key]) # self.db[key] > KeyError: '13' > Anybody please help me in running the program. For now you can ignore the code in the traceback which may be a bit intimidating to a newbie. It contains lines from the implementation of the database interface. Instead have a look at the keys that are in the database with db = anydb.open("font.db") for key in db: print key and then decide if you to need to change the lookup key or to add records to the database. From news1234 at free.fr Wed Jun 6 04:34:52 2012 From: news1234 at free.fr (News123) Date: Wed, 06 Jun 2012 10:34:52 +0200 Subject: How to exec() a string like interactive python does? In-Reply-To: <4fce8430$0$6476$426a74cc@news.free.fr> References: <4fce8430$0$6476$426a74cc@news.free.fr> Message-ID: <4fcf162c$0$21938$426a74cc@news.free.fr> On 06/06/2012 12:12 AM, News123 wrote: > If I start Python in interactive mode, > and I yype the commands, > 'a=3', 'a', 'print a' > > > Then the output would look like: > >>> a = 3 > >>> a > 3 > >>> print a > 3 > > > Now within an application I'd like to achieve exactly this behaviour > Meaning, that > - for assignments nothing is displayed > - for expressions the result of the exprission displayed > - and statements like print statements would be executed > > > The only thing, that I came up with is following code and that would > even print out results for 'a=3', where the normal interactive python > would not echo any result. > > for cmd in [ 'a=3', 'a', 'print a' ] : > try: > print('>>> ' + cmd) > exec('__rslt = ' + cmd) > if __rslt is not None: > print repr(__rslt) > except SyntaxError: > exec(cmd) > > The result would look like: > >>> a=3 > 3 > >>> a > 3 > >>> print a > 3 > >>> > > > Is There anything better? > Thanks a lot Devin, Following line does the trick: eval(compile(s, '', 'single')) From ulrich.eckhardt at dominolaser.com Wed Jun 6 06:03:34 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 06 Jun 2012 12:03:34 +0200 Subject: English version for =?UTF-8?B?TcOpbWVudG8gUHl0aG9uIDMgKGRyYWY=?= =?UTF-8?B?dCwgcmVhZGVycyBuZWVkZWQp?= In-Reply-To: <4fce42ba$0$2028$426a74cc@news.free.fr> References: <4fce42ba$0$2028$426a74cc@news.free.fr> Message-ID: Am 05.06.2012 19:32, schrieb Laurent Pointal: > I started a first translation of my document originally in french. Could > some fluent english people read it and indicate errors or bad english > expressions. Just one note up front: Languages or nationalities are written with uppercase letters, like English and French. Other common faults of that category are days of the week (Monday..) and month names (January..), although that's irrelevant for your doc. Another thing I noticed that was missing was that the "in" keyword can not only be used to iterate over a sequence (for i in seq:...) but also to test if something is contained in a sequence (if i in seq:...). "don't miss to close file after use": Use a "with" statement. "see verso for string formatting..." - what is "verso"? "dont" -> "don't" "char strings" -> "strings" (in the context of indexing, byte strings have the same syntax) "with several else if, else if..." - there is no "else if" but "elif". "block else for other cases" - this sounds as if it was blocking the else. Maybe "else-block for other cases", but English hyphenation is complicated and I'm not sure. Thanks for your work! Uli From tim.wintle at teamrubber.com Wed Jun 6 07:08:58 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Wed, 06 Jun 2012 12:08:58 +0100 Subject: English version for =?ISO-8859-1?Q?M=E9mento?= Python 3 (draft, readers needed) In-Reply-To: References: <4fce42ba$0$2028$426a74cc@news.free.fr> Message-ID: <1338980938.6265.21.camel@tim-laptop> On Wed, 2012-06-06 at 12:03 +0200, Ulrich Eckhardt wrote: > "block else for other cases" - this sounds as if it was blocking the > else. Maybe "else-block for other cases", I would say "else block". "else-block" is grammatically correct too, but I don't think I've seen it used regularly. RE: the order - "else" is being used as an adjective to clarify the noun "block" - in English the adjective comes before the noun (unlike a lot of European languages) e.g. we say "the red book", not "the book red", where the French would say "livre rouge" (I believe). If you want to put an adjective after the noun (for poetical reasons etc) then there needs to be another clause. e.g. "the book, which was red" > but English hyphenation is complicated and I'm not sure. You're German and you say English hyphenation is complicated! ;-) Tim From king.tom44 at yahoo.com Wed Jun 6 07:25:04 2012 From: king.tom44 at yahoo.com (Tom King) Date: Wed, 6 Jun 2012 04:25:04 -0700 (PDT) Subject: problem python Message-ID: <1338981904.49606.YahooMailNeo@web113912.mail.gq1.yahoo.com> hi im new in python and i have a problem about when i type python in my command line console i get an error message? 'import site' failed; use -v for traceback Python 2.4.3 (#1, May? 5 2011, 18:44:23) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> what is going on and how i can fix it thanks in andvance -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Jun 6 08:19:07 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jun 2012 14:19:07 +0200 Subject: problem python References: <1338981904.49606.YahooMailNeo@web113912.mail.gq1.yahoo.com> Message-ID: Tom King wrote: > hi im new in python and i have a problem about > > when i type python in my command line console i get an error message > > 'import site' failed; use -v for traceback > Python 2.4.3 (#1, May 5 2011, 18:44:23) > [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> > > > what is going on and how i can fix it > thanks in andvance Did you write a module site.py yourself? If so rename it and don't forget to remove the corresponding site.pyc. If that doesn't help invoke python with $ python -S and then import site explicitly in the interactive interpreter: >>> import site You should get a traceback. If you cut and paste it and show it to us we might tell you more. From jldunn2000 at gmail.com Wed Jun 6 08:50:02 2012 From: jldunn2000 at gmail.com (loial) Date: Wed, 6 Jun 2012 05:50:02 -0700 (PDT) Subject: Compare 2 times Message-ID: I have a requirement to test the creation time of a file with the current time and raise a message if the file is more than 15 minutes old. Platform is Unix. I have looked at using os.path.getctime for the file creation time and time.time() for the current time, but is this the best approach? From list at qtrac.plus.com Wed Jun 6 09:06:54 2012 From: list at qtrac.plus.com (Mark Summerfield) Date: Wed, 6 Jun 2012 06:06:54 -0700 (PDT) Subject: ttk.Spinbox missing? Message-ID: <28745ccb-4d88-4aa8-9c54-cc55f438d207@m3g2000vbl.googlegroups.com> Hi, I have Python 3.2 with Tcl/Tk 8.5, but there doesn't seem to be a ttk.Spinbox widget even though that widget is part of Tcl/Tk 8.5: http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_spinbox.htm Why is that? From __peter__ at web.de Wed Jun 6 09:14:18 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jun 2012 15:14:18 +0200 Subject: KeyError: '13' References: Message-ID: Phanindra Ramesh Challa wrote: [Please hit "reply-all" in you email client when you answer a post. That way it will appear on the mailing list and give more people a chance to answer] > output of the is just the line > "sizes". >> and then decide if you to need to change the lookup key or to add records >> to the database. >> > How can I add recors to the database? The Python part of the answer is db[some_key] = some_value but I fear that won't help. Google suggests you are struggling with the metatype project If so, there seems to be a corresponding mk_db.py that you can use. I don't know anything about metatype, but the comment in mk_db.py at http://metatype.cvs.sourceforge.net/viewvc/metatype/metatype/mk_db.py?revision=1.3&view=markup tells to run it like so: find . -name '*.ugs' | python mk_db.py -a glyphlist -o dbmfile Perhaps you ran it, but there weren't any *.ugs files? From __peter__ at web.de Wed Jun 6 09:29:18 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jun 2012 15:29:18 +0200 Subject: problem python References: <1338981904.49606.YahooMailNeo@web113912.mail.gq1.yahoo.com> Message-ID: Tom King wrote: [Please hit "reply-all" in your email client when you answer a post. That way it will appear on the mailing list and give more people a chance to answer] >>> when i type python in my command line console i get an error message >>> >>> 'import site' failed; use -v for traceback >>> Python 2.4.3 (#1, May 5 2011, 18:44:23) >>> [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 >>> Type "help", "copyright", "credits" or "license" for more information. >>> what is going on and how i can fix it >>> thanks in andvance >> >> Did you write a module site.py yourself? If so rename it and don't forget >> to remove the corresponding site.pyc. If that doesn't help invoke python >> with >> >> $ python -S >> >> and then import site explicitly in the interactive interpreter: >> >> >>> import site >> >> You should get a traceback. If you cut and paste it and show it to us we >> might tell you more. > thank you Peter for your response i followed your instructions and > get this time > > python -S > Python 2.4.3 (#1, May 5 2011, 18:44:23) > [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 > >>> import site > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named site > >>> So the file seems to be missing indeed. Frankly, that's not what I expected, and I don't know how to proceed from here. Can you import other modules, e. g. >>> import dis ? What does >>> import sys >>> sys.path show? From alain at dpt-info.u-strasbg.fr Wed Jun 6 09:29:37 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 06 Jun 2012 15:29:37 +0200 Subject: Compare 2 times References: Message-ID: <878vg036wu.fsf@dpt-info.u-strasbg.fr> loial writes: > I have a requirement to test the creation time of a file with the > current time and raise a message if the file is more than 15 minutes > old. > Platform is Unix. > I have looked at using os.path.getctime for the file creation time and > time.time() for the current time, but is this the best approach? No. getctime() returns the last "change" time. The creation time is not kept anywhere. This may still match your requirement though. And os.path is the right package to look at for such tasks. -- Alain. From __peter__ at web.de Wed Jun 6 09:35:20 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Jun 2012 15:35:20 +0200 Subject: Compare 2 times References: Message-ID: loial wrote: > I have a requirement to test the creation time of a file with the > current time and raise a message if the file is more than 15 minutes > old. > > Platform is Unix. > > I have looked at using os.path.getctime for the file creation time and ctime is not actually the creation time: http://www.brandonhutchinson.com/ctime_atime_mtime.html > time.time() for the current time, but is this the best approach? What kind of improvement do you have in mind? From lists at cheimes.de Wed Jun 6 09:39:14 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 06 Jun 2012 15:39:14 +0200 Subject: Compare 2 times In-Reply-To: References: Message-ID: Am 06.06.2012 14:50, schrieb loial: > I have a requirement to test the creation time of a file with the > current time and raise a message if the file is more than 15 minutes > old. > > Platform is Unix. > > I have looked at using os.path.getctime for the file creation time and > time.time() for the current time, but is this the best approach? Lots of people are confused by ctime because they think 'c' stands for change. That's wrong. st_ctime is status change time. The ctime is updated when you change (for example) owner or group of a file, create a hard link etc. POSIX has no concept of creation time stamp. Christian From wrw at mac.com Wed Jun 6 09:45:14 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Wed, 06 Jun 2012 09:45:14 -0400 Subject: Compare 2 times In-Reply-To: <878vg036wu.fsf@dpt-info.u-strasbg.fr> References: <878vg036wu.fsf@dpt-info.u-strasbg.fr> Message-ID: <8D92E91A-6343-4E33-A18E-6486B13FFE55@mac.com> On Jun 6, 2012, at 9:29 AM, Alain Ketterlin wrote: > loial writes: > >> I have a requirement to test the creation time of a file with the >> current time and raise a message if the file is more than 15 minutes >> old. >> Platform is Unix. >> I have looked at using os.path.getctime for the file creation time and >> time.time() for the current time, but is this the best approach? > > No. getctime() returns the last "change" time. The creation time is not > kept anywhere. This may still match your requirement though. And os.path > is the right package to look at for such tasks. > > -- Alain. > -- > http://mail.python.org/mailman/listinfo/python-list If you REALLY want the creation time rather than the last time the file was touched, you will probably have to invoke the subprocess module and call ls -U, something like the following: creation_time = subprocess.check_output(["ls", "-U", string_filename_variable]) The -U option isn't universal, but it does exist in most of the UNIces I'm familiar with. -Bill From wrw at mac.com Wed Jun 6 09:55:43 2012 From: wrw at mac.com (William R. Wing (Bill Wing)) Date: Wed, 06 Jun 2012 09:55:43 -0400 Subject: Compare 2 times In-Reply-To: <8D92E91A-6343-4E33-A18E-6486B13FFE55@mac.com> References: <878vg036wu.fsf@dpt-info.u-strasbg.fr> <8D92E91A-6343-4E33-A18E-6486B13FFE55@mac.com> Message-ID: On Jun 6, 2012, at 9:45 AM, William R. Wing (Bill Wing) wrote: > On Jun 6, 2012, at 9:29 AM, Alain Ketterlin wrote: > >> loial writes: >> >>> I have a requirement to test the creation time of a file with the >>> current time and raise a message if the file is more than 15 minutes >>> old. >>> Platform is Unix. >>> I have looked at using os.path.getctime for the file creation time and >>> time.time() for the current time, but is this the best approach? >> >> No. getctime() returns the last "change" time. The creation time is not >> kept anywhere. This may still match your requirement though. And os.path >> is the right package to look at for such tasks. >> >> -- Alain. >> -- >> http://mail.python.org/mailman/listinfo/python-list > > If you REALLY want the creation time rather than the last time the file was touched, you will probably have to invoke the subprocess module and call ls -U, something like the following: > > creation_time = subprocess.check_output(["ls", "-U", string_filename_variable]) > > The -U option isn't universal, but it does exist in most of the UNIces I'm familiar with. > > -Bill Addendum, with apologies - I was in too much of a hurry. The -U option has to be used with -l (at least on my system). Thus, it would be ls -lU. Alternatively, you could "stat" the file in a subprocess and then parse the return data to extract the creation date. -Bill From alain at dpt-info.u-strasbg.fr Wed Jun 6 10:03:52 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 06 Jun 2012 16:03:52 +0200 Subject: Compare 2 times References: <878vg036wu.fsf@dpt-info.u-strasbg.fr> Message-ID: <874nqo35br.fsf@dpt-info.u-strasbg.fr> Alain Ketterlin writes: > loial writes: > >> I have a requirement to test the creation time of a file with the >> current time and raise a message if the file is more than 15 minutes >> old. >> Platform is Unix. >> I have looked at using os.path.getctime for the file creation time and >> time.time() for the current time, but is this the best approach? > > No. getctime() returns the last "change" time. The creation time is not > kept anywhere. This may still match your requirement though. And os.path > is the right package to look at for such tasks. Sorry, it may happen that the filesystem you're working with provides that time, in which case it's called birthtime. This _may_ be available via os.stat(). -- Alain. From python at mrabarnett.plus.com Wed Jun 6 11:30:53 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Jun 2012 16:30:53 +0100 Subject: English version for =?ISO-8859-1?Q?M=E9mento_Python_3_?= =?ISO-8859-1?Q?=28draft=2C_readers_needed=29?= In-Reply-To: <1338980938.6265.21.camel@tim-laptop> References: <4fce42ba$0$2028$426a74cc@news.free.fr> <1338980938.6265.21.camel@tim-laptop> Message-ID: <4FCF77AD.2010406@mrabarnett.plus.com> On 06/06/2012 12:08, Tim Wintle wrote: > On Wed, 2012-06-06 at 12:03 +0200, Ulrich Eckhardt wrote: >> "block else for other cases" - this sounds as if it was blocking the >> else. Maybe "else-block for other cases", > > I would say "else block". "else-block" is grammatically correct too, but > I don't think I've seen it used regularly. > If the "else" could be in a different colour, that may be clearer. > RE: the order - "else" is being used as an adjective to clarify the noun > "block" - in English the adjective comes before the noun (unlike a lot > of European languages) > > e.g. we say "the red book", not "the book red", where the French would > say "livre rouge" (I believe). > > If you want to put an adjective after the noun (for poetical reasons > etc) then there needs to be another clause. e.g. "the book, which was > red" > >> but English hyphenation is complicated and I'm not sure. > > You're German and you say English hyphenation is complicated! ;-) > > Tim > From python at mrabarnett.plus.com Wed Jun 6 11:42:58 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Jun 2012 16:42:58 +0100 Subject: [Python-Dev] TZ-aware local time In-Reply-To: <87haup2cob.fsf@benfinney.id.au> References: <4FCE922A.2010003@canterbury.ac.nz> <4FCECEA9.1040608@mrabarnett.plus.com> <87haup2cob.fsf@benfinney.id.au> Message-ID: <4FCF7A82.2000107@mrabarnett.plus.com> On 06/06/2012 07:10, Ben Finney wrote: > MRAB writes: > >> datetime objects would consist of the UTC time, time zone and DST. > > ?time zone? information always entails DST information doesn't it? It > isn't proper time zone information if it doesn't tell you about DST. > > That is, when you know the full time zone information, that includes > when (if ever) DST kicks on or off. > > Or have I been spoiled by the Olsen database? > I was thinking timezone as the base offset from UTC; DST would be an additional offset which changes (or may change) twice a year. From python at mrabarnett.plus.com Wed Jun 6 12:09:06 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Jun 2012 17:09:06 +0100 Subject: [Python-ideas] changing sys.stdout encoding In-Reply-To: <1338966574.75723.YahooMailClassic@web161506.mail.bf1.yahoo.com> References: <1338966574.75723.YahooMailClassic@web161506.mail.bf1.yahoo.com> Message-ID: <4FCF80A2.7060406@mrabarnett.plus.com> On 06/06/2012 08:09, Rurpy wrote: > On 06/05/2012 05:56 PM, MRAB wrote: >> On 06/06/2012 00:34, Victor Stinner wrote: >>> 2012/6/5 Rurpy: >>>> In my first foray into Python3 I've encountered this problem: >>>> I work in a multi-language environment. I've written a number >>>> of tools, mostly command-line, that generate output on stdout. >>>> Because these tools and their output are used by various people >>>> in varying environments, the tools all have an --encoding option >>>> to provide output that meets the needs and preferences of the >>>> output's ultimate consumers. >>> >>> What happens if the specified encoding is different than the encoding >>> of the console? Mojibake? >>> >>> If the output is used as in the input of another program, does the >>> other program use the same encoding? >>> >>> In my experience, using an encoding different than the locale encoding >>> for input/output (stdout, environment variables, command line >>> arguments, etc.) causes various issues. So I'm curious of your use >>> cases. >>> >>>> In converting them to Python3, I found the best (if not very >>>> pleasant) way to do this in Python3 was to put something like >>>> this near the top of each tool[*1]: >>>> >>>> import codecs >>>> sys.stdout = codecs.getwriter(opts.encoding)(sys.stdout.buffer) >>> >>> In Python 3, you should use io.TextIOWrapper instead of >>> codecs.StreamWriter. It's more efficient and has less bugs. >>> >>>> What I want to be able to put there instead is: >>>> >>>> sys.stdout.set_encoding (opts.encoding) >>> >>> I don't think that your use case merit a new method on >>> io.TextIOWrapper: replacing sys.stdout does work and should be used >>> instead. TextIOWrapper is generic and your use case if specific to >>> sys.std* streams. >>> >>> It would be surprising to change the encoding of an arbitrary file >>> after it is opened. At least, I don't see the use case. >>> >> [snip] >> >> And if you _do_ want multiple encodings in a file, it's clearer to open >> the file as binary and then explicitly encode to bytes and write _that_ >> to the file. > > But is it really? > > The following is very simple and the level of python > expertise required is minimal. It (would) works fine > with redirection. One could substitute any other ordinary > open (for write) text file for sys.stdout. > > [off the top of my head] > text = 'This is %s text: ??????????' > sys.stdout.set_encoding ('sjis') > print (text % 'sjis') > sys.stdout.set_encoding ('euc-jp') > print (text % 'euc-jp') > sys.stdout.set_encoding ('iso2022-jp') > print (text % 'iso2022-jp') > > As for your suggestion, how do I reopen sys.stdout in > binary mode? I don't need to do that often and don't > know off the top of my head. (And it's too late for > me to look it up.) And what happens to redirected output > when I close and reopen the stream? I can open a regular > filename instead. But remember to make the last two > opens with "a" rather than "w". And don't forget the > "\n" at the end of the text line. > > Could you show me an code example of your suggestion > for comparison? > > Disclaimer: As I said before, I am not particularly > advocating for a for a set_encoding() method -- my > primary suggestion is a programatic way to change the > sys.std* encodings prior to first use. Here I am just > questioning the claim that a set_encoding() method > would not be clearer than existing alternatives. > This example accesses the underlying binary output stream: # -*- coding: utf-8 -*- import sys class Writer: def __init__(self, output): self.output = output self.encoding = output.encoding def write(self, string): self.output.buffer.write(string.encode(self.encoding)) def set_encoding(self, encoding): self.output.buffer.flush() self.encoding = encoding sys.stdout = Writer(sys.stdout) initial_encoding = sys.stdout.encoding text = 'This is %s text: ??????????' sys.stdout.set_encoding('utf-8') print (text % 'utf-8') sys.stdout.set_encoding('sjis') print (text % 'sjis') sys.stdout.set_encoding('euc-jp') print (text % 'euc-jp') sys.stdout.set_encoding('iso2022-jp') print (text % 'iso2022-jp') sys.stdout.set_encoding(initial_encoding) From laurent.pointal at free.fr Wed Jun 6 13:06:12 2012 From: laurent.pointal at free.fr (Laurent Pointal) Date: Wed, 06 Jun 2012 19:06:12 +0200 Subject: English version for =?UTF-8?B?TcOpbWVudG8=?= Python 3 (draft, readers needed) References: <4fce42ba$0$2028$426a74cc@news.free.fr> <7x62b54ozc.fsf@ruckus.brouhaha.com> <4fce665c$0$15486$426a74cc@news.free.fr> <7x1ult9iwe.fsf@ruckus.brouhaha.com> Message-ID: <4fcf8e05$0$15465$426a74cc@news.free.fr> Paul Rubin wrote: > Laurent Pointal writes: >>> There are a few other things like that, and I'll try to look more >>> carefully tonight, I can't spend more time on it right now. >> I updated the document into 1.0.5a (and fix some other errors). > > A few more things: > > In "Files" > don't miss to close file => don't forget to close the file > [but you might mention the "with" statement] I put it as a note (I want students to have file closing in mind, they may practice other languages without such constructions). > In "Function definition" > bloc => block > (? black box ?) => ("black box") > [English speakers may not recognize ? ? symbols] I switched them to "". Its here to remember students that they can't access to functions internal variables from outside (and should try to limit access to outside world from inside functions) - a common error during practice. In lecture class, I try to show them only two access points to functions: parameters and return value, and a "black box" blocking all other informations. > In "Generator of int sequences" > You might mention that range makes a generator only in Python 3. > In Python 2 it makes an actual list and xrange makes a generator. We teach with Python3 as several modifications in the language are better for leaning programming basics (like 1/2 => 0.5). Thanks for all your corrections, I'll continue with other posters. A+ L.Pointal. -- Laurent POINTAL - laurent.pointal at laposte.net From laurent.pointal at free.fr Wed Jun 6 13:19:04 2012 From: laurent.pointal at free.fr (Laurent Pointal) Date: Wed, 06 Jun 2012 19:19:04 +0200 Subject: English version for =?UTF-8?B?TcOpbWVudG8=?= Python 3 (draft, readers needed) References: <4fce42ba$0$2028$426a74cc@news.free.fr> Message-ID: <4fcf9108$0$16471$426a74cc@news.free.fr> Ulrich Eckhardt wrote: > Am 05.06.2012 19:32, schrieb Laurent Pointal: >> I started a first translation of my document originally in french. Could >> some fluent english people read it and indicate errors or bad english >> expressions. > > Just one note up front: Languages or nationalities are written with > uppercase letters, like English and French. Other common faults of that > category are days of the week (Monday..) and month names (January..), > although that's irrelevant for your doc. I modified slightly the page, to have first links in the page for document downloading (and other links deeper in the page). > Another thing I noticed that was missing was that the "in" keyword can > not only be used to iterate over a sequence (for i in seq:...) but also > to test if something is contained in a sequence (if i in seq:...). I reworked the second page to have less informations about string formating (nice, but less important than operations on containers), and add sections on containers, lists, dictionaries and set. > "don't miss to close file after use": Use a "with" statement. Added as a note. > "see verso for string formatting..." - what is "verso"? Modified with Paul indications (its the "other side" in french - from latin). > "dont" -> "don't" Done. > "char strings" -> "strings" (in the context of indexing, byte strings > have the same syntax) Modified (even if I dont teach byte strings with my students). > "with several else if, else if..." - there is no "else if" but "elif". Modified (it was originally a translation from french, but the correcpondance between english version and keywords can be confusing). > "block else for other cases" - this sounds as if it was blocking the > else. Maybe "else-block for other cases", but English hyphenation is > complicated and I'm not sure. Modified to "else block..." Thanks for your reading and comments. A+ Laurent. -- Laurent POINTAL - laurent.pointal at laposte.net From jugurtha.hadjar at gmail.com Wed Jun 6 13:23:19 2012 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Wed, 06 Jun 2012 18:23:19 +0100 Subject: English version for =?ISO-8859-1?Q?M=E9mento_Python_3_?= =?ISO-8859-1?Q?=28draft=2C_readers_needed=29?= In-Reply-To: <4fce42ba$0$2028$426a74cc@news.free.fr> References: <4fce42ba$0$2028$426a74cc@news.free.fr> Message-ID: <4FCF9207.3090908@gmail.com> On 06/05/2012 06:32 PM, Laurent Pointal wrote: > Hello, > > I started a first translation of my document originally in french. Could > some fluent english people read it and indicate errors or bad english > expressions. > > http://perso.limsi.fr/pointal/python:memento > > Thanks. > A+ > Laurent. > Very nice ! Some additions.. "formating" --> "formatting" In the french version: "Parcours des index de la s?quence" .. In the english one "Go over sequence's index" .. I think it would be"Go over sequence's indexes". In the upper left corner, the "sigma" sign for the sum of the squares. i=1, i=100... It should be "100" alone, not "i=100". The "i" is written only on the bottom of sigma. "strings formating" --> "string formatting" "range returns a ? generator ?, convert it to list to see.." --> "converts" instead of "convert". "frequently used in for iterative loops" --> .. I think it should be "frequently used in "for" iterative loops" .. It is confusing if there are no quotes, because "for" is a meaningful english word.. So specifying you are talking about the reserved word would be nice. "storage of data on disk, and read back" --> maybe something like "storing data on disk, and reading it back". "memorisation" --> "memorization" (most used spelling). "initialisation" --> "initialization" Thanks you, -- ~Jugurtha Hadjar, From ramit.prasad at jpmorgan.com Wed Jun 6 13:54:24 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 6 Jun 2012 17:54:24 +0000 Subject: file pointer array In-Reply-To: <4fcd8f0b$0$11109$c3e8da3@news.astraweb.com> References: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> <4fcd8f0b$0$11109$c3e8da3@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D83C7A@SCACMX008.exchad.jpmchase.net> > > > > I have a simple question. I wish to generate an array of file pointers. > > For example, I have files: > > > > data1.txt > > data2.txt > > data3.txt > > .... > > > > I wish to generate fine pointer array so that I can read the files at > > the same time. > > > > for index in range(N): > > fid[index] = open('data%d.txt' % index,'r') > You can let the files be closed by the garbage collector, but there is no > guarantee that this will happen in a timely manner. Best practice is to > close them manually once you are done. I personally prefer to use context managers when possible. Not sure it will work for you, but I would probably just read all data into memory first by doing. I imagine file access would be faster read all at once rather than switching between files unless you have very large files. data= [] for index in range(N, 1): # see Chris Rebert's comment with open('data%d.txt' % index,'r') as f: data.append( f.readlines() ) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From nobody at nowhere.com Wed Jun 6 14:20:55 2012 From: nobody at nowhere.com (Nobody) Date: Wed, 06 Jun 2012 19:20:55 +0100 Subject: Compare 2 times References: Message-ID: On Wed, 06 Jun 2012 05:50:02 -0700, loial wrote: > I have a requirement to test the creation time of a file with the current > time and raise a message if the file is more than 15 minutes old. > > Platform is Unix. > > I have looked at using os.path.getctime for the file creation time and > time.time() for the current time, but is this the best approach? Most Unix filesystems don't store a "creation" time. From joncle at googlemail.com Wed Jun 6 14:28:53 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 06 Jun 2012 19:28:53 +0100 Subject: file pointer array In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47412D83C7A@SCACMX008.exchad.jpmchase.net> References: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> <4fcd8f0b$0$11109$c3e8da3@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47412D83C7A@SCACMX008.exchad.jpmchase.net> Message-ID: <4FCFA165.201@googlemail.com> On 06/06/12 18:54, Prasad, Ramit wrote: > data= [] > for index in range(N, 1): # see Chris Rebert's comment > with open('data%d.txt' % index,'r') as f: > data.append( f.readlines() ) > I think "data.extend(f)" would be a better choice. Jon. From joncle at googlemail.com Wed Jun 6 14:28:53 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 06 Jun 2012 19:28:53 +0100 Subject: file pointer array In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47412D83C7A@SCACMX008.exchad.jpmchase.net> References: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> <4fcd8f0b$0$11109$c3e8da3@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47412D83C7A@SCACMX008.exchad.jpmchase.net> Message-ID: <4FCFA165.201@googlemail.com> On 06/06/12 18:54, Prasad, Ramit wrote: > data= [] > for index in range(N, 1): # see Chris Rebert's comment > with open('data%d.txt' % index,'r') as f: > data.append( f.readlines() ) > I think "data.extend(f)" would be a better choice. Jon. From ramit.prasad at jpmorgan.com Wed Jun 6 14:44:20 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 6 Jun 2012 18:44:20 +0000 Subject: file pointer array In-Reply-To: <4FCFA165.201@googlemail.com> References: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> <4fcd8f0b$0$11109$c3e8da3@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47412D83C7A@SCACMX008.exchad.jpmchase.net> <4FCFA165.201@googlemail.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D83D78@SCACMX008.exchad.jpmchase.net> > > data= [] > > for index in range(N, 1): # see Chris Rebert's comment > > with open('data%d.txt' % index,'r') as f: > > data.append( f.readlines() ) > > > > I think "data.extend(f)" would be a better choice. Wouldn't that concatenate the data from each file rather than keeping each file's data separate? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From python at mrabarnett.plus.com Wed Jun 6 14:45:22 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Jun 2012 19:45:22 +0100 Subject: English version for =?ISO-8859-1?Q?M=E9mento_Python_3_?= =?ISO-8859-1?Q?=28draft=2C_readers_needed=29?= In-Reply-To: <4FCF9207.3090908@gmail.com> References: <4fce42ba$0$2028$426a74cc@news.free.fr> <4FCF9207.3090908@gmail.com> Message-ID: <4FCFA542.5010806@mrabarnett.plus.com> On 06/06/2012 18:23, Jugurtha Hadjar wrote: [snip] > "range returns a ? generator ?, convert it to list to see.." --> > "converts" instead of "convert". > No, "convert" is correct here; it's the imperative, i.e. "convert it to a list if you want to see...". > "frequently used in for iterative loops" --> .. I think it should be > "frequently used in "for" iterative loops" .. It is confusing if there > are no quotes, because "for" is a meaningful english word.. So > specifying you are talking about the reserved word would be nice. > > "storage of data on disk, and read back" --> maybe something like > "storing data on disk, and reading it back". > > "memorisation" --> "memorization" (most used spelling). > > "initialisation" --> "initialization" > Some use "s", others use "z". As long as it's consistent, I wouldn't worry too much about it. From python at mrabarnett.plus.com Wed Jun 6 14:51:03 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Jun 2012 19:51:03 +0100 Subject: file pointer array In-Reply-To: <4FCFA165.201@googlemail.com> References: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> <4fcd8f0b$0$11109$c3e8da3@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47412D83C7A@SCACMX008.exchad.jpmchase.net> <4FCFA165.201@googlemail.com> Message-ID: <4FCFA697.5030706@mrabarnett.plus.com> On 06/06/2012 19:28, Jon Clements wrote: > On 06/06/12 18:54, Prasad, Ramit wrote: >> data= [] >> for index in range(N, 1): # see Chris Rebert's comment >> with open('data%d.txt' % index,'r') as f: >> data.append( f.readlines() ) >> > > I think "data.extend(f)" would be a better choice. > .extend does something different, and "range(N, 1)" is an empty range if N > 0. From bahamutzero8825 at gmail.com Wed Jun 6 15:08:54 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 06 Jun 2012 14:08:54 -0500 Subject: English version for =?UTF-8?B?TcOpbWVudG8gUHl0aG9uIDMgKGRyYWY=?= =?UTF-8?B?dCwgcmVhZGVycyBuZWVkZWQp?= In-Reply-To: <4FCFA542.5010806@mrabarnett.plus.com> References: <4fce42ba$0$2028$426a74cc@news.free.fr> <4FCF9207.3090908@gmail.com> <4FCFA542.5010806@mrabarnett.plus.com> Message-ID: <4FCFAAC6.9040508@gmail.com> On 6/6/2012 1:45 PM, MRAB wrote: > On 06/06/2012 18:23, Jugurtha Hadjar wrote: > [snip] >> "range returns a ? generator ?, convert it to list to see.." --> >> "converts" instead of "convert". >> > No, "convert" is correct here; it's the imperative, i.e. "convert it to > a list if you want to see...". > >> "frequently used in for iterative loops" --> .. I think it should be >> "frequently used in "for" iterative loops" .. It is confusing if there >> are no quotes, because "for" is a meaningful english word.. So >> specifying you are talking about the reserved word would be nice. >> >> "storage of data on disk, and read back" --> maybe something like >> "storing data on disk, and reading it back". >> >> "memorisation" --> "memorization" (most used spelling). >> >> "initialisation" --> "initialization" >> > Some use "s", others use "z". As long as it's consistent, I wouldn't > worry too > much about it. https://en.wikipedia.org/wiki/American_and_British_English_spelling_differences American English is more common, but either is acceptable as long as it's consistent. -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From joncle at googlemail.com Wed Jun 6 15:10:01 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 06 Jun 2012 20:10:01 +0100 Subject: file pointer array In-Reply-To: <4FCFA697.5030706@mrabarnett.plus.com> References: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> <4fcd8f0b$0$11109$c3e8da3@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47412D83C7A@SCACMX008.exchad.jpmchase.net> <4FCFA165.201@googlemail.com> <4FCFA697.5030706@mrabarnett.plus.com> Message-ID: <4FCFAB09.2020407@googlemail.com> On 06/06/12 19:51, MRAB wrote: > On 06/06/2012 19:28, Jon Clements wrote: >> On 06/06/12 18:54, Prasad, Ramit wrote: >>> data= [] >>> for index in range(N, 1): # see Chris Rebert's comment >>> with open('data%d.txt' % index,'r') as f: >>> data.append( f.readlines() ) >>> >> >> I think "data.extend(f)" would be a better choice. >> > .extend does something different, and "range(N, 1)" is an empty range > if N > 0. Mea culpa - I had it in my head the OP wanted to treat the files as one contiguous one. So yeah: # something equiv to... (unless it is definitely a fixed range in which # case (x)range can be used) data = [ list(open(fname)) for fname in iglob('/home/jon/data*.txt') ] # then if they ever need to treat it as a contiguous sequence... all_data = list(chain.from_iterable(data)) Jon. From joncle at googlemail.com Wed Jun 6 15:10:01 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 06 Jun 2012 20:10:01 +0100 Subject: file pointer array In-Reply-To: <4FCFA697.5030706@mrabarnett.plus.com> References: <3a49268e-4db7-4513-8c2f-52a29947b551@w24g2000vby.googlegroups.com> <4fcd8f0b$0$11109$c3e8da3@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF47412D83C7A@SCACMX008.exchad.jpmchase.net> <4FCFA165.201@googlemail.com> <4FCFA697.5030706@mrabarnett.plus.com> Message-ID: <4FCFAB09.2020407@googlemail.com> On 06/06/12 19:51, MRAB wrote: > On 06/06/2012 19:28, Jon Clements wrote: >> On 06/06/12 18:54, Prasad, Ramit wrote: >>> data= [] >>> for index in range(N, 1): # see Chris Rebert's comment >>> with open('data%d.txt' % index,'r') as f: >>> data.append( f.readlines() ) >>> >> >> I think "data.extend(f)" would be a better choice. >> > .extend does something different, and "range(N, 1)" is an empty range > if N > 0. Mea culpa - I had it in my head the OP wanted to treat the files as one contiguous one. So yeah: # something equiv to... (unless it is definitely a fixed range in which # case (x)range can be used) data = [ list(open(fname)) for fname in iglob('/home/jon/data*.txt') ] # then if they ever need to treat it as a contiguous sequence... all_data = list(chain.from_iterable(data)) Jon. From jugurtha.hadjar at gmail.com Wed Jun 6 15:35:57 2012 From: jugurtha.hadjar at gmail.com (Jugurtha Hadjar) Date: Wed, 06 Jun 2012 20:35:57 +0100 Subject: English version for =?ISO-8859-1?Q?M=E9mento_Python_3_?= =?ISO-8859-1?Q?=28draft=2C_readers_needed=29?= In-Reply-To: <4FCFA542.5010806@mrabarnett.plus.com> References: <4fce42ba$0$2028$426a74cc@news.free.fr> <4FCF9207.3090908@gmail.com> <4FCFA542.5010806@mrabarnett.plus.com> Message-ID: <4FCFB11D.30803@gmail.com> On 06/06/2012 07:45 PM, MRAB wrote: > On 06/06/2012 18:23, Jugurtha Hadjar wrote: > [snip] >> "range returns a ? generator ?, convert it to list to see.." --> >> "converts" instead of "convert". >> > No, "convert" is correct here; it's the imperative, i.e. "convert it to > a list if you want to see...". My bad. I didn't understand it that way because of the comma before it. -- ~Jugurtha Hadjar, From tjreedy at udel.edu Wed Jun 6 15:52:08 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Jun 2012 15:52:08 -0400 Subject: ttk.Spinbox missing? In-Reply-To: <28745ccb-4d88-4aa8-9c54-cc55f438d207@m3g2000vbl.googlegroups.com> References: <28745ccb-4d88-4aa8-9c54-cc55f438d207@m3g2000vbl.googlegroups.com> Message-ID: On 6/6/2012 9:06 AM, Mark Summerfield wrote: > I have Python 3.2 with Tcl/Tk 8.5, but there doesn't seem to be a > ttk.Spinbox widget even though that widget is part of Tcl/Tk 8.5: > http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_spinbox.htm > > Why is that? My guess is that Spinbox was not present when tkinter.ttk was written (perhaps back in 8.4+tile days). I presume the intention has been to expand the set of themed widgets. Or perhaps it was simply overlooked. I suggest you open an issue on the tracker: "Update tkinter.ttk" and put 'gpolo' and 'terry.reedy' on the nosy list. If you can, check if anything else is missing and put a list in the message. If you look at the formulaic code for other ttk widgets in tkinter.ttk.py and you understand the Spinbox doc you referenced, http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_spinbox.htm and that of one of the other ttk widgets, you should be able to contribute a patch. -- Terry Jan Reedy From alec at arlross.demon.co.uk Wed Jun 6 16:10:38 2012 From: alec at arlross.demon.co.uk (Alec Ross) Date: Wed, 6 Jun 2012 21:10:38 +0100 Subject: English version for Mémento Python 3 (draft, readers needed) References: <4fce42ba$0$2028$426a74cc@news.free.fr> <4fcf9108$0$16471$426a74cc@news.free.fr> Message-ID: In message <4fcf9108$0$16471$426a74cc at news.free.fr>, Laurent Pointal writes >Ulrich Eckhardt wrote: > >> Am 05.06.2012 19:32, schrieb Laurent Pointal: ... > >> "see verso for string formatting..." - what is "verso"? > >Modified with Paul indications (its the "other side" in french - from >latin). > FWIW, English idiomatic usage includes "see overleaf", and "see over", for the obverse side of a page/sheet, i.e, the following page; and "see facing page", w/ the obvious meaning. Alec -- Alec Ross From tkacvins at gmail.com Wed Jun 6 16:19:08 2012 From: tkacvins at gmail.com (Tom Kacvinsky) Date: Wed, 6 Jun 2012 13:19:08 -0700 (PDT) Subject: Need to build Python 2.6 with Microsoft Visual Studio 2010 Message-ID: For reasons beyond my control, I have a need to build Python 2.6 with MSVC 2010 (for x64). Does anyone have any hints as to how I can accomplish this? I see there are instructions for building Python 2.7 with MSVC 2010, but those are using the Python 2.7 source as the base for patching, so they do me little to no good. My main tripping point right now is the deprecation of vcbuild (replaced by msbuild). I can run msbuild on the 2.6 solution files: msbuild PCbuild\pcbuild.sln /p:Configuration="Release" / p:platform="x64" but I get all sorts of errors, related to vcbuild not being available. Will this be as simple as getting the project/solution files up to date for MSVC 2010, or am I going to have to patch a lot of code? Any and all help is much appreciated Thanks in advance, Tom From malaclypse2 at gmail.com Wed Jun 6 16:56:16 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 6 Jun 2012 16:56:16 -0400 Subject: =?UTF-8?Q?Re=3A_English_version_for_M=C3=A9mento_Python_3_=28draft=2C_re?= =?UTF-8?Q?aders_needed=29?= In-Reply-To: References: <4fce42ba$0$2028$426a74cc@news.free.fr> <4fcf9108$0$16471$426a74cc@news.free.fr> Message-ID: On Wed, Jun 6, 2012 at 4:10 PM, Alec Ross wrote: > FWIW, English idiomatic usage includes "see overleaf", and "see over", for > the obverse side of a page/sheet, i.e, the following page; and "see facing > page", w/ the obvious meaning. For what it's worth, I've never seen either of those constructs ("see overleaf" and "see over"). Are they perhaps more common in a particular academic context, or possibly more common in places that use "British English" spellings rather than "American English"? Typically I've just seen "see other side", or (very occasionally) "see reverse" and "see obverse". Jerry From diego.uribe.gamez at gmail.com Wed Jun 6 17:04:41 2012 From: diego.uribe.gamez at gmail.com (Diego Uribe Gamez) Date: Wed, 6 Jun 2012 16:04:41 -0500 Subject: =?ISO-8859-1?Q?Documentaci=F3n_desde_la_terminal_de_comandos=2E?= Message-ID: Una pregunta, como puedo listar todas las librer?as que puedo importar a un .py? y de sus clases? en la terminal de Linux Debian, algo as? como cuando listo todos los programas usando "# aptitude search nombre" Se que entro a otra terminal usando "# Python" Gracias -- *Diego Alonso Uribe Gamez* ------------------------------ *Desarrollador web* Twitter: @DiegoUG Google+: http://gplus.to/diegoug ------------------------------ -------------- next part -------------- An HTML attachment was scrubbed... URL: From news1234 at free.fr Wed Jun 6 17:09:22 2012 From: news1234 at free.fr (News123) Date: Wed, 06 Jun 2012 23:09:22 +0200 Subject: How to exec() a string like interactive python does? In-Reply-To: <4fce96b9$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <4fce8430$0$6476$426a74cc@news.free.fr> <4fce96b9$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4fcfc703$0$1719$426a34cc@news.free.fr> On 06/06/2012 01:31 AM, Steven D'Aprano wrote: > On Wed, 06 Jun 2012 00:12:00 +0200, News123 wrote: > >> If I start Python in interactive mode, and I yype the commands, >> 'a=3', 'a', 'print a' >> >> >> Then the output would look like: >> >>> a = 3 >> >>> a >> 3 >> >>> print a >> 3 >> >> >> Now within an application I'd like to achieve exactly this behaviour > > Before you reinvent the wheel, see the cmd and code modules. > > http://docs.python.org/library/cmd.html > http://docs.python.org/library/code.html Thanks a lot. The cmd library looks great at a first glance However somehow I fail to get it working (meaning, that it executes following strings identical to the python interactive shell 'a = 3' 'a' 'print a' It reports errors for each line, The code snippet I tried: > import cmd > > class MyCmd(cmd.Cmd): > pass > > my_cmd = MyCmd() > my_cmd.cmdloop() I assume the part, that I don't understand is Cmd.identchars and the concept of a command prefix. Perhaps it's the fact, that my native language is not English, but folowing sentence doesn't make a lot of sense to me: " A command is parsed out of each line by collecting the prefix composed of characters in the identchars member." It almost seems as if the part of executing valid 'python strings' is missing and had to be added manually to the default() method > help(cmd) > Interpreters constructed with this class obey the following conventions: > > 1. End of file on input is processed as the command 'EOF'. > 2. A command is parsed out of each line by collecting the prefix composed > of characters in the identchars member. > 3. A command `foo' is dispatched to a method 'do_foo()'; the do_ method > is passed a single argument consisting of the remainder of the line. > 4. Typing an empty line repeats the last command. (Actually, it calls the > method `emptyline', which may be overridden in a subclass.) > 5. There is a predefined `help' method. Given an argument `topic', it > calls the command `help_topic'. With no arguments, it lists all topics > with defined help_ functions, broken into up to three topics; documented > commands, miscellaneous help topics, and undocumented commands. > 6. The command '?' is a synonym for `help'. The command '!' is a synonym > for `shell', if a do_shell method exists. > 7. If completion is enabled, completing commands will be done automatically, > and completing of commands args is done by calling complete_foo() with > arguments text, line, begidx, endidx. text is string we are matching > against, all returned matches must begin with it. line is the current > input line (lstripped), begidx and endidx are the beginning and end > indexes of the text being matched, which could be used to provide > different completion depending upon which position the argument is in. > > The `default' method may be overridden to intercept commands for which there > is no do_ method. > > The `completedefault' method may be overridden to intercept completions for > commands that have no complete_ method. > > The data member `self.ruler' sets the character used to draw separator lines From diego.uribe.gamez at gmail.com Wed Jun 6 17:12:16 2012 From: diego.uribe.gamez at gmail.com (Diego Uribe Gamez) Date: Wed, 6 Jun 2012 16:12:16 -0500 Subject: UDPSock.recvfrom(buf) ??????? (buf) ??? Message-ID: Estoy mirando una conexi?n por Soket y no logro entender que hace el buf? que es lo que cambia? el numero que se le asigna es que? host = "localhost" port = 21567 buf = 1024 data = '' addr = (host, port) UDPSock = socket(AF_INET, SOCK_DGRAM) while (1): data, addr = UDPSock.recvfrom(buf) -- *Diego Alonso Uribe Gamez* ------------------------------ *Desarrollador web* Twitter: @DiegoUG Google+: http://gplus.to/diegoug ------------------------------ -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Wed Jun 6 17:17:19 2012 From: d at davea.name (Dave Angel) Date: Wed, 06 Jun 2012 17:17:19 -0400 Subject: Searching 2 Strings in A File In-Reply-To: <63935675.1428309.1339017023327.JavaMail.root@sz0045a.westchester.pa.mail.comcast.net> References: <63935675.1428309.1339017023327.JavaMail.root@sz0045a.westchester.pa.mail.comcast.net> Message-ID: <4FCFC8DF.4050002@davea.name> On 06/06/2012 05:10 PM, dohoang4093 at comcast.net wrote: > hi all, (You forgot to include the list in your reply) > > thanks a lot for your quick response. > > Dave, actually it's a 2 arguments. Sorry, i did not make it clear in my question. I used Ramit's hint and it worked. The code should be as follows: > > pattern = "({0}|{1})".format(x,y) > cmd_line = Popen(["egrep", pattern, aLogFile], stdout=PIPE, stdin=PIPE, stderr=STDOUT) > > Regards, > > Do Nguyen > If it's two arguments, then you need pattern1 and pattern2. But if it works, perhaps egrep is happy with a single argument. -- DaveA From ramit.prasad at jpmorgan.com Wed Jun 6 17:29:23 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 6 Jun 2012 21:29:23 +0000 Subject: Searching 2 Strings in A File In-Reply-To: <4FCFC8DF.4050002@davea.name> References: <63935675.1428309.1339017023327.JavaMail.root@sz0045a.westchester.pa.mail.comcast.net> <4FCFC8DF.4050002@davea.name> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D84EC3@SCACMX008.exchad.jpmchase.net> > > Dave, actually it's a 2 arguments. Sorry, i did not make it clear in my > question. I used Ramit's hint and it worked. The code should be as follows: > > > > pattern = "({0}|{1})".format(x,y) > > cmd_line = Popen(["egrep", pattern, aLogFile], stdout=PIPE, stdin=PIPE, > stderr=STDOUT) > > > > Regards, > > > > Do Nguyen > > > > If it's two arguments, then you need pattern1 and pattern2. > > But if it works, perhaps egrep is happy with a single argument. egrep is happy with a single arugment because '(1|2)' is a regular expression meaning match either 1 or 2. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From colinh at somewhere.invalid Wed Jun 6 18:16:03 2012 From: colinh at somewhere.invalid (Colin Higwell) Date: Wed, 6 Jun 2012 22:16:03 +0000 (UTC) Subject: what gui designer is everyone using References: Message-ID: On Tue, 05 Jun 2012 10:10:17 -0400, Mark R Rivet wrote: > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. I'm using wxGlade,and am very happy with it. From tjreedy at udel.edu Wed Jun 6 18:19:55 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 06 Jun 2012 18:19:55 -0400 Subject: English version for =?UTF-8?B?TcOpbWVudG8gUHl0aG9uIDMgKGRyYWY=?= =?UTF-8?B?dCwgcmVhZGVycyBuZWVkZWQp?= In-Reply-To: References: <4fce42ba$0$2028$426a74cc@news.free.fr> <4fcf9108$0$16471$426a74cc@news.free.fr> Message-ID: On 6/6/2012 4:56 PM, Jerry Hill wrote: > On Wed, Jun 6, 2012 at 4:10 PM, Alec Ross wrote: >> FWIW, English idiomatic usage includes "see overleaf", and "see over", for >> the obverse side of a page/sheet, i.e, the following page; and "see facing >> page", w/ the obvious meaning. > > For what it's worth, I've never seen either of those constructs ("see > overleaf" and "see over"). Are they perhaps more common in a > particular academic context, or possibly more common in places that > use "British English" spellings rather than "American English"? > Typically I've just seen "see other side", or (very occasionally) "see > reverse" and "see obverse". While this nice document is intended to be printed on two sides of one card or sheet, it may also get printed on two sheets. 'see page 1' and 'see page 2' will work either way -- Terry Jan Reedy From colinh at somewhere.invalid Wed Jun 6 18:21:16 2012 From: colinh at somewhere.invalid (Colin Higwell) Date: Wed, 6 Jun 2012 22:21:16 +0000 (UTC) Subject: usenet reading References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: On Sun, 03 Jun 2012 16:25:53 +0200, Matej Cepl wrote: > Yes, Pan is better, but it used to have some rough edges > (e.g., it's offline qualities were a bit elusive) I wouldn't know about that. My connection is always-on. From ironfroggy at gmail.com Wed Jun 6 18:37:44 2012 From: ironfroggy at gmail.com (Calvin Spealman) Date: Wed, 6 Jun 2012 18:37:44 -0400 Subject: ANN: Tracerlib 0.1 Released Message-ID: Tracerlib is a set of utilities to make tracing Python code easier. It provides TracerManager, which can allow multiple trace functions to coexist. It can easily be enabled and disabled, either manually or as a context manager in a with statement. Tracer classes make handling the different trace events much easier. class TraceExceptions(Tracer): def trace_exception(self, func_name, exctype, value, tb): print "Saw an exception: %r" % (value,) Tracer is also easily capable of filtering which events it listens to. It accepts both an events parameter, a list of trace events it will respond to, and a watch parameter, a list of paths it will respond to in the form of package.module.class.function. This can easily wrap a trace function, or you can subclass Tracer and implement one of its helpful trace_*() methods. And, a helper class FrameInspector which wraps a frame and makes it trivial to inspect the function name and arguments the function had been called with. inspector = FrameInspector(sys._getframe()) print "Called", inspector.func_name print "args:", inspector.args print "kwargs:", inspector.kwargs You can read the full documentation at the read the docs site and see the code at github. http://tracerlib.readthedocs.org https://github.com/ironfroggy/tracerlib From joncle at googlemail.com Wed Jun 6 18:48:40 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 06 Jun 2012 23:48:40 +0100 Subject: Compare 2 times In-Reply-To: References: Message-ID: <4FCFDE48.7060402@googlemail.com> On 06/06/12 14:39, Christian Heimes wrote: > Am 06.06.2012 14:50, schrieb loial: >> I have a requirement to test the creation time of a file with the >> current time and raise a message if the file is more than 15 minutes >> old. >> >> Platform is Unix. >> >> I have looked at using os.path.getctime for the file creation time and >> time.time() for the current time, but is this the best approach? > > Lots of people are confused by ctime because they think 'c' stands for > change. That's wrong. st_ctime is status change time. The ctime is > updated when you change (for example) owner or group of a file, create a > hard link etc. POSIX has no concept of creation time stamp. > > Christian I haven't thought this through too much, but perhaps an ugly "work-around" would be to use inotify (in some kind of daemon) to watch for the IN_CREATE events and store the crtime in a personal DB. Then possibly look at some sort of scheduling to fulfil what happens after 15 minutes. I'm sure there's subtleties I'm missing, but just thought it could be useful. Jon. From joncle at googlemail.com Wed Jun 6 18:48:40 2012 From: joncle at googlemail.com (Jon Clements) Date: Wed, 06 Jun 2012 23:48:40 +0100 Subject: Compare 2 times In-Reply-To: References: Message-ID: <4FCFDE48.7060402@googlemail.com> On 06/06/12 14:39, Christian Heimes wrote: > Am 06.06.2012 14:50, schrieb loial: >> I have a requirement to test the creation time of a file with the >> current time and raise a message if the file is more than 15 minutes >> old. >> >> Platform is Unix. >> >> I have looked at using os.path.getctime for the file creation time and >> time.time() for the current time, but is this the best approach? > > Lots of people are confused by ctime because they think 'c' stands for > change. That's wrong. st_ctime is status change time. The ctime is > updated when you change (for example) owner or group of a file, create a > hard link etc. POSIX has no concept of creation time stamp. > > Christian I haven't thought this through too much, but perhaps an ugly "work-around" would be to use inotify (in some kind of daemon) to watch for the IN_CREATE events and store the crtime in a personal DB. Then possibly look at some sort of scheduling to fulfil what happens after 15 minutes. I'm sure there's subtleties I'm missing, but just thought it could be useful. Jon. From python at mrabarnett.plus.com Wed Jun 6 18:59:51 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 06 Jun 2012 23:59:51 +0100 Subject: UDPSock.recvfrom(buf) ??????? (buf) ??? In-Reply-To: References: Message-ID: <4FCFE0E7.2080100@mrabarnett.plus.com> On 06/06/2012 22:12, Diego Uribe Gamez wrote: > Estoy mirando una conexi?n por Soket y no logro entender que hace el > buf? que es lo que cambia? el numero que se le asigna es que? > > |host= "localhost" > > port= 21567 > > buf= 1024 > > data= '' > > addr= (host, port) > > UDPSock = socket(AF_INET, SOCK_DGRAM)| > > |while (1): > > data, addr = UDPSock.recvfrom(buf)| > 'buf' is the size of the buffer. 'recvfrom' reads at most 'buf' bytes ('bufsize' would be a better name) and returns them as the bytestring 'data'. From tim.wintle at teamrubber.com Wed Jun 6 19:18:37 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 07 Jun 2012 00:18:37 +0100 Subject: English version for =?ISO-8859-1?Q?M=E9mento?= Python 3 (draft, readers needed) In-Reply-To: References: <4fce42ba$0$2028$426a74cc@news.free.fr> <4fcf9108$0$16471$426a74cc@news.free.fr> Message-ID: <1339024717.13262.3.camel@tim-laptop> On Wed, 2012-06-06 at 16:56 -0400, Jerry Hill wrote: > For what it's worth, I've never seen either of those constructs ("see > overleaf" and "see over"). Are they perhaps more common in a > particular academic context, or possibly more common in places that > use "British English" spellings rather than "American English"? Perhaps - "overleaf" is relatively common in documents here - while filling out forms, in exam papers, etc. However a quick search suggests the usage is in British and American dictionaries with the same meaning. Tim From rurpy at yahoo.com Wed Jun 6 22:42:36 2012 From: rurpy at yahoo.com (Rurpy) Date: Wed, 6 Jun 2012 19:42:36 -0700 (PDT) Subject: [Python-ideas] changing sys.stdout encoding Message-ID: <1339036956.89626.YahooMailClassic@web161506.mail.bf1.yahoo.com> On 06/06/2012 10:09 AM, MRAB wrote: > On 06/06/2012 08:09, Rurpy wrote: >> On 06/05/2012 05:56 PM, MRAB wrote: >>> On 06/06/2012 00:34, Victor Stinner wrote: >>>> 2012/6/5 Rurpy: >>>>> In my first foray into Python3 I've encountered this problem: >>>>> I work in a multi-language environment. I've written a number >>>>> of tools, mostly command-line, that generate output on stdout. >>>>> Because these tools and their output are used by various people >>>>> in varying environments, the tools all have an --encoding option >>>>> to provide output that meets the needs and preferences of the >>>>> output's ultimate consumers. [snip] >>>>> In converting them to Python3, I found the best (if not very >>>>> pleasant) way to do this in Python3 was to put something like >>>>> this near the top of each tool[*1]: >>>>> >>>>> import codecs >>>>> sys.stdout = codecs.getwriter(opts.encoding)(sys.stdout.buffer) >>>> >>> In Python 3, you should use io.TextIOWrapper instead of >>> codecs.StreamWriter. It's more efficient and has less bugs. >>> > >>>> What I want to be able to put there instead is: > >>>> > >>>> sys.stdout.set_encoding (opts.encoding) [snip] >>> And if you _do_ want multiple encodings in a file, it's clearer to open >>> the file as binary and then explicitly encode to bytes and write _that_ >>> to the file. >> >> But is it really? >> >> The following is very simple and the level of python >> expertise required is minimal. It (would) works fine >> with redirection. One could substitute any other ordinary >> open (for write) text file for sys.stdout. >> >> [off the top of my head] >> text = 'This is %s text: ??????????' >> sys.stdout.set_encoding ('sjis') >> print (text % 'sjis') >> sys.stdout.set_encoding ('euc-jp') >> print (text % 'euc-jp') >> sys.stdout.set_encoding ('iso2022-jp') >> print (text % 'iso2022-jp') >> >> As for your suggestion, how do I reopen sys.stdout in >> binary mode? I don't need to do that often and don't >> know off the top of my head. (And it's too late for >> me to look it up.) And what happens to redirected output >> when I close and reopen the stream? I can open a regular >> filename instead. But remember to make the last two >> opens with "a" rather than "w". And don't forget the >> "\n" at the end of the text line. >> >> Could you show me an code example of your suggestion >> for comparison? >> >> Disclaimer: As I said before, I am not particularly >> advocating for a for a set_encoding() method -- my >> primary suggestion is a programatic way to change the >> sys.std* encodings prior to first use. Here I am just >> questioning the claim that a set_encoding() method >> would not be clearer than existing alternatives. >> > This example accesses the underlying binary output stream: > > > # -*- coding: utf-8 -*- > > import sys > > class Writer: > def __init__(self, output): > self.output = output > self.encoding = output.encoding > def write(self, string): > self.output.buffer.write(string.encode(self.encoding)) > def set_encoding(self, encoding): > self.output.buffer.flush() > self.encoding = encoding > > sys.stdout = Writer(sys.stdout) > > initial_encoding = sys.stdout.encoding > > text = 'This is %s text: ??????????' > sys.stdout.set_encoding('utf-8') > print (text % 'utf-8') > sys.stdout.set_encoding('sjis') > print (text % 'sjis') > sys.stdout.set_encoding('euc-jp') > print (text % 'euc-jp') > sys.stdout.set_encoding('iso2022-jp') > print (text % 'iso2022-jp') > > sys.stdout.set_encoding(initial_encoding) OK, let's see if I've got this right... You take a duplicate of my code, add a class with three methods and some other statements and you claim the result is clearer and simpler than my code? That is, union (A, B) is simpler than A? Interesting definition of simpler you've got there :-) From tyevans at gmail.com Wed Jun 6 23:49:38 2012 From: tyevans at gmail.com (t_texas) Date: Wed, 6 Jun 2012 20:49:38 -0700 (PDT) Subject: Compare 2 times References: Message-ID: <5bc8f150-4a1f-401c-9bc5-79ea1e1baac9@h9g2000yqi.googlegroups.com> On Jun 6, 7:50?am, loial wrote: > I have a requirement to test the creation time of a file with the > current time and raise a message if the file is ?more than 15 minutes > old. > > Platform is Unix. > > I have looked at using os.path.getctime for the file creation time and > time.time() for the current time, but is this the best approach? Unless you are using ext4 you are going to have to store the creation time yourself. If the files are coming from your application, use the sqlite3 or shelve module to store the creation time for each file then check that data to determine which files are more than 15 minutes old. If the files are being generated from another application or from users, have your application check the directory every minute and record any new files. Worst case scenario, a file will be present for 16 minutes vs 15. From ben+python at benfinney.id.au Thu Jun 7 00:28:27 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 07 Jun 2012 14:28:27 +1000 Subject: Adopting =?utf-8?B?4oCYbG9ja2ZpbGXigJk=?= References: <874nu5nywc.fsf@benfinney.id.au> <87ty1sgma4.fsf@benfinney.id.au> Message-ID: <87pq9b21as.fsf@benfinney.id.au> Ben Finney writes: > Thanks for the suggestion. I've imported it from Subversion into Bazaar > (my preferred DVCS), and it went smoothly. Development of ?python-lockfile? now proceeds on Alioth . > I will proceed with a handover from Skip for maintenance of ?lockfile?. > > This will definitely need more people than me to maintain, though! Thanks to Aaron Maxwell for joining the development team, with initial progress to a Python 3 port of the library. > I am interested and motivated to work on the Linux platform, but other > platforms will suffer unless I get co-maintainers with experience in > the different file locking semantics there. We still need people capable of working with this library on non-Linux platforms. Join the development discussion mailing list if you can offer us assistance with this. -- \ ?I was trying to daydream, but my mind kept wandering.? ?Steven | `\ Wright | _o__) | Ben Finney From aldrich.demata at gmail.com Thu Jun 7 00:32:55 2012 From: aldrich.demata at gmail.com (Aldrich DeMata) Date: Wed, 6 Jun 2012 23:32:55 -0500 Subject: problem python In-Reply-To: <1338981904.49606.YahooMailNeo@web113912.mail.gq1.yahoo.com> References: <1338981904.49606.YahooMailNeo@web113912.mail.gq1.yahoo.com> Message-ID: Python can't find site.py. It's either missing when you installed python, it was deleted, or it's located in another directory. Run >>> find / -iname 'site.py' , sudo if needed, and add the location of site.py in your python search path. The python online docs has a good documentation on python search path: http://docs.python.org/install/index.html#search-path On Wed, Jun 6, 2012 at 6:25 AM, Tom King wrote: > hi im new in python and i have a problem about > when i type python in my command line console i get an error message > > > 'import site' failed; use -v for traceback > Python 2.4.3 (#1, May 5 2011, 18:44:23) > [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> > > what is going on and how i can fix it > thanks in andvance > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cpr.17a at gmail.com Thu Jun 7 01:55:30 2012 From: cpr.17a at gmail.com (Phanindra Ramesh Challa) Date: Thu, 7 Jun 2012 11:25:30 +0530 Subject: KeyError: '13' In-Reply-To: References: Message-ID: I got metatype compiled. Thanks for your help On Wed, Jun 6, 2012 at 6:44 PM, Peter Otten <__peter__ at web.de> wrote: > Phanindra Ramesh Challa wrote: > > [Please hit "reply-all" in you email client when you answer a post. That > way > it will appear on the mailing list and give more people a chance to answer] > > > output of the is just the line > > "sizes". > > >> and then decide if you to need to change the lookup key or to add > records > >> to the database. > >> > > How can I add recors to the database? > > The Python part of the answer is > > db[some_key] = some_value > > but I fear that won't help. Google suggests you are struggling with the > metatype project If so, there seems to be a corresponding mk_db.py that you > can use. I don't know anything about metatype, but the comment in mk_db.py > at > > http://metatype.cvs.sourceforge.net/viewvc/metatype/metatype/mk_db.py?revision=1.3&view=markup > > tells to run it like so: > > find . -name '*.ugs' | python mk_db.py -a glyphlist -o dbmfile > > Perhaps you ran it, but there weren't any *.ugs files? > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Jun 7 04:15:56 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 7 Jun 2012 01:15:56 -0700 Subject: =?UTF-8?Q?Re=3A_Documentaci=C3=B3n_desde_la_terminal_de_comandos=2E?= In-Reply-To: References: Message-ID: 2012/6/6 Diego Uribe Gamez > > Una pregunta, como puedo listar todas las?librer?as?que puedo importar a > un .py? y de sus clases? en la terminal de Linux Debian, algo?as??como > cuando listo todos los programas usando "# aptitude search nombre" > > Se que entro a otra terminal usando "# Python" > > Gracias > > -- > ?Diego Alonso Uribe Gamez Hola Diego, Esta lista de correo (python-list) es en ingl?s. Recomiendo que usted le pregunte a python-es (http://mail.python.org/mailman/listinfo/python-es ), que es la lista equivalente pero en espa?ol. (Lo siento por mi espa?ol malo.) Adios, Chris From stanigator at gmail.com Thu Jun 7 05:33:43 2012 From: stanigator at gmail.com (Stanley Lee) Date: Thu, 7 Jun 2012 02:33:43 -0700 (PDT) Subject: Career related question Message-ID: Hey all, Can I only post jobs on Python's official website, or can I also direct the message to the appropriate mailing list in http://mail.python.org/ ? Btw, do I have to be a subscriber of a given list in order to submit messages? Thanks in advance, Stanley From davidgshi at yahoo.co.uk Thu Jun 7 06:05:10 2012 From: davidgshi at yahoo.co.uk (David Shi) Date: Thu, 7 Jun 2012 11:05:10 +0100 (BST) Subject: Where is the lastest step by step guide to compile Python into an executable? Message-ID: <1339063510.4959.YahooMailNeo@web171603.mail.ir2.yahoo.com> Hi, folks. Where is the lastest step by step guide to compile Python into an executable? Regards. David -------------- next part -------------- An HTML attachment was scrubbed... URL: From jdmorgan at unca.edu Thu Jun 7 08:09:36 2012 From: jdmorgan at unca.edu (jdmorgan) Date: Thu, 07 Jun 2012 08:09:36 -0400 Subject: next alpha sequence value from var pointing to array Message-ID: <4FD09A00.5000306@gmail.com> Hello, I am still fairly new to python, but find it to be a great scripting language.Here is my issue: I am attempting to utilize a function to receive any sequence of letter characters and return to me the next value in alphabetic order e.g. send in "abc" get back "abd".I found a function on StackExchange (Rosenfield, A 1995) that seems to work well enough (I think): /def next(s):/ /strip_zs = s.rstrip('z')/ /if strip_zs:/ /return strip_zs[:-1] + chr(ord(strip_zs[-1]) + 1) + 'a' * (len(s) - len(strip_zs))/ /else:/ /return 'a' * (len(s) + 1)/ I have found this function works well if I call it directly with a string enclosed in quotes: returnValue = next("abc") However, if I call the function with a variable populated from a value I obtain from an array[] it fails returning only ^K Unfortunately, because I don't fully understand this next function I can't really interpret the error.Any help would be greatly appreciated. Thanks ahead of time, Derek -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Jun 7 08:23:47 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jun 2012 22:23:47 +1000 Subject: Career related question In-Reply-To: References: Message-ID: On Thu, Jun 7, 2012 at 7:33 PM, Stanley Lee wrote: > Hey all, > > Can I only post jobs on Python's official website, or can I also > direct the message to the appropriate mailing list in http://mail.python.org/ > ? Btw, do I have to be a subscriber of a given list in order to submit > messages? Job postings are frowned upon here on the list; the job board is the appropriate place (assuming that it's a definitely Python-related job). You normally have to be subscribed to the list to post, since responses are usually going to also be on-list; but python-list cross-communicates with the newsgroup comp.lang.python, so you can be on either (and there are web-based newsgroup readers too). Chris Angelico From __peter__ at web.de Thu Jun 7 08:59:40 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jun 2012 14:59:40 +0200 Subject: next alpha sequence value from var pointing to array References: <4FD09A00.5000306@gmail.com> Message-ID: jdmorgan wrote: > Hello, Welcome! > I am still fairly new to python, but find it to be a great scripting > language.Here is my issue: > > I am attempting to utilize a function to receive any sequence of letter > characters and return to me the next value in alphabetic order e.g. send > in "abc" get back "abd".I found a function on StackExchange (Rosenfield, > A 1995) that seems to work well enough (I think): Please don't try to be clever about formatting your mail. Use text only. > /def next(s):/ > > /strip_zs = s.rstrip('z')/ > > /if strip_zs:/ > > /return strip_zs[:-1] + chr(ord(strip_zs[-1]) + 1) + 'a' * (len(s) - > len(strip_zs))/ > > /else:/ > > /return 'a' * (len(s) + 1)/ This should be def next_alpha(s): strip_zs = s.rstrip('z') if strip_zs: return (strip_zs[:-1] + chr(ord(strip_zs[-1]) + 1) + 'a' * (len(s) - len(strip_zs))) else: return 'a' * (len(s) + 1) (I renamed the function because next() already is a built-in function since Python 2.6) The function removes all lowercase "z" letters from the end of the string. If the rest is empty like for next_alpha("zzz") it returns len(s) + 1 "a"s, or "aaaa" in the example. If the rest is not empty, e.g for next_alpha("abcz") it replaces the last non-"z" character with its successor in the alphabet >>> chr(ord("c")+1) 'd' and replaces the trailing "z"s with the same number of trailing "a"s. > I have found this function works well if I call it directly with a > string enclosed in quotes: > > returnValue = next("abc") > > However, if I call the function with a variable populated from a value I > obtain from an array[] it fails returning only ^K I'm assuming that something is missing here, but if the function actually returns the string "^K" that is the expected result for >>> next_alpha("^J") '^K' The function only handles lowercase letters a...z correctly. > Unfortunately, because I don't fully understand this next function I > can't really interpret the error.Any help would be greatly appreciated. What is the actual value you pass to the function? Add print statements argument = ... # your code print argument return_value = next_alpha(argument) print return_value and post what is printed. If you get a traceback, e. g. >>> next_alpha([]) Traceback (most recent call last): File "", line 1, in File "next_alpha.py", line 2, in next_alpha strip_zs = s.rstrip('z') AttributeError: 'list' object has no attribute 'rstrip' cut and paste it, and post it here, too From jdmorgan at unca.edu Thu Jun 7 09:25:18 2012 From: jdmorgan at unca.edu (jdmorgan) Date: Thu, 07 Jun 2012 09:25:18 -0400 Subject: next alpha sequence value from var pointing to array Message-ID: <4FD0ABBE.1090601@gmail.com> Hi Peter, Thanks for you feedback. I have the next_alpha function you have provided. But, am still getting the same result. The actual value I am passing in is "btl". But, as I mentioned I am getting it from an array value. Here is my actual code. I am reading a comma separated file, getting the last item and trying to get the next alpha. Thanks again. def getNRTLid(layerName): lids_seen = [] lyrs_seen = [] last_lid = "" f = open("NRTLayerLID.csv", "r"); for line in f: sp = line.split(',') lyrs_seen.append(sp[0]) lids_seen.append(sp[1]) f.close(); sorted_array = sorted(lids_seen) sorted_array.reverse() print "highest lid is %s" % sorted_array[0] highest_lid = sorted_array[0] test = highest_lid.lower() nl = next_alpha(test) Best, Derek From __peter__ at web.de Thu Jun 7 10:03:05 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jun 2012 16:03:05 +0200 Subject: next alpha sequence value from var pointing to array References: <4FD0ABBE.1090601@gmail.com> Message-ID: jdmorgan wrote: > Hi Peter, > > Thanks for you feedback. I have the next_alpha function you have > provided. But, am still getting the same result. > The actual value I am passing in is "btl". But, as I mentioned I am > getting it from an array value. Note that what you are calling an array is (somewhat confusingly) called "list" in Python. Still, it doesn't matter where you get it from if you are actually passing the string "btl" to next_alpha() the result should be "btm". > Here is my actual code. There seems to be missing something at the end of the function... > I am reading a comma separated file, getting the last item and trying to > get the next alpha. Thanks again. > > > def getNRTLid(layerName): > lids_seen = [] > lyrs_seen = [] > last_lid = "" > f = open("NRTLayerLID.csv", "r"); > for line in f: > sp = line.split(',') > lyrs_seen.append(sp[0]) > lids_seen.append(sp[1]) > f.close(); > sorted_array = sorted(lids_seen) > sorted_array.reverse() > print "highest lid is %s" % sorted_array[0] Change %s to %r in the above. There may be whitespace characters at the end of the string which you can detect that way. print "highest lid is %r" % sorted_array[0] # what does that print? > highest_lid = sorted_array[0] > test = highest_lid.lower() > nl = next_alpha(test) print repr(nl) # what does that print? From davecook at nowhere.net Thu Jun 7 10:33:09 2012 From: davecook at nowhere.net (Dave Cook) Date: 07 Jun 2012 14:33:09 GMT Subject: what gui designer is everyone using References: Message-ID: <4fd0bba5$0$24754$c3e8da3$e408f015@news.astraweb.com> On 2012-06-05, Mark R Rivet wrote: > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. I've been using wxFormBuilder since last summer. It's reasonably easy to use, and there are regular releases by the developers. I have a coworker who's had a lot of success using Boa for everything. It would be a shame if Boa is allowed to bitrot in to complete unuseability. Dave Cook From breamoreboy at yahoo.co.uk Thu Jun 7 11:21:04 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 07 Jun 2012 16:21:04 +0100 Subject: Where is the lastest step by step guide to compile Python into an executable? In-Reply-To: <1339063510.4959.YahooMailNeo@web171603.mail.ir2.yahoo.com> References: <1339063510.4959.YahooMailNeo@web171603.mail.ir2.yahoo.com> Message-ID: On 07/06/2012 11:05, David Shi wrote: > Hi, folks. > > Where is the lastest step by step guide to compile Python into an executable? > > Regards. > > David > > > > Google. -- Cheers. Mark Lawrence. From chris at simplistix.co.uk Thu Jun 7 11:38:32 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 07 Jun 2012 16:38:32 +0100 Subject: xlrd 0.7.8 released! Message-ID: <4FD0CAF8.2070608@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlrd 0.7.8: http://pypi.python.org/pypi/xlrd/0.7.8 This release features the following changes: - Compatibility with Python 2.1 and 2.2 is restored. - Fix for github issue #7: assertion error when reading file with xlwt-written bitmap. The assertion is now ignored and a warning logged if verbosity > 0. - superfluous zero bytes at end of xls OBJECT records are now ignored. For full details, please see the GitHub repository: https://github.com/python-excel/xlrd Barring any packaging issues or serious bugs, this will be the last release in the 0.7 series and the last release supporting Python 2.1 and 2.2. The next release, likely in a couple of weeks time, will be 0.8.0 targeting Python 2.6 and upwards and featuring support for reading data from .xlsx files (although not formatting, unless some sponsorship or patches turn up). If you're interested in this, it would be great if you could try out the master branch and let us know if you find any problems: https://github.com/python-excel/xlrd There's also details of all things Python and Excel related here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From juliosergio at gmail.com Thu Jun 7 12:04:42 2012 From: juliosergio at gmail.com (Julio Sergio) Date: Thu, 7 Jun 2012 16:04:42 +0000 (UTC) Subject: Interprocess comunication Message-ID: I'm trying to call an external process to filter some of my data, i.e., I'm trying to pass some information to the called process, and have this information back transformed. I started testing with the linux 'cat' command, in this way: ->>> import subprocess as sp ->>> p = sp.Popen(["cat"],stdin=sp.PIPE,stdout=sp.PIPE,close_fds=True) ->>> (fi,fo) = (p.stdin, p.stdout) ->>> fi.write("SOMETHING\n") ->>> fi.flush() ->>> fo.readline() 'SOMETHING\n' ->>> fi.write("OTHER\n") ->>> fi.flush() ->>> fo.readline() 'OTHER\n' ->>> fi.write("NEXT\n") ->>> fi.flush() ->>> fo.readline() 'NEXT\n' ->>> fi.write("NEXT1\n") ->>> fi.flush() ->>> s = fo.readline() ->>> s 'NEXT1\n' Up to this point it worked as expected. However, when I tryied with the methods that write and read several lines, apparently the process got stalled: ->>> fi.writelines(["uno\n","dos\n","tres\n"]) ->>> fi.flush() ->>> s = fo.readlines() . . . Do you have any comments on this? Thanks, --Sergio From oscar.benjamin at bristol.ac.uk Thu Jun 7 12:25:20 2012 From: oscar.benjamin at bristol.ac.uk (Oscar Benjamin) Date: Thu, 7 Jun 2012 17:25:20 +0100 Subject: Interprocess comunication In-Reply-To: References: Message-ID: On 7 June 2012 17:04, Julio Sergio wrote: > I'm trying to call an external process to filter some of my data, i.e., I'm > trying to pass some information to the called process, and have this > information > back transformed. I started testing with the linux 'cat' command, in this > way: > > > ->>> import subprocess as sp > ->>> p = sp.Popen(["cat"],stdin=sp.PIPE,stdout=sp.PIPE,close_fds=True) > ->>> (fi,fo) = (p.stdin, p.stdout) > ->>> fi.write("SOMETHING\n") > ->>> fi.flush() > ->>> fo.readline() > 'SOMETHING\n' > ->>> fi.write("OTHER\n") > ->>> fi.flush() > ->>> fo.readline() > 'OTHER\n' > ->>> fi.write("NEXT\n") > ->>> fi.flush() > ->>> fo.readline() > 'NEXT\n' > ->>> fi.write("NEXT1\n") > ->>> fi.flush() > ->>> s = fo.readline() > ->>> s > 'NEXT1\n' > > Up to this point it worked as expected. However, when I tryied with the > methods > that write and read several lines, apparently the process got stalled: > > ->>> fi.writelines(["uno\n","dos\n","tres\n"]) > ->>> fi.flush() > ->>> s = fo.readlines() > The readlines() method is intended to read an entire file and split it into lines, so it blocks until EOF is found. If you want to use readlines(), you should first close the subprocesses stdin: >>> fi.writelines(["uno\n","dos\n","tres\n"]) >>> fi.flush() >>> fi.close() >>> s = fo.readlines() Although now you can no longer use the subprocess for reading or writing. If that is not what you want in your actual problem then you'll need to avoid readlines(). > . > . > . > > Do you have any comments on this? > > Thanks, > > --Sergio > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Jun 7 12:29:02 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 07 Jun 2012 17:29:02 +0100 Subject: Interprocess comunication In-Reply-To: References: Message-ID: <4FD0D6CE.7050102@mrabarnett.plus.com> On 07/06/2012 17:04, Julio Sergio wrote: > I'm trying to call an external process to filter some of my data, i.e., I'm > trying to pass some information to the called process, and have this information > back transformed. I started testing with the linux 'cat' command, in this way: > > > ->>> import subprocess as sp > ->>> p = sp.Popen(["cat"],stdin=sp.PIPE,stdout=sp.PIPE,close_fds=True) > ->>> (fi,fo) = (p.stdin, p.stdout) > ->>> fi.write("SOMETHING\n") > ->>> fi.flush() > ->>> fo.readline() > 'SOMETHING\n' > ->>> fi.write("OTHER\n") > ->>> fi.flush() > ->>> fo.readline() > 'OTHER\n' > ->>> fi.write("NEXT\n") > ->>> fi.flush() > ->>> fo.readline() > 'NEXT\n' > ->>> fi.write("NEXT1\n") > ->>> fi.flush() > ->>> s = fo.readline() > ->>> s > 'NEXT1\n' > > Up to this point it worked as expected. However, when I tryied with the methods > that write and read several lines, apparently the process got stalled: > > ->>> fi.writelines(["uno\n","dos\n","tres\n"]) > ->>> fi.flush() > ->>> s = fo.readlines() > . > . > . > > Do you have any comments on this? > I believe it's waiting for the end of the input, i.e. for the pipe to close. Have you tried calling fo.readline() 3 times instead? From jcd at sdf.lonestar.org Thu Jun 7 12:30:40 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Thu, 07 Jun 2012 12:30:40 -0400 Subject: Interprocess comunication In-Reply-To: References: Message-ID: <1339086640.3077.1.camel@jcdyer-laptop> On Thu, 2012-06-07 at 16:04 +0000, Julio Sergio wrote: > Up to this point it worked as expected. However, when I tryied with the methods > that write and read several lines, apparently the process got stalled: > > ->>> fi.writelines(["uno\n","dos\n","tres\n"]) > ->>> fi.flush() > ->>> s = fo.readlines() > . > . > . readlines() reads all the lines from the filehandle, but the filehandle hasn't signalled that it is done writing lines, so fo is waiting until fi is complete. You either need to keep reading one line at a time, and manually release control when there's nothing more to read, or you need to do an fi.close() before you try to use fo.readlines(). From juliosergio at gmail.com Thu Jun 7 12:39:55 2012 From: juliosergio at gmail.com (Julio Sergio) Date: Thu, 7 Jun 2012 16:39:55 +0000 (UTC) Subject: Interprocess comunication References: <4FD0D6CE.7050102@mrabarnett.plus.com> Message-ID: MRAB mrabarnett.plus.com> writes: > > I believe it's waiting for the end of the input, i.e. for the pipe to > close. > > Have you tried calling fo.readline() 3 times instead? > yeah! It worked!... A question remains: what is then the purpose of fo.readlines(...)? Thanks, --Sergio From juliosergio at gmail.com Thu Jun 7 12:45:01 2012 From: juliosergio at gmail.com (Julio Sergio) Date: Thu, 7 Jun 2012 16:45:01 +0000 (UTC) Subject: Interprocess comunication References: <1339086640.3077.1.camel@jcdyer-laptop> Message-ID: J. Cliff Dyer sdf.lonestar.org> writes: > > readlines() reads all the lines from the filehandle, but the filehandle > hasn't signalled that it is done writing lines, so fo is waiting until > fi is complete. You either need to keep reading one line at a time, and > manually release control when there's nothing more to read, or you need > to do an fi.close() before you try to use fo.readlines(). > > Thanks... It worked as you said. Here is how I coded it: ->>> fi.writelines(["uno\n","dos\n","tres\n"]) ->>> fi.close() ->>> l = fo.readlines() ->>> l ['uno\n', 'dos\n', 'tres\n'] --Sergio From jcd at sdf.lonestar.org Thu Jun 7 12:56:56 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Thu, 07 Jun 2012 12:56:56 -0400 Subject: Interprocess comunication In-Reply-To: References: <4FD0D6CE.7050102@mrabarnett.plus.com> Message-ID: <1339088216.3077.4.camel@jcdyer-laptop> It is for reading all the lines from a complete file. If the file is still being written to, it doesn't have an end yet. File objects do many things besides RPC. Also, there are instances where all you want to do is block until the file is done, and then get all the content. readlines will do that, too. On Thu, 2012-06-07 at 16:39 +0000, Julio Sergio wrote: > MRAB mrabarnett.plus.com> writes: > > > > > I believe it's waiting for the end of the input, i.e. for the pipe to > > close. > > > > Have you tried calling fo.readline() 3 times instead? > > > > yeah! It worked!... > A question remains: what is then the purpose of fo.readlines(...)? > > Thanks, > --Sergio > > > > From lamialily at cleverpun.com Thu Jun 7 13:39:11 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Thu, 07 Jun 2012 10:39:11 -0700 Subject: Career related question In-Reply-To: References: Message-ID: On Thu, 7 Jun 2012 22:23:47 +1000, Chris Angelico wrote: >On Thu, Jun 7, 2012 at 7:33 PM, Stanley Lee wrote: >> Hey all, >> >> Can I only post jobs on Python's official website, or can I also >> direct the message to the appropriate mailing list in http://mail.python.org/ >> ? Btw, do I have to be a subscriber of a given list in order to submit >> messages? > >Job postings are frowned upon here on the list; the job board is the >appropriate place (assuming that it's a definitely Python-related >job). You normally have to be subscribed to the list to post, since >responses are usually going to also be on-list; but python-list >cross-communicates with the newsgroup comp.lang.python, so you can be >on either (and there are web-based newsgroup readers too). > >Chris Angelico From what I've seen, the cross-communication isn't working properly - it's all one-way, and nobody's done anything to look into it yet. Or, failing that, there's just some intercommunication problems between the NNTP servers and the mailing list just samples from multiple sources... ~Temia -- The amazing programming device: fuelled entirely by coffee, it codes while awake and tests while asleep! From __peter__ at web.de Thu Jun 7 13:42:31 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jun 2012 19:42:31 +0200 Subject: Interprocess comunication References: <1339086640.3077.1.camel@jcdyer-laptop> Message-ID: Julio Sergio wrote: > J. Cliff Dyer sdf.lonestar.org> writes: > >> >> readlines() reads all the lines from the filehandle, but the filehandle >> hasn't signalled that it is done writing lines, so fo is waiting until >> fi is complete. You either need to keep reading one line at a time, and >> manually release control when there's nothing more to read, or you need >> to do an fi.close() before you try to use fo.readlines(). >> >> > > Thanks... It worked as you said. Here is how I coded it: > > ->>> fi.writelines(["uno\n","dos\n","tres\n"]) > ->>> fi.close() > ->>> l = fo.readlines() > ->>> l > ['uno\n', 'dos\n', 'tres\n'] I believe this may hang on the fi.writelines(...) line if you write "too much" data. >From the subprocess documentation: """ Warning Use communicate() rather than .stdin.write, .stdout.read or .stderr.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process. """ From no at spam.com Thu Jun 7 14:48:54 2012 From: no at spam.com (Steve) Date: Thu, 7 Jun 2012 19:48:54 +0100 Subject: Why does this leak memory? Message-ID: When I run this program: import configparser, sys, gc def test(): config=configparser.ConfigParser() #del(config) #gc.collect() test() sys.stderr.write(sys.version) gc.set_debug(gc.DEBUG_LEAK|gc.DEBUG_STATS) It reports: 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)]gc: collecting generation 2... gc: objects in each generation: 453 258 4553 gc: collectable gc: collectable gc: collectable gc: collectable <_Link 02713300> gc: collectable gc: collectable gc: collectable gc: collectable <_Link 02713350> gc: collectable gc: collectable gc: collectable gc: collectable <_Link 02713378> gc: collectable gc: collectable gc: collectable gc: collectable gc: collectable <_Link 02713328> gc: collectable gc: collectable gc: done, 19 unreachable, 0 uncollectable, 0.0000s elapsed. The leaks can be removed by uncommenting both lines shown. This strikes me as very odd behaviour. Can anyone explain it, or is it a bug? Thanks, S. From tim at akwebsoft.com Thu Jun 7 14:55:25 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Thu, 7 Jun 2012 10:55:25 -0800 Subject: Installing MySQLdb via FTP? Message-ID: <20120607185525.GH7630@mail.akwebsoft.com> Is it possible to install MySQLdb via FTP? 1)I have a hostmonster account with SSH. I have been able to log in and install MySQLdb from the shell. Works fine. 2)Now I have a client who wants to have a hostmonster account and we will need MySQLdb. I *will not* have SSH access since (as I understand it) hostmonster allows SSH access from 1 IP only. 3)The hostmonster account services (I.E. cpanel) does not have any service to do this. 4)I wouldn't need to make the install on PYTHONPATH as my resources will handle sys.path configuration. This isn't an immediate need so URLs and pointers to relevant discussions would suffice. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From miki.tebeka at gmail.com Thu Jun 7 15:05:41 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 7 Jun 2012 12:05:41 -0700 (PDT) Subject: what gui designer is everyone using In-Reply-To: References: Message-ID: <8398c6e5-3cd3-41e0-aaba-f8c074623f2f@googlegroups.com> > what is the gui designer that is most popular? IIRC Qt designer can output Python code. From jtkells at verizon.net Thu Jun 7 16:20:47 2012 From: jtkells at verizon.net (jkells) Date: Thu, 07 Jun 2012 20:20:47 GMT Subject: Python libraries portable? Message-ID: We are new to developing applications with Python. A question came up concerning Python libraries being portable between Architectures. More specifically, can we take a python library that runs on a X86 architecture and run it on a SPARC architecture or do we need to get the native libraries for SPARC? Thanking you in advance From gordon at panix.com Thu Jun 7 16:46:29 2012 From: gordon at panix.com (John Gordon) Date: Thu, 7 Jun 2012 20:46:29 +0000 (UTC) Subject: Why does this leak memory? References: Message-ID: In "Steve" writes: > gc: objects in each generation: 453 258 4553 > gc: collectable > gc: collectable > gc: collectable > gc: collectable <_Link 02713300> > gc: collectable > gc: collectable > gc: collectable > gc: collectable <_Link 02713350> > gc: collectable > gc: collectable > gc: collectable > gc: collectable <_Link 02713378> > gc: collectable > gc: collectable > gc: collectable > gc: collectable > gc: collectable <_Link 02713328> > gc: collectable > gc: collectable > gc: done, 19 unreachable, 0 uncollectable, 0.0000s elapsed. > The leaks can be removed by uncommenting both lines shown. > This strikes me as very odd behaviour. Can anyone explain it, or is it a > bug? I'm unfamiliar with gc output, but just glancing over it I don't see anything that looks like a leak. It reported that there were 19 objects which are unreachable and therefore are candidates for being collected. What makes you think there is a leak? -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From kw at codebykevin.com Thu Jun 7 17:18:37 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 07 Jun 2012 17:18:37 -0400 Subject: what gui designer is everyone using In-Reply-To: References: Message-ID: On 6/5/12 10:10 AM, Mark R Rivet wrote: > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. None. I write GUI code by hand (Tkinter). -- Kevin Walzer Code by Kevin http://www.codebykevin.com From corey at octayn.net Thu Jun 7 18:03:36 2012 From: corey at octayn.net (Corey Richardson) Date: Thu, 7 Jun 2012 18:03:36 -0400 Subject: Python libraries portable? In-Reply-To: References: Message-ID: <20120607180336.3834acce@Ulysses.myhome.westell.com> On Thu, 07 Jun 2012 20:20:47 GMT jkells wrote: > We are new to developing applications with Python. A question came > up concerning Python libraries being portable between > Architectures. More specifically, can we take a python library > that runs on a X86 architecture and run it on a SPARC architecture or > do we need to get the native libraries for SPARC? > Pure-python libraries should run wherever Python does, if it doesn't, that's a bug. C extensions to CPython shouldn't have any platform incompatibilities, but of course you'll need to recompile. -- Corey Richardson From ian.g.kelly at gmail.com Thu Jun 7 18:31:02 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Jun 2012 16:31:02 -0600 Subject: Why does this leak memory? In-Reply-To: References: Message-ID: On Thu, Jun 7, 2012 at 12:48 PM, Steve wrote: > The leaks can be removed by uncommenting both lines shown. That's just a matter of timing. You call the function before you call set_debug, so when you uncomment the lines, the garbage collector is explicitly run before the debug flags are set. When it runs again later, there are no collectable objects for it to find, as they've already been collected. With the lines commented, the garbage collector doesn't get run until after the set_debug call, so it finds the collectable objects at that time. Either way the objects get collected sooner or later, so I don't see any leaks here. Cheers, Ian From ian.g.kelly at gmail.com Thu Jun 7 18:41:27 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Jun 2012 16:41:27 -0600 Subject: Why does this leak memory? In-Reply-To: References: Message-ID: For comparison, here is what a leaking program would look like: class Foo(object): def __init__(self, other=None): if other is None: other = Foo(self) self.other = other def __del__(self): pass import gc gc.set_debug(gc.DEBUG_STATS | gc.DEBUG_LEAK) for i in range(5): foo = Foo() del foo gc.collect() print "len(gc.garbage) ==", len(gc.garbage) gc: collecting generation 2... gc: objects in each generation: 167 3363 0 gc: uncollectable gc: uncollectable gc: uncollectable gc: uncollectable gc: done, 4 unreachable, 4 uncollectable, 0.0000s elapsed. len(gc.garbage) == 4 gc: collecting generation 2... gc: objects in each generation: 4 0 3463 gc: uncollectable gc: uncollectable gc: uncollectable gc: uncollectable gc: done, 4 unreachable, 4 uncollectable, 0.0000s elapsed. len(gc.garbage) == 8 gc: collecting generation 2... gc: objects in each generation: 4 0 3467 gc: uncollectable gc: uncollectable gc: uncollectable gc: uncollectable gc: done, 4 unreachable, 4 uncollectable, 0.0000s elapsed. len(gc.garbage) == 12 gc: collecting generation 2... gc: objects in each generation: 4 0 3471 gc: uncollectable gc: uncollectable gc: uncollectable gc: uncollectable gc: done, 4 unreachable, 4 uncollectable, 0.0000s elapsed. len(gc.garbage) == 16 gc: collecting generation 2... gc: objects in each generation: 4 0 3475 gc: uncollectable gc: uncollectable gc: uncollectable gc: uncollectable gc: done, 4 unreachable, 4 uncollectable, 0.0000s elapsed. len(gc.garbage) == 20 gc: collecting generation 2... gc: objects in each generation: 0 0 3475 gc: done, 0.0000s elapsed. Note that on each iteration, it reports only the four new uncollectable objects, not any of the previous uncollectable objects, because when they are found to be uncollectable they are added to gc.garbage and so become reachable again. Cheers, Ian From tismer at stackless.com Thu Jun 7 18:51:16 2012 From: tismer at stackless.com (Christian Tismer) Date: Fri, 08 Jun 2012 00:51:16 +0200 Subject: tiffany 0.3 released Message-ID: <4FD13064.7060401@stackless.com> # coding=utf-8 Tiffany - Read/Write Multipage-Tiff with PIL without PIL ======================================================== Tiffany stands for any tiff. The tiny module solves a large set of problems, has no dependencies and just works wherever Python works. Tiffany was developed in the course of the *DiDoCa* project and will now appear on PyPi. Abstract ======== During the development of *DiDoCa* (Distributed Document Capture) we were confronted with the problem to read multipage Tiff scans. The GUI toolkit *PySide (Qt)* does support Tiff, but only shows the first page. We also had to support Fax compression (CCITT G3/G4), but *Qt* supports this. As a first approach we copied single pages out of multi-page tiff files using *tiffcp* or *tiffutil* (OS X) as a temp file for display. A sub-optimum solution, especially for data security reasons. The second approach replaced this by a tiny modification of the linkage of the tiff directories (IFD). This way, a tiff file could be patched in memory with the wanted page offset and then be shown without any files involved. Unfortunately also this solution was not satisfactory: - out tiff files have anomalies in their tiff tags like too many null-bytes and wrong tag order, - Qt's implementation of tiff is over-pedantic and ignores all tags after the smalles error. Being a good friend of *Fredrik Lundh* and his *PIL* since years, I tried to attach the problem using this. Sadly Fredrik hasn't worked much on this since 2006, and the situation is slightly messed up: *PIL* has a clean-up of tiff tags, but cannot cope with fax compression by default. There exists a patch since many years, but this complicates the build process and pulls with *libtiff* a lot of dependencies in. Furthermore, *PIL* is unable to write fax compressed files, but blows the data up to the full size, making this approach only a half solution as well. After a longer odyssey I saw then the light of a Tiffany lamp: I use only a hand-full of *PIL*s files, without any modification, pretend to unpack a tiff file, but actually cheating. Only the tiff tags are nicely processed and streamlined, but the compressed data is taken unmodified as-is. When writing a tiff page out, the existing data is just assembled in the correct order. For many projects like *didoca* that are processing tiff files without editing their contents, this is a complete solution of their tiff problem. The dependencies of the project stay minimal, there are no binaries required, and Tiffany is with less than 300 lines remarkably small. Because just 5 files from *PIL* are used and the _imaging module is not compiled at all, I'm talking about "PIL without PIL" ;-) Tiffany is a stand-alone module and has no interference with *PIL*. You can see this by looking at ``import_mapper.py``. This module modifies ``__import__`` so that the *PIL* modules appear as top-level internally, but become sub-modules of tiffany in ``sys.modules``. Please let me know if this stuff works for you, and send requests to or use the links in the bitbucket website: https://bitbucket.org/didoca/tiffany cheers -- Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From tim at akwebsoft.com Thu Jun 7 19:09:36 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Thu, 7 Jun 2012 15:09:36 -0800 Subject: Python libraries portable? In-Reply-To: <20120607180336.3834acce@Ulysses.myhome.westell.com> References: <20120607180336.3834acce@Ulysses.myhome.westell.com> Message-ID: <20120607230936.GA43227@mail.akwebsoft.com> * Corey Richardson [120607 14:19]: > On Thu, 07 Jun 2012 20:20:47 GMT > jkells wrote: > > > We are new to developing applications with Python. A question came > > up concerning Python libraries being portable between > > Architectures. More specifically, can we take a python library > > that runs on a X86 architecture and run it on a SPARC architecture or > > do we need to get the native libraries for SPARC? > > > > Pure-python libraries should run wherever Python does, if it doesn't, > that's a bug. C extensions to CPython shouldn't have any platform > incompatibilities, but of course you'll need to recompile. Perhaps this respons to this thread contains a possible solution to my question subject "Installing MySQLdb via FTP?" Does this mean that I could copy my MySQLdb module directly from my workstation via ftp to a server, and have it work, given that sys.path contained the path? -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From corey at octayn.net Thu Jun 7 19:17:13 2012 From: corey at octayn.net (Corey Richardson) Date: Thu, 7 Jun 2012 19:17:13 -0400 Subject: Python libraries portable? In-Reply-To: <20120607230936.GA43227@mail.akwebsoft.com> References: <20120607180336.3834acce@Ulysses.myhome.westell.com> <20120607230936.GA43227@mail.akwebsoft.com> Message-ID: <20120607191713.197ea84b@Ulysses.myhome.westell.com> On Thu, 7 Jun 2012 15:09:36 -0800 Tim Johnson wrote: > Does this mean that I could copy my MySQLdb module directly from > my workstation via ftp to a server, and have it work, given that > sys.path contained the path? > No, absolutely not. MySQLdb is a C extension. Assuming same architecture and shared libraries, it will *probably* work, but no guarantees. If any of those are different, even slightly, it will break. -- Corey Richardson From tim at akwebsoft.com Thu Jun 7 20:43:26 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Thu, 7 Jun 2012 16:43:26 -0800 Subject: Python libraries portable? In-Reply-To: <20120607191713.197ea84b@Ulysses.myhome.westell.com> References: <20120607180336.3834acce@Ulysses.myhome.westell.com> <20120607230936.GA43227@mail.akwebsoft.com> <20120607191713.197ea84b@Ulysses.myhome.westell.com> Message-ID: <20120608004326.GB43227@mail.akwebsoft.com> * Corey Richardson [120607 15:20]: > On Thu, 7 Jun 2012 15:09:36 -0800 > Tim Johnson wrote: > > > Does this mean that I could copy my MySQLdb module directly from > > my workstation via ftp to a server, and have it work, given that > > sys.path contained the path? > > > > No, absolutely not. MySQLdb is a C extension. Assuming same > architecture and shared libraries, it will *probably* work, but no > guarantees. If any of those are different, even slightly, it will break. Yeah, you're right - I knew that and I had forgotten! Sorry. So what to do if I can't install from the command line? I could use python's external command tools like subprocess.call(), but am not sure what the implications would be since privileges might be limited. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From corey at octayn.net Thu Jun 7 20:52:16 2012 From: corey at octayn.net (Corey Richardson) Date: Thu, 7 Jun 2012 20:52:16 -0400 Subject: Python libraries portable? In-Reply-To: <20120608004326.GB43227@mail.akwebsoft.com> References: <20120607180336.3834acce@Ulysses.myhome.westell.com> <20120607230936.GA43227@mail.akwebsoft.com> <20120607191713.197ea84b@Ulysses.myhome.westell.com> <20120608004326.GB43227@mail.akwebsoft.com> Message-ID: <20120607205216.0514ff29@Ulysses.myhome.westell.com> On Thu, 7 Jun 2012 16:43:26 -0800 Tim Johnson wrote: > So what to do if I can't install from the command line? > I could use python's external command tools like > subprocess.call(), but am not sure what the implications would be > since privileges might be limited. > https://github.com/petehunt/PyMySQL/ is your best option, when it comes to using mysql without C extensions. I don't even know if it works, but it's the only one I could fine. -- Corey Richardson From tim at akwebsoft.com Thu Jun 7 21:07:12 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Thu, 7 Jun 2012 17:07:12 -0800 Subject: Python libraries portable? In-Reply-To: <20120607205216.0514ff29@Ulysses.myhome.westell.com> References: <20120607180336.3834acce@Ulysses.myhome.westell.com> <20120607230936.GA43227@mail.akwebsoft.com> <20120607191713.197ea84b@Ulysses.myhome.westell.com> <20120608004326.GB43227@mail.akwebsoft.com> <20120607205216.0514ff29@Ulysses.myhome.westell.com> Message-ID: <20120608010712.GD43227@mail.akwebsoft.com> * Corey Richardson [120607 17:01]: > On Thu, 7 Jun 2012 16:43:26 -0800 > Tim Johnson wrote: > > > So what to do if I can't install from the command line? > > I could use python's external command tools like > > subprocess.call(), but am not sure what the implications would be > > since privileges might be limited. > > > > https://github.com/petehunt/PyMySQL/ is your best option, when it comes > to using mysql without C extensions. I don't even know if it works, but > it's the only one I could fine. Thanks, but I need to add my own thread about how to install on a server without the command line being available? I kind of hijacked this one.. Will post tomorrow. cheers -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From cmpython at gmail.com Thu Jun 7 23:58:09 2012 From: cmpython at gmail.com (CM) Date: Thu, 7 Jun 2012 20:58:09 -0700 (PDT) Subject: what gui designer is everyone using References: Message-ID: <99d32987-2b78-48ff-8fc6-791ddd0ffea6@l5g2000vbo.googlegroups.com> On Jun 5, 10:10?am, Mark R Rivet wrote: > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. Boa Constructor. Very happy with it. Mostly use it for the IDE these days, as it already served to help build the GUI. From rosuav at gmail.com Fri Jun 8 04:09:21 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jun 2012 18:09:21 +1000 Subject: what gui designer is everyone using In-Reply-To: References: Message-ID: On Fri, Jun 8, 2012 at 7:18 AM, Kevin Walzer wrote: > On 6/5/12 10:10 AM, Mark R Rivet wrote: >> >> I want a gui designer that writes the gui code for me. I don't want to >> write gui code. what is the gui designer that is most popular? >> I tried boa-constructor, and it works, but I am concerned about how >> dated it seems to be with no updates in over six years. > > > None. I write GUI code by hand (Tkinter). I don't often build GUIs in Python, but all my GUI code these days is hand-built. The last builder I used would probably have been VX-REXX on OS/2, which doesn't help you much :) But my GTK code has always been hand-made. ChrisA From alister.ware at ntlworld.com Fri Jun 8 04:09:52 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 08 Jun 2012 08:09:52 GMT Subject: Python libraries portable? References: Message-ID: On Thu, 07 Jun 2012 20:20:47 +0000, jkells wrote: > We are new to developing applications with Python. A question came up > concerning Python libraries being portable between Architectures. > More specifically, can we take a python library that runs on a X86 > architecture and run it on a SPARC architecture or do we need to get the > native libraries for SPARC? > > Thanking you in advance That would depend on the particular module if it is a pure python module then it will work anywhere if it is a C module for example cStringIO then it would be architecture dependent. some modules are wrappers to external library's (example GTK) so for those to work the necessary library files would need to be available if you are using modules that are in the standard library (except some platform specific ones ) then they should be available across all platforms, otherwise you would need to check see http://docs.python/library for details of the standard library From alister.ware at ntlworld.com Fri Jun 8 04:11:17 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 08 Jun 2012 08:11:17 GMT Subject: what gui designer is everyone using References: <99d32987-2b78-48ff-8fc6-791ddd0ffea6@l5g2000vbo.googlegroups.com> Message-ID: On Thu, 07 Jun 2012 20:58:09 -0700, CM wrote: > On Jun 5, 10:10?am, Mark R Rivet wrote: >> I want a gui designer that writes the gui code for me. I don't want to >> write gui code. what is the gui designer that is most popular? >> I tried boa-constructor, and it works, but I am concerned about how >> dated it seems to be with no updates in over six years. > > Boa Constructor. Very happy with it. Mostly use it for the IDE these > days, as it already served to help build the GUI. I am using glade at present but I am still in the process of learning From tismer at stackless.com Fri Jun 8 05:16:42 2012 From: tismer at stackless.com (Christian Tismer) Date: Fri, 8 Jun 2012 11:16:42 +0200 Subject: what gui designer is everyone using In-Reply-To: References: <99d32987-2b78-48ff-8fc6-791ddd0ffea6@l5g2000vbo.googlegroups.com> Message-ID: <859A4FE8-EEB8-44B2-B63C-BD89C74A571F@stackless.com> I used wx and Boa years before and Was quite pleased. In these days I switched to Qt with PySide. Qt designer works quite well. If you have the choice, then my recommendation is this. Cheers - chris Sent from my Ei4Steve On Jun 8, 2012, at 8:11, Alister wrote: > On Thu, 07 Jun 2012 20:58:09 -0700, CM wrote: > >> On Jun 5, 10:10 am, Mark R Rivet wrote: >>> I want a gui designer that writes the gui code for me. I don't want to >>> write gui code. what is the gui designer that is most popular? >>> I tried boa-constructor, and it works, but I am concerned about how >>> dated it seems to be with no updates in over six years. >> >> Boa Constructor. Very happy with it. Mostly use it for the IDE these >> days, as it already served to help build the GUI. > > I am using glade at present but I am still in the process of learning > -- > http://mail.python.org/mailman/listinfo/python-list From tismer at stackless.com Fri Jun 8 05:27:44 2012 From: tismer at stackless.com (Christian Tismer) Date: Fri, 8 Jun 2012 11:27:44 +0200 Subject: what gui designer is everyone using In-Reply-To: <8398c6e5-3cd3-41e0-aaba-f8c074623f2f@googlegroups.com> References: <8398c6e5-3cd3-41e0-aaba-f8c074623f2f@googlegroups.com> Message-ID: <7277D5B4-1A7E-4A98-82A6-E3D8B7CF7C2F@stackless.com> Hi Miki, Yes, and this works very well. As a side effect it also serves as a template when you need to change certain things dynamically. You can pick snippets for your Gui dynamication. But as a strong recommendation: never ever change the generated code. Import the generated classes and derive your own on top of it. I even prefer not to derive, but to delegate, to keep my name space tidy. Cheers - chris Sent from my Ei4Steve On Jun 7, 2012, at 21:05, Miki Tebeka wrote: >> what is the gui designer that is most popular? > IIRC Qt designer can output Python code. > -- > http://mail.python.org/mailman/listinfo/python-list From merwin.irc at gmail.com Fri Jun 8 06:10:08 2012 From: merwin.irc at gmail.com (Thibaut DIRLIK) Date: Fri, 8 Jun 2012 12:10:08 +0200 Subject: Order a list to get a hierarchical order Message-ID: Hi, Having a list of objet with a parent_id attribute pointing to a parent, I want to order this list like this : [Parent #1, Child #1.1, Child#1.1.1, Child#1.1.2, Child#1.2, Parent #2, Child #2.1, ...] Any clue on how to do this ? Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From ivars.geidans at gmail.com Fri Jun 8 06:58:54 2012 From: ivars.geidans at gmail.com (Ivars Geidans) Date: Fri, 8 Jun 2012 11:58:54 +0100 Subject: Order a list to get a hierarchical order In-Reply-To: References: Message-ID: Something like this? #!/usr/bin/env python3 import random class Node: def __init__(self, parent, name): self.parent, self.name = parent, name def __repr__(self): return self.name p_1 = Node(None, 'Parent #1') p_2 = Node(None, 'Parent #2') c_1_1 = Node(p_1, 'Child #1.1') c_1_1_1 = Node(c_1_1, 'Child #1.1.1') c_1_1_2 = Node(c_1_1, 'Child #1.1.2') c_1_2 = Node(p_1, 'Child #1.2') c_2_1 = Node(p_2, 'Child #2.1') node_list = [p_1, p_2, c_1_1, c_1_1_1, c_1_1_2, c_1_2, c_2_1] random.shuffle(node_list) print(node_list) def append_node(n, l, ls): ls.append(n) for c in [nc for nc in l if nc.parent is n]: append_node(c, l, ls) return ls def sort_nodes(l): ls = [] for r in l: if r.parent == None: append_node(r, l, ls) return ls print(sort_nodes(node_list)) On Fri, Jun 8, 2012 at 11:10 AM, Thibaut DIRLIK wrote: > Hi, > > Having a list of objet with a parent_id attribute pointing to a parent, I > want to order this list like this : > > [Parent #1, Child #1.1, Child#1.1.1, Child#1.1.2, Child#1.2, Parent #2, > Child #2.1, ...] > > Any clue on how to do this ? > > Thanks, > > -- > http://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Fri Jun 8 07:47:46 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Jun 2012 13:47:46 +0200 Subject: Order a list to get a hierarchical order References: Message-ID: Ivars Geidans wrote: > Something like this? Or this (I'm reusing some of your code but let the built-in sorted() do the hard work): #!/usr/bin/env python3 import random def _reverse_iterpath(node): while node is not None: yield node.name node = node.parent def path(node): return tuple(_reverse_iterpath(node))[::-1] class Node: def __init__(self, parent, name): self.parent = parent self.name = name def __repr__(self): return "/".join(path(self)) def show(caption, node_list): print(caption.center(len(caption)+10, "-")) for node in node_list: print(node) print() if __name__ == "__main__": p_1 = Node(None, 'Parent #1') p_2 = Node(None, 'Parent #2') c_1_1 = Node(p_1, 'Child #1.1') c_1_1_1 = Node(c_1_1, 'Child #1.1.1') c_1_1_2 = Node(c_1_1, 'Child #1.1.2') c_1_2 = Node(p_1, 'Child #1.2') c_2_1 = Node(p_2, 'Child #2.1') node_list = [p_1, p_2, c_1_1, c_1_1_1, c_1_1_2, c_1_2, c_2_1] random.shuffle(node_list) show("before", node_list) show("after", sorted(node_list, key=path)) From __peter__ at web.de Fri Jun 8 08:10:13 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Jun 2012 14:10:13 +0200 Subject: Order a list to get a hierarchical order References: Message-ID: Ivars Geidans wrote: > def append_node(n, l, ls): > ls.append(n) > for c in [nc for nc in l if nc.parent is n]: > append_node(c, l, ls) > return ls > > def sort_nodes(l): > ls = [] > for r in l: > if r.parent == None: > append_node(r, l, ls) > > return ls This ensures that child nodes appear after their parent but leaves the order of nodes on the same level undefined. I think adding def sort_nodes(l): l = sorted(l, key=lambda node: node.name) #untested ... would fix that. From laureote-loic at hotmail.fr Fri Jun 8 08:22:58 2012 From: laureote-loic at hotmail.fr (=?iso-8859-1?B?bG/vYyBMYXVy6W90ZQ==?=) Date: Fri, 8 Jun 2012 14:22:58 +0200 Subject: what gui designer is everyone using In-Reply-To: <7277D5B4-1A7E-4A98-82A6-E3D8B7CF7C2F@stackless.com> References: , <8398c6e5-3cd3-41e0-aaba-f8c074623f2f@googlegroups.com>, <7277D5B4-1A7E-4A98-82A6-E3D8B7CF7C2F@stackless.com> Message-ID: Hi, pyQt is really good for fast graphic GUI designing. Maybe not the best for beginners,cause this can't allow them to understand how to code GUIs. And as said before, for each modification not need to regenerate the code,it's sometimes boring Lo?c > From: tismer at stackless.com > Subject: Re: what gui designer is everyone using > Date: Fri, 8 Jun 2012 11:27:44 +0200 > To: miki.tebeka at gmail.com > CC: python-list at python.org > > Hi Miki, > > Yes, and this works very well. As a side > effect it also serves as a template when > you need to change certain things > dynamically. You can pick snippets for > your Gui dynamication. > > But as a strong recommendation: never > ever change the generated code. Import the generated classes and derive > your own on top of it. > I even prefer not to derive, but to delegate, to keep my name space tidy. > > Cheers - chris > > Sent from my Ei4Steve > > On Jun 7, 2012, at 21:05, Miki Tebeka wrote: > > >> what is the gui designer that is most popular? > > IIRC Qt designer can output Python code. > > -- > > http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From feliphil at gmx.net Fri Jun 8 08:27:21 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Fri, 8 Jun 2012 14:27:21 +0200 Subject: Pythonic cross-platform GUI desingers =?ISO-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: Message-ID: <20120608142721.3ab95cb7.feliphil@gmx.net> > I want a gui designer that writes the gui code for me. I don't want to > write gui code. what is the gui designer that is most popular? > I tried boa-constructor, and it works, but I am concerned about how > dated it seems to be with no updates in over six years. Sorry to "hijack" your thread, but since this is a very related question... What "GUI designer" would come the closest to the way that Cocoa's Interface Builder works? I.e. is there any one (cross-platform) that allows to actually "connect" the GUI created directly to the code and make it available "live" in an IDE? This whole cycle of "design GUI"->"generate code"->add own code to generated code"->"run application with GUI" has always seemed very un-pythonic to me. A dynamic, interpreted language should allow to work in a more "lively", "direct" way to build a GUI. TIA, Sincerely, Wolfgang From merwin.irc at gmail.com Fri Jun 8 09:07:26 2012 From: merwin.irc at gmail.com (Thibaut DIRLIK) Date: Fri, 8 Jun 2012 15:07:26 +0200 Subject: Order a list to get a hierarchical order In-Reply-To: References: Message-ID: Thanks for your help, I'll test this. 2012/6/8 Peter Otten <__peter__ at web.de> > Ivars Geidans wrote: > > > def append_node(n, l, ls): > > ls.append(n) > > for c in [nc for nc in l if nc.parent is n]: > > append_node(c, l, ls) > > return ls > > > > def sort_nodes(l): > > ls = [] > > for r in l: > > if r.parent == None: > > append_node(r, l, ls) > > > > return ls > > This ensures that child nodes appear after their parent but leaves the > order > of nodes on the same level undefined. I think adding > > def sort_nodes(l): > l = sorted(l, key=lambda node: node.name) #untested > ... > > would fix that. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Jun 8 10:52:58 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 08 Jun 2012 10:52:58 -0400 Subject: Python libraries portable? In-Reply-To: References: Message-ID: On 6/8/2012 4:09 AM, Alister wrote: > On Thu, 07 Jun 2012 20:20:47 +0000, jkells wrote: > >> We are new to developing applications with Python. A question came up >> concerning Python libraries being portable between Architectures. >> More specifically, can we take a python library that runs on a X86 >> architecture and run it on a SPARC architecture or do we need to get the >> native libraries for SPARC? >> >> Thanking you in advance > > That would depend on the particular module > if it is a pure python module then it will work anywhere Unless it uses one of the few things that are system dependent. But these are marked in the docs (example: "Abailability: Unix") and are mostly in the os module. An example is os.fork. There are also some system-specific things in the socket module, although it embodies much effort to make things as cross-platform as possible. > if it is a C module for example cStringIO then it would be architecture > dependent. > > some modules are wrappers to external library's (example GTK) so for > those to work the necessary library files would need to be available > > if you are using modules that are in the standard library (except some > platform specific ones ) then they should be available across all > platforms, otherwise you would need to check > > see http://docs.python/library for details of the standard library -- Terry Jan Reedy From laureote-loic at hotmail.fr Fri Jun 8 11:06:16 2012 From: laureote-loic at hotmail.fr (=?iso-8859-1?B?bG/vYyBMYXVy6W90ZQ==?=) Date: Fri, 8 Jun 2012 17:06:16 +0200 Subject: what gui designer is everyone using In-Reply-To: References: , , <8398c6e5-3cd3-41e0-aaba-f8c074623f2f@googlegroups.com>, , <7277D5B4-1A7E-4A98-82A6-E3D8B7CF7C2F@stackless.com>, Message-ID: Hi, pyQt is really good for fast graphic GUI design. Maybe not the best for beginners,cause this can't allow them to understand how to code GUIs. And as said before, for each modification you need to regenerate the code,it's sometimes boring. (sorry) Lo?c From: laureote-loic at hotmail.fr To: python-list at python.org Subject: what gui designer is everyone using Date: Fri, 8 Jun 2012 14:22:58 +0200 Hi, pyQt is really good for fast graphic GUI designing. Maybe not the best for beginners,cause this can't allow them to understand how to code GUIs. And as said before, for each modification not need to regenerate the code,it's sometimes boring Lo?c > From: tismer at stackless.com > Subject: Re: what gui designer is everyone using > Date: Fri, 8 Jun 2012 11:27:44 +0200 > To: miki.tebeka at gmail.com > CC: python-list at python.org > > Hi Miki, > > Yes, and this works very well. As a side > effect it also serves as a template when > you need to change certain things > dynamically. You can pick snippets for > your Gui dynamication. > > But as a strong recommendation: never > ever change the generated code. Import the generated classes and derive > your own on top of it. > I even prefer not to derive, but to delegate, to keep my name space tidy. > > Cheers - chris > > Sent from my Ei4Steve > > On Jun 7, 2012, at 21:05, Miki Tebeka wrote: > > >> what is the gui designer that is most popular? > > IIRC Qt designer can output Python code. > > -- > > http://mail.python.org/mailman/listinfo/python-list > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From cmpython at gmail.com Fri Jun 8 11:11:23 2012 From: cmpython at gmail.com (CM) Date: Fri, 8 Jun 2012 08:11:23 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> Message-ID: <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> On Jun 8, 8:27?am, Wolfgang Keller wrote: > > I want a gui designer that writes the gui code for me. I don't want to > > write gui code. what is the gui designer that is most popular? > > I tried boa-constructor, and it works, but I am concerned about how > > dated it seems to be with no updates in over six years. > > Sorry to "hijack" your thread, but since this is a very related > question... > > What "GUI designer" would come the closest to the way that Cocoa's > Interface Builder works? I.e. is there any one (cross-platform) that > allows to actually "connect" the GUI created directly to the code and > make it available "live" in an IDE? > > This whole cycle of "design GUI"->"generate code"->add own code to > generated code"->"run application with GUI" has always seemed very > un-pythonic to me. A dynamic, interpreted language should allow to work > in a more "lively", "direct" way to build a GUI. > > TIA, > > Sincerely, > > Wolfgang I'm curious about your point but I don't really understand it. Could you try again without using any scare-quoted words? Maybe given an example of creating a small text editor application with a GUI builder/ IDE in this Pythonic way you are hoping for. From no at spam.com Fri Jun 8 12:02:39 2012 From: no at spam.com (Steve) Date: Fri, 8 Jun 2012 17:02:39 +0100 Subject: Why does this leak memory? References: Message-ID: > "John Gordon" wrote in message news:jqr3v5$src$1 at reader1.panix.com... > > I'm unfamiliar with gc output, but just glancing over it I don't see > anything that looks like a leak. It reported that there were 19 objects > which are unreachable and therefore are candidates for being collected. > > What makes you think there is a leak? Well, I guess I was confused by the terminology. I thought there were leaked objects _after_ a garbage collection had been run (as it said "collecting generation 2"). Also, "unreachable" actually appears to mean "unreferenced". You live n learn... Cheers. From juliosergio at gmail.com Fri Jun 8 12:10:15 2012 From: juliosergio at gmail.com (Julio Sergio) Date: Fri, 8 Jun 2012 16:10:15 +0000 (UTC) Subject: About a list comprehension to transform an input list Message-ID: >From a sequence of numbers, I'm trying to get a list that does something to even numbers but leaves untouched the odd ones, say: [0,1,2,3,4,...] ==> [100,1,102,3,104,...] I know that this can be done with an auxiliary function, as follows: ->>> def filter(n): ... if (n%2 == 0): ... return 100+n ... return n ... ->>> L = range(10) ->>> [filter(n) for n in L] [100, 1, 102, 3, 104, 5, 106, 7, 108, 9] I wonder whether there can be a single list comprehension expression to get this result without the aid of the auxiliary function. Do you have any comments on this? Thanks, --Sergio. From urban.dani at gmail.com Fri Jun 8 12:17:14 2012 From: urban.dani at gmail.com (Daniel Urban) Date: Fri, 8 Jun 2012 18:17:14 +0200 Subject: About a list comprehension to transform an input list In-Reply-To: References: Message-ID: On Fri, Jun 8, 2012 at 6:10 PM, Julio Sergio wrote: > >From a sequence of numbers, I'm trying to get a list that does something to even > numbers but leaves untouched the odd ones, say: > > [0,1,2,3,4,...] ==> [100,1,102,3,104,...] > > I know that this can be done with an auxiliary function, as follows: > > ->>> def filter(n): > ... ? ? if (n%2 == 0): > ... ? ? ? ? return 100+n > ... ? ? return n > ... > ->>> L = range(10) > ->>> [filter(n) for n in L] > [100, 1, 102, 3, 104, 5, 106, 7, 108, 9] > > I wonder whether there can be a single list comprehension expression to get this > result without the aid of the auxiliary function. > > Do you have any comments on this? >>> l = [0,1,2,3,4,5,6,7,8,9] >>> [n if n%2 else 100+n for n in l] [100, 1, 102, 3, 104, 5, 106, 7, 108, 9] Daniel From emile at fenx.com Fri Jun 8 12:43:55 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 08 Jun 2012 09:43:55 -0700 Subject: About a list comprehension to transform an input list In-Reply-To: References: Message-ID: On 6/8/2012 9:17 AM Daniel Urban said... > On Fri, Jun 8, 2012 at 6:10 PM, Julio Sergio wrote: >> > From a sequence of numbers, I'm trying to get a list that does something to even >> numbers but leaves untouched the odd ones, say: >> >> [0,1,2,3,4,...] ==> [100,1,102,3,104,...] >> >> I know that this can be done with an auxiliary function, as follows: >> >> ->>> def filter(n): >> ... if (n%2 == 0): >> ... return 100+n >> ... return n >> ... >> ->>> L = range(10) >> ->>> [filter(n) for n in L] >> [100, 1, 102, 3, 104, 5, 106, 7, 108, 9] >> >> I wonder whether there can be a single list comprehension expression to get this >> result without the aid of the auxiliary function. >> >> Do you have any comments on this? > >>>> l = [0,1,2,3,4,5,6,7,8,9] >>>> [n if n%2 else 100+n for n in l] > [100, 1, 102, 3, 104, 5, 106, 7, 108, 9] > Or alternately by leveraging true/false as 1/0: >>> [ 100*(not(ii%2))+ii for ii in range(10)] [100, 1, 102, 3, 104, 5, 106, 7, 108, 9] >>> [ 100*(ii%2)+ii for ii in range(10)] [0, 101, 2, 103, 4, 105, 6, 107, 8, 109] From ian.g.kelly at gmail.com Fri Jun 8 13:04:25 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Jun 2012 11:04:25 -0600 Subject: Why does this leak memory? In-Reply-To: References: Message-ID: On Fri, Jun 8, 2012 at 10:02 AM, Steve wrote: > Well, I guess I was confused by the terminology. I thought there were leaked > objects _after_ a garbage collection had been run (as it said "collecting > generation 2"). That means that it's going to check all objects. The garbage collector divides the objects up into "generations", based on how many collection attempts they've so far survived (due to not being unreachable). For efficiency, higher generation objects are checked less frequently than lower generation objects, and generation 2 is the highest. > Also, "unreachable" actually appears to mean "unreferenced". Not exactly. CPython uses reference counting as well as periodic garbage collection, so an unreferenced object is deallocated immediately. "Unreachable" means that the object is referenced but cannot be reached via direct or indirect reference from any stack frame -- i.e., the object is only referenced in unreachable reference cycles. From ian.g.kelly at gmail.com Fri Jun 8 13:10:42 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Jun 2012 11:10:42 -0600 Subject: About a list comprehension to transform an input list In-Reply-To: References: Message-ID: On Fri, Jun 8, 2012 at 10:43 AM, Emile van Sebille wrote: > Or alternately by leveraging true/false as 1/0: > >>>> [ 100*(not(ii%2))+ii for ii in range(10)] The same thing, leaving bools out of it altogether: >>> [100*(1-ii%2)+ii for ii in range(10)] From ramit.prasad at jpmorgan.com Fri Jun 8 13:36:02 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 8 Jun 2012 17:36:02 +0000 Subject: Installing MySQLdb via FTP? In-Reply-To: <20120607185525.GH7630@mail.akwebsoft.com> References: <20120607185525.GH7630@mail.akwebsoft.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D88F57@SCACMX008.exchad.jpmchase.net> > Is it possible to install MySQLdb via FTP? > > 1)I have a hostmonster account with SSH. I have been able to log in > and install MySQLdb from the shell. Works fine. > > 2)Now I have a client who wants to have a hostmonster account and we > will need MySQLdb. I *will not* have SSH access since (as I > understand it) hostmonster allows SSH access from 1 IP only. > > 3)The hostmonster account services (I.E. cpanel) does not have any > service to do this. > > 4)I wouldn't need to make the install on PYTHONPATH as my resources > will handle sys.path configuration. > > This isn't an immediate need so URLs and pointers to relevant > discussions would suffice. Why not just write a script that will install it for them and then give them a copy of that script? Alternatively, have the client contact hostmonster and have them install it; I imagine a decent webhost would be able to do this manually if asked via email/ticket. I would imagine that if you know where all the files go, it would be possible copy all the files over FTP and have it work. Granted, I am not familiar with installing this package so I could be wrong. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Fri Jun 8 13:41:58 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 8 Jun 2012 17:41:58 +0000 Subject: Where is the lastest step by step guide to compile Python into an executable? In-Reply-To: References: <1339063510.4959.YahooMailNeo@web171603.mail.ir2.yahoo.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D88F9E@SCACMX008.exchad.jpmchase.net> > > Where is the lastest step by step guide to compile Python into an > executable? > > > > Regards. > > > > David > > > > > > > > > > Google. I think you mean the Internet as Google is just an index. Unless you are referring to Google's cache. :) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From tim at akwebsoft.com Fri Jun 8 13:55:23 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Fri, 8 Jun 2012 09:55:23 -0800 Subject: Installing MySQLdb via FTP? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47412D88F57@SCACMX008.exchad.jpmchase.net> References: <20120607185525.GH7630@mail.akwebsoft.com> <5B80DD153D7D744689F57F4FB69AF47412D88F57@SCACMX008.exchad.jpmchase.net> Message-ID: <20120608175523.GG43227@mail.akwebsoft.com> * Prasad, Ramit [120608 09:38]: > > Is it possible to install MySQLdb via FTP? > > > > 1)I have a hostmonster account with SSH. I have been able to log in > > and install MySQLdb from the shell. Works fine. > > > > 2)Now I have a client who wants to have a hostmonster account and we > > will need MySQLdb. I *will not* have SSH access since (as I > > understand it) hostmonster allows SSH access from 1 IP only. > > > > 3)The hostmonster account services (I.E. cpanel) does not have any > > service to do this. > > > > 4)I wouldn't need to make the install on PYTHONPATH as my resources > > will handle sys.path configuration. > > > > This isn't an immediate need so URLs and pointers to relevant > > discussions would suffice. > > Why not just write a script that will install it for them and then > give them a copy of that script? Alternatively, have the client > contact hostmonster and have them install it; I imagine a decent > webhost would be able to do this manually if asked via email/ticket. No they would not. In fact, the hoster that I am trying to get my client away from won't either. It would be great to find a dependable hoster that *would* do manually installs, but most seem to be a one-size fits all. > I would imagine that if you know where all the files go, it would > be possible copy all the files over FTP and have it work. Granted, > I am not familiar with installing this package so I could be wrong. See the thread titled "Python libraries portable?" you will note that Corey Richardson makes the statement that MySQLdb is a C extension. I accepted that statement, but upon looking at the directories (I am on Mac Lion, but believe it may be the same for Linux) I see no binaries, just straight .py and .pyc files. *However* as it often turns out, I was barking up the wrong tree. A very nice gentleman (I presume) emailed me privately to say (I'm sure to save me the public embarassment because I should have though of it myself) "Ssh to your client and from the client ssh hostmonster" and therein is the solution. I guess I would have thought of it in the next few days whilst visiting the little boys room or mowing the lawn, but Kudos to Rod Person for his solution. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From jamtlu at gmail.com Fri Jun 8 14:32:43 2012 From: jamtlu at gmail.com (James Lu) Date: Fri, 8 Jun 2012 14:32:43 -0400 Subject: RunPy (was py2bat (was: How do I make a Python .bat executable file?)) Message-ID: no way just use py2exe 1.download it and python 2.make a setup file with this replacing ? with python file name: from setuptools import setup setup(app=['Tic-Tac-Toe easy.py']) james a intermediate child programmer -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Fri Jun 8 14:36:18 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 08 Jun 2012 14:36:18 -0400 Subject: mode for file created by open Message-ID: If a new file is created by open ('xxx', 'w') How can I control the file permission bits? Is my only choice to use chmod after opening, or use os.open? Wouldn't this be a good thing to have as a keyword for open? Too bad what python calls 'mode' is like what posix open calls 'flags', and what posix open calls 'mode' is what should go to chmod. From jeanpierreda at gmail.com Fri Jun 8 14:53:54 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 8 Jun 2012 14:53:54 -0400 Subject: mode for file created by open In-Reply-To: References: Message-ID: On Fri, Jun 8, 2012 at 2:36 PM, Neal Becker wrote: > If a new file is created by open ('xxx', 'w') > > How can I control the file permission bits? ?Is my only choice to use chmod > after opening, or use os.open? For whatever it's worth, in Python 3.3 you have the additional option of providing a special file opener. http://docs.python.org/dev/library/functions.html#open -- Devin From corey at octayn.net Fri Jun 8 15:36:00 2012 From: corey at octayn.net (Corey Richardson) Date: Fri, 8 Jun 2012 15:36:00 -0400 Subject: Installing MySQLdb via FTP? In-Reply-To: <20120608175523.GG43227@mail.akwebsoft.com> References: <20120607185525.GH7630@mail.akwebsoft.com> <5B80DD153D7D744689F57F4FB69AF47412D88F57@SCACMX008.exchad.jpmchase.net> <20120608175523.GG43227@mail.akwebsoft.com> Message-ID: <20120608153600.4d10657d@Ulysses.myhome.westell.com> On Fri, 8 Jun 2012 09:55:23 -0800 Tim Johnson wrote: > See the thread titled "Python libraries portable?" you will note > that Corey Richardson makes the statement that MySQLdb is a C > extension. I accepted that statement, but upon looking at the > directories (I am on Mac Lion, but believe it may be the same for > Linux) I see no binaries, just straight .py and .pyc files. > http://mysql-python.hg.sourceforge.net/hgweb/mysql-python/MySQLdb-2.0/file/566baac88764/src It definitely is. The C extension part is the '_mysql' module, here it is /usr/lib64/python2.7/site-packages/_mysql.so. MySQLdb (of which _mysql is a part) uses that to provide a DB-API 2.0 compliant API. > *However* as it often turns out, I was barking up the wrong tree. > (I haven't followed this thread at all besides noticing this message) -- Corey Richardson From drsalists at gmail.com Fri Jun 8 17:52:18 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 8 Jun 2012 14:52:18 -0700 Subject: Import semantics? Message-ID: Did the import semantics change in cpython 3.3a4? I used to be able to import treap.py even though I had a treap directory in my cwd. With 3.3a4, I have to rename the treap directory to see treap.py. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Jun 8 18:16:15 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 08 Jun 2012 15:16:15 -0700 Subject: Import semantics? In-Reply-To: References: Message-ID: <4FD279AF.1010104@stoneleaf.us> Dan Stromberg wrote: > > Did the import semantics change in cpython 3.3a4? > > I used to be able to import treap.py even though I had a treap directory > in my cwd. With 3.3a4, I have to rename the treap directory to see > treap.py. Check out PEP 420 -- Implicit Namespace Packages [http://www.python.org/dev/peps/pep-0420/] ~Ethan~ From drsalists at gmail.com Fri Jun 8 18:24:00 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 8 Jun 2012 15:24:00 -0700 Subject: Import semantics? In-Reply-To: <4FD279AF.1010104@stoneleaf.us> References: <4FD279AF.1010104@stoneleaf.us> Message-ID: On Fri, Jun 8, 2012 at 3:16 PM, Ethan Furman wrote: > Dan Stromberg wrote: > >> >> Did the import semantics change in cpython 3.3a4? >> >> I used to be able to import treap.py even though I had a treap directory >> in my cwd. With 3.3a4, I have to rename the treap directory to see >> treap.py. >> > > Check out PEP 420 -- Implicit Namespace Packages [ > http://www.python.org/dev/peps/pep-0420/] > Am I misinterpreting this? It seems like according to the PEP, I should have still been able to import treap.py despite having a treap/. But I couldn't; I had to rename treap/ to treap-dir/ first. During import processing, the import machinery will continue to iterate over each directory in the parent path as it does in Python 3.2. While looking for a module or package named "foo", for each directory in the parent path: - If /foo/__init__.py is found, a regular package is imported and returned. - If not, but /foo.{py,pyc,so,pyd} is found, a module is imported and returned. The exact list of extension varies by platform and whether the -O flag is specified. The list here is representative. - If not, but /foo is found and is a directory, it is recorded and the scan continues with the next directory in the parent path. - Otherwise the scan continues with the next directory in the parent path. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Fri Jun 8 18:48:17 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Jun 2012 16:48:17 -0600 Subject: Import semantics? In-Reply-To: References: <4FD279AF.1010104@stoneleaf.us> Message-ID: On Fri, Jun 8, 2012 at 4:24 PM, Dan Stromberg wrote: > Am I misinterpreting this?? It seems like according to the PEP, I should > have still been able to import treap.py despite having a treap/.? But I > couldn't; I had to rename treap/ to treap-dir/ first. That's how I understand it. The existence of a module or regular package 'foo' anywhere in the path should trump the creation of a 'foo' namespace package, even if the namespace package would be earlier in the path. Ar you sure you don't have an __init__.py in your treap directory? From jeanpierreda at gmail.com Fri Jun 8 19:05:28 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 8 Jun 2012 19:05:28 -0400 Subject: Import semantics? In-Reply-To: References: <4FD279AF.1010104@stoneleaf.us> Message-ID: On Fri, Jun 8, 2012 at 6:24 PM, Dan Stromberg wrote: > Am I misinterpreting this?? It seems like according to the PEP, I should > have still been able to import treap.py despite having a treap/.? But I > couldn't; I had to rename treap/ to treap-dir/ first. Only if treap/ and treap.py were in the same directory. Otherwise it looks like whichever comes first in the search path is imported first. -- Devin From ethan at stoneleaf.us Fri Jun 8 19:07:45 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 08 Jun 2012 16:07:45 -0700 Subject: [Python-Dev] Import semantics? In-Reply-To: <4FD2811A.2020108@trueblade.com> References: <4FD279AF.1010104@stoneleaf.us> <4FD27F82.50801@stoneleaf.us> <4FD2811A.2020108@trueblade.com> Message-ID: <4FD285C1.50107@stoneleaf.us> Eric V. Smith wrote: > On 6/8/2012 6:41 PM, Ethan Furman wrote: >> Dan Stromberg wrote: >>> On Fri, Jun 8, 2012 at 3:16 PM, Ethan Furman wrote: >>> Dan Stromberg wrote: >>>> Did the import semantics change in cpython 3.3a4? >>>> >>>> I used to be able to import treap.py even though I had a treap >>>> directory in my cwd. With 3.3a4, I have to rename the treap >>>> directory to see treap.py. >>> Check out PEP 420 -- Implicit Namespace Packages >>> [http://www.python.org/dev/peps/pep-0420/] >>> >>> >>> Am I misinterpreting this? It seems like according to the PEP, I >>> should have still been able to import treap.py despite having a >>> treap/. But I couldn't; I had to rename treap/ to treap-dir/ first. >>> >>> During import processing, the import machinery will continue to >>> iterate over each directory in the parent path as it does in Python >>> 3.2. While looking for a module or package named "foo", for each >>> directory in the parent path: >>> >>> * If /foo/__init__.py is found, a regular package is >>> imported and returned. >>> * If not, but /foo.{py,pyc,so,pyd} is found, a module >>> is imported and returned. The exact list of extension varies >>> by platform and whether the -O flag is specified. The list >>> here is representative. >>> * If not, but /foo is found and is a directory, it is >>> recorded and the scan continues with the next directory in the >>> parent path. >>> * Otherwise the scan continues with the next directory in the >>> parent path. >> I do not understand PEP 420 well enough to say if this is intentional or >> a bug -- thoughts? > > I missed the beginning of this discussion and I need some more details. > What directories are on sys.path, where do treap.py and treap/ appear in > them, and is there an __init__.py in treap? At first blush it sounds > like it should continue working. > > If you (Dan?) could re-create this in a small example and open a bug, > that would be great. > > Eric. From cs at zip.com.au Fri Jun 8 19:19:46 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 9 Jun 2012 09:19:46 +1000 Subject: mode for file created by open In-Reply-To: References: Message-ID: <20120608231946.GA2379@cskk.homeip.net> On 08Jun2012 14:36, Neal Becker wrote: | If a new file is created by open ('xxx', 'w') | | How can I control the file permission bits? Is my only choice to use chmod | after opening, or use os.open? | | Wouldn't this be a good thing to have as a keyword for open? Too bad what | python calls 'mode' is like what posix open calls 'flags', and what posix open | calls 'mode' is what should go to chmod. Well, it does honour the umask, and will call the OS open with 0666 mode so you'll get 0666-umask mode bits in the new file (if it is new). Last time I called os.open was to pass a mode of 0 (raceproof lockfile). I would advocate (untested): fd = os.open(...) os.fchmod(fd, new_mode) fp = os.fdopen(fd) If you need to constrain access in a raceless fashion (specificly, no ealy window of _extra_ access) pass a restrictive mode to os.open and open it up with fchmod. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It was a joke, OK? If we thought it would actually be used, we wouldn't have written it! - Marc Andreessen on the creation of a tag From stayvoid at gmail.com Fri Jun 8 19:41:40 2012 From: stayvoid at gmail.com (stayvoid) Date: Fri, 8 Jun 2012 16:41:40 -0700 (PDT) Subject: Passing ints to a function Message-ID: Hello, I want to pass several values to a function which is located on a server (so I can't change its behavior). That function only accepts five values which must be ints. There are several lists: a = [1, 2, 3, 4, 5] b = [5, 4, 3, 2, 1] c = [0, 0, 0, 0, 0] I want to pass each value from these lists to that function. What is the most pythonic way? This wouldn't work because we're passing a list not ints: function(a) function(b) function(c) This wouldn't work too (the reason is the same): def foo(x): return x[0], x[1], x[2], x[3], x[4], x[5] function(foo(a)) function(foo(b)) function(foo(c)) This would work, but it's not pythonic at all (imagine that you want to call it 10 times or even more). function(a[0], a[1], a[2], a[3], a[4], a[5]) function(b[0], b[1], b[2], b[3], b[4], b[5]) function(c[0], c[1], c[2], c[3], c[4], c[5]) Thanks From ian.g.kelly at gmail.com Fri Jun 8 19:52:34 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Jun 2012 17:52:34 -0600 Subject: Passing ints to a function In-Reply-To: References: Message-ID: On Fri, Jun 8, 2012 at 5:41 PM, stayvoid wrote: > Hello, > > I want to pass several values to a function which is located on a > server (so I can't change its behavior). > That function only accepts five values which must be ints. > > There are several lists: > a = [1, 2, 3, 4, 5] > b = [5, 4, 3, 2, 1] > c = [0, 0, 0, 0, 0] > > I want to pass each value from these lists to that function. > What is the most pythonic way? function(*a) Cheers, Ian From benjamin.kaplan at case.edu Fri Jun 8 19:55:24 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 8 Jun 2012 19:55:24 -0400 Subject: Passing ints to a function In-Reply-To: References: Message-ID: On Fri, Jun 8, 2012 at 7:41 PM, stayvoid wrote: > Hello, > > I want to pass several values to a function which is located on a > server (so I can't change its behavior). > That function only accepts five values which must be ints. > > There are several lists: > a = [1, 2, 3, 4, 5] > b = [5, 4, 3, 2, 1] > c = [0, 0, 0, 0, 0] > > I want to pass each value from these lists to that function. > What is the most pythonic way? > function(*a) * expands a list into positional arguments and ** expands a dictionary into keyword arguments. From steve+comp.lang.python at pearwood.info Fri Jun 8 19:56:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Jun 2012 23:56:47 GMT Subject: Passing ints to a function References: Message-ID: <4fd2913f$0$29973$c3e8da3$5496439d@news.astraweb.com> On Fri, 08 Jun 2012 16:41:40 -0700, stayvoid wrote: > Hello, > > I want to pass several values to a function which is located on a server > (so I can't change its behavior). That function only accepts five values > which must be ints. > > There are several lists: > a = [1, 2, 3, 4, 5] > b = [5, 4, 3, 2, 1] > c = [0, 0, 0, 0, 0] > > I want to pass each value from these lists to that function. What is the > most pythonic way? You want to unpack the list: function(*a) # like function(a[0], a[1], a[2], ...) If you have many lists, use a for-loop: for L in (a, b, c): function(*L) -- Steven From drsalists at gmail.com Fri Jun 8 20:02:03 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 8 Jun 2012 17:02:03 -0700 Subject: Import semantics? In-Reply-To: References: <4FD279AF.1010104@stoneleaf.us> Message-ID: On Fri, Jun 8, 2012 at 3:48 PM, Ian Kelly wrote: > On Fri, Jun 8, 2012 at 4:24 PM, Dan Stromberg wrote: > > Am I misinterpreting this? It seems like according to the PEP, I should > > have still been able to import treap.py despite having a treap/. But I > > couldn't; I had to rename treap/ to treap-dir/ first. > > That's how I understand it. The existence of a module or regular > package 'foo' anywhere in the path should trump the creation of a > 'foo' namespace package, even if the namespace package would be > earlier in the path. Ar you sure you don't have an __init__.py in > your treap directory? > The issue replicated in a minimal way (it's in the ticket too): dstromberg at zareason-limbo6000a /tmp/tt $ mv treap treap-dir dstromberg at zareason-limbo6000a /tmp/tt $ /usr/local/cpython-3.3/bin/python -c 'import sys; print(sys.path); import treap; t = treap.treap()' ['', '/usr/local/cpython-3.3/lib/python33.zip', '/usr/local/cpython-3.3/lib/python3.3', '/usr/local/cpython-3.3/lib/python3.3/plat-linux', '/usr/local/cpython-3.3/lib/python3.3/lib-dynload', '/usr/local/cpython-3.3/lib/python3.3/site-packages'] dstromberg at zareason-limbo6000a /tmp/tt $ mv treap-dir/ treap dstromberg at zareason-limbo6000a /tmp/tt $ /usr/local/cpython-3.3/bin/python -c 'import sys; print(sys.path); import treap; t = treap.treap()' ['', '/usr/local/cpython-3.3/lib/python33.zip', '/usr/local/cpython-3.3/lib/python3.3', '/usr/local/cpython-3.3/lib/python3.3/plat-linux', '/usr/local/cpython-3.3/lib/python3.3/lib-dynload', '/usr/local/cpython-3.3/lib/python3.3/site-packages'] Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'treap' dstromberg at zareason-limbo6000a /tmp/tt $ ls -l treap/__init__.py ls: cannot access treap/__init__.py: No such file or directory dstromberg at zareason-limbo6000a /tmp/tt $ /usr/local/cpython-3.3/bin/python Python 3.3.0a4 (default, Jun 8 2012, 14:14:41) [GCC 4.6.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From stayvoid at gmail.com Fri Jun 8 20:21:38 2012 From: stayvoid at gmail.com (stayvoid) Date: Fri, 8 Jun 2012 17:21:38 -0700 (PDT) Subject: Passing ints to a function References: <4fd2913f$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0ab8a335-57d2-4845-a522-0e70df5d36f0@m3g2000vbl.googlegroups.com> > You want to unpack the list: > > function(*a) ?# like function(a[0], a[1], a[2], ...) Awesome! I forgot about this. Thanks. From drsalists at gmail.com Fri Jun 8 20:37:23 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 8 Jun 2012 17:37:23 -0700 Subject: Import semantics? In-Reply-To: References: <4FD279AF.1010104@stoneleaf.us> Message-ID: And a link to the ticket: http://bugs.python.org/issue15039 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From robertmiles at teranews.com Fri Jun 8 23:16:42 2012 From: robertmiles at teranews.com (Robert Miles) Date: Fri, 08 Jun 2012 22:16:42 -0500 Subject: Some posts do not show up in Google Groups In-Reply-To: <19700023.3233.1335766827264.JavaMail.geo-discussion-forums@vbuo17> References: <19700023.3233.1335766827264.JavaMail.geo-discussion-forums@vbuo17> Message-ID: On 4/30/2012 1:20 AM, Frank Millman wrote: > Hi all > > For a while now I have been using Google Groups to read this group, but on the odd occasion when I want to post a message, I use Outlook Express, as I know that some people reject all messages from Google Groups due to the high spam ratio (which seems to have improved recently, BTW). > > From time to time I see a thread where the original post is missing, but the follow-ups do appear. My own posts have shown up with no problem. > > Now, in the last month, I have posted two messages using Outlook Express, and neither of them have shown up in Google Groups. I can see replies in OE, so they are being accepted. I send to the group gmane.comp.python.general. > > Does anyone know a reason for this, or have a solution? > > Frank Millman I can't answer your main question, but I have seen a reason for Google Groups appearing to have less spam. That was about the time Google Groups introduced a new interface which makes it obvious if anyone has already reported a message as spam (or any other type of abuse), and also made those messages inaccessible after two different users reported the same message as abuse. Therefore, many spammers are moving toward newsgroups where no one reports the spam. Robert Miles From robertmiles at teranews.com Fri Jun 8 23:27:33 2012 From: robertmiles at teranews.com (Robert Miles) Date: Fri, 08 Jun 2012 22:27:33 -0500 Subject: Some posts do not show up in Google Groups In-Reply-To: <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> References: <19700023.3233.1335766827264.JavaMail.geo-discussion-forums@vbuo17> <19a3f770-7577-4624-b141-ef30a4849f93@j3g2000vba.googlegroups.com> Message-ID: On 5/1/2012 1:12 AM, Frank Millman wrote: > On Apr 30, 8:20 am, Frank Millman wrote: >> Hi all >> >> For a while now I have been using Google Groups to read this group, but on the odd occasion when I want to post a message, I use Outlook Express, as I know that some people reject all messages from Google Groups due to the high spam ratio (which seems to have improved recently, BTW). >> >> From time to time I see a thread where the original post is missing, but the follow-ups do appear. My own posts have shown up with no problem. >> >> Now, in the last month, I have posted two messages using Outlook Express, and neither of them have shown up in Google Groups. I can see replies in OE, so they are being accepted. I send to the group gmane.comp.python.general. >> >> Does anyone know a reason for this, or have a solution? >> >> Frank Millman > > Thanks for the replies. I am also coming to the conclusion that Google > Groups is no longer fit-for-purpose. > > Ironically, here are two replies that I can see in Outlook Express, > but do not appear in Google Groups. > > Reply from Benjamin Kaplan - >> I believe the mail-to-news gateway has trouble with HTML messages. Try sending everything as plain text and see if that works. > > I checked, and all my posts were sent in plain text. > > Reply from Terry Reedy - >> Read and post through news.gmane.org > > I have had a look at this before, but there is one thing that Google > Groups does that no other reader seems to do, and that is that > messages are sorted according to thread-activity, not original posting > date. This makes it easy to see what has changed since the last time I > checked. > > All the other ones I have looked at - Outlook Express, Thunderbird, > and gmane.org, sort by original posting date, so I have to go > backwards to see if any threads have had any new postings. > > Maybe there is a setting that I am not aware of. Can anyone enlighten > me? > > Thanks > > Frank Thunderbird appears to change the sorting order for me based on whether I tell it to put the newest messages at the top of its window or at the bottom. Some newsgroups servers appear to discard every post they get that contains any HTML. This may be because Google Groups often adds HTML even if you don't ask for it, and those servers want to avoid the poor signal to noise ratio from Google Groups. Robert Miles From rosuav at gmail.com Fri Jun 8 23:31:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Jun 2012 13:31:20 +1000 Subject: Where is the lastest step by step guide to compile Python into an executable? In-Reply-To: <5B80DD153D7D744689F57F4FB69AF47412D88F9E@SCACMX008.exchad.jpmchase.net> References: <1339063510.4959.YahooMailNeo@web171603.mail.ir2.yahoo.com> <5B80DD153D7D744689F57F4FB69AF47412D88F9E@SCACMX008.exchad.jpmchase.net> Message-ID: On Sat, Jun 9, 2012 at 3:41 AM, Prasad, Ramit wrote: >> > Where is the lastest step by step guide to compile Python into an >> executable? >> >> Google. > > I think you mean the Internet as Google is just an index. > Unless you are referring to Google's cache. He means this: http://www.catb.org/~esr/faqs/smart-questions.html#rtfm ChrisA From robertmiles at teranews.com Fri Jun 8 23:41:03 2012 From: robertmiles at teranews.com (Robert Miles) Date: Fri, 08 Jun 2012 22:41:03 -0500 Subject: Create directories and modify files with Python In-Reply-To: <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: On 5/1/2012 5:51 AM, deltaquattro at gmail.com wrote: > Il giorno marted? 1 maggio 2012 01:57:12 UTC+2, Irmen de Jong ha scritto: [snip] >> Focus on file input and output, string manipulation, and look in the os module for stuff >> to help scanning directories (such as os.walk). >> >> Irmen > > Thanks for the directions. By the way, can you see my post in Google Groups? I'm not able to, and I don't know why. > > Sergio They may have copied the Gmail idea that you never need to see anything anything you posted yourself. When I post anything using Google Groups, my posts usually show but often very slowly - as in 5 minutes after I tell it to post. Robert Miles From jpiitula at ling.helsinki.fi Sat Jun 9 04:29:13 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 09 Jun 2012 11:29:13 +0300 Subject: Passing ints to a function References: <4fd2913f$0$29973$c3e8da3$5496439d@news.astraweb.com> <0ab8a335-57d2-4845-a522-0e70df5d36f0@m3g2000vbl.googlegroups.com> Message-ID: stayvoid writes: > > You want to unpack the list: > > > > function(*a) ?# like function(a[0], a[1], a[2], ...) > > Awesome! I forgot about this. Here's something you could have thought of for yourself even when you didn't remember that Python does have special built-in support for applying a function to a list of arguments: def five(func, args): a, b, c, d, e = args return func(a, b, c, d, e) five(function, a) five(function, b) five(function, c) for args in argses: five(function, args) The point is that the function itself can be passed as an argument to the auxiliary function that extracts the individual arguments from the list. From rosuav at gmail.com Sat Jun 9 05:00:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Jun 2012 19:00:20 +1000 Subject: Passing ints to a function In-Reply-To: References: <4fd2913f$0$29973$c3e8da3$5496439d@news.astraweb.com> <0ab8a335-57d2-4845-a522-0e70df5d36f0@m3g2000vbl.googlegroups.com> Message-ID: On Sat, Jun 9, 2012 at 6:29 PM, Jussi Piitulainen wrote: > The point is that the function itself can be passed as an argument to > the auxiliary function ... And unlike in Javascript, a bound method is fully callable too. Chris Angelico From ndbecker2 at gmail.com Sat Jun 9 07:42:59 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 09 Jun 2012 07:42:59 -0400 Subject: mode for file created by open References: <20120608231946.GA2379@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > On 08Jun2012 14:36, Neal Becker wrote: > | If a new file is created by open ('xxx', 'w') > | > | How can I control the file permission bits? Is my only choice to use chmod > | after opening, or use os.open? > | > | Wouldn't this be a good thing to have as a keyword for open? Too bad what > | python calls 'mode' is like what posix open calls 'flags', and what posix > | open calls 'mode' is what should go to chmod. > > Well, it does honour the umask, and will call the OS open with 0666 > mode so you'll get 0666-umask mode bits in the new file (if it is new). > > Last time I called os.open was to pass a mode of 0 (raceproof lockfile). > > I would advocate (untested): > > fd = os.open(...) > os.fchmod(fd, new_mode) > fp = os.fdopen(fd) > > If you need to constrain access in a raceless fashion (specificly, no > ealy window of _extra_ access) pass a restrictive mode to os.open and > open it up with fchmod. > > Cheers, Doesn't anyone else think it would be a good addition to open to specify a file creation mode? Like posix open? Avoid all these nasty workarounds? From jdmorgan at unca.edu Sat Jun 9 09:25:30 2012 From: jdmorgan at unca.edu (jdmorgan) Date: Sat, 09 Jun 2012 09:25:30 -0400 Subject: next alpha sequence value from var pointing to array In-Reply-To: References: Message-ID: <4FD34ECA.7000506@gmail.com> Newline was the issue indeed. Thanks for you help Peter. Cheers, Derek From news at schwertberger.de Sat Jun 9 09:25:47 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sat, 09 Jun 2012 15:25:47 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= In-Reply-To: <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> Message-ID: Am 08.06.2012 17:11, schrieb CM: > I'm curious about your point but I don't really understand it. Could > you try again without using any scare-quoted words? Maybe given an > example of creating a small text editor application with a GUI builder/ > IDE in this Pythonic way you are hoping for. Before anyone now writes "Good GUIs are coded by hand": I agree, but for many purposes only simple GUIs are required and it should be possible to create these without studying manuals (on toolkit and GUI editor). A typical simple GUI would e.g. be for a measurement / data aquisition program, where you just need some buttons and fields. I think that something in the style of Visual BASIC (version 6) is required for either wxPython or PyQt/PySide (or both). In the Visual BASIC editor you can e.g. add a GUI element and directly go to the code editor to fill methods (e.g. an OnClick method). If you have not used VB before, you should just try it. You can create GUIs within a few minutes even if you haven't used it before. (Sure, the fact that anyone can use it has the side effect that most of these GUIs are not good...) Also: Such an editor should support simple manual layouts without enforcing the use of sizers (wx) or layout managers (Qt). These add an additional level of complexity which is not required for simple GUIs. Background: I'm using Python in a corporate environment but I'm more or less the only one using it. I could propagate Python for wider use as it is the best available language for things like hardware control and data acquisition, but the lack of an easy-to-use GUI editor is the blocking point. I can teach anyone how to create a program for data acquisition, but I don't see how more than a few could create a GUI without an easy-to-use tool. There's still a lot of VB6 code around as there's no replacement and this gap could well be filled by Python. Regards, Dietmar From jeanpierreda at gmail.com Sat Jun 9 10:08:15 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 9 Jun 2012 10:08:15 -0400 Subject: mode for file created by open In-Reply-To: References: <20120608231946.GA2379@cskk.homeip.net> Message-ID: On Sat, Jun 9, 2012 at 7:42 AM, Neal Becker wrote: > Doesn't anyone else think it would be a good addition to open to specify a file > creation mode? ?Like posix open? ?Avoid all these nasty workarounds? I do, although I'm hesitant, because this only applies when mode == 'w', and open has a large and growing list of parameters. A chmod method would also work. Although you can use os.fchmod(f.fileno(), ...) instead (another workaround? fun. TIMTOWTDI I guess). -- Devin From asa at vorsicht-bissig.de Sat Jun 9 10:23:22 2012 From: asa at vorsicht-bissig.de (asa at vorsicht-bissig.de) Date: Sat, 09 Jun 2012 16:23:22 +0200 Subject: Strange Problem with pythonw.exe Message-ID: <20120609142322.242710@gmx.net> Hello subscribers, I've recently encountered a strange problem with Python for Windows. I'm using Windows 7 Pro 64 Bit and Python 3.2.3 64 Bit (also tried 32 bit). The Problem is, that pythonw.exe does not work at all! Therefore no IDLE for me... But python.exe runs just fine. I ran Process Monitor, which showed some activity for pythonw.exe, but no window is coming up. The problem isn't restricted to my main python installation. I have also tried running portable python and active state python. No pythonw.exe of them is working. Reinstallation didn't change anything. Windows firewall was deactivated, no difference. No firewall-software or any possibilities of blocking pythonw.exe. I couldn't find the problem online. My problem was triggered by using PyQt. I've loaded an .ui, which did NOT show up. I have Never seen IDLE since that "crash". Advice anyone? Regards, Arthur From tim at akwebsoft.com Sat Jun 9 11:27:05 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Sat, 9 Jun 2012 07:27:05 -0800 Subject: Installing MySQLdb via FTP? In-Reply-To: <20120608153600.4d10657d@Ulysses.myhome.westell.com> References: <20120607185525.GH7630@mail.akwebsoft.com> <5B80DD153D7D744689F57F4FB69AF47412D88F57@SCACMX008.exchad.jpmchase.net> <20120608175523.GG43227@mail.akwebsoft.com> <20120608153600.4d10657d@Ulysses.myhome.westell.com> Message-ID: <20120609152705.GM43227@mail.akwebsoft.com> * Corey Richardson [120608 11:39]: > On Fri, 8 Jun 2012 09:55:23 -0800 > Tim Johnson wrote: > > > See the thread titled "Python libraries portable?" you will note > > that Corey Richardson makes the statement that MySQLdb is a C > > extension. I accepted that statement, but upon looking at the > > directories (I am on Mac Lion, but believe it may be the same for > > Linux) I see no binaries, just straight .py and .pyc files. > > > > http://mysql-python.hg.sourceforge.net/hgweb/mysql-python/MySQLdb-2.0/file/566baac88764/src > > It definitely is. The C extension part is the '_mysql' module, here it > is /usr/lib64/python2.7/site-packages/_mysql.so. MySQLdb (of which > _mysql is a part) uses that to provide a DB-API 2.0 compliant API. Understood. I missed that because the shared object file is in another directory. On mac (darwin) it is /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From cmpython at gmail.com Sat Jun 9 11:34:25 2012 From: cmpython at gmail.com (CM) Date: Sat, 9 Jun 2012 08:34:25 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> Message-ID: <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> > I think that something in the style of Visual BASIC (version 6) is required > for either wxPython or PyQt/PySide (or both). > In the Visual BASIC editor you can e.g. add a GUI element > and directly go to the code editor to fill methods (e.g. an OnClick > method). You can do this for wxPython with Boa Constructor easily. You can bind an event handler for a wx.EVT_BUTTON to, e.g., "Button1" with Boa and it will add this code for you to the bottom of your code: def OnButton1Button(self,evt): evt.Skip() And you can than go in the code editor to that function and change the code to do whatever you want. > If you have not used VB before, you should just try it. You can create > GUIs within a few minutes even if you haven't used it before. Same with Boa. > Such an editor should support simple manual layouts without enforcing > the use of sizers (wx) or layout managers (Qt). > These add an additional level of complexity which is not required > for simple GUIs. Same with Boa, though it also has good support for sizers which generally should be required for anything other than the simplest GUIs. > data acquisition, but the lack of an easy-to-use GUI editor is > the blocking point. I can teach anyone how to create a program for data > acquisition, but I don't see how more than a few could create a GUI > without an easy-to-use tool. > There's still a lot of VB6 code around as there's no replacement and > this gap could well be filled by Python. In addition to Boa, I get the sense that the other tools mentioned here are also good, so is this "blocking point" real? From rosuav at gmail.com Sat Jun 9 11:50:52 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jun 2012 01:50:52 +1000 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> Message-ID: On Sat, Jun 9, 2012 at 11:25 PM, Dietmar Schwertberger wrote: > ... for many purposes only simple GUIs are required > and it should be possible to create these without studying manuals > (on toolkit and GUI editor). > A typical simple GUI would e.g. be for a measurement / data aquisition > program, where you just need some buttons and fields. > > > If you have not used VB before, you should just try it. You can create > GUIs within a few minutes even if you haven't used it before. > (Sure, the fact that anyone can use it has the side effect that most > ?of these GUIs are not good...) There's an assumption in most of the Windows world that everything needs a GUI. For a simple data acquisition program, I wouldn't use one - I'd have it run in a console. That's something that any programmer should be able to create without studying complex manuals; all you need to know is the basics of I/O and possibly argument parsing. I've used Visual Basic. My first salaried work was on VB. Making it easy to throw together a simple GUI doesn't mean a thing when you have a large project to write - your business logic and UI design work will massively dwarf the effort of actually throwing widgets into a hierarchy. So the only time it's going to be an issue is with trivial programs; which means there isn't much to be saved. Just make your trivial things run in a console, and then either use a GUI builder (several have been mentioned) or hand-write your UI code. Actually, there's a third option these days. Give it no console and no GUI, make it respond to HTTP connections, and use a web browser as your UI. :) ChrisA From rosuav at gmail.com Sat Jun 9 12:32:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jun 2012 02:32:09 +1000 Subject: mode for file created by open In-Reply-To: References: <20120608231946.GA2379@cskk.homeip.net> Message-ID: On Sun, Jun 10, 2012 at 12:08 AM, Devin Jeanpierre wrote: > I do, although I'm hesitant, because this only applies when mode == > 'w', and open has a large and growing list of parameters. True, but keyword arguments don't cost much complexity. open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True) I don't think this would be hurt by another parameter, since most of them will be happily ignored by most calls. It's not like opening files in assembly language under OS/2, where it takes thirteen pushes for each call (arguments on the stack, make sure you push them in the right order, don't forget that pointers require a segment and an offset and make sure they're the right way around). File handling IS complex, so it stands to reason that the file-open function should carry that complexity. ChrisA From news at schwertberger.de Sat Jun 9 13:07:00 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sat, 09 Jun 2012 19:07:00 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= In-Reply-To: <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> Message-ID: Am 09.06.2012 17:34, schrieb CM: > You can do this for wxPython with Boa Constructor easily. You can > bind an event handler for a wx.EVT_BUTTON to, e.g., "Button1" with Boa > and it will add this code for you to the bottom of your code: > > def OnButton1Button(self,evt): > evt.Skip() > > And you can than go in the code editor to that function and change the > code to do whatever you want. Having to go there is already more work than I would expect. I would expect to go there e.g. by a double-click. This is just a minor point, but many minor points sum up... If you take maybe 10 people each with some BASIC or Python knowledge, I would bet that you can teach most of them how to write a simple GUI program in VB within five minutes, but you'll probably fail with Boa. (And even then you would have to re-teach them in a few months when they try to write their next program.) >> If you have not used VB before, you should just try it. You can create >> GUIs within a few minutes even if you haven't used it before. > > Same with Boa. Not for me when I tried Boa. The logic / usage concept behind is not exactly straightforward. At the time, Boa was suggested to be the perfect choice for previous Delphi users. Maybe my problem was that I did never use Delphi. (Only Turbo Pascal in the pre-gui era...) >> Such an editor should support simple manual layouts without enforcing >> the use of sizers (wx) or layout managers (Qt). >> These add an additional level of complexity which is not required >> for simple GUIs. > > Same with Boa, though it also has good support for sizers which > generally should be required for anything other than the simplest > GUIs. Yes, at least Boa left the choice to the user. Some of the other tools even insist on sizers at places where they are not even required with a sizer-based layout. (E.g. with wx you usually place a notebook directly on a frame while some tools insist on using a sizer first.) > In addition to Boa, I get the sense that the other tools mentioned > here are also good, so is this "blocking point" real? I've tried several: wxDesigner, Boa, QtCreator, wxFormBuilder, wxGlade, None of these were such that I could propagate it as GUI development tool for non-programmers / casual users. Sure, some are good for designing the GUI, but at the point where the user code is to be added, most people would be lost. (I think that was the point that Wolfgang did not like and did describe as un-pythonic.) Also, another requirement for this purpose would be that the tool is under active development. This would e.g. rule out Boa. I would not care whether the tool is freeware or commercial. Being freeware would make handling easier, though (e.g. deployment to all measurement PCs by just running it from a file share is easier than local installations and license handling). Regards, Dietmar From rosuav at gmail.com Sat Jun 9 13:19:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jun 2012 03:19:09 +1000 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> Message-ID: On Sun, Jun 10, 2012 at 3:07 AM, Dietmar Schwertberger wrote: > None of these were such that I could propagate it as GUI development > tool for non-programmers / casual users. > Sure, some are good for designing the GUI, but at the point where > the user code is to be added, most people would be lost. There was a time when that was a highly advertisable feature - "build XYZ applications without writing a single line of code!". I've seen it in database front-end builders as well as GUI tools, same thing. But those sorts of tools tend not to be what experts want to use. You end up having to un-learn the "easy way" before you learn the "hard way" that lets you do everything. You refer to "non-programmers" and then point out that they would be lost trying to add code. That's a natural consequence of not being a programmer, and of all languages to help someone bridge that gap and start coding, I would say Python is, if not the absolute best, certainly up there somewhere. Just as you wouldn't expect a music authoring program to let someone publish score without knowing how to compose music, you can't expect a GUI tool to relieve you of the need to write code. WYSIWYG UI designers suffer badly from a need to guess _why_ the human did what s/he did. Build your UI manually, and there's no guesswork - you explicitly _tell_ the computer what to do and why. ChrisA From tjreedy at udel.edu Sat Jun 9 14:05:50 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 09 Jun 2012 14:05:50 -0400 Subject: Strange Problem with pythonw.exe In-Reply-To: <20120609142322.242710@gmx.net> References: <20120609142322.242710@gmx.net> Message-ID: On 6/9/2012 10:23 AM, asa at vorsicht-bissig.de wrote: > Hello subscribers, > > I've recently encountered a strange problem with Python for Windows. > I'm using Windows 7 Pro 64 Bit and Python 3.2.3 64 Bit (also tried 32 > bit). The Problem is, that pythonw.exe does not work at all! > Therefore no IDLE for me... But python.exe runs just fine. I ran > Process Monitor, which showed some activity for pythonw.exe, but no > window is coming up. It is not quite clear what you did here, but if you just run pythonw.exe, you should not see anything, as the 'w' stands for 'Windows', 'windowless', or 'with user interaction through a gui brought up by the python program being run'. It make it hard to debug if no gui is being brought up. > The problem isn't restricted to my main python > installation. I have also tried running portable python and active > state python. No pythonw.exe of them is working. Reinstallation > didn't change anything. Windows firewall was deactivated, no > difference. No firewall-software or any possibilities of blocking > pythonw.exe. I couldn't find the problem online. My problem was > triggered by using PyQt. I've loaded an .ui, which did NOT show up. I > have Ne ver seen IDLE since that "crash". Advice anyone? I take it that IDLE *did* work before using PyQT. If this is correct (I must admit, I hope so), I would ask the author of PyQT whether it or QT does anything to the system that could persist across installs. The most likely change to me would be in the registry. So if it were my machine, I would fire up regedit, back up the registry, search it for 'pythonw', look at the results, and perhaps delete all pythonw entries. Then reinstall the core component. You might also try 3.3.0a4, which had additional bug fixes, or go back to something like 3.2.0. -- Terry Jan Reedy From tim at akwebsoft.com Sat Jun 9 14:30:06 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Sat, 9 Jun 2012 10:30:06 -0800 Subject: Installing MySQLdb via FTP? In-Reply-To: <20120609152705.GM43227@mail.akwebsoft.com> References: <20120607185525.GH7630@mail.akwebsoft.com> <5B80DD153D7D744689F57F4FB69AF47412D88F57@SCACMX008.exchad.jpmchase.net> <20120608175523.GG43227@mail.akwebsoft.com> <20120608153600.4d10657d@Ulysses.myhome.westell.com> <20120609152705.GM43227@mail.akwebsoft.com> Message-ID: <20120609183006.GN43227@mail.akwebsoft.com> * Tim Johnson [120609 07:30]: > > > > http://mysql-python.hg.sourceforge.net/hgweb/mysql-python/MySQLdb-2.0/file/566baac88764/src > > > > It definitely is. The C extension part is the '_mysql' module, here it > > is /usr/lib64/python2.7/site-packages/_mysql.so. MySQLdb (of which > > _mysql is a part) uses that to provide a DB-API 2.0 compliant API. > Understood. I missed that because the shared object file is in > another directory. > On mac (darwin) it is > /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ I would note that some programming languages with mysql APIs access the mysql client library directly from the PL's code base (newlisp as an example) or use TCP/IP to query the mysql server directly (rebol as an example) -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From tjreedy at udel.edu Sat Jun 9 14:31:07 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 09 Jun 2012 14:31:07 -0400 Subject: mode for file created by open In-Reply-To: References: <20120608231946.GA2379@cskk.homeip.net> Message-ID: On 6/9/2012 10:08 AM, Devin Jeanpierre wrote: > On Sat, Jun 9, 2012 at 7:42 AM, Neal Becker wrote: >> Doesn't anyone else think it would be a good addition to open to specify a file >> creation mode? Like posix open? Avoid all these nasty workarounds? > > I do, although I'm hesitant, because this only applies when mode == > 'w', and open has a large and growing list of parameters. The buffer parameter (I believe it is) also does not always apply. The original open builtin was a thin wrapper around old C's stdio.open. Open no longer has that constraint. After more discussion here, someone could open a tracker issue with a specific proposal. Keep in mind that 'mode' is already a parameter name for the mode of opening, as opposed to the permission mode for subsequent users. -- Terry Jan Reedy From ndbecker2 at gmail.com Sat Jun 9 18:25:12 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 09 Jun 2012 18:25:12 -0400 Subject: mode for file created by open References: <20120608231946.GA2379@cskk.homeip.net> Message-ID: Terry Reedy wrote: > On 6/9/2012 10:08 AM, Devin Jeanpierre wrote: >> On Sat, Jun 9, 2012 at 7:42 AM, Neal Becker wrote: >>> Doesn't anyone else think it would be a good addition to open to specify a >>> file >>> creation mode? Like posix open? Avoid all these nasty workarounds? >> >> I do, although I'm hesitant, because this only applies when mode == >> 'w', and open has a large and growing list of parameters. > > The buffer parameter (I believe it is) also does not always apply. > > The original open builtin was a thin wrapper around old C's stdio.open. > Open no longer has that constraint. After more discussion here, someone > could open a tracker issue with a specific proposal. Keep in mind that > 'mode' is already a parameter name for the mode of opening, as opposed > to the permission mode for subsequent users. > I haven't seen the current code - I'd guess it just uses posix open. So I would guess it wouldn't be difficult to add the creation mode argument. How about call it cr_mode? From howmuchistoday at gmail.com Sat Jun 9 18:44:44 2012 From: howmuchistoday at gmail.com (Yesterday Paid) Date: Sat, 9 Jun 2012 15:44:44 -0700 (PDT) Subject: which one do you prefer? python with C# or java? Message-ID: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> I'm planning to learn one more language with my python. Someone recommended to do Lisp or Clojure, but I don't think it's a good idea(do you?) So, I consider C# with ironpython or Java with Jython. It's a hard choice...I like Visual studio(because my first lang is VB6 so I'm familiar with that) but maybe java would be more useful out of windows. what do you think? From cs at zip.com.au Sat Jun 9 18:57:14 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 10 Jun 2012 08:57:14 +1000 Subject: mode for file created by open In-Reply-To: References: Message-ID: <20120609225714.GA22529@cskk.homeip.net> On 09Jun2012 07:42, Neal Becker wrote: | Cameron Simpson wrote: | Doesn't anyone else think it would be a good addition to open to specify a file | creation mode? Like posix open? Avoid all these nasty workarounds? -1 open() is cross platform. os.open() is platform specific, generally POSIX. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Is it true, Sen. Bedfellow, that your wife rides with bikers? - Milo Bloom From cs at zip.com.au Sat Jun 9 18:58:45 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 10 Jun 2012 08:58:45 +1000 Subject: mode for file created by open In-Reply-To: References: Message-ID: <20120609225845.GA22699@cskk.homeip.net> On 09Jun2012 18:25, Neal Becker wrote: | I haven't seen the current code - I'd guess it just uses posix open. | So I would guess it wouldn't be difficult to add the creation mode argument. | How about call it cr_mode? What shall it contain on Windows? What shall it contain on Jython? -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If you push something hard enough, it will fall over. [Fudd's first law of opposition] From tjreedy at udel.edu Sat Jun 9 19:03:07 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 09 Jun 2012 19:03:07 -0400 Subject: mode for file created by open In-Reply-To: References: <20120608231946.GA2379@cskk.homeip.net> Message-ID: On 6/9/2012 6:25 PM, Neal Becker wrote: > Terry Reedy wrote: > >> The original open builtin was a thin wrapper around old C's stdio.open. >> Open no longer has that constraint. After more discussion here, someone >> could open a tracker issue with a specific proposal. Keep in mind that >> 'mode' is already a parameter name for the mode of opening, as opposed >> to the permission mode for subsequent users. >> > > I haven't seen the current code - I'd guess it just uses posix open. open is io.open. io.py mostly just imports _io (from .c). That will do whatever is appropriate for the platform. > > So I would guess it wouldn't be difficult to add the creation mode argument. On posix system, probably not. On windows, just ignore it, unless 'root' can be mapped to 'admin'. > > How about call it cr_mode? Probably too cryptic. creation_mode possible. -- Terry Jan Reedy From bex.lewis at gmail.com Sat Jun 9 19:04:41 2012 From: bex.lewis at gmail.com (becky_lewis) Date: Sat, 9 Jun 2012 16:04:41 -0700 (PDT) Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> Message-ID: <83a9b3b8-78fe-4fce-b486-2a25fe9070f5@s9g2000vbg.googlegroups.com> Lisp and Clojure are functional languages. Learning one of those (or a similar language) will help by providing you with a fairly different perspective on how to approach programming problems. Personally I think learning Lisp or Clojure is good advice. However, if you're really adamant about going with Java or C# I'd probably go with Java. Not only can you play around on multiple platforms but should you decide to give Clojure a go in the future it'll come in handy :) (Clojure runs on the JVM so you can make use of Java libraries directly from it). On Jun 9, 11:44?pm, Yesterday Paid wrote: > I'm planning to learn one more language with my python. > Someone recommended to do Lisp or Clojure, but I don't think it's a > good idea(do you?) > So, I consider C# with ironpython or Java with Jython. > It's a hard choice...I like Visual studio(because my first lang is VB6 > so I'm familiar with that) > but maybe java would be more useful out of windows. > > what do you think? From cs at zip.com.au Sat Jun 9 19:19:27 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 10 Jun 2012 09:19:27 +1000 Subject: mode for file created by open In-Reply-To: References: Message-ID: <20120609231927.GA23964@cskk.homeip.net> On 09Jun2012 19:03, Terry Reedy wrote: | > So I would guess it wouldn't be difficult to add the creation mode argument. | | On posix system, probably not. On windows, just ignore it, unless 'root' | can be mapped to 'admin'. Oh please NO! Either implement it correctly, or raise a ValueError if it is supplied and not whatever means "default open". A huge -1000 for arguments that have meaning but are ignored. This is why I'm -1 to start with: a file permission bitmap is a posix.open() value. It does not map portably to the general open(). -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ This calls for a really stupid and futile gesture. - Strayhorn From jeanpierreda at gmail.com Sat Jun 9 19:55:57 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 9 Jun 2012 19:55:57 -0400 Subject: which one do you prefer? python with C# or java? In-Reply-To: <83a9b3b8-78fe-4fce-b486-2a25fe9070f5@s9g2000vbg.googlegroups.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <83a9b3b8-78fe-4fce-b486-2a25fe9070f5@s9g2000vbg.googlegroups.com> Message-ID: On Sat, Jun 9, 2012 at 7:04 PM, becky_lewis wrote: > Lisp and Clojure are functional languages. Sorry, pet peeve. Lisps are a class of languages that are only united by their common syntax and their use of syntax transformations (macros). Most lisps are not really functional at all, not any moreso than Python. I mean, sure, they have first class functions, and map, and reduce -- but so does Python. (On the other hand, they sometimes support creation of immutable types, Python makes this difficult). There are functional lisps, of course, just like there are imperative ones -- see, for example, Qi and Liskell. > However, if you're really adamant about going with Java or C# I'd > probably go with Java. Not only can you play around on multiple > platforms but should you decide to give Clojure a go in the future > it'll come in handy :) (Clojure runs on the JVM so you can make use of > Java libraries directly from it). On the contrary, of the two, I would learn C#, because it's more fun to work with than Java (subjective as that judgement may be.) They've got your type inference here, nullable types there, dynamic typing over here, generators all the way back there... But if any language is available, I would learn C. All these high-level languages are really more similar than they are different (although Java-style static typing is kinda interesting). C has, fundamentally, some properties very few programming languages do, with regards to memory access and safety, as well as compilation model and status (as the lingua franca of ABIs). It also can work together with CPython and PyPy, via wrappers written in C itself, or Cython or ctypes. Other weird/great languages that expand your mind: Prolog, Haskell, Agda (learn it after Haskell). Of those three, Prolog would be easiest to use with Python, due to its predictable execution and the existence of bindings (search PyPI). -- Devin From no.email at nospam.invalid Sat Jun 9 20:05:13 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 09 Jun 2012 17:05:13 -0700 Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> Message-ID: <7xobos116u.fsf@ruckus.brouhaha.com> Yesterday Paid writes: > I'm planning to learn one more language with my python. > Someone recommended to do Lisp or Clojure, but I don't think it's a > good idea(do you?) Why do you want to do that? First of all, why not stick with learning one language at a time? Get familiar with one before moving on to the next. Second, what is your goal in wanting to learn multiple languages? The right advice to give you depends on what your goals are. In my opinion (this is not a universally accepted notion), Python and Clojure are at least spiritually similar to Lisp. So if you know one of them, the other two should be easy. That might be good or bad depending on your goals. Good because it means you get extra tools without a lot of extra effort. Bad because you're learning something close to something you already know, rather than something new and different. I'd suggest C# after Python, out of languages in your list. Not because C# is great or anything like that, but because it's different, so you get exposed to more concepts. After C# you might try Haskell, which will expand your horizons even further. From tim at akwebsoft.com Sat Jun 9 20:12:49 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Sat, 9 Jun 2012 16:12:49 -0800 Subject: which one do you prefer? python with C# or java? In-Reply-To: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> Message-ID: <20120610001249.GA382@mail.akwebsoft.com> * Yesterday Paid [120609 14:52]: > I'm planning to learn one more language with my python. > Someone recommended to do Lisp or Clojure, but I don't think it's a > good idea(do you?) > So, I consider C# with ironpython or Java with Jython. > It's a hard choice...I like Visual studio(because my first lang is VB6 > so I'm familiar with that) > but maybe java would be more useful out of windows. I am kind on the same wavelength as becky_lewis - and bye the way is not clojure based on java? Two lesser known programming languages that I have done extensive development with in the past are rebol (www.rebol.com) and newlisp (http://www.newlisp.org/) newlisp and rebol are both *symbolic* languages as well as newlisp is very *functional* The additional advantage of using newlisp is that the very mention of newlisp drives the lispers crazy. Just mention 'newlisp' and watch the spittle fly. On the other hand, clojure and C# have a much larger user base. (small-user-base) is why I don't use newlisp or rebol for any new projects. MTCW -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From kwa at kuwata-lab.com Sat Jun 9 21:55:13 2012 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Sun, 10 Jun 2012 10:55:13 +0900 Subject: [Q] How to specify options for 'setup.py install' by environment variable? Message-ID: Hi, "setup.py install" command supports options such as --prefix, --install-scripts, and so on. For example: $ python setup.py install --prefix=$PWD/local --install-scripts=$PWD/bin Question: is it possible to specify these options by environment variable? I want to specify --prefix or --install-scripts options, but it is too troublesome for me to specify them in command line every time. -- regards, makoto kuwata From abcampbell.mt at gmail.com Sat Jun 9 22:46:56 2012 From: abcampbell.mt at gmail.com (Adam Campbell) Date: Sat, 9 Jun 2012 19:46:56 -0700 (PDT) Subject: Nexus Programming Language Message-ID: <9b7c32dc-fd7c-4c4d-9765-0a629939da48@m8g2000yqo.googlegroups.com> The Nexus programming language version 0.5.0 has been released. It is an "object-oriented, dynamically-typed, reflective programming language", drawing from Lua and Ruby. www.nexuslang.org From nad at acm.org Sat Jun 9 22:55:51 2012 From: nad at acm.org (Ned Deily) Date: Sat, 09 Jun 2012 19:55:51 -0700 Subject: [Q] How to specify options for 'setup.py install' by environment variable? References: Message-ID: In article , Makoto Kuwata wrote: > Hi, > > "setup.py install" command supports options such as --prefix, > --install-scripts, and so on. > For example: > > $ python setup.py install --prefix=$PWD/local --install-scripts=$PWD/bin > > Question: is it possible to specify these options by environment variable? > I want to specify --prefix or --install-scripts options, but it is > too troublesome for me to specify them in command line every time. There are some environment variable options for Distutils-based (i.e. with setup.py) installations. The supported method is to put frequently-used preferences into one of several configuration files. See http://docs.python.org/install/index.html#inst-config-fileshttp://docs.py thon.org/install/index.html#inst-config-files -- Ned Deily, nad at acm.org From vijay.nori at gmail.com Sat Jun 9 22:58:07 2012 From: vijay.nori at gmail.com (V N) Date: Sat, 9 Jun 2012 19:58:07 -0700 (PDT) Subject: compiling py 2.7.3 with openssl Message-ID: RHEL 5.3 x86_64 / Python 2.7.3 compiled as shown below ==> PYTHON=Python-2.7.3 tar xjf bin/$PYTHON.tar.bz2 cd $PYTHON PYHOME=/usr/local/$PYTHON; export PYHOME LDFLAGS="-L/usr/local/lib64"; export LDFLAGS CPPFLAGS="-I/usr/local/include/ncurses -I/usr/local/include/readline -I/usr/local/include"; export CPPFLAGS ./configure --prefix=$PYHOME 1>"$PYTHON"_cfg.log 2>&1 make 1>"$PYTHON"_mk.log 2>&1 sudo make install 1>"$PYTHON"_inst.log 2>&1 able to install setuptools-0.6c11 and libraries such as nose, cx_Oracle, pyODBC, etc. suppose I compile and install openssl (same thing happens with openssl 1.0.0x as well) OPNSSL=openssl-1.0.1c tar xzf bin/$OPNSSL.tar.gz cd $OPNSSL ./config --prefix=/usr/local zlib-dynamic 1>"$OPNSSL"_cfg.log 2>&1 make 1>"$OPNSSL"_mk.log 2>&1 sudo make install 1>"$OPNSSL"_inst.log 2>&1 and change CPPFLAGS as CPPFLAGS="... -I/usr/local/include/openssl -I/usr/local/include"; export CPPFLAGS I can compile python but when I trying to install setuptools-0.6c11, I get [... setuptools-0.6c11]$ sudo -E $PYHOME/bin/python setup.py build install running build running build_py running install ERROR:root:code for hash md5 was not found. Traceback (most recent call last): File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type md5 ERROR:root:code for hash sha1 was not found. Traceback (most recent call last): File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha1 ERROR:root:code for hash sha224 was not found. Traceback (most recent call last): File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha224 ERROR:root:code for hash sha256 was not found. Traceback (most recent call last): File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha256 ERROR:root:code for hash sha384 was not found. Traceback (most recent call last): File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha384 ERROR:root:code for hash sha512 was not found. Traceback (most recent call last): File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/usr/local/Python-2.7.3/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha512 Traceback (most recent call last): File "setup.py", line 94, in scripts = scripts, File "/usr/local/Python-2.7.3/lib/python2.7/distutils/core.py", line 152, in setup dist.run_commands() File "/usr/local/Python-2.7.3/lib/python2.7/distutils/dist.py", line 953, in run_commands self.run_command(cmd) File "/usr/local/Python-2.7.3/lib/python2.7/distutils/dist.py", line 972, in run_command cmd_obj.run() File "/export/home/myacc/setuptools-0.6c11/setuptools/command/install.py", line 76, in run self.do_egg_install() File "/export/home/myacc/setuptools-0.6c11/setuptools/command/install.py", line 85, in do_egg_install easy_install = self.distribution.get_command_class('easy_install') File "/export/home/myacc/setuptools-0.6c11/setuptools/dist.py", line 395, in get_command_class self.cmdclass[command] = cmdclass = ep.load() File "/export/home/myacc/setuptools-0.6c11/pkg_resources.py", line 1954, in load entry = __import__(self.module_name, globals(),globals(), ['__name__']) File "/export/home/myacc/setuptools-0.6c11/setuptools/command/easy_install.py", line 21, in from setuptools.package_index import PackageIndex, parse_bdist_wininst File "/export/home/myacc/setuptools-0.6c11/setuptools/package_index.py", line 10, in from md5 import md5 File "/usr/local/Python-2.7.3/lib/python2.7/md5.py", line 10, in from hashlib import md5 ImportError: cannot import name md5 From kwa at kuwata-lab.com Sun Jun 10 00:24:05 2012 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Sun, 10 Jun 2012 13:24:05 +0900 Subject: [Q] How to specify options for 'setup.py install' by environment variable? In-Reply-To: References: Message-ID: On Sun, Jun 10, 2012 at 11:55 AM, Ned Deily wrote: > In article > , > ?Makoto Kuwata wrote: > >> Hi, >> >> "setup.py install" command supports options such as --prefix, >> --install-scripts, and so on. >> For example: >> >> ? $ python setup.py install --prefix=$PWD/local --install-scripts=$PWD/bin >> >> Question: is it possible to specify these options by environment variable? >> I want to specify --prefix or --install-scripts options, but it is >> too troublesome for me to specify them in command line every time. > > There are some environment variable options for Distutils-based (i.e. > with setup.py) installations. ?The supported method is to put > frequently-used preferences into one of several configuration files. > See > http://docs.python.org/install/index.html#inst-config-fileshttp://docs.py > thon.org/install/index.html#inst-config-files Thank you Ned, but I can't find environment variable name on that page which is equivarent to '--install-scripts' or other options. $PYTHONHOME seems equivarent to --prefix option, but the following reports error. $ mkdir -p local/lib/python2.7/site-packages $ PYTHONHOME=local python setup.py install ImportError: No module named site -- regards, makoto kuwata From rustompmody at gmail.com Sun Jun 10 01:45:55 2012 From: rustompmody at gmail.com (rusi) Date: Sat, 9 Jun 2012 22:45:55 -0700 (PDT) Subject: Nexus Programming Language References: <9b7c32dc-fd7c-4c4d-9765-0a629939da48@m8g2000yqo.googlegroups.com> Message-ID: <034525d9-50d7-4221-824e-b66cf11c6c88@po9g2000pbb.googlegroups.com> On Jun 10, 7:46?am, Adam Campbell wrote: > The Nexus programming language version 0.5.0 has been released. It is > an "object-oriented, dynamically-typed, reflective programming > language", drawing from Lua and Ruby.www.nexuslang.org What does nexus have that python doesn't? Yeah I know this kind of question leads to flames but a brief glance at the about page does not tell me anything in this direction. From rustompmody at gmail.com Sun Jun 10 02:16:35 2012 From: rustompmody at gmail.com (rusi) Date: Sat, 9 Jun 2012 23:16:35 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> Message-ID: <0efa2cbd-c0a3-4dcb-beae-2cdf9063999a@l10g2000pbi.googlegroups.com> On Jun 9, 10:07 pm, Dietmar Schwertberger wrote: > > And you can than go in the code editor to that function and change the > > code to do whatever you want. > > Having to go there is already more work than I would expect. > I would expect to go there e.g. by a double-click. > > This is just a minor point, but many minor points sum up... > > If you take maybe 10 people each with some BASIC or Python knowledge, > I would bet that you can teach most of them how to write a > simple GUI program in VB within five minutes, but you'll probably fail > with Boa. (And even then you would have to re-teach them in a few > months when they try to write their next program.) This is worth a read in this context: http://osteele.com/archives/2004/11/ides From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sun Jun 10 02:31:02 2012 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sun, 10 Jun 2012 06:31:02 +0000 (UTC) Subject: Compare 2 times References: <5bc8f150-4a1f-401c-9bc5-79ea1e1baac9@h9g2000yqi.googlegroups.com> Message-ID: t_texas wrote: > On Jun 6, 7:50?am, loial wrote: >> I have a requirement to test the creation time of a file with the >> current time and raise a message if the file is ?more than 15 minutes >> old. >> >> Platform is Unix. >> >> I have looked at using os.path.getctime for the file creation time and >> time.time() for the current time, but is this the best approach? > > Unless you are using ext4 you are going to have to store the creation > time yourself. If the files are coming from your application, use the > sqlite3 or shelve module to store the creation time for each file then > check that data to determine which files are more than 15 minutes old. > pyinotify might be worth a look -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From nad at acm.org Sun Jun 10 02:51:56 2012 From: nad at acm.org (Ned Deily) Date: Sat, 09 Jun 2012 23:51:56 -0700 Subject: [Q] How to specify options for 'setup.py install' by environment variable? References: Message-ID: In article , Makoto Kuwata wrote: > On Sun, Jun 10, 2012 at 11:55 AM, Ned Deily wrote: > > In article > > , > > ?Makoto Kuwata wrote: > >> "setup.py install" command supports options such as --prefix, > >> --install-scripts, and so on. > >> For example: > >> > >> ? $ python setup.py install --prefix=$PWD/local --install-scripts=$PWD/bin > >> > >> Question: is it possible to specify these options by environment variable? > >> I want to specify --prefix or --install-scripts options, but it is > >> too troublesome for me to specify them in command line every time. > > There are some environment variable options for Distutils-based (i.e. > > with setup.py) installations. ?The supported method is to put > > frequently-used preferences into one of several configuration files. > > See > > http://docs.python.org/install/index.html#inst-config-fileshttp://docs.py > > thon.org/install/index.html#inst-config-files > > Thank you Ned, > but I can't find environment variable name on that page which is > equivarent to '--install-scripts' or other options. Sorry, I wasn't clear. Using the Distutils config files would be instead of setting environment variables. For example, you could do something like this: $ cat >$HOME/.pydistutils.cfg < Greets! Since i'm new to Python, i've decided to create a handy plugin for Elipse SDK which is my primary dev environment. Practically the plugin is a simple html archive from python documentation website running inside Eclipse so you can call it using Eclipse help system. As for now it is pretty large (~7 mb), but i'm planning to optimize it in near future. For more information, please visit: http://pydoc.tk/ or https://sourceforge.net/projects/pydoc/ ------------------------------------------------------------------------ Advices are appreciated! Contact e-mail:
ahaidamaka at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ahaidamaka at gmail.com Sun Jun 10 05:22:39 2012 From: ahaidamaka at gmail.com (Alexey Gaidamaka) Date: Sun, 10 Jun 2012 12:22:39 +0300 Subject: PyDoc - Python Documentation Plugin for Eclipse In-Reply-To: <4FD46567.2080003@gmail.com> References: <4FD46567.2080003@gmail.com> Message-ID: <4FD4675F.3080404@gmail.com> Greets! Since i'm new to Python, i've decided to create a handy plugin for Elipse SDK which is my primary dev environment. Practically the plugin is a simple html archive from python documentation website running inside Eclipse so you can call it using Eclipse help system. As for now it is pretty large (~7 mb), but i'm planning to optimize it in near future. For more information, please visit: http://pydoc.tk/ or https://sourceforge.net/projects/pydoc/ ------------------------------------------------------------------------ Advices are appreciated! Contact e-mail:
ahaidamaka at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Sun Jun 10 06:02:35 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 10 Jun 2012 05:02:35 -0500 Subject: PyDoc - Python Documentation Plugin for Eclipse In-Reply-To: <4FD4675F.3080404@gmail.com> References: <4FD46567.2080003@gmail.com> <4FD4675F.3080404@gmail.com> Message-ID: <4FD470BB.8030002@gmail.com> On 6/10/2012 4:22 AM, Alexey Gaidamaka wrote: > Practically the plugin is a simple html archive from python > documentation website running > inside Eclipse so you can call it using Eclipse help system. > As for now it is pretty large (~7 mb), but i'm planning to optimize it > in near future. Rather than archive documentation, why not use a simple static page that points to the different sections for each version of Python on docs.python.org? The 2.7.3 documentation is mostly useless to me since I'm using 3.3 (and of course there are some using 2.6 or 3.2 or 3.1...), but I can easily access it from a link in the page you've archived. Not only would this reduce the size of the plugin to almost nothing, but it would prevent the documentation from being outdated. > For more information, please visit: > https://sourceforge.net/projects/pydoc/ Why isn't it installed like other Eclipse plugins? Is it even possible to update the plugin via Eclipse? This does look like a very useful plugin, though. Great idea. -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From arnodel at gmail.com Sun Jun 10 06:36:07 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 10 Jun 2012 11:36:07 +0100 Subject: =?UTF-8?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=C3=A0_la_Inte?= =?UTF-8?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= In-Reply-To: <0efa2cbd-c0a3-4dcb-beae-2cdf9063999a@l10g2000pbi.googlegroups.com> References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> <0efa2cbd-c0a3-4dcb-beae-2cdf9063999a@l10g2000pbi.googlegroups.com> Message-ID: On 10 June 2012 07:16, rusi wrote: > This is worth a read in this context: http://osteele.com/archives/2004/11/ides Interesting! I definitely fall nicely at one extreme of this dichotomy. Every time I've tried to use an IDE, it's made me feel inadequate and I've quickly retreated to my comfort zone (emacs + xterm). I felt inadequate because I felt like the IDE was hindering me rather than helping me. All I ask from the program that I use to write code is: * syntax highlighting * sensible auto-indenting * as little reliance on the mouse as possible * emacs key bindings :) This article makes me feel more positive about my inability to feel comfortable in an IDE. Thanks for the link! -- Arnaud From hanche at math.ntnu.no Sun Jun 10 07:25:57 2012 From: hanche at math.ntnu.no (Harald Hanche-Olsen) Date: Sun, 10 Jun 2012 13:25:57 +0200 Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <83a9b3b8-78fe-4fce-b486-2a25fe9070f5@s9g2000vbg.googlegroups.com> Message-ID: [becky_lewis ] > Lisp and Clojure are functional languages. No, they're not. But you can (and often will) do quite a bit of functional programming in Lisp, as it lends itself quite naturally to that way of thinking. But in (Common) Lisp you also have CLOS, which is a rather different way to do object oriented programming. It will widen your horizon in more than one way. The advice to learn just one programming language at a time seems sound, though. I would take it, if I were you. -- * Harald Hanche-Olsen - It is undesirable to believe a proposition when there is no ground whatsoever for supposing it is true. -- Bertrand Russell From news at schwertberger.de Sun Jun 10 07:52:43 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sun, 10 Jun 2012 13:52:43 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= In-Reply-To: <0efa2cbd-c0a3-4dcb-beae-2cdf9063999a@l10g2000pbi.googlegroups.com> References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> <0efa2cbd-c0a3-4dcb-beae-2cdf9063999a@l10g2000pbi.googlegroups.com> Message-ID: Am 10.06.2012 08:16, schrieb rusi: > This is worth a read in this context: http://osteele.com/archives/2004/11/ides So which language would you suggest to use next? ;-) I've read the article. It presents some nice ideas, but probably the author has not used Python before. Otherwise he would have noticed that the overall productivity does not only depend on language and IDE/editor, but on the complete environment which in the case of Python includes the ability to use the interpreter interactively. For many tasks that's a major productivity boost. But that's a point that many people don't see because their current language like C# or Java does not have an interpreter and when they just look at the syntax, the find "there's not enough improvement to switch". Also, I'm not sure whether the author counts the libraries as language or tool feature. In my opinion the environment and the libraries should be listed on their own in such an article. Libraries are developed after the language, but usually they are ahead of the other tools/IDEs. The author lists many IDE features that I personally don't find too important (the refactoring capabilities of a simple text editor are fine for me...). But following the link to Laszlo made the reason quite clear because his IDE background is from Eclipse not from Python. Btw.: I've been using Python for 16 or 17 years now. Only 3 years ago I did the switch from Editor to IDE (Wing IDE) and this has brought a *significant* boost of productivity (especially the good debugger allows you to code in a different way as you can use the interactive interpreter at any point in your program). But back to my original point, this time in the context of the article: If you want to 'sell' a programming language for corporate use, you absolutely need the tools. And this includes an easy-to-use GUI editor which does not only allow to create the GUI, but also to fill it with code. Most corporate users are casual users, not full time programmers. Regards, Dietmar From bex.lewis at gmail.com Sun Jun 10 07:56:15 2012 From: bex.lewis at gmail.com (becky_lewis) Date: Sun, 10 Jun 2012 04:56:15 -0700 (PDT) Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <83a9b3b8-78fe-4fce-b486-2a25fe9070f5@s9g2000vbg.googlegroups.com> Message-ID: <1bb58392-fece-4ebe-872a-e3342d2fe65b@w24g2000vby.googlegroups.com> My mistake about Lisp being purely functional (I have very little experience with common Lisp itself), though Clojure is. That doesn't change my point, to which you appear to agree, Lisp and Clojure teach folks a different way of approaching problems, which is always useful :) On Jun 10, 12:25?pm, Harald Hanche-Olsen wrote: > [becky_lewis ] > > > Lisp and Clojure are functional languages. > > No, they're not. > > But you can (and often will) do quite a bit of functional programming in > Lisp, as it lends itself quite naturally to that way of thinking. > > But in (Common) Lisp you also have CLOS, which is a rather different way > to do object oriented programming. It will widen your horizon in more > than one way. > > The advice to learn just one programming language at a time seems sound, > though. I would take it, if I were you. > > -- > * Harald Hanche-Olsen ? ? > - It is undesirable to believe a proposition > ? when there is no ground whatsoever for supposing it is true. > ? -- Bertrand Russell From tbaror at gmail.com Sun Jun 10 08:15:00 2012 From: tbaror at gmail.com (tbaror at gmail.com) Date: Sun, 10 Jun 2012 05:15:00 -0700 (PDT) Subject: looking for a python script disk/storage benchmark Message-ID: <8795b8d8-814e-4ee6-8b2f-cb6d525da00f@googlegroups.com> Hi All, I am started to write a utility (python 3.x) to test storage/disk benchmark , my thought were using binary buffered Io, but i would like to see if there any script out there written so i would use as template searching via Google found only one but not what exactly what i am looking for. if someone knows or have one please share. Thanks From cjw at ncf.ca Sun Jun 10 08:21:01 2012 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 10 Jun 2012 08:21:01 -0400 Subject: Nexus Programming Language In-Reply-To: <034525d9-50d7-4221-824e-b66cf11c6c88@po9g2000pbb.googlegroups.com> References: <9b7c32dc-fd7c-4c4d-9765-0a629939da48@m8g2000yqo.googlegroups.com> <034525d9-50d7-4221-824e-b66cf11c6c88@po9g2000pbb.googlegroups.com> Message-ID: On 10/06/2012 1:45 AM, rusi wrote: > On Jun 10, 7:46 am, Adam Campbell wrote: >> The Nexus programming language version 0.5.0 has been released. It is >> an "object-oriented, dynamically-typed, reflective programming >> language", drawing from Lua and Ruby.www.nexuslang.org > > What does nexus have that python doesn't? > Yeah I know this kind of question leads to flames but a brief glance > at the about page does not tell me anything in this direction. It has a more complex block structure, with lots of braces {}. Colin W. From animator333 at gmail.com Sun Jun 10 08:38:13 2012 From: animator333 at gmail.com (Prashant) Date: Sun, 10 Jun 2012 05:38:13 -0700 (PDT) Subject: Another non blocking method in thread Message-ID: <62ed1b28-ad2a-400f-941a-7e54bf9cb17c@googlegroups.com> Hi, I have created a very simple client-server model using sockets. Server is created by sub classing threading.thread. The 'run' method is continuously listening for client's response. When server send a string to client, client response back by changing that string into uppercase. I would like to synchronize send and receive. For example: def sendmsg(self, msg): self.client.send(msg) #wait until next msg is received in 'run' return self.response I tried using a while loop for waiting but it's blocking the 'run' method. Don't know much about threading event and lock and if they can help me here. Any pointers? Prashant From mcepl at redhat.com Sun Jun 10 09:40:41 2012 From: mcepl at redhat.com (Matej Cepl) Date: Sun, 10 Jun 2012 15:40:41 +0200 Subject: which one do you prefer? python with C# or java? In-Reply-To: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> Message-ID: <4FD4A3D9.5040500@redhat.com> On 10/06/12 00:44, Yesterday Paid wrote: > I'm planning to learn one more language with my python. Just my personal experience, but after passively learning many many languages, I came to the conclusion that I (and I suppose many others) am able to learn only one platform well. The point is that you are never interested in learning *a language*, everybody who has at least some touch with programming can learn most languages in one session in the afternoon. But nobody is interested in you knowing a language, you need to know the platform with all libraries, standards, style, and culture. And *that* demands you focus on one language completely. Yes, of course, you will know couple of other languages and be able to write a thing in it (everybody needs to know a bit of JavaScript these days, and if you are on Unix/Linux,Mac OS X, you need to know a bit of shell scripting), but that's different from "Zen & Writing" (that's my personal homage to recently deceased Ray Bradbury and his essay http://www.worldcat.org/search?qt=wikipedia&q=isbn%3A1877741094). The language in which you write those 100 lines of code per day (that's my rough estimate of an equivalent for Bradbury's daily portion of prose to be written) should be IMHO only the one. I think the similarity with story writing makes a lot of sense. Yes, many people speak and write more than one language (me included, English is not my first language), but that's not the same as writing stories professionally. At the moment, I can think only about one successful famous writer how changed his main language (Kundera), but I don't recall ATM any writer who would be writing in multiple languages at one time. (yes, switches between main programming languages is more possible, because programming languages are endlessly less complicated than natural ones) Just my 0.02CZK Mat?j From rosuav at gmail.com Sun Jun 10 10:25:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jun 2012 00:25:02 +1000 Subject: which one do you prefer? python with C# or java? In-Reply-To: <4FD4A3D9.5040500@redhat.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> Message-ID: On Sun, Jun 10, 2012 at 11:40 PM, Matej Cepl wrote: > Just my personal experience, but after passively learning many many > languages, I came to the conclusion that I (and I suppose many others) am > able to learn only one platform well. The point is that you are never > interested in learning *a language*, everybody who has at least some touch > with programming can learn most languages in one session in the afternoon. > But nobody is interested in you knowing a language, you need to know the > platform with all libraries, standards, style, and culture. And *that* > demands you focus on one language completely. Currently, I'm working professionally in Pike, C++, bash, PHP, and Javascript, but only one platform: Unix. Everything's done to our own internal philosophy, which mostly aligns with the Unix notion of building small tools that link together (rather than monoliths for entire tasks). Learning and managing multiple languages isn't itself a problem, though I do recommend learning just one at a time until you stop considering yourself a novice (master a half-dozen languages or so, that's a start). ChrisA From ahaidamaka at gmail.com Sun Jun 10 11:37:50 2012 From: ahaidamaka at gmail.com (Alexey Gaidamaka) Date: Sun, 10 Jun 2012 15:37:50 +0000 (UTC) Subject: PyDoc - Python Documentation Plugin for Eclipse References: <4FD46567.2080003@gmail.com> <4FD4675F.3080404@gmail.com> <4FD470BB.8030002@gmail.com> Message-ID: On Sun, 10 Jun 2012 05:02:35 -0500, Andrew Berg wrote: > On 6/10/2012 4:22 AM, Alexey Gaidamaka wrote: >> Practically the plugin is a simple html archive from python >> documentation website running >> inside Eclipse so you can call it using Eclipse help system. As for now >> it is pretty large (~7 mb), but i'm planning to optimize it in near >> future. > Rather than archive documentation, why not use a simple static page that > points to the different sections for each version of Python on > docs.python.org? The 2.7.3 documentation is mostly useless to me since > I'm using 3.3 (and of course there are some using 2.6 or 3.2 or 3.1...), > but I can easily access it from a link in the page you've archived. Not > only would this reduce the size of the plugin to almost nothing, but it > would prevent the documentation from being outdated. > >> For more information, please visit: >> https://sourceforge.net/projects/pydoc/ > Why isn't it installed like other Eclipse plugins? Is it even possible > to update the plugin via Eclipse? > > > This does look like a very useful plugin, though. Great idea. Thanx! All that you've mentioned is planned in the next versions of the plugin. From no.email at nospam.invalid Sun Jun 10 12:32:43 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 10 Jun 2012 09:32:43 -0700 Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> Message-ID: <7xwr3fjff8.fsf@ruckus.brouhaha.com> Matej Cepl writes: > The point is that you are never interested in learning *a language*, > everybody who has at least some touch with programming can learn most > languages in one session in the afternoon. Really, that's only if the new language is pretty much the same as the old ones, in which case you haven't really learned much of anything. Languages that use interesting new concepts are challenges in their own right. Here is an interesting exercise for statically typed languages, unsuitable for Python but not too hard in Haskell: http://blog.tmorris.net/understanding-practical-api-design-static-typing-and-functional-programming/ It doesn't require the use of any libraries, standards, style, or culture. I can tell you as a fairly strong Python programemr who got interested in Haskell a few years ago, it took me much longer than an afternoon to get to the point of being able to solve a problem like the above. It required absorbing new concepts that Python simply does not contain. But it gave me the ability to do things I couldn't do before. That's a main reason studying new languages is challenging and worthwhile. From kw at codebykevin.com Sun Jun 10 12:40:23 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 10 Jun 2012 12:40:23 -0400 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= In-Reply-To: <20120608142721.3ab95cb7.feliphil@gmx.net> References: <20120608142721.3ab95cb7.feliphil@gmx.net> Message-ID: On 6/8/12 8:27 AM, Wolfgang Keller wrote: > What "GUI designer" would come the closest to the way that Cocoa's > Interface Builder works? I.e. is there any one (cross-platform) that > allows to actually "connect" the GUI created directly to the code and > make it available "live" in an IDE? If you're developing on the Mac, PyObjC allows you to use Interface Builder for developing Python apps. However, there are those of us who are deeply uncomfortable with IB and related tools, such as RealBasic and LiveCode/Runtime Revolution. These tools make code organization very hard by reducing the amount of code written to the point of the UI working by "magic," and/or by breaking up your code into little snippets that you can only view by clicking on the widget in the UI tool. A related issue is that using a tool such as this makes you heavily dependent on that particular tool, and subject to its developers' priorities, release schedule, and bugs. The pace of Xcode development--with Apple making frequent changes to project formats in a backwards-incompatible way--is an example of this. One reason I prefer to code UI's by hand is because a) in Tkinter it's very easy to do, and b) it allows me to have a much better mental model of my code and my app's functionality--I can put everything into as many .py files as I need to, and can edit my code with any text editor. I think these issues are a reason that the slick "drag-and-drop" UI builders tend to be developed by commercial software shops to support their language and/or IDE, but find little traction among open-source developers and languages. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From rantingrickjohnson at gmail.com Sun Jun 10 14:50:52 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2012 11:50:52 -0700 (PDT) Subject: Nexus Programming Language References: <9b7c32dc-fd7c-4c4d-9765-0a629939da48@m8g2000yqo.googlegroups.com> <034525d9-50d7-4221-824e-b66cf11c6c88@po9g2000pbb.googlegroups.com> Message-ID: <245e86df-e405-4b8a-a840-6fdb5429fca2@i19g2000yqn.googlegroups.com> On Jun 10, 12:45?am, rusi wrote: > On Jun 10, 7:46?am, Adam Campbell wrote: > > > The Nexus programming language version 0.5.0 has been released. It is > > an "object-oriented, dynamically-typed, reflective programming > > language", drawing from Lua and Ruby.www.nexuslang.org > > What does nexus have that python doesn't? > Yeah I know this kind of question leads to flames but a brief glance > at the about page does not tell me anything in this direction. Oh rusi, you're not fooling anybody. We know your a total ruby fanboy and probably an "unoffical" member of the nexus dev team. From rantingrickjohnson at gmail.com Sun Jun 10 14:51:23 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2012 11:51:23 -0700 (PDT) Subject: Nexus Programming Language References: <9b7c32dc-fd7c-4c4d-9765-0a629939da48@m8g2000yqo.googlegroups.com> <034525d9-50d7-4221-824e-b66cf11c6c88@po9g2000pbb.googlegroups.com> Message-ID: <3469aa71-0feb-4271-bf1c-fdfb50ee89fd@l32g2000yqb.googlegroups.com> On Jun 10, 7:21?am, "Colin J. Williams" wrote: > On 10/06/2012 1:45 AM, rusi wrote: > > What does nexus have that python doesn't? > > Yeah I know this kind of question leads to flames but a brief glance > > at the about page does not tell me anything in this direction. > > It has a more complex block structure, with lots of braces {}. So in other words, it another Ruby? From rantingrickjohnson at gmail.com Sun Jun 10 14:56:16 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2012 11:56:16 -0700 (PDT) Subject: what gui designer is everyone using References: Message-ID: <56a2a6e3-ee18-4d4f-95fb-a216ac7db5f4@j10g2000yqd.googlegroups.com> On Jun 7, 4:18?pm, Kevin Walzer wrote: > On 6/5/12 10:10 AM, Mark R Rivet wrote: > > > I want a gui designer that writes the gui code for me. I don't want to > > write gui code. what is the gui designer that is most popular? > None. I write GUI code by hand (Tkinter). I second that notion. Writing GUI code by hand is the only way. From rantingrickjohnson at gmail.com Sun Jun 10 14:57:11 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2012 11:57:11 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> Message-ID: <36b25d5f-27a1-45a0-b8d5-b970b89b7840@b21g2000yqn.googlegroups.com> On Jun 8, 7:27?am, Wolfgang Keller wrote: > This whole cycle of "design GUI"->"generate code"->add own code to > generated code"->"run application with GUI" has always seemed very > un-pythonic to me. A dynamic, interpreted language should allow to work > in a more "lively", "direct" way to build a GUI. I strongly agree with this statement also. From mcepl at redhat.com Sun Jun 10 15:10:34 2012 From: mcepl at redhat.com (Matej Cepl) Date: Sun, 10 Jun 2012 21:10:34 +0200 Subject: which one do you prefer? python with C# or java? In-Reply-To: <7xwr3fjff8.fsf@ruckus.brouhaha.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> Message-ID: On 10/06/12 18:32, Paul Rubin wrote: > Really, that's only if the new language is pretty much the same as the > old ones, in which case you haven't really learned much of anything. > Languages that use interesting new concepts are challenges in their own > right. Well, I could at least passively read many languages (starting with Pascal, C, and unsuccessful attempt to learn Prolog, so even statically typed languages are not that mysterious to me), so learning new ones is not that problem. And yes, to be completely honest, functional languages are my weakest part (although I have used Emacs for some time, I still haven't learned writing in any Lisp properly). Mat?j From rantingrickjohnson at gmail.com Sun Jun 10 15:36:23 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2012 12:36:23 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> Message-ID: On Jun 9, 8:25?am, Dietmar Schwertberger wrote: > Before anyone now writes "Good GUIs are coded by hand": > I agree, but for many purposes only simple GUIs are required > and it should be possible to create these without studying manuals > (on toolkit and GUI editor). It is possible. Try Tkinter for the "get-you-from-a-to-b" solution, or, wxPython if you like fog lamps, heated seats, and navigation systems. > A typical simple GUI would e.g. be for a measurement / data aquisition > program, where you just need some buttons and fields. Buttons and feilds are just a few short lines of code. Look. You guys don't need a visual GUI builder. What you need to do is stop being lazy and spend a few hours studing the basics of Tkinter and wxPyhon (or whatever else suits your needs). IMO, every single python programmer who needs GUI interfaces should know the basics of AT LEAST Tkinter without even looking at the docs. I mean, how difficult is: import Tkinter as tk from Tkconstants import * root = tk.Tk() root.title('Noob') for x in range(10): f = tk.Frame(root) f.pack(fill=X, expand=YES) l = tk.Label(f, text="Field_"+str(x)) l.pack(side=LEFT, anchor=W) e = tk.Entry(f) e.pack(side=LEFT, fill=X, expand=YES) root.mainloop() # # Or even better. Use grid! # root = tk.Tk() root.title('Amatuer') root.columnconfigure(1, weight=1) for x in range(10): l = tk.Label(root, text="Field_"+str(x)) l.grid(row=x, column=0, sticky=W) e = tk.Entry(root) e.grid(row=x, column=1, sticky=W+E) root.mainloop() # # Or become a pro and create reusable objects! # class LE(tk.Frame): def __init__(self, master, **kw): tk.Frame.__init__(self, master) self.l = tk.Label(self, **kw) self.l.pack(side=LEFT) self.e = tk.Entry(self) self.e.pack(side=LEFT, fill=X, expand=YES) root = tk.Tk() root.title('Pro') for x in range(10): le = LE(root, text="Field_"+str(x)) le.pack(fill=X, expand=YES) root.mainloop() > > I think that something in the style of Visual BASIC (version 6) is required > for either wxPython or PyQt/PySide (or both). > In the Visual BASIC editor you can e.g. add a GUI element > and directly go to the code editor to fill methods (e.g. an OnClick > method). With Tkinter you add a GUI element IN THE CODE and then you are ALREADY in the code editor! What an amazing concept! No juggling editors and windows. No need to mentally switch from one language to another. Can you imagine how productive you could be? > If you have not used VB before, you should just try it. You can create > GUIs within a few minutes even if you haven't used it before. Allow me to qualify that very naive generalization: "ANYBODY and point and click, very few can actually write code". > (Sure, the fact that anyone can use it has the side effect that most > of these GUIs are not good...) Well i see that you agree. Look. This is fact. GUI's require you to write code. You cannot get around this fact. Sure, you can create some templates. But in the end, you will have to write in order to link the templates together. I say. If your GUI kit gives you the feeling that you are writing too much boilerplate, well, then, it's time to wrap up some re-usable functionality on your own. I have done this myself with Tkinter AND Wx. ( although much more so with Tkinter being that is a poorly designed GUI) > Also: > Such an editor should support simple manual layouts without enforcing > the use of sizers (wx) or layout managers (Qt). > These add an additional level of complexity which is not required > for simple GUIs. See above code for example of *gasps* simple layouts in REAL code! > Background: > I'm using Python in a corporate environment but I'm more or less > the only one using it. I could propagate Python for wider use as it > is the best available language for things like hardware control and > data acquisition, but the lack of an easy-to-use GUI editor is > the blocking point. BS! > I can teach anyone how to create a program for data > acquisition, but I don't see how more than a few could create a GUI > without an easy-to-use tool. Like Tkinter? > There's still a lot of VB6 code around as there's no replacement and > this gap could well be filled by Python. Visual Basic sucks. I spend more time re-focusing my mental energy than actually getting work done. There is no replacement for pure raw code. You visualize GUI's in you mind, and fingers bring that vision to life through properly written API's. Never invent a new problem for a solution that does not exist. From maillist at schwertberger.de Sun Jun 10 15:37:01 2012 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Sun, 10 Jun 2012 21:37:01 +0200 Subject: =?ISO-8859-15?Q?Re=3A_Pythonic_cross-platform_GUI_desing?= =?ISO-8859-15?Q?ers_=E0_la_Interface_Builder_=28Re=3A_what_?= =?ISO-8859-15?Q?gui_designer_is_everyone_using=29?= Message-ID: <4FD4F75D.40602@schwertberger.de> (Sorry for posting without references to the previous messages, but it seems that many messages don't get through to the nntp server that I'm using.) Chris Angelico wrote (in two posts): > There was a time when that was a highly advertisable feature - "build > XYZ applications without writing a single line of code!". I've seen it > in database front-end builders as well as GUI tools, same thing. But > those sorts of tools tend not to be what experts want to use. You end > up having to un-learn the "easy way" before you learn the "hard way" > that lets you do everything. This time is not over. Especially when you look at data acquisition and control applications where tools like Labview are widely used. Personally, I would not want to use such tools as I find it quite complicated to implement any logic with a graphical editor. But when you want to sell an alternative to such tools, then you should not offer a tool which makes it almost impossible for a typical engineer to create a simple GUI. > You refer to "non-programmers" and then point out that they would be > lost trying to add code. That's a natural consequence of not being a > programmer, Sure, but with "non-programmers" I'm referring to typical engineers who can implement some basic programs for measurement, control or data processing. > and of all languages to help someone bridge that gap and > start coding, I would say Python is, if not the absolute best, > certainly up there somewhere. Just as you wouldn't expect a music 100% agreed. It's the only programming language that I can recommend to casual or even non-programmers, but only as long as he/she's not interested in GUI programming. > authoring program to let someone publish score without knowing how to > compose music, you can't expect a GUI tool to relieve you of the need > to write code. The audience of GUI editors is not the artist / professional... > WYSIWYG UI designers suffer badly from a need to guess _why_ the human > did what s/he did. Build your UI manually, and there's no guesswork - > you explicitly _tell_ the computer what to do and why. True for non-trivial applications. I don't have many windows and dialogs that could have been created using a GUI editor in my main wxPython based application. But even then: I've learned wxPython from looking at the code that wxDesigner created. Of course, that was in 1999/2000 when no books on such matters were available. > There's an assumption in most of the Windows world that everything > needs a GUI. For a simple data acquisition program, I wouldn't use one > - I'd have it run in a console. That's something that any programmer > should be able to create without studying complex manuals; all you > need to know is the basics of I/O and possibly argument parsing. Yes, usually I'm using a console as most measurement programs are quite straighforward and linear. But I don't see a way to convince people to go back to the console. They will always want to implement a basic GUI for one or the other program and then they will end up frustrated... (Or I have to implement the GUI for them, which is not an option.) > I've used Visual Basic. My first salaried work was on VB. Making it > easy to throw together a simple GUI doesn't mean a thing when you have > a large project to write - your business logic and UI design work will I would never consider or recommend to write anything significant using a GUI builder. Also, I would never recommend anyone to use VB at all. But given the lack of alternatives, it still has a significant market share. (The fact that anyone can hack together a program in VB has the side- effect that most programs are not very good...) > massively dwarf the effort of actually throwing widgets into a > hierarchy. So the only time it's going to be an issue is with trivial > programs; which means there isn't much to be saved. Just make your > trivial things run in a console, and then either use a GUI builder > (several have been mentioned) or hand-write your UI code. Right, we're talking about non-trivial programs with almost trivial user interfaces. But I don't see a Python GUI builder which a casual user could use to add a GUI to the code. (To be exact: it's easy to create a GUI with one or the other builder, but non-trivial to connect it to the backend.) > Actually, there's a third option these days. Give it no console and no > GUI, make it respond to HTTP connections, and use a web browser as > your UI. :) I don't think that this is easier for the casual user as multiple languages and environments are involved. But on the other hand there are some (mainly commercial) organizations who believe that HTML5, CSS and Javascript are the future for GUI programming. Personally, I prefer Python with console, wx or Qt for local applications and Python/HTTP/HTML/Javascript for multi-user database applications. Regards, Dietmar From rantingrickjohnson at gmail.com Sun Jun 10 15:47:43 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2012 12:47:43 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> Message-ID: <0124bd28-bbb5-455f-b5c6-4af0e2f9747a@b21g2000yqn.googlegroups.com> On Jun 10, 2:36?pm, Rick Johnson wrote: > # > # Or become a pro and create reusable objects! > # > class LE(tk.Frame): > ? ? def __init__(self, master, **kw): > ? ? ? ? tk.Frame.__init__(self, master) > ? ? ? ? self.l = tk.Label(self, **kw) > ? ? ? ? self.l.pack(side=LEFT) > ? ? ? ? self.e = tk.Entry(self) > ? ? ? ? self.e.pack(side=LEFT, fill=X, expand=YES) > root = tk.Tk() > root.title('Pro') > for x in range(10): > ? ? le = LE(root, text="Field_"+str(x)) > ? ? le.pack(fill=X, expand=YES) > root.mainloop() PS: The keywords argument should have been passed to the entry widget and NOT the label. Yes, occasionally, even pros make subtle mistakes. From news at schwertberger.de Sun Jun 10 16:08:31 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Sun, 10 Jun 2012 22:08:31 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> Message-ID: Am 10.06.2012 21:36, schrieb Rick Johnson: > It is possible. Try Tkinter for the "get-you-from-a-to-b" solution, > or, wxPython if you like fog lamps, heated seats, and navigation > systems. I prefer wx or Qt. The look and feel is one reason. But the fact that Tkinter is still the standard GUI toolkit tells a lot about the situation... > Buttons and feilds are just a few short lines of code. Look. You guys > don't need a visual GUI builder. What you need to do is stop being > lazy and spend a few hours studing the basics of Tkinter and wxPyhon > (or whatever else suits your needs). IMO, every single python > programmer who needs GUI interfaces should know the basics of AT LEAST > Tkinter without even looking at the docs. I mean, how difficult is: [snipped code examples] Sure, I know how to code GUIs. But the learning curve is too steep for new users wanting to implement simple GUIs. > With Tkinter you add a GUI element IN THE CODE and then you are > ALREADY in the code editor! What an amazing concept! No juggling > editors and windows. No need to mentally switch from one language to > another. Can you imagine how productive you could be? I thought about preparing some templates for typcial applications, but I abandonded this as I don't think that it would work out well. >> If you have not used VB before, you should just try it. You can create >> GUIs within a few minutes even if you haven't used it before. > > Allow me to qualify that very naive generalization: "ANYBODY and point > and click, very few can actually write code". Right. I won't comment on the quality of the most VB code. But there are many applications where the quality of the code is not the main objective. It just needs to work e.g. to set up the instrument and read back data. The know-how and value is not the GUI code, but in the instrument setup and data evaluation. > I say. If your GUI kit gives you the feeling that you are writing too > much boilerplate, well, then, it's time to wrap up some re-usable > functionality on your own. I have done this myself with Tkinter AND Wx. > ( although much more so with Tkinter being that is a poorly designed > GUI) Did the same for wx twelve years ago as I did not like e.g. the event handling. Most of the time I'm still using my own wrappers. Still, once or twice a year I'm writing some small applications where I would use a GUI builder if it was available instead of copying old code as template. >> I can teach anyone how to create a program for data >> acquisition, but I don't see how more than a few could create a GUI >> without an easy-to-use tool. > > Like Tkinter? Don't like Tkinter, even though the alternatives are not too Pythonic either. > Visual Basic sucks. I spend more time re-focusing my mental energy > than actually getting work done. There is no replacement for pure raw > code. You visualize GUI's in you mind, and fingers bring that vision > to life through properly written API's. > > Never invent a new problem for a solution that does not exist. Sure, VB language sucks, but still I do not see any other tool that would cover the RAD aspect of the VB 6 environment. I would love to see Python for this, even though this would have negative side effects (e.g. attracting stupid people like PHP seems to). Regards, Dietmar From gbin at gootz.net Sun Jun 10 16:27:47 2012 From: gbin at gootz.net (Guillaume BINET) Date: Sun, 10 Jun 2012 13:27:47 -0700 (PDT) Subject: err: A cool new chatbot written and extensible in python Message-ID: Hi all, We have released a cool extensible chatbot for your development teams chatrooms. At my current company we have a ton of fun with it so we have decided to spread the love and release it as an open source project. Of course it is written and extensible in Python. Feel free to give it a try. Any feedback is welcome ! Its homepage is http://gbin.github.com/err/ Some sample commands : http://github.com/gbin/err/wiki/Catalog If you want to see our easy it is to write your own extensions to integrate it with other tools of your company, have a look here : https://github.com/gbin/err/wiki/plugin-dev Feel free to contact us if you have cool plugins to submit ! Guillaume. From no.email at nospam.invalid Sun Jun 10 16:40:22 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 10 Jun 2012 13:40:22 -0700 Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> Message-ID: <7xfwa2vr2h.fsf@ruckus.brouhaha.com> Matej Cepl writes: > Well, I could at least passively read many languages (starting with > Pascal, C, and unsuccessful attempt to learn Prolog, so even > statically typed languages are not that mysterious to me), I wouldn't count Pascal or C as statically typed in any interesting way. C++ (template generics), ML, or Haskell would be more meaningful. Prolog is worth spending more time on, and it's on my own list. > so learning new ones is not that problem. And yes, to be completely > honest, functional languages are my weakest part (although I have used > Emacs for some time, I still haven't learned writing in any Lisp > properly). You might start with Abelson and Sussman's classic book: http://mitpress.mit.edu/sicp From mcepl at redhat.com Sun Jun 10 16:58:09 2012 From: mcepl at redhat.com (Matej Cepl) Date: Sun, 10 Jun 2012 22:58:09 +0200 Subject: which one do you prefer? python with C# or java? In-Reply-To: <7xfwa2vr2h.fsf@ruckus.brouhaha.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> <7xfwa2vr2h.fsf@ruckus.brouhaha.com> Message-ID: On 10/06/12 22:40, Paul Rubin wrote: > You might start with Abelson and Sussman's classic book: > http://mitpress.mit.edu/sicp I know that, and it lies on my badtable for some time already, but I just never got enough excited about the idea yet. Python is just much more fun. Mat?j From no.email at nospam.invalid Sun Jun 10 17:27:15 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 10 Jun 2012 14:27:15 -0700 Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> <7xfwa2vr2h.fsf@ruckus.brouhaha.com> Message-ID: <7x1ulmoo24.fsf@ruckus.brouhaha.com> Matej Cepl writes: > I know that, and it lies on my badtable for some time already, but I > just never got enough excited about the idea yet. Python is just much > more fun. Here is an exercise from the book that you might like to try in Python: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_idx_3894 It's not easy ;-) From rantingrickjohnson at gmail.com Sun Jun 10 17:41:58 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Jun 2012 14:41:58 -0700 (PDT) Subject: Passing ints to a function References: <4fd2913f$0$29973$c3e8da3$5496439d@news.astraweb.com> <0ab8a335-57d2-4845-a522-0e70df5d36f0@m3g2000vbl.googlegroups.com> Message-ID: On Jun 9, 3:29?am, Jussi Piitulainen wrote: > Here's something you could have thought of for yourself even when you > didn't remember that Python does have special built-in support for > applying a function to a list of arguments: > > def five(func, args): > ? ?a, b, c, d, e = args > ? ?return func(a, b, c, d, e) > > The point is that the function itself can be passed as an argument to > the auxiliary function that extracts the individual arguments from the > list. Good point. However the function "five" is much too narrowly defined and the name is atrocious! I like concise, self-documenting identifiers. py> L5 = [1, 2, 3, 4, 5] py> L4 = [1, 2, 3, 4] py> def f4(a,b,c,d): print a,b,c,d py> def f5(a,b,c,d,e): print a,b,c,d,e py> def apply_five(func, args): a, b, c, d, e = args return func(a, b, c, d, e) py> apply_five(f5, L5) 1 2 3 4 5 py> apply_five(f5, L4) ValueError: need more than 4 values to unpack # # Try this instead: # py> def apply_arglst(func, arglst): return func(*arglst) py> apply_arglst(f4,L4) 1 2 3 4 py> apply_arglst(f5,L5) 1 2 3 4 5 ...of course you could create a general purpose apply function; like the one Python does not possess any longer ;-) From rosuav at gmail.com Sun Jun 10 19:15:49 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jun 2012 09:15:49 +1000 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= In-Reply-To: <4FD4F75D.40602@schwertberger.de> References: <4FD4F75D.40602@schwertberger.de> Message-ID: On Mon, Jun 11, 2012 at 5:37 AM, Dietmar Schwertberger wrote: > Chris Angelico wrote (in two posts): > >> There was a time when that was a highly advertisable feature - "build >> XYZ applications without writing a single line of code!". I've seen it >> in database front-end builders as well as GUI tools, same thing. But >> those sorts of tools tend not to be what experts want to use. You end >> up having to un-learn the "easy way" before you learn the "hard way" >> that lets you do everything. > This time is not over. > Especially when you look at data acquisition and control applications > where tools like Labview are widely used. > Personally, I would not want to use such tools as I find it quite > complicated to implement any logic with a graphical editor. > But when you want to sell an alternative to such tools, then you > should not offer a tool which makes it almost impossible for a > typical engineer to create a simple GUI. > > [chomp lots of other examples - go read 'em in the original post :) ] Either these people know how to write code, or they don't. If they do, then building a simple GUI shouldn't be beyond them; if they don't know that much code, then anything more than trivial _will_ be beyond them. Here's the window building code from something I just knocked together, with all comments stripped out: object mainwindow=GTK2.Window(GTK2.WindowToplevel); mainwindow->set_title("Timing")->set_default_size(400,300)->signal_connect("destroy",window_destroy); GTK2.HbuttonBox btns=GTK2.HbuttonBox()->set_layout(GTK2.BUTTONBOX_SPREAD); foreach (labels,string lbl) btns->add(buttons[lbl]=button(lbl,mode_change)); mainwindow->add(GTK2.Vbox(0,0) ->add(GTK2.TextView(buffer=GTK2.TextBuffer())->set_size_request(0,0)) ->pack_start(btns,0,0,0))->show_all(); If you're a complete non-programmer, then of course that's an opaque block of text. But to a programmer, it ought to be fairly readable - it says what it does. I'm confident that anyone who's built a GUI should be able to figure out what that's going to create, even if you've never used GTK before. (And yes, it's not Python. Sorry. I don't have a Python example handy.) Modern UI toolkits are generally not that difficult to use. Add just a few convenience functions (you'll see a call to a "button" function in the above code - it creates a GTK2.Button, sets it up, and returns it), and make a nice, well-commented configuration file that just happens to be executed as Python, and you've made it pretty possible for a non-programmer to knock together a GUI. They'll have learned to write code without, perhaps, even realizing it. ChrisA From asa at vorsicht-bissig.de Sun Jun 10 19:39:49 2012 From: asa at vorsicht-bissig.de (asa at vorsicht-bissig.de) Date: Mon, 11 Jun 2012 01:39:49 +0200 Subject: Strange Problem with pythonw.exe In-Reply-To: References: <20120609142322.242710@gmx.net> Message-ID: <20120610233949.318660@gmx.net> > > Hello subscribers, > > > > I've recently encountered a strange problem with Python for Windows. > > I'm using Windows 7 Pro 64 Bit and Python 3.2.3 64 Bit (also tried 32 > > bit). The Problem is, that pythonw.exe does not work at all! > > Therefore no IDLE for me... But python.exe runs just fine. I ran > > Process Monitor, which showed some activity for pythonw.exe, but no > > window is coming up. > > It is not quite clear what you did here, but if you just run > pythonw.exe, you should not see anything, as the 'w' stands for > 'Windows', 'windowless', or 'with user interaction through a gui brought > up by the python program being run'. It make it hard to debug if no gui > is being brought up. > > > The problem isn't restricted to my main python > > installation. I have also tried running portable python and active > > state python. No pythonw.exe of them is working. Reinstallation > > didn't change anything. Windows firewall was deactivated, no > > difference. No firewall-software or any possibilities of blocking > > pythonw.exe. I couldn't find the problem online. My problem was > > triggered by using PyQt. I've loaded an .ui, which did NOT show up. I > > have Ne ver seen IDLE since that "crash". Advice anyone? > > I take it that IDLE *did* work before using PyQT. If this is correct (I > must admit, I hope so), I would ask the author of PyQT whether it or QT > does anything to the system that could persist across installs. The most > likely change to me would be in the registry. So if it were my machine, > I would fire up regedit, back up the registry, search it for 'pythonw', > look at the results, and perhaps delete all pythonw entries. > Then reinstall the core component. You might also try 3.3.0a4, which had > additional bug fixes, or go back to something like 3.2.0. > > -- > Terry Jan Reedy > Thank you for your help. I found the problem at some other place. The registry tweaks didn't solve it. But I found the hint to look up my .idlerc folder. So the problem was entirely IDLE related (yes, it worked before). But it wasnt PyQt'S problem, but the mapping of some keyboard command I made. I used the '?' key (german keyboard), which kept me from using IDLE for 4 days now... Deleting the %username%/.idlerc folder got the job done finally! Arthur J From kwa at kuwata-lab.com Sun Jun 10 20:30:32 2012 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Mon, 11 Jun 2012 09:30:32 +0900 Subject: [Q] How to specify options for 'setup.py install' by environment variable? In-Reply-To: References: Message-ID: On Sun, Jun 10, 2012 at 3:51 PM, Ned Deily wrote: >> >> Thank you Ned, >> but I can't find environment variable name on that page which is >> equivarent to '--install-scripts' or other options. > > Sorry, I wasn't clear. ?Using the Distutils config files would be > instead of setting environment variables. ?For example, you could do > something like this: > > $ cat >$HOME/.pydistutils.cfg < [install] > prefix = local > install-scripts = local/bin > EOF > > That will apply globally whenever you run a Distutils script, unless it > is overridden by a $PWD/setup.cfg file with an [install] section. Thank you Ned, I'm clear. You mean that there is no environment variable equivarent to options, therefore I should create configuration file of distutils. I'll try it. Thank you. -- regards, makoto kuwata From tjreedy at udel.edu Sun Jun 10 21:30:24 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Jun 2012 21:30:24 -0400 Subject: Strange Problem with pythonw.exe In-Reply-To: <20120610233949.318660@gmx.net> References: <20120609142322.242710@gmx.net> <20120610233949.318660@gmx.net> Message-ID: On 6/10/2012 7:39 PM, asa at vorsicht-bissig.de wrote: > Thank you for your help. I found the problem at some other place. The > registry tweaks didn't solve it. But I found the hint to look up my > .idlerc folder. So the problem was entirely IDLE related (yes, it > worked before). But it wasnt PyQt'S problem, but the mapping of some > keyboard command I made. I used the '?' key (german keyboard), which > kept me from using IDLE for 4 days now... Deleting the > %username%/.idlerc folder got the job done finally! I believe there is a patch, either on the tracker or applied since 3.2.3, to catch .idlerc problems and report to the user rather than quit. -- Terry Jan Reedy From rustompmody at gmail.com Mon Jun 11 00:05:25 2012 From: rustompmody at gmail.com (rusi) Date: Sun, 10 Jun 2012 21:05:25 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> <0efa2cbd-c0a3-4dcb-beae-2cdf9063999a@l10g2000pbi.googlegroups.com> Message-ID: On Jun 10, 4:52?pm, Dietmar Schwertberger wrote: > Am 10.06.2012 08:16, schrieb rusi:> This is worth a read in this context:http://osteele.com/archives/2004/11/ides > > > I've read the article. It presents some nice ideas, but probably the > author has not used Python before. > Otherwise he would have noticed that the overall productivity does not > only depend on language and IDE/editor, but on the complete environment > which in the case of Python includes the ability to use the interpreter > interactively. For many tasks that's a major productivity boost. > But that's a point that many people don't see because their current > language like C# or Java does not have an interpreter and when they > just look at the syntax, the find "there's not enough improvement to > switch". Full agreement here > > Also, I'm not sure whether the author counts the libraries as language > or tool feature. In my opinion the environment and the libraries should > be listed on their own in such an article. Libraries are developed > after the language, but usually they are ahead of the other tools/IDEs. That was my main point and the reason for referring to that article. If I may rephrase your points in OSteele's terminology: If python is really a "language maven's" language then it does not do very well: - its not as object-oriented as Ruby (or other arcana like Eiffel) - its not as functional as Haskell - its not as integrable as Lua - its not as close-to-bare-metal as C - etc Then why is it up-there among our most popular languages? Because of the 'batteries included.' And not having a good gui-builder is a battery (cell?) that is lacking. From rustompmody at gmail.com Mon Jun 11 00:20:34 2012 From: rustompmody at gmail.com (rusi) Date: Sun, 10 Jun 2012 21:20:34 -0700 (PDT) Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> Message-ID: On Jun 10, 6:40?pm, Matej Cepl wrote: > On 10/06/12 00:44, Yesterday Paid wrote: > > > I'm planning to learn one more language with my python. > > Just my personal experience, but after passively learning many many > languages, I came to the conclusion that I (and I suppose many others) > am able to learn only one platform well. The point is that you are never > interested in learning *a language*, everybody who has at least some > touch with programming can learn most languages in one session in the > afternoon. But nobody is interested in you knowing a language, you need > to know the platform with all libraries, standards, style, and culture. > And *that* demands you focus on one language completely. Hi Mat?j! If this question is politically incorrect please forgive me. Do you speak only one (natural) language -- English? And if this set is plural is your power of expression identical in each language? Speaking for myself I can think of examples in Hindi, Marathi, Sanskrit and Tamil that when translated into English are so tame as to almost completely miss the point... From broadliyn at gmail.com Mon Jun 11 00:46:50 2012 From: broadliyn at gmail.com (Broad Liyn) Date: Sun, 10 Jun 2012 21:46:50 -0700 (PDT) Subject: which one do you prefer? python with C# or java? In-Reply-To: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> Message-ID: ? 2012?6?10????UTC+8??6?44?44??Yesterday Paid??? > I'm planning to learn one more language with my python. > Someone recommended to do Lisp or Clojure, but I don't think it's a > good idea(do you?) > So, I consider C# with ironpython or Java with Jython. > It's a hard choice...I like Visual studio(because my first lang is VB6 > so I'm familiar with that) > but maybe java would be more useful out of windows. > > what do you think? of course java is the best option in my opinion.There is no need to provide many evidences that java is better than c# because its advantages are really obvious.But java IDEs are not as convenient as visual studio. Anyway,it's on your choice.No matter what you option is,keeping going on it will make your skill more and more mature.Programming languages are just tools,programmer themselves are the key. From corey at octayn.net Mon Jun 11 00:54:07 2012 From: corey at octayn.net (Corey Richardson) Date: Mon, 11 Jun 2012 00:54:07 -0400 Subject: which one do you prefer? python with C# or java? In-Reply-To: References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> Message-ID: <20120611005407.51cdc267@Ulysses.myhome.westell.com> On Sun, 10 Jun 2012 21:46:50 -0700 (PDT) Broad Liyn wrote: > of course java is the best option in my opinion.There is no need to > provide many evidences that java is better than c# because its > advantages are really obvious. > Not as obvious as you'd imagine... I can't think of many. -- Corey Richardson From maha.jabeen92 at gmail.com Mon Jun 11 01:24:17 2012 From: maha.jabeen92 at gmail.com (Maha Jabeen) Date: Sun, 10 Jun 2012 22:24:17 -0700 (PDT) Subject: School Girls Mobile Number Message-ID: <71265632-739b-492a-88fb-b3bbf76005d8@z19g2000vbe.googlegroups.com> http://www.schoolgirlsnumber.com/ http://www.schoolgirlsnumber.com/ http://www.schoolgirlsnumber.com/ From celephicus at gmail.com Mon Jun 11 03:51:11 2012 From: celephicus at gmail.com (Tom Harris) Date: Mon, 11 Jun 2012 17:51:11 +1000 Subject: Decorator Pattern with Iterator Message-ID: Greetings, I have a class that implements the iterator protocol, and tokenises a string into a series of tokens. As well as the token, it keeps track of some information such as line number, source file, etc. for tokens in Tokeniser(): do_stuff(token) What I want is to be able to wrap the tokeniser to add functionality to the base parser without subclassing, e.g. for tokens in processor(Tokeniser()): do_stuff(token) Sort of Decorator pattern, so that I can chain more processors, but I cannot think how to implement it. Any clues for me? Thanks TomH -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Mon Jun 11 03:56:44 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 11 Jun 2012 09:56:44 +0200 Subject: Why does this leak memory? In-Reply-To: References: Message-ID: Am 08.06.2012 18:02, schrieb Steve: > Well, I guess I was confused by the terminology. I thought there were > leaked objects _after_ a garbage collection had been run (as it said > "collecting generation 2"). Also, "unreachable" actually appears to mean > "unreferenced". You live n learn... Actually I understand that differently. If you have circular references between two objects they are both referenced. If neither is referenced (directly or indirectly) by the current context, they are unreachable and can be garbage-collected. Being unreferenced implies that it is unreachable, but not vice-versa. Uli From dihedral88888 at googlemail.com Mon Jun 11 06:11:51 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 11 Jun 2012 03:11:51 -0700 (PDT) Subject: which one do you prefer? python with C# or java? In-Reply-To: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> Message-ID: <2c3cb961-2684-40ce-af50-979c8ab17067@googlegroups.com> Yesterday Paid? 2012?6?10????UTC+8??6?44?44???? > I'm planning to learn one more language with my python. > Someone recommended to do Lisp or Clojure, but I don't think it's a > good idea(do you?) > So, I consider C# with ironpython or Java with Jython. > It's a hard choice...I like Visual studio(because my first lang is VB6 > so I'm familiar with that) > but maybe java would be more useful out of windows. > > what do you think? If the goal is to write programs to be cross-platform, then I suggest some utilities like p2c (pascal to c), and f2c (fortran to c), and etc. to be available. Also source programs which are structured well with unit tests do help a lot in translations to other computer languages. From feliphil at gmx.net Mon Jun 11 07:55:51 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Mon, 11 Jun 2012 13:55:51 +0200 Subject: Pythonic cross-platform GUI desingers =?ISO-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> Message-ID: <20120611135551.ca7b259e.feliphil@gmx.net> > > What "GUI designer" would come the closest to the way that Cocoa's > > Interface Builder works? I.e. is there any one (cross-platform) that > > allows to actually "connect" the GUI created directly to the code > > and make it available "live" in an IDE? > > > > This whole cycle of "design GUI"->"generate code"->add own code to > > generated code"->"run application with GUI" has always seemed very > > un-pythonic to me. A dynamic, interpreted language should allow to > > work in a more "lively", "direct" way to build a GUI. > > I'm curious about your point but I don't really understand it. Could > you try again without using any scare-quoted words? myidea.explanation.retry() Python has this insanely great thing that e.g. Delphi, Java, C#, Visual Basic, etc. lack and that's called an interactive commandline interpreter, which allows you to build GUIs while exploring/trying out the API of a GUI framework step by step. You simply type the code for the GUI at the python prompt and your GUI comes directly to life. Here's an example by someone else: http://pysnippet.blogspot.de/2010/11/getting-interactive-with-pyqt.html Now "just" (sorry for those quotes again) imagine a GUI builder that generates _and_ _runs_ the code (pyqt, wxpython, pygtk, whatever) for the GUI you edit _while_ you do so. And now imagine that this GUI builder would be integrated with the IDE you use (I use one), so that the GUI code is run in the same interpreter instance as the other code of your application. So that you can directly interact with your application through the GUI you build while you do so. The advantage of using a GUI builder over typing the code into the interpreter window would be that users who rarely implement a GUI(*) would not need to re-dig into the details of the API every time. This is especially tedious since those APIs are essentially C++ APIs wrapped in Python and thus they are honestly simply ?$%&@# to use for a certain type of Python user(*). And the lack of Python-specific documentation, tutorials etc. doesn't really help. Did I mention yet that just having to read C++ example code in documentation makes me spill my last meal over keyboard, screen etc.? Of course there's PyGUI, but that's unfortunately far from being as complete as PyQt or wxPython and unless someone creates something like an equivalent of Apache Software Foundation for Python, declares PyGUI as the canonical Python GUI framework and funds the work needed to complete it... And then you still need a GUI builder for it. *sigh* > Maybe given an example of creating a small text editor application > with a GUI builder/ IDE in this Pythonic way you are hoping for. I'm not into text editors as example applications since I don't develop text editors, I rarely even use one. And besides, I don't think any typical user(*) of such a GUI builder would ever implement a text editor in his whole life. Personally, my typical use of such a GUI builder would be for database applications. Which make up, according to my experience, for at least 90% of all custom-built applications in companies. Today, these applications have to be made by external, paid developers who have typically no clue of the application domain in question. Consequently, the applications, no matter how many pages of detailed specifications you as the domain expert write, never do what you wanted them to do. Although just writing the specification takes more time than it would take to implement it myself if only the (GUI) tools and (GUI) frameworks(**) for Python would be at the level required to make them useful for such "developers" as me(*). And did I mention that the cost of external developers (plus the overhead cost for interaction with them) makes them prohibitive anyway? And did I mention that the time required such external development (plus the overhead time for interaction with the external developers) takes doesn't help either? * Such as "casual" Python scripting dilettants who are not full-time software developers but domain experts who just use Python to help get their main work done. ** In my case of database applications, something like this: http://www.nakedobjects.org/book/ http://www.nakedobjects.org/downloads/Pawson%20thesis.pdf Sincerely, Wolfgang From feliphil at gmx.net Mon Jun 11 08:01:16 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Mon, 11 Jun 2012 14:01:16 +0200 Subject: Pythonic cross-platform GUI desingers =?ISO-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: <20120608142721.3ab95cb7.feliphil@gmx.net> Message-ID: <20120611140116.001241a2.feliphil@gmx.net> > > What "GUI designer" would come the closest to the way that Cocoa's > > Interface Builder works? I.e. is there any one (cross-platform) that > > allows to actually "connect" the GUI created directly to the code > > and make it available "live" in an IDE? > > If you're developing on the Mac, PyObjC allows you to use Interface > Builder for developing Python apps. I know that. And no, I haven't used Interface Builder yet myself, just because I would need those GUIs also to run elsewhere than on my private Mac. > However, there are those of us who are deeply uncomfortable with IB > and related tools, such as RealBasic and LiveCode/Runtime Revolution. I haven't used any of these either, just because I don't like those languages. Their syntax is ugly, static type declarations are imho perfectly redundant for interpreted languages and besides they don't offer me an interactive interpreter, which is an absolute must-have for my day-to-day use of Python - "office automation", ad-hoc "information logistics" etc. (errr, sorry for those quotation marks again... ;-). > These tools make code organization very hard by reducing the amount > of code written to the point of the UI working by "magic," Any modern GUI framework has quite a lot of "magic" going on "behind the curtains" without that the user needs to know or understand how it works. And this is the way it _should_ be. As long as it is well documented how to use that "magic". The current GUI frameworks which are available for Python require way too much "glue code" that needs to be written by hand, imho simply because they are primitive wrappers around frameworks for C++ developers who are used to such bulkloads of slave labour. Python as a language is way ahead of C++, Java, C# etc. in terms of functionality that you can implement per coding effort required , but it simply lacks GUI frameworks and corresponding development tools that are equally efficient. > and/or by breaking up your code into little snippets that you can > only view by clicking on the widget in the UI tool. I remember reading about RAD IDEs/frameworks out there that managed to integrate/seperate their generated code with/from user-written code quite well. And which could even use external revision control systems etc.. Back in the good old days of software diversity, before MS/Java took over the whole world... > A related issue is that using a tool such as this makes you heavily > dependent on that particular tool, and subject to its developers' > priorities, release schedule, and bugs. This is true with _any_ language, library, framework or software. Heck, it's even true with hardware! If this was such a show-stopper, we would still write computer programs like this: 0100011100101010101.... Well, certainly not me, in that case. > The pace of Xcode development--with Apple making frequent changes to > project formats in a backwards-incompatible way--is an example of > this. Wxwidgets/python has a reputation for frequent incompatible API changes, too... And Apple's "product politics", oh, well, errr, uhm, don't get me into that... *sigh*. If only all those third-party applications for MacOS X were available on Linux, I would happily forget about Apple's very existence. > One reason I prefer to code UI's by hand is because a) in Tkinter > it's very easy to do, Tkinter is imho honestly the very best "argument" if you want to make potential new users turn their backs away from Python for good. Just show them one GUI implemented with it and, hey, wait, where are you running to... > I think these issues are a reason that the slick "drag-and-drop" UI > builders tend to be developed by commercial software shops to support > their language and/or IDE, but find little traction among open-source > developers and languages. The point is that loads of potential "developers"(*) simply don't ever get to use Python due to the very lack of such tools (and corresponding frameworks). * Domain experts in fact who would need to implement loads of software to help them get their work done but can't. And since there's no budget for external developers, nothing get's ever done about this. Sincerely, Wolfgang From kw at codebykevin.com Mon Jun 11 08:47:05 2012 From: kw at codebykevin.com (Kevin Walzer) Date: Mon, 11 Jun 2012 08:47:05 -0400 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= In-Reply-To: <20120611140116.001241a2.feliphil@gmx.net> References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: On 6/11/12 8:01 AM, Wolfgang Keller wrote: > Tkinter is imho honestly the very best "argument" if you want to make > potential new users turn their backs away from Python for good. Just > show them one GUI implemented with it and, hey, wait, where are you > running to... Yes, Tkinter GUI's are very ugly. http://www.codebykevin.com/phynchronicity-running.png http://www.codebykevin.com/quickwho-main.png -- Kevin Walzer Code by Kevin http://www.codebykevin.com From breamoreboy at yahoo.co.uk Mon Jun 11 09:31:08 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 11 Jun 2012 14:31:08 +0100 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: On 11/06/2012 13:47, Kevin Walzer wrote: > Yes, Tkinter GUI's are very ugly. > > http://www.codebykevin.com/phynchronicity-running.png > > http://www.codebykevin.com/quickwho-main.png > At last we're getting to the crux of the matter. Provided that the GUI is pretty who cares about picking appropriate algorithms for the code, or a sensible database design or whatever. And heaven forbid that anyone suggest using a command line even if this was the better solution for the problem that the user wants solved. -- Cheers. Mark Lawrence. From oscar.j.benjamin at gmail.com Mon Jun 11 09:48:24 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 11 Jun 2012 14:48:24 +0100 Subject: Decorator Pattern with Iterator In-Reply-To: References: Message-ID: On 11 June 2012 08:51, Tom Harris wrote: > Greetings, > > I have a class that implements the iterator protocol, and tokenises a > string into a series of tokens. As well as the token, it keeps track of > some information such as line number, source file, etc. > > for tokens in Tokeniser(): > do_stuff(token) > > What I want is to be able to wrap the tokeniser to add functionality to > the base parser without subclassing, e.g. > > for tokens in processor(Tokeniser()): > do_stuff(token) > > Sort of Decorator pattern, so that I can chain more processors, but I > cannot think how to implement it. Any clues for me? > Maybe I've misunderstood. Is this what you're looking for? def processer(tokens): for token in tokens: yield func(token) > Thanks > > TomH > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark at markroseman.com Mon Jun 11 10:09:23 2012 From: mark at markroseman.com (Mark Roseman) Date: Mon, 11 Jun 2012 08:09:23 -0600 Subject: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using) References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> Message-ID: Dietmar Schwertberger wrote: > But the fact that Tkinter is still the standard GUI toolkit tells a lot > about the situation... > ... > Sure, I know how to code GUIs. But the learning curve is too steep > for new users wanting to implement simple GUIs. As is obvious to everybody, the massive interest in web-based applications in recent years has certainly not helped advance the state of the art in desktop GUI's, nor enlarged the developer population actively engaged in maintaining and improving desktop GUI toolkits. Given that, we're likely "stuck" with more or less what we have now, so let's make the best of it. On the Tkinter front, I just want to reiterate two important points that are not nearly as well known as they should be. First, it is possible and in fact easy to do decent looking GUI's in Tkinter, with the caveat that you do in fact have to do things very slightly differently than you would have 15 years ago. Shocking, I know. Second, there does exist at least one fairly good source of documentation for new users wishing to do exactly this (according to many, many comments I have received), though that documentation is admittedly buried in a sea of out-of-date information that is still all too easy to find. Please see http://www.tkdocs.com and in particular the tutorial there. Mark From ksd.che at gmail.com Mon Jun 11 10:12:18 2012 From: ksd.che at gmail.com (chebrian) Date: Mon, 11 Jun 2012 07:12:18 -0700 (PDT) Subject: python with xl Message-ID: <9dd2dc9f-6d1f-4be9-bfaf-85aaaa0e4b5e@h9g2000yqi.googlegroups.com> Hi, How to append the list of data in individual column of XL file, every time from python script . From as at sci.fi Mon Jun 11 10:14:52 2012 From: as at sci.fi (Anssi Saari) Date: Mon, 11 Jun 2012 17:14:52 +0300 Subject: Pythonic cross-platform GUI desingers =?iso-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: <20120608142721.3ab95cb7.feliphil@gmx.net> Message-ID: Wolfgang Keller writes: > This whole cycle of "design GUI"->"generate code"->add own code to > generated code"->"run application with GUI" has always seemed very > un-pythonic to me. A dynamic, interpreted language should allow to work > in a more "lively", "direct" way to build a GUI. What about Qt Quick? I have used it very little, but it does allow dynamic modification of the GUI elements so that the application changes on the fly. I don't know how pythonic it is, since the GUI is described in QML, which combines CSS and javascript. From kliateni at gmail.com Mon Jun 11 10:35:17 2012 From: kliateni at gmail.com (Karim) Date: Mon, 11 Jun 2012 16:35:17 +0200 Subject: python with xl In-Reply-To: <9dd2dc9f-6d1f-4be9-bfaf-85aaaa0e4b5e@h9g2000yqi.googlegroups.com> References: <9dd2dc9f-6d1f-4be9-bfaf-85aaaa0e4b5e@h9g2000yqi.googlegroups.com> Message-ID: <4FD60225.3050403@gmail.com> Le 11/06/2012 16:12, chebrian a ?crit : > Hi, > > How to append the list of data in individual column of XL file, every > time from python script . In standard lib => module csv (ascii comma separated values) In non standard => binary xl => module xlrd for reading and module xlwt for writing (http://www.python-excel.org/) Cheers Karim From ian.g.kelly at gmail.com Mon Jun 11 11:57:00 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jun 2012 09:57:00 -0600 Subject: Decorator Pattern with Iterator In-Reply-To: References: Message-ID: On Mon, Jun 11, 2012 at 1:51 AM, Tom Harris wrote: > Greetings, > > I have a class that implements the iterator protocol, and tokenises a string > into a series of tokens. As well as the token, it keeps track of some > information such as line number, source file, etc. So each processor needs to be able to access that information? A decorator pattern for the processors to propagate that information down might look like this: class TokenProcessor(object): def __init__(self, processor): self._processor = processor def __call__(self, tokens): self._tokens = tokens return self._processor(tokens) @property def line_number(self): return self._tokens.line_number @property def source_file(self): return self._tokens.source_file @TokenProcessor def processor(tokens): for token in tokens: line_number = tokens.line_number do_stuff(token, line_number) yield token for token in processor_1(processor_2(tokeniser)): do_more_stuff(token) From tismer at stackless.com Mon Jun 11 13:01:25 2012 From: tismer at stackless.com (Christian Tismer) Date: Mon, 11 Jun 2012 19:01:25 +0200 Subject: Ann: New Stackless Website Message-ID: <4FD62465.7020604@stackless.com> I'm very happy to announce ================================== Stackless Python has a New Website ================================== Due to a great effort of the Nagare people: http://www.nagare.org/ and namely by the tremendous work of Alain Pourier, Stackless Python has now a new website! This is no longer Plone based, but a nicely configured Trac site. The switch to it has happened right now, the old website will be around for a few days under http://zope.stackless.com while the new site is accessible as http://www.stackless.com stackless.com now allows the source to be browsed (an hourly updated clone from hg.python.org) and includes a new issue tracker. Please let me know if you encounter any problems. cheers -- Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From news at blinne.net Mon Jun 11 13:23:57 2012 From: news at blinne.net (Alexander Blinne) Date: Mon, 11 Jun 2012 19:23:57 +0200 Subject: which one do you prefer? python with C# or java? In-Reply-To: <7x1ulmoo24.fsf@ruckus.brouhaha.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> <7xfwa2vr2h.fsf@ruckus.brouhaha.com> <7x1ulmoo24.fsf@ruckus.brouhaha.com> Message-ID: <4fd629ae$0$9515$9b4e6d93@newsspool1.arcor-online.net> On 10.06.2012 23:27, Paul Rubin wrote: > Here is an exercise from the book that you might like to try in Python: > > http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_idx_3894 > > It's not easy ;-) I liked this exercize. At first I wrote my own merger. > def merge(*iterables): > iterables = list(iterables) > current = [i.next() for i in iterables] > last = None > while True: > m = min(current) > while last == m: > p = current.index(m) > try: > current[p] = iterables[p].next() > except StopIteration: > del current[p] > del iterables[p] > if len(current) == 0: > raise StopIteration > m = min(current) > yield m > last = m But then I realised the vast library of python already contained (a faster) one (propably based upon ), which just needed to be enhanced a little bit to allow duplicate items to be removed: > import heapq > > def skipdups(m): > l = k = m.next() > yield k > while True: > while l == k: > k = m.next() > yield k > l = k > > def gen_s(): > s = [1] > m = skipdups(heapq.merge(*[(lambda j: (k*j for k in s))(n) for n in [2,3,5]])) > yield s[0] > while True: > k = m.next() > s.append(k) > yield k Now gen_s() generates the wanted sequence. Greetings From dncarac at gmail.com Mon Jun 11 14:37:32 2012 From: dncarac at gmail.com (Dennis Carachiola) Date: Mon, 11 Jun 2012 11:37:32 -0700 (PDT) Subject: Where to set default data - where received, or where used Message-ID: <6d632fae-b11f-447c-86d8-6ea32ab9d5ab@x6g2000pbh.googlegroups.com> I'm programming a project which will use a file to save parameters needed by the program. There are already two previous file formats, each of which can only be run by the version of the program which created them. I'm trying to avoid that problem in the future. To do that, I intend to use a dictionary, and default data. I believe that most new versions will add parameters. Each version of the program will have reasonable default values for each key in the dictionary handled by that version. If an older file is used, the data values in that file replace the keys that exist. The program then can operate on the values supplied by the older data file and the default values. Conversely, if a newer file is used, the data in the file replaces the keys in the dictionary. The program then simply doesn't access the newer data values. I'm hoping that this will make the file backward and forward compatible. Here's my question. I could do this by creating the dictionary with the default values, then read the file into it. Or I could use a 'get' with default values at the location in the program where those values are used. >From what I can see, creating the dictionary with default values puts everything in one place. While, supplying the default values at the place where they're used places the default values nearest the place where actually used. I can't decide on one way over the other. Can anyone give me some ideas if one is a preferred method, or other criteria I've overlooked? Thanks, Den From nick.cash at npcinternational.com Mon Jun 11 14:47:45 2012 From: nick.cash at npcinternational.com (Nick Cash) Date: Mon, 11 Jun 2012 18:47:45 +0000 Subject: Where to set default data - where received, or where used In-Reply-To: <6d632fae-b11f-447c-86d8-6ea32ab9d5ab@x6g2000pbh.googlegroups.com> References: <6d632fae-b11f-447c-86d8-6ea32ab9d5ab@x6g2000pbh.googlegroups.com> Message-ID: <846C3A8E860C4344B567D813B63AA51D0AE0B03F@BY2PRD0610MB353.namprd06.prod.outlook.com> This is really up to your programming style, but I'm of the opinion that defining all of the default values in one place keeps maintenance easier. Of course, if it's done differently elsewhere in your code base, I would aim for consistency instead. Thanks, Nick Cash -----Original Message----- From: python-list-bounces+nick.cash=npcinternational.com at python.org [mailto:python-list-bounces+nick.cash=npcinternational.com at python.org] On Behalf Of Dennis Carachiola Sent: Monday, June 11, 2012 13:38 To: python-list at python.org Subject: Where to set default data - where received, or where used I'm programming a project which will use a file to save parameters needed by the program. There are already two previous file formats, each of which can only be run by the version of the program which created them. I'm trying to avoid that problem in the future. To do that, I intend to use a dictionary, and default data. I believe that most new versions will add parameters. Each version of the program will have reasonable default values for each key in the dictionary handled by that version. If an older file is used, the data values in that file replace the keys that exist. The program then can operate on the values supplied by the older data file and the default values. Conversely, if a newer file is used, the data in the file replaces the keys in the dictionary. The program then simply doesn't access the newer data values. I'm hoping that this will make the file backward and forward compatible. Here's my question. I could do this by creating the dictionary with the default values, then read the file into it. Or I could use a 'get' with default values at the location in the program where those values are used. >From what I can see, creating the dictionary with default values puts everything in one place. While, supplying the default values at the place where they're used places the default values nearest the place where actually used. I can't decide on one way over the other. Can anyone give me some ideas if one is a preferred method, or other criteria I've overlooked? Thanks, Den -- http://mail.python.org/mailman/listinfo/python-list From rtomek at ceti.pl Mon Jun 11 14:54:13 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Mon, 11 Jun 2012 20:54:13 +0200 Subject: which one do you prefer? python with C# or java? In-Reply-To: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> Message-ID: On Sat, 9 Jun 2012, Yesterday Paid wrote: > I'm planning to learn one more language with my python. > Someone recommended to do Lisp or Clojure, but I don't think it's a > good idea(do you?) > So, I consider C# with ironpython or Java with Jython. > It's a hard choice...I like Visual studio(because my first lang is VB6 > so I'm familiar with that) > but maybe java would be more useful out of windows. > > what do you think? If you don't know C yet, I second recommendation to learn it. It is a very 70-tish and 80-tish language, but it is still very relevant if you want to call yourself a programmer (rather than a hobbyist, with all credits due to clever genius hobbyists out there). There are things I would rather do in C than in any other language (like, writing a Python interpreter or Linux kernel - wait, what you say they have been written already?). Also, it gives one a way to handtune the code quite a lot (at expense of time, but this is sometimes acceptable), to the point where next choice is assembly (and results not necessarily better)... Later on, since C and C++ share quite a bit, you can gradually include C++ elements into your code, thus writing in a kinda "bettered C" (compiled with C++ compiler), using constructs like "const" to make your programs more correct. And you will learn to not use "new" for variables, which is good thing. However, some C++ constructs include performance penalty, so it is good to not better it too much. Later on, you could choose from the list: - Common Lisp - "nice industrial standard" (depends on one's preferred definition of "nice", of course, as well as "industrial" and "standard") - Racket - Scheme on steroids, with IDE, JIT and crossplatform-ity (I can think of somebody writing Python/Racket to be used in this environment but it is hard to imagine someone doing the other direction, so go figure ;-) http://www.reddit.com/r/programming/comments/i1slm/amazing_tutorial_demonstrating_the_power_of/ http://hashcollision.org/brainfudge/ ) - Haskell or Ocaml - but I have a feeling Ocaml is developing at slower pace now, with many people choosing Haskell (I guess they sometimes curse themselves for this, because behaviour of code in Haskell is a bit hard to predict, sometimes). If you want to delve into Java world, well, I consider Java an unbearably ugly hog. When I was younger and fearless I programmed a bit in Java, but nowadays, the only way I myself could swallow this would be to use some other language on top of it (Scala, Clojure or Kaffe). C# as a - kind of - Java clone from MS, is not really so attractive to me. (Yes, both Java and C# have some merits in some situations, so do COBOL, VB and Fortran but I tend to avoid such situations and thus life gets much simpler). If you would like to bend your mind a little, Racket or Forth or Smalltalk (in a form of SqueakVM) could do the job. Every time I read about Smalltalk and think how Java took over, I mentally weep. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From rtomek at ceti.pl Mon Jun 11 15:21:20 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Mon, 11 Jun 2012 21:21:20 +0200 Subject: which one do you prefer? python with C# or java? In-Reply-To: References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> Message-ID: On Mon, 11 Jun 2012, Tomasz Rola wrote: > If you want to delve into Java world, well, I consider Java an unbearably > ugly hog. When I was younger and fearless I programmed a bit in Java, but > nowadays, the only way I myself could swallow this would be to use some > other language on top of it (Scala, Clojure or Kaffe). Uhuh, I meant Kawa, not Kaffe: http://en.wikipedia.org/wiki/Kawa_(Scheme_implementation) Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From robertb at trdlnk.com Mon Jun 11 16:26:38 2012 From: robertb at trdlnk.com (Robert Boehne) Date: Mon, 11 Jun 2012 15:26:38 -0500 Subject: Sybase module 0.40 released Message-ID: <4FD6547E.80809@trdlnk.com> WHAT IS IT: The Sybase module provides a Python interface to the Sybase relational database system. It supports all of the Python Database API, version 2.0 with extensions. The module is available here: http://downloads.sourceforge.net/python-sybase/python-sybase-0.40.tar.gz The module home page is here: http://python-sybase.sourceforge.net/ MAJOR CHANGES SINCE 0.39: Modify the DateTimeAsPython output conversion to return None when NULL is output support for Python without threads Ignore additional non-error codes from Sybase (1918 and 11932) Use outputmap in bulkcopy mode (thanks to patch by Cyrille Froehlich) Raise exception when opening a cursor on a closed connection Added unit tests Added new exception DeadLockError when Sybase is in a deadlock situation Add command properties CS_STICKY_BINDS and CS_HAVE_BINDS Added support for inputmap in bulkcopy reuse command and cursor when calling cursor.execute with same request Use ct_setparam to define ct_cursor parameters types instead of ct_param implicit conversion for CS_DATE_TYPE in CS_DATETIME_TYPE DataBuf Adding ct_cmd_props wrapper Increase DataBuf maxlength for params of a request when using CS_CHAR_TYPE params so that the buf can be reused BUGS CORRECTED SINCE 0.39: Corrected money type when using CS_MONEY4 (close bug 2615821) Corrected thread locking in ct_cmd_props (thanks to patch by Cyrille Froehlich) Corrected bug in type mapping in callproc (thanks to report by Skip Montanaro) Correct passing None in a DataBuf (thanks to patch by Bram Kuijvenhoven) The full ChangeLog is here: https://python-sybase.svn.sourceforge.net/svnroot/python-sybase/tags/r0_40/ChangeLog From d at davea.name Mon Jun 11 17:01:15 2012 From: d at davea.name (Dave Angel) Date: Mon, 11 Jun 2012 17:01:15 -0400 Subject: Where to set default data - where received, or where used In-Reply-To: <6d632fae-b11f-447c-86d8-6ea32ab9d5ab@x6g2000pbh.googlegroups.com> References: <6d632fae-b11f-447c-86d8-6ea32ab9d5ab@x6g2000pbh.googlegroups.com> Message-ID: <4FD65C9B.1080503@davea.name> On 06/11/2012 02:37 PM, Dennis Carachiola wrote: > I'm programming a project which will use a file to save parameters > needed by the program. There are already two previous file formats, > each of which can only be run by the version of the program which > created them. I'm trying to avoid that problem in the future. To do > that, I intend to use a dictionary, and default data. I believe that > most new versions will add parameters. > > Each version of the program will have reasonable default values for > each key in the dictionary handled by that version. If an older file > is used, the data values in that file replace the keys that exist. > The program then can operate on the values supplied by the older data > file and the default values. Conversely, if a newer file is used, the > data in the file replaces the keys in the dictionary. The program > then simply doesn't access the newer data values. I'm hoping that > this will make the file backward and forward compatible. > > Here's my question. I could do this by creating the dictionary with > the default values, then read the file into it. Or I could use a > 'get' with default values at the location in the program where those > values are used. > > >From what I can see, creating the dictionary with default values puts > everything in one place. While, supplying the default values at the > place where they're used places the default values nearest the place > where actually used. > > I can't decide on one way over the other. Can anyone give me some > ideas if one is a preferred method, or other criteria I've overlooked? > > Thanks, > > Den i would do it at the point of input. In fact, one option might be to save an updated version of the file, with the missing fields filled in. By doing it all in one place, you can test whether the code works with each external variant you intend to support, and gives you one place to fix whatever incompatibilities you find. You very well might discover you need a fancier algorithm than just having default values. For example, you might fill in missing values with a computation based on the values you do have. Further, if it gets really messy, you might end up with multiple input funcitons, keyed on the type (version) of the file. The point is, none of the other code should care one iota. I certainly hope the version information for those existing files is unambiguously stored. -- DaveA From mcepl at redhat.com Mon Jun 11 18:19:44 2012 From: mcepl at redhat.com (Matej Cepl) Date: Tue, 12 Jun 2012 00:19:44 +0200 Subject: which one do you prefer? python with C# or java? In-Reply-To: References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> Message-ID: On 11/06/12 06:20, rusi wrote: > Hi Mat?j! If this question is politically incorrect please forgive me. > Do you speak only one (natural) language -- English? > And if this set is plural is your power of expression identical in > each language? I have written about that later ... no, I am a native Czech, but I have passive Russian, and active English. But there is a difference ... I can read and enjoy beautiful texts in Russian or English (couple of months read Eugen Onegin in Russian and that's just a beauty! or C.S.Lewis ... oh my!) but I will never be able to write professionally in these languages. I can write (as evidenced by this message) somehow in English, but I cannot imagine that I would be ever professional art writer or (even worse) poet. I could imagine (if spent couple of thousands of days working on it) that I would be a Czech professional writer though. Mat?j From news at schwertberger.de Mon Jun 11 18:49:18 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Tue, 12 Jun 2012 00:49:18 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> <0efa2cbd-c0a3-4dcb-beae-2cdf9063999a@l10g2000pbi.googlegroups.com> Message-ID: Am 11.06.2012 06:05, schrieb rusi: > If python is really a "language maven's" language then it does not do > very well: > - its not as object-oriented as Ruby (or other arcana like Eiffel) > - its not as functional as Haskell > - its not as integrable as Lua > - its not as close-to-bare-metal as C > - etc Depends on the definition. Maybe, that Python is not a perfect language from an academic point of view, but it's a good choice for anyone looking for a pragmatic programming language. > Then why is it up-there among our most popular languages? Because of > the 'batteries included.' It's not only the batteries, but also the language itself. As someone wrote a long time ago "Python fits my brain". > And not having a good gui-builder is a battery (cell?) that is > lacking. It's a cell that would make it much easier to compete with other languages/environments. These environments need not necessarily be classical programming language, but could also be Labview, Matlab etc. And regarding popularity, I see very much potential. I have been working for two high-tech companies and I have never met anyone else using Python there. Focus is not classical databases, but data acquisition and processing. Many are still using VB, some are even using HT/HP-BASIC. Quite a lot moved to Labview, some are using Matlab or thinking about moving to it. The ones who actually see the point the advantages of a general purpose language moved to C#. (Nobody is using Java in this context as it obviously would not make any sense.) Anyway, I don't see how people could be persuaded to use a console-only environment, which - realistically - Python is at the moment for most people. From what I see, Python is recognized as a language for scripting and maybe for web servers, but not as a general purpose language to implement GUI software. (To make it clear: I have been using Python as a general purpose language for many years.) Regards, Dietmar From news at schwertberger.de Mon Jun 11 18:55:38 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Tue, 12 Jun 2012 00:55:38 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la___Interface_Builder_=28Re=3A_wh?= =?ISO-8859-1?Q?at_gui_designer_is_everyone_using=29?= In-Reply-To: <20120611140116.001241a2.feliphil@gmx.net> References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: Am 11.06.2012 14:01, schrieb Wolfgang Keller: > * Domain experts in fact who would need to implement loads of > software to help them get their work done but can't. And since there's > no budget for external developers, nothing get's ever done about this. Well, typically or at least very often sooner or later something gets done about this as someone finds out that all could be solved using MS Excel and some macros / VBA programming. I would prefer people to invest the same time into a Python based solution. But then we're back to the initial point: As long as there's no GUI builder for Python, most people will stick to Excel / VBA / VB. Regards, Dietmar From news at schwertberger.de Mon Jun 11 19:04:27 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Tue, 12 Jun 2012 01:04:27 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la___Interface_Builder_=28Re=3A_wh?= =?ISO-8859-1?Q?at_gui_designer_is_everyone_using=29?= In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> Message-ID: Am 11.06.2012 16:14, schrieb Anssi Saari: > Wolfgang Keller writes: > >> This whole cycle of "design GUI"->"generate code"->add own code to >> generated code"->"run application with GUI" has always seemed very >> un-pythonic to me. A dynamic, interpreted language should allow to work >> in a more "lively", "direct" way to build a GUI. > > What about Qt Quick? I have used it very little, but it does allow > dynamic modification of the GUI elements so that the application > changes on the fly. I don't know how pythonic it is, since the GUI is > described in QML, which combines CSS and javascript. I have been following the Qt development as I have been using PySide for some small projects on the Maemo platform. Qt Quick / QML seems to enable the implementation of so-called "modern" UIs. It's more for people who think that HTML5/CSS/Javascript is the future for UIs. Well, maybe they are right for certain advanced requirements. But for the beginner I don't see how it would help as it's even more difficult to link the GUI to the backend code and also I don't see how having to deal with multiple environments would make things easier. I think that for beginners some basic controls are fine enough and there's no need to care for fancy effects for the most non-consumer applications. For getting an impression about Qt Quick, have a look at http://qt.nokia.com/qtquick/ (The slide show 1,2,3,...) Regards, Dietmar From maillist at schwertberger.de Mon Jun 11 19:15:00 2012 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Tue, 12 Jun 2012 01:15:00 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> Message-ID: <4FD67BF4.9070603@schwertberger.de> Am 11.06.2012 16:09, schrieb Mark Roseman: > On the Tkinter front, I just want to reiterate two important points that > are not nearly as well known as they should be. > > First, it is possible and in fact easy to do decent looking GUI's in > Tkinter, with the caveat that you do in fact have to do things very > slightly differently than you would have 15 years ago. Shocking, I know. Yes, but when I have the choice between Tkinter, Qt and wx, I still would go for wx or Qt (or stick to wx which I chose 12 years ago). I don't see the point of chosing Tkinter over the other toolkits. > Second, there does exist at least one fairly good source of > documentation for new users wishing to do exactly this (according to > many, many comments I have received), though that documentation is > admittedly buried in a sea of out-of-date information that is still all > too easy to find. > > Please see http://www.tkdocs.com and in particular the tutorial there. The point of this thread is that Python is not attractive to casual users who want to implement some GUI programs. I don't see how that would change without an easy-to-use GUI builder, no matter how good the documentation is. Of course, it's possible to split up the documentation into many small building blocks which the user could copy & paste together. But then we have a poor-man's GUI builder. I doubt that it would attract new users. (For more straightforward tasks like hardware control / data acquisition I made good experiences with a Wiki-based approach of providing snippets. But *simple* GUIs are mainly visual and there should be a way to create them visually without consulting much documentation.) Regards, Dietmar From maillist at schwertberger.de Mon Jun 11 19:32:17 2012 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Tue, 12 Jun 2012 01:32:17 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= In-Reply-To: References: <4FD4F75D.40602@schwertberger.de> Message-ID: <4FD68001.7010003@schwertberger.de> Am 11.06.2012 01:15, schrieb Chris Angelico: > If you're a complete non-programmer, then of course that's an opaque > block of text. But to a programmer, it ought to be fairly readable - Well, I can read the code. But still I would not be able (or interested) to write C++/GTK code. With my rusty C++ knowledge and a simple GUI builder, I might be able to create the GUI, though. Whether I could then connect the events to actions is a different question and depends on the GUI builder. If it does not support this, then I would just not write the software. That's the starting point of this thread: for Python we could not identify such a GUI editor. > it says what it does. I'm confident that anyone who's built a GUI > should be able to figure out what that's going to create, even if > you've never used GTK before. (And yes, it's not Python. Sorry. I > don't have a Python example handy.) All the discussion about casual users being able to implement GUIs by manually coding it is somehow based on the assumption that suitable examples for any purpose are available. So to me the above example seems to be the proof that suitable examples are not available easily. > Modern UI toolkits are generally not that difficult to use. Add just a > few convenience functions (you'll see a call to a "button" function in > the above code - it creates a GTK2.Button, sets it up, and returns > it), and make a nice, well-commented configuration file that just > happens to be executed as Python, and you've made it pretty possible > for a non-programmer to knock together a GUI. They'll have learned to > write code without, perhaps, even realizing it. Right, they are not too difficult to use for full-time programmers or for people who want to invest a lot of time (as hobbyist). But there are many people who just need to get things done and who don't want to invest too many time on a simple GUI. No matter how cool it may seem to create simple GUIs manually or to write business letters using LaTeX: just try to persuade people to move from Word to LaTeX for business letters... Regards, Dietmar From rantingrickjohnson at gmail.com Mon Jun 11 21:21:26 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 11 Jun 2012 18:21:26 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> <0efa2cbd-c0a3-4dcb-beae-2cdf9063999a@l10g2000pbi.googlegroups.com> Message-ID: <2d53119d-bb4b-404f-abd9-e5bbf65be418@f7g2000yqh.googlegroups.com> On Jun 10, 11:05?pm, rusi wrote: > If python is really a "language maven's" language then it does not do > very well: > - its not as object-oriented as Ruby (or other arcana like Eiffel) if it were object-oreiented as Ruby, then why not use Ruby? > - its not as functional as Haskell if it were as functional as Haskell, then why not use Haskell? > - its not as integrable as Lua if it were as integrable as Lua, then why not use Lua? > - its not as close-to-bare-metal as C if it were as asinine as C, then why not use C? > - etc exactly! > Then why is it up-there among our most popular languages? Because of > the 'batteries included.' No. It's up there because it does not FORCE you to program in a single paradigm. Look. I love OOP. It works well for so many problems -- but not for ALL problems! I like the freedom i have when using Python. I don't get that feeling anywhere else. > And not having a good gui-builder is a battery (cell?) that is > lacking. Nonsense. I'm not saying we should NEVER have a visual gui builder, no, but i am saying that we don't need one to be a great language. From rantingrickjohnson at gmail.com Mon Jun 11 21:37:39 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 11 Jun 2012 18:37:39 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> Message-ID: On Jun 11, 9:09?am, Mark Roseman wrote: > Second, there does exist at least one fairly good source of > documentation for new users wishing to do exactly this (according to > many, many comments I have received), though that documentation is > admittedly buried in a sea of out-of-date information that is still all > too easy to find. Well you Mark you have really hit it this time. * Outdated tuts are contributing to the slow adoption of Python3000 * Outdated tuts are contributing the animosity towards Tkinter. * Poorly written tuts are doing even more damage. I have pointed this out before with very little feedback from our community members. So you know what i did... about two years ago i start a quest to rid the WWW of old and outdated tutorials. I send out email after email; begging; pleading, and yes even brown-nosing!... and you know how many reposes i got? Three! Yes three! And one of the three told me to eef-off. The other two chaps not only updated their tutorials, they even sent me a nice Thank you letter. Oh. And the one who told me to eff-off, he re-read my email and decided he took it out of context and then he updated his tut also. You see. If "I", or me rather, the despised and hated "rantingrick" can inspire three people to contribute positively to this community, well, just imagine what you or *gasps* GvR could do! Is any heavy weight willing to step forward and be heard? What say you? The silence is deafening. From nospam at nospam.com Tue Jun 12 05:39:50 2012 From: nospam at nospam.com (Gilles) Date: Tue, 12 Jun 2012 11:39:50 +0200 Subject: [newbie] Equivalent to PHP? Message-ID: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> Hello I'm an amateur programmer, and would like to know what the main options are to build web applications in Python instead of PHP. I notice that Python-based solutions are usually built as long-running processes with their own web server (or can run in the back with eg. Nginx and be reached through eg. FastCGI/WSGI ) while PHP is simply a language to write scripts and requires a web server (short running processes). Since web scripts are usually very short anyway (user sends query, server handles request, sends response, and closes the port) because the user is waiting and browsers usually give up after 30 seconds anyway... why did Python solutions go for long-running processes while PHP was built from the start as short-running processes? Thank you. From alain at dpt-info.u-strasbg.fr Tue Jun 12 06:12:55 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Tue, 12 Jun 2012 12:12:55 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> Message-ID: <87r4tk25zs.fsf@dpt-info.u-strasbg.fr> Gilles writes: > I notice that Python-based solutions are usually built as long-running > processes with their own web server (or can run in the back with eg. > Nginx and be reached through eg. FastCGI/WSGI ) while PHP is simply a > language to write scripts and requires a web server (short running > processes). It's an artefact of the server infrastructure, there is no rule here. Any solution used with one language could be used with the other. > Since web scripts are usually very short anyway (user sends query, > server handles request, sends response, and closes the port) because > the user is waiting and browsers usually give up after 30 seconds > anyway... why did Python solutions go for long-running processes while > PHP was built from the start as short-running processes? You misunderstand the problem here. It's not about the duration of the actions, it's about the latency it takes to read/parse/execute the script. HTTP is stateless anyway, so if the same "interpreter" handles several requests, what you save by keeping the interpreter alive is the load/parse phase. If you relaunch an interpreter for every HTTP request, you pay the same price again and again for something which is not even related to your scripts' execution. -- Alain. From rosuav at gmail.com Tue Jun 12 06:18:21 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jun 2012 20:18:21 +1000 Subject: [newbie] Equivalent to PHP? In-Reply-To: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> Message-ID: On Tue, Jun 12, 2012 at 7:39 PM, Gilles wrote: > Since web scripts are usually very short anyway (user sends query, > server handles request, sends response, and closes the port) because > the user is waiting and browsers usually give up after 30 seconds > anyway... why did Python solutions go for long-running processes while > PHP was built from the start as short-running processes? Think of it as Apache + PHP versus Python. Apache keeps running, it's only your PHP script that starts and stops. With a long-running process, you keep everything all in together, which IMHO is simpler and better. ChrisA From nospam at nospam.com Tue Jun 12 06:36:36 2012 From: nospam at nospam.com (Gilles) Date: Tue, 12 Jun 2012 12:36:36 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <87r4tk25zs.fsf@dpt-info.u-strasbg.fr> Message-ID: On Tue, 12 Jun 2012 12:12:55 +0200, Alain Ketterlin wrote: >You misunderstand the problem here. It's not about the duration of the >actions, it's about the latency it takes to read/parse/execute the >script. HTTP is stateless anyway, so if the same "interpreter" handles >several requests, what you save by keeping the interpreter alive is the >load/parse phase. If you relaunch an interpreter for every HTTP request, >you pay the same price again and again for something which is not even >related to your scripts' execution. Thanks for the input. But I read that PHP-based heavy-duty web servers compile the scripts once and keep them in a cache, so they don't have to be read/parsed/executed with each new query. In that case, what is the benefit of using a long-running process in Python? I enjoy writing scripts in Python much more than PHP, but with so many sites written in PHP, I need to know what major benefits there are in choosing Python (or Ruby, ie. not PHP). Apparently, very few people use Python ? la PHP, ie. Python code embedded in web pages? From orasnita at gmail.com Tue Jun 12 07:28:22 2012 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 12 Jun 2012 14:28:22 +0300 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> Message-ID: <113727260AC640D3AC8300078ADEFAE1@octavian> From: "Chris Angelico" Subject: Re: [newbie] Equivalent to PHP? > On Tue, Jun 12, 2012 at 7:39 PM, Gilles wrote: >> Since web scripts are usually very short anyway (user sends query, >> server handles request, sends response, and closes the port) because >> the user is waiting and browsers usually give up after 30 seconds >> anyway... why did Python solutions go for long-running processes while >> PHP was built from the start as short-running processes? Perl, Ruby, Python and PHP also can do the same thing. You can use a persistent program which is loaded/parsed/compiled once and kept into memory and it will just answer the requests, or you can create a program which is loaded/parsed/compiled on each request. The first way is much better for performance reasons but it consumes much more memory and it is more complicated, because the programs can have memory leaks (they will consume more and more memory after a long period), while the second way is more simple to do, but the performance is not great. Most PHP programs are done using the second way, because it is much simple to do and it is much simple to configure the environment for it, and most of the free web hosting sites that offer PHP support don't offer something better. And... most of the sites don't need a very good performance, because they usually don't have millions visitors per day. Also, most of the sites made in PHP use low level programs using only what the default PHP distribution installed on the server offers, so no web frameworks, or form managers, or templating systems or many other modules that can do a part of the work. The PHP distribution has compiled C programs which run pretty fast, while loading/parsing/compiling a lot of other modules made in Ruby/Perl/Python/PHP would decrease the performance, so a persistent environment is usually required in case those modules are used. And usually Python and Perl and Ruby programs use a lot of modules because for these languages there are a lot of modules available that can do a lot of things for free, while for PHP there are much fewer, and even if there are, (because there are templating systems and web frameworks for PHP also), they are much seldomly used, because those who choose to use a broken language like PHP, usually choose it not only for its main advantage regarding the easiness of deployment, but choose it because it is much more simple and easy to learn, and they usually don't like to learn a lot of other modules. Otherwise... if you want you can also create a web app using PHP and CodeIgniter web framework and run it with fastcgi... Octavian From darcy at druid.net Tue Jun 12 07:42:56 2012 From: darcy at druid.net (D'Arcy Cain) Date: Tue, 12 Jun 2012 07:42:56 -0400 Subject: [newbie] Equivalent to PHP? In-Reply-To: References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <87r4tk25zs.fsf@dpt-info.u-strasbg.fr> Message-ID: <4FD72B40.8050804@druid.net> On 12-06-12 06:36 AM, Gilles wrote: > I enjoy writing scripts in Python much more than PHP, but with so many > sites written in PHP, I need to know what major benefits there are in > choosing Python (or Ruby, ie. not PHP). I think that you just answered your own question in the first line of that paragraph. With computers running so fast and memory and disk being so cheap, the only decision left for most applications is what language do you prefer. Python wins because it is so nice to work with. It's clean and you don't have to deal with the daily security holes of PHP. > Apparently, very few people use Python ? la PHP, ie. Python code > embedded in web pages? I guess I am in the minority then. I do plan to turn one of my larger projects into a standalone web server some day but so far writing simple Python CGI scripts has served me fine. I even do some embedding by using server side scripting. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From rosuav at gmail.com Tue Jun 12 08:01:10 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jun 2012 22:01:10 +1000 Subject: [newbie] Equivalent to PHP? In-Reply-To: References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <87r4tk25zs.fsf@dpt-info.u-strasbg.fr> Message-ID: On Tue, Jun 12, 2012 at 8:36 PM, Gilles wrote: > Thanks for the input. > > But I read that PHP-based heavy-duty web servers compile the scripts > once and keep them in a cache, so they don't have to be > read/parsed/executed with each new query. > > In that case, what is the benefit of using a long-running process in > Python? Apache's mod_php partially evens out the difference, but not completely, and of course, it's perfectly possible to write a dispatch loop in PHP, as Octavian said. Python is a far better language than PHP, I would strongly recommend making use of it if you can. ChrisA From mcepl at redhat.com Tue Jun 12 10:48:27 2012 From: mcepl at redhat.com (Matej Cepl) Date: Tue, 12 Jun 2012 16:48:27 +0200 Subject: [newbie] Equivalent to PHP? In-Reply-To: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> Message-ID: On 12/06/12 11:39, Gilles wrote: > I notice that Python-based solutions are usually built as long-running > processes with their own web server (or can run in the back with eg. > Nginx and be reached through eg. FastCGI/WSGI ) while PHP is simply a > language to write scripts and requires a web server (short running > processes). I don't think it is a proper description of the situation (please, somebody correct my mistakes, I am not 100% sure about it myself). WSGI applications (which is basically all web applications in Python) could run in the hosted servers (using for example mod_wsgi for Apache), and I would expect that it is the situation with most production uses. From the programmer's point of view WSGI application (read http://en.wikipedia.org/wiki/Wsgi) is just one script which takes HTTP request on input and generates HTTP Response on output, so it is actually quite simple. And actually quite similar to what JSGI, PSGI, and Rake do (I am not sure who was first whether WSGI or Rake). > anyway... why did Python solutions go for long-running processes while > PHP was built from the start as short-running processes? It is all about caching ... I am not sure how it is done exactly, but I would expect for example mod_wsgi to cache parsed Python script in memory as well. Mat?j From juliosergio at gmail.com Tue Jun 12 13:53:31 2012 From: juliosergio at gmail.com (Julio Sergio) Date: Tue, 12 Jun 2012 17:53:31 +0000 (UTC) Subject: using identifiers before they are defined Message-ID: I'm puzzled with the following example, which is intended to be a part of a module, say "tst.py": a = something(5) def something(i): return i When I try: ->>> import tst The interpreter cries out: Traceback (most recent call last): File "", line 1, in File "tst.py", line 11, in a = something(5) NameError: name 'something' is not defined I know that changing the order of the definitions will work, however there are situations in which referring to an identifier before it is defined is necessary, e.g., in crossed recursion. So I modified my module: global something a = something(5) def something(i): return i And this was the answer I got from the interpreter: ->>> import tst Traceback (most recent call last): File "", line 1, in File "tst.py", line 12, in a = something(5) NameError: global name 'something' is not defined Do you have any comments? Thanks, --Sergio. From josehmartinezz at gmail.com Tue Jun 12 14:16:47 2012 From: josehmartinezz at gmail.com (Jose H. Martinez) Date: Tue, 12 Jun 2012 14:16:47 -0400 Subject: using identifiers before they are defined In-Reply-To: References: Message-ID: You should define the function first and then call it. def something(i): return i a = something(5) If you want a reference to the function somewhere else you can do this: global alias = something print alias(i) On Tue, Jun 12, 2012 at 1:53 PM, Julio Sergio wrote: > I'm puzzled with the following example, which is intended to be a part of a > module, say "tst.py": > > a = something(5) > > def something(i): > return i > > > > When I try: > > ->>> import tst > > The interpreter cries out: > > Traceback (most recent call last): > File "", line 1, in > File "tst.py", line 11, in > a = something(5) > NameError: name 'something' is not defined > > I know that changing the order of the definitions will work, however there > are > situations in which referring to an identifier before it is defined is > necessary, e.g., in crossed recursion. > > So I modified my module: > > global something > > a = something(5) > > > def something(i): > return i > > > And this was the answer I got from the interpreter: > > ->>> import tst > > Traceback (most recent call last): > File "", line 1, in > File "tst.py", line 12, in > a = something(5) > NameError: global name 'something' is not defined > > > Do you have any comments? > > Thanks, > > --Sergio. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From emile at fenx.com Tue Jun 12 14:17:16 2012 From: emile at fenx.com (Emile van Sebille) Date: Tue, 12 Jun 2012 11:17:16 -0700 Subject: using identifiers before they are defined In-Reply-To: References: Message-ID: On 6/12/2012 10:53 AM Julio Sergio said... > So I modified my module: > > global something > > a = something(5) > > > def something(i): > return i > > > And this was the answer I got from the interpreter: > > ->>> import tst > > Traceback (most recent call last): > File "", line 1, in > File "tst.py", line 12, in > a = something(5) > NameError: global name 'something' is not defined > > > Do you have any comments? python executes each line as it encounters it. a=something(5) as you have it attempts to bind the label 'a' to the result of something(5) which has not yet been defined. You seem to want it to compile everything first, then execute but it doesn't work that way. Emile From python at mrabarnett.plus.com Tue Jun 12 14:25:24 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 12 Jun 2012 19:25:24 +0100 Subject: using identifiers before they are defined In-Reply-To: References: Message-ID: <4FD78994.4090005@mrabarnett.plus.com> On 12/06/2012 18:53, Julio Sergio wrote: > I'm puzzled with the following example, which is intended to be a part of a > module, say "tst.py": > > a = something(5) > > def something(i): > return i > > > > When I try: > > ->>> import tst > > The interpreter cries out: > > Traceback (most recent call last): > File "", line 1, in > File "tst.py", line 11, in > a = something(5) > NameError: name 'something' is not defined > > I know that changing the order of the definitions will work, however there are > situations in which referring to an identifier before it is defined is > necessary, e.g., in crossed recursion. > > So I modified my module: > > global something > > a = something(5) > > > def something(i): > return i > > > And this was the answer I got from the interpreter: > > ->>> import tst > > Traceback (most recent call last): > File "", line 1, in > File "tst.py", line 12, in > a = something(5) > NameError: global name 'something' is not defined > > > Do you have any comments? > In Python, "def" is a statement, not a declaration. It binds the body of the function to the name when the "def" statement is run. A Python script is, basically, run from top to bottom, and both "def" and "class" are actually statements, not declarations. A function can refer to another function, even one that hasn't been defined yet, provided that it has been defined by the time it is called. For example, this: def first(): second() def second(): pass first() is OK because it defines function "first", then function "second", then calls "first". By the time "first" calls "second", "second" has been defined. From juliosergio at gmail.com Tue Jun 12 14:33:06 2012 From: juliosergio at gmail.com (Julio Sergio) Date: Tue, 12 Jun 2012 18:33:06 +0000 (UTC) Subject: using identifiers before they are defined References: Message-ID: Jose H. Martinez gmail.com> writes: > > > You should define the function first and then call it. > > > ?def something(i):? ? ?return i > > > a = something(5) > > > If you want a reference to the function somewhere else you can do this: > I know that. That was what I meant by "changing the order of the definitions will work" in my original message. And I insist in the issue, which is not trivial... In my message I mentioned "crossed recursion", and I delve into it here: Suppose I have to define two functions, aa, and, bb that are designed to call each other: def aa(): ... ... a call of bb() somewhere in the body of aa ... def bb(): ... ... a call of aa() somewhere in the body of bb ... Whatever the order of definition of aa and bb the problem remains, one of the two identifiers is not known ... Most of computer languages have mechanisms to deal with this issue. Is there any in Python or it is in disadvantage with respect to other languages like C++, Java, Perl, PHP, etc.? From driscoll at cs.wisc.edu Tue Jun 12 14:33:31 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Tue, 12 Jun 2012 13:33:31 -0500 Subject: using identifiers before they are defined In-Reply-To: References: Message-ID: <4FD78B7B.2030905@cs.wisc.edu> On 01/-10/-28163 01:59 PM, Julio Sergio wrote: > I know that changing the order of the definitions will work, however there are > situations in which referring to an identifier before it is defined is > necessary, e.g., in crossed recursion. Mutual recursion isn't a problem: the following strange expression of factorial works fine: def strange_helper(x): return factorial(x) def factorial(x): if x==0: return 1 else: return x * strange_helper(x-1) print factorial(5) The reason is names are never looked up when the parser sees them, but rather only when execution reaches them. So the fact that 'factorial' hasn't been defined yet when the parser is dealing with 'strange_helper' is fine, because when 'strange_helper' is actually *called*, 'factorial' has been defined. Here's another example to illustrate, in a different manner that doesn't use this "undefined" thing: def foo(): print "Inside the first version of foo" def call_foo(): foo() call_foo() def foo(): print "Inside the second version of foo" call_foo() This prints: Inside the first version of foo Inside the second version of foo Evan From malaclypse2 at gmail.com Tue Jun 12 14:36:41 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 12 Jun 2012 14:36:41 -0400 Subject: using identifiers before they are defined In-Reply-To: References: Message-ID: On Tue, Jun 12, 2012 at 2:33 PM, Julio Sergio wrote: > Suppose I have to define two functions, aa, and, bb that are designed to call > each other: > > ?def aa(): > ? ? ... > ? ? ... a call of bb() somewhere in the body of aa > ? ? ... > > ?def bb(): > ? ? ... > ? ? ... a call of aa() somewhere in the body of bb > ? ? ... > > > Whatever the order of definition of aa and bb the problem remains, one of the > two identifiers is not known ... This works just fine in python, exactly as you've written it. What's the actual problem you're having? -- Jerry From cmpython at gmail.com Tue Jun 12 14:48:32 2012 From: cmpython at gmail.com (CM) Date: Tue, 12 Jun 2012 11:48:32 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: <7f3cbf65-bb3e-4a9b-a5df-9fc40531748b@n16g2000vbn.googlegroups.com> On Jun 11, 6:55?pm, Dietmar Schwertberger wrote: > But then we're back to the initial point: As long as there's no GUI > builder for Python, most people will stick to Excel / VBA / VB. Then good thing there *are* GUI builder/IDEs for Python, one of which was good enough for me to take me from essentially zero modern programming experience to a sizable (> ~15k LOC) application. From ethan at stoneleaf.us Tue Jun 12 14:51:56 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 12 Jun 2012 11:51:56 -0700 Subject: using identifiers before they are defined In-Reply-To: References: Message-ID: <4FD78FCC.5070700@stoneleaf.us> Julio Sergio wrote: > Jose H. Martinez gmail.com> writes: > >> >> You should define the function first and then call it. >> >> >> def something(i): return i >> >> >> a = something(5) >> >> >> If you want a reference to the function somewhere else you can do this: >> > > I know that. That was what I meant by "changing the order of the definitions > will work" in my original message. > > And I insist in the issue, which is not trivial... In my message I mentioned > "crossed recursion", and I delve into it here: > > Suppose I have to define two functions, aa, and, bb that are designed to call > each other: > > def aa(): > ... > ... a call of bb() somewhere in the body of aa > ... > > def bb(): > ... > ... a call of aa() somewhere in the body of bb > ... > > > Whatever the order of definition of aa and bb the problem remains No. The reply from MRAB explains this. ~Ethan~ From josehmartinezz at gmail.com Tue Jun 12 15:02:51 2012 From: josehmartinezz at gmail.com (Jose H. Martinez) Date: Tue, 12 Jun 2012 15:02:51 -0400 Subject: using identifiers before they are defined In-Reply-To: <4FD78FCC.5070700@stoneleaf.us> References: <4FD78FCC.5070700@stoneleaf.us> Message-ID: Seems like what you need is from othermodule import bb def aa(): bb() On Tue, Jun 12, 2012 at 2:51 PM, Ethan Furman wrote: > Julio Sergio wrote: > >> Jose H. Martinez gmail.com> writes: >> >> >>> You should define the function first and then call it. >>> >>> >>> def something(i): return i >>> >>> >>> a = something(5) >>> >>> >>> If you want a reference to the function somewhere else you can do this: >>> >>> >> I know that. That was what I meant by "changing the order of the >> definitions will work" in my original message. >> >> And I insist in the issue, which is not trivial... In my message I >> mentioned "crossed recursion", and I delve into it here: >> >> Suppose I have to define two functions, aa, and, bb that are designed to >> call each other: >> >> def aa(): >> ... >> ... a call of bb() somewhere in the body of aa >> ... >> >> def bb(): >> ... >> ... a call of aa() somewhere in the body of bb >> ... >> >> >> Whatever the order of definition of aa and bb the problem remains >> > > No. The reply from MRAB explains this. > > ~Ethan~ > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From salmanmk at live.com Tue Jun 12 15:36:10 2012 From: salmanmk at live.com (Salman Malik) Date: Tue, 12 Jun 2012 14:36:10 -0500 Subject: Using pdb with greenlet? In-Reply-To: References: Message-ID: Hi, I am sort of a newbie to Python ( have just started to use pdb). My problem is that I am debugging an application that uses greenlets and when I encounter something in code that spawns the coroutines or wait for an event, I lose control over the application (I mean that after that point I can no longer do 'n' or 's' on the code). Can anyone of you tell me how to tame greenlet with pdb, so that I can see step-by-step as to what event does a coroutine sees and how does it respond to it. Any help would be highly appreciated. Thanks, Salman -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim at akwebsoft.com Tue Jun 12 15:41:04 2012 From: tim at akwebsoft.com (Tim Johnson) Date: Tue, 12 Jun 2012 11:41:04 -0800 Subject: which one do you prefer? python with C# or java? In-Reply-To: References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> Message-ID: <20120612194104.GI372@mail.akwebsoft.com> * Tomasz Rola [120611 11:18]: > On Sat, 9 Jun 2012, Yesterday Paid wrote: > > > I'm planning to learn one more language with my python. > > Someone recommended to do Lisp or Clojure, but I don't think it's a > > good idea(do you?) > > So, I consider C# with ironpython or Java with Jython. > > It's a hard choice...I like Visual studio(because my first lang is VB6 > > so I'm familiar with that) > > but maybe java would be more useful out of windows. > > > > what do you think? > > If you don't know C yet, I second recommendation to learn it. It is a very > 70-tish and 80-tish language, but it is still very relevant if you want to > call yourself a programmer (rather than a hobbyist, with all credits due > to clever genius hobbyists out there). There are things I would rather do > in C than in any other language (like, writing a Python interpreter or > Linux kernel - wait, what you say they have been written already?). Also, > it gives one a way to handtune the code quite a lot (at expense of time, > but this is sometimes acceptable), to the point where next choice is > assembly (and results not necessarily better)... > > Later on, since C and C++ share quite a bit, you can gradually include C++ > elements into your code, thus writing in a kinda "bettered C" (compiled > with C++ compiler), using constructs like "const" to make your programs > more correct. And you will learn to not use "new" for variables, which is > good thing. However, some C++ constructs include performance penalty, so > it is good to not better it too much. I concur, I worked in C and C++ for 12 years. I added C++ later in my programming life. I don't recommend C++ for single programmers. - that is to say - 1 coder for 1 codebase. One can do good enough OOP in ansi C believe it or not, I learned to. It is interesting to note that most of linux is written in C, rather than C++ and is not python as well? > - Common Lisp - "nice industrial standard" (depends on one's preferred > definition of "nice", of course, as well as "industrial" and "standard") I took a hard look at Common Lisp at one time. I got the impression that the "Common Lisp" is not to Lisp what Ansi C is to C. IOWS, there does remain incompatibilities between different Common Lisp implementations. Whereas Ansi C is pretty strict as code portability (or was so when I was working in it) -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com From juliosergio at gmail.com Tue Jun 12 16:25:57 2012 From: juliosergio at gmail.com (Julio Sergio) Date: Tue, 12 Jun 2012 20:25:57 +0000 (UTC) Subject: using identifiers before they are defined References: <4FD78FCC.5070700@stoneleaf.us> Message-ID: Ethan Furman stoneleaf.us> writes: > > > No. The reply from MRAB explains this. > > ~Ethan~ > Thanks, you're right! I was confusing statemens with declarations. From ethan at stoneleaf.us Tue Jun 12 16:46:08 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 12 Jun 2012 13:46:08 -0700 Subject: using identifiers before they are defined In-Reply-To: References: <4FD78FCC.5070700@stoneleaf.us> Message-ID: <4FD7AA90.8070803@stoneleaf.us> Julio Sergio wrote: > Ethan Furman stoneleaf.us> writes: > >> >> No. The reply from MRAB explains this. >> >> ~Ethan~ >> > > Thanks, you're right! > I was confusing statemens with declarations. Yeah, it took me a while to get that straight as well. ~Ethan~ From ramit.prasad at jpmorgan.com Tue Jun 12 16:57:42 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Tue, 12 Jun 2012 20:57:42 +0000 Subject: Create directories and modify files with Python In-Reply-To: References: <1276909.20.1335828291506.JavaMail.geo-discussion-forums@vbep19> <4f9f26d8$0$6848$e4fe514c@news2.news.xs4all.nl> <26387065.12.1335869517324.JavaMail.geo-discussion-forums@vbkv21> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D906D0@SCACMX008.exchad.jpmchase.net> > > Thanks for the directions. By the way, can you see my post in Google Groups? > I'm not able to, and I don't know why. > > > They may have copied the Gmail idea that you never need to see anything > anything you posted yourself. I can see all my posts in a Gmail thread/conversation but if there are no replies then I would have to look in All Mail. But for "normal" email conversations it does have my posts in there. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From daverz at gmail.com Tue Jun 12 17:02:43 2012 From: daverz at gmail.com (Dave Cook) Date: Tue, 12 Jun 2012 14:02:43 -0700 (PDT) Subject: multiprocessing: excepthook not getting called Message-ID: Why doesn't my excepthook get called in the child process? import sys import multiprocessing as mp def target(): name = mp.current_process().name def exceptHook(*args): print 'exceptHook:', name, args sys.excepthook = exceptHook raise ValueError if __name__=='__main__': p = mp.Process(target=target) p.start() p.join() # try it here in main target() Thanks, Dave Cook From rdsteph at mac.com Tue Jun 12 17:19:57 2012 From: rdsteph at mac.com (rdsteph at mac.com) Date: Tue, 12 Jun 2012 14:19:57 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: Message-ID: <19e8593c-26ea-49c7-af76-01f85fa42387@t2g2000pbl.googlegroups.com> On Jun 10, 12:37?pm, Dietmar Schwertberger wrote: > Personally, I prefer Python with console, wx or Qt for local > applications and Python/HTTP/HTML/Javascript for multi-user > database applications. > > Regards, > > Dietmar +1 I think this is the wave of the furture for deploying simple programs to many users. It is almost 100% cross platform (can be used on desktop, smartphone, tablet, windows, linux, mac etc) and is very easy to do, even for casual "non-programmers" who do a little programming (such as many engineers). I think efforts to make a better, and more definitive, "GUI builder" for Python should focus on makigng an easy to use "IDE" for creating these kinds of Python-HTMl-Javascript front ends for applications. *That* would really help Python's popularity to take off and expode. Ron Stephens From rosuav at gmail.com Tue Jun 12 18:14:50 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jun 2012 08:14:50 +1000 Subject: Where to set default data - where received, or where used In-Reply-To: <6d632fae-b11f-447c-86d8-6ea32ab9d5ab@x6g2000pbh.googlegroups.com> References: <6d632fae-b11f-447c-86d8-6ea32ab9d5ab@x6g2000pbh.googlegroups.com> Message-ID: On Tue, Jun 12, 2012 at 4:37 AM, Dennis Carachiola wrote: > Here's my question. ?I could do this by creating the dictionary with > the default values, then read the file into it. ?Or I could use a > 'get' with default values at the location in the program where those > values are used. Both options have their recommendations. As others have said, setting your defaults in one place has advantages of coherence; but setting them at point of read keeps all the code using it together. You can have an entirely dumb I/O submodule that feeds smart other-modules. Take your pick based on what you're doing. What I would definitely suggest, though, is making a structured config file. (You could "cheat" by importing it as a module and making it simply Python code.) Provide a template config file with lots of explanatory comments, and (crucially) every config entry given, commented out, and set to its default. # Configures the default and maximum flurble percentages # Flurblization increases from the default until either the maximum is # reached, or max_sort_memory is exceeded, whichever comes first. #flurble_default = 10 #flurble_max = 30 Having all your defaults in one place makes it easier to produce this sort of file; in fact, you could have your documentation there as well. It does become a little more maintenance work, though. It's possible to have a hybrid, where you run a preprocessor over your code that analyzes it, collects all config entries, and builds your config file parser... but that may be beyond the scope of your project. Anything you can imagine can be done in code. It's just a question of how much work. :) Chris Angelico From nospam at nospam.com Tue Jun 12 19:57:23 2012 From: nospam at nospam.com (Gilles) Date: Wed, 13 Jun 2012 01:57:23 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <87r4tk25zs.fsf@dpt-info.u-strasbg.fr> Message-ID: On Tue, 12 Jun 2012 07:42:56 -0400, D'Arcy Cain wrote: >I guess I am in the minority then. I do plan to turn one of my larger >projects into a standalone web server some day but so far writing >simple Python CGI scripts has served me fine. I even do some embedding >by using server side scripting. Out of curiosity, why did you choose to write CGI scripts or embedded server-side scripting while standalone web servers are usually presented as _the_ solution for Python (Django, Pylons, etc.)? From nospam at nospam.com Tue Jun 12 19:58:52 2012 From: nospam at nospam.com (Gilles) Date: Wed, 13 Jun 2012 01:58:52 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <87r4tk25zs.fsf@dpt-info.u-strasbg.fr> Message-ID: On Tue, 12 Jun 2012 22:01:10 +1000, Chris Angelico wrote: >Apache's mod_php partially evens out the difference, but not >completely, and of course, it's perfectly possible to write a dispatch >loop in PHP, as Octavian said. It looks like mod_php and equivalents for web servers other than Apache are anecdotal compared to solutions based on standalone web servers. Is that the case? Why is that? From nospam at nospam.com Tue Jun 12 19:59:26 2012 From: nospam at nospam.com (Gilles) Date: Wed, 13 Jun 2012 01:59:26 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> Message-ID: <6ulft7tflehvjaakm9qvqufplpqhlmldlt@4ax.com> On Tue, 12 Jun 2012 20:18:21 +1000, Chris Angelico wrote: >Think of it as Apache + PHP versus Python. Apache keeps running, it's >only your PHP script that starts and stops. With a long-running >process, you keep everything all in together, which IMHO is simpler >and better. Why is a long-running process better? From nospam at nospam.com Tue Jun 12 20:00:49 2012 From: nospam at nospam.com (Gilles) Date: Wed, 13 Jun 2012 02:00:49 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> Message-ID: On Tue, 12 Jun 2012 14:28:22 +0300, "Octavian Rasnita" wrote: >Otherwise... if you want you can also create a web app using PHP and CodeIgniter web framework and run it with fastcgi... Thanks for the infos. From rosuav at gmail.com Tue Jun 12 20:19:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jun 2012 10:19:29 +1000 Subject: [newbie] Equivalent to PHP? In-Reply-To: <6ulft7tflehvjaakm9qvqufplpqhlmldlt@4ax.com> References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <6ulft7tflehvjaakm9qvqufplpqhlmldlt@4ax.com> Message-ID: On Wed, Jun 13, 2012 at 9:59 AM, Gilles wrote: > On Tue, 12 Jun 2012 20:18:21 +1000, Chris Angelico > wrote: >>Think of it as Apache + PHP versus Python. Apache keeps running, it's >>only your PHP script that starts and stops. With a long-running >>process, you keep everything all in together, which IMHO is simpler >>and better. > > Why is a long-running process better? It's far simpler to manage, it retains running state, and is easily enough encapsulated. It's the non-magic way of doing things. Also, it plays very nicely with the MUD style of process, which is something I do a lot with Pike. Plus, if you manage it right, you have a guarantee that you can never be in a half-updated state - that's somewhat tricky when you have inter-dependencies in PHP code and the file system itself manages things. What happens if a request comes in while you're half-way through uploading new code to the server? By default, you could use half old code and half new code. Keeping everything in memory makes it easier to prevent that. ChrisA From ben+python at benfinney.id.au Tue Jun 12 23:33:17 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 13 Jun 2012 13:33:17 +1000 Subject: using identifiers before they are defined References: Message-ID: <87aa07yjgi.fsf@benfinney.id.au> Julio Sergio writes: > Suppose I have to define two functions, aa, and, bb that are designed > to call each other: > > def aa(): > ... > ... a call of bb() somewhere in the body of aa > ... > > def bb(): > ... > ... a call of aa() somewhere in the body of bb > ... > > > Whatever the order of definition of aa and bb the problem remains, one > of the two identifiers is not known ... What problem? Can you show actual code that we can execute, which demonstrates the problem? -- \ ?I turned to speak to God/About the world's despair; But to | `\ make bad matters worse/I found God wasn't there.? ?Robert Frost | _o__) | Ben Finney From rustompmody at gmail.com Wed Jun 13 00:37:20 2012 From: rustompmody at gmail.com (rusi) Date: Tue, 12 Jun 2012 21:37:20 -0700 (PDT) Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> Message-ID: <97990bf0-1945-44b6-803e-980034d51316@qs4g2000pbc.googlegroups.com> On Jun 12, 3:19?am, Matej Cepl wrote: > On 11/06/12 06:20, rusi wrote: > > > Hi Mat?j! If this question is politically incorrect please forgive me. > > Do you speak only one (natural) language -- English? > > And if this set is plural is your power of expression identical in > > each language? > > I have written about that later ... no, I am a native Czech, but I have > passive Russian, and active English. But there is a difference ... I can > read and enjoy beautiful texts in Russian or English (couple of months > read Eugen Onegin in Russian and that's just a beauty! or C.S.Lewis ... > oh my!) but I will never be able to write professionally in these > languages. I can write (as evidenced by this message) somehow in > English, but I cannot imagine that I would be ever professional art > writer or (even worse) poet. I could imagine (if spent couple of > thousands of days working on it) that I would be a Czech professional > writer though. > > Mat?j If we were back-translate that standard to the programming field it would go something like: "You cannot call yourself a programmer until you create something of significance. So Linus writing the linux kernel or Knuth writing Tex or Stallman writing emacs, GvR writing Python are programmers; the rest not." Believe me your English is good enough and better than some mono- lingual ranters on this list who cannot write 2 straight correct sentences yet take it upon themselves to correct others' English. [Sorry for pontificating. I am nearing 50 and have wasted too much of my life in the misguided pursuit of perfectionism. I would wish for younger folks to not err samely] To come back to the OP's question, Alan Perlis said: A language that doesn't affect the way you think about programming, is not worth knowing. More gems here: http://en.wikiquote.org/wiki/Alan_Perlis If you use this to choose what language to learn, you cant go wrong. Most programmers who know dozens of programming languages really know only one imperative language iced with different syntax. Which reminds me of another quip by Alan Perlis: Syntactic sugar causes cancer of the semicolon. From darcy at druid.net Wed Jun 13 01:52:01 2012 From: darcy at druid.net (D'Arcy Cain) Date: Wed, 13 Jun 2012 01:52:01 -0400 Subject: [newbie] Equivalent to PHP? In-Reply-To: References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <87r4tk25zs.fsf@dpt-info.u-strasbg.fr> Message-ID: <4FD82A81.4000308@druid.net> On 12-06-12 07:57 PM, Gilles wrote: > On Tue, 12 Jun 2012 07:42:56 -0400, D'Arcy Cain > wrote: >> I guess I am in the minority then. I do plan to turn one of my larger >> projects into a standalone web server some day but so far writing >> simple Python CGI scripts has served me fine. I even do some embedding >> by using server side scripting. > > Out of curiosity, why did you choose to write CGI scripts or embedded > server-side scripting while standalone web servers are usually > presented as _the_ solution for Python (Django, Pylons, etc.)? History and laziness I suppose. My biggest project started out as Tcl and was switched to Python around 1.5. Besides, the boys and girls at Apache have done a great job. May as well build on that. Even if I go with a standalone server I will probably put Apache in front of it for images, style sheets and other static content. I also want to look into writing Apache modules in Python some day. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From dieter at handshake.de Wed Jun 13 01:58:06 2012 From: dieter at handshake.de (Dieter Maurer) Date: Wed, 13 Jun 2012 07:58:06 +0200 Subject: Using pdb with greenlet? References: Message-ID: <87vciv69e9.fsf@handshake.de> Salman Malik writes: > I am sort of a newbie to Python ( have just started to use pdb). > My problem is that I am debugging an application that uses greenlets and when > I encounter something in code that spawns the coroutines or wait for an event, > I lose control over the application (I mean that after that point I can no > longer do 'n' or 's' on the code). Can anyone of you tell me how to tame > greenlet with pdb, so that I can see step-by-step as to what event does a > coroutine sees and how does it respond to it. > Any help would be highly appreciated. Debugging works via the installation of a "tracehook" function. If such a function is installed in a thread, the Python interpreter calles back via the installed hook to report events relevant for debugging. Usually the hook function is defined by a debugger which examines whether the event is user relevant (e.g. if a breakpoint has been hit, or code for a new line has been entered) and in this case imforms the user and may give him control. It is important that the trace hook installation is thread specific. Otherwise, debugging in a multithreaded environment would be a nightmare - as events from multiple threads may arrive and seriously confuse the debugger as well as the user. I do not know "greenlet". However, I expect that it uses threads under the hood to implement coroutines. In such a case, it would be natural that debugging one coroutine would not follow the execution into a different coroutine. To change this, "greenlet" would need to specially support the "tracehook" feature: when control is transfered to a different coroutine, the "tracehook" would need to be transfered as well. Personally, I am not sure that this would be a good idea (I sometimes experience debugging interaction from different threads -- and I can tell you that it is a really nasty experience). However, you can set the "tracehook" youself in your each of your coroutines: "import pdb; pdb.set_trace()". This is called a "code breakpoint". It installs the debuggers "tracehook" function in the current thread and gives control to the debugger (i.e. it works like a breakpoint). I use this quite frequently to debug multithreaded web applications and it works quite well (sometimes with nasty experiences). "pdb" is not optimal to for multithread debugging because it expects to interact with a single thread only. For a good experience, a thread aware extension would be necessary. -- Dieter From nagle at animats.com Wed Jun 13 02:17:32 2012 From: nagle at animats.com (John Nagle) Date: Tue, 12 Jun 2012 23:17:32 -0700 Subject: Internationalized domain names not working with URLopen Message-ID: I'm trying to open http://??????.????????? with urllib2.urlopen(s1) in Python 2.7 on Windows 7. This produces a Unicode exception: >>> s1 u'http://\u043f\u0440\u0438\u043c\u0435\u0440.\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435' >>> fd = urllib2.urlopen(s1) Traceback (most recent call last): File "", line 1, in File "C:\python27\lib\urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "C:\python27\lib\urllib2.py", line 394, in open response = self._open(req, data) File "C:\python27\lib\urllib2.py", line 412, in _open '_open', req) File "C:\python27\lib\urllib2.py", line 372, in _call_chain result = func(*args) File "C:\python27\lib\urllib2.py", line 1199, in http_open return self.do_open(httplib.HTTPConnection, req) File "C:\python27\lib\urllib2.py", line 1168, in do_open h.request(req.get_method(), req.get_selector(), req.data, headers) File "C:\python27\lib\httplib.py", line 955, in request self._send_request(method, url, body, headers) File "C:\python27\lib\httplib.py", line 988, in _send_request self.putheader(hdr, value) File "C:\python27\lib\httplib.py", line 935, in putheader hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values])) UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128) >>> The HTTP library is trying to put the URL in the header as ASCII. Why isn't "urllib2" handling that? What does "urllib2" want? Percent escapes? Punycode? John Nagle From bahamutzero8825 at gmail.com Wed Jun 13 02:42:41 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 13 Jun 2012 01:42:41 -0500 Subject: Internationalized domain names not working with URLopen In-Reply-To: References: Message-ID: <4FD83661.3000701@gmail.com> On 6/13/2012 1:17 AM, John Nagle wrote: > What does "urllib2" want? Percent escapes? Punycode? Looks like Punycode is the correct answer: https://en.wikipedia.org/wiki/Internationalized_domain_name#ToASCII_and_ToUnicode I haven't tried it, though. -- CPython 3.3.0a3 | Windows NT 6.1.7601.17790 From hash.3g at gmail.com Wed Jun 13 02:47:06 2012 From: hash.3g at gmail.com (=?KOI8-R?B?98nUwczJyiD3z8zLz9c=?=) Date: Wed, 13 Jun 2012 09:47:06 +0300 Subject: Internationalized domain names not working with URLopen In-Reply-To: References: Message-ID: Answer in this topic should help you to solve issue. http://stackoverflow.com/questions/8152161/open-persian-url-domains-with-urllib2?answertab=active#tab-top Regards. 2012/6/13 John Nagle > I'm trying to open > > http://??????.????????? > > with > > urllib2.urlopen(s1) > > in Python 2.7 on Windows 7. This produces a Unicode exception: > > >>> s1 > u'http://\u043f\u0440\u0438\**u043c\u0435\u0440.\u0438\** > u0441\u043f\u044b\u0442\u0430\**u043d\u0438\u0435' > >>> fd = urllib2.urlopen(s1) > Traceback (most recent call last): > File "", line 1, in > File "C:\python27\lib\urllib2.py", line 126, in urlopen > return _opener.open(url, data, timeout) > File "C:\python27\lib\urllib2.py", line 394, in open > response = self._open(req, data) > File "C:\python27\lib\urllib2.py", line 412, in _open > '_open', req) > File "C:\python27\lib\urllib2.py", line 372, in _call_chain > result = func(*args) > File "C:\python27\lib\urllib2.py", line 1199, in http_open > return self.do_open(httplib.**HTTPConnection, req) > File "C:\python27\lib\urllib2.py", line 1168, in do_open > h.request(req.get_method(), req.get_selector(), req.data, headers) > File "C:\python27\lib\httplib.py", line 955, in request > self._send_request(method, url, body, headers) > File "C:\python27\lib\httplib.py", line 988, in _send_request > self.putheader(hdr, value) > File "C:\python27\lib\httplib.py", line 935, in putheader > hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values])) > UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: > ordinal not in range(128) > >>> > > The HTTP library is trying to put the URL in the header as ASCII. Why > isn't "urllib2" handling that? > > What does "urllib2" want? Percent escapes? Punycode? > > John Nagle > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Jun 13 04:29:05 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Jun 2012 08:29:05 GMT Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <87r4tk25zs.fsf@dpt-info.u-strasbg.fr> Message-ID: <4fd84f51$0$11123$c3e8da3@news.astraweb.com> On Tue, 12 Jun 2012 12:36:36 +0200, Gilles wrote: > I enjoy writing scripts in Python much more than PHP, but with so many > sites written in PHP, I need to know what major benefits there are in > choosing Python (or Ruby, ie. not PHP). The main benefit is that they are not PHP. http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ and especially lack PHP's security vulnerabilities. -- Steven From phihag at phihag.de Wed Jun 13 04:40:01 2012 From: phihag at phihag.de (Philipp Hagemeister) Date: Wed, 13 Jun 2012 10:40:01 +0200 Subject: multiprocessing: excepthook not getting called In-Reply-To: References: Message-ID: <4FD851E1.5010406@phihag.de> multiprocessing just mimicks the threading module here, see http://bugs.python.org/issue1230540 . Why do you need excepthook in the first place? You can perfectly simulate it by wrapping the root method (target in your example) in a try .. catch: import multiprocessing import sys def printErrors(func): def wrapped(*args, **kwargs): try: func() except: print ('except: ', sys.exc_info()) return wrapped @printErrors def target(): raise ValueError() if __name__ == '__main__': p = multiprocessing.Process(target=target) p.start() p.join() # try it here in main target() Cheers, Philipp On 06/12/2012 11:02 PM, Dave Cook wrote: > Why doesn't my excepthook get called in the child process? > > import sys > import multiprocessing as mp > > def target(): > name = mp.current_process().name > def exceptHook(*args): > print 'exceptHook:', name, args > sys.excepthook = exceptHook > raise ValueError > > if __name__=='__main__': > p = mp.Process(target=target) > p.start() > p.join() > # try it here in main > target() > > Thanks, > Dave Cook -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: OpenPGP digital signature URL: From nospam at nospam.com Wed Jun 13 05:21:45 2012 From: nospam at nospam.com (Gilles) Date: Wed, 13 Jun 2012 11:21:45 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <87r4tk25zs.fsf@dpt-info.u-strasbg.fr> <4fd84f51$0$11123$c3e8da3@news.astraweb.com> Message-ID: <1tmgt7lfmbffgr5r8ivj3e8ss8tqlohd3m@4ax.com> On 13 Jun 2012 08:29:05 GMT, Steven D'Aprano wrote: >http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ > >and especially lack PHP's security vulnerabilities. Thanks for the link. From nospam at nospam.com Wed Jun 13 05:22:55 2012 From: nospam at nospam.com (Gilles) Date: Wed, 13 Jun 2012 11:22:55 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <6ulft7tflehvjaakm9qvqufplpqhlmldlt@4ax.com> Message-ID: On Wed, 13 Jun 2012 10:19:29 +1000, Chris Angelico wrote: >It's far simpler to manage, it retains running state, and is easily >enough encapsulated. It's the non-magic way of doing things. Also, it >plays very nicely with the MUD style of process, which is something I >do a lot with Pike. Plus, if you manage it right, you have a guarantee >that you can never be in a half-updated state - that's somewhat tricky >when you have inter-dependencies in PHP code and the file system >itself manages things. What happens if a request comes in while you're >half-way through uploading new code to the server? By default, you >could use half old code and half new code. Keeping everything in >memory makes it easier to prevent that. Thanks for the input. From phihag at phihag.de Wed Jun 13 05:23:43 2012 From: phihag at phihag.de (Philipp Hagemeister) Date: Wed, 13 Jun 2012 11:23:43 +0200 Subject: multiprocessing: excepthook not getting called In-Reply-To: References: <4FD851E1.5010406@phihag.de> Message-ID: <4FD85C1F.4040300@phihag.de> On 06/13/2012 11:00 AM, Dave Cook wrote: > Originally, I was trying to send formatted > tracebacks back to the main process on a queue. You can still do that: import multiprocessing import sys def queueErrors(q): def decorator(func): def wrapped(*args, **kwargs): try: func() except: q.put((multiprocessing.current_process().name, repr(sys.exc_info()))) return wrapped return decorator q = multiprocessing.Queue() @queueErrors(q) def target(): raise ValueError() if __name__ == '__main__': p = multiprocessing.Process(target=target) p.start() p.join() # try it here in main while True: pname,exc = q.get() print('Caught error in process %r: %s' % (pname, exc)) It gets somewhat harder when you also want to catch termination of threads, but you can just queue a special message. - Philipp -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: OpenPGP digital signature URL: From nospam at nospam.com Wed Jun 13 05:25:39 2012 From: nospam at nospam.com (Gilles) Date: Wed, 13 Jun 2012 11:25:39 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> Message-ID: <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> On Tue, 12 Jun 2012 16:48:27 +0200, Matej Cepl wrote: >I don't think it is a proper description of the situation (please, >somebody correct my mistakes, I am not 100% sure about it myself). WSGI >applications (which is basically all web applications in Python) could >run in the hosted servers (using for example mod_wsgi for Apache), and I >would expect that it is the situation with most production uses. I have a couple more questions: 1. Today what is the recommended way to connect a long-running Python web application with a web server running in the front? FastCGI? WSGI? Other? 2. Which solid web server is recommended to connect to Python web applications in the back? 3. What Python web framework would you recommend to get started, and possibly more heavy duty framework in case I need something bigger later? Thank you. From rosuav at gmail.com Wed Jun 13 05:41:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jun 2012 19:41:41 +1000 Subject: [newbie] Equivalent to PHP? In-Reply-To: <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> Message-ID: On Wed, Jun 13, 2012 at 7:25 PM, Gilles wrote: > I have a couple more questions: > > 1. Today what is the recommended way to connect a long-running Python > web application with a web server running in the front? FastCGI? WSGI? > Other? > > 2. Which solid web server is recommended to connect to Python web > applications in the back? > > 3. What Python web framework would you recommend to get started, and > possibly more heavy duty framework in case I need something bigger > later? There are quite a few Python web frameworks, but I've never used any. What I have done, though, is subclass BaseHTTPServer.BaseHTTPRequestHandler, override do_GET(self), and run a core loop with a single line of code (well, there's a little more so the server can be halted cleanly with Ctrl-C, but close enough). And it runs beautifully on Windows and Linux, and would probably run on any other platform with a Python, if anyone felt like trying.it. However, there are times when you need a little more organization, and I don't know how easy it is to minimize downtime when you need to update code (with this particular example, I just restart it and have a couple of minutes' outage, which isn't an issue). For high-availability servers, I can't speak for Python, as I've never done that there; but it seems likely that there's good facilities. My personal preference is Pike, but that's off-topic for this list. :) But the simple answer for simple tasks is: Don't bother with frameworks, run an HTTP server. Chris Angelico From nospam at nospam.com Wed Jun 13 05:49:00 2012 From: nospam at nospam.com (Gilles) Date: Wed, 13 Jun 2012 11:49:00 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> Message-ID: On Wed, 13 Jun 2012 19:41:41 +1000, Chris Angelico wrote: >For high-availability servers, I can't speak for Python, as I've never >done that there; but it seems likely that there's good facilities. My >personal preference is Pike, but that's off-topic for this list. :) >But the simple answer for simple tasks is: Don't bother with >frameworks, run an HTTP server. Thanks. What do you mean with "Don't bother with frameworks, run an HTTP server"? Subclassing BaseHTTPServer? From rosuav at gmail.com Wed Jun 13 06:00:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jun 2012 20:00:59 +1000 Subject: [newbie] Equivalent to PHP? In-Reply-To: References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> Message-ID: On Wed, Jun 13, 2012 at 7:49 PM, Gilles wrote: > On Wed, 13 Jun 2012 19:41:41 +1000, Chris Angelico > wrote: >>For high-availability servers, I can't speak for Python, as I've never >>done that there; but it seems likely that there's good facilities. My >>personal preference is Pike, but that's off-topic for this list. :) >>But the simple answer for simple tasks is: Don't bother with >>frameworks, run an HTTP server. > > Thanks. What do you mean with "Don't bother with frameworks, run an > HTTP server"? Subclassing BaseHTTPServer? Apache is a web server, by which one technically means an HTTP server. HTTP is the protocol (HyperText Transfer Protocol) by which web servers and browsers communicate. Basically, you listen on a TCP/IP socket, usually port 80, and respond to requests. One way to achieve that is to let somebody else do the whole listen-on-80 bit and then call upon you to generate a block of text. That's what happens with Apache and PHP - your PHP script doesn't think about sockets, listening, and so on, it just gets a request and deals with it. The other obvious option is to write your own code using the basic BSD socket functions, and do the whole job yourself. That's a good thing to do once in a while, just to get to know how it all fits together, but unless you're working in C, there's no particular reason to go to that much hassle. Half way in between is where BaseHTTPServer puts you. All the grunt-work is done for you, but your program is still 100% in control. You call on somebody else's code (the Python standard library) to handle all the socket basics, and your code gets called to generate a page. But you can do more than just generate a page, if you so desire. Most high level languages probably have some sort of HTTP server available. Some make it trivially easy to plug some code in and start serving. Python is advertised as "batteries included", and one of its packets of batteries is a fairly full-featured set of internet protocol handlers. ChrisA From andrea.crotti.0 at gmail.com Wed Jun 13 06:06:03 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 13 Jun 2012 11:06:03 +0100 Subject: validating XML Message-ID: Hello Python friends, I have to validate some xml files against some xsd schema files, but I can't use any cool library as libxml unfortunately. A Python-only validator might be also fine, but all the projects I've seen are partial or seem dead.. So since we define the schema ourselves, I was allowed to only implement the parts of the huge XML definition that we actually need. Now I'm not quite sure how to do the validation myself, any suggestions? I thought that I could first parse and store in memory the schema, then iterate over the XML I need to validate and do the needed sanity checks there. So I might use or minidom.parse or ElementTree.parse, which both look fine even if I'm not sure which one is more suitable. Another thing is that I would like to be able that if the schema changes my validation is still correct, so I would need some sort of meta-schema that declares all the XML constructs that I'm allowed to use. Anyone did something like this? Thanks, Andrea -------------- next part -------------- An HTML attachment was scrubbed... URL: From nospam at nospam.com Wed Jun 13 06:17:12 2012 From: nospam at nospam.com (Gilles) Date: Wed, 13 Jun 2012 12:17:12 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> Message-ID: <50qgt7lg5qpkm8nocs0c85uj72trnegh3t@4ax.com> On Wed, 13 Jun 2012 20:00:59 +1000, Chris Angelico wrote: >Most high level languages probably have some sort of HTTP server >available. Some make it trivially easy to plug some code in and start >serving. Python is advertised as "batteries included", and one of its >packets of batteries is a fairly full-featured set of internet >protocol handlers. Thanks for the longer explanation. With so many frameworks, I'd like to know what benefits they offer as compared to writing an application from scratch, and if they do offer obvious benefits, which one to pick :-/ http://wiki.python.org/moin/WebFrameworks From ramapraba2653 at gmail.com Wed Jun 13 07:12:20 2012 From: ramapraba2653 at gmail.com (SUPREME) Date: Wed, 13 Jun 2012 04:12:20 -0700 (PDT) Subject: SOUTH INDIAN ACTRESS HOT STILLS & TOP INTERVIEW QUESTIONS Message-ID: ALL INTERVIEW QUESTIONS& STUDY MATERIAL http://newdotnetinterviewquestions.blogspot.in/ TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR LATEST MOVIE UPDATED LINKS COOL BOYS HOT GIRLS MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/06/cool-boys-hot-girls-movie-stills.html MITAAYI MOVIE LATEST GALLERY http://actressgallery-kalyani.blogspot.in/2012/06/mitaayi-movie-stills.html NAGARJUNA DAMARUKAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/damarukam-movie-stills.html ALLU ARJUN JULAYI MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/julayi-movie-stills.html SUDIGADU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/sudigadu-movie-stills.html MR 7 MOVIE FILM GALLERY http://actressgallery-kalyani.blogspot.in/2012/05/mr7-movie-stills.html ALL THE BEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/all-best-movie-stills.html Midatha Telugu movie Hot Namitha Stills http://actressgallery-kalyani.blogspot.com/2012/05/midatha-movie-stills.html OKA COLLEGE LOVE STORY MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/oka-college-love-story-movie-stills.html KATRINA KAIF LATEST UNSEENED PHOTOS http://actressgallery-kalyani.blogspot.com/2012/05/katrina-kaif-latest-pics.html TAMIL ACTRESS ARUNDHATI HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/05/arundhati-tamil-actress.html THANDHAVAM MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/05/thandavam-movie-stills.html KHO KHO LATEST MOVIE SPICY STILLS http://actressgallery-kalyani.blogspot.com/2012/05/kho-kho-movie-stills.html Oh My Love Movie Latest Photo Gallery http://actressgallery-kalyani.blogspot.com/2012/04/oh-my-love-movie-stills.html Oka Romantic Crime katha Movie stills http://actressgallery-kalyani.blogspot.in/2012/04/oka-romantic-crime-katha-movie-stills.html DARUVU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/03/daruvu-movie-stills.html Pavan Kalyan,Shruthi Hasan Gabbar Singh Movie Photos http://actressgallery-kalyani.blogspot.in/2012/04/gabbar-singh-movie-stills.html Good Morning Latest Movie Stills http://actressgallery-kalyani.blogspot.com/2012/04/good-morning-movie-stills.html EEGA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/04/eega-movie-stills.html Mem Vayasuku Vacham Latest Hot Stills http://actressgallery-kalyani.blogspot.com/2012/04/mem-vayasuku-vacham-stills.html DAMMU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/04/dammu-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html HOT LINKS FOR YOUTH ONLY SHRUTHI HASSAN HALF SAREE STILLS http://actressimages-9.blogspot.in/2012/05/shruti-hassan-half-saree-stills.html TAMANNA HOT NAVEL PHOTOS http://actressimages-9.blogspot.in/2012/05/tamanna-navel-photos.html TRISHA LATEST HOT STILLS http://actressgallery9.blogspot.in/2012/05/trisha.html MONIKA LATEST HOT HD STLLS http://actressgallery9.blogspot.in/2012/05/monika-stills.html MALLIKA KAPOOR HOT SIZZLING STILLS http://actressimages-9.blogspot.in/2012/05/mallika-kapoor.html Richa Panai Stills http://actressimages-9.blogspot.com/2012/04/richa-panai-stills.html MADHAVI LATHA LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/04/madhavi-latha-stills.html KRITI KHARBANDA HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/kriti-kharbanda.html NEELAM UPADHYAY HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/neelam-upadhyay.html SAMANTHA LATEST HOT ROMANTIC STILLS http://actressimages-9.blogspot.in/2012/03/samantha-latest-stills.html NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html From tarek at ziade.org Wed Jun 13 07:41:25 2012 From: tarek at ziade.org (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Wed, 13 Jun 2012 13:41:25 +0200 Subject: network protocols Message-ID: <4FD87C65.7060905@ziade.org> Hey I was surprised not to find any way to list all protocol names listed in /etc/protocols in Python We have socket.getprotobyname(NAME) But there's no way to get the list of names Any ideas if this is available in the stdlib somehwere ? Thx Tarek From pf at artcom-gmbh.de Wed Jun 13 08:05:29 2012 From: pf at artcom-gmbh.de (Peter Funk) Date: Wed, 13 Jun 2012 14:05:29 +0200 Subject: Ann: New Stackless Website In-Reply-To: <4FD62465.7020604@stackless.com> References: <4FD62465.7020604@stackless.com> Message-ID: <20120613120529.GF6006@artcom0.artcom-gmbh.de> Christian Tismer wrote on monday, 11.06.2012 at 19:01: ... > Stackless Python has a New Website ... > Due to a great effort of the Nagare people: > > http://www.nagare.org/ > > and namely by the tremendous work of Alain Pourier, > > Stackless Python has now a new website! > > This is no longer Plone based, but a nicely configured Trac site. I'm only another user of Plone and I'm only curious: Would you or someone else care to explain what made you move away from Plone? I think especially the Plone community might also be interested. Viele Gr??e (Best Regards), Peter Funk -- Peter Funk mobile:+49-179-640-8878 phone:+49-421-20419-0 office: ArtCom GmbH, ?Haferwende 2, D-28357 Bremen, Germany From feliphil at gmx.net Wed Jun 13 08:26:29 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Wed, 13 Jun 2012 14:26:29 +0200 Subject: Pythonic cross-platform GUI desingers =?ISO-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: <20120613142629.76c0130e.feliphil@gmx.net> > > * Domain experts in fact who would need to implement loads of > > software to help them get their work done but can't. And since > > there's no budget for external developers, nothing get's ever done > > about this. > Well, typically or at least very often sooner or later something > gets done about this as someone finds out that all could be solved > using MS Excel and some macros / VBA programming. MS Excel is unusable for any kind of serious work, due its serious design deficiences. But that's off-topic here. VB(A) is unusable for everyday office automation because it doesn't offer an interactive commandline interpreter. Besides, both only run^H^H^Hlimp on a pathologic non-operating system that's just as unsuitable for any productive work. But that's off-topic, too. > I would prefer people to invest the same time into a Python based > solution. > But then we're back to the initial point: As long as there's no GUI > builder for Python, most people will stick to Excel / VBA / VB. There are quite a few GUI builders out there for Python. The point is that they are not very "pythonic" imho, i.e. they don't really show what the advantage of Python is for GUIs over those other languages. And imho these GUI builders, just like the frameworks that they generate code for are not very suitable for someone who's not a software developer by profession. Because they require way too much "glue code". And unfortunately the origin of this problem seems to be the open-source development model itself: Since developers of open source development tools (GUI frameworks, GUI builders etc.) usually implement these for their own use, and since these people are typically software developers by profession who come from a C++-dominated background, they don't see the necessity and they don't have any motivation to implement anything that would help all those potential Python users out there who just can't devote the time and effort required to get over that pretty huge step in the learning curve of those frameworks and tools. Please note that this is not meant as criticism to open-source developers, but as a hint that there might be a business opportunity for someone here to develop and sell something for money. ;-) Sincerely, Wolfgang From feliphil at gmx.net Wed Jun 13 08:36:08 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Wed, 13 Jun 2012 14:36:08 +0200 Subject: Pythonic cross-platform GUI desingers =?ISO-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: <20120613143608.f0125a3b.feliphil@gmx.net> > > Tkinter is imho honestly the very best "argument" if you want to > > make potential new users turn their backs away from Python for > > good. Just show them one GUI implemented with it and, hey, wait, > > where are you running to... > > Yes, Tkinter GUI's are very ugly. > > http://www.codebykevin.com/phynchronicity-running.png > > http://www.codebykevin.com/quickwho-main.png OK, so after what - one and a half decades? - Tkinter now finally has caught up with wxPython and PyQt (concerning the look). Which can be used in an as interactive way from the commandline interpreter as Tkinter. Argument against Tkinter withdrawn from my side. But there's afaik still no interactive GUI builder out there for any of these frameworks, nor a higher level framework that requires less glue code between bare naked "event handling" and the domain-specific code. "Event handling" - that term already raises my hair because it stinks like bulkloads of clumsy, error-prone diligence work that has nothing to do with the problem I need to get solved. Sincerely, Wolfgang From feliphil at gmx.net Wed Jun 13 08:49:31 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Wed, 13 Jun 2012 14:49:31 +0200 Subject: Pythonic cross-platform GUI desingers =?ISO-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: <4FD4F75D.40602@schwertberger.de> Message-ID: <20120613144931.adbb2c52.feliphil@gmx.net> > No matter how cool it may seem to create simple GUIs manually or to > write business letters using LaTeX: just try to persuade people to > move from Word to LaTeX for business letters... Good example. I have done nearly exactly this* - but it was only possible thanks to LyX. Sincerely, Wolfgang *I moved not from Wugh, but from other software to LyX/LaTeX for all my document processing. From jsutter55 at hotmail.com Wed Jun 13 10:10:25 2012 From: jsutter55 at hotmail.com (John Sutterfield) Date: Wed, 13 Jun 2012 10:10:25 -0400 Subject: network protocols In-Reply-To: <4FD87C65.7060905@ziade.org> References: <4FD87C65.7060905@ziade.org> Message-ID: Tarek, There doesn't appear to be a function in stdlib to cover that particular case. Doug Hellman has a nice section on finding service info here: http://www.doughellmann.com/PyMOTW/socket/addressing.html It wouldn't be "built-in", but it looks like it would be pretty simple to get the info you need. Best regards, JS > Date: Wed, 13 Jun 2012 13:41:25 +0200 > From: tarek at ziade.org > To: python-list at python.org > Subject: network protocols > > Hey > > I was surprised not to find any way to list all protocol names listed in > /etc/protocols in Python > > We have > > socket.getprotobyname(NAME) > > But there's no way to get the list of names > > Any ideas if this is available in the stdlib somehwere ? > > Thx > Tarek > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tdldev at gmail.com Wed Jun 13 10:50:41 2012 From: tdldev at gmail.com (Verde Denim) Date: Wed, 13 Jun 2012 10:50:41 -0400 Subject: network protocols In-Reply-To: References: <4FD87C65.7060905@ziade.org> Message-ID: On 6/13/12, John Sutterfield wrote: > > Tarek, > > There doesn't appear to be a function in stdlib to cover that particular > case. > > Doug Hellman has a nice section on finding service info here: > > http://www.doughellmann.com/PyMOTW/socket/addressing.html > > It wouldn't be "built-in", but it looks like it would be pretty simple to > get the info you need. > > Best regards, > > JS > JS Very nice link! Great information here. -- Jack >> Date: Wed, 13 Jun 2012 13:41:25 +0200 >> From: tarek at ziade.org >> To: python-list at python.org >> Subject: network protocols >> >> Hey >> >> I was surprised not to find any way to list all protocol names listed in >> /etc/protocols in Python >> >> We have >> >> socket.getprotobyname(NAME) >> >> But there's no way to get the list of names >> >> Any ideas if this is available in the stdlib somehwere ? >> >> Thx >> Tarek >> -- >> http://mail.python.org/mailman/listinfo/python-list > From lists at cheimes.de Wed Jun 13 10:56:12 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 13 Jun 2012 16:56:12 +0200 Subject: network protocols In-Reply-To: <4FD87C65.7060905@ziade.org> References: <4FD87C65.7060905@ziade.org> Message-ID: Am 13.06.2012 13:41, schrieb Tarek Ziad?: > Hey > > I was surprised not to find any way to list all protocol names listed in > /etc/protocols in Python > > We have > > socket.getprotobyname(NAME) > > But there's no way to get the list of names > > Any ideas if this is available in the stdlib somehwere ? No, I can't find any reference to the relevant NSS APIs in the Python code. You can easily roll your own with ctypes: from ctypes import * libc = CDLL("libc.so.6") class protoent(Structure): _fields_ = [("p_name", c_char_p), ("p_aliases", POINTER(c_char_p)), ("p_proto", c_int)] libc.getprotoent.restype = POINTER(protoent) # open database libc.setprotoent(0) while True: pr = libc.getprotoent() if not pr: break r = pr[0] print r.p_name, r.p_proto # close database libc.endprotoent() From lists at cheimes.de Wed Jun 13 11:27:21 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 13 Jun 2012 17:27:21 +0200 Subject: [newbie] Equivalent to PHP? In-Reply-To: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> Message-ID: Am 12.06.2012 11:39, schrieb Gilles: > I notice that Python-based solutions are usually built as long-running > processes with their own web server (or can run in the back with eg. > Nginx and be reached through eg. FastCGI/WSGI ) while PHP is simply a > language to write scripts and requires a web server (short running > processes). A long running process has lots of benefits that makes design and development easier and makes your app faster. * Don't underestimate the costs of process creation. It doesn't scale unless you fork() childs which is more complex and still doesn't scale as well as a long running process. * you can do all costly and time consuming operations on startup like loading all configuration files and databases like i18n stuff. * performance tweaks like database connection pool works only with a long running process. * in-process caching is usually easier to implement and faster. In some cases only in-process works. * you can have background tasks without the requirement of an outside service like cron + wget. * async server based on a select()-like reactor are only possible when a single process handles the incoming connections. A long running process is more powerful and the 'enterprise' way of doing it right. All important and large scale Python and Java solutions are using long running processes instead of a CGI-like model. PHP's way is a poor man's solution to compensate for bad design and memory holes. PHP's ancestor PHTML still bleeds through and makes you suffer for mistakes of the past. Christian From hemanth.hm at gmail.com Wed Jun 13 11:32:17 2012 From: hemanth.hm at gmail.com (Hemanth H.M) Date: Wed, 13 Jun 2012 21:02:17 +0530 Subject: Internationalized domain names not working with URLopen In-Reply-To: References: Message-ID: Well not really! does not work with '?.net' Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "/usr/lib/python2.6/urllib2.py", line 391, in open response = self._open(req, data) File "/usr/lib/python2.6/urllib2.py", line 409, in _open '_open', req) File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain result = func(*args) File "/usr/lib/python2.6/urllib2.py", line 1170, in http_open return self.do_open(httplib.HTTPConnection, req) File "/usr/lib/python2.6/urllib2.py", line 1116, in do_open h = http_class(host, timeout=req.timeout) # will parse host:port File "/usr/lib/python2.6/httplib.py", line 661, in __init__ self._set_hostport(host, port) File "/usr/lib/python2.6/httplib.py", line 686, in _set_hostport raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) httplib.InvalidURL: nonnumeric port: On Wed, Jun 13, 2012 at 12:17 PM, ??????? ?????? wrote: > Answer in this topic should help you to solve issue. > > > http://stackoverflow.com/questions/8152161/open-persian-url-domains-with-urllib2?answertab=active#tab-top > > > Regards. > > > 2012/6/13 John Nagle > >> I'm trying to open >> >> http://??????.????????? >> >> with >> >> urllib2.urlopen(s1) >> >> in Python 2.7 on Windows 7. This produces a Unicode exception: >> >> >>> s1 >> u'http://\u043f\u0440\u0438\**u043c\u0435\u0440.\u0438\** >> u0441\u043f\u044b\u0442\u0430\**u043d\u0438\u0435' >> >>> fd = urllib2.urlopen(s1) >> Traceback (most recent call last): >> File "", line 1, in >> File "C:\python27\lib\urllib2.py", line 126, in urlopen >> return _opener.open(url, data, timeout) >> File "C:\python27\lib\urllib2.py", line 394, in open >> response = self._open(req, data) >> File "C:\python27\lib\urllib2.py", line 412, in _open >> '_open', req) >> File "C:\python27\lib\urllib2.py", line 372, in _call_chain >> result = func(*args) >> File "C:\python27\lib\urllib2.py", line 1199, in http_open >> return self.do_open(httplib.**HTTPConnection, req) >> File "C:\python27\lib\urllib2.py", line 1168, in do_open >> h.request(req.get_method(), req.get_selector(), req.data, headers) >> File "C:\python27\lib\httplib.py", line 955, in request >> self._send_request(method, url, body, headers) >> File "C:\python27\lib\httplib.py", line 988, in _send_request >> self.putheader(hdr, value) >> File "C:\python27\lib\httplib.py", line 935, in putheader >> hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values])) >> UnicodeEncodeError: 'ascii' codec can't encode characters in position >> 0-5: ordinal not in range(128) >> >>> >> >> The HTTP library is trying to put the URL in the header as ASCII. Why >> isn't "urllib2" handling that? >> >> What does "urllib2" want? Percent escapes? Punycode? >> >> John Nagle >> -- >> http://mail.python.org/**mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- *'I am what I am because of who we all are'* h3manth.com *-- Hemanth HM * -------------- next part -------------- An HTML attachment was scrubbed... URL: From hemanth.hm at gmail.com Wed Jun 13 11:44:00 2012 From: hemanth.hm at gmail.com (Hemanth H.M) Date: Wed, 13 Jun 2012 21:14:00 +0530 Subject: Internationalized domain names not working with URLopen In-Reply-To: References: Message-ID: My bad, it worked; need to avoid http:// along with snowman, before encode. On Wed, Jun 13, 2012 at 9:02 PM, Hemanth H.M wrote: > Well not really! does not work with '?.net' > > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen > return _opener.open(url, data, timeout) > File "/usr/lib/python2.6/urllib2.py", line 391, in open > response = self._open(req, data) > File "/usr/lib/python2.6/urllib2.py", line 409, in _open > '_open', req) > File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain > result = func(*args) > File "/usr/lib/python2.6/urllib2.py", line 1170, in http_open > return self.do_open(httplib.HTTPConnection, req) > File "/usr/lib/python2.6/urllib2.py", line 1116, in do_open > h = http_class(host, timeout=req.timeout) # will parse host:port > File "/usr/lib/python2.6/httplib.py", line 661, in __init__ > self._set_hostport(host, port) > File "/usr/lib/python2.6/httplib.py", line 686, in _set_hostport > raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) > httplib.InvalidURL: nonnumeric port: > > > On Wed, Jun 13, 2012 at 12:17 PM, ??????? ?????? wrote: > >> Answer in this topic should help you to solve issue. >> >> >> http://stackoverflow.com/questions/8152161/open-persian-url-domains-with-urllib2?answertab=active#tab-top >> >> >> Regards. >> >> >> 2012/6/13 John Nagle >> >>> I'm trying to open >>> >>> http://??????.????????? >>> >>> with >>> >>> urllib2.urlopen(s1) >>> >>> in Python 2.7 on Windows 7. This produces a Unicode exception: >>> >>> >>> s1 >>> u'http://\u043f\u0440\u0438\**u043c\u0435\u0440.\u0438\** >>> u0441\u043f\u044b\u0442\u0430\**u043d\u0438\u0435' >>> >>> fd = urllib2.urlopen(s1) >>> Traceback (most recent call last): >>> File "", line 1, in >>> File "C:\python27\lib\urllib2.py", line 126, in urlopen >>> return _opener.open(url, data, timeout) >>> File "C:\python27\lib\urllib2.py", line 394, in open >>> response = self._open(req, data) >>> File "C:\python27\lib\urllib2.py", line 412, in _open >>> '_open', req) >>> File "C:\python27\lib\urllib2.py", line 372, in _call_chain >>> result = func(*args) >>> File "C:\python27\lib\urllib2.py", line 1199, in http_open >>> return self.do_open(httplib.**HTTPConnection, req) >>> File "C:\python27\lib\urllib2.py", line 1168, in do_open >>> h.request(req.get_method(), req.get_selector(), req.data, headers) >>> File "C:\python27\lib\httplib.py", line 955, in request >>> self._send_request(method, url, body, headers) >>> File "C:\python27\lib\httplib.py", line 988, in _send_request >>> self.putheader(hdr, value) >>> File "C:\python27\lib\httplib.py", line 935, in putheader >>> hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values])) >>> UnicodeEncodeError: 'ascii' codec can't encode characters in position >>> 0-5: ordinal not in range(128) >>> >>> >>> >>> The HTTP library is trying to put the URL in the header as ASCII. Why >>> isn't "urllib2" handling that? >>> >>> What does "urllib2" want? Percent escapes? Punycode? >>> >>> John Nagle >>> -- >>> http://mail.python.org/**mailman/listinfo/python-list >>> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > *'I am what I am because of who we all are'* > h3manth.com > *-- Hemanth HM * > -- *'I am what I am because of who we all are'* h3manth.com *-- Hemanth HM * -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrea.crotti.0 at gmail.com Wed Jun 13 11:45:20 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 13 Jun 2012 16:45:20 +0100 Subject: validating XML In-Reply-To: References: Message-ID: So as far as I understood what I should do is the following. Go through my own XML keeping track of the full path of everything for example and so on, then for every entry found in this iteration, check the schema to make sure that that particular construct is allowed on that level of the tree. I have something like this for example that creates a dictionary from an element tree element... Does it make sense or am I going in the wrong direction? def etree_to_dict(xml_file): """Takes the root node from the XML and generates a dictionary """ dic = {} etree = ElementTree.parse(open(xml_file)) root = list(etree.iter())[0] queue = [root] while queue: el = queue.pop() childs = el.getchildren() queue += childs dic[el] = childs return dic -------------- next part -------------- An HTML attachment was scrubbed... URL: From dieter at handshake.de Wed Jun 13 12:16:45 2012 From: dieter at handshake.de (Dieter Maurer) Date: Wed, 13 Jun 2012 18:16:45 +0200 Subject: validating XML References: Message-ID: <87boknuqz6.fsf@handshake.de> andrea crotti writes: > Hello Python friends, I have to validate some xml files against some xsd > schema files, but I can't use any cool library as libxml unfortunately. Why? It seems not very rational to implement a complex task (such as XML-Schema validation) when there are ready solutions around. > A Python-only validator might be also fine, but all the projects I've > seen are partial or seem dead.. > So since we define the schema ourselves, I was allowed to only implement > the parts of the huge XML definition that we actually need. > Now I'm not quite sure how to do the validation myself, any suggestions? I would look for a command line tool available on your platform which performs the validation and call this from Python. -- Dieter From rdsteph at mac.com Wed Jun 13 12:30:09 2012 From: rdsteph at mac.com (rdsteph at mac.com) Date: Wed, 13 Jun 2012 09:30:09 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <19e8593c-26ea-49c7-af76-01f85fa42387@t2g2000pbl.googlegroups.com> Message-ID: <6c928a7a-6ffb-48c4-b0c6-0715678cc0f8@tx6g2000pbc.googlegroups.com> > I think this is the wave of the furture for deploying simple programs > to many users. It is almost 100% cross platform (can be used on > desktop, smartphone, tablet, windows, linux, mac etc) and is very easy > to do, even for casual "non-programmers" who do a little programming > (such as many engineers). > > I think efforts to make a better, and more definitive, "GUI builder" > for Python should focus on makigng an easy to use "IDE" for creating > these kinds of Python-HTMl-Javascript front ends for applications. > > *That* would really help Python's popularity to take off and expode. > > Ron Stephens Replying to myself, to add this note: I just read the link likehacker.com/learn-to-code/ about Google's "Blockly" a drag and drop tool for building apps that outputs Python or Javascript code (among others) and it might be usable along these lines...I'm sure serious programmers would not use it but maybe engineers looking to make web front ends for data acquisition or data base apps might use it... From stefan_ml at behnel.de Wed Jun 13 13:11:04 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 13 Jun 2012 19:11:04 +0200 Subject: validating XML In-Reply-To: References: Message-ID: andrea crotti, 13.06.2012 12:06: > Hello Python friends, I have to validate some xml files against some xsd > schema files, but I can't use any cool library as libxml unfortunately. Any reason for that? Because the canonical answer to your question would be lxml, which uses libxml2. Stefan From invalid at invalid.invalid Wed Jun 13 13:38:25 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 13 Jun 2012 17:38:25 +0000 (UTC) Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <87r4tk25zs.fsf@dpt-info.u-strasbg.fr> <4fd84f51$0$11123$c3e8da3@news.astraweb.com> Message-ID: On 2012-06-13, Steven D'Aprano wrote: > On Tue, 12 Jun 2012 12:36:36 +0200, Gilles wrote: > >> I enjoy writing scripts in Python much more than PHP, but with so many >> sites written in PHP, I need to know what major benefits there are in >> choosing Python (or Ruby, ie. not PHP). > > The main benefit is that they are not PHP. > > http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ I just started learning PHP about a week ago in order to do some work on an embedded device's web site implementation my employer contracted out. I've done a fair bit of web stuff using CGI in shell, C, and Python as well as server-side Javascript. I've done a lot of normal application programming in C and Python and have used a smattering of other languages (Smalltalk, Scheme, Modula, FORTRAN, BASIC, assembly for a variety of processors, and even Prolog). I must say that I agree with the assessement of PHP linked above. It's not that the language has a design that's not to my taste -- it's that it has no design at all. It seems to be a mass of miscellaneous bits and bobs from other languages that have accreted over the years via some sort of random-walk process. PHP seems to encourage (if not require) bad practices such as returning values from functions via global or instance variables. -- Grant Edwards grant.b.edwards Yow! ! I'm in a very at clever and adorable INSANE gmail.com ASYLUM!! From rtomek at ceti.pl Wed Jun 13 14:00:48 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Wed, 13 Jun 2012 20:00:48 +0200 (CEST) Subject: which one do you prefer? python with C# or java? In-Reply-To: <20120612194104.GI372@mail.akwebsoft.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <20120612194104.GI372@mail.akwebsoft.com> Message-ID: On Tue, 12 Jun 2012, Tim Johnson wrote: > I concur, I worked in C and C++ for 12 years. I added C++ later in > my programming life. I don't recommend C++ for single programmers. > - that is to say - 1 coder for 1 codebase. One can do good enough > OOP in ansi C believe it or not, I learned to. > > It is interesting to note that most of linux is written in C, > rather than C++ and is not python as well? You are right, I remember this was explicitly stated somewhere on usenet that Linux kernel was written in object oriented style and AFAIK this is true (based on my own lurking into the source). But I think C++ could and should be used by solo programmers. I just suspect once we get past trivial stuff (defining class hierarchies, using iostreams, containers and STL and the like), things get a little tricky but I cannot say for sure because I am yet to go there. I probably agree C++ should not be used by solo progs writing very big programs, if this is what you mean. I am still researching alternatives, but for such endeavour I would rather choose Haskell or CL. However, I notice, for example, Boost C++ Library and their attempt to recreate some aspects of functional language. This gives me idea about what can be done in C++ - basically, the stuff is so powerfull it seems to almost reach into CL-reserved realms. With limitations, because it's different language, but still impressive for me. http://en.wikipedia.org/wiki/Boost_(C%2B%2B_libraries) http://www.boost.org/doc/libs/1_49_0/?view=category_Function-objects http://www.boost.org/doc/libs/1_49_0/doc/html/lambda.html http://www.boost.org/doc/libs/1_49_0/libs/bind/bind.html OTOH, I guess there are performance penalties. So, it boils down to individual's decision about pricing his own time or machine's time higher than another. Like, hand writing specially optimised versions of some functions or trying to lure compiler into generating them automatically (with templates). But, compilers are improving. In algorithmic contests, C++ is used quite a lot, from what I could see (and some people use Pascal, compile with Free Pascal Compiler, nice thing). BTW, Java folks trie(d|s) to go this way (templates etc) too, but I don't trace their efforts much, so cannot say how they fare(d). > > - Common Lisp - "nice industrial standard" (depends on one's preferred > > definition of "nice", of course, as well as "industrial" and "standard") > I took a hard look at Common Lisp at one time. I got the > impression that the "Common Lisp" is not to Lisp what Ansi C is to > C. > > IOWS, there does remain incompatibilities between different > Common Lisp implementations. Interesting. I play with CL for some time but haven't rammed this particular wall yet. Do you remember more about it? If you can't be specific, perhaps some hint will do. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From ramit.prasad at jpmorgan.com Wed Jun 13 14:01:23 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 13 Jun 2012 18:01:23 +0000 Subject: [newbie] Equivalent to PHP? In-Reply-To: <50qgt7lg5qpkm8nocs0c85uj72trnegh3t@4ax.com> References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> <50qgt7lg5qpkm8nocs0c85uj72trnegh3t@4ax.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D91511@SCACMX008.exchad.jpmchase.net> > Thanks for the longer explanation. With so many frameworks, I'd like > to know what benefits they offer as compared to writing an application > from scratch, and if they do offer obvious benefits, which one to pick I am going to state up front that I have never tried any of the frameworks so take my recommendation with a *lot* of salt! :) I would recommend Django as it seems to scale up nicely and I know that it has an active community which can be a godsend for getting help as a "newbie". That being said it does have a bit of a learning curve compared to some of the lighter frameworks, but not so much of one as to counteract the advantage of scalability. Again, this is all based on opinions that I have read (and remember) and not on any facts. Maybe this article will help you http://www.infoworld.com/d/application-development/pillars-python-six-python-web-frameworks-compared-169442 The comments on /. should round out anything missing from the article (I hope) http://developers.slashdot.org/story/11/08/10/2111203/six-python-web-frameworks-compared Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From lists at cheimes.de Wed Jun 13 14:33:39 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 13 Jun 2012 20:33:39 +0200 Subject: network protocols In-Reply-To: References: <4FD87C65.7060905@ziade.org> Message-ID: Am 13.06.2012 16:56, schrieb Christian Heimes: > Am 13.06.2012 13:41, schrieb Tarek Ziad?: >> Hey >> >> I was surprised not to find any way to list all protocol names listed in >> /etc/protocols in Python >> >> We have >> >> socket.getprotobyname(NAME) >> >> But there's no way to get the list of names >> >> Any ideas if this is available in the stdlib somehwere ? > > No, I can't find any reference to the relevant NSS APIs in the Python > code. You can easily roll your own with ctypes: PS: You can also parse the output of "getent protocols". As for all name services you shouldn't parse the file as other sources (ldap, dns, nis, databases) can provide additional information. See man nsswitch.conf Christian From tarek at ziade.org Wed Jun 13 14:58:28 2012 From: tarek at ziade.org (=?ISO-8859-1?Q?Tarek_Ziad=E9?=) Date: Wed, 13 Jun 2012 20:58:28 +0200 Subject: network protocols In-Reply-To: References: <4FD87C65.7060905@ziade.org> Message-ID: <4FD8E2D4.1090302@ziade.org> On 6/13/12 8:33 PM, Christian Heimes wrote: > Am 13.06.2012 16:56, schrieb Christian Heimes: >> Am 13.06.2012 13:41, schrieb Tarek Ziad?: >>> Hey >>> >>> I was surprised not to find any way to list all protocol names listed in >>> /etc/protocols in Python >>> >>> We have >>> >>> socket.getprotobyname(NAME) >>> >>> But there's no way to get the list of names >>> >>> Any ideas if this is available in the stdlib somehwere ? >> No, I can't find any reference to the relevant NSS APIs in the Python >> code. You can easily roll your own with ctypes: > PS: You can also parse the output of "getent protocols". As for all name > services you shouldn't parse the file as other sources (ldap, dns, nis, > databases) can provide additional information. See man nsswitch.conf > > Christian > Thanks for the pointers -- I was going to open('etc/protocols').readlines() :) From nospam at nospam.com Wed Jun 13 16:45:45 2012 From: nospam at nospam.com (Gilles) Date: Wed, 13 Jun 2012 22:45:45 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> <50qgt7lg5qpkm8nocs0c85uj72trnegh3t@4ax.com> Message-ID: On Wed, 13 Jun 2012 18:01:23 +0000, "Prasad, Ramit" wrote: >Maybe this article will help you http://www.infoworld.com/d/application-development/pillars-python-six-python-web-frameworks-compared-169442 >The comments on /. should round out anything missing from the article (I hope) >http://developers.slashdot.org/story/11/08/10/2111203/six-python-web-frameworks-compared Thanks for the links. From nospam at nospam.com Wed Jun 13 16:48:07 2012 From: nospam at nospam.com (Gilles) Date: Wed, 13 Jun 2012 22:48:07 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> Message-ID: <61vht7pcs4ks5fvp76gb2l5i62nk0noe4l@4ax.com> On Wed, 13 Jun 2012 17:27:21 +0200, Christian Heimes wrote: >A long running process has lots of benefits that makes design and >development easier and makes your app faster. Thanks much for the infos. Makes you wonder why commercial companies still choose PHP to write their web site. From bringa at gmail.com Wed Jun 13 16:55:06 2012 From: bringa at gmail.com (bringa at gmail.com) Date: Wed, 13 Jun 2012 13:55:06 -0700 (PDT) Subject: Pytz error: unpack requires a string argument of length 44 Message-ID: <43c40179-fcdb-4919-b912-d010eedb7726@googlegroups.com> Hi! I'm trying to get a handle on pytz (http://pytz.sourceforge.net/). I don't have root on the system I'll be running my script on, so I need to go for a local installation. I copied pytz into a folder in my sys.path and am importing from there. That part seems to work. I downloaded the tarball on http://pypi.python.org/pypi/pytz/#downloads So now I'm walking through the examples on http://pytz.sourceforge.net/#example-usage. This is what happens: Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from datetime import datetime, timedelta >>> from pytz import timezone >>> import pytz >>> utc = pytz.utc >>> utc.zone 'UTC' >>> eastern = timezone('US/Eastern') Traceback (most recent call last): File "", line 1, in File "C:\code\SoF\serversonfire\pytz\__init__.py", line 181, in timezone _tzinfo_cache[zone] = build_tzinfo(zone, fp) File "C:\code\SoF\serversonfire\pytz\tzfile.py", line 30, in build_tzinfo typecnt, charcnt) = unpack(head_fmt, fp.read(head_size)) error: unpack requires a string argument of length 44 Can anyone explain to me why that call fails? From lists at cheimes.de Wed Jun 13 17:16:31 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 13 Jun 2012 23:16:31 +0200 Subject: [newbie] Equivalent to PHP? In-Reply-To: <61vht7pcs4ks5fvp76gb2l5i62nk0noe4l@4ax.com> References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <61vht7pcs4ks5fvp76gb2l5i62nk0noe4l@4ax.com> Message-ID: Am 13.06.2012 22:48, schrieb Gilles: > On Wed, 13 Jun 2012 17:27:21 +0200, Christian Heimes > wrote: >> A long running process has lots of benefits that makes design and >> development easier and makes your app faster. > > Thanks much for the infos. Makes you wonder why commercial companies > still choose PHP to write their web site. PHP was developed for non-developers. (see http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ ). It's much easier and also cheaper to find bad coders and non-developers than code people. The outcome is bad performance and lots of security issues. Christian From tjreedy at udel.edu Wed Jun 13 17:43:46 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jun 2012 17:43:46 -0400 Subject: Pytz error: unpack requires a string argument of length 44 In-Reply-To: <43c40179-fcdb-4919-b912-d010eedb7726@googlegroups.com> References: <43c40179-fcdb-4919-b912-d010eedb7726@googlegroups.com> Message-ID: On 6/13/2012 4:55 PM, bringa at gmail.com wrote: > Hi! > > I'm trying to get a handle on pytz (http://pytz.sourceforge.net/). I don't have root on the system I'll be running my script on, so I need to go for a local installation. I copied pytz into a folder in my sys.path and am importing from there. That part seems to work. I downloaded the tarball on http://pypi.python.org/pypi/pytz/#downloads > > So now I'm walking through the examples on http://pytz.sourceforge.net/#example-usage. This is what happens: > > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > (InteractiveConsole) >>>> from datetime import datetime, timedelta >>>> from pytz import timezone >>>> import pytz >>>> utc = pytz.utc >>>> utc.zone > 'UTC' >>>> eastern = timezone('US/Eastern') > Traceback (most recent call last): > File "", line 1, in > File "C:\code\SoF\serversonfire\pytz\__init__.py", line 181, in timezone > _tzinfo_cache[zone] = build_tzinfo(zone, fp) > File "C:\code\SoF\serversonfire\pytz\tzfile.py", line 30, in build_tzinfo > typecnt, charcnt) = unpack(head_fmt, fp.read(head_size)) > error: unpack requires a string argument of length 44 > > > Can anyone explain to me why that call fails? 1. Either pytz has a bug, it was not installed correctly, or it does not work on windows. 2. If you read the module struct section of the fine manual, which you can easily find by typing 'unpack' on the Index tab of the Windows help version of the manual, it will tell you the following. Unpack takes two arguments, a format defining character fields of specifics lengths and a string whose length must be the sum of those lengths. (The contents of each field must also match the format spec, but you never got that far.) If there is a length mismatch, you get the message above. 3. In the specific case, we may presume that head_size is the sum of field lengths for head_fmt. (You could check; if not, that is a bug.) Since fp.read cannot read too many bytes, it must have read too little. ("Read up to n bytes from the object and return them.") You could look in C:\code\SoF\serversonfire\pytz\__init__.py and see what file fp is supposed to be and then take a look at the file. Is it empty? Is anything read before the statement that failer? -- Terry Jan Reedy From bringa at gmail.com Wed Jun 13 17:59:02 2012 From: bringa at gmail.com (bringa at gmail.com) Date: Wed, 13 Jun 2012 14:59:02 -0700 (PDT) Subject: Pytz error: unpack requires a string argument of length 44 In-Reply-To: References: <43c40179-fcdb-4919-b912-d010eedb7726@googlegroups.com> Message-ID: <29296dc4-6298-4f1c-a4c3-7166eedacbd3@googlegroups.com> Thanks Terry! There indeed seems to be something wrong with my installation of pytz. I had a look around the zoneinfo dir, which is where build_tzinfo polls its info from, and a whole bunch of files are 0 bytes. Whenever I try to instantiate a timezone whose corresponding file is 0 bytes I get that error (it's trying to read the head of the tzinfo file to make sure the right magic bytes are in there, and reading 44 bytes out of a 0 byte file isn't going to work). So I guess I'll poke around to find some specific help with pytz or a non-broken zoneinfo dir. On Wednesday, June 13, 2012 10:43:46 PM UTC+1, Terry Reedy wrote: > On 6/13/2012 4:55 PM, I wrote: > > Hi! > > > > I'm trying to get a handle on pytz (http://pytz.sourceforge.net/). I don't have root on the system I'll be running my script on, so I need to go for a local installation. I copied pytz into a folder in my sys.path and am importing from there. That part seems to work. I downloaded the tarball on http://pypi.python.org/pypi/pytz/#downloads > > > > So now I'm walking through the examples on http://pytz.sourceforge.net/#example-usage. This is what happens: > > > > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > (InteractiveConsole) > >>>> from datetime import datetime, timedelta > >>>> from pytz import timezone > >>>> import pytz > >>>> utc = pytz.utc > >>>> utc.zone > > 'UTC' > >>>> eastern = timezone('US/Eastern') > > Traceback (most recent call last): > > File "", line 1, in > > File "C:\code\SoF\serversonfire\pytz\__init__.py", line 181, in timezone > > _tzinfo_cache[zone] = build_tzinfo(zone, fp) > > File "C:\code\SoF\serversonfire\pytz\tzfile.py", line 30, in build_tzinfo > > typecnt, charcnt) = unpack(head_fmt, fp.read(head_size)) > > error: unpack requires a string argument of length 44 > > > > > > Can anyone explain to me why that call fails? > > 1. Either pytz has a bug, it was not installed correctly, or it does not > work on windows. > > 2. If you read the module struct section of the fine manual, which you > can easily find by typing 'unpack' on the Index tab of the Windows help > version of the manual, it will tell you the following. Unpack takes two > arguments, a format defining character fields of specifics lengths and a > string whose length must be the sum of those lengths. (The contents of > each field must also match the format spec, but you never got that far.) > If there is a length mismatch, you get the message above. > > 3. In the specific case, we may presume that head_size is the sum of > field lengths for head_fmt. (You could check; if not, that is a bug.) > Since fp.read cannot read too many bytes, it must have read too little. > ("Read up to n bytes from the object and return them.") > > You could look in > C:\code\SoF\serversonfire\pytz\__init__.py > and see what file fp is supposed to be and then take a look at the file. > Is it empty? Is anything read before the statement that failer? > > -- > Terry Jan Reedy From bringa at gmail.com Wed Jun 13 17:59:02 2012 From: bringa at gmail.com (bringa at gmail.com) Date: Wed, 13 Jun 2012 14:59:02 -0700 (PDT) Subject: Pytz error: unpack requires a string argument of length 44 In-Reply-To: References: <43c40179-fcdb-4919-b912-d010eedb7726@googlegroups.com> Message-ID: <29296dc4-6298-4f1c-a4c3-7166eedacbd3@googlegroups.com> Thanks Terry! There indeed seems to be something wrong with my installation of pytz. I had a look around the zoneinfo dir, which is where build_tzinfo polls its info from, and a whole bunch of files are 0 bytes. Whenever I try to instantiate a timezone whose corresponding file is 0 bytes I get that error (it's trying to read the head of the tzinfo file to make sure the right magic bytes are in there, and reading 44 bytes out of a 0 byte file isn't going to work). So I guess I'll poke around to find some specific help with pytz or a non-broken zoneinfo dir. On Wednesday, June 13, 2012 10:43:46 PM UTC+1, Terry Reedy wrote: > On 6/13/2012 4:55 PM, I wrote: > > Hi! > > > > I'm trying to get a handle on pytz (http://pytz.sourceforge.net/). I don't have root on the system I'll be running my script on, so I need to go for a local installation. I copied pytz into a folder in my sys.path and am importing from there. That part seems to work. I downloaded the tarball on http://pypi.python.org/pypi/pytz/#downloads > > > > So now I'm walking through the examples on http://pytz.sourceforge.net/#example-usage. This is what happens: > > > > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > (InteractiveConsole) > >>>> from datetime import datetime, timedelta > >>>> from pytz import timezone > >>>> import pytz > >>>> utc = pytz.utc > >>>> utc.zone > > 'UTC' > >>>> eastern = timezone('US/Eastern') > > Traceback (most recent call last): > > File "", line 1, in > > File "C:\code\SoF\serversonfire\pytz\__init__.py", line 181, in timezone > > _tzinfo_cache[zone] = build_tzinfo(zone, fp) > > File "C:\code\SoF\serversonfire\pytz\tzfile.py", line 30, in build_tzinfo > > typecnt, charcnt) = unpack(head_fmt, fp.read(head_size)) > > error: unpack requires a string argument of length 44 > > > > > > Can anyone explain to me why that call fails? > > 1. Either pytz has a bug, it was not installed correctly, or it does not > work on windows. > > 2. If you read the module struct section of the fine manual, which you > can easily find by typing 'unpack' on the Index tab of the Windows help > version of the manual, it will tell you the following. Unpack takes two > arguments, a format defining character fields of specifics lengths and a > string whose length must be the sum of those lengths. (The contents of > each field must also match the format spec, but you never got that far.) > If there is a length mismatch, you get the message above. > > 3. In the specific case, we may presume that head_size is the sum of > field lengths for head_fmt. (You could check; if not, that is a bug.) > Since fp.read cannot read too many bytes, it must have read too little. > ("Read up to n bytes from the object and return them.") > > You could look in > C:\code\SoF\serversonfire\pytz\__init__.py > and see what file fp is supposed to be and then take a look at the file. > Is it empty? Is anything read before the statement that failer? > > -- > Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed Jun 13 18:16:51 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Jun 2012 22:16:51 GMT Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> <50qgt7lg5qpkm8nocs0c85uj72trnegh3t@4ax.com> Message-ID: <4fd91153$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Jun 2012 12:17:12 +0200, Gilles wrote: > Thanks for the longer explanation. With so many frameworks, I'd like to > know what benefits they offer as compared to writing an application from > scratch Surely the obvious answer is that a framework offers the benefit that you don't have to write the application from scratch. Why write in Python instead of creating your application from scratch written in assembly? Because you get the benefit of 40+ years of collective programming language design experience, 10+ years of collective Python experience, tens or hundreds of thousands of lines of carefully debugged and tuned code, and a large community of users with experience in the language, books, training courses, etc. whom you can call on for advice (free or paid consulting) and as a pool of would-be employees if you need to hire developers. You wouldn't (or at least shouldn't) even *consider* writing your own language unless you had really good reason, and no other existing language would do. Web frameworks are similar: you get tens or hundreds of thousands of lines of carefully debugged and tuned code, and a community of users, books, etc. Unless your needs are minuscule, writing your application from scratch will end up duplicating much of the framework, only (let's be realistic here) badly. By the time your application is as stable, debugged and tuned as as existing framework, you will have spent probably in excess of ten person-years. At which point, you have a community of one, yourself. (Or possibly you and a handful of your fellow project members.) For anything but the smallest web applications, where no framework is necessary, and the very largest, if no existing framework will do, why would you even consider reinventing the wheel? -- Steven From ramit.prasad at jpmorgan.com Wed Jun 13 18:25:28 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 13 Jun 2012 22:25:28 +0000 Subject: Pytz error: unpack requires a string argument of length 44 In-Reply-To: <29296dc4-6298-4f1c-a4c3-7166eedacbd3@googlegroups.com> References: <43c40179-fcdb-4919-b912-d010eedb7726@googlegroups.com> <29296dc4-6298-4f1c-a4c3-7166eedacbd3@googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D9258B@SCACMX008.exchad.jpmchase.net> > There indeed seems to be something wrong with my installation of pytz. I had a > look around the zoneinfo dir, which is where build_tzinfo polls its info from, > and a whole bunch of files are 0 bytes. Whenever I try to instantiate a > timezone whose corresponding file is 0 bytes I get that error (it's trying to > read the head of the tzinfo file to make sure the right magic bytes are in > there, and reading 44 bytes out of a 0 byte file isn't going to work). > > So I guess I'll poke around to find some specific help with pytz or a non- > broken zoneinfo dir. Did you follow the installation instructions located on the front page? I would unpack the tarball (not in a Python directory) and then do `python setup.py install` (use the full path to the executable you want the module installed to if you have more than one version of Python installed) from the directory with the unpacked contents of the tarball. I did not need admin rights to manually install on Windows, but that might depend on where your Python is installed. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From howmuchistoday at gmail.com Wed Jun 13 18:33:55 2012 From: howmuchistoday at gmail.com (Yesterday Paid) Date: Wed, 13 Jun 2012 15:33:55 -0700 (PDT) Subject: When adding my application to Windows right-click menu Message-ID: <36f21cb7-8ffd-4143-a43a-707170b55f10@ra8g2000pbc.googlegroups.com> I made a cipher app but to make easy, I want to make it Windows rightclick menu can execute it I found the way with dealing with Registry [HKEY_CLASSES_ROOT\Directory\Background\shell\app] [HKEY_CLASSES_ROOT\Directory\Background\shell\app\command] @="C;\myapp filelocation" but I don't know how to automatically get filelocation Can I get the address of file that I right_clicked(it's not a proper expression maybe) From nospam at nospam.com Wed Jun 13 18:44:23 2012 From: nospam at nospam.com (Gilles) Date: Thu, 14 Jun 2012 00:44:23 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> <50qgt7lg5qpkm8nocs0c85uj72trnegh3t@4ax.com> <4fd91153$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 13 Jun 2012 22:16:51 GMT, Steven D'Aprano wrote: >Surely the obvious answer is that a framework offers the benefit that you >don't have to write the application from scratch. Yes, but between receiving the query and sending the response, what features do frameworks offer that I'd have to write myself otherwise? From nospam at nospam.com Wed Jun 13 18:45:21 2012 From: nospam at nospam.com (Gilles) Date: Thu, 14 Jun 2012 00:45:21 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <61vht7pcs4ks5fvp76gb2l5i62nk0noe4l@4ax.com> Message-ID: On Wed, 13 Jun 2012 23:16:31 +0200, Christian Heimes wrote: >PHP was developed for non-developers. (see >http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ ). >It's much easier and also cheaper to find bad coders and non-developers >than code people. The outcome is bad performance and lots of security >issues. And as to why Facebook chose PHP... From ramit.prasad at jpmorgan.com Wed Jun 13 19:12:37 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 13 Jun 2012 23:12:37 +0000 Subject: [newbie] Equivalent to PHP? In-Reply-To: References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <61vht7pcs4ks5fvp76gb2l5i62nk0noe4l@4ax.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D93650@SCACMX008.exchad.jpmchase.net> > >PHP was developed for non-developers. (see > >http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ ). > >It's much easier and also cheaper to find bad coders and non-developers > >than code people. The outcome is bad performance and lots of security > >issues. > > And as to why Facebook chose PHP... You are not Facebook (at least yet). They also choose to transform PHP into C++ for performance reasons. Not something the average large website would want to do. http://www.sdtimes.com/blog/post/2010/01/30/Facebook-rewrites-PHP-runtime.aspx http://www.datacenterknowledge.com/the-facebook-data-center-faq-page-2/ The real question is would they use it again if they were to start over? http://www.quora.com/Quora-Infrastructure/Why-did-Quora-choose-Python-for-its-development These decisions are influenced by a multitude of factors 1. familiarity/popularity of a framework 2. support 3. what someone thinks is "best" for specifications 4. cost Notice only 1 of those factors was what was actually "best". Also remember you asked this on a *Python* mailing list. I am sure you will get different responses on a PHP mailing list. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From ramit.prasad at jpmorgan.com Wed Jun 13 19:17:57 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Wed, 13 Jun 2012 23:17:57 +0000 Subject: When adding my application to Windows right-click menu In-Reply-To: <36f21cb7-8ffd-4143-a43a-707170b55f10@ra8g2000pbc.googlegroups.com> References: <36f21cb7-8ffd-4143-a43a-707170b55f10@ra8g2000pbc.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D93662@SCACMX008.exchad.jpmchase.net> > I made a cipher app but to make easy, I want to make it Windows > rightclick menu can execute it > I found the way with dealing with Registry > > > [HKEY_CLASSES_ROOT\Directory\Background\shell\app] > [HKEY_CLASSES_ROOT\Directory\Background\shell\app\command] > @="C;\myapp filelocation" > > > but I don't know how to automatically get filelocation > Can I get the address of file that I right_clicked(it's not a proper > expression maybe) This is not a Python question... This might help http://www.velocityreviews.com/forums/t229799-how-to-add-a-program-to-the-open-with-right-click-menu.html There is a way to do it via registry but I cannot find the link, but essentially it should have a string like c:\Python\python.exe %1 where %1 is the file being currently selected (cipher app module). Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From nospam at nospam.com Wed Jun 13 19:36:12 2012 From: nospam at nospam.com (Gilles) Date: Thu, 14 Jun 2012 01:36:12 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <61vht7pcs4ks5fvp76gb2l5i62nk0noe4l@4ax.com> Message-ID: On Wed, 13 Jun 2012 23:12:37 +0000, "Prasad, Ramit" wrote: >You are not Facebook (at least yet). Indeed, but with so much criticism about PHP, it's odd that they would still choose it. Anyway, thanks much for the infos. I'll look at the web frameworks and how to connect the Python app to a front-end web server. From bobtnur78 at gmail.com Wed Jun 13 19:44:22 2012 From: bobtnur78 at gmail.com (bob) Date: Wed, 13 Jun 2012 23:44:22 +0000 (UTC) Subject: consecutive node sequence and pathlength problem using networkx graph Message-ID: Let say,I have a conjugated cyclic polygon and its nodes are given by the list: list_p=[a,b,c,d,e,f,g,a,a,b,d,d,d,d,d,c,c,e,e,a,d,d,g]. If X & Y are any elements in a list_p except d, and Z is also an element of list_p but has value only d, i.e, Z=d. Now,I want to compute the number of paths with sequence X-Z- Y consecutive nodes, example: a-d-d-e,a-d-d-a, a-d-d-d-g, etc. Consecutive path length of Z can be 1,2,3,4 or 5. To generalize: Find total number of paths with consecutive X-Z-Y sequence for path length of z within range(1,6): or (i) X-Z-Y for len(Z)=1 (ii) X-Z-Y for len(Z)=2 (iii)X-Z-Y for len(Z)=3 (iv) X-Z-Y for len(Z)=4 (v) X-Z-Y for len(Z)=5 Is there any easy way to program this using python networkx or igraph? From python.list at tim.thechases.com Wed Jun 13 20:03:29 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 13 Jun 2012 19:03:29 -0500 Subject: [newbie] Equivalent to PHP? In-Reply-To: References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> <50qgt7lg5qpkm8nocs0c85uj72trnegh3t@4ax.com> <4fd91153$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FD92A51.8000403@tim.thechases.com> On 06/13/12 17:44, Gilles wrote: > On 13 Jun 2012 22:16:51 GMT, Steven D'Aprano > wrote: >> Surely the obvious answer is that a framework offers the benefit that you >> don't have to write the application from scratch. > > Yes, but between receiving the query and sending the response, what > features do frameworks offer that I'd have to write myself otherwise? Let's see - CRSF protection - keeping things DRY - templating (or you could use many others) - user management - administrative interface - database creation/introspection - i18n - an ecosystem of pluggable add-on apps - URL routing - view decorators - easily swappable back-ends - active development across multiple lines of business - GIS support - abstracted ORM (or you could use SQLObject or its kin) to allow you mobility between DB back-ends should you want to That's just my off-the-top-of-my-head list of things that you'd have to come up with that Django happens to give you out-of-the-box. -tkc From steve+comp.lang.python at pearwood.info Wed Jun 13 20:08:57 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Jun 2012 00:08:57 GMT Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> <50qgt7lg5qpkm8nocs0c85uj72trnegh3t@4ax.com> <4fd91153$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4fd92b99$0$1701$c3e8da3$76491128@news.astraweb.com> On Thu, 14 Jun 2012 00:44:23 +0200, Gilles wrote: > On 13 Jun 2012 22:16:51 GMT, Steven D'Aprano > wrote: >>Surely the obvious answer is that a framework offers the benefit that >>you don't have to write the application from scratch. > > Yes, but between receiving the query and sending the response, what > features do frameworks offer that I'd have to write myself otherwise? What, google broken for you? *wink* Copied and pasted from http://cherrypy.org/ FEATURES A fast, HTTP/1.1-compliant, WSGI thread-pooled webserver. Easy to run multiple HTTP servers (e.g. on multiple ports) at once. A powerful configuration system for developers and deployers alike. A flexible plugin system. Built-in tools for caching, encoding, sessions, authorization, static content, and many more. Swappable and customizable...everything. Built-in profiling, coverage, and testing support. Runs on Python 2.5+, 3.1+, Jython and Android. Plus you have a whole community of people working on the framework, fixing bugs and writing documentation, and you don't have to pay them a cent. http://duckduckgo.com/?q=cherrypy+features Repeat as needed for any other framework you are interested in. Essentially, using a framework means you get to concentrate on the actual problem your application is meant to solve instead of spending most of your time worrying about building the infrastructure (the framework!) to hold your application. -- Steven From ramit.prasad at jpmorgan.com Wed Jun 13 20:25:02 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 14 Jun 2012 00:25:02 +0000 Subject: [newbie] Equivalent to PHP? In-Reply-To: References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <61vht7pcs4ks5fvp76gb2l5i62nk0noe4l@4ax.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D9373F@SCACMX008.exchad.jpmchase.net> > Indeed, but with so much criticism about PHP, it's odd that they would > still choose it. Could be a familiarity/ease issue as it was originally started by a college student (and college students seldom have meaningful real world experience) before it exploded in size. Also do not forget that it was developed nearly a decade ago and technology has changed (hopefully improved) a lot since then. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From bringa at gmail.com Wed Jun 13 21:05:12 2012 From: bringa at gmail.com (Daniel Klein) Date: Wed, 13 Jun 2012 18:05:12 -0700 (PDT) Subject: Pytz error: unpack requires a string argument of length 44 In-Reply-To: References: <43c40179-fcdb-4919-b912-d010eedb7726@googlegroups.com> <29296dc4-6298-4f1c-a4c3-7166eedacbd3@googlegroups.com> Message-ID: <59e26be3-9312-4395-ab48-e33f37b78486@googlegroups.com> The windows box is my development box, it's not where the script will be running in the end. It'll be running on a Linux box where I don't have root so python setup.py install isn't an option (to my understanding). So what happened is that 7zip didn't unzip the .tar.gz2 properly, but it does fine with the .zip from the Python Package Index. Using the zoneinfo from the properly unzipped file everything works. Thanks everyone, consider this solved. On Wednesday, June 13, 2012 11:25:28 PM UTC+1, Prasad, Ramit wrote: > > There indeed seems to be something wrong with my installation of pytz. I had a > > look around the zoneinfo dir, which is where build_tzinfo polls its info from, > > and a whole bunch of files are 0 bytes. Whenever I try to instantiate a > > timezone whose corresponding file is 0 bytes I get that error (it's trying to > > read the head of the tzinfo file to make sure the right magic bytes are in > > there, and reading 44 bytes out of a 0 byte file isn't going to work). > > > > So I guess I'll poke around to find some specific help with pytz or a non- > > broken zoneinfo dir. > > Did you follow the installation instructions located on the front page? > > I would unpack the tarball (not in a Python directory) and then do > `python setup.py install` (use the full path to the executable you want > the module installed to if you have more than one version of Python installed) > from the directory with the unpacked contents of the tarball. I did not need > admin rights to manually install on Windows, but that might depend on > where your Python is installed. > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > -- > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. From bringa at gmail.com Wed Jun 13 21:05:12 2012 From: bringa at gmail.com (Daniel Klein) Date: Wed, 13 Jun 2012 18:05:12 -0700 (PDT) Subject: Pytz error: unpack requires a string argument of length 44 In-Reply-To: References: <43c40179-fcdb-4919-b912-d010eedb7726@googlegroups.com> <29296dc4-6298-4f1c-a4c3-7166eedacbd3@googlegroups.com> Message-ID: <59e26be3-9312-4395-ab48-e33f37b78486@googlegroups.com> The windows box is my development box, it's not where the script will be running in the end. It'll be running on a Linux box where I don't have root so python setup.py install isn't an option (to my understanding). So what happened is that 7zip didn't unzip the .tar.gz2 properly, but it does fine with the .zip from the Python Package Index. Using the zoneinfo from the properly unzipped file everything works. Thanks everyone, consider this solved. On Wednesday, June 13, 2012 11:25:28 PM UTC+1, Prasad, Ramit wrote: > > There indeed seems to be something wrong with my installation of pytz. I had a > > look around the zoneinfo dir, which is where build_tzinfo polls its info from, > > and a whole bunch of files are 0 bytes. Whenever I try to instantiate a > > timezone whose corresponding file is 0 bytes I get that error (it's trying to > > read the head of the tzinfo file to make sure the right magic bytes are in > > there, and reading 44 bytes out of a 0 byte file isn't going to work). > > > > So I guess I'll poke around to find some specific help with pytz or a non- > > broken zoneinfo dir. > > Did you follow the installation instructions located on the front page? > > I would unpack the tarball (not in a Python directory) and then do > `python setup.py install` (use the full path to the executable you want > the module installed to if you have more than one version of Python installed) > from the directory with the unpacked contents of the tarball. I did not need > admin rights to manually install on Windows, but that might depend on > where your Python is installed. > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > -- > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. From bruceg113355 at gmail.com Wed Jun 13 22:29:44 2012 From: bruceg113355 at gmail.com (bruce g) Date: Wed, 13 Jun 2012 19:29:44 -0700 (PDT) Subject: string to list Message-ID: What is the best way to parse a CSV string to a list? For example, how do I parse: 'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG' to get: ['AAA','BBB,CCC,DDDD','EEE','FFF','GGG?] Thanks, Bruce From clp2 at rebertia.com Wed Jun 13 22:53:44 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 13 Jun 2012 19:53:44 -0700 Subject: string to list In-Reply-To: References: Message-ID: n Wed, Jun 13, 2012 at 7:29 PM, bruce g wrote: > What is the best way to parse a CSV string to a list? Use the `csv` module: http://docs.python.org/library/csv.html http://www.doughellmann.com/PyMOTW/csv/ The `StringIO` module can be used to wrap your string as a file-like object for consumption by the `csv` module: http://docs.python.org/library/stringio.html Cheers, Chris From tjreedy at udel.edu Wed Jun 13 23:38:18 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 13 Jun 2012 23:38:18 -0400 Subject: [newbie] Equivalent to PHP? In-Reply-To: References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <61vht7pcs4ks5fvp76gb2l5i62nk0noe4l@4ax.com> Message-ID: On 6/13/2012 6:45 PM, Gilles wrote: > On Wed, 13 Jun 2012 23:16:31 +0200, Christian Heimes > wrote: >> PHP was developed for non-developers. (see >> http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ ). >> It's much easier and also cheaper to find bad coders and non-developers >> than code people. The outcome is bad performance and lots of security >> issues. > > And as to why Facebook chose PHP... *When* did 'Facebook' choose it? (My brief search did not reveal this.) Facebook started as a quick hack (Facemash) by student Mark Zuckerberg in Nov 2003. If he used PHP (1995) then or for his next site or for the initial Facebook a few months later, that would suggest an answer. -- Terry Jan Reedy From josehmartinezz at gmail.com Thu Jun 14 00:06:50 2012 From: josehmartinezz at gmail.com (Jose H. Martinez) Date: Thu, 14 Jun 2012 00:06:50 -0400 Subject: string to list In-Reply-To: References: Message-ID: string.split(',') will give you an array. Example: 'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG '.split(',') ['AAA', '"BBBB', 'CCCC', 'DDDD"', 'EEE', 'FFF', 'GGG'] On Wed, Jun 13, 2012 at 10:53 PM, Chris Rebert wrote: > n Wed, Jun 13, 2012 at 7:29 PM, bruce g wrote: > > What is the best way to parse a CSV string to a list? > > Use the `csv` module: > http://docs.python.org/library/csv.html > http://www.doughellmann.com/PyMOTW/csv/ > > The `StringIO` module can be used to wrap your string as a file-like > object for consumption by the `csv` module: > http://docs.python.org/library/stringio.html > > Cheers, > Chris > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Thu Jun 14 00:53:03 2012 From: nagle at animats.com (John Nagle) Date: Wed, 13 Jun 2012 21:53:03 -0700 Subject: Internationalized domain names not working with URLopen In-Reply-To: References: Message-ID: On 6/12/2012 11:42 PM, Andrew Berg wrote: > On 6/13/2012 1:17 AM, John Nagle wrote: >> What does "urllib2" want? Percent escapes? Punycode? > Looks like Punycode is the correct answer: > https://en.wikipedia.org/wiki/Internationalized_domain_name#ToASCII_and_ToUnicode > > I haven't tried it, though. This is Python bug #9679: http://bugs.python.org/issue9679 It's been open for years, and the maintainers offer elaborate excuses for not fixing the problem. The socket module accepts Unicode domains, as does httplib. But urllib2, which is a front end to both, is still broken. It's failing when it constructs the HTTP headers. Domains in HTTP headers have to be in punycode. The code in stackoverflow doesn't really work right. Only the domain part of a URL should be converted to punycode. Path, port, and query parameters need to be converted to percent-encoding. (Unclear if urllib2 or httplib does this already. The documentation doesn't say.) While HTTP content can be in various character sets, the headers are currently required to be ASCII only, since the header has to be processed to determine the character code. (http://lists.w3.org/Archives/Public/ietf-http-wg/2011OctDec/0155.html) Here's a workaround, for the domain part only. # # idnaurlworkaround -- workaround for Python defect 9679 # PYTHONDEFECT9679FIXED = False # Python defect #9679 - change when fixed def idnaurlworkaround(url) : """ Convert a URL to a form the currently broken urllib2 will accept. Converts the domain to "punycode" if necessary. This is a workaround for Python defect #9679. """ if PYTHONDEFECT9679FIXED : # if defect fixed return(url) # use unmodified URL url = unicode(url) # force to Unicode (scheme, accesshost, path, params, query, fragment) = urlparse.urlparse(url) # parse URL if scheme == '' and accesshost == '' and path != '' : # bare domain accesshost = path # use path as access host path = '' # no path labels = accesshost.split('.') # split domain into sections ("labels") labels = [encodings.idna.ToASCII(w) for w in labels]# convert each label to punycode if necessary accesshost = '.'.join(labels) # reassemble domain url = urlparse.urlunparse((scheme, accesshost, path, params, query, fragment)) # reassemble url return(url) # return complete URL with punycode domain John Nagle From ian.g.kelly at gmail.com Thu Jun 14 01:10:20 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jun 2012 23:10:20 -0600 Subject: string to list In-Reply-To: References: Message-ID: On Wed, Jun 13, 2012 at 10:06 PM, Jose H. Martinez wrote: > string.split(',') will give you an array. > > Example: > > 'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG?'.split(',') > > ['AAA', '"BBBB', 'CCCC', 'DDDD"', 'EEE', 'FFF', 'GGG'] But it incorrectly splits the quoted part. A proper CSV parser (like the csv module) should leave that part as a single string, even though it contains commas. From kushal.kumaran+python at gmail.com Thu Jun 14 02:39:09 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 14 Jun 2012 12:09:09 +0530 Subject: Pytz error: unpack requires a string argument of length 44 In-Reply-To: <59e26be3-9312-4395-ab48-e33f37b78486@googlegroups.com> References: <43c40179-fcdb-4919-b912-d010eedb7726@googlegroups.com> <29296dc4-6298-4f1c-a4c3-7166eedacbd3@googlegroups.com> <59e26be3-9312-4395-ab48-e33f37b78486@googlegroups.com> Message-ID: On Thu, Jun 14, 2012 at 6:35 AM, Daniel Klein wrote: > The windows box is my development box, it's not where the script will be running in the end. It'll be running on a Linux box where I don't have root so python setup.py install isn't an option (to my understanding). > You might want to use virtualenv for this: http://pypi.python.org/pypi/virtualenv > So what happened is that 7zip didn't unzip the .tar.gz2 properly, but it does fine with the .zip from the Python Package Index. Using the zoneinfo from the properly unzipped file everything works. > -- regards, kushal From Shambhu.Rajak at kpitcummins.com Thu Jun 14 02:58:12 2012 From: Shambhu.Rajak at kpitcummins.com (Shambhu Rajak) Date: Thu, 14 Jun 2012 06:58:12 +0000 Subject: string to list In-Reply-To: References: Message-ID: <408F64D89899604FB24015E64E10490C3B7AE15E@KCHJEXMB02.kpit.com> This will do you job: >>> a = 'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG' >>> b = [] >>> for x in a.split(','): ... if (x.find("\"") > -1): ... x = x.strip("\"") ... b.append(x) If you want reduce the lines of code u can go for this option: b = [x.strip("\"") for x in a.split(',')] So Just Cheerz, -Shambhu -----Original Message----- From: bruce g [mailto:bruceg113355 at gmail.com] Sent: 14/06/2012 8:00 AM To: python-list at python.org Subject: string to list What is the best way to parse a CSV string to a list? For example, how do I parse: 'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG' to get: ['AAA','BBB,CCC,DDDD','EEE','FFF','GGG'] Thanks, Bruce From __peter__ at web.de Thu Jun 14 03:19:19 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Jun 2012 09:19:19 +0200 Subject: string to list References: Message-ID: bruce g wrote: > What is the best way to parse a CSV string to a list? > > For example, how do I parse: > 'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG' > to get: > ['AAA','BBB,CCC,DDDD','EEE','FFF','GGG?] >>> import csv >>> next(csv.reader(['AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG'])) ['AAA', 'BBBB,CCCC,DDDD', 'EEE', 'FFF', 'GGG'] For multiple records: list(csv.reader(text.splitlines(True))) From atmb4u at gmail.com Thu Jun 14 03:28:15 2012 From: atmb4u at gmail.com (Anoop Thomas Mathew) Date: Thu, 14 Jun 2012 12:58:15 +0530 Subject: string to list In-Reply-To: <408F64D89899604FB24015E64E10490C3B7AE15E@KCHJEXMB02.kpit.com> References: <408F64D89899604FB24015E64E10490C3B7AE15E@KCHJEXMB02.kpit.com> Message-ID: Hi, You can use literal_eval from ast package. >>> from ast import literal_eval >>> list(literal_eval("'aa','bb','cc'") this will return ['aa', 'bb', 'cc'] Thanks, Anoop Thomas Mathew atm ___ Life is short, Live it hard. On 14 June 2012 12:28, Shambhu Rajak wrote: > This will do you job: > > >>> a = 'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG' > >>> b = [] > >>> for x in a.split(','): > ... if (x.find("\"") > -1): > ... x = x.strip("\"") > ... b.append(x) > > If you want reduce the lines of code u can go for this option: > b = [x.strip("\"") for x in a.split(',')] > > > So Just Cheerz, > -Shambhu > > -----Original Message----- > From: bruce g [mailto:bruceg113355 at gmail.com] > Sent: 14/06/2012 8:00 AM > To: python-list at python.org > Subject: string to list > > What is the best way to parse a CSV string to a list? > > For example, how do I parse: > 'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG' > to get: > ['AAA','BBB,CCC,DDDD','EEE','FFF','GGG'] > > Thanks, > Bruce > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hemanth.hm at gmail.com Thu Jun 14 03:39:20 2012 From: hemanth.hm at gmail.com (Hemanth H.M) Date: Thu, 14 Jun 2012 13:09:20 +0530 Subject: string to list In-Reply-To: References: <408F64D89899604FB24015E64E10490C3B7AE15E@KCHJEXMB02.kpit.com> Message-ID: @Annop Nice one, but you seem to have missed a parenthesis. >>> list(literal_eval("'aa','bb','cc'") should have been >>> list(literal_eval("'aa','bb','cc'")) On Thu, Jun 14, 2012 at 12:58 PM, Anoop Thomas Mathew wrote: > >>> list(literal_eval("'aa','bb','cc'") -- *'I am what I am because of who we all are'* h3manth.com *-- Hemanth HM * -------------- next part -------------- An HTML attachment was scrubbed... URL: From hemanth.hm at gmail.com Thu Jun 14 03:40:33 2012 From: hemanth.hm at gmail.com (Hemanth H.M) Date: Thu, 14 Jun 2012 13:10:33 +0530 Subject: string to list In-Reply-To: References: <408F64D89899604FB24015E64E10490C3B7AE15E@KCHJEXMB02.kpit.com> Message-ID: >>> list(literal_eval('"aa","bb 'b'","cc"')) ['aa', 'bb ', 'cc'] Strange? On Thu, Jun 14, 2012 at 1:09 PM, Hemanth H.M wrote: > @Annop Nice one, but you seem to have missed a parenthesis. > > >>> list(literal_eval("'aa','bb','cc'") should have been >>> > list(literal_eval("'aa','bb','cc'")) > > > On Thu, Jun 14, 2012 at 12:58 PM, Anoop Thomas Mathew wrote: > >> >>> list(literal_eval("'aa','bb','cc'") > > > > > -- > *'I am what I am because of who we all are'* > h3manth.com > *-- Hemanth HM * > -- *'I am what I am because of who we all are'* h3manth.com *-- Hemanth HM * -------------- next part -------------- An HTML attachment was scrubbed... URL: From atmb4u at gmail.com Thu Jun 14 03:44:01 2012 From: atmb4u at gmail.com (Anoop Thomas Mathew) Date: Thu, 14 Jun 2012 13:14:01 +0530 Subject: string to list In-Reply-To: References: <408F64D89899604FB24015E64E10490C3B7AE15E@KCHJEXMB02.kpit.com> Message-ID: @group: Sorry for the mistake. @Hemanth: Thank You for pointing out. I just realized that, we should not copy paste from the console. :) atm ___ Life is short, Live it hard. On 14 June 2012 13:09, Hemanth H.M wrote: > @Annop Nice one, but you seem to have missed a parenthesis. > > >>> list(literal_eval("'aa','bb','cc'") should have been >>> > list(literal_eval("'aa','bb','cc'")) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Thu Jun 14 04:06:18 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 14 Jun 2012 01:06:18 -0700 Subject: string to list In-Reply-To: References: <408F64D89899604FB24015E64E10490C3B7AE15E@KCHJEXMB02.kpit.com> Message-ID: On Thu, Jun 14, 2012 at 12:40 AM, Hemanth H.M wrote: >>>> list(literal_eval('"aa","bb 'b'","cc"')) > ['aa', 'bb ', 'cc'] > > Strange? Not really. You didn't properly escape the embedded quotation marks in the string itself! So before anything ever even gets passed to literal_eval(), that part is parsed as two adjacent literals: '"aa","bb ' and b'","cc"' In Python 3.x, the "b" prefix indicates a `bytes` literal rather than a `str` literal. Implicit adjacent string literal concatenation then occurs. Thus: >>> print '"aa","bb ' b'","cc"' "aa","bb ","cc" Compare: >>> print '''"aa","bb 'b'","cc"''' "aa","bb 'b'","cc" But really, literal_eval() should not be used for CSV; it won't handle unquoted fields at all, among other issues. Cheers, Chris From andrea.crotti.0 at gmail.com Thu Jun 14 04:20:10 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 14 Jun 2012 09:20:10 +0100 Subject: validating XML In-Reply-To: References: Message-ID: 2012/6/13 Stefan Behnel > andrea crotti, 13.06.2012 12:06: > > Hello Python friends, I have to validate some xml files against some xsd > > schema files, but I can't use any cool library as libxml unfortunately. > > Any reason for that? Because the canonical answer to your question would be > lxml, which uses libxml2. > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > Yes sure and I would perfectly agree with you, the more I look into this taks the less I want to do it ;) The reason is that it has to work on many platforms and without any c module installed, the reason of that I'm not sure yet but I'm not going to complain again... Anyway in a sense it's also quite interesting, and I don't need to implement the whole XML, so it should be fine. What I haven't found yet is an explanation of a possible algorithm to use for the validation, that I could then implement.. Thanks, Andrea -------------- next part -------------- An HTML attachment was scrubbed... URL: From nospam at nospam.com Thu Jun 14 06:53:27 2012 From: nospam at nospam.com (Gilles) Date: Thu, 14 Jun 2012 12:53:27 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <60ngt7563ri587i6rjjsu6kfk3qtqrmi39@4ax.com> <50qgt7lg5qpkm8nocs0c85uj72trnegh3t@4ax.com> <4fd91153$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 13 Jun 2012 19:03:29 -0500, Tim Chase wrote: >That's just my off-the-top-of-my-head list of things that you'd have >to come up with that Django happens to give you out-of-the-box. Thanks much. So the next step will have to find a framework that's right for a given application. From albert at spenarnc.xs4all.nl Thu Jun 14 07:17:01 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 14 Jun 2012 11:17:01 GMT Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> Message-ID: In article <7xwr3fjff8.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >Matej Cepl writes: >> The point is that you are never interested in learning *a language*, >> everybody who has at least some touch with programming can learn most >> languages in one session in the afternoon. > >Really, that's only if the new language is pretty much the same as the >old ones, in which case you haven't really learned much of anything. >Languages that use interesting new concepts are challenges in their own >right. > >Here is an interesting exercise for statically typed languages, >unsuitable for Python but not too hard in Haskell: > >http://blog.tmorris.net/understanding-practical-api-design-static-typing-and-functional-programming/ When I'm satisfied with a program, it has this ethereal property that if the problem is slightly altered, the program is only slightly altered. Case in point:going to incorporate the extra 8 register from 64 bit pentium into a pre-existing 32 bit Pentium assembler. (Which is a in fact a somewhat large messy change that would trigger a rewrite in most assemblers.) I much doubt if e.g. the whowonordraw gives a compile time error on a non-finished board, that the program can be robust against a small change of the rules. Say strikes going through the lower left square are not counted as a win. It is sooo bloody artifical. A normal requirement would be an API that gives on any tic-tac-toe board one of: Iwin, youwin, draw, not-finished. Then there are static typed languages like Forth where the programmer is the judge whether there is a type error, and type errors are not generated by the compiler. A much more natural api is where a board is an object. You can send a move message -> accepted or nor You can send an inspect message -> won lost draw or not-finished. I can make that totally robust without storing lost or draw information using the type system. He requires that on several calls, if the data is wrong, you get a compile time error. How could that be a reasonable demand from a language like Python where the call can be made interpretively? Of course it is an exercise. But I think that it went this way: 1. solve it in Haskell 2. require incidental and non-useful features of the solution to work in other languages the same way. If he is bashing Scrum, I'm bashing staic typing. > >It doesn't require the use of any libraries, standards, style, or >culture. I can tell you as a fairly strong Python programemr who got >interested in Haskell a few years ago, it took me much longer than an >afternoon to get to the point of being able to solve a problem like the >above. It required absorbing new concepts that Python simply does not >contain. But it gave me the ability to do things I couldn't do before. >That's a main reason studying new languages is challenging and >worthwhile. I give you that. Mastering a functional language is a real step, but I don't think this tic-tac-toe exercise will entice me to do that. Maybe the solutions to http://projecteuler.net that are published in Haskell sometimes condensing a few pages of my sequential code in a few lines, will inspire me to take up Haskell. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From no.email at nospam.invalid Thu Jun 14 11:38:02 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 14 Jun 2012 08:38:02 -0700 Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> Message-ID: <7xsjdxzyxx.fsf@ruckus.brouhaha.com> >>http://blog.tmorris.net/understanding-practical-api-design-static-typing-and-functional-programming/ > > When I'm satisfied with a program, it has this ethereal property that > if the problem is slightly altered, the program is only slightly > altered. One thing I find with Haskell: the type system really seems to help guide the program towards having that property, by making sure all the parts fit together cleanly. > Case in point:going to incorporate the extra 8 register from > 64 bit pentium into a pre-existing 32 bit Pentium assembler. > (Which is a in fact a somewhat large messy change that would > trigger a rewrite in most assemblers.) I'd hope that such a change would be easy in a well-designed assembler. > I much doubt if e.g. the whowonordraw gives a compile time error > on a non-finished board, that the program can be robust against > a small change of the rules. Say strikes going through the lower > left square are not counted as a win. Eh? No, that kind of change is trivial, and wouldn't affect the types at all. Maybe you're imagining the rules of tic-tac-toe being encoded in the types, which could in fact be done, especially in fancier systems like Agda's. But all that we're talking about here is that creation of values describing game states is reserved to the API implementation by the module system. The API doesn't export the constructors for values in the "game state" types. It's just like an OO system that enforces private instance variables, so that clients can only get at those variables through accessor functions supplied by the instances. > Then there are static typed languages like Forth where the programmer > is the judge whether there is a type error, and type errors are not > generated by the compiler. That is not static typing in any normal sense of the term. Forth is untyped. > A much more natural api is where a board is an object. > You can send a move message -> accepted or nor > You can send an inspect message -> won lost draw or not-finished. If you attempt a move on a finished board, that is a programming error. By suffering some extra complexity in the types, you can catch this particular error at compile time, decreasing your testing and support burden at runtime. Whether that trade-off is worth it in practice depends on the problem. For tic-tac-toe it's probably not worth it except as an exercise, and this tic-tac-toe problem was in fact presented as an exercise. > I can make that totally robust without storing lost or draw > information using the type system. I think the exercise simply wanted separate types for complete and incomplete games, not separate types for win/lose/draw. I could imagine wanting separate types for wins/losses/draws if there were functions to award prizes to the winners of games. You'd want to make sure that lost games didn't get awarded these prizes. > He requires that on several calls, if the data is wrong, you get > a compile time error. How could that be a reasonable demand from > a language like Python where the call can be made interpretively? You can't, that's the entire point, Python is good for many things but not for this. So if you want to expand your horizons as a programmer enough to be able to do this sort of problem, you have to try out more languages. > Of course it is an exercise. But I think that it went this way: > 1. solve it in Haskell > 2. require incidental and non-useful features of the solution > to work in other languages the same way. Not sure what you mean there. The exercise was to use static types to write an API with certain characteristics. Obviously you can't do that without static types. It's just like programming exercises involving writing recursive functions can't be solved in languages like Fortran(?) that don't support recursion, etc. And those characteristics (per the specification in the exercise) were not incidental or non-useful, they were essential. > If he is bashing Scrum, I'm bashing staic typing. I don't remember what if anything he said about Scrum. > I give you that. Mastering a functional language is a real > step, but I don't think this tic-tac-toe exercise will entice me to > do that. Functional programming and fancy type systems are separate subjects and Haskell implements both. Scheme is functional without static types, and I got interested in Scheme some time before starting to use Haskell. When I did try out Haskell, I got more from its type system than I expected to. I thought the following was really cool: https://gist.github.com/2659812 with discussion at: http://www.reddit.com/r/haskell/comments/ti5il/redblack_trees_in_haskell_using_gadts_existential/ it implements a data structure (red-black trees) with complicated invariants that are expressed in the type system in a natural way, so that the compiler ensures that all manipulations on the trees don't mess up the invariants. > Maybe the solutions to http://projecteuler.net that are published > in Haskell sometimes condensing a few pages of my sequential code in > a few lines, will inspire me to take up Haskell. I've done some Euler problems in Haskell but so far, my solutions haven't used types in particularly interesting ways. Project Euler is mostly about problems in number theory and combinatorics, and Python is great for that. Haskell may have more attraction if you like abstract algebra or mathematical logic. Here is a really nice article that explains Haskell's type system in terms of categories: http://en.wikibooks.org/wiki/Haskell/Category_theory From golfshoe at gmail.com Thu Jun 14 13:35:27 2012 From: golfshoe at gmail.com (golfshoe at gmail.com) Date: Thu, 14 Jun 2012 10:35:27 -0700 (PDT) Subject: Create thumbnail image (jpg/png) of PDF file using Python In-Reply-To: <9c15c8a2-2250-43d4-9084-e8d3bdab2107@c30g2000hsa.googlegroups.com> References: <104837c4-898a-4f67-98ab-37df8ff76f0f@e25g2000prg.googlegroups.com> <9c15c8a2-2250-43d4-9084-e8d3bdab2107@c30g2000hsa.googlegroups.com> Message-ID: <951a74bf-5bff-4bef-a929-1e11eb995225@googlegroups.com> On Wednesday, November 21, 2007 1:16:55 PM UTC-5, sophie_newbie wrote: > On Nov 20, 5:36 pm, sophie_newbie > wrote: > > Is there any way to do this directly within python? > > > > If not is there any other good way to achieve it? > > > > Thanks in advance for any help! > > I think I've solved this problem using a piece of software called > imageMagick. Good stuff so it is. Interesting. I wonder if GS can be used to convert PDF To JPG and JPG back to PDF? Pillow is a better alternative to PIL if you are in need of compiling on a Mac. From feliphil at gmx.net Thu Jun 14 14:25:09 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Thu, 14 Jun 2012 20:25:09 +0200 Subject: Pythonic cross-platform GUI desingers =?ISO-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> Message-ID: <20120614202509.ed996411.feliphil@gmx.net> > > None of these were such that I could propagate it as GUI development > > tool for non-programmers / casual users. > > Sure, some are good for designing the GUI, but at the point where > > the user code is to be added, most people would be lost. > > There was a time when that was a highly advertisable feature - "build > XYZ applications without writing a single line of code!". That's the typical nonsense cheaptalk of sales promotion advertising, directed at clueless managers. What is needed for domain specialists are frameworks and related tools such as GUI builders that allow them to write exclusively the domain-specific code (this is where a domain specialist will always be better than any software developer), layout the GUI as ergonomically convenient (same) and then have the framework do all the rest. > I've seen it in database front-end builders as well as GUI tools, > same thing. But those sorts of tools tend not to be what experts want > to use. If by "experts" you mean "domain specialists", you're wrong. If you mean full-time software developers, I don't care for what they want, because they already have what they want. And where they don't have it already, they can do it themselves. > You end up having to un-learn the "easy way" before you learn the > "hard way" that lets you do everything. I see no technical reason why a GUI builder would prevent anyone to add customised code by hand. No tool/framework can cover 100%, no doubt. My point is that there are currently no frameworks/tools available for Python that cover the 90/95/98% of use cases where they would help a L-O-T. Sincerely, Wolfgang From feliphil at gmx.net Thu Jun 14 14:43:10 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Thu, 14 Jun 2012 20:43:10 +0200 Subject: Pythonic cross-platform GUI desingers =?ISO-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: <4FD4F75D.40602@schwertberger.de> Message-ID: <20120614204310.41063542.feliphil@gmx.net> > object mainwindow=GTK2.Window(GTK2.WindowToplevel); > mainwindow->set_title("Timing")->set_default_size > (400,300)->signal_connect("destroy",window_destroy); GTK2.HbuttonBox > btns=GTK2.HbuttonBox()->set_layout(GTK2.BUTTONBOX_SPREAD); foreach > (labels,string lbl) btns->add(buttons[lbl]=button(lbl,mode_change)); > mainwindow->add(GTK2.Vbox(0,0) > > ->add(GTK2.TextView(buffer=GTK2.TextBuffer())->set_size_request(0,0)) > ->pack_start(btns,0,0,0))->show_all(); > > If you're a complete non-programmer, then of course that's an opaque > block of text. Thanks for that hideously appalling example of a ridiculously low-level mess. If you're an occasional Python scripting dilettant, this looks like a heap of syntax garbage of exactly that kind that has made me avoid all C-derived languages at university (I'm a mechanical engineer) and that makes me avoid GUI programming with Python so far. If a domain specialist needs an application with a GUI, (s)he typically only wants to have to tell the framework three things: 1. What the domain model looks like (classes, attributes) and what it does in terms of behaviour (domain logic, methods). In my use-cases this would be typically done with SQLalchemy. 2. What the GUI shows of the domain model and how it does it - define menus with entries, layout forms/dialog boxes with fields etc. This should be done without having to permanently look up all the specific details of the API of the GUI framework. 3. What attribute/method of the domain model a GUI element is "connected to" (sorry for the quotes again). This should be possible in an interactive way, so that you can test whether GUI and code work together as required while defining the connections. Anything else should be done by the framework without the necessity to write a single line of code for the "straight forward" use cases: - creating, retrieving, updating, deleting instances of domain model classes - setting values of attributes instances of domain model classes - calling methods of instances of domain model classes Sincerely, Wolfgang From feliphil at gmx.net Thu Jun 14 14:45:55 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Thu, 14 Jun 2012 20:45:55 +0200 Subject: Pythonic cross-platform GUI desingers =?ISO-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: <19e8593c-26ea-49c7-af76-01f85fa42387@t2g2000pbl.googlegroups.com> Message-ID: <20120614204555.b4e6e386.feliphil@gmx.net> Danger: Flame ahead! > I think efforts to make a better, and more definitive, "GUI builder" > for Python should focus on makigng an easy to use "IDE" for creating > these kinds of Python-HTMl-Javascript front ends for applications. The idea of so-called "web applications" is a cerebral flatulance emanating from braindead morons (typically the pointy-haired type), sorry. >From the perspective of the domain specialist who needs to get some work done and who needs to get it done efficiently they are simply unusable. The "functionality" that such "web interfaces" provide is ridiculously poor, they are clumsy to use and even worse hourglass-display systems than the junk that MS or SAP sell. Besides the fact that they require obscene amounts of runtime ressources. Besides... Sorry, this subject isn't worth wasting my brain bandwidth on it. I have started to use computers with GEM on Atari ST, MacOS 6.0.7 and DOS 3.3, and if all those "web mailers" or "Google apps" had been the only applications available back then I would have never started to use computers at all. In short: "web applications" are in no way a solution to the mentioned problem, but they make this problem worse by piling up other problems on top of it. End of flame. Sincerely, Wolfgang From dieter at handshake.de Thu Jun 14 15:19:31 2012 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 14 Jun 2012 21:19:31 +0200 Subject: validating XML References: Message-ID: <87y5np66rg.fsf@handshake.de> andrea crotti writes: > ... > The reason is that it has to work on many platforms and without any c module > installed, the reason of that Searching for a pure Python solution, you might have a look at "PyXB". It has not been designed to validate XML instances against XML-Schema (but to map between XML instances and Python objects based on an XML-Schema description) but it detects many problems in the XML instances. It does not introduce its own C extensions (but relies on an XML parser shipped with Python). > Anyway in a sense it's also quite interesting, and I don't need to implement > the whole XML, so it should be fine. The XML is the lesser problem. The big problem is XML-Schema: it is *very* complex with structure definitions (elements, attributes and "#PCData"), inheritance, redefinition, grouping, scoping rules, inclusion, data types with restrictions and extensions. Thus if you want to implement a reliable algorithm which for given XML-schema and XML-instance checks whether the instance is valid with respect to the schema, then you have a really big task. Maybe, you have a fixed (and quite simple) schema. Then you may be able to implement a validator (for the fixed schema). But I do not understand why you would want such a validation. If you generate the XML instances, then thouroughly test your generation process (using any available validator) and then trust it. If the XML instances come from somewhere else and must be interpreted by your application, then the important thing is that they are understood by your application, not that they are valid. If you get a complaint that your application cannot handle a specific XML instance, then you validate it in your development environment (again with any validator available) and if the validation fails, you have good arguments. > What I haven't found yet is an explanation of a possible algorithm to use for > the validation, that I could then implement.. You parse the XML (and get a tree) and then recursively check that the elements, attributes and text nodes in the tree conform to the schema (in an abstract sense, the schema is a collection of content models for the various elements; each content model tells you how the element content and attributes should look like). For a simple schema, this is straight forward. If the schema starts to include foreign schemas, uses extensions, restrictions or "redefine"s, then it gets considerably more difficult. -- Dieter From btemperton at gmail.com Thu Jun 14 15:27:38 2012 From: btemperton at gmail.com (Ben Temperton) Date: Thu, 14 Jun 2012 12:27:38 -0700 (PDT) Subject: finding the byte offset of an element in an XML file (tell() and seek()?) Message-ID: Hi there, I am working with mass spectroscopy data in the mzXML format that looks like this: ... ... ... ... ..... 160409990 160442725 160474927 160497386 .... Where the offset element contains the byte offset of the scan element that shares the id. I am trying to write a python script to remove scan elements and their respective offset, but I can't figure out how I re-calculate the byte offset for each remaining element once the elements have been removed. My plan was to write the file out, the read it back in again and search through the file for a particular string (e.g. '') and then use the tell() method to return the current byte location in the file. However, I'm not sure how I would implement this. Any ideas? Many thanks, Ben From cloughrm at gmail.com Thu Jun 14 15:57:47 2012 From: cloughrm at gmail.com (Ryan Clough) Date: Thu, 14 Jun 2012 15:57:47 -0400 Subject: mbox parsing, specifically message body Message-ID: <567D8913BB8B4EA299F0E58F7D9CA6D9@gmail.com> Hello everyone, Is anyone familiar with a simple way to parse mbox emails in Python? I use Mail::MBoxParser in perl and it provides a simple way to grab the bodies from the emails. In my research online, people have suggested searching for lines starting with "From ", but this doesn't seem reliable to me. I am using the built in mailbox module and am able to do something like: import mailbox for message in mbox: print message['subject'] It would be great if you could do something like the following: print messages['body'] Any thoughts are appreciated. Thanks, Ryan -------------- next part -------------- An HTML attachment was scrubbed... URL: From cmpython at gmail.com Thu Jun 14 15:59:23 2012 From: cmpython at gmail.com (CM) Date: Thu, 14 Jun 2012 12:59:23 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> <20120614202509.ed996411.feliphil@gmx.net> Message-ID: <35c66602-8827-4dd9-9ca5-723be4d22a90@b1g2000vbb.googlegroups.com> On Jun 14, 2:25?pm, Wolfgang Keller wrote: > > What is needed for domain specialists are frameworks and related tools > such as GUI builders that allow them to write exclusively the > domain-specific code (this is where a domain specialist will always be > better than any software developer), layout the GUI as ergonomically > convenient (same) and then have the framework do all the rest. Above this you also mentioned a disdain for the need for "glue code", which in the context of your post seemed to be binding to event handlers. So is there a possible way for a GUI builder to *automatically* bind widgets to the appropriate functions in your domain-specific code? It's hard to see how this would be generally possible, even with an AI (maybe a mind-reading AI would work). Or maybe I'm misunderstanding something. From ralf at systemexit.de Thu Jun 14 16:01:44 2012 From: ralf at systemexit.de (Ralf Schmitt) Date: Thu, 14 Jun 2012 22:01:44 +0200 Subject: [ANNOUNCE] pypiserver 0.6.0 - minimal private pypi server Message-ID: <87haudslw7.fsf@myhost.lan> Hi, I've just uploaded pypiserver 0.6.0 to the python package index. pypiserver is a minimal PyPI compatible server. It can be used to serve a set of packages and eggs to easy_install or pip. pypiserver is easy to install (i.e. just easy_install pypiserver). It doesn't have any external dependencies. http://pypi.python.org/pypi/pypiserver/ should contain enough information to easily get you started running your own PyPI server in a few minutes. The code is available on github: https://github.com/schmir/pypiserver Changes in version 0.6.0 ------------------------- - make pypiserver work with pip on windows - add support for password protected uploads - make pypiserver work with non-root paths - make pypiserver 'paste compatible' - allow to serve multiple package directories using paste -- Cheers, Ralf From colinh at somewhere.invalid Thu Jun 14 16:06:35 2012 From: colinh at somewhere.invalid (Colin Higwell) Date: Thu, 14 Jun 2012 20:06:35 +0000 (UTC) Subject: Pythonic cross-platform GUI desingers =?iso-8859-1?b?4A==?= la Interface Builder (Re: what gui designer is everyone using) References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: On Tue, 12 Jun 2012 00:55:38 +0200, Dietmar Schwertberger wrote: > As long as there's no GUI > builder for Python, most people will stick to Excel / VBA / VB. No GUI builder for Python? There are plenty. I use wxGlade with wxPython and it works beautifully. It writes the code for the GUI elements, and I put in the event handlers, database access code and so on. From emile at fenx.com Thu Jun 14 16:28:16 2012 From: emile at fenx.com (Emile van Sebille) Date: Thu, 14 Jun 2012 13:28:16 -0700 Subject: finding the byte offset of an element in an XML file (tell() and seek()?) In-Reply-To: References: Message-ID: On 6/14/2012 12:27 PM Ben Temperton said... > Hi there, > > I am working with mass spectroscopy data in the mzXML format that looks like this: > > > ... > ... > ... > ... > ..... > > > 160409990 > 160442725 > 160474927 > 160497386 > .... > > > > Where the offset element contains the byte offset byte offset to what in what? > of the scan element that shares the id. I am trying to write a python script to remove scan elements and their respective offset, but I can't figure out how I re-calculate the byte offset for each remaining element once the elements have been removed. Removing the reference will render the location as inaccessible so you may not need to recalculate the remaining offsets. I'm assuming these are offset in some other file and that the lengths of the data contained at that location is known or knowable. But, if you don't point to that location you won't try to get the data at the offset. If you're trying to minimize the size on disk you'll probably want to write a new file and leave the original alone. Initialize a buffer, then for each valid offset id add the content and bump the offset by the content length (or whatever is appropriate) Emile > > My plan was to write the file out, the read it back in again and search through the file for a particular string (e.g. '') and then use the tell() method to return the current byte location in the file. However, I'm not sure how I would implement this. > > Any ideas? > > Many thanks, > > Ben From emile at fenx.com Thu Jun 14 16:50:12 2012 From: emile at fenx.com (Emile van Sebille) Date: Thu, 14 Jun 2012 13:50:12 -0700 Subject: mbox parsing, specifically message body In-Reply-To: <567D8913BB8B4EA299F0E58F7D9CA6D9@gmail.com> References: <567D8913BB8B4EA299F0E58F7D9CA6D9@gmail.com> Message-ID: On 6/14/2012 12:57 PM Ryan Clough said... > Hello everyone, > > Is anyone familiar with a simple way to parse mbox emails in Python? >>> import mailbox >>> help(mailbox) Help on module mailbox: NAME mailbox - Read/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes. Emile > I > use Mail::MBoxParser in perl and it provides a simple way to grab the > bodies from the emails. In my research online, people have suggested > searching for lines starting with "From ", but this doesn't seem > reliable to me. I am using the built in mailbox module and am able to do > something like: > > import mailbox > for message in mbox: > print message['subject'] > > It would be great if you could do something like the following: > print messages['body'] > > Any thoughts are appreciated. > > Thanks, Ryan > > From news at schwertberger.de Thu Jun 14 16:52:32 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Thu, 14 Jun 2012 22:52:32 +0200 Subject: Pythonic cross-platform GUI desingers =?UTF-8?B?w6AgbGEgICAg?= =?UTF-8?B?IEludGVyZmFjZSBCdWlsZGVyIChSZTogd2hhdCBndWkgZGVzaWduZXIgaXMgZXY=?= =?UTF-8?B?ZXJ5b25lIHVzaW5nKQ==?= In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: Am 14.06.2012 22:06, schrieb Colin Higwell: > On Tue, 12 Jun 2012 00:55:38 +0200, Dietmar Schwertberger wrote: >> As long as there's no GUI >> builder for Python, most people will stick to Excel / VBA / VB. > > No GUI builder for Python? There are plenty. Yes, sorry. I posted that too late in the night. The point was that there's no easy-to-use GUI builder which would allow the casual user to create a GUI. > I use wxGlade with wxPython and it works beautifully. It writes the code > for the GUI elements, and I put in the event handlers, database access > code and so on. Yes, from the ones I've tested, wxGlade came closest to what I was looking for. But still, it's far away from being the tool that is required IMHO. (An it does not seem to be in active development.) Also, with wxGlade you are forced to use sizers - even at positions where they are not useful at all. For simple GUIs that adds a level of complexity which is counter productive. (From the GUI editors that I tried, Qt Creator/Designer was the only one where I agree that it handles sizers/layout containers well.) When I compare e.g. wxGlade to VB6, whether a casual programmer can use it to create a GUI, then still VB6 wins. VB is crap, but at least it allows to create GUIs by using a GUI and will help you getting started in writing GUI applications. It will take only a few minutes to teach someone how to get started. On the other hand, I need to know wx very well to be able to create a GUI using wxGlade as otherwise I will never find where to add e.g. the handlers. But when I know wx very well, then there's no point in using wxGlade. Regards, Dietmar From roy at panix.com Thu Jun 14 17:03:01 2012 From: roy at panix.com (Roy Smith) Date: 14 Jun 2012 17:03:01 -0400 Subject: Finding all loggers? Message-ID: Is there any way to get a list of all the loggers that have been defined? So if somebody has done: from logging import getLogger getLogger("foo") getLogger("foo.bar") getLogger("baz") I want something which will give me back ["foo", "foo.bar", "baz"]. From invalid at invalid.invalid Thu Jun 14 17:29:10 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 14 Jun 2012 21:29:10 +0000 (UTC) Subject: Pythonic cross-platform GUI desingers ?? la Interface Builder (Re: what gui designer is everyone using) References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: On 2012-06-14, Dietmar Schwertberger wrote: > Yes, sorry. I posted that too late in the night. The point was that > there's no easy-to-use GUI builder which would allow the casual user > to create a GUI. I'm not sure I'm in favor of casual users creating GUIs. Have you ever tried to _use_ a program built by a casual user? [OK, I'm half joking.] If casual users want a GUI builder they can use, then let 'em write one... :) -- Grant Edwards grant.b.edwards Yow! My nose feels like a at bad Ronald Reagan movie ... gmail.com From mhrivnak at hrivnak.org Thu Jun 14 17:38:00 2012 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Thu, 14 Jun 2012 17:38:00 -0400 Subject: Finding all loggers? In-Reply-To: References: Message-ID: >>> import logging >>> logging.Logger.manager.loggerDict {} >>> logging.getLogger('foo') >>> logging.getLogger('bar') >>> logging.Logger.manager.loggerDict {'foo': , 'bar': } Enjoy, Michael On Thu, Jun 14, 2012 at 5:03 PM, Roy Smith wrote: > Is there any way to get a list of all the loggers that have been > defined? ?So if somebody has done: > > from logging import getLogger > getLogger("foo") > getLogger("foo.bar") > getLogger("baz") > > I want something which will give me back ["foo", "foo.bar", "baz"]. > -- > http://mail.python.org/mailman/listinfo/python-list From news at schwertberger.de Thu Jun 14 17:47:15 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Thu, 14 Jun 2012 23:47:15 +0200 Subject: Pythonic cross-platform GUI desingers ?? la Interface Builder (Re: what gui designer is everyone using) In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: Am 14.06.2012 23:29, schrieb Grant Edwards: > On 2012-06-14, Dietmar Schwertberger wrote: >> Yes, sorry. I posted that too late in the night. The point was that >> there's no easy-to-use GUI builder which would allow the casual user >> to create a GUI. > > I'm not sure I'm in favor of casual users creating GUIs. > > Have you ever tried to _use_ a program built by a casual user? > > [OK, I'm half joking.] I understand your point. I've used and fixed many such programs. Plenty of those were by so-called professionals. Usually, those are the most problematic cases as you don't have the sources available or they are developed and deployed by a central IT department. There's a correlation between technical knowledge of creating a GUI and the quality of the resulting GUI, but the correlation is not too strong. The casual programmer that I was refering to, is also among the users of the software that (s)he is writing and therefore the GUI tends to be improved over time, which often is not the case with the software developed by so-called professionals who get paid for the program and then move on. The point is, that if you want to promote Python as replacement for e.g. VB, Labview etc., then an easy-to-use GUI builder is required. The typical GUI programs will just have an input mask, a button and one or two output fields. Regards, Dietmar From news at schwertberger.de Thu Jun 14 17:49:49 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Thu, 14 Jun 2012 23:49:49 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la___Interface_Builder_=28Re=3A_wh?= =?ISO-8859-1?Q?at_gui_designer_is_everyone_using=29?= In-Reply-To: <20120613144931.adbb2c52.feliphil@gmx.net> References: <4FD4F75D.40602@schwertberger.de> <20120613144931.adbb2c52.feliphil@gmx.net> Message-ID: Am 13.06.2012 14:49, schrieb Wolfgang Keller: >> No matter how cool it may seem to create simple GUIs manually or to >> write business letters using LaTeX: just try to persuade people to >> move from Word to LaTeX for business letters... > > Good example. > > I have done nearly exactly this* - but it was only possible thanks to > LyX. > *I moved not from Wugh, but from other software to LyX/LaTeX for all my > document processing. But of course, you were only doing so because you had LyX available, which is the equivalent of an easy-to-use GUI builder. So maybe I should be more precise: just try to persuade people to move from Word to *pure* LaTeX for business letters... Regards, Dietmar From roy at panix.com Thu Jun 14 18:57:25 2012 From: roy at panix.com (Roy Smith) Date: Thu, 14 Jun 2012 18:57:25 -0400 Subject: Finding all loggers? In-Reply-To: References: Message-ID: <2B14B8D6-0A3C-4C35-9482-816FC41AC43F@panix.com> Neat, thanks! On Jun 14, 2012, at 5:38 PM, Michael Hrivnak wrote: >>>> import logging >>>> logging.Logger.manager.loggerDict > {} >>>> logging.getLogger('foo') > >>>> logging.getLogger('bar') > >>>> logging.Logger.manager.loggerDict > {'foo': , 'bar': > } > > Enjoy, > Michael > > On Thu, Jun 14, 2012 at 5:03 PM, Roy Smith wrote: >> Is there any way to get a list of all the loggers that have been >> defined? So if somebody has done: >> >> from logging import getLogger >> getLogger("foo") >> getLogger("foo.bar") >> getLogger("baz") >> >> I want something which will give me back ["foo", "foo.bar", "baz"]. >> -- >> http://mail.python.org/mailman/listinfo/python-list > --- Roy Smith roy at panix.com From chrisjrn at gmail.com Thu Jun 14 21:21:11 2012 From: chrisjrn at gmail.com (Chris Neugebauer) Date: Fri, 15 Jun 2012 11:21:11 +1000 Subject: PyCon Australia 2012 Conference Programme Revealed! In-Reply-To: References: Message-ID: (Hobart Tasmania, 15 June 2012) With both of our keynotes announced, PyCon Australia is very proud to be able to reveal the programme for the 2012 conference, to be held on Saturday 18 and Sunday 19 August 2012 in Hobart, Tasmania. Following an impressive response to our Call for Proposals the conference will feature three full tracks of presentations and tutorials, across two days, covering all aspects of the Python ecosystem, presented by experts and core developers of key Python technology. Our keynote presenters, Mark Ramm, Engineering Manager on Juju at Canonical [1], and Kenneth Reitz, Python lead at Heroku [2] will be joined by a wide array of presenters covering a broad range of backgrounds, including industry, research, government and academia. As ever, PyCon Australia is a great place to keep up-to-date with the latest trends in Python web technology: From Heroku, Lincoln Stoll will be presenting on the 12 Factor Method for building software-as-a-service apps [3]. Other web related topics include deployment and testing techniques for Django applications and techniques for asynchronous web programming. There's also a wide range of talks for the rapidly growing community of developers using Python in science. Edward Schofield's survey of the latest developments in Python for Science and Engineering [4] will get you up to scratch on what tools and techniques are shaping the Python world for scientists. From there, case studies and introductory talks will delve into all aspects of Python in science: including techniques for handling large scientific data sets, natural language processing, and data visualisation -- attendees working with Python in all fields of science will gain something from PyCon Australia 2012. Finally, for newcomers to Python looking to quickly enhance their Python skillset, Graeme Cross' tutorials [5] in our Classroom stream will help you to rapidly enhance your knowledge of Python -- you can then attend our general stream talks to glean a snapshot of the state of the art in Python. PyCon Australia 2012 programme committee chair, Richard Jones, was impressed with the level of response to the Call for Proposals, which closed in early May: "We had an unprecedented response to our Call for Proposals this year, and this has helped us to put together one of the strongest programmes ever at PyCon Australia. There's something for every developer working with Python in this year's programme -- be they working in web technology, in research, or even if they're just a Python enthusiast who wants to learn more about their favourite language." The full schedule for PyCon Australia 2012 can be found at http://2012.pycon-au.org/programme/schedule Registrations for PyCon Australia 2012 are now open, with prices starting at AU$44 for students, and tickets for the general public starting at AU$198. All prices include GST, and more information can be found at http://2012.pycon-au.org/register/prices We're looking forward to seeing this excellent programme brought to life at PyCon Australia 2012, in Hobart, in August. [1] http://2012.pycon-au.org/media/news/24 [2] http://2012.pycon-au.org/media/news/18 [3] http://2012.pycon-au.org/schedule/59/view_talk?day=sunday [4] http://2012.pycon-au.org/schedule/67/view_talk?day=saturday [5] http://2012.pycon-au.org/schedule/56/view_talk?day=saturday === About PyCon Australia === PyCon Australia is the national conference for the Python Programming Community. The third PyCon Australia will be held on August 18 and 19, 2012 in Hobart, Tasmania, bringing together professional, student and enthusiast developers with a love for developing with Python. PyCon Australia informs the country?s Python developers with presentations, tutorials and panel sessions by experts and core developers of Python, as well as the libraries and frameworks that they rely on. To find out more about PyCon Australia 2012, visit our website at http://pycon-au.org or e-mail us at contact at pycon-au.org. PyCon Australia is presented by Linux Australia (www.linux.org.au) and acknowledges the support of our Gold sponsors: Google Australia ( www.google.com.au), and the Australian Computer Society (Tasmanian Branch) ( www.acs.org.au); our Event partners: Kogan, and Secret Lab; and our Silver sponsors: the Python Software Foundation, the Django Software Foundation, Anchor Systems, 99designs, Red Hat, ekit, RimuHosting, and CSIRO. -- --Christopher Neugebauer Conference Coordinator and Sponsor Liaison PyCon Australia: Hobart 2012 -- http://2012.pycon-au.org -- @pyconau Conference registration and accommodation deals now available! See our website for details. Jabber: chrisjrn at gmail.com -- IRC: chrisjrn on irc.freenode.net -- WWW: http://chris.neugebauer.id.au -- Twitter/Identi.ca: @chrisjrn -------------- next part -------------- An HTML attachment was scrubbed... URL: From k.sahithi2862 at gmail.com Fri Jun 15 01:04:40 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Thu, 14 Jun 2012 22:04:40 -0700 (PDT) Subject: EXCLUSIVE HOT PHOTOS & VIDEOS Message-ID: <638bd424-b5cc-4ae2-9b45-dce11624d2b7@po9g2000pbb.googlegroups.com> ALL INTERVIEW QUESTIONS& STUDY MATERIAL http://newdotnetinterviewquestions.blogspot.in/ TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR LATEST MOVIE UPDATED LINKS COOL BOYS HOT GIRLS MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/06/cool-boys-hot-girls-movie-stills.html MITAAYI MOVIE LATEST GALLERY http://actressgallery-kalyani.blogspot.in/2012/06/mitaayi-movie-stills.html NAGARJUNA DAMARUKAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/damarukam-movie-stills.html ALLU ARJUN JULAYI MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/julayi-movie-stills.html SUDIGADU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/sudigadu-movie-stills.html MR 7 MOVIE FILM GALLERY http://actressgallery-kalyani.blogspot.in/2012/05/mr7-movie-stills.html ALL THE BEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/all-best-movie-stills.html Midatha Telugu movie Hot Namitha Stills http://actressgallery-kalyani.blogspot.com/2012/05/midatha-movie-stills.html OKA COLLEGE LOVE STORY MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/oka-college-love-story-movie-stills.html KATRINA KAIF LATEST UNSEENED PHOTOS http://actressgallery-kalyani.blogspot.com/2012/05/katrina-kaif-latest-pics.html TAMIL ACTRESS ARUNDHATI HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/05/arundhati-tamil-actress.html THANDHAVAM MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/05/thandavam-movie-stills.html KHO KHO LATEST MOVIE SPICY STILLS http://actressgallery-kalyani.blogspot.com/2012/05/kho-kho-movie-stills.html Oh My Love Movie Latest Photo Gallery http://actressgallery-kalyani.blogspot.com/2012/04/oh-my-love-movie-stills.html Oka Romantic Crime katha Movie stills http://actressgallery-kalyani.blogspot.in/2012/04/oka-romantic-crime-katha-movie-stills.html DARUVU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/03/daruvu-movie-stills.html Pavan Kalyan,Shruthi Hasan Gabbar Singh Movie Photos http://actressgallery-kalyani.blogspot.in/2012/04/gabbar-singh-movie-stills.html Good Morning Latest Movie Stills http://actressgallery-kalyani.blogspot.com/2012/04/good-morning-movie-stills.html EEGA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/04/eega-movie-stills.html Mem Vayasuku Vacham Latest Hot Stills http://actressgallery-kalyani.blogspot.com/2012/04/mem-vayasuku-vacham-stills.html DAMMU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/04/dammu-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html HOT LINKS FOR YOUTH ONLY SHRUTHI HASSAN HALF SAREE STILLS http://actressimages-9.blogspot.in/2012/05/shruti-hassan-half-saree-stills.html TAMANNA HOT NAVEL PHOTOS http://actressimages-9.blogspot.in/2012/05/tamanna-navel-photos.html TRISHA LATEST HOT STILLS http://actressgallery9.blogspot.in/2012/05/trisha.html MONIKA LATEST HOT HD STLLS http://actressgallery9.blogspot.in/2012/05/monika-stills.html MALLIKA KAPOOR HOT SIZZLING STILLS http://actressimages-9.blogspot.in/2012/05/mallika-kapoor.html Richa Panai Stills http://actressimages-9.blogspot.com/2012/04/richa-panai-stills.html MADHAVI LATHA LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/04/madhavi-latha-stills.html KRITI KHARBANDA HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/kriti-kharbanda.html NEELAM UPADHYAY HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/neelam-upadhyay.html SAMANTHA LATEST HOT ROMANTIC STILLS http://actressimages-9.blogspot.in/2012/03/samantha-latest-stills.html NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html From howmuchistoday at gmail.com Fri Jun 15 02:52:52 2012 From: howmuchistoday at gmail.com (Yesterday Paid) Date: Thu, 14 Jun 2012 23:52:52 -0700 (PDT) Subject: does python have bright future? Message-ID: <939c24f6-0194-44c0-8fe3-ab61a0eb7863@m2g2000pbv.googlegroups.com> I'm very new to programing though I learn very little of java,C I love python and have fun to do something with it but some people said python's future perhaps not that bright. I know this question maybe looks like an idiot:( I really hope the python rules long~ time. what do you think about future of this lang or famous lang like C, JAVA, C#, LISP &C From no.email at nospam.invalid Fri Jun 15 03:00:16 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 15 Jun 2012 00:00:16 -0700 Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> <7xfwa2vr2h.fsf@ruckus.brouhaha.com> <7x1ulmoo24.fsf@ruckus.brouhaha.com> <4fd629ae$0$9515$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <7xlijpukjj.fsf@ruckus.brouhaha.com> Alexander Blinne writes: >> def gen_s(): >> s = [1] >> m = skipdups(heapq.merge(*[(lambda j: (k*j for k in s))(n) for n in [2,3,5]])) >> yield s[0] >> while True: >> k = m.next() >> s.append(k) >> yield k Nice. I wouldn't have been sure that "for k in s" worked properly when s was changing like that. There is a space complexity problem compared to the Scheme or Haskell version: all the s[i]'s are saved in the s array, instead of being discarded once they are yielded. That means generating n elements needs O(n) space instead of O(n**0.7) or something like that. I guess you can get around it with collections.deque instead of a list. From howmuchistoday at gmail.com Fri Jun 15 03:04:34 2012 From: howmuchistoday at gmail.com (Yesterday Paid) Date: Fri, 15 Jun 2012 00:04:34 -0700 (PDT) Subject: python's future? Message-ID: <1e37eed4-bf4c-4a3e-9981-415f4df2f76c@x6g2000pbh.googlegroups.com> I'm very new to programing though I learn very little of java,C I love python and have fun to do something with it but some people said python's future perhaps not that bright. I know this question maybe looks like an idiot:( I really hope the python rules long~ time. what do you think about future of this lang or famous lang like C, JAVA, C#, LISP &C From rosuav at gmail.com Fri Jun 15 03:30:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jun 2012 17:30:20 +1000 Subject: python's future? In-Reply-To: <1e37eed4-bf4c-4a3e-9981-415f4df2f76c@x6g2000pbh.googlegroups.com> References: <1e37eed4-bf4c-4a3e-9981-415f4df2f76c@x6g2000pbh.googlegroups.com> Message-ID: On Fri, Jun 15, 2012 at 5:04 PM, Yesterday Paid wrote: > I'm very new to programing though I learn very little of java,C > I love python and have fun to do something with it > but some people said python's future perhaps not that bright. > I know this question maybe looks like an idiot:( > I really hope the python rules long~ time. > what do you think about future of this lang > or famous lang like C, JAVA, C#, LISP &C Python's future is looking pretty bright at the moment. It's extremely well supported, has an active and helpful mailing list/newsgroup (hi!) and issue tracker and so on, it's found pre-installed on several Linuxes, it's easy to get for Windows, and lots of Python software is around and being developed all the time. There's big companies who have pledged support, including Google, who employ Guido van Rossum (the project head). As a language, Python has its issues, but overall it's awesome. I have no hesitation in recommending it as a first language, a scripting language, and an application language. There's things I dislike about it (design choices like the lack of declared variables), but that's true of pretty much everything. There's no need to fear its imminent demise :) ChrisA From breamoreboy at yahoo.co.uk Fri Jun 15 03:58:20 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 15 Jun 2012 08:58:20 +0100 Subject: python's future? In-Reply-To: <1e37eed4-bf4c-4a3e-9981-415f4df2f76c@x6g2000pbh.googlegroups.com> References: <1e37eed4-bf4c-4a3e-9981-415f4df2f76c@x6g2000pbh.googlegroups.com> Message-ID: On 15/06/2012 08:04, Yesterday Paid wrote: > I'm very new to programing though I learn very little of java,C > I love python and have fun to do something with it > but some people said python's future perhaps not that bright. > I know this question maybe looks like an idiot:( > I really hope the python rules long~ time. > what do you think about future of this lang > or famous lang like C, JAVA, C#, LISP&C I believe that this still holds true http://www.gossamer-threads.com/lists/python/python/129650?do=post_view_threaded -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Fri Jun 15 04:05:20 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 15 Jun 2012 09:05:20 +0100 Subject: python's future? In-Reply-To: References: <1e37eed4-bf4c-4a3e-9981-415f4df2f76c@x6g2000pbh.googlegroups.com> Message-ID: On 15/06/2012 08:30, Chris Angelico wrote: > On Fri, Jun 15, 2012 at 5:04 PM, Yesterday Paid > wrote: >> I'm very new to programing though I learn very little of java,C >> I love python and have fun to do something with it >> but some people said python's future perhaps not that bright. >> I know this question maybe looks like an idiot:( >> I really hope the python rules long~ time. >> what do you think about future of this lang >> or famous lang like C, JAVA, C#, LISP&C > > Python's future is looking pretty bright at the moment. It's extremely > well supported, has an active and helpful mailing list/newsgroup (hi!) > and issue tracker and so on, it's found pre-installed on several > Linuxes, it's easy to get for Windows, and lots of Python software is > around and being developed all the time. There's big companies who > have pledged support, including Google, who employ Guido van Rossum > (the project head). > > As a language, Python has its issues, but overall it's awesome. I have > no hesitation in recommending it as a first language, a scripting > language, and an application language. There's things I dislike about > it (design choices like the lack of declared variables), but that's > true of pretty much everything. > > There's no need to fear its imminent demise :) > > ChrisA "an active and helpful mailing list/newsgroup (hi!)"? Gmane lists 322 entries under comp.python :) I believe that some manufacturers pre-install on Windows, and I know that it's also pre-installed on OS X. It's just a pity that Python is no longer maintained on the finest OS ever, i.e. VMS :( -- Cheers. Mark Lawrence. From rosuav at gmail.com Fri Jun 15 04:24:11 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jun 2012 18:24:11 +1000 Subject: python's future? In-Reply-To: References: <1e37eed4-bf4c-4a3e-9981-415f4df2f76c@x6g2000pbh.googlegroups.com> Message-ID: On Fri, Jun 15, 2012 at 6:05 PM, Mark Lawrence wrote: > "an active and helpful mailing list/newsgroup (hi!)"? ?Gmane lists 322 > entries under comp.python :) Sorry, should have said: A set of active and helpful mailing lists/newsgroups! You're quite right, there's a lot of them :) I wonder... is there anyone insane enough to have them all subscribed and to actually read every post... ChrisA From dickie.moseley at virgin.net Fri Jun 15 04:28:47 2012 From: dickie.moseley at virgin.net (RICHARD MOSELEY) Date: Fri, 15 Jun 2012 09:28:47 +0100 Subject: Use of internal ctypes objects Message-ID: I have a module which makes use of ctypes to interface to the IBM C-ISAM library under linux. I have created a libpyisam.so library which combines the two official libraries, libifisam.so and libifisamx.so and provides a SONAME for the ctypes module (if that is still required). My main object uses a dictionary in which the keys are the external functions that can be called from the externl library, and the values are initially tuples which define the arguments and return type for the functions. The first time that a function is called, the __getattr__ function locates the function in the library then modifies the return type and arguments according to the tuple stored in the value, this object is then stored in place of the tuple so that subsequent calls simply use the previous object. To check whether the function has been previously converted, I make use of internal objects within the ctypes module, namely, _SimpleCData and _CFuncPtr. Is this a safe thing to do, bearing in mind that the objects are documentated as internal? In order to make the above paragraphs clear, I provide a cutdown version of the object in question with a sample of the functions and the calling convention used. Is there a better way to do this using ctypes: from ctypes import * class ISAMobject(dict): """ The _func dictionary initially consists of: (args,...) where the return type is c_int and arguments are passed, (None,) where the return type is c_int but no arguments are passed, (ret,(args,...)) where the return type is not c_int and arguments are passed, (ret,None) where the return type is not c_int and no arguments are passed, None where there is no return type and no arguments are passed """ _func = { 'isbegin' : (None,), 'iscluster' : (c_int, byref(keydesc)), 'islangchk' : None, 'islanginfo' : (c_char_p, (c_char_p,)) } _const = { 'iserrno' : c_int, 'iscopyright' : c_char_p } _lib = cdll.LoadLibrary('./libpyisam.so') def __getattr__(self, name): func_info = self._func.get(name, 'NONE') if func_info == 'NONE': const_info = self._const.get(name, 'NONE') if const_info == 'NONE': raise AttributeError('Underlying ISAM library does not have %s attribute' % name) if not isinstance(const_info, ctypes._SimpleCData): const_info = const_info.in_dll(self._lib, name) self._const[name] = const_info return const_info.value if hasattr(const_info, 'value') else const_info elif not instance(func_info, ctypes._CFuncPtr): real_func = getattr(self._lib, name) if real_func is None: raise AttributeError('Underlying ISAM library does not support %s function' % name) if func_info is None: real_func.restype = real.argtypes = None elif isinstance(func_info, list): real_func.restype, real_func.argtypes = func_info elif len(func_info) > 1 and isinstance(func_info[1], tuple): real_func.restype, real_func.argtypes = func_info elif isinstance(func_info, tuple): real_func.argtypes = func_info else: real_func.restype = func_info self._func[name] = func_info = real_func return func_info Thank you in advance, Richard Moseley -------------- next part -------------- An HTML attachment was scrubbed... URL: From albert.tresens at gmail.com Fri Jun 15 06:41:33 2012 From: albert.tresens at gmail.com (LoadWalker) Date: Fri, 15 Jun 2012 03:41:33 -0700 (PDT) Subject: Python script for device automatic update. Message-ID: <9635b432-3a9c-4820-bd51-658c1dcda829@googlegroups.com> Hi, I am completly new to python. I need to create and script that needs to do the following steps and would apreciate if someone can give me the guidelines to do it as will be my first python script: The script will be in a linux machine. Will wait for a device to conect on the usb. So needs to constantly check for a new driver usb connection. At the same time looks for new .zip files in a remote URL that contains a file to be copied to the device. So that one a device connectets to the machine it gets copied via ssh the last content of the .zip file. Is it possible to do it in Python? From dmitrey15 at gmail.com Fri Jun 15 07:09:32 2012 From: dmitrey15 at gmail.com (dmitrey) Date: Fri, 15 Jun 2012 04:09:32 -0700 (PDT) Subject: OpenOpt Suite 0.39 Message-ID: Hi all, I'm glad to inform you about new OpenOpt release 0.39 (quarterly since 2007). OpenOpt is free, even for commercial purposes, cross-platform software for mahematical modeling and (mainstream) optimization. Our website have reached 259 visitors daily, that is same to tomopt.com and ~ 1/3 of gams.com (details). In the new release: interalg (medium-scaled solver with specifiable accuracy abs(f-f*) <= fTol): add categorical variables and general logical constraints, many other improvements Some improvements for automatic differentiation DerApproximator and some OpenOpt/FuncDesigner functionality now works with PyPy (Python with dinamic compilation, some problems are solved several times faster now) New solver lsmr for dense/sparse LLSP (linear least squares) Some bugfixes and some other changes In our website (http://openopt.org) you could vote for most required OpenOpt Suite development direction(s). Regards, D. From gdesoto at adinet.com.uy Fri Jun 15 08:18:39 2012 From: gdesoto at adinet.com.uy (Gonzalo de Soto) Date: Fri, 15 Jun 2012 09:18:39 -0300 Subject: PIL for the Python 3.2.3 Message-ID: Dear Python Org, It wanted to know if already PIL's version is available for Python 3.2.3. Thanks. Gonzalo -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Fri Jun 15 08:34:53 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 15 Jun 2012 13:34:53 +0100 Subject: PIL for the Python 3.2.3 In-Reply-To: References: Message-ID: On 15/06/2012 13:18, Gonzalo de Soto wrote: > Dear Python Org, > > It wanted to know if already PIL's > version is available for Python 3.2.3. > > > > Thanks. > > Gonzalo > Please refer to Matthew 7:7 for a way forward. -- Cheers. Mark Lawrence. From emile at fenx.com Fri Jun 15 08:58:16 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 15 Jun 2012 05:58:16 -0700 Subject: PIL for the Python 3.2.3 In-Reply-To: References: Message-ID: On 6/15/2012 5:18 AM Gonzalo de Soto said... > Dear Python Org, > > It wanted to know if already PIL's version is available for Python 3.2.3. > Not yet. See http://www.pythonware.com/products/pil/ Emile From alec.taylor6 at gmail.com Fri Jun 15 09:11:25 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 15 Jun 2012 23:11:25 +1000 Subject: PIL for the Python 3.2.3 In-Reply-To: References: Message-ID: On Fri, Jun 15, 2012 at 10:18 PM, Gonzalo de Soto wrote: > Dear Python Org,**** > > It wanted to know if already PIL's > version is available for Python 3.2.3.**** > > ** ** > > Thanks.**** > > Gonzalo**** > > **** > > ** ** > > * * > > ** ** > > -- > http://mail.python.org/mailman/listinfo/python-list > > Looks like the PIL fork "Pillow" is coming close to support for Python 3: https://github.com/collective/Pillow/pull/25 -------------- next part -------------- An HTML attachment was scrubbed... URL: From research at johnohagan.com Fri Jun 15 09:49:09 2012 From: research at johnohagan.com (John O'Hagan) Date: Fri, 15 Jun 2012 23:49:09 +1000 Subject: Threads vs subprocesses Message-ID: <20120615234909.d509d3ce182ed78f4c43e9d0@johnohagan.com> I have a program in which the main thread launches a number of CPU-intensive worker threads. For each worker thread two python subprocesses are started, each of which runs in its own terminal: one displays output received from the worker thread via a socket, the other takes text input to control the thread (this is done by having another thread receive the input via a socket and write to the worker thread's arguments). So far so good, but it occurred to me that instead of launching all these worker threads, I could just put their target code in separate executable files and launch them as subprocesses. That way there would be fewer threads, but each subprocess would be doing more work. My question is, on a single core machine, what are the pros and cons of threads vs subprocesses in a setup like this? Thanks, John From jiangwen365 at gmail.com Fri Jun 15 10:08:41 2012 From: jiangwen365 at gmail.com (=?GB2312?B?va3OxA==?=) Date: Fri, 15 Jun 2012 22:08:41 +0800 Subject: PyPyODBC 0.5 alpha released! (A Pure Python ODBC module) Message-ID: PyPyODBC - A Pure Python ctypes ODBC module Features - Pure Python, compatible with?PyPy?(tested on Win32) - Almost totally same usage as?pyodbc You can simply try pypyodbc in your existing pyodbc powered script with the following changes: #import pyodbc ? ? ? ? ? ? ? <-- Comment out the original pyodbc importing line import pypyodbc as pyodbc ? ? # Let pypyodbc "pretend" the pyodbc pyodbc.connect(...) ? ? ? ? ? # This is pypyodbc pretending pyodbc! They have same APIs! ... Homepage: http://code.google.com/p/pypyodbc/ Demo Script: http://code.google.com/p/pypyodbc/source/browse/trunk/pypyodbc/test.py From torriem at gmail.com Fri Jun 15 10:19:47 2012 From: torriem at gmail.com (Michael Torrie) Date: Fri, 15 Jun 2012 08:19:47 -0600 Subject: python's future? In-Reply-To: <1e37eed4-bf4c-4a3e-9981-415f4df2f76c@x6g2000pbh.googlegroups.com> References: <1e37eed4-bf4c-4a3e-9981-415f4df2f76c@x6g2000pbh.googlegroups.com> Message-ID: <4FDB4483.5080503@gmail.com> On 06/15/2012 01:04 AM, Yesterday Paid wrote: > I'm very new to programing though I learn very little of java,C > I love python and have fun to do something with it > but some people said python's future perhaps not that bright. > I know this question maybe looks like an idiot:( > I really hope the python rules long~ time. > what do you think about future of this lang > or famous lang like C, JAVA, C#, LISP &C If it works for you, use, it. If not, move on to a more appropriate language. Python may be more appropriate for some tasks than others. And as others have said, it's well-supported by its developers, and has a rich library to draw on. So there's no reason not to use it now. Either Python 2.x or Python 3.x, though it appears that targeting Python 3 maybe wisest. If in the future Python fades away, you will simply move onto another language. A good programmer should be able to rapidly transition from language to language as appropriate. And even if in fact Python should die, there are other languages that have been inspired by Python, and will hopefully continue a semblance of Pythonic goodness. From news at blinne.net Fri Jun 15 10:48:00 2012 From: news at blinne.net (Alexander Blinne) Date: Fri, 15 Jun 2012 16:48:00 +0200 Subject: which one do you prefer? python with C# or java? In-Reply-To: <7xlijpukjj.fsf@ruckus.brouhaha.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> <7xfwa2vr2h.fsf@ruckus.brouhaha.com> <7x1ulmoo24.fsf@ruckus.brouhaha.com> <4fd629ae$0$9515$9b4e6d93@newsspool1.arcor-online.net> <7xlijpukjj.fsf@ruckus.brouhaha.com> Message-ID: <4fdb4b21$0$9514$9b4e6d93@newsspool1.arcor-online.net> On 15.06.2012 09:00, Paul Rubin wrote: > Alexander Blinne writes: >>> def gen_s(): >>> s = [1] >>> m = skipdups(heapq.merge(*[(lambda j: (k*j for k in s))(n) for n in [2,3,5]])) >>> yield s[0] >>> while True: >>> k = m.next() >>> s.append(k) >>> yield k > > Nice. I wouldn't have been sure that "for k in s" worked properly when > s was changing like that. I just tried it and it worked. Not sure if it is guaranteed. > There is a space complexity problem compared to the Scheme or Haskell > version: all the s[i]'s are saved in the s array, instead of being > discarded once they are yielded. That means generating n elements needs > O(n) space instead of O(n**0.7) or something like that. I guess you can > get around it with collections.deque instead of a list. An Element of s could be discarded, after every one of the three (k*j for k in s)-generators went over it. I don't think that this is possible with one deque (at least with the built-in merger of heapq, a self-written one could be adapted). Storing everything three times (one deque for every generator) would be a mess as well. "Manual" garbage collection could be done by discarding all elements smaller one fifth of the current element of s, because the three generators already went by them. This could be done with a deque. How do Haskell or Scheme determine when elements are not longer needed? Greetings From edcjones at comcast.net Fri Jun 15 11:12:18 2012 From: edcjones at comcast.net (Edward C. Jones) Date: Fri, 15 Jun 2012 11:12:18 -0400 Subject: Hashable object with self references OR how to create a tuple that refers to itself Message-ID: <4FDB50D2.2080706@comcast.net> I am trying to create a collection of hashable objects, where each object contains references to other objects in the collection. The references may be circular. To simplify, one can define x= list() x.append(x) which satisfies x == [x]. Can I create a similar object for tuples which satisfies x == (x,)? From ramit.prasad at jpmorgan.com Fri Jun 15 11:26:35 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 15 Jun 2012 15:26:35 +0000 Subject: does python have bright future? In-Reply-To: <939c24f6-0194-44c0-8fe3-ab61a0eb7863@m2g2000pbv.googlegroups.com> References: <939c24f6-0194-44c0-8fe3-ab61a0eb7863@m2g2000pbv.googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D958FF@SCACMX008.exchad.jpmchase.net> > I'm very new to programing though I learn very little of java,C > I love python and have fun to do something with it > but some people said python's future perhaps not that bright. > I know this question maybe looks like an idiot:( > I really hope the python rules long~ time. > what do you think about future of this lang > or famous lang like C, JAVA, C#, LISP &C Well, some people think the world will end in 2012 so I would say that Python's future is pretty dim. :) On a more serious note, it really depends on what you mean by future. 1 year, 5 years, 20 years or 100 years? At the moment I do not see any of the mentioned languages going away in the next 2-3 or even 5 years but technology can change rapidly. I am not sure there is really a dominant LISP language so that might change but as a family I doubt it goes away. As for Python, it has been around for two decades and seems to be growing in popularity (just my opinion, not based on fact). I expect it will be around for another decade or two. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From mhrivnak at hrivnak.org Fri Jun 15 11:43:08 2012 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Fri, 15 Jun 2012 11:43:08 -0400 Subject: Python script for device automatic update. In-Reply-To: <9635b432-3a9c-4820-bd51-658c1dcda829@googlegroups.com> References: <9635b432-3a9c-4820-bd51-658c1dcda829@googlegroups.com> Message-ID: Let udev run your script when the appropriate device is connected. http://www.reactivated.net/writing_udev_rules.html Then you just need to run an ssh command against the correct mount point. Honestly, python might be overkill for this. Consider writing a very small bash script. Michael On Fri, Jun 15, 2012 at 6:41 AM, LoadWalker wrote: > Hi, > I am completly new to python. > I need to create and script that needs to do the following steps and would apreciate if someone can give me the guidelines to do it as will be my first python script: > > The script will be in a linux machine. > Will wait for a device to conect on the usb. So needs to constantly check for a new driver usb connection. > At the same time looks for new .zip files in a remote URL that contains a file to be copied to the device. > So that one a device connectets to the machine it gets copied via ssh the last content of the .zip file. > > > Is it possible to do it in Python? > -- > http://mail.python.org/mailman/listinfo/python-list From d at davea.name Fri Jun 15 11:51:01 2012 From: d at davea.name (Dave Angel) Date: Fri, 15 Jun 2012 11:51:01 -0400 Subject: Threads vs subprocesses In-Reply-To: <20120615234909.d509d3ce182ed78f4c43e9d0@johnohagan.com> References: <20120615234909.d509d3ce182ed78f4c43e9d0@johnohagan.com> Message-ID: <4FDB59E5.9020708@davea.name> On 06/15/2012 09:49 AM, John O'Hagan wrote: > I have a program in which the main thread launches a number of CPU-intensive > worker threads. For each worker thread two python subprocesses are started, > each of which runs in its own terminal: one displays output received from the > worker thread via a socket, the other takes text input to control the thread > (this is done by having another thread receive the input via a socket and write > to the worker thread's arguments). > > So far so good, but it occurred to me that instead of launching all these > worker threads, I could just put their target code in separate executable > files and launch them as subprocesses. That way there would be fewer threads, > but each subprocess would be doing more work. > > My question is, on a single core machine, what are the pros and cons of > threads vs subprocesses in a setup like this? > > Thanks, > > John Two key phrases in your message; CPU-intensive, single-core-machine. If these have the conventional meaning, you're better off doing all the processing in your main executable, without threads at all. Neither threads nor separate process speed up CPU-intensive execution on a single-core machine. Now, your single core is probably hyper-threaded, so you MIGHT get some improvement from one extra thread. Or you might have other reasons for multiple threads, such as ease of dealing with multiple processes. But if you let them compete for a single core, they'll slow things down. DaveA -- DaveA From news at schwertberger.de Fri Jun 15 12:35:47 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Fri, 15 Jun 2012 18:35:47 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_____Interface_Builder_=28Re=3A?= =?ISO-8859-1?Q?_what_gui_designer_is_everyone_using=29?= In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: Am 15.06.2012 01:07, schrieb Dennis Lee Bieber: > Visual Basic was essentially developed as a unified whole (drop a Sure. I prefer modular approaches. I don't see why this should not be possible (e.g. an IDE like Wing integrates well with other tools and frameworks; I'm sure it could also integrate with a GUI builder). > VB6 "form" module into a pure text editor and look at how much hidden > code was embedded)... I did so several times before. It's nothing that you want to create manually, but you can fix small items there and also, being text based, it works with revision control systems and can be printed for documentation purposes. > Have you ever seen the crud created by Visual C++? I'd rather create No. And I don't have plans to. C/C++ is good as a system-level language but I don't see the point in using it for implementation of a GUI or business logic. > a GUI using Fujitsu COBOL version 4 (unfortunately, the installer that > came with my Y2K COBOL book(s) doesn't work on WinXP and I no longer > have a Win98 system; wonder if it can run under Win7 using one of the > compatibility modes; I think v4 itself would work -- it is just the > installer doing something odd; v3, OTOH, is a 16-bit application) If you have access to a Win98 system, you could try to install there an move only the installed program to your current PC (including any DLLs from the system folder). Well-written software does not need an installer. Just move where you want to have it and execute (works well with Python; you can e.g. run a shared installation from the network, even though I would not recommend this for processes requiring highest reliability). IMHO under Windows installers and the crappy start menus are a side effect of the initial decision to separate into File Manager and Program Manager. Other platforms did things better from a UI and technical point of view, but not from a commercial one... (E.g. Acorn's RISC OS where you could even run software from within zip archives as it had the equivalent of user-space file systems twenty years ago already.) Regards, Dietmar From tismer at stackless.com Fri Jun 15 12:39:59 2012 From: tismer at stackless.com (Christian Tismer) Date: Fri, 15 Jun 2012 18:39:59 +0200 Subject: tiffany 0.4 released Message-ID: <4FDB655F.7020600@stackless.com> Tiffany - Read/Write Multipage-Tiff with PIL without PIL ======================================================== Tiffany stands for any tiff. The tiny module solves a large set of problems, has no dependencies and just works wherever Python works. Tiffany was developed in the course of the *DiDoCa* project and will now appear on PyPi. Version 0.4 ----------- This is a compatibility update for Python 2.6. I hope to submit Python 3.2 compatibility with version 0.5. Please let me know if this stuff works for you, and send requests to or use the links in the bitbucket website: https://bitbucket.org/didoca/tiffany cheers -- Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From news at schwertberger.de Fri Jun 15 12:45:33 2012 From: news at schwertberger.de (Dietmar Schwertberger) Date: Fri, 15 Jun 2012 18:45:33 +0200 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= In-Reply-To: <6c928a7a-6ffb-48c4-b0c6-0715678cc0f8@tx6g2000pbc.googlegroups.com> References: <19e8593c-26ea-49c7-af76-01f85fa42387@t2g2000pbl.googlegroups.com> <6c928a7a-6ffb-48c4-b0c6-0715678cc0f8@tx6g2000pbc.googlegroups.com> Message-ID: Am 13.06.2012 18:30, schrieb rdsteph at mac.com: > about Google's "Blockly" a drag and drop tool for building apps that > outputs Python or Javascript code (among others) and it might be > usable along these lines...I'm sure serious programmers would not use > it but maybe engineers looking to make web front ends > for data acquisition or data base apps might use it... Actually, there are mouse based tools for engineers, but they are more focused on data flow. For the low level they need to fall back to something similar to Blockly. That's the reason why I don't want to use them. Still they have a significant market share. With Python not having an easy-to-use GUI builder, I don't see how to get people to move from such tools to Python. For the data acquisition and processing itself I could well imagine them to see the potential, but when it comes to implementation of a complete program... (Most people consider a software without GUI as incomplete.) Regards, Dietmar From rtomek at ceti.pl Fri Jun 15 13:03:10 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Fri, 15 Jun 2012 19:03:10 +0200 Subject: which one do you prefer? python with C# or java? In-Reply-To: <4fdb4b21$0$9514$9b4e6d93@newsspool1.arcor-online.net> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> <7xfwa2vr2h.fsf@ruckus.brouhaha.com> <7x1ulmoo24.fsf@ruckus.brouhaha.com> <4fd629ae$0$9515$9b4e6d93@newsspool1.arcor-online.net> <7xlijpukjj.fsf@ruckus.brouhaha.com> <4fdb4b21$0$9514$9b4e6d93@newsspool1.arcor-online.net> Message-ID: On Fri, 15 Jun 2012, Alexander Blinne wrote: > How do Haskell or Scheme determine when elements are not longer needed? Just like Python, they use garbage collection - in one sentence, if it can be proved the object (not a OO-object, just a piece of data) will no longer be needed, it can be safely deleted - and the code will work as if nothing happened, because the proof said it won't need this data in the future (so you need a right proving technique). Now, the difference is, Scheme (and Lisps AFAIK) and Haskell (and those functional langs I heard of) posess one neat data type, linked list. They also allow for tail-call recursion, which - if one organises one's code properly - means infinite recursion, if one needs it. Some problems are expressed in an elegant and natural manner as linked lists (head to be processed now and rest/tail to be processed later). Such linked lists are ideal fit for tail-call recursion - you process a head and recurse with results and tail in place of original list (thus becoming a next level head+tail list). If no other piece of code stores your current head in a variable (simply speaking), it can be proven that head is no longer needed. Once you call your function recursively, head is waiting to be GC-ed. Your code does not need to worry about this. Last time I checked, Python didn't have linked lists - arrayed lists are nice, but their elements can't be automatically GC-ed (or, this requires very nontrivial GC algorithm), the easiest way I can think would be replacing them with None manually. I'm not sure if del is performance-nice. Also, around the same time, Python couldn't do tail-call, so the whole point of having linked lists was kind of theoretical. Even more cool, with lazy evaluation (like in Haskell) one can generate lists on a fly and process them like they were statically allocated. Say, you only have a 2GB of ram but would like to process 128GB of list, generated ad hoc as your program runs? Like, counting all even numbers less than 2**39 - this is trivial, I know (2**38), but you could run such code with 2GB of ram. Your code processes head and when it recurses with tail, the new head (next number) is generated, so it can be processed. And so on. And thanks to lazy evaluation, you don't need to think about it, this is the job of compiler to organize your program in such way. Yes, you could also run it in a loop or simulate lazy-eval manually (with yield) but the point here is you can have more choice for your algorithm with some languages and in some other languages (Ruby belongs here, too, AFAIK) you don't use recursion (too much) even if you'd like to. Myself, I love more choice, but of course everybody can have his own preferences. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From chris at python.org Fri Jun 15 13:14:28 2012 From: chris at python.org (Chris Withers) Date: Fri, 15 Jun 2012 18:14:28 +0100 Subject: Need a Python Developer... In-Reply-To: References: Message-ID: <4FDB6D74.3020305@python.org> On 05/06/2012 19:18, o2kcompliant wrote: > Hi Guys, > > I have a need for a Python Developer... How about using the Python job board rather than spamming the mailing list: http://www.python.org/community/jobs/howto/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From research at johnohagan.com Fri Jun 15 13:24:13 2012 From: research at johnohagan.com (John O'Hagan) Date: Sat, 16 Jun 2012 03:24:13 +1000 Subject: Threads vs subprocesses In-Reply-To: <4FDB59E5.9020708@davea.name> References: <20120615234909.d509d3ce182ed78f4c43e9d0@johnohagan.com> <4FDB59E5.9020708@davea.name> Message-ID: <20120616032413.aee179153e7b6b4a0df62d07@johnohagan.com> On Fri, 15 Jun 2012 11:51:01 -0400 Dave Angel wrote: > On 06/15/2012 09:49 AM, John O'Hagan wrote: > > I have a program in which the main thread launches a number of CPU-intensive > > worker threads. For each worker thread two python subprocesses are started, [...] > > > > So far so good, but it occurred to me that instead of launching all these > > worker threads, I could just put their target code in separate executable > > files and launch them as subprocesses. That way there would be fewer > > threads, but each subprocess would be doing more work. > > > > My question is, on a single core machine, what are the pros and cons of > > threads vs subprocesses in a setup like this? > > [...] > > Two key phrases in your message; CPU-intensive, > single-core-machine. If these have the conventional meaning, you're > better off doing all the processing in your main executable, without > threads at all. > > Neither threads nor separate process speed up CPU-intensive execution on > a single-core machine. [...] I should have made it clear that I'm not using threads to speed anything up; each thread produces an independently controlled, timed stream of musical events. I think it would be hard to achieve that in a single process. The streams need to run simultaneously without getting out of sync or dropping notes, which begins to happen if there are a lot of them, or they are run very fast or are very calculation-intensive to produce. So I guess what I'm really asking is, given that I need to use threads or subprocesses, which approach slows the processing down the least? John From no.email at nospam.invalid Fri Jun 15 13:32:03 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 15 Jun 2012 10:32:03 -0700 Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> <7xfwa2vr2h.fsf@ruckus.brouhaha.com> <7x1ulmoo24.fsf@ruckus.brouhaha.com> <4fd629ae$0$9515$9b4e6d93@newsspool1.arcor-online.net> <7xlijpukjj.fsf@ruckus.brouhaha.com> <4fdb4b21$0$9514$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <7xwr38pjl8.fsf@ruckus.brouhaha.com> Alexander Blinne writes: > An Element of s could be discarded, after every one of the three (k*j > for k in s)-generators went over it. I don't think that this is possible > with one deque (at least with the built-in merger of heapq, a > self-written one could be adapted). Storing everything three times (one > deque for every generator) would be a mess as well. I think for 3 lists I'd have just merged manually instead of figuring out the heapq merge. The deque approach sounds straightforward but often there is subtlety, so I'll have to try it. > How do Haskell or Scheme determine when elements are not longer needed? Normal gc, once there is no reference to an elemeent it is released. Actually again there may be a subtlety, if there is a symbol pointing to the stream. I'll check into this but I think when I tested it in Haskell, it did the right thing. From dieter at handshake.de Fri Jun 15 14:22:33 2012 From: dieter at handshake.de (Dieter Maurer) Date: Fri, 15 Jun 2012 20:22:33 +0200 Subject: Hashable object with self references OR how to create a tuple that refers to itself References: <4FDB50D2.2080706@comcast.net> Message-ID: <87r4tgv3iu.fsf@handshake.de> "Edward C. Jones" writes: > I am trying to create a collection of hashable objects, where each > object contains references to > other objects in the collection. The references may be circular. > > To simplify, one can define > x= list() > x.append(x) > which satisfies x == [x]. > Can I create a similar object for tuples which satisfies x == (x,)? You can create a tuple in "C" and then put a reference to itself into it, but I am quite convinced that you cannot do it in Python itself. (Of course, you could use "cython" to generate C code with a source language very similar to Python). But, you do not need tuples; You could use a standard class: >>> class C(object): pass ... >>> c=C() >>> c.c=c >>> d=dict(c=c) >>> d {'c': <__main__.C object at 0xb737f86c>} -- Dieter From ramit.prasad at jpmorgan.com Fri Jun 15 14:22:40 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 15 Jun 2012 18:22:40 +0000 Subject: Threads vs subprocesses In-Reply-To: <20120616032413.aee179153e7b6b4a0df62d07@johnohagan.com> References: <20120615234909.d509d3ce182ed78f4c43e9d0@johnohagan.com> <4FDB59E5.9020708@davea.name> <20120616032413.aee179153e7b6b4a0df62d07@johnohagan.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D96090@SCACMX008.exchad.jpmchase.net> > > > My question is, on a single core machine, what are the pros and cons of > > > threads vs subprocesses in a setup like this? > > > > [...] > > > > Two key phrases in your message; CPU-intensive, > > single-core-machine. If these have the conventional meaning, you're > > better off doing all the processing in your main executable, without > > threads at all. > > > > Neither threads nor separate process speed up CPU-intensive execution on > > a single-core machine. > [...] > > I should have made it clear that I'm not using threads to speed anything > up; > each thread produces an independently controlled, timed stream of musical > events. I think it would be hard to achieve that in a single process. The > streams need to run simultaneously without getting out of sync or dropping > notes, which begins to happen if there are a lot of them, or they are run > very > fast or are very calculation-intensive to produce. > > So I guess what I'm really asking is, given that I need to use threads or > subprocesses, which approach slows the processing down the least? Threads to do not really run simultaneously (in CPython) and without multiple CPUs/HT neither do subprocesses. Your machine might be fast enough to *look* like they are but they are not. Technically they might be running "simultaneously" but the CPU will have to keep switching from one calculation to another which just slows all of the calculations down. I would imagine the fastest way to proceed would be to iteratively do the calculations; thread and subprocess creation have their own memory/CPU overheads. In summary a single process/thread on a single core machine would be fastest. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From tjreedy at udel.edu Fri Jun 15 14:45:02 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 15 Jun 2012 14:45:02 -0400 Subject: which one do you prefer? python with C# or java? In-Reply-To: References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> <7xfwa2vr2h.fsf@ruckus.brouhaha.com> <7x1ulmoo24.fsf@ruckus.brouhaha.com> <4fd629ae$0$9515$9b4e6d93@newsspool1.arcor-online.net> <7xlijpukjj.fsf@ruckus.brouhaha.com> <4fdb4b21$0$9514$9b4e6d93@newsspool1.arcor-online.net> Message-ID: On 6/15/2012 1:03 PM, Tomasz Rola wrote: > Last time I checked, Python didn't have linked lists - arrayed lists are > nice, but their elements can't be automatically GC-ed (or, this requires > very nontrivial GC algorithm), the easiest way I can think would be > replacing them with None manually. I'm not sure if del is > performance-nice. Python does not come with a linked-list class, but one can easily use tuples or lists with two items as linked-list cells. One can optionally wrap such cell in a linked-list class. However, if array lists do the job, which they usually do, using linked-lists will take more time and space. The problem being discussed may be a case where they are useful and make it easier to save space. > Also, around the same time, Python couldn't do tail-call, Nonsense. A tail call is a call temporally followed by a return. In CPython bytecode, it would be a call followed by return. In Python code, it is a call spatially preceded by 'return'. Any "return f(whatever)", a common operation is a tail call. I presume you actually mean that CPython does not automatically convert tail calls into local assignments and a jump to reuse the existing execution frame instead of a new one. True. A Python interpreter could easily detect all tail calls at either compilation or execution, but such conversions would erase call history, leaving gaps in exception tracebacks and make debugging harder. Depending on your viewpoint, such conversion might be considered a semantic change. Selectively converting recursive tail calls has specific problems that have been discussed on other threads, and it would *still* erase the call history that one might need to debug. If you do branching recursion, as with a tree, and there is an unexpected exception, you most likely really do want to see the complete call path leading up to the exception. In addition, it is a feature that non-terminating recursions such as "def forever(): return forever()" get stopped. In any case, a properly written linear tail-recursive function is, usually, easily converted to an explicit while loop. So if you want within-frame looping, write it explicitly. To illustrate one general pattern: def tail_rec(a, b=start): # use default arg to avoid nesting if should_loop(a, b): return tail_rec(A(a,b), B(a,b)) else: return term(a, b) def while_equiv(a, b=start): while should_loop(a, b): a, b = A(a,b), B(a,b) else: return term(a, b) In practice, should_loop, A, and B will usually be in-line expressions rather than calls. There may be additional statements after if, else, and while headers. In while_equiv, move b=start into the body. Else is typically omitted from the while version, but I prefer it in the recursive version. One downside of the space saving is that the history of a,b values is invisible unless one add a debug print statement. Another is that the forever function becomes def forever(): while True: pass and Python will never stop it without intervention. > Even more cool, with lazy evaluation (like in Haskell) one can generate > lists on a fly and process them like they were statically allocated. Python iterators can do lazy evaluation. All the builtin classes come with a corresponding iterator. > Yes, you could also run it in a loop or simulate lazy-eval manually (with > yield) There is nothing simulated about yield. Python mostly does what you tell it to do. You just have to learn how to tell it to do what you want. -- Terry Jan Reedy From tjreedy at udel.edu Fri Jun 15 14:52:38 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 15 Jun 2012 14:52:38 -0400 Subject: Use of internal ctypes objects In-Reply-To: References: Message-ID: On 6/15/2012 4:28 AM, RICHARD MOSELEY wrote: >> To check whether the function has been previously converted, I make use > of internal objects within the ctypes module, namely, _SimpleCData and > _CFuncPtr. Is this a safe thing to do, bearing in mind that the objects > are documentated as internal? It depends on what you mean by 'safe'. "Internal" generally means 'use at your own risk' and 'subject to change (in future releases) without notification'. On the other hand, they should not silently reformat your disk ;-). -- Terry Jan Reedy From no.email at nospam.invalid Fri Jun 15 15:04:29 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 15 Jun 2012 12:04:29 -0700 Subject: which one do you prefer? python with C# or java? References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> <7xfwa2vr2h.fsf@ruckus.brouhaha.com> <7x1ulmoo24.fsf@ruckus.brouhaha.com> <4fd629ae$0$9515$9b4e6d93@newsspool1.arcor-online.net> <7xlijpukjj.fsf@ruckus.brouhaha.com> <4fdb4b21$0$9514$9b4e6d93@newsspool1.arcor-online.net> Message-ID: <7xpq90pfb6.fsf@ruckus.brouhaha.com> Terry Reedy writes: > Python iterators can do lazy evaluation. All the builtin classes come > with a corresponding iterator. ... I wouldn't say iterators do lazy evaluation in the Scheme or Haskell sense. Lazy evaluation imho means evaluation is deferred until you actually try to use the value, and when you use it, it is computed and kept around for later re-use (until it becomes gc-able). Python iterators simply generate one value at a time and leave retention of old values to be managed by the programmer. > There is nothing simulated about yield. Python mostly does what you > tell it to do. You just have to learn how to tell it to do what you > want. I'd be interested in seeing a clean implementation of that algorithm using python iterators. From tkacvins at gmail.com Fri Jun 15 15:10:08 2012 From: tkacvins at gmail.com (Tom Kacvinsky) Date: Fri, 15 Jun 2012 12:10:08 -0700 (PDT) Subject: Installing numpy over an older numpy Message-ID: <11ad3161-e868-4c76-b451-a92754ae7cd8@googlegroups.com> I am having problems installing a newer version of numpy over an older installation. The general problem is that the older version's distutils code is being used instead of the distutils code in the newer version, no matter how much I play around with sys.path in setup.py and the like. Any ideas on how to install a newer version over an older version? Thanks, Tom From miki.tebeka at gmail.com Fri Jun 15 15:15:56 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 15 Jun 2012 12:15:56 -0700 (PDT) Subject: Installing numpy over an older numpy In-Reply-To: <11ad3161-e868-4c76-b451-a92754ae7cd8@googlegroups.com> References: <11ad3161-e868-4c76-b451-a92754ae7cd8@googlegroups.com> Message-ID: <24e04ced-1f5e-4fa3-a335-27e7d23cc266@googlegroups.com> > Any ideas on how to install a newer version over an older version? pip uninstall numpy pip install numpy From ahaidamaka at gmail.com Fri Jun 15 15:47:11 2012 From: ahaidamaka at gmail.com (Alexey Gaidamaka) Date: Fri, 15 Jun 2012 19:47:11 +0000 (UTC) Subject: PyDoc - Python Documentation Plugin for Eclipse References: <4FD46567.2080003__19477.5355667391$1339355024$gmane$org@gmail.com> Message-ID: On Sun, 10 Jun 2012 12:14:15 +0300, Alexey Gaidamaka wrote: > Greets! > > Since i'm new to Python, i've decided to create a handy plugin for > Elipse SDK which is my primary dev environment. Practically the plugin > is a simple html archive from python documentation website running > inside Eclipse so you can call it using Eclipse help system. As for now > it is pretty large (~7 mb), but i'm planning to optimize it in near > future. > > For more information, please visit: > > http://pydoc.tk/ > > or > > https://sourceforge.net/projects/pydoc/ > ------------------------------------------------------------------------ > > Advices are appreciated! > > Contact e-mail:
> > ahaidamaka at gmail.com Hi there again! I've made up some minor changes in plugin. Now it works with online documentation from docs.python.org and supports online doc for 2.6, 2.7, 3.2, 3.3. Plugin weights around 8KB because all the static content was deleted. Additional infos are here: http://pydoc.tk/news.html From ahaidamaka at gmail.com Fri Jun 15 15:50:07 2012 From: ahaidamaka at gmail.com (Alexey Gaidamaka) Date: Fri, 15 Jun 2012 19:50:07 +0000 (UTC) Subject: PyDoc - Python Documentation Plugin for Eclipse References: <4FD46567.2080003@gmail.com> <4FD4675F.3080404@gmail.com> <4FD470BB.8030002@gmail.com> Message-ID: On Sun, 10 Jun 2012 15:37:50 +0000, Alexey Gaidamaka wrote: > On Sun, 10 Jun 2012 05:02:35 -0500, Andrew Berg wrote: > >> On 6/10/2012 4:22 AM, Alexey Gaidamaka wrote: >>> Practically the plugin is a simple html archive from python >>> documentation website running >>> inside Eclipse so you can call it using Eclipse help system. As for >>> now it is pretty large (~7 mb), but i'm planning to optimize it in >>> near future. >> Rather than archive documentation, why not use a simple static page >> that points to the different sections for each version of Python on >> docs.python.org? The 2.7.3 documentation is mostly useless to me since >> I'm using 3.3 (and of course there are some using 2.6 or 3.2 or >> 3.1...), but I can easily access it from a link in the page you've >> archived. Not only would this reduce the size of the plugin to almost >> nothing, but it would prevent the documentation from being outdated. >> >>> For more information, please visit: >>> https://sourceforge.net/projects/pydoc/ >> Why isn't it installed like other Eclipse plugins? Is it even possible >> to update the plugin via Eclipse? >> >> >> This does look like a very useful plugin, though. Great idea. > > Thanx! All that you've mentioned is planned in the next versions of the > plugin. http://pydoc.tk/news.html TBD: 1. updating and installing plugin through standard Eclipse "work with..." dialogue 2. reduce size of the original plugin that utilizes static content From ramit.prasad at jpmorgan.com Fri Jun 15 16:23:50 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 15 Jun 2012 20:23:50 +0000 Subject: Hashable object with self references OR how to create a tuple that refers to itself In-Reply-To: <87r4tgv3iu.fsf@handshake.de> References: <4FDB50D2.2080706@comcast.net> <87r4tgv3iu.fsf@handshake.de> Message-ID: <5B80DD153D7D744689F57F4FB69AF47412D9656E@SCACMX008.exchad.jpmchase.net> > > I am trying to create a collection of hashable objects, where each > > object contains references to > > other objects in the collection. The references may be circular. > > > > To simplify, one can define > > x= list() > > x.append(x) > > which satisfies x == [x]. > > Can I create a similar object for tuples which satisfies x == (x,)? > > You can create a tuple in "C" and then put a reference to itself into it, > but I am quite convinced that you cannot do it in Python itself. > (Of course, you could use "cython" to generate C code with a source > language > very similar to Python). > > But, you do not need tuples; You could use a standard class: > > >>> class C(object): pass > ... > >>> c=C() > >>> c.c=c > >>> d=dict(c=c) > >>> d > {'c': <__main__.C object at 0xb737f86c>} > Using a class is a good approach. You can also override __contains__ for the custom classes internal collection so instead of x==[x,] you would use x in obj where obj is a collection with the equivalent [x,]. Not entirely sure why Dieter is bringing up C code / Cython... Just as a note, if you store references to an object A in the collection in another object B in the collection and then try to remove A from the collection it will not get garbage collected nor removed from B. To allow for garbage collection you should store a weakref instead. http://docs.python.org/library/weakref.html Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From albert at spenarnc.xs4all.nl Fri Jun 15 17:25:09 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 15 Jun 2012 21:25:09 GMT Subject: usenet reading References: <48b26758-71ab-4da8-832a-5ed1dc967781@googlegroups.com> Message-ID: In article , Colin Higwell wrote: >On Fri, 25 May 2012 15:38:55 -0700, Jon Clements wrote: > >> >> Is there a server out there where I can get my news groups? I use to be >> with an ISP that hosted usenet servers, but alas, it's no longer >> around... >> >I use Albasani.net (free and very reliable), as well as gmane.org. > >Google Groups is an abomination IMHO, and I find it much easier to read >mailing lists via a newsreader. I highly recommend Pan, by the way. I still use UUCP. This machine is a UUCP node (spenarnc.xs4all.nl). I fetch my mail and news using a UUCP-feed (login over the internet with ADSL to a machine of xs4all). From that moment on it is a newsserver. I can access it from other machines on my network or I could make it available to friends over the internet. (Not that I plan to do that.) I can use any newsreader, and it is fast/instantaneous. Set this stuff up in 1994 with Coherent. Upgraded to Linux, and upgraded the hardware a couple of times. Running on a Pentium 120 Mhz now. I take it for granted but last time I heard, UUCP was down to less than a dozen users with this service. Groetjes Albert > -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From cmpython at gmail.com Fri Jun 15 19:35:52 2012 From: cmpython at gmail.com (CM) Date: Fri, 15 Jun 2012 16:35:52 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <19e8593c-26ea-49c7-af76-01f85fa42387@t2g2000pbl.googlegroups.com> <6c928a7a-6ffb-48c4-b0c6-0715678cc0f8@tx6g2000pbc.googlegroups.com> Message-ID: Dietmar quotes: > With Python not having an easy-to-use GUI builder, > The point is, that if you want to promote Python as replacement > for e.g. VB, Labview etc., then an easy-to-use GUI builder is required. > The typical GUI programs will just have an input mask, a button and one > or two output fields. > On the other hand, I need to know wx very well to be able to create > a GUI using wxGlade as otherwise I will never find where to add > e.g. the handlers. > But when I know wx very well, then there's no point in using wxGlade. In response to all of these and the general heavily repeated mantra here that "there is no easy to use GUI builder for Python", OK, tell you what: describe what the "GUI that an engineer would want to make" should look like--give all widgets and their bindings--and I will see about making a video that shows how easy this is to do with a GUI builder, even with the user having a very rudimentary (or perhaps zero) knowledge of wxPython. And it will be timed. Let's test your idea for real. (I should note, I don't know what an "input mask" refers to above). From jason at powerpull.net Fri Jun 15 19:42:04 2012 From: jason at powerpull.net (Jason Friedman) Date: Fri, 15 Jun 2012 17:42:04 -0600 Subject: python3 raw strings and \u escapes In-Reply-To: <4FC5CB68.9070108@gmail.com> References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> <4FC5CB68.9070108@gmail.com> Message-ID: This is a related question. I perform an octal dump on a file: $ od -cx file 0000000 h e l l o w o r l d \n 6568 6c6c 206f 6f77 6c72 0a64 I want to output the names of those characters: $ python3 Python 3.2.3 (default, May 19 2012, 17:01:30) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import unicodedata >>> unicodedata.name("\u0068") 'LATIN SMALL LETTER H' >>> unicodedata.name("\u0065") 'LATIN SMALL LETTER E' But, how to do this programatically: >>> first_two_letters = "6568 6c6c 206f 6f77 6c72 0a64".split()[0] >>> first_two_letters '6568' >>> first_letter = "00" + first_two_letters[2:] >>> first_letter '0068' Now what? From python at mrabarnett.plus.com Fri Jun 15 20:20:28 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 16 Jun 2012 01:20:28 +0100 Subject: python3 raw strings and \u escapes In-Reply-To: References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> <4FC5CB68.9070108@gmail.com> Message-ID: <4FDBD14C.1010804@mrabarnett.plus.com> On 16/06/2012 00:42, Jason Friedman wrote: > This is a related question. > > I perform an octal dump on a file: > $ od -cx file > 0000000 h e l l o w o r l d \n > 6568 6c6c 206f 6f77 6c72 0a64 > > I want to output the names of those characters: > $ python3 > Python 3.2.3 (default, May 19 2012, 17:01:30) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import unicodedata >>>> unicodedata.name("\u0068") > 'LATIN SMALL LETTER H' >>>> unicodedata.name("\u0065") > 'LATIN SMALL LETTER E' > > But, how to do this programatically: >>>> first_two_letters = "6568 6c6c 206f 6f77 6c72 0a64".split()[0] >>>> first_two_letters > '6568' >>>> first_letter = "00" + first_two_letters[2:] >>>> first_letter > '0068' > > Now what? >>> hex_code = "65" >>> unicodedata.name(chr(int(hex_code, 16))) 'LATIN SMALL LETTER E' From jason at powerpull.net Fri Jun 15 22:14:40 2012 From: jason at powerpull.net (Jason Friedman) Date: Fri, 15 Jun 2012 20:14:40 -0600 Subject: python3 raw strings and \u escapes In-Reply-To: <4FDBD14C.1010804@mrabarnett.plus.com> References: <06ad6696-7ede-491b-9b2c-ef940effef09@w19g2000yqb.googlegroups.com> <4FC5CB68.9070108@gmail.com> <4FDBD14C.1010804@mrabarnett.plus.com> Message-ID: >> This is a related question. >> >> I perform an octal dump on a file: >> $ od -cx file >> 0000000 ? h ? e ? l ? l ? o ? ? ? w ? o ? r ? l ? d ?\n >> ? ? ? ? ? ?6568 ? ?6c6c ? ?206f ? ?6f77 ? ?6c72 ? ?0a64 >> >> I want to output the names of those characters: >> $ python3 >> Python 3.2.3 (default, May 19 2012, 17:01:30) >> [GCC 4.6.3] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> >>>>> ?import unicodedata >>>>> ?unicodedata.name("\u0068") >> >> 'LATIN SMALL LETTER H' >>>>> >>>>> ?unicodedata.name("\u0065") >> >> 'LATIN SMALL LETTER E' >> >> But, how to do this programatically: >>>>> >>>>> ?first_two_letters = "6568 ? ?6c6c ? ?206f ? ?6f77 ? ?6c72 >>>>> ?0a64".split()[0] >>>>> ?first_two_letters >> >> '6568' >>>>> >>>>> ?first_letter = "00" + first_two_letters[2:] >>>>> ?first_letter >> >> '0068' >> >> Now what? >>>> hex_code = "65" >>>> unicodedata.name(chr(int(hex_code, 16))) > 'LATIN SMALL LETTER E' Very helpful, thank you MRAB. The finished product: http://pastebin.com/4egQcke2. From tjreedy at udel.edu Fri Jun 15 23:22:12 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 15 Jun 2012 23:22:12 -0400 Subject: which one do you prefer? python with C# or java? In-Reply-To: <7xpq90pfb6.fsf@ruckus.brouhaha.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> <7xfwa2vr2h.fsf@ruckus.brouhaha.com> <7x1ulmoo24.fsf@ruckus.brouhaha.com> <4fd629ae$0$9515$9b4e6d93@newsspool1.arcor-online.net> <7xlijpukjj.fsf@ruckus.brouhaha.com> <4fdb4b21$0$9514$9b4e6d93@newsspool1.arcor-online.net> <7xpq90pfb6.fsf@ruckus.brouhaha.com> Message-ID: On 6/15/2012 3:04 PM, Paul Rubin wrote: > Terry Reedy writes: >> Python iterators can do lazy evaluation. All the builtin classes come >> with a corresponding iterator. ... > > I wouldn't say iterators do lazy evaluation in the Scheme or Haskell > sense. Lazy evaluation imho means evaluation is deferred until you > actually try to use the value, and when you use it, it is computed and > kept around for later re-use (until it becomes gc-able). Python > iterators simply generate one value at a time and leave retention of old > values to be managed by the programmer. Ok, I see the difference. You are talking about something like a memoized __getitem__ that computes and store values as needed. >> There is nothing simulated about yield. Python mostly does what you >> tell it to do. You just have to learn how to tell it to do what you >> want. > > I'd be interested in seeing a clean implementation of that algorithm > using python iterators. I already wrote "The problem being discussed may be a case where [linked lists] are useful and make it easier to save space" -- because, from what I understood, a moving buffer of temporarily saved buffers is needed. -- Terry Jan Reedy From livingstonemark at gmail.com Fri Jun 15 23:24:04 2012 From: livingstonemark at gmail.com (Mark Livingstone) Date: Sat, 16 Jun 2012 13:24:04 +1000 Subject: Academic citation of Python Message-ID: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Hello! I wish to properly cite Python in an academic paper I am writing. Is there a preferred document etc to cite? Thanks in advance, MArkL From alec.taylor6 at gmail.com Fri Jun 15 23:37:51 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 16 Jun 2012 13:37:51 +1000 Subject: Academic citation of Python In-Reply-To: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: Maybe quote the "Programming Python" book, since Guido wrote the forward? http://www.python.org/doc/essays/foreword2/ On Sat, Jun 16, 2012 at 1:24 PM, Mark Livingstone wrote: > Hello! > > I wish to properly cite Python in an academic paper I am writing. > > Is there a preferred document etc to cite? > > Thanks in advance, > > MArkL > -- > http://mail.python.org/mailman/listinfo/python-list From rtomek at ceti.pl Sat Jun 16 00:00:40 2012 From: rtomek at ceti.pl (Tomasz Rola) Date: Sat, 16 Jun 2012 06:00:40 +0200 (CEST) Subject: which one do you prefer? python with C# or java? In-Reply-To: References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> <4FD4A3D9.5040500@redhat.com> <7xwr3fjff8.fsf@ruckus.brouhaha.com> <7xfwa2vr2h.fsf@ruckus.brouhaha.com> <7x1ulmoo24.fsf@ruckus.brouhaha.com> <4fd629ae$0$9515$9b4e6d93@newsspool1.arcor-online.net> <7xlijpukjj.fsf@ruckus.brouhaha.com> <4fdb4b21$0$9514$9b4e6d93@newsspool1.arcor-online.net> Message-ID: On Fri, 15 Jun 2012, Terry Reedy wrote: > On 6/15/2012 1:03 PM, Tomasz Rola wrote: > > > Last time I checked, Python didn't have linked lists - arrayed lists are > > nice, but their elements can't be automatically GC-ed (or, this requires > > very nontrivial GC algorithm), the easiest way I can think would be > > replacing them with None manually. I'm not sure if del is > > performance-nice. > > Python does not come with a linked-list class, but one can easily use tuples > or lists with two items as linked-list cells. One can optionally wrap such > cell in a linked-list class. However, if array lists do the job, which they > usually do, using linked-lists will take more time and space. The problem > being discussed may be a case where they are useful and make it easier to save > space. Yes. I made linked lists in Python few years ago, just to test something. At the time Python was my main algorithmic toy, so I couldn't resist. However, handling the list felt half Pascal-y and half unnatural. Later on, I felt I didn't like cramming everything into arrays and switched to something else. > > Also, around the same time, Python couldn't do tail-call, > > Nonsense. A tail call is a call temporally followed by a return. In CPython > bytecode, it would be a call followed by return. In Python code, it is a call > spatially preceded by 'return'. Any "return f(whatever)", a common operation > is a tail call. Actually I was wrong. http://code.activestate.com/recipes/474088-tail-call-optimization-decorator/ Now I am intrigued because this code just worked a minute ago, on 2.6. Given this was written for 2.4, I was wrong. Definitely something I would like to experiment with a bit. The need for adding decorator takes some joy away but it is interesting. > In practice, should_loop, A, and B will usually be in-line expressions rather > than calls. There may be additional statements after if, else, and while > headers. In while_equiv, move b=start into the body. Else is typically omitted > from the while version, but I prefer it in the recursive version. You see, I spend quite a lot of time playing with concepts etc. Code performance is nice to have, but I prefer to maximize my performance as I write something and move on. If I feel (from my own point of view) something would be nicer to write with recursion, so be it - even though some Common Lisp manual advises to use loops because they are faster. Actually, from what I have tested, this not always is true - both recursion and loops were comparable speed wise in some simple cases I checked. This manual is a bit old, and new compiler had its own say about optimisation, maybe that's the truth behind it. For cases where I really want speed, proper algorithm (if only I can think it) and compilation rule. If algorithm codes better with loops, this is ok. But if it codes better with recursion, this should be ok too, because if I feel better while coding it, I make less errors. > > Even more cool, with lazy evaluation (like in Haskell) one can generate > > lists on a fly and process them like they were statically allocated. > > Python iterators can do lazy evaluation. All the builtin classes come with a > corresponding iterator. This is fine, but I don't mind having more, like the whole language supporting the idea of being lazy. http://stackoverflow.com/questions/265392/why-is-lazy-evaluation-useful > > Yes, you could also run it in a loop or simulate lazy-eval manually (with > > yield) > > There is nothing simulated about yield. Yes, yield is real and not simulated. And one can use it to do tricks with how/when Python evaluates/generates/performs. It is nicer than if I had to write lazy code in, say, C or Pascal, but it doesn't mean one should only use one language rather than choose language according to the task, > Python mostly does what you tell it to do. You just have to learn how to > tell it to do what you want. Well I believe I have already learnt some of it. I am not using Python on a daily basis nowadays, and I am stuck somewhere in 2.x land. To stay in this semicurrent state I read this group and, from time to time, some shorter PEPs. So I think I can tell Python a thing or two, but at the same time I don't want to tell it everything, everytime. :-) I like telling things in a language that sounds better, which depends on what I tell, actually. Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From ben+python at benfinney.id.au Sat Jun 16 00:13:20 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 16 Jun 2012 14:13:20 +1000 Subject: Academic citation of Python References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: <87bokjx5b3.fsf@benfinney.id.au> Mark Livingstone writes: > I wish to properly cite Python in an academic paper I am writing. > > Is there a preferred document etc to cite? I think you're best positioned to answer that. Python isn't a document, so what specifically are you citing it as? -- \ ?A ?No? uttered from deepest conviction is better and greater | `\ than a ?Yes? merely uttered to please, or what is worse, to | _o__) avoid trouble.? ?Mohandas K. Gandhi | Ben Finney From alec.taylor6 at gmail.com Sat Jun 16 00:18:48 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 16 Jun 2012 14:18:48 +1000 Subject: Academic citation of Python In-Reply-To: <87bokjx5b3.fsf@benfinney.id.au> References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> <87bokjx5b3.fsf@benfinney.id.au> Message-ID: I think it's more like when you see articles with a passage like: The C programming language[1] or the C++ programming language[2] are both > examples of... > Are both easy to find the proper reference for. On Sat, Jun 16, 2012 at 2:13 PM, Ben Finney wrote: > Mark Livingstone writes: > > > I wish to properly cite Python in an academic paper I am writing. > > > > Is there a preferred document etc to cite? > > I think you're best positioned to answer that. Python isn't a document, > so what specifically are you citing it as? > > -- > \ ?A ?No? uttered from deepest conviction is better and greater | > `\ than a ?Yes? merely uttered to please, or what is worse, to | > _o__) avoid trouble.? ?Mohandas K. Gandhi | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From contropinion at gmail.com Sat Jun 16 00:31:10 2012 From: contropinion at gmail.com (contro opinion) Date: Sat, 16 Jun 2012 00:31:10 -0400 Subject: is the same betweent python3 and python3.2? Message-ID: when i download python-3.2.3.tgz extract ./configure prefix=/usr/lib/python-3.2 make make install when ls /usr/lib/python-3.2.3/bin/ /usr/lib/python-3.2.3/bin/python3.2m /usr/lib/python-3.2.3/bin/python3-config /usr/lib/python-3.2.3/bin/python3 /usr/lib/python-3.2.3/bin/python3.2m-config /usr/lib/python-3.2.3/bin/python3.2 /usr/lib/python-3.2.3/bin/python3.2-config is the /usr/lib/python-3.2.3/bin/python3 same as /usr/lib/python-3.2.3/bin/python3.2? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryanwoo1989 at gmail.com Sat Jun 16 00:52:26 2012 From: ryanwoo1989 at gmail.com (Isaac@AU) Date: Fri, 15 Jun 2012 21:52:26 -0700 (PDT) Subject: Komodo, Python Message-ID: I just started learning python. I have komodo2.5 in my computer. And I installed python2.7. I tried to write python scripts in komodo. But every time I run the code, there's always the error: Traceback (most recent call last): File "C:\Program Files\ActiveState Komodo 2.5\callkomodo\kdb.py", line 920, in requestor, connection_port, cookie = ConnectToListener(localhost_addr, port) File "C:\Program Files\ActiveState Komodo 2.5\callkomodo\kdb.py", line 872, in ConnectToListener cookie = makeCookie() File "C:\Program Files\ActiveState Komodo 2.5\callkomodo\kdb.py", line 146, in makeCookie generator=whrandom.whrandom() NameError: global name 'whrandom' is not defined Is it the compatibility problem? Can anybody tell how to fix this problem? Because komodo is not free, so I don't want to uninstall komodo. From alec.taylor6 at gmail.com Sat Jun 16 01:23:39 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 16 Jun 2012 15:23:39 +1000 Subject: which one do you prefer? python with C# or java? In-Reply-To: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> References: <054bfc18-df7f-44ea-bc6a-ec171832265d@si8g2000pbc.googlegroups.com> Message-ID: On Sun, Jun 10, 2012 at 8:44 AM, Yesterday Paid wrote: > > I'm planning to learn one more language with my python. > Someone recommended to do Lisp or Clojure, but I don't think it's a > good idea(do you?) > So, I consider C# with ironpython or Java with Jython. > It's a hard choice...I like Visual studio(because my first lang is VB6 > so I'm familiar with that) > but maybe java would be more useful out of windows. > > what do you think? Learn C and Python. They work well together... you can write Python modules in C (using Cython or CTypes), and the most popular implementation is written in C (CPython). Alternatively learn C++ and Python. You can can generate C++ from Python using ShedSkin (http://shed-skin.blogspot.com.au/), and you can write extension to Python in C++ (http://docs.python.org/extending/extending.html#writing-extensions-in-c). From dieter at handshake.de Sat Jun 16 05:20:09 2012 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 16 Jun 2012 11:20:09 +0200 Subject: Komodo, Python References: Message-ID: <87395v8vg6.fsf@handshake.de> "Isaac at AU" writes: > I just started learning python. I have komodo2.5 in my computer. And I installed python2.7. I tried to write python scripts in komodo. But every time I run the code, there's always the error: > > Traceback (most recent call last): > File "C:\Program Files\ActiveState Komodo 2.5\callkomodo\kdb.py", line 920, in > > requestor, connection_port, cookie = ConnectToListener(localhost_addr, port) > > File "C:\Program Files\ActiveState Komodo 2.5\callkomodo\kdb.py", line 872, in > ConnectToListener > cookie = makeCookie() > File "C:\Program Files\ActiveState Komodo 2.5\callkomodo\kdb.py", line 146, in > makeCookie > generator=whrandom.whrandom() > NameError: global name 'whrandom' is not defined This is a bug in "kdb.py". I forgets to import "whrandom". In addition it shows that the "kdb.py" code is very old. "whrandom" is been replaced by "random" a long time ago. -- Dieter From research at johnohagan.com Sat Jun 16 06:01:12 2012 From: research at johnohagan.com (John O'Hagan) Date: Sat, 16 Jun 2012 20:01:12 +1000 Subject: Threads vs subprocesses In-Reply-To: <7i6nt71nflpnndm42fdk0irph4m5sld9j3@invalid.netcom.com> References: <20120615234909.d509d3ce182ed78f4c43e9d0@johnohagan.com> <4FDB59E5.9020708@davea.name> <20120616032413.aee179153e7b6b4a0df62d07@johnohagan.com> <7i6nt71nflpnndm42fdk0irph4m5sld9j3@invalid.netcom.com> Message-ID: <20120616200112.3991c2d45b4fd62834758faa@johnohagan.com> On Fri, 15 Jun 2012 16:34:57 -0400 Dennis Lee Bieber wrote: > On Sat, 16 Jun 2012 03:24:13 +1000, John O'Hagan > declaimed the following in > gmane.comp.python.general: > > > > I should have made it clear that I'm not using threads to speed anything up; > > each thread produces an independently controlled, timed stream of musical > > events. I think it would be hard to achieve that in a single process. The > > streams need to run simultaneously without getting out of sync or dropping > > notes, which begins to happen if there are a lot of them, or they are run > > very fast or are very calculation-intensive to produce. > > > Sounds like something in the realm of discrete event simulation... > which is commonly single-threaded -- a list of events & time-points > which dispatch to event handlers as time is incremented... > > Or for your case: a time-ordered list of stream&event; issue all > events at a given time point, then dispatch to each stream to compute > the next event&time for that stream, which is placed into the ordered > list. Read the first pending event, sleep until the event time is > reached, then repeat the process. That looks like a possible way to do all the streams in a single thread, although it works a little differently from your outline above if I understand you correctly, in that only the events know their start times and they are produced by iterators which can be modified on the fly and which can be added and removed from the overall process at any time, so it's not possible to know in advance which iterator will produce the chronologically next event. I think that means that any ordered list of events would have to be re-ordered after each event is read. It might be worth a try though. I notice there is simpy for discrete event simulation in python. I'll look into it, thanks. John From olmo.hernandez-cuba at gmx.es Sat Jun 16 06:16:43 2012 From: olmo.hernandez-cuba at gmx.es (Olmo =?UTF-8?B?SGVybsOhbmRleg==?= Cuba) Date: Sat, 16 Jun 2012 12:16:43 +0200 Subject: Academic citation of Python In-Reply-To: References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> <87bokjx5b3.fsf@benfinney.id.au> Message-ID: <20120616121643.5abaccc9@gmx.es> Well, maybe something like: G. Van Rossum. The Python Language Reference Manual. Network Theory Ltd., September 2003. In other languages I use, the proper citation is obtained from the interpreter itself, and it points you to the language reference. Hope this helps. El Sat, 16 Jun 2012 14:18:48 +1000 Alec Taylor escribi?: > I think it's more like when you see articles with a passage like: > > > The C programming language[1] or the C++ programming language[2] are > both > > examples of... > > > > > Are both easy to find the proper reference for. > > On Sat, Jun 16, 2012 at 2:13 PM, Ben Finney > wrote: > > > Mark Livingstone writes: > > > > > I wish to properly cite Python in an academic paper I am writing. > > > > > > Is there a preferred document etc to cite? > > > > I think you're best positioned to answer that. Python isn't a > > document, so what specifically are you citing it as? > > > > -- > > \ ?A ?No? uttered from deepest conviction is better and > > greater | `\ than a ?Yes? merely uttered to please, or what > > is worse, to | _o__) avoid trouble.? > > ?Mohandas K. Gandhi | Ben Finney > > -- > > http://mail.python.org/mailman/listinfo/python-list > > From rosuav at gmail.com Sat Jun 16 06:43:51 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jun 2012 20:43:51 +1000 Subject: Create thumbnail image (jpg/png) of PDF file using Python In-Reply-To: <3rrkt75act29kbajgrdtkk3k7c2s2kp94d@invalid.netcom.com> References: <104837c4-898a-4f67-98ab-37df8ff76f0f@e25g2000prg.googlegroups.com> <9c15c8a2-2250-43d4-9084-e8d3bdab2107@c30g2000hsa.googlegroups.com> <951a74bf-5bff-4bef-a929-1e11eb995225@googlegroups.com> <3rrkt75act29kbajgrdtkk3k7c2s2kp94d@invalid.netcom.com> Message-ID: On Fri, Jun 15, 2012 at 9:15 AM, Dennis Lee Bieber wrote: > ? ? ? ?PDF is not an "image" file format; it is a "program" describing how > to render each page. Some of the page contents can be image bitmap data, > but a "proper" PDF has text AS text. Plus, JPG is very poor at handling text. It's designed for photos and photo-like images. I would recommend using PNG for the bitmapped side. ChrisA From bahamutzero8825 at gmail.com Sat Jun 16 07:11:29 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 16 Jun 2012 06:11:29 -0500 Subject: is the same betweent python3 and python3.2? In-Reply-To: References: Message-ID: <4FDC69E1.4010600@gmail.com> On 6/15/2012 11:31 PM, contro opinion wrote: > is the /usr/lib/python-3.2.3/bin/python3 same as > /usr/lib/python-3.2.3/bin/python3.2? It should be. IIRC, ls -l will tell you if something is a link. You could also run python3 and it will tell you the version. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From breamoreboy at yahoo.co.uk Sat Jun 16 09:01:12 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 16 Jun 2012 14:01:12 +0100 Subject: Academic citation of Python In-Reply-To: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: On 16/06/2012 04:24, Mark Livingstone wrote: > Hello! > > I wish to properly cite Python in an academic paper I am writing. > > Is there a preferred document etc to cite? > > Thanks in advance, > > MArkL The main website www.python.org and possibly the sites for Jython, IronPython and PyPY? -- Cheers. Mark Lawrence. From jcd at sdf.lonestar.org Sat Jun 16 09:15:40 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Sat, 16 Jun 2012 09:15:40 -0400 Subject: Academic citation of Python In-Reply-To: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: <1339852540.2639.3.camel@webb> That's a rather vague question. What do you want to cite about python? If you're just mentioning python, that shouldn't warrant a citation, though a parenthetical note linking to python.org might be useful. The standard documentation should be acceptable, or possibly a link to the source code at a given revision. Cheers, Cliff On Sat, 2012-06-16 at 13:24 +1000, Mark Livingstone wrote: > Hello! > > I wish to properly cite Python in an academic paper I am writing. > > Is there a preferred document etc to cite? > > Thanks in advance, > > MArkL From feliphil at gmx.net Sat Jun 16 11:06:46 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Sat, 16 Jun 2012 17:06:46 +0200 Subject: Pythonic cross-platform GUI desingers =?ISO-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> <20120614202509.ed996411.feliphil@gmx.net> <35c66602-8827-4dd9-9ca5-723be4d22a90@b1g2000vbb.googlegroups.com> Message-ID: <20120616170646.5bfaf623.feliphil@gmx.net> On Thu, 14 Jun 2012 12:59:23 -0700 (PDT) CM wrote: > On Jun 14, 2:25?pm, Wolfgang Keller wrote: > > > > What is needed for domain specialists are frameworks and related > > tools such as GUI builders that allow them to write exclusively the > > domain-specific code (this is where a domain specialist will always > > be better than any software developer), layout the GUI as > > ergonomically convenient (same) and then have the framework do all > > the rest. > > Above this you also mentioned a disdain for the need for "glue code", > which in the context of your post seemed to be binding to event > handlers. With "glue code" I mean any code other than that which serves to implement purely domain-specific behaviour. > So is there a possible way for a GUI builder to *automatically* bind > widgets to the appropriate functions in your domain-specific code? > It's hard to see how this would be generally possible, even with an > AI (maybe a mind-reading AI would work). > > Or maybe I'm misunderstanding something. Probably, since there are GUI builders/frameworks available that do what I described. I have already pointed to some for my specific type of application (database applications) that don't even need any GUI definition at all, since the GUI is entirely reflected from the domain model. Which I would not consider as the most ergonomic way to define a GUI. Unfortunately these excellent GUI builders and frameworks all use languages which imho are not at all suitable for domain specialists who are not full-time software developers by training. Sincerely, Wolfgang From bbew.ar at mapson.nozirev.ten Sat Jun 16 11:45:41 2012 From: bbew.ar at mapson.nozirev.ten (Rich Webb) Date: Sat, 16 Jun 2012 11:45:41 -0400 Subject: Academic citation of Python References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: On Sat, 16 Jun 2012 14:01:12 +0100, Mark Lawrence wrote: >On 16/06/2012 04:24, Mark Livingstone wrote: >> Hello! >> >> I wish to properly cite Python in an academic paper I am writing. >> >> Is there a preferred document etc to cite? >> >> Thanks in advance, >> >> MArkL > >The main website www.python.org and possibly the sites for Jython, >IronPython and PyPY? He's probably looking for an IEC or ANSI standard, like "Information technology ? Programming languages ? C INCITS/ISO/IEC 9899-2011[2012] (ISO/IEC 9899-2011, IDT)". I don't think URLs qualify as standards documents. -- Rich Webb Norfolk, VA From emile at fenx.com Sat Jun 16 12:10:36 2012 From: emile at fenx.com (Emile van Sebille) Date: Sat, 16 Jun 2012 09:10:36 -0700 Subject: Academic citation of Python In-Reply-To: References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: Or copy a citation from Guido: http://www.python.org/~guido/Publications.html Emile From wxjmfauth at gmail.com Sat Jun 16 13:36:42 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Sat, 16 Jun 2012 10:36:42 -0700 (PDT) Subject: Python 3.3.0a4, please add ru'...' Message-ID: <94326790-ccd1-4306-a216-7cd79f2a9ab6@w24g2000vby.googlegroups.com> Please consistency. >>> sys.version '3.3.0a4 (v3.3.0a4:7c51388a3aa7+, May 31 2012, 20:15:21) [MSC v.1600 32 bit (Intel)]' >>> 'a' 'a' >>> b'a' b'a' >>> br'a' b'a' >>> rb'a' b'a' >>> u'a' 'a' >>> ur'a' 'a' >>> ru'a' SyntaxError: invalid syntax >>> jmf From pauli.rikula at gmail.com Sat Jun 16 13:42:52 2012 From: pauli.rikula at gmail.com (Pauli Rikula) Date: Sat, 16 Jun 2012 20:42:52 +0300 Subject: python 3.3 bz2 decompression testing results Message-ID: I tested http://python.org/ftp/python/3.3.0/python-3.3.0a4.amd64.msi bz2 module's decompression using the bz2 -files from: https://www.ee.oulu.fi/research/ouspg/PROTOS_Test-Suite_c10-archive and found nothing. I did not use anything like Valgrind though. Should I try to run these tests again using Linux and Valgrind? Testscript is at: http://code.google.com/p/my-never-ending-projects/source/browse/trunk/tests/python3_3_bz2/test_decompress.py you might find it interesting.. or not. The test took about 2 hours and all the exceptions I got from tests were the like these two (exceptions.txt -file which was made by the test_decompress.py -testscript): -------- testcase 0: 00000184e108021bf3b3f860f1c7618c.bz2 file len: 76 local testtime: 2012-06-16 18:44:25 ('Traceback (most recent call last):\n', ' File "C:/projektit/bz2_python33_test/test_decompress.py", line 52, in \n _ = bz2.decompress(fs)\n', ' File "C:\\Python33-0a4\\lib\\bz2.py", line 419, in decompress\n raise ValueError("Compressed data ended before the "\n', 'ValueError: Compressed data ended before the end-of-stream marker was reached\n') -------- testcase 1: 000001d8c11b84d738de284a8ba76226.bz2 file len: 3629 local testtime: 2012-06-16 18:44:25 ('Traceback (most recent call last):\n', ' File "C:/projektit/bz2_python33_test/test_decompress.py", line 52, in \n _ = bz2.decompress(fs)\n', ' File "C:\\Python33-0a4\\lib\\bz2.py", line 417, in decompress\n results.append(decomp.decompress(data))\n', 'OSError: Invalid data stream\n') From ben+python at benfinney.id.au Sat Jun 16 14:10:49 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 17 Jun 2012 04:10:49 +1000 Subject: Academic citation of Python References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> <87bokjx5b3.fsf@benfinney.id.au> Message-ID: <877gv7w2ja.fsf@benfinney.id.au> Olmo Hern?ndez Cuba writes: > Well, maybe something like: > > G. Van Rossum. The Python Language > Reference Manual. Network Theory Ltd., September 2003. Are you referencing material from that document? If so, go ahead and reference that document's URL. > In other languages I use, the proper citation is obtained from the > interpreter itself, and it points you to the language reference. But why cite the language reference, or any document, if you're not actually referencing material in that document? I don't see how merely writing programs in a language warrants bibliographic citation for it. Perhaps just referring to the main URL for the Python website? -- \ ?What you have become is the price you paid to get what you | `\ used to want.? ?Mignon McLaughlin | _o__) | Ben Finney From tjreedy at udel.edu Sat Jun 16 16:44:15 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 Jun 2012 16:44:15 -0400 Subject: Academic citation of Python In-Reply-To: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: On 6/15/2012 11:24 PM, Mark Livingstone wrote: > Hello! > > I wish to properly cite Python in an academic paper I am writing. > > Is there a preferred document etc to cite? At present, I would use something like Rossum, Guido van, et al, *The Python Language Reference*, Python Software Foundation; http://docs.python.org/py3k/reference/index.html with punctuation adjusted to your target. That url should continue to work as new versions are released. If you want to cite a particular version, http://docs.python.org/release/3.2/reference/index.html with 3.2 replaced by x.y as appropriate. -- Terry Jan Reedy From lists at cheimes.de Sat Jun 16 17:01:22 2012 From: lists at cheimes.de (Christian Heimes) Date: Sat, 16 Jun 2012 23:01:22 +0200 Subject: Academic citation of Python In-Reply-To: References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: Am 16.06.2012 22:44, schrieb Terry Reedy: > Rossum, Guido van, et al, *The Python Language Reference*, Python > Software Foundation; http://docs.python.org/py3k/reference/index.html Actually it's "van Rossum, Guido", not "Rossum, Guido van". The "van" is part of the family name, not a middle name. It's like "da Vinci, Leonardo" or "von Sydow, Max". On one occasion Guido complained that Americans always get his name wrong. Christian From tjreedy at udel.edu Sat Jun 16 20:25:29 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 Jun 2012 20:25:29 -0400 Subject: Academic citation of Python In-Reply-To: References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: On 6/16/2012 5:01 PM, Christian Heimes wrote: > Am 16.06.2012 22:44, schrieb Terry Reedy: >> Rossum, Guido van, et al, *The Python Language Reference*, Python >> Software Foundation; http://docs.python.org/py3k/reference/index.html > > Actually it's "van Rossum, Guido", not "Rossum, Guido van". The "van" is > part of the family name, not a middle name. It's like "da Vinci, > Leonardo" or "von Sydow, Max". On one occasion Guido complained that > Americans always get his name wrong. Thank you for the correction. I was going by an old book (1996) he co-wrote that just had 'Rossum' on the spine. I guess that must have been done without consulting him and must have annoyed him. -- Terry Jan Reedy From contropinion at gmail.com Sat Jun 16 20:34:44 2012 From: contropinion at gmail.com (contro opinion) Date: Sat, 16 Jun 2012 20:34:44 -0400 Subject: is the same betweent python3 and python3.2? In-Reply-To: <4FDC69E1.4010600@gmail.com> References: <4FDC69E1.4010600@gmail.com> Message-ID: root at debian:/home/debian# find / -name 'python3' /usr/lib/python-3.2.3/bin/python3 root at debian:/home/debian# /usr/lib/python-3.2.3/bin/python3 Python 3.2.3 (default, Jun 16 2012, 10:59:54) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> it is the same thing,think you 2012/6/16 Andrew Berg > On 6/15/2012 11:31 PM, contro opinion wrote: > > is the /usr/lib/python-3.2.3/bin/python3 same as > > /usr/lib/python-3.2.3/bin/python3.2? > It should be. IIRC, ls -l will tell you if something is a link. You > could also run python3 and it will tell you the version. > > -- > CPython 3.3.0a4 | Windows NT 6.1.7601.17803 > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From smitty1e at gmail.com Sat Jun 16 21:39:42 2012 From: smitty1e at gmail.com (smitty1e) Date: Sat, 16 Jun 2012 18:39:42 -0700 (PDT) Subject: Smart quote character replacement for those with deficient sed-fu. Message-ID: Use case: ======= 1. OSX 10.7, bunch of .tex files culled from a blog via some cruddy old Perl script. .tex files are utf-8 encoded, which means the quotes and apostrophes drop out going through pdflatex. 2. Recommend using git to manage the .tex files, which are all in a /src directory in the project. If you're going to do batch edits, You Will Need to branch, realize you gooned up, and roll back. 3. Understood, sed is the more classical tool here, except that I could not it to work in my OSX terminal. Invocation: ======= python charfix.py `ls src/*.tex` charfix.py code: ======= # -*- coding: utf-8 -*- import fileinput def process(line): print line.replace( "?", "'" ).replace( "?", '"' ).replace( "?", '"' ) if __name__=="__main__": for line in fileinput.input( inplace=1 ): process(line) ======= Discussion: ======= Thank you, python! From howmuchistoday at gmail.com Sat Jun 16 22:15:34 2012 From: howmuchistoday at gmail.com (Yesterday Paid) Date: Sat, 16 Jun 2012 19:15:34 -0700 (PDT) Subject: Is that safe to use ramdom.random() for key to encrypt? Message-ID: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> I'm making cipher program with random.seed(), random.random() as the key table of encryption. I'm not good at security things and don't know much about the algorithm used by random module. Is it really random or safe enough to keep my data safe? From rosuav at gmail.com Sat Jun 16 22:31:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jun 2012 12:31:04 +1000 Subject: Is that safe to use ramdom.random() for key to encrypt? In-Reply-To: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> Message-ID: On Sun, Jun 17, 2012 at 12:15 PM, Yesterday Paid wrote: > I'm making cipher program with random.seed(), random.random() as the > key table of encryption. > I'm not good at security things and don't know much about the > algorithm used by random module. For security, you don't want any algorithm, you want something like /dev/random (on Unix-like platforms). I'm pretty sure Python includes crypto facilities. Unless it (most oddly) lacks these batteries, I would recommend using one of them instead. ChrisA From rosuav at gmail.com Sat Jun 16 22:42:58 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jun 2012 12:42:58 +1000 Subject: Pythonic cross-platform GUI desingers ?? la Interface Builder (Re: what gui designer is everyone using) In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: On Fri, Jun 15, 2012 at 7:47 AM, Dietmar Schwertberger wrote: > The point is, that if you want to promote Python as replacement > for e.g. VB, Labview etc., then an easy-to-use GUI builder is required. > The typical GUI programs will just have an input mask, a button and one > or two output fields. I want to promote Linux as a replacement for Windows. But I do not see that Linux needs to be able to run Internet Explorer in order to do that. Maybe when people move to a replacement, they need to learn a slightly different way of doing things; and in this case, I would strongly recommend the "build your UI in code" method. ChrisA From no.email at nospam.invalid Sat Jun 16 22:58:25 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 16 Jun 2012 19:58:25 -0700 Subject: Is that safe to use ramdom.random() for key to encrypt? References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> Message-ID: <7xlijm4pbi.fsf@ruckus.brouhaha.com> Yesterday Paid writes: > I'm making cipher program with random.seed(), random.random() as the > key table of encryption... > Is it really random or safe enough to keep my data safe? No. Use os.urandom instead. From joncle at googlemail.com Sat Jun 16 23:12:20 2012 From: joncle at googlemail.com (Jon Clements) Date: Sun, 17 Jun 2012 03:12:20 +0000 (UTC) Subject: Is that safe to use ramdom.random() for key to encrypt? References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> Message-ID: On Sun, 17 Jun 2012 12:31:04 +1000, Chris Angelico wrote: > On Sun, Jun 17, 2012 at 12:15 PM, Yesterday Paid > wrote: >> I'm making cipher program with random.seed(), random.random() as the >> key table of encryption. >> I'm not good at security things and don't know much about the algorithm >> used by random module. > > For security, you don't want any algorithm, you want something like > /dev/random (on Unix-like platforms). > > I'm pretty sure Python includes crypto facilities. Unless it (most > oddly) lacks these batteries, I would recommend using one of them > instead. > > ChrisA Cryptography is a complex subject - I've had the (mis)fortune to study it briefly. Whatever you do - *do not* attempt to write your own algorithm. Python includes hashlib (forms of SHA and MD5) and uuid modules, but I take it a symmetric or possibly public/private key system is required - depending on what you want to secure, where it's stored and who needs access. I generally find a separate partition with an encrypted file-system (which is fairly straight forward on *nix systems or I think there's a product out there that works with Windows), is a lot easier and puts the load on the filesystem/OS instead of having to be handled in your application is a lot simpler. Jon From steve+comp.lang.python at pearwood.info Sat Jun 16 23:54:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jun 2012 03:54:04 GMT Subject: Python 3.3.0a4, please add ru'...' References: <94326790-ccd1-4306-a216-7cd79f2a9ab6@w24g2000vby.googlegroups.com> Message-ID: <4fdd54dc$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Jun 2012 10:36:42 -0700, jmfauth wrote: > Please consistency. There is no point asking here. Feature requests and bug reports must go on the tracker, or they are unlikely to be noticed or remembered by anyone who can fix it. http://bugs.python.org/ Given that 3.3's feature-freeze is only days away, I strongly recommend that you also raise it here: http://mail.python.org/mailman/listinfo/python-dev -- Steven From steve+comp.lang.python at pearwood.info Sun Jun 17 00:18:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jun 2012 04:18:52 GMT Subject: Is that safe to use ramdom.random() for key to encrypt? References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> Message-ID: <4fdd5aac$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Jun 2012 19:15:34 -0700, Yesterday Paid wrote: > I'm making cipher program with random.seed(), random.random() as the key > table of encryption. > I'm not good at security things and don't know much about the algorithm > used by random module. Start by reading the Fine Manual: http://docs.python.org/library/random.html which answers your question: "it is not suitable for all purposes, and is completely unsuitable for cryptographic purposes." Please don't write yet another broken cipher program that doesn't work. Use a proper one that has been mathematically analysed by professionals. I don't mean to cast aspersions on you, but any fool can write a cipher program that *they* can't break themselves. It takes many years of study to design a cipher that professionals can't break. At the very least, start with PyCrypto. http://pypi.python.org/pypi/pycrypto If all you want is to play around obfuscating data, you might be interested in my toy encryption module: http://pypi.python.org/pypi/obfuscate/ (which is also completely unsuitable for cryptographic purposes, but may be useful if you have some interest in the history of cryptography). > Is it really random or safe enough to keep my data safe? Safe from what? What is your threat model? Are you worried about your little sister reading your diary? Or the NSA discovering your plans to assassinate the President? Or something in between? Python's random module is not cryptographically strong, which means that it will probably take an organisation like the NSA, MI5, ASIO, Mossad, etc. about 10 or 20 minutes to crack your password. But your little sister will probably take a hundred million years to guess it. -- Steven From steve+comp.lang.python at pearwood.info Sun Jun 17 00:24:27 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jun 2012 04:24:27 GMT Subject: Smart quote character replacement for those with deficient sed-fu. References: Message-ID: <4fdd5bfb$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Jun 2012 18:39:42 -0700, smitty1e wrote: [...] > python charfix.py `ls src/*.tex` > > charfix.py code: Thanks for that. You might like to also publish it on the ActiveState Python recipes site, where people are more likely to find it in the future. http://code.activestate.com/recipes/langs/python/ -- Steven From rosuav at gmail.com Sun Jun 17 00:48:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jun 2012 14:48:12 +1000 Subject: Is that safe to use ramdom.random() for key to encrypt? In-Reply-To: <4fdd5aac$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> <4fdd5aac$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jun 17, 2012 at 2:18 PM, Steven D'Aprano wrote: > Safe from what? What is your threat model? Are you worried about your > little sister reading your diary? Or the NSA discovering your plans to > assassinate the President? Or something in between? > > Python's random module is not cryptographically strong, which means that > it will probably take an organisation like the NSA, MI5, ASIO, Mossad, > etc. about 10 or 20 minutes to crack your password. But your little > sister will probably take a hundred million years to guess it. Your little sister would quite possibly be kept off by rot13, which everyone knows isn't cryptographically secure. All it takes is making something look encrypted and most people won't bother to try (plus it's the whole "this isn't public kthx" thing, which many people will respect). Of course, if you're just trying to fool the BOFH's technical manager, it's even easier. http://bofh.ch/newbofh/bofh4oct.html ChrisA From ian.g.kelly at gmail.com Sun Jun 17 02:31:12 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 17 Jun 2012 00:31:12 -0600 Subject: Komodo, Python In-Reply-To: <87395v8vg6.fsf@handshake.de> References: <87395v8vg6.fsf@handshake.de> Message-ID: On Sat, Jun 16, 2012 at 3:20 AM, Dieter Maurer wrote: > In addition it shows that the "kdb.py" code is very old. "whrandom" > is been replaced by "random" a long time ago. Komodo 2.5 was released in 2003. At the time, Python was on release 2.3. Komodo is currently on version 7. The OP should consider updating their IDE. From chris at robotninja.net Sun Jun 17 05:01:57 2012 From: chris at robotninja.net (Chris Fox) Date: Sun, 17 Jun 2012 10:01:57 +0100 Subject: Pythonic cross-platform GUI desingers ?? la Interface Builder (Re: what gui designer is everyone using) In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 17/06/2012 03:42, Chris Angelico wrote: > On Fri, Jun 15, 2012 at 7:47 AM, Dietmar Schwertberger > wrote: >> The point is, that if you want to promote Python as replacement >> for e.g. VB, Labview etc., then an easy-to-use GUI builder is >> required. The typical GUI programs will just have an input mask, >> a button and one or two output fields. > > I want to promote Linux as a replacement for Windows. But I do not > see that Linux needs to be able to run Internet Explorer in order > to do that. Maybe when people move to a replacement, they need to > learn a slightly different way of doing things; and in this case, I > would strongly recommend the "build your UI in code" method. > > ChrisA So you use wget on linux and read the html code in a terminal? That would seem to be a reasonable analogy. (a different) Chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk/dnQUACgkQ/UgLKfoJxI6FzgCg0zRwrwQJwwCMatEEMhYyMvPN eGsAn111DGx2lgo7Y6vMJr0EcD+zGDHD =GjZF -----END PGP SIGNATURE----- From stefan_ml at behnel.de Sun Jun 17 05:07:56 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 17 Jun 2012 11:07:56 +0200 Subject: Academic citation of Python In-Reply-To: References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: Dennis Lee Bieber, 17.06.2012 02:46: > On Sat, 16 Jun 2012 20:25:29 -0400, Terry Reedy > declaimed the following in gmane.comp.python.general: > >> Thank you for the correction. I was going by an old book (1996) he >> co-wrote that just had 'Rossum' on the spine. I guess that must have >> been done without consulting him and must have annoyed him. > > If ALL they had on the spine was "Rossum", that may have been > correct usage for a surname only reference. The "van", "von", "da" > prefixes sort of translate to "of the" and for a book spine "of the XYZ" > may be meaningless unless the given name is included, a la "ABC of the > XYZ"... It's a bit like using "New York" as a surname, when you refer to that guy Jason who was born there, as in "Jason of New York". Stefan From clickfirm2007 at gmail.com Sun Jun 17 05:27:47 2012 From: clickfirm2007 at gmail.com (Mohamed Gad) Date: Sun, 17 Jun 2012 02:27:47 -0700 (PDT) Subject: ~~** 365 Tips for Saving, Investing, and Making Money **~~ Message-ID: <2f28bf52-ab08-41bb-beae-ab3ad97ce8bf@m3g2000vbl.googlegroups.com> Hey, Grab This Free Report Revealing 365 Daily Tips To Motivate You To Save & Make Money While Still Enjoying Life... >> http://bit.ly/Daily-Money-Motivator 365 Tips for Saving, Investing, and Making Money So check it out now while it?s still on offer: >> http://bit.ly/Daily-Money-Motivator From gmspro at yahoo.com Sun Jun 17 05:54:28 2012 From: gmspro at yahoo.com (gmspro) Date: Sun, 17 Jun 2012 02:54:28 -0700 (PDT) Subject: How does python bytecode works? Message-ID: <1339926868.23717.YahooMailClassic@web164605.mail.gq1.yahoo.com> We know python is written in C. C is not portable. So how does python work on a webserver like apache/httpd for a python website? How does the intermediate language communicate with server without compiling python code? Or how does python interpreted code work with webserver for python based websites? Please elaborate/explain this topic with example. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From storchaka at gmail.com Sun Jun 17 06:20:00 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sun, 17 Jun 2012 13:20:00 +0300 Subject: Python 3.3.0a4, please add ru'...' In-Reply-To: <94326790-ccd1-4306-a216-7cd79f2a9ab6@w24g2000vby.googlegroups.com> References: <94326790-ccd1-4306-a216-7cd79f2a9ab6@w24g2000vby.googlegroups.com> Message-ID: On 16.06.12 20:36, jmfauth wrote: >>>> u'a' > 'a' >>>> ur'a' > 'a' Please, never use u'' in new Python 3 code. This is only for compatibility with Python 2. And Python 2 does not support ru''. From kevin.p.dwyer at gmail.com Sun Jun 17 06:41:57 2012 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 17 Jun 2012 11:41:57 +0100 Subject: How does python bytecode works? References: <1339926868.23717.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: gmspro wrote: > We know python is written in C. > C is not portable. > So how does python work on a webserver like apache/httpd for a python > website? How does the intermediate language communicate with server > without compiling python code? Or how does python interpreted code work > with webserver for python based websites? > > Please elaborate/explain this topic with example. > > Thanks. http://en.wikipedia.org/wiki/Bytecode From lists at cheimes.de Sun Jun 17 07:30:53 2012 From: lists at cheimes.de (Christian Heimes) Date: Sun, 17 Jun 2012 13:30:53 +0200 Subject: Python 3.3.0a4, please add ru'...' In-Reply-To: <94326790-ccd1-4306-a216-7cd79f2a9ab6@w24g2000vby.googlegroups.com> References: <94326790-ccd1-4306-a216-7cd79f2a9ab6@w24g2000vby.googlegroups.com> Message-ID: Am 16.06.2012 19:36, schrieb jmfauth: > Please consistency. Python 3.3 supports the ur"" syntax just as Python 2.x: $ ./python Python 3.3.0a4+ (default:4c704dc97496, Jun 16 2012, 00:06:09) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ur"" '' [73917 refs] Neither Python 2 nor Python 3 supports ru"". I'm a bit astonished that rb"" works in Python 3 as it doesn't work in Python 2.7. But br"" works everywhere. Christian From wxjmfauth at gmail.com Sun Jun 17 08:11:25 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 17 Jun 2012 05:11:25 -0700 (PDT) Subject: Python 3.3.0a4, please add ru'...' References: <94326790-ccd1-4306-a216-7cd79f2a9ab6@w24g2000vby.googlegroups.com> Message-ID: <4f3f55f6-d2a2-435d-a28d-03895c63b586@k5g2000vbf.googlegroups.com> On 17 juin, 13:30, Christian Heimes wrote: > Am 16.06.2012 19:36, schrieb jmfauth: > > > Please consistency. > > Python 3.3 supports the ur"" syntax just as Python 2.x: > > $ ./python > Python 3.3.0a4+ (default:4c704dc97496, Jun 16 2012, 00:06:09) > [GCC 4.6.3] on linux > Type "help", "copyright", "credits" or "license" for more information.>>> ur"" > > '' > [73917 refs] > > Neither Python 2 nor Python 3 supports ru"". I'm a bit astonished that > rb"" works in Python 3 as it doesn't work in Python 2.7. But br"" works > everywhere. > > Christian I noticed this at the 3.3.0a0 realease. The main motivation for this came from this: http://bugs.python.org/issue13748 PS I saw the dev-list message. PS2 Opinion, if not really useful, consistency nver hurts. jmf From steve+comp.lang.python at pearwood.info Sun Jun 17 09:26:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jun 2012 13:26:14 GMT Subject: Python 3.3.0a4, please add ru'...' References: <94326790-ccd1-4306-a216-7cd79f2a9ab6@w24g2000vby.googlegroups.com> <4f3f55f6-d2a2-435d-a28d-03895c63b586@k5g2000vbf.googlegroups.com> Message-ID: <4fdddaf5$0$29980$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Jun 2012 05:11:25 -0700, jmfauth wrote: > PS2 Opinion, if not really useful, consistency nver hurts. If you're doing something useless or harmful, why would you want to do more of it for the sake of consistency? "Consistency" requires somebody to write the code in the first place, which isn't free. If you don't have to pay for it, *somebody* pays for it, even if it is only in their own time and effort. That's a real cost. Somebody has to write the code, update the documentation and create tests for it. Somebody else has to review the code. Every single time Python's test suite is run, extra tests are run. More code means greater chance of bugs or regressions. These are real costs. Python programmers have to learn the new functionality, which may or may not be simple. Every time they write a string, they have to decide which delimiter to use: currently, there are 16 in Python 2, and a similar number in Python 3 (more? fewer? I'm honestly not sure). That decision isn't free. Your proposal would add four more string delimiters. Now these may all be *small* costs, perhaps. They might be small enough that consistency for its own sake outweighs those costs. Maybe. But consistency doesn't happen for free. So it is not true that consistency *never* hurts. Consistency ALWAYS hurts, at least a bit, because it adds complexity. The only question is whether or not the benefit outweighs the harm. Often it will, but that can't be taken for granted. "A foolish consistency is the hobgoblin of little minds" - Ralph Waldo Emerson -- Steven From lists at cheimes.de Sun Jun 17 09:48:25 2012 From: lists at cheimes.de (Christian Heimes) Date: Sun, 17 Jun 2012 15:48:25 +0200 Subject: Python 3.3.0a4, please add ru'...' In-Reply-To: <4f3f55f6-d2a2-435d-a28d-03895c63b586@k5g2000vbf.googlegroups.com> References: <94326790-ccd1-4306-a216-7cd79f2a9ab6@w24g2000vby.googlegroups.com> <4f3f55f6-d2a2-435d-a28d-03895c63b586@k5g2000vbf.googlegroups.com> Message-ID: Am 17.06.2012 14:11, schrieb jmfauth: > I noticed this at the 3.3.0a0 realease. > > The main motivation for this came from this: > http://bugs.python.org/issue13748 > > PS I saw the dev-list message. > > PS2 Opinion, if not really useful, consistency nver hurts. We are must likely drop the ur"" syntax as it's not compatible with Python 2.x's raw unicode notation. http://bugs.python.org/issue15096 Christian From research at johnohagan.com Sun Jun 17 10:17:28 2012 From: research at johnohagan.com (John O'Hagan) Date: Mon, 18 Jun 2012 00:17:28 +1000 Subject: Threads vs subprocesses In-Reply-To: References: <20120615234909.d509d3ce182ed78f4c43e9d0@johnohagan.com> <4FDB59E5.9020708@davea.name> <20120616032413.aee179153e7b6b4a0df62d07@johnohagan.com> <7i6nt71nflpnndm42fdk0irph4m5sld9j3@invalid.netcom.com> <20120616200112.3991c2d45b4fd62834758faa@johnohagan.com> Message-ID: <20120618001728.5e31e84a92c059373e4f51a8@johnohagan.com> On Sat, 16 Jun 2012 13:27:45 -0400 Dennis Lee Bieber wrote: > On Sat, 16 Jun 2012 20:01:12 +1000, John O'Hagan > declaimed the following in > gmane.comp.python.general: > > > > > That looks like a possible way to do all the streams in a single thread, > > although it works a little differently from your outline above if I > > understand you correctly, in that only the events know their start times > > and they are produced by iterators which can be modified on the fly and > > which can be added and removed from the overall process at any time, so > > it's not possible to know in advance which iterator will produce the > > chronologically next event. I think > > Which is why I mentioned processing all events at a time-point, then > iterate for the next events if any are generated -- and a "time-ordered" > (aka; priority) list, so the new events are positioned in the correct > sequence against any other events that are in it. Now I get it, I thought you meant generating all events ahead of time. > > that means that any ordered list of events would have to be re-ordered after > > each event is read. It might be worth a try though. I notice there is simpy > > for > > Not "after each event is read" but when a new event is > generated/inserted. The list is not a FIFO where new events are added to > the end, but more of a priority queue where the lowest time is the next > to be retrieved. You're right, of course. > > discrete event simulation in python. I'll look into it, thanks. > > > One major difference is that traditional discrete event simulation > uses a false clock -- the simulation time advances to the next (first > pending) event time immediately. You'd need to modify that operation to > put in a real-time clock "sleep until" effect. My events are already handled that way so that's easy - the hard part is the more complex logic required by doing it without threads. Or maybe it's just different, I'm in the process of getting my head around it; thanks for the pointers. John From curty at free.fr Sun Jun 17 11:18:07 2012 From: curty at free.fr (Curt) Date: 17 Jun 2012 15:18:07 GMT Subject: Academic citation of Python References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: On 2012-06-16, Christian Heimes wrote: > > Actually it's "van Rossum, Guido", not "Rossum, Guido van". The "van" is > part of the family name, not a middle name. It's like "da Vinci, > Leonardo" or "von Sydow, Max". On one occasion Guido complained that > Americans always get his name wrong. I've read that now he prefers Guido V. Rossum, Jr. From rosuav at gmail.com Sun Jun 17 11:51:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2012 01:51:41 +1000 Subject: Pythonic cross-platform GUI desingers ?? la Interface Builder (Re: what gui designer is everyone using) In-Reply-To: References: <20120608142721.3ab95cb7.feliphil@gmx.net> <20120611140116.001241a2.feliphil@gmx.net> Message-ID: On Sun, Jun 17, 2012 at 7:01 PM, Chris Fox wrote: > On 17/06/2012 03:42, Chris Angelico wrote: >> I want to promote Linux as a replacement for Windows. But I do not >> see that Linux needs to be able to run Internet Explorer in order >> to do that. Maybe when people move to a replacement, they need to >> learn a slightly different way of doing things; and in this case, I >> would strongly recommend the "build your UI in code" method. >> >> ChrisA > > So you use wget on linux and read the html code in a terminal? That > would seem to be a reasonable analogy. > > (a different) Chris Well, I have been known to use wget, a simple HTML-to-text converter, and watch... made for a fairly simple monitor for something that had a browser-based status display. But no, I don't go to that extent. That would be analogous to abolishing GUI frameworks altogether and expecting everyone to use and write command-line tools. We're talking here about building your own program, and whether or not you can use a GUI to build a GUI. Most other interfaces aren't built using themselves; look at web-based web site builders, they almost universally suck (and those that don't suck are special-purpose things, like MediaWiki, that just happen to be able to be used to build a web site). WYSIWYG HTML editors have become rather better now than they were (say) 10-15 years ago, but I still believe in hand-writing HTML and CSS (or using straight-forward tools) for best results. ChrisA (keeping the A(ngelico) on the name to distinguish from all the other geeky Chrises, of whom there are a good few on this list) From wxjmfauth at gmail.com Sun Jun 17 11:53:28 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Sun, 17 Jun 2012 08:53:28 -0700 (PDT) Subject: Python 3.3.0a4, please add ru'...' References: <94326790-ccd1-4306-a216-7cd79f2a9ab6@w24g2000vby.googlegroups.com> <4f3f55f6-d2a2-435d-a28d-03895c63b586@k5g2000vbf.googlegroups.com> Message-ID: <0b9c3664-3553-4bd2-b2b4-5a2ce6c0c1ce@eh4g2000vbb.googlegroups.com> On 17 juin, 15:48, Christian Heimes wrote: > Am 17.06.2012 14:11, schrieb jmfauth: > > > I noticed this at the 3.3.0a0 realease. > > > The main motivation for this came from this: > >http://bugs.python.org/issue13748 > > > PS I saw the dev-list message. > > > PS2 Opinion, if not really useful, consistency nver hurts. > > We are must likely drop the ur"" syntax as it's not compatible with > Python 2.x's raw unicode notation.http://bugs.python.org/issue15096 > > Christian Yes, but on the other side, "you" (core developers) have reintroduced the messs of the unicode literal, now *assume* it (logiccally). If the core developers have introduced rb'' or br' (Py2)' because they never know if the have to type "rb" or "br" (me too), what a beginner should thing about "ur" and "ru"? Finally, the ultimate argument: what it is Python 3 supposed to be? A Python 2 derivative for lazy (ascii) programmers or an appealing clean and coherent language? jmf From gmspro at yahoo.com Sun Jun 17 12:40:15 2012 From: gmspro at yahoo.com (gmspro) Date: Sun, 17 Jun 2012 09:40:15 -0700 (PDT) Subject: How can i build python3 without optimization? Message-ID: <1339951215.28645.YahooMailClassic@web164601.mail.gq1.yahoo.com> I tried this: CFLAG=-g ./configure --prefix=/home/user/localdir But during debugging python i get: (gdb)next (gdb)print variable (gdb)$1 = What should i do? How can i get the value of a variable instead of ? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rafadurancastaneda at gmail.com Sun Jun 17 13:06:19 2012 From: rafadurancastaneda at gmail.com (=?ISO-8859-1?Q?Rafael_Dur=E1n_Casta=F1eda?=) Date: Sun, 17 Jun 2012 19:06:19 +0200 Subject: Is that safe to use ramdom.random() for key to encrypt? In-Reply-To: References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> <4fdd5aac$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FDE0E8B.3050701@gmail.com> El 17/06/12 06:48, Chris Angelico escribi?: > On Sun, Jun 17, 2012 at 2:18 PM, Steven D'Aprano > wrote: >> Safe from what? What is your threat model? Are you worried about your >> little sister reading your diary? Or the NSA discovering your plans to >> assassinate the President? Or something in between? >> >> Python's random module is not cryptographically strong, which means that >> it will probably take an organisation like the NSA, MI5, ASIO, Mossad, >> etc. about 10 or 20 minutes to crack your password. But your little >> sister will probably take a hundred million years to guess it. > Your little sister would quite possibly be kept off by rot13, which > everyone knows isn't cryptographically secure. All it takes is making > something look encrypted and most people won't bother to try (plus > it's the whole "this isn't public kthx" thing, which many people will > respect). > > Of course, if you're just trying to fool the BOFH's technical manager, > it's even easier. > > http://bofh.ch/newbofh/bofh4oct.html > > ChrisA Hi, When generating random strings I usually do something like this wikepedia extract (http://en.wikipedia.org/wiki/Random_password_generator): The language Python includes a SystemRandom class that obtains cryptographic grade random bits from /dev/urandom on a Unix-like system, including Linux and Mac OS X, while on Windows it uses CryptGenRandom.^[4] ^[5] Here is a simple Python 2 script that demonstrates the use of this class: #!/usr/bin/python import random, string myrg= random.SystemRandom() length= 10 # If you want non-English characters, remove the [0:52] alphabet= string.letters[0:52] +string.digits pw= str().join(myrg.choice(alphabet) for _in range(length)) print pw Do you think is secure enough for token generation? (40 chars long tokens are used for password reset links in a website, there isn't any special security concern for the web). -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.p.dwyer at gmail.com Sun Jun 17 13:29:25 2012 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 17 Jun 2012 18:29:25 +0100 Subject: How can i build python3 without optimization? References: <1339951215.28645.YahooMailClassic@web164601.mail.gq1.yahoo.com> Message-ID: gmspro wrote: > I tried this: > CFLAG=-g ./configure --prefix=/home/user/localdir > > But during debugging python i get: > > (gdb)next > (gdb)print variable > (gdb)$1 = > > What should i do? > How can i get the value of a variable instead of ? > > Thanks. Maybe try: http://docs.python.org/devguide/setup.html#compiling-for- debugging From tjreedy at udel.edu Sun Jun 17 14:10:32 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 17 Jun 2012 14:10:32 -0400 Subject: How does python bytecode works? In-Reply-To: <1339926868.23717.YahooMailClassic@web164605.mail.gq1.yahoo.com> References: <1339926868.23717.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: On 6/17/2012 5:54 AM, gmspro wrote: > We know python is written in C. Nope. The CPython Python interpreter is written in (as portable as possible) C. The Jython, IronPython, and PyPy Python interpreters are written in Jave, C#, and Python respectively. Each compiles Python to something different. I presume each (normally) saves the compiled form until the source changes. CPython compiles to CPython-specific bytecode. It saves the bytecode as a .pyc file in a .__cache__ subdirectory (in 3.2+). > C is not portable. Yes it is (mostly). CPython has been compilied, with minor adjustments, on numerous (>20) systems. > So how does python work on a webserver like apache/httpd for a python > website? The website has a Python interpreter. > How does the intermediate language communicate with server without > compiling python code? The Python interpreter of the website *does* compile Python code to whatever it compiles to. -- Terry Jan Reedy From missive at hotmail.com Sun Jun 17 14:49:06 2012 From: missive at hotmail.com (Lee Harr) Date: Sun, 17 Jun 2012 23:19:06 +0430 Subject: [ANNC] vbot-0.3 Message-ID: vBot is a visual programming game. ??? Use a small set of command tiles to build a program. ??? The program must control the vBot and make it activate ??? every target using the limited command set. It is meant to be an easy environment for introducing ??? some programming concepts to beginning programmers. https://bitbucket.org/leeharr/vbot This release adds several new levels and organizes them by ??? level of difficulty. It also adds several new features. vBot is tested with Python 2.7.3 and PyQt 4.9.1 vBot is released under GPLv3. Changes in vbot-0.3: ??? - Added success dialog with option to go to next level ??? - Sorted levels by difficulty and concept ??????? - Added utility for re-sorting levels by difficulty ??? - Backspace key removes last tile in active function ??? - Added ability to remember a player's completed levels online ??????? - server code not included with this distribution... From jeanpierreda at gmail.com Sun Jun 17 15:53:37 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 17 Jun 2012 15:53:37 -0400 Subject: How does python bytecode works? In-Reply-To: <1339926868.23717.YahooMailClassic@web164605.mail.gq1.yahoo.com> References: <1339926868.23717.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: On Sun, Jun 17, 2012 at 5:54 AM, gmspro wrote: > > We know python is written in C. > C is not portable. Badly written C is not portable. But C is probably the most portable language on the planet, by virtue of basically every system having a C compiler backend. The issue is that a lot of people make nonportable assumptions about C, and runtimes / OSes / architectures are free to make lots of very weird decisions. For example, this code is not strictly universally-compatible C. It is "portable" in that the changes required to make it run on any system are trivial, but not in the sense that it should be able to compile without any changes. (Not unless a cheeky/smart compiler is involved, anyway). int main () { return 0; } Instead of 0, it should "technically" return EXIT_SUCCESS AIUI. Most people don't care because EXIT_SUCCESS is 0 almost everywhere. > So how does python work on a webserver like apache/httpd for a python > website? > How does the intermediate language communicate with server without > compiling python code? Apache is written in C, and can embed CPython. This is easy enough, because CPython is written in C, and C works well with other C code. CPython itself can communicate with Python code, because it is directly responsible for running Python code. So the server communicates with CPython, and CPython communicates with the Python code. At no time does Python code ever "directly" touch anything other than the interpreter. The bytecode doesn't really have much to do with all this, except that it is the specific thing that CPython works with. -- Devin From alex.e.susu at gmail.com Sun Jun 17 17:15:59 2012 From: alex.e.susu at gmail.com (Alex Susu) Date: Sun, 17 Jun 2012 21:15:59 +0000 Subject: Cross-platform mobile application written in Python Message-ID: Hello. I would like to point you to a project that I worked on lately: iCam, a video surveillance cross-platform mobile application (Android, Symbian, iOS, WinCE) written in Python, which uploads normally media to YouTube and Picasa. The project can be found at http://code.google.com/p/icam-mobile-revival/ (also at http://go.to/slog). I would be happy to answer questions related to the project and appreciate if you can provide me feedback. With best regards, Alex Susu -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Sun Jun 17 17:28:21 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 18 Jun 2012 07:28:21 +1000 Subject: Threads vs subprocesses In-Reply-To: <20120618001728.5e31e84a92c059373e4f51a8@johnohagan.com> References: <20120618001728.5e31e84a92c059373e4f51a8@johnohagan.com> Message-ID: <20120617212820.GA13281@cskk.homeip.net> On 18Jun2012 00:17, John O'Hagan wrote: | On Sat, 16 Jun 2012 13:27:45 -0400 | Dennis Lee Bieber wrote: | > Not "after each event is read" but when a new event is | > generated/inserted. The list is not a FIFO where new events are added to | > the end, but more of a priority queue where the lowest time is the next | > to be retrieved. | | You're right, of course. Thought I'd point out that a heapq works nicely for this, or it has for me in this scenario , anyway. -- Cameron Simpson From gelonida at gmail.com Sun Jun 17 17:35:12 2012 From: gelonida at gmail.com (Gelonida N) Date: Sun, 17 Jun 2012 23:35:12 +0200 Subject: lazy evaluation of a variable Message-ID: Hi, I'm not sure whether what I ask for is impossible, but would know how others handle such situations. I'm having a module, which should lazily evaluate one of it's variables. Meaning that it is evaluated only if anybody tries to use this variable. At the moment I don't know how to do this and do therefore following: ####### mymodule.py ####### var = None def get_var(): global var if var is not None: return var var = something_time_consuming() Now the importing code would look like import mymodule def f(): var = mymodule.get_var() The disadvantage is, that I had to change existing code directly accessing the variable. I wondered if there were any way to change mymodule.py such, that the importing code could just access a variable and the lazy evaluation would happen transparently. import mymodule def f(): var = mymodule.var Thanks in advance for you suggestions From cs at zip.com.au Sun Jun 17 17:44:47 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 18 Jun 2012 07:44:47 +1000 Subject: lazy evaluation of a variable In-Reply-To: References: Message-ID: <20120617214447.GA14782@cskk.homeip.net> On 17Jun2012 23:35, Gelonida N wrote: | I'm having a module, which should lazily evaluate one of it's variables. | Meaning that it is evaluated only if anybody tries to use this variable. If it were an object member you could use a property. Does it need to be a module global? In related news, can one make "properties" for modules? I was wondering about this a month or so ago. -- Cameron Simpson If your new theorem can be stated with great simplicity, then there will exist a pathological exception. - Adrian Mathesis From rosuav at gmail.com Sun Jun 17 18:41:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jun 2012 08:41:57 +1000 Subject: Is that safe to use ramdom.random() for key to encrypt? In-Reply-To: <4FDE0E8B.3050701@gmail.com> References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> <4fdd5aac$0$29980$c3e8da3$5496439d@news.astraweb.com> <4FDE0E8B.3050701@gmail.com> Message-ID: On Mon, Jun 18, 2012 at 3:06 AM, Rafael Dur?n Casta?eda wrote: > The language Python includes a SystemRandom class that obtains cryptographic > grade random bits from /dev/urandom on a Unix-like system, including Linux > and Mac OS X, while on Windows it uses CryptGenRandom. /dev/urandom isn't actually cryptographically secure; it promises not to block, even if it has insufficient entropy. But in your instance... > Do you think is secure enough for token generation? (40 chars long tokens > are used for password reset links in a website, there isn't any special > security concern for the web). ... it probably is fine, since password reset tokens don't need to be as secure as encryption keys (if anyone _does_ figure out how to predict your password resets, all they'll be able to do is lock people out of their accounts one by one, not snoop on them all unbeknownst, and you'll be able to see log entries showing the resets - you DO log them, right?). In fact, you could probably get away with something pretty trivial there, like a SHA1 of the current timestamp, the user name, and the user's current password hash. The chances that anybody would be able to exploit that are fairly low, given that you're not a bank or other high-profile target. ChrisA From steve+comp.lang.python at pearwood.info Sun Jun 17 19:01:03 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jun 2012 23:01:03 GMT Subject: lazy evaluation of a variable References: Message-ID: <4fde61ae$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jun 2012 07:44:47 +1000, Cameron Simpson wrote: > On 17Jun2012 23:35, Gelonida N wrote: | I'm having > a module, which should lazily evaluate one of it's variables. | Meaning > that it is evaluated only if anybody tries to use this variable. > > If it were an object member you could use a property. Does it need to be > a module global? > > In related news, can one make "properties" for modules? I was wondering > about this a month or so ago. There have been various half-hearted requests for such a feature, including by myself, but nothing concrete. One day, in my Copious Spare Time, I intend to write a proper feature request and/or PEP for such a feature. Obviously the absolute earliest such a feature could be introduced is Python 3.4, about 18 months from now. (Although frankly, I would imagine significant opposition from the more conservative Python developers.) -- Steven From steve+comp.lang.python at pearwood.info Sun Jun 17 19:17:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jun 2012 23:17:37 GMT Subject: Is that safe to use ramdom.random() for key to encrypt? References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> <4fdd5aac$0$29980$c3e8da3$5496439d@news.astraweb.com> <4FDE0E8B.3050701@gmail.com> Message-ID: <4fde6591$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jun 2012 08:41:57 +1000, Chris Angelico wrote: > On Mon, Jun 18, 2012 at 3:06 AM, Rafael Dur?n Casta?eda > wrote: >> The language Python includes a SystemRandom class that obtains >> cryptographic grade random bits from /dev/urandom on a Unix-like >> system, including Linux and Mac OS X, while on Windows it uses >> CryptGenRandom. > > /dev/urandom isn't actually cryptographically secure; it promises not to > block, even if it has insufficient entropy. But in your instance... Correct. /dev/random is meant to be used for long-lasting cryptographically-significant uses, such as keys. urandom is not. http://en.wikipedia.org/wiki//dev/random >> Do you think is secure enough for token generation? (40 chars long >> tokens are used for password reset links in a website, there isn't any >> special security concern for the web). > > ... it probably is fine, since password reset tokens don't need to be as > secure as encryption keys (if anyone _does_ figure out how to predict > your password resets, all they'll be able to do is lock people out of > their accounts one by one, not snoop on them all unbeknownst, and you'll > be able to see log entries showing the resets - you DO log them, > right?). In fact, you could probably get away with something pretty > trivial there, like a SHA1 of the current timestamp, the user name, and > the user's current password hash. The chances that anybody would be able > to exploit that are fairly low, given that you're not a bank or other > high-profile target. If I were an identity thief, I would *love* low-profile targets. Even though the payoff would be reduced, the cost would be reduced even more: - they tend to be complacent, even more so than high-profile targets; - they tend to be smaller, with fewer resources for security; - mandatory disclosure laws tend not to apply to them; - they don't tend to have the resources to look for anomalous usage patterns, if they even cared enough to want to. If there was a Facebook-like website that wasn't Facebook[1], but still with multiple tens of thousands of users, I reckon a cracker who didn't vandalise people's accounts could steal private data from it for *years* before anyone noticed, and months or years more before they did something about it. [1] And very likely a Facebook-like website that *was* Facebook. I reckon the odds are about 50:50 that FB would prefer to keep a breach secret than risk the bad publicity by fixing it. -- Steven From __peter__ at web.de Sun Jun 17 19:40:57 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Jun 2012 01:40:57 +0200 Subject: lazy evaluation of a variable References: Message-ID: Gelonida N wrote: > I'm having a module, which should lazily evaluate one of it's variables. > Meaning that it is evaluated only if anybody tries to use this variable. > > At the moment I don't know how to do this and do therefore following: > > > ####### mymodule.py ####### > var = None > > def get_var(): > global var > if var is not None: > return var > var = something_time_consuming() > > > > Now the importing code would look like > > import mymodule > def f(): > var = mymodule.get_var() > > The disadvantage is, that I had to change existing code directly > accessing the variable. > > > I wondered if there were any way to change mymodule.py such, that the > importing code could just access a variable and the lazy evaluation > would happen transparently. > > import mymodule > def f(): > var = mymodule.var > > > > Thanks in advance for you suggestions You can inject arbitrary objects into sys.modules: >>> import sys >>> class MyModule(object): ... def __init__(self): ... self._var = None ... @property ... def var(self): ... result = self._var ... if result is None: ... print "calculating..." ... self._var = result = 42 ... return result ... >>> sys.modules["mymodule"] = MyModule() >>> import mymodule >>> mymodule.var calculating... 42 >>> mymodule.var 42 From no.email at nospam.invalid Sun Jun 17 19:48:48 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 17 Jun 2012 16:48:48 -0700 Subject: Is that safe to use ramdom.random() for key to encrypt? References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> <4fdd5aac$0$29980$c3e8da3$5496439d@news.astraweb.com> <4FDE0E8B.3050701@gmail.com> <4fde6591$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xd34x1ov3.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >> /dev/urandom isn't actually cryptographically secure; it promises not to >> block, even if it has insufficient entropy. But in your instance... > > Correct. /dev/random is meant to be used for long-lasting > cryptographically-significant uses, such as keys. urandom is not. They are both ill-advised if you're doing anything really serious. In practice if enough entropy has been in the system to make a key with /dev/random, then urandom should also be ok. Unfortunately the sensible interface is missing: block until there's enough entropy, then generate data cryptographically, folding in new entropy when it's available. http://web.archive.org/web/20081003041432/http://www.pinkas.net/PAPERS/gpr06.pdf has gory details of how random/urandom work. If you're really paranoid, get one of these: http://www.entropykey.co.uk/ From josehmartinezz at gmail.com Sun Jun 17 19:54:24 2012 From: josehmartinezz at gmail.com (Jose H. Martinez) Date: Sun, 17 Jun 2012 19:54:24 -0400 Subject: lazy evaluation of a variable In-Reply-To: References: Message-ID: Another option would be to refactor your function so that it is a generator expression using the yield keyword. On Sun, Jun 17, 2012 at 7:40 PM, Peter Otten <__peter__ at web.de> wrote: > Gelonida N wrote: > > > I'm having a module, which should lazily evaluate one of it's variables. > > Meaning that it is evaluated only if anybody tries to use this variable. > > > > At the moment I don't know how to do this and do therefore following: > > > > > > ####### mymodule.py ####### > > var = None > > > > def get_var(): > > global var > > if var is not None: > > return var > > var = something_time_consuming() > > > > > > > > Now the importing code would look like > > > > import mymodule > > def f(): > > var = mymodule.get_var() > > > > The disadvantage is, that I had to change existing code directly > > accessing the variable. > > > > > > I wondered if there were any way to change mymodule.py such, that the > > importing code could just access a variable and the lazy evaluation > > would happen transparently. > > > > import mymodule > > def f(): > > var = mymodule.var > > > > > > > > Thanks in advance for you suggestions > > You can inject arbitrary objects into sys.modules: > > >>> import sys > >>> class MyModule(object): > ... def __init__(self): > ... self._var = None > ... @property > ... def var(self): > ... result = self._var > ... if result is None: > ... print "calculating..." > ... self._var = result = 42 > ... return result > ... > >>> sys.modules["mymodule"] = MyModule() > >>> import mymodule > >>> mymodule.var > calculating... > 42 > >>> mymodule.var > 42 > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Sun Jun 17 19:57:11 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 17 Jun 2012 16:57:11 -0700 Subject: How does python bytecode works? In-Reply-To: <1339926868.23717.YahooMailClassic@web164605.mail.gq1.yahoo.com> References: <1339926868.23717.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: On Sun, Jun 17, 2012 at 2:54 AM, gmspro wrote: > We know python is written in C. > Yes, at least CPython is. Of course, java is written in C, as are many other languages. > C is not portable. > C gives you lots of rope to hang yourself with, but if you use C well, it's more portable than anything else, including the "portable" languages (the ones that don't give you much rope). > So how does python work on a webserver like apache/httpd for a python > website? > I guess this is kind of like asking how you breathe. Python just gets exec'd or dlopen'd or something. > How does the intermediate language communicate with server without > compiling python code? > CPython is to .pyc as java is to .class. They're both byte-compiled. Java is more commonly JIT compiled than CPython, but Python in general does allow JIT compilation. IOW, CPython is compiled, it just doesn't burden the developer with a separate compile step. > Or how does python interpreted code work with webserver for python based > websites? > Please see above. > Please elaborate/explain this topic with example. > You may get better answers if you get into more specifics about what your question really is. -------------- next part -------------- An HTML attachment was scrubbed... URL: From joncle at googlemail.com Sun Jun 17 20:07:28 2012 From: joncle at googlemail.com (Jon Clements) Date: Mon, 18 Jun 2012 00:07:28 +0000 (UTC) Subject: Is that safe to use ramdom.random() for key to encrypt? References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> <4fdd5aac$0$29980$c3e8da3$5496439d@news.astraweb.com> <4FDE0E8B.3050701@gmail.com> <4fde6591$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 17 Jun 2012 23:17:37 +0000, Steven D'Aprano wrote: > On Mon, 18 Jun 2012 08:41:57 +1000, Chris Angelico wrote: > >> On Mon, Jun 18, 2012 at 3:06 AM, Rafael Dur?n Casta?eda >> wrote: >>> The language Python includes a SystemRandom class that obtains >>> cryptographic grade random bits from /dev/urandom on a Unix-like >>> system, including Linux and Mac OS X, while on Windows it uses >>> CryptGenRandom. >> >> /dev/urandom isn't actually cryptographically secure; it promises not >> to block, even if it has insufficient entropy. But in your instance... > > Correct. /dev/random is meant to be used for long-lasting > cryptographically-significant uses, such as keys. urandom is not. > > http://en.wikipedia.org/wiki//dev/random > > >>> Do you think is secure enough for token generation? (40 chars long >>> tokens are used for password reset links in a website, there isn't any >>> special security concern for the web). >> >> ... it probably is fine, since password reset tokens don't need to be >> as secure as encryption keys (if anyone _does_ figure out how to >> predict your password resets, all they'll be able to do is lock people >> out of their accounts one by one, not snoop on them all unbeknownst, >> and you'll be able to see log entries showing the resets - you DO log >> them, right?). In fact, you could probably get away with something >> pretty trivial there, like a SHA1 of the current timestamp, the user >> name, and the user's current password hash. The chances that anybody >> would be able to exploit that are fairly low, given that you're not a >> bank or other high-profile target. > > If I were an identity thief, I would *love* low-profile targets. Even > though the payoff would be reduced, the cost would be reduced even more: > > - they tend to be complacent, even more so than high-profile targets; > > - they tend to be smaller, with fewer resources for security; > > - mandatory disclosure laws tend not to apply to them; > > - they don't tend to have the resources to look for anomalous usage > patterns, if they even cared enough to want to. > > > If there was a Facebook-like website that wasn't Facebook[1], but still > with multiple tens of thousands of users, I reckon a cracker who didn't > vandalise people's accounts could steal private data from it for *years* > before anyone noticed, and months or years more before they did > something about it. > > > > [1] And very likely a Facebook-like website that *was* Facebook. I > reckon the odds are about 50:50 that FB would prefer to keep a breach > secret than risk the bad publicity by fixing it. > > > -- > Steven I'm reminded of: http://xkcd.com/936/ http://xkcd.com/792/ There's also one where it's pointed out it's easier to brute force a person who has the code, than brute force the computer. [but can't find that one at the moment] From bahamutzero8825 at gmail.com Sun Jun 17 20:18:55 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 17 Jun 2012 19:18:55 -0500 Subject: Is that safe to use ramdom.random() for key to encrypt? In-Reply-To: References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> <4fdd5aac$0$29980$c3e8da3$5496439d@news.astraweb.com> <4FDE0E8B.3050701@gmail.com> <4fde6591$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FDE73EF.7070708@gmail.com> On 6/17/2012 7:07 PM, Jon Clements wrote: > I'm reminded of: > > http://xkcd.com/936/ > http://xkcd.com/792/ > > There's also one where it's pointed out it's easier to brute force a > person who has the code, than brute force the computer. [but can't find > that one at the moment] http://xkcd.com/538/ -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From ben+python at benfinney.id.au Sun Jun 17 20:19:35 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 18 Jun 2012 10:19:35 +1000 Subject: Academic citation of Python References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> Message-ID: <87k3z5v5d4.fsf@benfinney.id.au> Curt writes: > On 2012-06-16, Christian Heimes wrote: > > > > Actually it's "van Rossum, Guido", not "Rossum, Guido van". The > > "van" is part of the family name, not a middle name. It's like "da > > Vinci, Leonardo" or "von Sydow, Max". On one occasion Guido > > complained that Americans always get his name wrong. > > I've read that now he prefers Guido V. Rossum, Jr. Citation needed. -- \ ?Alternative explanations are always welcome in science, if | `\ they are better and explain more. Alternative explanations that | _o__) explain nothing are not welcome.? ?Victor J. Stenger, 2001-11-05 | Ben Finney From kushal.kumaran+python at gmail.com Mon Jun 18 02:08:53 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 18 Jun 2012 11:38:53 +0530 Subject: How does python bytecode works? In-Reply-To: References: <1339926868.23717.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: On Mon, Jun 18, 2012 at 1:23 AM, Devin Jeanpierre wrote: > On Sun, Jun 17, 2012 at 5:54 AM, gmspro wrote: >> >> We know python is written in C. >> C is not portable. > > Badly written C is not portable. But C is probably the most portable > language on the planet, by virtue of basically every system having a C > compiler backend. > > The issue is that a lot of people make nonportable assumptions about > C, and runtimes / OSes / architectures are free to make lots of very > weird decisions. > > For example, this code is not strictly universally-compatible C. It is > "portable" in that the changes required to make it run on any system > are trivial, but not in the sense that it should be able to compile > without any changes. (Not unless a cheeky/smart compiler is involved, > anyway). > > int main () { > ? ?return 0; > } > > Instead of 0, it should "technically" return EXIT_SUCCESS AIUI. Most > people don't care because EXIT_SUCCESS is 0 almost everywhere. > In the interests of pedantry, I will point out that the C standard requires implementation to treat both 0 and EXIT_SUCCESS to be treated as successful exits. The implementation must translate this to whatever the environment treats as successful termination of the program. Ref: specification of the exit(int) function. >> So how does python work on a webserver like apache/httpd for a python >> website? >> How does the intermediate language communicate with server without >> compiling python code? > > Apache is written in C, and can embed CPython. This is easy enough, > because CPython is written in C, and C works well with other C code. > CPython itself can communicate with Python code, because it is > directly responsible for running Python code. So the server > communicates with CPython, and CPython communicates with the Python > code. At no time does Python code ever "directly" touch anything other > than the interpreter. > > > The bytecode doesn't really have much to do with all this, except that > it is the specific thing that CPython works with. > -- regards, kushal From curty at free.fr Mon Jun 18 02:20:41 2012 From: curty at free.fr (Curt) Date: 18 Jun 2012 06:20:41 GMT Subject: Academic citation of Python References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> <87k3z5v5d4.fsf@benfinney.id.au> Message-ID: On 2012-06-18, Ben Finney wrote: >> > >> > Actually it's "van Rossum, Guido", not "Rossum, Guido van". The >> > "van" is part of the family name, not a middle name. It's like "da >> > Vinci, Leonardo" or "von Sydow, Max". On one occasion Guido >> > complained that Americans always get his name wrong. >> >> I've read that now he prefers Guido V. Rossum, Jr. > > Citation needed. Sorry: ;-) From tjreedy at udel.edu Mon Jun 18 02:40:03 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Jun 2012 02:40:03 -0400 Subject: lazy evaluation of a variable In-Reply-To: References: Message-ID: On 6/17/2012 5:35 PM, Gelonida N wrote: > I'm having a module, which should lazily evaluate one of it's variables. If you literally mean a module object, that is not possible. On the other hand, it is easy to do with class instances, via the __getattr__ special method or via properties. > At the moment I don't know how to do this and do therefore following: > ####### mymodule.py ####### > var = None > > def get_var(): > global var > if var is not None: > return var > var = something_time_consuming() > Now the importing code would look like > > import mymodule > def f(): > var = mymodule.get_var() > > The disadvantage is, that I had to change existing code directly > accessing the variable. > I wondered if there were any way to change mymodule.py such, that the > importing code could just access a variable and the lazy evaluation > would happen transparently. > > import mymodule > def f(): > var = mymodule.var You could now do (untested, too late at night) # mymodule.py class _Lazy(): def __getattr__(self, name): if name == 'var': self.var = something_time_consuming() return self.var lazy = _Lazy() # user script from mymodule import lazy def f(): var = lazy.var See Peter's post for using properties instead. That probably scales better for multiple lazy attibutes. -- Terry Jan Reedy From animator333 at gmail.com Mon Jun 18 03:10:53 2012 From: animator333 at gmail.com (Prashant) Date: Mon, 18 Jun 2012 00:10:53 -0700 (PDT) Subject: post init call Message-ID: <7cbcea32-075b-42a1-bae6-77b9a407d17e@googlegroups.com> class Shape(object): def __init__(self, shapename): self.shapename = shapename def update(self): print "update" class ColoredShape(Shape): def __init__(self, color): Shape.__init__(self, color) self.color = color print 1 print 2 print 3 self.update() User can sub-class 'Shape' and create custom shapes. How ever user must call 'self.update()' as the last argument when ever he is sub-classing 'Shape'. I would like to know if it's possible to call 'self.update()' automatically after the __init__ of sub-class is done? Cheers From wxjmfauth at gmail.com Mon Jun 18 04:19:32 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 18 Jun 2012 01:19:32 -0700 (PDT) Subject: Py3.3 unicode literal and input() Message-ID: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> What is input() supposed to return? >>> u'a' == 'a' True >>> >>> r1 = input(':') :a >>> r2 = input(':') :u'a' >>> r1 == r2 False >>> type(r1), len(r1) (, 1) >>> type(r2), len(r2) (, 4) >>> --- sys.argv? jmf From ulrich.eckhardt at dominolaser.com Mon Jun 18 04:27:42 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 18 Jun 2012 10:27:42 +0200 Subject: post init call In-Reply-To: <7cbcea32-075b-42a1-bae6-77b9a407d17e@googlegroups.com> References: <7cbcea32-075b-42a1-bae6-77b9a407d17e@googlegroups.com> Message-ID: Am 18.06.2012 09:10, schrieb Prashant: > class Shape(object): > def __init__(self, shapename): > self.shapename = shapename > > > def update(self): > print "update" > > class ColoredShape(Shape): > def __init__(self, color): > Shape.__init__(self, color) Two things here: 1. You pass "color" as "shapename" to the baseclass' initialisation function, which is a bit surprising. 2. You can use super(ColoredShape, self).__init__(color) or even super(self).__init__(color). > User can sub-class 'Shape' and create custom shapes. How ever user > must call 'self.update()' as the last argument when ever he is > sub-classing 'Shape'. > I would like to know if it's possible to call 'self.update()' > automatically after the __init__ of sub-class is done? You might be able to, by hacking on the (meta?) class and how/when things are constructed. I'm not sure how to approach that though. What I would do is to use lazy initialisation, i.e. call update() when it is actually needed. For that, you could create a decorator and put it on all methods that require this initialisation. Good luck! Uli From benjamin.kaplan at case.edu Mon Jun 18 04:28:11 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 18 Jun 2012 01:28:11 -0700 Subject: Py3.3 unicode literal and input() In-Reply-To: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> Message-ID: On Mon, Jun 18, 2012 at 1:19 AM, jmfauth wrote: > What is input() supposed to return? > >>>> u'a' == 'a' > True >>>> >>>> r1 = input(':') > :a >>>> r2 = input(':') > :u'a' >>>> r1 == r2 > False >>>> type(r1), len(r1) > (, 1) >>>> type(r2), len(r2) > (, 4) >>>> > > --- > > sys.argv? > > jmf Python 3 made several backwards-incompatible changes over Python 2. First of all, input() in Python 3 is equivalent to raw_input() in Python 2. It always returns a string. If you want the equivalent of Python 2's input(), eval the result. Second, Python 3 is now unicode by default. The "str" class is a unicode string. There is a separate bytes class, denoted by b"", for byte strings. The u prefix is only there to make it easier to port a codebase from Python 2 to Python 3. It doesn't actually do anything. From wxjmfauth at gmail.com Mon Jun 18 05:30:50 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 18 Jun 2012 02:30:50 -0700 (PDT) Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> Message-ID: On 18 juin, 10:28, Benjamin Kaplan wrote: > On Mon, Jun 18, 2012 at 1:19 AM, jmfauth wrote: > > What is input() supposed to return? > > >>>> u'a' == 'a' > > True > > >>>> r1 = input(':') > > :a > >>>> r2 = input(':') > > :u'a' > >>>> r1 == r2 > > False > >>>> type(r1), len(r1) > > (, 1) > >>>> type(r2), len(r2) > > (, 4) > > > --- > > > sys.argv? > > > jmf > > Python 3 made several backwards-incompatible changes over Python 2. > First of all, input() in Python 3 is equivalent to raw_input() in > Python 2. It always returns a string. If you want the equivalent of > Python 2's input(), eval the result. Second, Python 3 is now unicode > by default. The "str" class is a unicode string. There is a separate > bytes class, denoted by b"", for byte strings. The u prefix is only > there to make it easier to port a codebase from Python 2 to Python 3. > It doesn't actually do anything. It does. I shew it! Related: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3aefd602507d2fbe# http://mail.python.org/pipermail/python-dev/2012-June/120341.html jmf From steve+comp.lang.python at pearwood.info Mon Jun 18 06:08:02 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Jun 2012 10:08:02 GMT Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> Message-ID: <4fdefe02$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jun 2012 01:19:32 -0700, jmfauth wrote: > What is input() supposed to return? Whatever you type. >>>> u'a' == 'a' > True This demonstrates that in Python 3.3, u'a' gives a string equal to 'a'. >>>> r1 = input(':') > :a Since you typed the letter a, r1 is the string "a" (a single character). >>>> r2 = input(':') > :u'a' Since you typed four characters, namely lowercase u, single quote, lowercase a, single quote, r2 is the string "u'a'" (four characters). >>>> r1 == r2 > False >>>> type(r1), len(r1) > (, 1) >>>> type(r2), len(r2) > (, 4) If you call print(r1) and print(r2), that will show you what they hold. If in doubt, calling print(repr(r1)) will show extra information about the object. > sys.argv? What about it? > > jmf From steve+comp.lang.python at pearwood.info Mon Jun 18 06:11:28 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Jun 2012 10:11:28 GMT Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> Message-ID: <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jun 2012 02:30:50 -0700, jmfauth wrote: > On 18 juin, 10:28, Benjamin Kaplan wrote: >> The u prefix is only there to >> make it easier to port a codebase from Python 2 to Python 3. It doesn't >> actually do anything. > > > It does. I shew it! Incorrect. You are assuming that Python 3 input eval's the input like Python 2 does. That is wrong. All you show is that the one-character string "a" is not equal to the four-character string "u'a'", which is hardly a surprise. You wouldn't expect the string "3" to equal the string "int('3')" would you? -- Steven From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Jun 18 06:21:59 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 18 Jun 2012 12:21:59 +0200 Subject: post init call In-Reply-To: <7cbcea32-075b-42a1-bae6-77b9a407d17e@googlegroups.com> References: <7cbcea32-075b-42a1-bae6-77b9a407d17e@googlegroups.com> Message-ID: Am 18.06.2012 09:10 schrieb Prashant: > class Shape(object): > def __init__(self, shapename): > self.shapename = shapename > def update(self): > print "update" > > class ColoredShape(Shape): > def __init__(self, color): > Shape.__init__(self, color) > self.color = color > print 1 > print 2 > print 3 > self.update() > > User can sub-class 'Shape' and create custom shapes. How ever user must call 'self.update()' as the last argument when ever he is sub-classing 'Shape'. > I would like to know if it's possible to call 'self.update()' automatically after the __init__ of sub-class is done? > > Cheers I would construct it this way: class Shape(object): def __init__(self, *args): self.args = args self.init() self.update() # or: if self.init(): self.update() def init(self): return False # don't call update def update(self): print "update" @propery def shapename(self): return self.args[0] class ColoredShape(Shape): def init(self): print 1, 2, 3 self.update() return True @property def color(self): return self.args[1] Thomas From __peter__ at web.de Mon Jun 18 06:45:57 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Jun 2012 12:45:57 +0200 Subject: post init call References: <7cbcea32-075b-42a1-bae6-77b9a407d17e@googlegroups.com> Message-ID: Prashant wrote: > class Shape(object): > def __init__(self, shapename): > self.shapename = shapename > > > def update(self): > print "update" > > class ColoredShape(Shape): > def __init__(self, color): > Shape.__init__(self, color) > self.color = color > print 1 > print 2 > print 3 > self.update() > > User can sub-class 'Shape' and create custom shapes. How ever user must > call 'self.update()' as the last argument when ever he is sub-classing > 'Shape'. I would like to know if it's possible to call 'self.update()' > automatically after the __init__ of sub-class is done? I don't think so. You could however shuffle things around a bit: class Shape(object): def __init__(self, shapename, *args, **kw): self.shapename = shapename self.init(*args, **kw) self.update() def init(self, *args, **kw): pass def update(self): print "update" In that constellation you would override init(), not __init__(): class ColoredShape(Shape): def init(self, color, **kw): self.color = color print 1 print 2 print 3 From merciervspam at gmail.com Mon Jun 18 07:31:12 2012 From: merciervspam at gmail.com (Valentin Mercier) Date: Mon, 18 Jun 2012 13:31:12 +0200 Subject: Problem with ImapLib and subject in French Message-ID: Hi, I'm trying to search some mails with SUBJECT criteria, but the problem is the encoding, I'm trying to search french terms (impalib and python V2.7) I've tried few things, but I think the encoding is the problem, in my mail header I have something like this: =?iso-8859-1?Q?Job:_"Full_Backup_Les_Gr=E8ves_du_Lac")_?= I need to search unseen mail with the FROM and the SUBJECT criteria. I take those two in parameters in my python script and the second contain special caracters like ? or ?, so I encode the string like this: temp = header_encode(unicode('Les gr?ves','utf-8'), charset='iso-8859-1') And the string is exactly the same as the header: =?iso-8859-1?q?Full_Backup_Les_Gr=E8ves?= But the search function doesn't find my email, and I don't know why, even if I try with the entire string of the subject. I hope you can understand my question and my english (I'm from switzerland so my english is not so good) and you can answer me. Thanks in advance and best regards Valentin Mercier -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Mon Jun 18 09:19:36 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 18 Jun 2012 09:19:36 -0400 Subject: module name vs '.' Message-ID: Am I correct that a module could never come from a file path with a '.' in the name? From d at davea.name Mon Jun 18 09:44:49 2012 From: d at davea.name (Dave Angel) Date: Mon, 18 Jun 2012 09:44:49 -0400 Subject: module name vs '.' In-Reply-To: References: Message-ID: <4FDF30D1.7020301@davea.name> On 06/18/2012 09:19 AM, Neal Becker wrote: > Am I correct that a module could never come from a file path with a '.' in the > name? > No. Simple example: Create a directory called src.directory In that directory, create two files ::neal.py:: import becker print becker.__file__ print becker.hello() ::becker.py:: def hello(): print "Inside hello" return "returning" Then run neal.py, from that directory; davea at think:~/temppython/src.directory$ python neal.py /mnt/data/davea/temppython/src.directory/becker.pyc Inside hello returning davea at think:~/temppython/src.directory$ Observe the results of printing __file__ Other approaches include putting a directory path containing a period into sys.path -- DaveA From ndbecker2 at gmail.com Mon Jun 18 09:47:46 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 18 Jun 2012 09:47:46 -0400 Subject: module name vs '.' In-Reply-To: <4FDF30D1.7020301@davea.name> References: <4FDF30D1.7020301@davea.name> Message-ID: I meant a module src.directory contains __init__.py neal.py becker.py from src.directory import neal On Mon, Jun 18, 2012 at 9:44 AM, Dave Angel wrote: > On 06/18/2012 09:19 AM, Neal Becker wrote: > > Am I correct that a module could never come from a file path with a '.' > in the > > name? > > > > No. > > Simple example: Create a directory called src.directory > In that directory, create two files > > ::neal.py:: > import becker > print becker.__file__ > print becker.hello() > > > ::becker.py:: > def hello(): > print "Inside hello" > return "returning" > > > Then run neal.py, from that directory; > > > davea at think:~/temppython/src.directory$ python neal.py > /mnt/data/davea/temppython/src.directory/becker.pyc > Inside hello > returning > davea at think:~/temppython/src.directory$ > > Observe the results of printing __file__ > > Other approaches include putting a directory path containing a period > into sys.path > > > > -- > > DaveA > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Mon Jun 18 09:54:53 2012 From: d at davea.name (Dave Angel) Date: Mon, 18 Jun 2012 09:54:53 -0400 Subject: module name vs '.' In-Reply-To: References: <4FDF30D1.7020301@davea.name> Message-ID: <4FDF332D.3000205@davea.name> On 06/18/2012 09:47 AM, Neal Becker wrote: > I meant a module > > src.directory contains > __init__.py > neal.py > becker.py > > from src.directory import neal > > > On Mon, Jun 18, 2012 at 9:44 AM, Dave Angel wrote: > >> On 06/18/2012 09:19 AM, Neal Becker wrote: >>> Am I correct that a module could never come from a file path with a '.' >> in the >>> name? >>> >> >> No. >> >> Simple example: Create a directory called src.directory >> In that directory, create two files >> >> ::neal.py:: >> import becker >> print becker.__file__ >> print becker.hello() >> >> >> ::becker.py:: >> def hello(): >> print "Inside hello" >> return "returning" >> >> >> Then run neal.py, from that directory; >> >> >> davea at think:~/temppython/src.directory$ python neal.py >> /mnt/data/davea/temppython/src.directory/becker.pyc >> Inside hello >> returning >> davea at think:~/temppython/src.directory$ >> >> Observe the results of printing __file__ >> >> Other approaches include putting a directory path containing a period >> into sys.path >> >> >> >> -- >> >> DaveA >> >> > In my example, becker.py is a module and I imported it. If you're now asking specifically about using the syntax from src.directory import neal that has nothing to do with periods being in a directory name. That period in the source code separates a package name from a module name, and will not find a package named "src.directory" -- DaveA From wxjmfauth at gmail.com Mon Jun 18 10:00:01 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 18 Jun 2012 07:00:01 -0700 (PDT) Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> On 18 juin, 12:11, Steven D'Aprano wrote: > On Mon, 18 Jun 2012 02:30:50 -0700, jmfauth wrote: > > On 18 juin, 10:28, Benjamin Kaplan wrote: > >> The u prefix is only there to > >> make it easier to port a codebase from Python 2 to Python 3. It doesn't > >> actually do anything. > > > It does. I shew it! > > Incorrect. You are assuming that Python 3 input eval's the input like > Python 2 does. That is wrong. All you show is that the one-character > string "a" is not equal to the four-character string "u'a'", which is > hardly a surprise. You wouldn't expect the string "3" to equal the string > "int('3')" would you? > > -- > Steven A string is a string, a "piece of text", period. I do not see why a unicode literal and an (well, I do not know how the call it) a "normal class " should behave differently in code source or as an answer to an input(). Should a user write two derived functions? input_for_entering_text() and input_if_you_are_entering_a_text_as_litteral() --- Side effect from the unicode litteral reintroduction. I do not mind about this, but I expect it does work logically and correctly. And it does not. PS English is not my native language. I never know to reply to an (interro)-negative sentence. jmf From bahamutzero8825 at gmail.com Mon Jun 18 10:28:59 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 18 Jun 2012 09:28:59 -0500 Subject: Py3.3 unicode literal and input() In-Reply-To: <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> Message-ID: <4FDF3B2B.9080400@gmail.com> Perhaps this will clear things up: Python 3.3.0a4 (v3.3.0a4:7c51388a3aa7, May 31 2012, 20:17:41) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> ua = u'a' >>> literal_ua = "u'a'" >>> ua == literal_ua False >>> input_ua = input() u'a' >>> input_ua "u'a'" >>> input_ua == ua False >>> input_ua == literal_ua True >>> eval_ua = eval(literal_ua) >>> eval_ua 'a' >>> eval(literal_ua) == input_ua False >>> eval(literal_ua) == ua True >>> u'a' == 'a' True >>> u'a' is 'a' True -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From d at davea.name Mon Jun 18 10:42:31 2012 From: d at davea.name (Dave Angel) Date: Mon, 18 Jun 2012 10:42:31 -0400 Subject: Py3.3 unicode literal and input() In-Reply-To: <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> Message-ID: <4FDF3E57.5040000@davea.name> On 06/18/2012 10:00 AM, jmfauth wrote: > > A string is a string, a "piece of text", period. I do not see why a > unicode literal and an (well, I do not know how the call it) a "normal > class " should behave differently in code source or as an answer > to an input(). Wrong. The rules for parsing source code are NOT applied in general to Python 3's input data, nor to file I/O done with methods like myfile.readline(). We do not expect the runtime code to look for def statements, nor for class statements, and not for literals. A literal is a portion of source code where there are specific rules applied, starting with the presence of some quote characters. This is true of nearly all languages, and in most languages, the difference is so obvious that the question seldom gets raised. For example, in C code a literal is evaluated at compile time, and by the time an end user sees an input prompt, he probably doesn't even have a compiler on the same machine. When an end user types in his data (into an input statement, typically), he does NOT use quote literals, he does not use hex escape codes, he does not escape things with backslash. If he wants an o with an umlaut on it, he'd better have such a character available on his keyboard. i'd suggest playing around a little with literal assignments and input statements and print functions. In those literals, try entering escape sequences (eg. "ab\x41cd") Run such programs from the command line, and observe the output from the prints. Do this without using the interactive interpreter, as by default it "helpfully" displays expressions with the repr() function, which confuses the issue. > Should a user write two derived functions? input_for_entering_text() > and input_if_you_are_entering_a_text_as_litteral() --- Side effect > from the unicode litteral reintroduction. I do not mind about this, > but I expect it does work logically and correctly. And it does not. PS > English is not my native language. I never know to reply to an > (interro)-negative sentence. jmf The user doesn't write functions, the programmer does. Until you learn to distinguish between those two phases, you'll continue having this confusion. If you (the programmer) want a function that asks the user to enter a literal at the input prompt, you'll have to write a post-processing for it, which looks for prefixes, for quotes, for backslashes, etc., and encodes the result. There very well may be such a decoder in the Python library, but input does nothing of the kind. The literal modifiers (u"" or r"") are irrelevant here. The "problem" you're having is universal, and not new. The characters in source code have different semantic meanings than those entered in input, or read from file I/O. -- DaveA From ulrich.eckhardt at dominolaser.com Mon Jun 18 10:46:20 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 18 Jun 2012 16:46:20 +0200 Subject: Py3.3 unicode literal and input() In-Reply-To: <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> Message-ID: Am 18.06.2012 16:00, schrieb jmfauth: > A string is a string, a "piece of text", period. No. There are different representations for the same piece of text even in the context of just Python. b'fou', u'fou', 'fou' are three different source code representations, resulting in two different runtime representation and they all represent the same text: fou. > I do not see why a unicode literal and an (well, I do not > know how the call it) a "normal class " should behave > differently in code source or as an answer to an input(). input() retrieves a string from a user, not from a programmer that can be expected to know the difference between b'\x81' and u'\u20ac'. > Should a user write two derived functions? > > input_for_entering_text() > and > input_if_you_are_entering_a_text_as_litteral() With "user" above, I guess you mean "Python programmer". In that case, the answer is yes. Although asking the user of your program to learn about Python's string literal formatting options is a bit much. > Side effect from the unicode litteral reintroduction. > I do not mind about this, but I expect it does > work logically and correctly. And it does not. Yes it does. The user enters something. Python receives this and provides it as string. You as a programmer are now supposed to interpret, parse etc this string according to your program logic. BTW: Just in case there is a language (native language, not programming language) problem, don't hesitate to write in your native language, too. Chances are good that someone here understands you. Good luck! Uli From arnodel at gmail.com Mon Jun 18 10:55:53 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 18 Jun 2012 15:55:53 +0100 Subject: Problem with ImapLib and subject in French In-Reply-To: References: Message-ID: On 18 June 2012 12:31, Valentin Mercier wrote: > Hi, > > I'm trying to search some mails with SUBJECT criteria, but the problem is > the encoding, I'm trying to search french terms (impalib and python V2.7) > > I've tried few things, but I think the encoding is the problem, in my mail > header I have something like this: > > ?=?iso-8859-1?Q?Job:_"Full_Backup_Les_Gr=E8ves_du_Lac")_?= > > I need to search unseen mail with the FROM and the SUBJECT criteria. I take > those two in parameters in my python script and the second contain special > caracters like ? or ?, so I encode the string like this: > > ?? ? ? ? ? ? temp = header_encode(unicode('Les gr?ves','utf-8'), > charset='iso-8859-1') > > And the string is exactly the same as the header: > > =?iso-8859-1?q?Full_Backup_Les_Gr=E8ves?= > > But the search function doesn't find my email, and I don't know why, even if > I try with the entire string of the subject. Can you post the code that doesn't work? It's hard to debug "search function doesn't find my email". It would be easier to debug actual code (note: I'm not a user of imaplib so I'm not promising anything :) -- Arnaud From alex.e.susu at gmail.com Mon Jun 18 11:10:47 2012 From: alex.e.susu at gmail.com (Alex Susu) Date: Mon, 18 Jun 2012 18:10:47 +0300 Subject: Cross-platform mobile application written in Python Message-ID: Hello. I would like to point you to a project that I worked on lately: iCam, a video surveillance cross-platform mobile application (Android, Symbian, iOS, WinCE) written in Python, which uploads normally media to YouTube and Picasa. The project can be found at http://code.google.com/p/icam-mobile-revival/ (also at http://go.to/slog). I would be happy to answer questions related to the project and appreciate if you can provide me feedback. With best regards, Alex Susu -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Mon Jun 18 11:44:17 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 18 Jun 2012 08:44:17 -0700 (PDT) Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> Message-ID: <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> Thinks are very clear to me. I wrote enough interactive interpreters with all available toolkits for Windows since I know Python (v. 1.5.6). I do not see why the semantic may vary differently in code source or in an interactive interpreter, esp. if Python allow it! If you have to know by advance what an end user is supposed to type and/or check it ('str' or unicode literal) in order to know if the answer has to be evaluated or not, then it is better to reintroduce input() and raw_input(). jmf From rosuav at gmail.com Mon Jun 18 12:01:25 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2012 02:01:25 +1000 Subject: Py3.3 unicode literal and input() In-Reply-To: <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> Message-ID: On Tue, Jun 19, 2012 at 1:44 AM, jmfauth wrote: > I do not see why the semantic may vary differently > in code source or in an interactive interpreter, > esp. if Python allow it! When you're asking for input, you usually aren't looking for code. It doesn't matter about string literal formats, because you don't need to delimit it. In code, you need to make it clear to the interpreter where your string finishes, and that's traditionally done with quote characters: name = "Chris Angelico" # this isn't part of the string, because the two quotes mark off the ends of it And you can include characters in your literals that you don't want in your source code: bad_chars = "\x00\x1A\x0A" # three characters NUL, SUB, LF Everything about raw strings, Unicode literals, triple-quoted strings, etc, etc, etc, is just variants on these two basic concepts. The interpreter needs to know what you mean. With input, though, the end of the string is defined in some other way (such as by the user pushing Enter). The interpreter knows without any extra hints where it's to stop parsing. Also, there's no need to protect certain characters from getting into your code. It's a much easier job for the interpreter, which translates to being much simpler for the user: just type what you want and hit Enter. Quote characters have no meaning. Chris Angelico From jpiitula at ling.helsinki.fi Mon Jun 18 12:32:21 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 18 Jun 2012 19:32:21 +0300 Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> Message-ID: jmfauth writes: > Thinks are very clear to me. I wrote enough interactive > interpreters with all available toolkits for Windows >>> r = input() u'a Traceback (most recent call last): File "", line 1, in SyntaxError: u'a Er, no, not really :-) From wxjmfauth at gmail.com Mon Jun 18 12:39:40 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 18 Jun 2012 09:39:40 -0700 (PDT) Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> Message-ID: <44a6bacd-d4d7-4c1f-ae1a-8f9ce4a1abc9@d6g2000vbe.googlegroups.com> We are turning in circles. You are somehow legitimating the reintroduction of unicode literals and I shew, not to say proofed, it may be a source of problems. Typical Python desease. Introduce a problem, then discuss how to solve it, but surely and definitivly do not remove that problem. As far as I know, Python 3.2 is working very well. jmf From bahamutzero8825 at gmail.com Mon Jun 18 12:55:14 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 18 Jun 2012 11:55:14 -0500 Subject: Py3.3 unicode literal and input() In-Reply-To: References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> Message-ID: <4FDF5D72.5020002@gmail.com> On 6/18/2012 11:32 AM, Jussi Piitulainen wrote: > jmfauth writes: > >> Thinks are very clear to me. I wrote enough interactive >> interpreters with all available toolkits for Windows > >>>> r = input() > u'a > Traceback (most recent call last): > File "", line 1, in > SyntaxError: u'a > > Er, no, not really :-) > You're using 2.x; this thread concerns 3.3, which, as has been repeated several times, does not evaluate strings passed via input() like 2.x. That code does not raise a SyntaxError in 3.x. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From johnroth1 at gmail.com Mon Jun 18 12:55:32 2012 From: johnroth1 at gmail.com (John Roth) Date: Mon, 18 Jun 2012 09:55:32 -0700 (PDT) Subject: Py3.3 unicode literal and input() In-Reply-To: <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> Message-ID: <6604f5b9-7946-4ddd-a4ce-50db764d63f1@googlegroups.com> On Monday, June 18, 2012 9:44:17 AM UTC-6, jmfauth wrote: > Thinks are very clear to me. I wrote enough interactive > interpreters with all available toolkits for Windows > since I know Python (v. 1.5.6). > > I do not see why the semantic may vary differently > in code source or in an interactive interpreter, > esp. if Python allow it! > > If you have to know by advance what an end user > is supposed to type and/or check it ('str' or unicode > literal) in order to know if the answer has to be > evaluated or not, then it is better to reintroduce > input() and raw_input(). > The change between Python 2.x and 3.x was made for security reasons. The developers felt, correctly in my opinion, that the simpler operation should not pose a security risk of a malicious user entering an expression that would corrupt the program. In Python 3.x the equivalent of Python 2.x's input() function is eval(input()). It poses the same security risk: acting on unchecked user data. John Roth > jmf From chess at us.ibm.com Mon Jun 18 12:58:37 2012 From: chess at us.ibm.com (David M Chess) Date: Mon, 18 Jun 2012 12:58:37 -0400 Subject: Py3.3 unicode literal and input() In-Reply-To: <4FDF3E57.5040000@davea.name> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <4FDF3E57.5040000@davea.name> Message-ID: > If you (the programmer) want a function that asks the user to enter a > literal at the input prompt, you'll have to write a post-processing for > it, which looks for prefixes, for quotes, for backslashes, etc., and > encodes the result. There very well may be such a decoder in the Python > library, but input does nothing of the kind. As it says at the end of eval() (which you definitely don't want to use here due to side effects): See ast.literal_eval() for a function that can safely evaluate strings with expressions containing only literals. DC -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Mon Jun 18 13:03:57 2012 From: d at davea.name (Dave Angel) Date: Mon, 18 Jun 2012 13:03:57 -0400 Subject: Py3.3 unicode literal and input() In-Reply-To: <4FDF5D72.5020002@gmail.com> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> <4FDF5D72.5020002@gmail.com> Message-ID: <4FDF5F7D.5090406@davea.name> On 06/18/2012 12:55 PM, Andrew Berg wrote: > On 6/18/2012 11:32 AM, Jussi Piitulainen wrote: >> jmfauth writes: >> >>> Thinks are very clear to me. I wrote enough interactive >>> interpreters with all available toolkits for Windows >>>>> r = input() >> u'a >> Traceback (most recent call last): >> File "", line 1, in >> SyntaxError: u'a >> >> Er, no, not really :-) >> > You're using 2.x; this thread concerns 3.3, which, as has been repeated > several times, does not evaluate strings passed via input() like 2.x. > That code does not raise a SyntaxError in 3.x. > And you're missing the context. jmfauth thinks we should re-introduce the input/raw-input distinction so he could parse literal strings. So Jussi demonstrated that the 2.x input did NOT satisfy fmfauth's dreams. -- DaveA From bahamutzero8825 at gmail.com Mon Jun 18 13:13:39 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 18 Jun 2012 12:13:39 -0500 Subject: Py3.3 unicode literal and input() In-Reply-To: <4FDF5F7D.5090406@davea.name> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> <4FDF5D72.5020002@gmail.com> <4FDF5F7D.5090406@davea.name> Message-ID: <4FDF61C3.3050601@gmail.com> On 6/18/2012 12:03 PM, Dave Angel wrote: > And you're missing the context. jmfauth thinks we should re-introduce > the input/raw-input distinction so he could parse literal strings. So > Jussi demonstrated that the 2.x input did NOT satisfy fmfauth's dreams. You're right. I missed that part of jmfauth's post. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From ethan at stoneleaf.us Mon Jun 18 13:24:58 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 18 Jun 2012 10:24:58 -0700 Subject: Academic citation of Python In-Reply-To: <87k3z5v5d4.fsf@benfinney.id.au> References: <4fdbfc54$0$11123$c3e8da3@news.astraweb.com> <87k3z5v5d4.fsf@benfinney.id.au> Message-ID: <4FDF646A.3060805@stoneleaf.us> Ben Finney wrote: > Curt writes: > >> On 2012-06-16, Christian Heimes wrote: >>> Actually it's "van Rossum, Guido", not "Rossum, Guido van". The >>> "van" is part of the family name, not a middle name. It's like "da >>> Vinci, Leonardo" or "von Sydow, Max". On one occasion Guido >>> complained that Americans always get his name wrong. >> I've read that now he prefers Guido V. Rossum, Jr. > > Citation needed. But what format should it take? ;) ~Ethan~ From jpiitula at ling.helsinki.fi Mon Jun 18 13:36:57 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 18 Jun 2012 20:36:57 +0300 Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> Message-ID: Andrew Berg writes: > On 6/18/2012 11:32 AM, Jussi Piitulainen wrote: > > jmfauth writes: > > > >> Thinks are very clear to me. I wrote enough interactive > >> interpreters with all available toolkits for Windows > > > >>>> r = input() > > u'a > > Traceback (most recent call last): > > File "", line 1, in > > SyntaxError: u'a > > > > Er, no, not really :-) > > > You're using 2.x; this thread concerns 3.3, which, as has been > repeated several times, does not evaluate strings passed via input() > like 2.x. That code does not raise a SyntaxError in 3.x. I used 3.1.2, and I really meant the "not really". And the ":-)". I edited out the command that raised the exception. This thread is weird. If I didn't know that things are very clear to jmfauth, I would think that the behaviour of input() that I observe has absolutely nothing to do with the u'' syntax in source code. From dieter at handshake.de Mon Jun 18 14:02:11 2012 From: dieter at handshake.de (Dieter Maurer) Date: Mon, 18 Jun 2012 20:02:11 +0200 Subject: Problem with ImapLib and subject in French References: Message-ID: <87pq8wcxcs.fsf@handshake.de> Valentin Mercier writes: > I'm trying to search some mails with SUBJECT criteria, but the problem is the > encoding, I'm trying to search french terms (impalib and python V2.7) > > I've tried few things, but I think the encoding is the problem, in my mail > header I have something like this: > > ?=?iso-8859-1?Q?Job:_"Full_Backup_Les_Gr=E8ves_du_Lac")_?= I would expect that it is the task of the IMap server to handle the header encoding on its side. Check the description of its search function how it expects its input: does it want it "header encoded" or in some other form. -- Dieter From duncan.booth at invalid.invalid Mon Jun 18 14:19:31 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 18 Jun 2012 18:19:31 GMT Subject: Hashable object with self references OR how to create a tuple that refers to itself References: <4FDB50D2.2080706@comcast.net> Message-ID: Dieter Maurer wrote: > You can create a tuple in "C" and then put a reference to itself into > it, but I am quite convinced that you cannot do it in Python itself. > (Of course, you could use "cython" to generate C code with a source > language very similar to Python). I don't think you can even do it in C without breaking the specified API: PyTuple_SetItem fails if the reference count of the tuple is not 1, but it also steals the reference of the object that is being added to the tuple so if you don't increment the reference count before attempting to add the tuple to itself you've broken the rules for reference counting. -- Duncan Booth http://kupuguy.blogspot.com From anthra.norell at bluewin.ch Mon Jun 18 14:21:02 2012 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Mon, 18 Jun 2012 20:21:02 +0200 Subject: Tkinter binding question Message-ID: <1340043662.4089.334.camel@hatchbox-one> Hi All, For most of an afternoon I've had that stuck-in-a-dead-end feeling probing to no avail all permutations formulating bindings, trying to make sense of manuals and tutorials. Here are my bindings: label_frame.bind ('', self.color_selected) label_frame.bind ('', self.color_selectable) label_frame.bind ('', self.pick_record) label_frame.bind ('', self.info_profile) and work fine. But when I try to select an entered item, the moment I push the left or the right button, color_selectable () and color_selected () are called again in rapid succession. The same effect happens even when I push the middle mouse button which is rather weird, because it has no binding. The behavior suggests that no event can occur on an entered widget before it is left again and if an event other that comes in, the callback gets called automatically. That can't be right, though. It isn't possible to click an item without entering it. I put traces in all of the four callbacks. So I know what gets called an what doesn't. Traces are: On : hit list.color_selected () On : hit list.color_selectable () Fine so far. : hit list.color_selected () # Still fine or or : hit list.color_selectable () # Not so fine! hit list.color_selected () (or -2 or -3) (nothing) Thanks for any suggestion Frederic OS: Ubuntu 10.04 LTS Python: sys.version: 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] Tkinter: VERSION 73770 (help (Tkinter), last line) From jeremiah.dodds at gmail.com Mon Jun 18 14:38:16 2012 From: jeremiah.dodds at gmail.com (Jeremiah Dodds) Date: Mon, 18 Jun 2012 14:38:16 -0400 Subject: Conditional decoration In-Reply-To: (Roy Smith's message of "18 Jun 2012 18:16:51 -0400") References: Message-ID: <874nq8h3dz.fsf@destructor.i-did-not-set--mail-host-address--so-tickle-me> roy at panix.com (Roy Smith) writes: > Is there any way to conditionally apply a decorator to a function? > For example, in django, I want to be able to control, via a run-time > config flag, if a view gets decorated with @login_required(). > > @login_required() > def my_view(request): > pass You could write a decorator that takes the value of the flag and either does nothing or decorates it's target function. From tjreedy at udel.edu Mon Jun 18 14:45:48 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Jun 2012 14:45:48 -0400 Subject: Py3.3 unicode literal and input() In-Reply-To: <44a6bacd-d4d7-4c1f-ae1a-8f9ce4a1abc9@d6g2000vbe.googlegroups.com> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> <44a6bacd-d4d7-4c1f-ae1a-8f9ce4a1abc9@d6g2000vbe.googlegroups.com> Message-ID: On 6/18/2012 12:39 PM, jmfauth wrote: > We are turning in circles. You are, not we. Please stop. > You are somehow legitimating the reintroduction of unicode > literals We are not 'reintroducing' unicode literals. In Python 3, string literals *are* unicode literals. Other developers reintroduced a now meaningless 'u' prefix for the purpose of helping people write 2&3 code that runs on both Python 2 and Python 3. Read about it here http://python.org/dev/peps/pep-0414/ In Python 3.3, 'u' should *only* be used for that purpose and should be ignored by anyone not writing or editing 2&3 code. If you are not writing such code, ignore it. > and I shew, not to say proofed, it may > be a source of problems. You are the one making it be a problem. > Typical Python desease. Introduce a problem, > then discuss how to solve it, but surely and > definitivly do not remove that problem. The simultaneous reintroduction of 'ur', but with a different meaning than in 2.7, *was* a problem and it should be removed in the next release. > As far as I know, Python 3.2 is working very > well. Except that many public libraries that we would like to see ported to Python 3 have not been. The purpose of reintroducing 'u' is to encourage more porting of Python 2 code. Period. -- Terry Jan Reedy From tjreedy at udel.edu Mon Jun 18 14:56:13 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Jun 2012 14:56:13 -0400 Subject: module name vs '.' In-Reply-To: <4FDF332D.3000205@davea.name> References: <4FDF30D1.7020301@davea.name> <4FDF332D.3000205@davea.name> Message-ID: On 6/18/2012 9:54 AM, Dave Angel wrote: > On 06/18/2012 09:47 AM, Neal Becker wrote: >> I meant a module You are correct that using periods in a module name conflicts with periods in import statement syntax. > from src.directory import neal > > that has nothing to do with periods being in a directory name. That > period in the source code separates a package name from a module name, > and will not find a package named "src.directory" So one would have to *not* use import statement syntax, but use lower level facilities, such as importlib or (untested) neal = __import__('src.directory', ) Conclusion: putting periods in the name of module files (including directories) except for .py- extensions, is generally a bad idea. -- Terry Jan Reedy From bahamutzero8825 at gmail.com Mon Jun 18 15:24:03 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 18 Jun 2012 14:24:03 -0500 Subject: Checking compatibility of a script across Python versions automatically Message-ID: <4FDF8053.7020505@gmail.com> Are there any tools out there that will parse a script and tell me if it is compatible with an arbitrary version of Python and highlight any incompatibilities? I need to check a few of my scripts that target 3.2 to see if I can make them compatible with 3.0 and 3.1 if they aren't already. I found pyqver, but it isn't accurate (at least for 3.2/3.3 scripts) and hasn't been updated in 2 years. I could look over the docs and do it manually, but one of the scripts isn't small, so I'd prefer not to. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From wxjmfauth at gmail.com Mon Jun 18 16:22:41 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 18 Jun 2012 13:22:41 -0700 (PDT) Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> <44a6bacd-d4d7-4c1f-ae1a-8f9ce4a1abc9@d6g2000vbe.googlegroups.com> Message-ID: <44c6eac8-0a80-476f-b94f-189412fc3a76@s9g2000vbg.googlegroups.com> On Jun 18, 8:45?pm, Terry Reedy wrote: > On 6/18/2012 12:39 PM, jmfauth wrote: > > > We are turning in circles. > > You are, not we. Please stop. > > > You are somehow legitimating the reintroduction of unicode > > literals > > We are not 'reintroducing' unicode literals. In Python 3, string > literals *are* unicode literals. > > Other developers reintroduced a now meaningless 'u' prefix for the > purpose of helping people write 2&3 code that runs on both Python 2 and > Python 3. Read about it herehttp://python.org/dev/peps/pep-0414/ > > In Python 3.3, 'u' should *only* be used for that purpose and should be > ignored by anyone not writing or editing 2&3 code. If you are not > writing such code, ignore it. > > ?> and I shew, not to say proofed, it may > > > be a source of problems. > > You are the one making it be a problem. > > > Typical Python desease. Introduce a problem, > > then discuss how to solve it, but surely and > > definitivly do not remove that problem. > > The simultaneous reintroduction of 'ur', but with a different meaning > than in 2.7, *was* a problem and it should be removed in the next release. > > > As far as I know, Python 3.2 is working very > > well. > > Except that many public libraries that we would like to see ported to > Python 3 have not been. The purpose of reintroducing 'u' is to encourage > more porting of Python 2 code. Period. > > -- > Terry Jan Reedy It's a matter of perspective. I expected to have finally a clean Python, the goal is missed. I have nothing to object. It is "your" (core devs) project, not mine. At least, you understood my point of view. I'm a more than two decades TeX user. At the release of XeTeX (a pure unicode TeX-engine), the devs had, like Python2/3, to make anything incompatible. A success. It did not happen a week without seeing a updated package or a refreshed documentation. Luckily for me, Xe(La)TeX is more important than Python. As a scientist, Python is perfect. >From an educational point of view, I'm becoming more and more skeptical about this language, a moving target. Note that I'm not complaining, only "desappointed". jmf From nadeem.vawda at gmail.com Mon Jun 18 17:07:46 2012 From: nadeem.vawda at gmail.com (Nadeem Vawda) Date: Mon, 18 Jun 2012 23:07:46 +0200 Subject: python 3.3 bz2 decompression testing results In-Reply-To: References: Message-ID: Hi Pauli, Thank you for your interest in improving the bz2 module. However, I'm not sure of what you are saying in your email. If you believe you have found a bug in the module, then please provide clear instructions on how to reproduce the error(s), preferably using just one data file that triggers the problem. About Valgrind and Linux, I would be happy to fix up any memory leaks you find. However, bear in mind that running CPython under Valgrind produces quite a number of warnings even without doing anything with the bz2 module, so interpreting its output will be take a substantial amount of effort. Regards, Nadeem From roy at panix.com Mon Jun 18 18:16:51 2012 From: roy at panix.com (Roy Smith) Date: 18 Jun 2012 18:16:51 -0400 Subject: Conditional decoration Message-ID: Is there any way to conditionally apply a decorator to a function? For example, in django, I want to be able to control, via a run-time config flag, if a view gets decorated with @login_required(). @login_required() def my_view(request): pass From python at mrabarnett.plus.com Mon Jun 18 18:43:47 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 18 Jun 2012 23:43:47 +0100 Subject: Conditional decoration In-Reply-To: References: Message-ID: <4FDFAF23.309@mrabarnett.plus.com> On 18/06/2012 23:16, Roy Smith wrote: > Is there any way to conditionally apply a decorator to a function? > For example, in django, I want to be able to control, via a run-time > config flag, if a view gets decorated with @login_required(). > > @login_required() > def my_view(request): > pass > A decorator is just syntactic sugar for function application after the definition. This: @deco def func(): pass is just another way of writing: def func(): pass func = deco(func) Not as neat, but you can make it conditional. From emile at fenx.com Mon Jun 18 18:49:24 2012 From: emile at fenx.com (Emile van Sebille) Date: Mon, 18 Jun 2012 15:49:24 -0700 Subject: Conditional decoration In-Reply-To: References: Message-ID: On 6/18/2012 3:16 PM Roy Smith said... > Is there any way to conditionally apply a decorator to a function? > For example, in django, I want to be able to control, via a run-time > config flag, if a view gets decorated with @login_required(). > > @login_required() > def my_view(request): > pass class myDecorator(object): def __init__(self, f): self.f = f def __call__(self): print "Entering", self.f.__name__ self.f() print "Exited", self.f.__name__ def null(a): return a #if condition: myDecorator = null @myDecorator def aFunction(): print "aFunction running" aFunction() Cobbled together from http://www.chrisevans3d.com/pub_blog/?p=530 and http://stackoverflow.com/questions/3687046/python-sphinx-autodoc-and-decorated-members HTH Emile From jason at powerpull.net Mon Jun 18 19:13:40 2012 From: jason at powerpull.net (Jason Friedman) Date: Mon, 18 Jun 2012 17:13:40 -0600 Subject: Read STDIN as bytes rather than a string Message-ID: I tried this: Python 3.2.2 (default, Feb 24 2012, 20:07:04) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> import io >>> fh = io.open(sys.stdin) Traceback (most recent call last): File "", line 1, in TypeError: invalid file: <_io.TextIOWrapper name='' mode='r' encoding='UTF-8'> >>> fh = io.open(sys.stdin, "rb") Traceback (most recent call last): File "", line 1, in TypeError: invalid file: <_io.TextIOWrapper name='' mode='r' encoding='UTF-8'> From gelonida at gmail.com Mon Jun 18 19:16:58 2012 From: gelonida at gmail.com (Gelonida N) Date: Tue, 19 Jun 2012 01:16:58 +0200 Subject: lazy evaluation of a variable In-Reply-To: References: Message-ID: On 06/17/2012 11:35 PM, Gelonida N wrote: > Hi, > > I'm not sure whether what I ask for is impossible, but would know how > others handle such situations. > > > > I'm having a module, which should lazily evaluate one of it's variables. > Meaning that it is evaluated only if anybody tries to use this variable. > > At the moment I don't know how to do this and do therefore following: > > > ####### mymodule.py ####### > var = None > > def get_var(): > global var > if var is not None: > return var > var = something_time_consuming() > > > > Now the importing code would look like > > import mymodule > def f(): > var = mymodule.get_var() > > The disadvantage is, that I had to change existing code directly > accessing the variable. > > > I wondered if there were any way to change mymodule.py such, that the > importing code could just access a variable and the lazy evaluation > would happen transparently. > > import mymodule > def f(): > var = mymodule.var > Thanks everybody for your responses. This gave me quite some ideas. It seems, that none of the solutions would allow to have the changes only in the module. More out of curiosity than out of real necessity I wanted to know, whether it would be possible to hide the lazy evaluation from already existing code, that has already the import statement written. So the question basically boiled down to "can one make 'properties' for modules?" It seems no. Probably there aren't many real use cases except for monkey patching libraries or for logging accesses to a module's variable From benjamin.kaplan at case.edu Mon Jun 18 19:18:55 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 18 Jun 2012 16:18:55 -0700 Subject: Read STDIN as bytes rather than a string In-Reply-To: References: Message-ID: On Mon, Jun 18, 2012 at 4:13 PM, Jason Friedman wrote: > I tried this: > > Python 3.2.2 (default, Feb 24 2012, 20:07:04) > [GCC 4.6.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> import io >>>> fh = io.open(sys.stdin) > Traceback (most recent call last): > ?File "", line 1, in > TypeError: invalid file: <_io.TextIOWrapper name='' mode='r' > encoding='UTF-8'> >>>> fh = io.open(sys.stdin, "rb") > Traceback (most recent call last): > ?File "", line 1, in > TypeError: invalid file: <_io.TextIOWrapper name='' mode='r' > encoding='UTF-8'> > -- You want to read from sys.stdin.buffer From lists at cheimes.de Mon Jun 18 19:35:31 2012 From: lists at cheimes.de (Christian Heimes) Date: Tue, 19 Jun 2012 01:35:31 +0200 Subject: Read STDIN as bytes rather than a string In-Reply-To: References: Message-ID: Am 19.06.2012 01:13, schrieb Jason Friedman: > I tried this: sys.stdin wraps a buffered reader which itself wraps a raw file reader. >>> sys.stdin <_io.TextIOWrapper name='' mode='r' encoding='UTF-8'> >>> sys.stdin.buffer <_io.BufferedReader name=''> >>> sys.stdin.buffer.raw <_io.FileIO name='' mode='rb'> You should read from sys.stdin.buffer unless you really need the bare metal. Christian From jason at powerpull.net Mon Jun 18 19:49:37 2012 From: jason at powerpull.net (Jason Friedman) Date: Mon, 18 Jun 2012 17:49:37 -0600 Subject: Read STDIN as bytes rather than a string In-Reply-To: References: Message-ID: > sys.stdin wraps a buffered reader which itself wraps a raw file reader. > >>>> sys.stdin > <_io.TextIOWrapper name='' mode='r' encoding='UTF-8'> >>>> sys.stdin.buffer > <_io.BufferedReader name=''> >>>> sys.stdin.buffer.raw > <_io.FileIO name='' mode='rb'> > > You should read from sys.stdin.buffer unless you really need the bare > metal. > Thank you, and just to close the loop: $ cat ~/my-input.py #!/opt/python/bin/python3 import sys print(sys.stdin.buffer.read()) $ echo hello | ~/my-input.py b'hello\n' From jeanpierreda at gmail.com Mon Jun 18 19:51:12 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 18 Jun 2012 19:51:12 -0400 Subject: Conditional decoration In-Reply-To: References: Message-ID: On Mon, Jun 18, 2012 at 6:49 PM, Emile van Sebille wrote: > On 6/18/2012 3:16 PM Roy Smith said... > class myDecorator(object): > ? ?def __init__(self, f): > ? ? ? ?self.f = f > ? ?def __call__(self): > ? ? ? ?print "Entering", self.f.__name__ > ? ? ? ?self.f() > ? ? ? ?print "Exited", self.f.__name__ I dunno about other people, but I generally avoid class decorators because they do not behave the way functions do when applied as a decorator for a method. This is a decorator taken out of some of my own source code. I was mostly dicking around with things, as opposed to actually coding. The docstring was even more ridiculous. from functools import reduce def rapply(*args): """apply(f, ...) <-> rapply(..., f)""" return args[-1](*args[:-1]) def condecorator(condition, *decorators): if condition: return lambda f: reduce(rapply, reversed(decorators), f) else: return lambda f: f Example usage: @condecorator(condition, decorator1, decorator2) def decorated(...): ... equivalent to: def decorated(...): ... if condition: decorated = decorator1(decorator2(decorated)) -- Devin From jason at powerpull.net Mon Jun 18 19:53:29 2012 From: jason at powerpull.net (Jason Friedman) Date: Mon, 18 Jun 2012 17:53:29 -0600 Subject: Read STDIN as bytes rather than a string In-Reply-To: References: Message-ID: Which leads me to another question ... how can I debug these things? $ echo 'hello' | python3 -m pdb ~/my-input.py > /home/jason/my-input.py(2)() -> import sys (Pdb) *** NameError: name 'hello' is not defined From rtw at rtw.me.uk Mon Jun 18 20:23:55 2012 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 19 Jun 2012 00:23:55 +0000 (UTC) Subject: Conditional decoration References: Message-ID: Roy Smith wrote in news:jro9cj$b44$1 at panix2.panix.com in gmane.comp.python.general: > Is there any way to conditionally apply a decorator to a function? > For example, in django, I want to be able to control, via a run-time > config flag, if a view gets decorated with @login_required(). > > @login_required() > def my_view(request): > pass You need to create a decorator that calls either the original function or the decorated funtion, depending on your condition, Something like (untested): def conditional_login_required( f ): _login_required = login_required()(f) def decorated( request ): if condition == "use-login": return _login_required( request ) else: return f( request ) return decorated @conditional_login_required def my_view(request): pass Replace (condition == "use-login") with whatever your "run-time control flag" is. -- Rob. From tjreedy at udel.edu Mon Jun 18 21:44:38 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Jun 2012 21:44:38 -0400 Subject: Checking compatibility of a script across Python versions automatically In-Reply-To: <4FDF8053.7020505@gmail.com> References: <4FDF8053.7020505@gmail.com> Message-ID: On 6/18/2012 3:24 PM, Andrew Berg wrote: > Are there any tools out there that will parse a script and tell me if it > is compatible with an arbitrary version of Python and highlight any Not that I know of. > incompatibilities? I need to check a few of my scripts that target 3.2 > to see if I can make them compatible with 3.0 and 3.1 if they aren't > already. Forget about 3.0. Really. As for 3.1 versus 3.2, there were no core syntax changes in 3.2. There were a few, but only a few, enhancements in builtin classes. If you have a decent test suite, just run it under 3.1. -- Terry Jan Reedy From chrisjrn at gmail.com Mon Jun 18 21:54:04 2012 From: chrisjrn at gmail.com (Chris Neugebauer) Date: Tue, 19 Jun 2012 11:54:04 +1000 Subject: Closes this week: PyCon Australia 2012 and Google Australia announce gender diversity grants Message-ID: Hello there! Just a friendly reminder to all of you that applications for our Gender Diversity Grants close on Friday this week. Google Australia are funding several AU$500 grants for deserving women living outside of the Souther Tasmania Region to attend PyCon Australia 2012, which us happening in August in Hobart. Please pass this onto anyone you know who may be interested in applying for one of these grants. Further information can be found at http://2012.pycon-au.org/diversity_grants including the application form. Original message follows. --Chris *** PyCon Australia and Google Australia are pleased to announce that they're joining forces to offer gender diversity delegate grants to women who wish to attend PyCon Australia in 2012. These grants will cover up to $AUD500 of travel, accommodation and registration costs for women living outside of the Southern Tasmania region to attend this year's conference. These grants aim to reduce the financial barriers to attending PyCon Australia 2012, by subsidising the registration and travel costs of people from diverse groups, who contribute in important ways to the Python community. More information can be found at http://2012.pycon-au.org/diversity_grants ==== Eligibility ==== In order to be eligible for one of the grants, you must be: - A woman, aged 18 or older - A professional, enthusiast or student interested in, or currently working in Python-related fields or projects - Planning to attend both days of PyCon Australia 2012 - In order to be eligible for the travel and accommodation grant, you must additionally: live further than 150 km (by road) from the conference venue. (If you are unsure, please visit http://maps.google.com.au/maps/place?q=Wrest%20Point,%20Tasmania and use the "Get Directions" link in the upper left-hand corner to calculate the driving distance from your place of residence to the venue.) More information can be found at http://2012.pycon-au.org/diversity_grants ?==== Award Amount ?==== All selected grant recipients will be extended the Early Bird registration rates to PyCon Australia, provided registration is completed prior to 13 July. In addition, recipients of the travel and accommodation grant will be reimbursed up to $500 in travel and accommodation costs. More information can be found at http://2012.pycon-au.org/diversity_grants ?==== Timeline ?==== Applications for the gender diversity delegates grants are open now, and will close on Friday 22 June We will notify all successful recipients of their award by Friday 29 June so that you can have ample time to complete your travel plans. More information can be found at http://2012.pycon-au.org/diversity_grants === About PyCon Australia === PyCon Australia is the national conference for the Python Programming Community. The third PyCon Australia will be held on August 18 and 19, 2012 in Hobart, Tasmania, bringing together professional, student and enthusiast developers with a love for developing with Python. PyCon Australia informs the country?s Python developers with presentations, tutorials and panel sessions by experts and core developers of Python, as well as the libraries and frameworks that they rely on. To find out more about PyCon Australia 2012, visit our website at http://pycon-au.org or e-mail us at contact at pycon-au.org. PyCon Australia is presented by Linux Australia (www.linux.org.au) and acknowledges the support of our Gold sponsors: Google Australia (www.google.com.au), and the Australian Computer Society (Tasmanian Branch) (www.acs.org.au); our Event partners: Kogan, and Secret Lab; and our Silver sponsors: the Python Software Foundation, the Django Software Foundation, Anchor Systems, Red Hat, ekit, RimuHosting, 99designs and CSIRO. -- --Christopher Neugebauer Conference Coordinator and Sponsor Liaison PyCon Australia: Hobart 2012 -- http://2012.pycon-au.org -- @pyconau Conference registration and accommodation deals now available! See our website for details. Jabber: chrisjrn at gmail.com -- IRC: chrisjrn on irc.freenode.net -- WWW: http://chris.neugebauer.id.au -- Twitter/Identi.ca: @chrisjrn From shearichard at gmail.com Mon Jun 18 22:52:53 2012 From: shearichard at gmail.com (shearichard at gmail.com) Date: Mon, 18 Jun 2012 19:52:53 -0700 (PDT) Subject: "constant sharing" works differently in REPL than in script ? Message-ID: Listening to 'Radio Free Python' episode 8 (http://radiofreepython.com/episodes/8/ - around about the 30 minute mark) I heard that Python pre creates some integer constants to avoid a proliferation of objects with the same value. I was interested in this and so I decided to try it out. First I did this at the prompt : >>> c = 1 >>> print id(1) 26906152 >>> print id(c) 26906152 >>> c is 1 True So that matched what I'd heard and then I did this to test the limits of it : >>> c = 259 >>> print id(259) 26167488 >>> print id(c) 26167512 >>> c is 259 False And that was reasonable too as the podcast mentioned it was only done for a small set of integers around zero. However when I wrote this script : c = 259 print id(259) print id(c) if c is 259: print "%s - yes" % (c) else: print "%s - no " % (c) I got this output : C:\data\src\Python\foo>python untitled-2.py 26760884 26760884 259 - yes So what's going on here. The script seems to be sharing objects in a way the REPL isn't ? Can anyone explain please ? BTW this is all on : Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 . From rantingrickjohnson at gmail.com Mon Jun 18 23:51:08 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Mon, 18 Jun 2012 20:51:08 -0700 (PDT) Subject: Tkinter binding question In-Reply-To: References: Message-ID: <7f22c54e-2cd1-4a7f-a9f6-a33b8f17eb23@googlegroups.com> On Monday, June 18, 2012 1:21:02 PM UTC-5, Frederic Rentsch wrote: > Hi All, > > For most of an afternoon I've had that stuck-in-a-dead-end feeling > probing to no avail all permutations formulating bindings, trying to > make sense of manuals and tutorials. Here are my bindings: > > label_frame.bind ('', self.color_selected) > label_frame.bind ('', self.color_selectable) > label_frame.bind ('', self.pick_record) > label_frame.bind ('', self.info_profile) This example is useless to me. As a matter of fact, your whole explanation of the problem is ambitious at best. But you do realize that by binding both the click and release of a mouse button to the same callback you will call the callback twice? Try to create a simplistic and generic example of the problem. Most times you'll find the flaw. Most code should start as template that prints messages to stdout. Large applications are built by taking babysteps. Not by jumping out the fire and into the frying pan! WARNING: Debugging large chucks of spaghetti code is bad for your brain! Tip of the day: DIVIDE AND CONQUER! ## START CODE ## from __future__ import print_function import Tkinter as tk root = tk.Tk() root.geometry('200x200+20+20') root.bind("", lambda e:print("Enter")) root.bind("", lambda e:print("Leave")) root.bind("", lambda e:print("ButtonOneRelease")) root.bind("", lambda e:print("ButtonThreeRelease")) root.mainloop() ## END CODE ## Q1: Now, what exactly is the problem? Hmm??? Q2: Can you modify this code to correct the problem? Hmm??? Q3: Why are there so many inconsistencies in the Tkinter API? Hmm??? Tip: NEVER bind "ButtonClick" to trigger a callback (ESPECIALLY FOR A BUTTON CALLBACK!!!). ONLY bind "ButtonRelease". Why? Well because if the user accidentally clicks the button, he can move his pointer beyond the boundaries of the button and then release the mouse "button" WITHOUT triggering the callback. All good GUI coders follow this design pattern. (Except in certain cases where you want a mouse click to trigger an action quickly; like a Listbox item or menu, or whatever.) if GUI.ergonomics < optimal: raise NeophyteError("Do not pass GUI. Do not collect 100 dollars!") > and work fine. But when I try to select an entered item, > the moment I push the left or the right button, color_selectable () > and color_selected () are called again in rapid succession. That does not make sense. Are you calling the method "w.update()" anywhere in the callback; or as a consequence of the callback? > The same > effect happens even when I push the middle mouse button which is > rather weird, because it has no binding. Not necessarily. Many of the Tk widgets come prepackaged with annoying little default bindings that would the test the patience of a saint. Like, for example, the Tkinter.Text widget. It has a nasty little default binding to paste the cut buffer contents when you press MouseButtonTwo. And since it also has a default binding of using MouseButtonTwo+MouseMotion to scroll vertically, you find yourself inserting cut buffers everywhere! > The behavior suggests that > no event can occur on an entered widget before it is left again and > if an event other that comes in, the callback gets > called automatically. That can't be right, though. It isn't possible > to click an item without entering it. Interesting observation. I would say your code is too complicated to properly debug. You need to divide and conquer this spaghetti mess. From rantingrickjohnson at gmail.com Mon Jun 18 23:51:08 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Mon, 18 Jun 2012 20:51:08 -0700 (PDT) Subject: Tkinter binding question In-Reply-To: References: Message-ID: <7f22c54e-2cd1-4a7f-a9f6-a33b8f17eb23@googlegroups.com> On Monday, June 18, 2012 1:21:02 PM UTC-5, Frederic Rentsch wrote: > Hi All, > > For most of an afternoon I've had that stuck-in-a-dead-end feeling > probing to no avail all permutations formulating bindings, trying to > make sense of manuals and tutorials. Here are my bindings: > > label_frame.bind ('', self.color_selected) > label_frame.bind ('', self.color_selectable) > label_frame.bind ('', self.pick_record) > label_frame.bind ('', self.info_profile) This example is useless to me. As a matter of fact, your whole explanation of the problem is ambitious at best. But you do realize that by binding both the click and release of a mouse button to the same callback you will call the callback twice? Try to create a simplistic and generic example of the problem. Most times you'll find the flaw. Most code should start as template that prints messages to stdout. Large applications are built by taking babysteps. Not by jumping out the fire and into the frying pan! WARNING: Debugging large chucks of spaghetti code is bad for your brain! Tip of the day: DIVIDE AND CONQUER! ## START CODE ## from __future__ import print_function import Tkinter as tk root = tk.Tk() root.geometry('200x200+20+20') root.bind("", lambda e:print("Enter")) root.bind("", lambda e:print("Leave")) root.bind("", lambda e:print("ButtonOneRelease")) root.bind("", lambda e:print("ButtonThreeRelease")) root.mainloop() ## END CODE ## Q1: Now, what exactly is the problem? Hmm??? Q2: Can you modify this code to correct the problem? Hmm??? Q3: Why are there so many inconsistencies in the Tkinter API? Hmm??? Tip: NEVER bind "ButtonClick" to trigger a callback (ESPECIALLY FOR A BUTTON CALLBACK!!!). ONLY bind "ButtonRelease". Why? Well because if the user accidentally clicks the button, he can move his pointer beyond the boundaries of the button and then release the mouse "button" WITHOUT triggering the callback. All good GUI coders follow this design pattern. (Except in certain cases where you want a mouse click to trigger an action quickly; like a Listbox item or menu, or whatever.) if GUI.ergonomics < optimal: raise NeophyteError("Do not pass GUI. Do not collect 100 dollars!") > and work fine. But when I try to select an entered item, > the moment I push the left or the right button, color_selectable () > and color_selected () are called again in rapid succession. That does not make sense. Are you calling the method "w.update()" anywhere in the callback; or as a consequence of the callback? > The same > effect happens even when I push the middle mouse button which is > rather weird, because it has no binding. Not necessarily. Many of the Tk widgets come prepackaged with annoying little default bindings that would the test the patience of a saint. Like, for example, the Tkinter.Text widget. It has a nasty little default binding to paste the cut buffer contents when you press MouseButtonTwo. And since it also has a default binding of using MouseButtonTwo+MouseMotion to scroll vertically, you find yourself inserting cut buffers everywhere! > The behavior suggests that > no event can occur on an entered widget before it is left again and > if an event other that comes in, the callback gets > called automatically. That can't be right, though. It isn't possible > to click an item without entering it. Interesting observation. I would say your code is too complicated to properly debug. You need to divide and conquer this spaghetti mess. From rantingrickjohnson at gmail.com Tue Jun 19 00:05:50 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Mon, 18 Jun 2012 21:05:50 -0700 (PDT) Subject: lazy evaluation of a variable In-Reply-To: <4fde61ae$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <4fde61ae$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, June 17, 2012 6:01:03 PM UTC-5, Steven D'Aprano wrote: > One day, in my Copious Spare Time, I intend to write a proper feature > request and/or PEP for such a feature. Obviously the absolute earliest > such a feature could be introduced is Python 3.4, about 18 months from > now. (Although frankly, I would imagine significant opposition from the > more conservative Python developers.) Well these conservatives must have been suffering from chronic mononucleosis because i have never heard a peep from them! I wish they would "grow a pair" and speak up a bit more often because the language would benefit greatly from some austerity measures, strong leadership, and most of all; some Gawd damned consistency! From benjamin.kaplan at case.edu Tue Jun 19 00:21:10 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 18 Jun 2012 21:21:10 -0700 Subject: "constant sharing" works differently in REPL than in script ? In-Reply-To: References: Message-ID: On Mon, Jun 18, 2012 at 7:52 PM, wrote: > Listening to 'Radio Free Python' episode 8 (http://radiofreepython.com/episodes/8/ - around about the 30 minute mark) I heard that Python pre creates some integer constants to avoid a proliferation of objects with the same value. > > I was interested in this and so I decided to try it out. > > First I did this at the prompt : > >>>> c = 1 >>>> print id(1) > 26906152 >>>> print id(c) > 26906152 >>>> c is 1 > True > > So that matched what I'd heard and then I did this to test the limits of it : > >>>> c = 259 >>>> print id(259) > 26167488 >>>> print id(c) > 26167512 >>>> c is 259 > False > > And that was reasonable too as the podcast mentioned it was only done for a small set of integers around zero. > > However when I wrote this script : > > c = 259 > print id(259) > print id(c) > if c is 259: > ? ?print "%s - yes" % (c) > else: > ? ?print "%s - no " % (c) > > I got this output : > > C:\data\src\Python\foo>python untitled-2.py > 26760884 > 26760884 > 259 - yes > > So what's going on here. The script seems to be sharing objects in a way the REPL isn't ? > > Can anyone explain please ? > > BTW this is all on : Python 2.6.1 (r261:67517, Dec ?4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 . > Python the language doesn't specify anything about this sort of behavior. CPython the implementation does all sorts of optimizations to make code run more efficiently. Caching integers is one of those optimizations. In the case where the code is compiled all at once (as in the script) instead of one line at a time (the REPL), it can do more optimizations. But as I said, none of this is in the specification so you shouldn't rely on it. The general rule for the "is" operator is that unless you specifically know that you need it, don't use it. From ranjithtenz at gmail.com Tue Jun 19 01:22:37 2012 From: ranjithtenz at gmail.com (Ranjith Kumar) Date: Tue, 19 Jun 2012 10:52:37 +0530 Subject: Pymongo Error Message-ID: Hi all, I tried Django with Mongodb while running manage.py syncdb I endup with this error note : it works fine with sqlite and mysql db (django-1.3)ranjith at ranjith:~/ sandbox/python-box/hukkster-core-site/hukk$ ./manage.py syncdb /home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/pymongo/connection.py:385: UserWarning: must provide a username and password to authenticate to hukkster_testing "to authenticate to %s" % (db,)) Creating tables ... Traceback (most recent call last): File "./manage.py", line 14, in execute_manager(settings) File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager utility.execute() File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv self.execute(*args, **options.__dict__) File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute output = self.handle(*args, **options) File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle return self.handle_noargs(**options) File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 109, in handle_noargs emit_post_sync_signal(created_models, verbosity, interactive, db) File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/sql.py", line 190, in emit_post_sync_signal interactive=interactive, db=db) File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send response = receiver(signal=self, sender=sender, **named) File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 41, in create_permissions "content_type", "codename" File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", line 107, in _result_iter self._fill_cache() File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", line 772, in _fill_cache self._result_cache.append(self._iter.next()) File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", line 959, in iterator for row in self.query.get_compiler(self.db).results_iter(): File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", line 229, in results_iter for entity in self.build_query(fields).fetch(low_mark, high_mark): File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", line 290, in build_query query.order_by(self._get_ordering()) File "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", line 339, in _get_ordering raise DatabaseError("Ordering can't span tables on non-relational backends (%s)" % order) django.db.utils.DatabaseError: Ordering can't span tables on non-relational backends (content_type__app_label) DB settings in settings.py DATABASES = { 'default': { 'ENGINE': 'django_mongodb_engine', 'NAME': 'helloworld', 'USER': '', 'PASSWORD': '12424214', 'HOST': 'mongodb://staff.mongohq.com/', 'PORT': 'XXXXX', }, } my requirement packages, Django==1.3 dictshield==0.4.4 django-mongodb-engine==0.4.0 django-social-auth==0.6.9 djangotoolbox==0.0.1 httplib2==0.7.4 mongoengine==0.6.10 mongokit==0.8 oauth2==1.5.211 pymongo==2.2 python-openid==2.2.5 simplejson==2.5.2 wsgiref==0.1.2 Please point me what i missed here... -- Cheers, Ranjith Kumar K, Chennai. http://ranjithtenz.wordpress.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ramsesh at gmail.com Tue Jun 19 01:39:40 2012 From: ramsesh at gmail.com (Ramesh Seshadri) Date: Tue, 19 Jun 2012 11:09:40 +0530 Subject: [chennaipy 1376] Pymongo Error In-Reply-To: References: Message-ID: Are you using django-nonrel or basic django version? Check out http://www.allbuttonspressed.com/projects/django-nonrel cheers Ramesh On Tue, Jun 19, 2012 at 10:52 AM, Ranjith Kumar wrote: > Hi all, > I tried Django with Mongodb while running manage.py syncdb I endup with > this error > > note : it works fine with sqlite and mysql db > > (django-1.3)ranjith at ranjith:~/ > sandbox/python-box/hukkster-core-site/hukk$ ./manage.py syncdb > /home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/pymongo/connection.py:385: > UserWarning: must provide a username and password to authenticate to > hukkster_testing > "to authenticate to %s" % (db,)) > Creating tables ... > Traceback (most recent call last): > File "./manage.py", line 14, in > execute_manager(settings) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/__init__.py", > line 438, in execute_manager > utility.execute() > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/__init__.py", > line 379, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 191, in run_from_argv > self.execute(*args, **options.__dict__) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 220, in execute > output = self.handle(*args, **options) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 351, in handle > return self.handle_noargs(**options) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", > line 109, in handle_noargs > emit_post_sync_signal(created_models, verbosity, interactive, db) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/sql.py", > line 190, in emit_post_sync_signal > interactive=interactive, db=db) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", > line 172, in send > response = receiver(signal=self, sender=sender, **named) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", > line 41, in create_permissions > "content_type", "codename" > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 107, in _result_iter > self._fill_cache() > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 772, in _fill_cache > self._result_cache.append(self._iter.next()) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 959, in iterator > for row in self.query.get_compiler(self.db).results_iter(): > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 229, in results_iter > for entity in self.build_query(fields).fetch(low_mark, high_mark): > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 290, in build_query > query.order_by(self._get_ordering()) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 339, in _get_ordering > raise DatabaseError("Ordering can't span tables on non-relational > backends (%s)" % order) > django.db.utils.DatabaseError: Ordering can't span tables on > non-relational backends (content_type__app_label) > > > DB settings in settings.py > > DATABASES = { > 'default': { > 'ENGINE': 'django_mongodb_engine', > 'NAME': 'helloworld', > 'USER': '', > 'PASSWORD': '12424214', > 'HOST': 'mongodb://staff.mongohq.com/', > 'PORT': 'XXXXX', > }, > } > > my requirement packages, > Django==1.3 > dictshield==0.4.4 > django-mongodb-engine==0.4.0 > django-social-auth==0.6.9 > djangotoolbox==0.0.1 > httplib2==0.7.4 > mongoengine==0.6.10 > mongokit==0.8 > oauth2==1.5.211 > pymongo==2.2 > python-openid==2.2.5 > simplejson==2.5.2 > wsgiref==0.1.2 > > Please point me what i missed here... > > -- > Cheers, > Ranjith Kumar K, > Chennai. > > http://ranjithtenz.wordpress.com > > > > -- > You received this message because you are subscribed to the Google Groups > "Chennaipy" group. > Wiki at http://nrcfosshelpline.in/chennaipy/ > To post to this group, send email to chennaipy at googlegroups.com > To unsubscribe from this group, send email to > chennaipy-unsubscribe at googlegroups.com > For more options, visit this group at > http://groups.google.com/group/chennaipy?hl=en -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Tue Jun 19 02:00:03 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 19 Jun 2012 08:00:03 +0200 Subject: Checking compatibility of a script across Python versions automatically In-Reply-To: <4FDF8053.7020505@gmail.com> References: <4FDF8053.7020505@gmail.com> Message-ID: Andrew Berg, 18.06.2012 21:24: > Are there any tools out there that will parse a script and tell me if it > is compatible with an arbitrary version of Python and highlight any > incompatibilities? I need to check a few of my scripts that target 3.2 > to see if I can make them compatible with 3.0 and 3.1 if they aren't > already. I found pyqver, but it isn't accurate (at least for 3.2/3.3 > scripts) and hasn't been updated in 2 years. I could look over the docs > and do it manually, but one of the scripts isn't small, so I'd prefer > not to. My advice: write a good test suite for your code and use something like tox to run it under the various Python versions that you want to support. No static analysis tool will ever be able to find all portability problems. Stefan From Nikunj.Badjatya at emc.com Tue Jun 19 02:28:26 2012 From: Nikunj.Badjatya at emc.com (Nikunj.Badjatya at emc.com) Date: Tue, 19 Jun 2012 02:28:26 -0400 Subject: Help On Paramiko Message-ID: <599CEBACD49B4144A61212D837EE3C0F1886E25E6C@MX34A.corp.emc.com> Howdy All, I am trying to use paramiko to automate logging in to remote unix machines and executing some commands there. When I normally do ssh from my linux machine (with Python 2.6) to this machine a different '>' prompt comes. It's a device specific custom prompt. After I run 'enable' command here, a new prompt opens up. '#' which is also custom prompt. Then I need to run 'configure terminal' there. And then some more device specific commands. i.e. {{{ Linux # Ssh admin at xx.xx.xx.xx ? Enable # configure terminal # }}} Can this be done using paramiko? I tried with: {{{ import paramiko client = paramiko.SSHClient() client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect('xx.xx.xx.xx', username='admin', password='') stdin, stdout, stderr = client.exec_command('enable') #stdin.write('configure t') print(stdout.readlines()) }}} (There is no passwd for username admin.) o/p ['UNIX shell commands cannot be executed using this account.\n'] Any suggestions? Thanks Nikunj -------------- next part -------------- An HTML attachment was scrubbed... URL: From noufal at nibrahim.net.in Tue Jun 19 02:30:57 2012 From: noufal at nibrahim.net.in (Noufal Ibrahim) Date: Tue, 19 Jun 2012 12:00:57 +0530 Subject: [BangPypers] Help On Paramiko In-Reply-To: <599CEBACD49B4144A61212D837EE3C0F1886E25E6C@MX34A.corp.emc.com> (Nikunj Badjatya's message of "Tue, 19 Jun 2012 02:28:26 -0400") References: <599CEBACD49B4144A61212D837EE3C0F1886E25E6C@MX34A.corp.emc.com> Message-ID: <87hau76cf2.fsf@sanitarium.localdomain> Fabric is a library built on paramiko that gives you abstractions so that you don't have to worry about things at such a fine grained level. Perhaps you should try using that. writes: > Howdy All, > > I am trying to use paramiko to automate logging in to remote unix machines and executing some commands there. > When I normally do ssh from my linux machine (with Python 2.6) to this machine a different '>' prompt comes. It's a device specific custom prompt. > After I run 'enable' command here, a new prompt opens up. '#' which is also custom prompt. > Then I need to run 'configure terminal' there. And then some more device specific commands. > > i.e. > {{{ > Linux # Ssh admin at xx.xx.xx.xx > > ? Enable > # configure terminal > # > }}} > > Can this be done using paramiko? > I tried with: > > {{{ > import paramiko > > client = paramiko.SSHClient() > client.load_system_host_keys() > client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) > client.connect('xx.xx.xx.xx', username='admin', password='') > stdin, stdout, stderr = client.exec_command('enable') > #stdin.write('configure t') > print(stdout.readlines()) > > }}} > (There is no passwd for username admin.) > > > o/p > ['UNIX shell commands cannot be executed using this account.\n'] > > Any suggestions? > > Thanks > Nikunj > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > http://mail.python.org/mailman/listinfo/bangpypers > -- Cordially, Noufal http://nibrahim.net.in From __peter__ at web.de Tue Jun 19 02:32:25 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Jun 2012 08:32:25 +0200 Subject: "constant sharing" works differently in REPL than in script ? References: Message-ID: shearichard at gmail.com wrote: > Listening to 'Radio Free Python' episode 8 > (http://radiofreepython.com/episodes/8/ - around about the 30 minute mark) > I heard that Python pre creates some integer constants to avoid a > proliferation of objects with the same value. > > I was interested in this and so I decided to try it out. > > First I did this at the prompt : > >>>> c = 1 >>>> print id(1) > 26906152 >>>> print id(c) > 26906152 >>>> c is 1 > True > > So that matched what I'd heard and then I did this to test the limits of > it : > >>>> c = 259 >>>> print id(259) > 26167488 >>>> print id(c) > 26167512 >>>> c is 259 > False > > And that was reasonable too as the podcast mentioned it was only done for > a small set of integers around zero. > > However when I wrote this script : > > c = 259 > print id(259) > print id(c) > if c is 259: > print "%s - yes" % (c) > else: > print "%s - no " % (c) > > I got this output : > > C:\data\src\Python\foo>python untitled-2.py > 26760884 > 26760884 > 259 - yes > > So what's going on here. The script seems to be sharing objects in a way > the REPL isn't ? > > Can anyone explain please ? As Benjamin wrote, this is a compile-time optimization (and you shouldn't rely on it). You can replicate it on the commandline: >>> a = 300 >>> b = 300 >>> a is b False >>> c = 300; d = 300 >>> c is d True Looking under the hood there's only one value for both constants: >>> import dis >>> code = compile("x = 300; y = 300", "", "exec") >>> code.co_consts (300, None) The generated bytecode is: >>> dis.dis(code) 1 0 LOAD_CONST 0 (300) 3 STORE_NAME 0 (x) 6 LOAD_CONST 0 (300) 9 STORE_NAME 1 (y) 12 LOAD_CONST 1 (None) 15 RETURN_VALUE From guru.eceng at gmail.com Tue Jun 19 03:04:13 2012 From: guru.eceng at gmail.com (Guru) Date: Tue, 19 Jun 2012 12:34:13 +0530 Subject: [BangPypers] Help On Paramiko In-Reply-To: <87hau76cf2.fsf@sanitarium.localdomain> References: <599CEBACD49B4144A61212D837EE3C0F1886E25E6C@MX34A.corp.emc.com> <87hau76cf2.fsf@sanitarium.localdomain> Message-ID: Refer this site you may get some useful information http://segfault.in/2010/03/paramiko-ssh-and-sftp-with-python/ On Tue, Jun 19, 2012 at 12:00 PM, Noufal Ibrahim wrote: > > Fabric is a library built on paramiko that gives you abstractions so > that you don't have to worry about things at such a fine grained > level. Perhaps you should try using that. > > writes: > > > Howdy All, > > > > I am trying to use paramiko to automate logging in to remote unix > machines and executing some commands there. > > When I normally do ssh from my linux machine (with Python 2.6) to this > machine a different '>' prompt comes. It's a device specific custom prompt. > > After I run 'enable' command here, a new prompt opens up. '#' which is > also custom prompt. > > Then I need to run 'configure terminal' there. And then some more device > specific commands. > > > > i.e. > > {{{ > > Linux # Ssh admin at xx.xx.xx.xx > > > > ? Enable > > # configure terminal > > # > > }}} > > > > Can this be done using paramiko? > > I tried with: > > > > {{{ > > import paramiko > > > > client = paramiko.SSHClient() > > client.load_system_host_keys() > > client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) > > client.connect('xx.xx.xx.xx', username='admin', password='') > > stdin, stdout, stderr = client.exec_command('enable') > > #stdin.write('configure t') > > print(stdout.readlines()) > > > > }}} > > (There is no passwd for username admin.) > > > > > > o/p > > ['UNIX shell commands cannot be executed using this account.\n'] > > > > Any suggestions? > > > > Thanks > > Nikunj > > _______________________________________________ > > BangPypers mailing list > > BangPypers at python.org > > http://mail.python.org/mailman/listinfo/bangpypers > > > > -- > Cordially, > Noufal > http://nibrahim.net.in > _______________________________________________ > BangPypers mailing list > BangPypers at python.org > http://mail.python.org/mailman/listinfo/bangpypers > -- -REGARDS Guruprasad K S -------------- next part -------------- An HTML attachment was scrubbed... URL: From alan.gauld at btinternet.com Tue Jun 19 03:46:02 2012 From: alan.gauld at btinternet.com (Alan Gauld) Date: Tue, 19 Jun 2012 08:46:02 +0100 Subject: Pymongo Error In-Reply-To: References: Message-ID: On 19/06/12 06:22, Ranjith Kumar wrote: > I tried Django with Mongodb while running manage.py syncdb I endup with > this error You might be better off trying a mongo forum./mailing list since this list is for Python beginners and focuses on the Python language and std library. Django is not in the standard library but is sufficiently common that you may get a response there. But Mongo is a wee bit specialised so it will be pure luck if you find a Mongo user who can answer... > django.db.utils.DatabaseError: Ordering can't span tables on > non-relational backends (content_type__app_label) Given we can't actually see the command you are trying to execute its virtually impossible to know what Mongo/Django/Python is complaining about. We would need to know a lot more about your data structure and your query. What is it you are trying to order for example? Does it span tables? HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ From gelonida at gmail.com Tue Jun 19 04:33:31 2012 From: gelonida at gmail.com (Gelonida N) Date: Tue, 19 Jun 2012 10:33:31 +0200 Subject: Conditional decoration In-Reply-To: References: Message-ID: On 06/19/2012 02:23 AM, Rob Williscroft wrote: > Roy Smith wrote in news:jro9cj$b44$1 at panix2.panix.com in > gmane.comp.python.general: > >> Is there any way to conditionally apply a decorator to a function? >> For example, in django, I want to be able to control, via a run-time >> config flag, if a view gets decorated with @login_required(). >> >> @login_required() >> def my_view(request): >> pass > > You need to create a decorator that calls either the original > function or the decorated funtion, depending on your condition, > Something like (untested): > > def conditional_login_required( f ): > _login_required = login_required()(f) > > def decorated( request ): > if condition == "use-login": > return _login_required( request ) > else: > return f( request ) > > return decorated > > @conditional_login_required > def my_view(request): > pass > > Replace (condition == "use-login") with whatever your "run-time > control flag" is. > Your suggestion will unconditionally decorate a function and depending on the condition call the original function or not. However if you want to evaluate the condition only once at decoration time, then you had probably to do something like (not tested) > def conditional_login_required( f ): > _login_required = login_required()(f) > > def decorated( request ): > return _login_required( request ) > if condition: > return decorated > else: > return f From rosuav at gmail.com Tue Jun 19 04:37:22 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jun 2012 18:37:22 +1000 Subject: "constant sharing" works differently in REPL than in script ? In-Reply-To: References: Message-ID: On Tue, Jun 19, 2012 at 12:52 PM, wrote: > ...Python pre creates some integer constants to avoid a proliferation of objects with the same value. > > I was interested in this and so I decided to try it out. > So that matched what I'd heard and then I did this to test the limits of it : > > And that was reasonable too as the podcast mentioned it was only done for a small set of integers around zero. The exact set varies according to Python version and, as others have mentioned, shouldn't be relied upon. import sys print(sys.version) wascached=False for i in range(-100,300): j=i+1 j-=1 if (i is j)!=wascached: wascached=i is j if wascached: firstcache=i else: print("%d to %d are cached"%(firstcache,i-1)) break 2.4.5 (#1, Jul 22 2011, 02:01:04) [GCC 4.1.1] -5 to 99 are cached 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] -5 to 256 are cached 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] -5 to 256 are cached It's definitely something that's fun to play with, though not something to take ANY notice of in real code :) ChrisA From jeanmichel at sequans.com Tue Jun 19 05:01:23 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 19 Jun 2012 11:01:23 +0200 Subject: Conditional decoration In-Reply-To: References: Message-ID: <4FE03FE3.7080302@sequans.com> Roy Smith wrote: > Is there any way to conditionally apply a decorator to a function? > For example, in django, I want to be able to control, via a run-time > config flag, if a view gets decorated with @login_required(). > > @login_required() > def my_view(request): > pass > Hi, def my_view(request): pass if flag: my_view = login_required(my_view) Regards, JM From johann.spies at gmail.com Tue Jun 19 06:10:53 2012 From: johann.spies at gmail.com (Johann Spies) Date: Tue, 19 Jun 2012 12:10:53 +0200 Subject: Converting html character codes to utf-8 text Message-ID: I am trying the following: Change data like this: Bien Donné : agri tourism to this: Bien Donn? agri tourism I am using the 'unescape' function published on http://effbot.org/zone/re-sub.htm#unescape-html but working through a file I get the following error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 519: ordinal not in range(128) and I do not now how to solve this problem. Any solution will be very appriciated. Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) -------------- next part -------------- An HTML attachment was scrubbed... URL: From clickfirm2007 at gmail.com Tue Jun 19 06:38:35 2012 From: clickfirm2007 at gmail.com (Mohamed Gad) Date: Tue, 19 Jun 2012 03:38:35 -0700 (PDT) Subject: DID YOU GET THIS? Message-ID: <38bd4502-81b5-46a8-9ded-722653392866@b1g2000vbb.googlegroups.com> Hey, Yesterday, I sent an email regarding my latest launch - Motivate To Empower: >> http://bit.ly/Motivate-To-Empower Remember, with this insane handbook, it'll save you months of frustration figuring out how to empower others. So far, there has been raving reviews about it already, and I don??t want you to miss out on this great opportunity. So grab it now before it's sold out: >> http://bit.ly/Motivate-To-Empower Warm regards http://bit.ly/Motivate-To-Empower From __peter__ at web.de Tue Jun 19 07:14:36 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Jun 2012 13:14:36 +0200 Subject: Converting html character codes to utf-8 text References: Message-ID: Johann Spies wrote: > I am trying the following: > > Change data like this: > > Bien Donné : agri tourism > > to this: > > Bien Donn? agri tourism > > I am using the 'unescape' function published on > http://effbot.org/zone/re-sub.htm#unescape-html but working through a file > I get the following error: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 519: > ordinal not in range(128) > > and I do not now how to solve this problem. > > Any solution will be very appriciated. The information you give is not sufficient to give a fix, but my crystal ball says that the string you pass to unescape() contains an e with acute encoded in utf-8 and not as an html escape. Instead of unescape(mydata) try unescape(mydata.decode("utf-8")) If that doesn't fix the problem come back with a self-contained example. From steve+comp.lang.python at pearwood.info Tue Jun 19 07:36:00 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Jun 2012 11:36:00 GMT Subject: Checking compatibility of a script across Python versions automatically References: Message-ID: <4fe06420$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jun 2012 14:24:03 -0500, Andrew Berg wrote: > Are there any tools out there that will parse a script and tell me if it > is compatible with an arbitrary version of Python and highlight any > incompatibilities? I need to check a few of my scripts that target 3.2 > to see if I can make them compatible with 3.0 and 3.1 if they aren't > already. I found pyqver, but it isn't accurate (at least for 3.2/3.3 > scripts) and hasn't been updated in 2 years. I could look over the docs > and do it manually, but one of the scripts isn't small, so I'd prefer > not to. You could try running it and see if it breaks. That usually works for me :) For anything except throw-away scripts, I prefer to write scripts with a "self-test" option so that I (or any other user) can run the test and see if it works without actually using it for production work. -- Steven From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Jun 19 07:44:47 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 19 Jun 2012 13:44:47 +0200 Subject: Is that safe to use ramdom.random() for key to encrypt? References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> <4fdd5aac$0$29980$c3e8da3$5496439d@news.astraweb.com> <4FDE0E8B.3050701@gmail.com> <4fde6591$0$29980$c3e8da3$5496439d@news.astraweb.com> <7xd34x1ov3.fsf@ruckus.brouhaha.com> Message-ID: Am 18.06.2012 01:48 schrieb Paul Rubin: > Steven D'Aprano writes: >>> /dev/urandom isn't actually cryptographically secure; it promises not to >>> block, even if it has insufficient entropy. But in your instance... >> >> Correct. /dev/random is meant to be used for long-lasting >> cryptographically-significant uses, such as keys. urandom is not. > > They are both ill-advised if you're doing anything really serious. Hm? > In practice if enough entropy has been in the system to make a key with > /dev/random, then urandom should also be ok. Right. > Unfortunately the sensible > interface is missing: block until there's enough entropy, then generate > data cryptographically, folding in new entropy when it's available. What am I missing? You exactly describe /dev/random's interface. Thomas From oscar.j.benjamin at gmail.com Tue Jun 19 08:24:25 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 19 Jun 2012 13:24:25 +0100 Subject: Read STDIN as bytes rather than a string In-Reply-To: References: Message-ID: On 19 June 2012 00:53, Jason Friedman wrote: > Which leads me to another question ... how can I debug these things? > > $ echo 'hello' | python3 -m pdb ~/my-input.py > > /home/jason/my-input.py(2)() > -> import sys > (Pdb) *** NameError: name 'hello' is not defined > -- > http://mail.python.org/mailman/listinfo/python-list > It's difficult to debug problems that are related to reading from stdin. I don't know of any good way, so I just end up doing things like adding print statements and checking the output rather than using a debugger. Tools like hd can help with checking the input/output files that you're using. If there were a debugger it would probably need to be one with a GUI - the only one I know is spyder but I don't think that will allow you to pipe anything on stdin. One thing I wanted to say is that if your script is intended to work on Windows you'll need to use msvcrt.setmode() to disable newline translation on stdin (I haven't tested with Python 3.x, but it's definitely necessary with Python 2.x). See Frazil's post here: http://stackoverflow.com/questions/2850893/reading-binary-data-from-stdin -------------- next part -------------- An HTML attachment was scrubbed... URL: From feliphil at gmx.net Tue Jun 19 09:07:16 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Tue, 19 Jun 2012 15:07:16 +0200 Subject: Pythonic cross-platform GUI desingers =?ISO-8859-1?Q?=E0?= la Interface Builder (Re: what gui designer is everyone using) References: <4FD4F75D.40602@schwertberger.de> <20120613144931.adbb2c52.feliphil@gmx.net> Message-ID: <20120619150716.263fc70d.feliphil@gmx.net> > >> No matter how cool it may seem to create simple GUIs manually or to > >> write business letters using LaTeX: just try to persuade people to > >> move from Word to LaTeX for business letters... > > > > Good example. > > > > I have done nearly exactly this* - but it was only possible thanks > > to LyX. > > > *I moved not from Wugh, but from other software to LyX/LaTeX for > > all my document processing. > But of course, you were only doing so because you had LyX available, > which is the equivalent of an easy-to-use GUI builder. No need to argue here. This was exactly my point. :-) > So maybe I should be more precise: just try to persuade people to move > from Word to *pure* LaTeX for business letters... Nearly impossible. And this was exactly my point. Again, no need to argue here. :-) The success of LyX (and TeXmacs and BaKoMaTeX and Scientific Word...) proves imho that the LaTeX community had missed to offer a "syntax-hiding"-GUI with LaTeX some 20 years ago. And the lack of success of Python so far to replace, in your application case, Labview, or, in my application case, all those proprietary 4GL IDEs/frameworks/GUI builders (just check the success that Realbasic has) proves imho that the Python community has totally missed to address the vast crowd of potential users who are domain experts in other domains than software development. Sincerely, Wolfgang From eire1130 at gmail.com Tue Jun 19 09:34:04 2012 From: eire1130 at gmail.com (James Reynolds) Date: Tue, 19 Jun 2012 09:34:04 -0400 Subject: [Tutor] Pymongo Error In-Reply-To: References: Message-ID: On Tue, Jun 19, 2012 at 1:22 AM, Ranjith Kumar wrote: > Hi all, > I tried Django with Mongodb while running manage.py syncdb I endup with > this error > > note : it works fine with sqlite and mysql db > > (django-1.3)ranjith at ranjith:~/ > sandbox/python-box/hukkster-core-site/hukk$ ./manage.py syncdb > /home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/pymongo/connection.py:385: > UserWarning: must provide a username and password to authenticate to > hukkster_testing > "to authenticate to %s" % (db,)) > Creating tables ... > Traceback (most recent call last): > File "./manage.py", line 14, in > execute_manager(settings) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/__init__.py", > line 438, in execute_manager > utility.execute() > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/__init__.py", > line 379, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 191, in run_from_argv > self.execute(*args, **options.__dict__) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 220, in execute > output = self.handle(*args, **options) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/base.py", > line 351, in handle > return self.handle_noargs(**options) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", > line 109, in handle_noargs > emit_post_sync_signal(created_models, verbosity, interactive, db) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/core/management/sql.py", > line 190, in emit_post_sync_signal > interactive=interactive, db=db) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", > line 172, in send > response = receiver(signal=self, sender=sender, **named) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", > line 41, in create_permissions > "content_type", "codename" > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 107, in _result_iter > self._fill_cache() > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 772, in _fill_cache > self._result_cache.append(self._iter.next()) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/django/db/models/query.py", > line 959, in iterator > for row in self.query.get_compiler(self.db).results_iter(): > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 229, in results_iter > for entity in self.build_query(fields).fetch(low_mark, high_mark): > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 290, in build_query > query.order_by(self._get_ordering()) > File > "/home/ranjith/virtualenvs/django-1.3/local/lib/python2.7/site-packages/djangotoolbox/db/basecompiler.py", > line 339, in _get_ordering > raise DatabaseError("Ordering can't span tables on non-relational > backends (%s)" % order) > django.db.utils.DatabaseError: Ordering can't span tables on > non-relational backends (content_type__app_label) > > > DB settings in settings.py > > DATABASES = { > 'default': { > 'ENGINE': 'django_mongodb_engine', > 'NAME': 'helloworld', > 'USER': '', > 'PASSWORD': '12424214', > 'HOST': 'mongodb://staff.mongohq.com/', > 'PORT': 'XXXXX', > }, > } > > my requirement packages, > Django==1.3 > dictshield==0.4.4 > django-mongodb-engine==0.4.0 > django-social-auth==0.6.9 > djangotoolbox==0.0.1 > httplib2==0.7.4 > mongoengine==0.6.10 > mongokit==0.8 > oauth2==1.5.211 > pymongo==2.2 > python-openid==2.2.5 > simplejson==2.5.2 > wsgiref==0.1.2 > > Please point me what i missed here... > > -- > Cheers, > Ranjith Kumar K, > Chennai. > > http://ranjithtenz.wordpress.com > > > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > This list here is for new users to python. Using mongo with django is a pretty advanced topic. I would suggest posting this on stackoverflow, or to the django-users group (and there are a ton of resources on this already on those two sites on this topic) That said, having used mongo with django, I'll bet your problem is that you are using the django version provided by the django project. For Mongo, you have to use the django-norel fork. Just google Django Mongo NoRel in various combinations and you will find it. To do this, and not screw up your working environment, you will need to make certain you have a virtual environment set up. Anyway, once you get it set up, it actually works pretty good. -------------- next part -------------- An HTML attachment was scrubbed... URL: From satyaakam at gmail.com Tue Jun 19 11:06:19 2012 From: satyaakam at gmail.com (satyaakam goswami) Date: Tue, 19 Jun 2012 20:36:19 +0530 Subject: [BangPypers] Help On Paramiko In-Reply-To: <599CEBACD49B4144A61212D837EE3C0F1886E25E6C@MX34A.corp.emc.com> References: <599CEBACD49B4144A61212D837EE3C0F1886E25E6C@MX34A.corp.emc.com> Message-ID: > > o/p > ['UNIX shell commands cannot be executed using this account.\n'] > > Any suggestions? > > last time i had such a requirement it started just like you into writing something , then i did a quick web search before starting and found http://code.google.com/p/sshpt/ which served all our requirements so we stuck to . it too uses paramiko. -Satya fossevents.in -------------- next part -------------- An HTML attachment was scrubbed... URL: From torriem at gmail.com Tue Jun 19 11:28:20 2012 From: torriem at gmail.com (Michael Torrie) Date: Tue, 19 Jun 2012 09:28:20 -0600 Subject: Help On Paramiko In-Reply-To: <599CEBACD49B4144A61212D837EE3C0F1886E25E6C@MX34A.corp.emc.com> References: <599CEBACD49B4144A61212D837EE3C0F1886E25E6C@MX34A.corp.emc.com> Message-ID: <4FE09A94.4050704@gmail.com> On 06/19/2012 12:28 AM, Nikunj.Badjatya at emc.com wrote: > Howdy All, > > I am trying to use paramiko to automate logging in to remote unix machines and executing some commands there. > When I normally do ssh from my linux machine (with Python 2.6) to this machine a different '>' prompt comes. It's a device specific custom prompt. > After I run 'enable' command here, a new prompt opens up. '#' which is also custom prompt. > Then I need to run 'configure terminal' there. And then some more device specific commands. I think you want an abstraction layer like fabric, or the old and venerable pexpect. Makes this kind of interaction a lot easier. From anthra.norell at bluewin.ch Tue Jun 19 11:55:48 2012 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Tue, 19 Jun 2012 17:55:48 +0200 Subject: Tkinter binding question In-Reply-To: <7f22c54e-2cd1-4a7f-a9f6-a33b8f17eb23@googlegroups.com> References: <7f22c54e-2cd1-4a7f-a9f6-a33b8f17eb23@googlegroups.com> Message-ID: <1340121348.2358.235.camel@hatchbox-one> Rick, Thank you for your thorough discussion. I tried your little program. Enter and leave work as expected. Pushing mouse buttons call leave-enter, exactly as it happened with my code. So that seems to be a default behavior. No big deal. Without the tracing messages it would go unnoticed. Releasing either of the bound mouse buttons displays the corresponding messages. So all works fine. If I copy your event descriptors into my program, the button-release callback still fails. It works in your code, not in mine. Here is what my code now looks like. It is somewhat more complicated than yours, because I bind Frames holding each a line (line_frame) and each frame contains a few Labels side by side. The idea is to achieve a table with vertically aligning columns each line of which I can click-select. (Is there a better way?) for line_frame in ...: line_frame.bind ('', self.color_selected) line_frame.bind ('', self.color_selectable) line_frame.bind ('', self.pick_record) line_frame.bind ('', self.info_profile) line_frame.grid (row = n+1, column = 0) for i in self.range_n_fields: field = Label (line_frame, width = ..., text = ... field.grid (row = 0, column = i, sticky = W) ... def color_selected (self, event): print 'hit list.color_selected ()' def color_selectable (self, event): print 'hit list.color_selectable ()' def pick_record (self, event): # Nver gets called print 'hit list.pick_record ()' def info_profile (self, event): # Never gets called print 'hit list.info_profile ()' I admit that I don't have an accurate conception of the inner workings. It's something the traveler on the learning curve has to acquire a feel for by trial and error. In this case the differing behavior should logically have to do with the structural difference: I bind Labels that contain Labels. If I click this nested assembly, who gets the event? The contained widget, the containing widget or both? Frederic Incidentally, my source of inspiration for chaining event descriptors was the New Mexico Tech Tkinter 8.4 reference, which says: ... In general, an event sequence is a string containing one or more event patterns. Each event pattern describes one thing that can happen. If there is more than one event pattern in a sequence, the handler will be called only when all the patterns happen in that same sequence ... Again, predicting the precedence with overlaps is much like solving a murder case: finding suspects and let the innocent ones off the hook. The only reference I have found on that topic is in effbot.org's tkinterbook, which says that precedence goes to the "closest match", but doesn't explain how one evaluates "closeness". From edcjones at comcast.net Tue Jun 19 12:23:52 2012 From: edcjones at comcast.net (Edward C. Jones) Date: Tue, 19 Jun 2012 12:23:52 -0400 Subject: Python equivalent to the "A" or "a" output conversions in C Message-ID: <4FE0A798.2010603@comcast.net> Consider the following line in C: printf('%a\n', x); where x is a float or double. This outputs a hexadecimal representation of x. Can I do this in Python? From hemanth.hm at gmail.com Tue Jun 19 12:41:04 2012 From: hemanth.hm at gmail.com (Hemanth H.M) Date: Tue, 19 Jun 2012 22:11:04 +0530 Subject: Python equivalent to the "A" or "a" output conversions in C In-Reply-To: <4FE0A798.2010603@comcast.net> References: <4FE0A798.2010603@comcast.net> Message-ID: Are you looking for : >>> x=10 >>> hex(x) '0xa' >>> x=10.5 >>> float.hex(x) '0x1.5000000000000p+3' On Tue, Jun 19, 2012 at 9:53 PM, Edward C. Jones wrote: > hexadecimal -- *'I am what I am because of who we all are'* h3manth.com *-- Hemanth HM * -------------- next part -------------- An HTML attachment was scrubbed... URL: From news at blinne.net Tue Jun 19 13:00:26 2012 From: news at blinne.net (Alexander Blinne) Date: Tue, 19 Jun 2012 19:00:26 +0200 Subject: Python equivalent to the "A" or "a" output conversions in C In-Reply-To: References: Message-ID: <4fe0b02a$0$9508$9b4e6d93@newsspool1.arcor-online.net> On 19.06.2012 18:23, Edward C. Jones wrote: > Consider the following line in C: > printf('%a\n', x); > where x is a float or double. This outputs a hexadecimal representation > of x. Can I do this in Python? Don't know why there is no format character %a or %A in python, but the conversion is done by float method hex(): a = 3.1415 print a.hex() Greetings From breamoreboy at yahoo.co.uk Tue Jun 19 13:12:37 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 19 Jun 2012 18:12:37 +0100 Subject: Python equivalent to the "A" or "a" output conversions in C In-Reply-To: <4FE0A798.2010603@comcast.net> References: <4FE0A798.2010603@comcast.net> Message-ID: On 19/06/2012 17:23, Edward C. Jones wrote: > Consider the following line in C: > printf('%a\n', x); > where x is a float or double. This outputs a hexadecimal representation > of x. Can I do this in Python? > See this http://docs.python.org/library/string.html#format-examples -- Cheers. Mark Lawrence. From roy at panix.com Tue Jun 19 13:55:49 2012 From: roy at panix.com (Roy Smith) Date: 19 Jun 2012 13:55:49 -0400 Subject: Finding absolute path of imported module? Message-ID: We're trying to debug a weird (and, of course, intermittent) problem a gunicorn-based web application. Our production directory structure looks like: deploy/ rel-2012-06-14/ rel-2012-06-12/ rel-2012-06-11/ current -> rel-2012006-14 Each time we deploy a new version, we create a new release directory, move the "current" symlink, and restart gunicorn. We've seen instances where some of the workers end up importing some modules from one directory and some from another (i.e. the old and new targets of current). So, the question is, is there any way to dump all the *absolute* pathnames of all the imported modules? I can iterate over sys.modules.values(), but that doesn't give me absolute pathnames, so I can't tell which version of the symlink existed when the module was imported. From lists at cheimes.de Tue Jun 19 15:32:53 2012 From: lists at cheimes.de (Christian Heimes) Date: Tue, 19 Jun 2012 21:32:53 +0200 Subject: Finding absolute path of imported module? In-Reply-To: References: Message-ID: Am 19.06.2012 19:55, schrieb Roy Smith: > So, the question is, is there any way to dump all the *absolute* > pathnames of all the imported modules? I can iterate over > sys.modules.values(), but that doesn't give me absolute pathnames, so > I can't tell which version of the symlink existed when the module was > imported. You can use os.path.abspath(module.__file__) to get the absolute path of a module. This works reliable unless you use os.chdir() in your code. abspath() may not normalize symlinks (not sure about it) but you can check for symlink with os.path.islink() (uses os.lstat) and resolve the link with os.readlink(). Christian From edcjones at comcast.net Tue Jun 19 15:54:05 2012 From: edcjones at comcast.net (Edward C. Jones) Date: Tue, 19 Jun 2012 15:54:05 -0400 Subject: Python equivalent to the "A" or "a" output conversions in C In-Reply-To: References: <4FE0A798.2010603@comcast.net> Message-ID: <4FE0D8DD.9040800@comcast.net> On 06/19/2012 12:41 PM, Hemanth H.M wrote: > >>> float.hex(x) > '0x1.5000000000000p+3' > Some days I don't ask the brightest questions. Suppose x was a numpy floating scalar (types numpy.float16, numpy.float32, numpy.float64, or numpy.float128). Is there an easy way to write x in binary or hex? From wxjmfauth at gmail.com Tue Jun 19 16:11:44 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 19 Jun 2012 13:11:44 -0700 (PDT) Subject: Python equivalent to the "A" or "a" output conversions in C References: <4FE0A798.2010603@comcast.net> Message-ID: <4bc897bd-5430-445a-8d14-c8a76e1f2d7e@5g2000vbf.googlegroups.com> On Jun 19, 9:54?pm, "Edward C. Jones" wrote: > On 06/19/2012 12:41 PM, Hemanth H.M wrote: > > > >>> float.hex(x) > > '0x1.5000000000000p+3' > > Some days I don't ask the brightest questions. ?Suppose x was a numpy > floating scalar (types numpy.float16, numpy.float32, numpy.float64, or > numpy.float128). ?Is there an easy way to write x in > binary or hex? I'm not aware about a buitin fct. May be the module struct ? Interpret bytes as packed binary data can help. jmf From shearichard at gmail.com Tue Jun 19 17:21:59 2012 From: shearichard at gmail.com (shearichard at gmail.com) Date: Tue, 19 Jun 2012 14:21:59 -0700 (PDT) Subject: "constant sharing" works differently in REPL than in script ? In-Reply-To: References: Message-ID: <137e93d3-17b3-41ad-8e1e-79e786f347e3@googlegroups.com> Thanks for all the replies. I hadn't thought about the opportunities that exist for optimization when the whole script is there (or when compound operations are taking place) by contrast with plain old REPL ops. I liked your code Chris demoing the different ranges in different versions. I tried to write something like that myself but you did it an awful lot better ! From rosuav at gmail.com Tue Jun 19 17:44:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Jun 2012 07:44:42 +1000 Subject: "constant sharing" works differently in REPL than in script ? In-Reply-To: <137e93d3-17b3-41ad-8e1e-79e786f347e3@googlegroups.com> References: <137e93d3-17b3-41ad-8e1e-79e786f347e3@googlegroups.com> Message-ID: On Wed, Jun 20, 2012 at 7:21 AM, wrote: > I liked your code Chris demoing the different ranges in different versions. I tried to write something like that myself but you did it an awful lot better ! There's no guarantee that it'll prove which are and aren't cached, but it does seem to work. (Incidentally, it doesn't handle the case where _no_ integers are cached.) ChrisA From gelonida at gmail.com Tue Jun 19 17:46:48 2012 From: gelonida at gmail.com (Gelonida N) Date: Tue, 19 Jun 2012 23:46:48 +0200 Subject: Finding absolute path of imported module? In-Reply-To: References: Message-ID: On 06/19/2012 09:32 PM, Christian Heimes wrote: > Am 19.06.2012 19:55, schrieb Roy Smith: >> So, the question is, is there any way to dump all the *absolute* >> pathnames of all the imported modules? I can iterate over >> sys.modules.values(), but that doesn't give me absolute pathnames, so >> I can't tell which version of the symlink existed when the module was >> imported. > > You can use os.path.abspath(module.__file__) to get the absolute path of > a module. This works reliable unless you use os.chdir() in your code. > > abspath() may not normalize symlinks (not sure about it) but you can > check for symlink with os.path.islink() (uses os.lstat) and resolve the > link with os.readlink(). > If I remember well, os.path.realpath(module.__file__) should normalize the paths and resolve the symlinks From steve+comp.lang.python at pearwood.info Tue Jun 19 19:21:23 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Jun 2012 23:21:23 GMT Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> Message-ID: <4fe10972$0$29980$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jun 2012 07:00:01 -0700, jmfauth wrote: > On 18 juin, 12:11, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Mon, 18 Jun 2012 02:30:50 -0700, jmfauth wrote: >> > On 18 juin, 10:28, Benjamin Kaplan wrote: >> >> The u prefix is only there to >> >> make it easier to port a codebase from Python 2 to Python 3. It >> >> doesn't actually do anything. >> >> > It does. I shew it! >> >> Incorrect. You are assuming that Python 3 input eval's the input like >> Python 2 does. That is wrong. All you show is that the one-character >> string "a" is not equal to the four-character string "u'a'", which is >> hardly a surprise. You wouldn't expect the string "3" to equal the >> string "int('3')" would you? >> >> -- >> Steven > > > A string is a string, a "piece of text", period. > > I do not see why a unicode literal and an (well, I do not know how the > call it) a "normal class " should behave differently in code source > or as an answer to an input(). They do not. As you showed earlier, in Python 3.3 the literal strings u'a' and 'a' have the same meaning: both create a one-character string containing the Unicode letter LOWERCASE-A. Note carefully that the quotation marks are not part of the string. They are delimiters. Python 3.3 allows you to create a string by using delimiters: ' ' " " u' ' u" " plus triple-quoted versions of the same. The delimiter is not part of the string. They are only there to mark the start and end of the string in source code so that Python can tell the difference between the string "a" and the variable named "a". Note carefully that quotation marks can exist inside strings: my_string = "This string has 'quotation marks'." The " at the start and end of the string literal are delimiters, not part of the string, but the internal ' characters *are* part of the string. When you read data from a file, or from the keyboard using input(), Python takes the data and returns a string. You don't need to enter delimiters, because there is no confusion between a string (all data you read) and other programming tokens. For example: py> s = input("Enter a string: ") Enter a string: 42 py> print(s, type(s)) 42 Because what I type is automatically a string, I don't need to enclose it in quotation marks to distinguish it from the integer 42. py> s = input("Enter a string: ") Enter a string: This string has 'quotation marks'. py> print(s, type(s)) This string has 'quotation marks'. What you type is exactly what you get, no more, no less. If you type 42, you get the two character string "42" and not the int 42. If you type [1, 2, 3], then you get the nine character string "[1, 2, 3]" and not a list containing integers 1, 2 and 3. If you type 3**0.5 then you get the six character string "3**0.5" and not the float 1.7320508075688772. If you type u'a' then you get the four character string "u'a'" and not the single character 'a'. There is nothing new going on here. The behaviour of input() in Python 3, and raw_input() in Python 2, has not changed. > Should a user write two derived functions? > > input_for_entering_text() > and > input_if_you_are_entering_a_text_as_litteral() If you, the programmer, want to force the user to write input in Python syntax, then yes, you have to write a function to do so. input() is very simple: it just reads strings exactly as typed. It is up to you to process those strings however you wish. -- Steven From rantingrickjohnson at gmail.com Tue Jun 19 22:19:59 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Tue, 19 Jun 2012 19:19:59 -0700 (PDT) Subject: Tkinter binding question In-Reply-To: References: <7f22c54e-2cd1-4a7f-a9f6-a33b8f17eb23@googlegroups.com> Message-ID: <38e7661b-23ee-4cda-ac80-e189a017e3e9@googlegroups.com> On Tuesday, June 19, 2012 10:55:48 AM UTC-5, Frederic Rentsch wrote: > If I copy your event descriptors into my program, the button-release > callback still fails. It works in your code, not in mine. Here is what > my code now looks like. It is somewhat more complicated than yours, > because I bind Frames holding each a line (line_frame) and each frame > contains a few Labels side by side. The idea is to achieve a table with > vertically aligning columns each line of which I can click-select. (Is > there a better way?) > > for line_frame in ...: > line_frame.bind ('', self.color_selected) > line_frame.bind ('', self.color_selectable) > line_frame.bind ('', self.pick_record) > line_frame.bind ('', self.info_profile) > line_frame.grid (row = n+1, column = 0) > for i in self.range_n_fields: > field = Label (line_frame, width = ..., text = ... > field.grid (row = 0, column = i, sticky = W) > ... > > def color_selected (self, event): > print 'hit list.color_selected ()' > > def color_selectable (self, event): > print 'hit list.color_selectable ()' > > def pick_record (self, event): # Nver gets called > print 'hit list.pick_record ()' > > def info_profile (self, event): # Never gets called > print 'hit list.info_profile ()' Events only fire for the widget that currently has "focus". Frames, labels, and other widgets do not receive focus simply by hovering over them. You can set the focus manually by calling "w.focus_set()" -- where "w" is any Tkinter widget. I can't be sure because i don't have enough of your code to analyze, but I think you should bind (either globally or by class type) all "Enter" events to a callback that sets the focus of the current widget under the mouse. Experiment with this code and see if it is what you need: ## START CODE ## from __future__ import print_function import Tkinter as tk def cb(event): print(event.widget.winfo_class()) event.widget.focus_set() root = tk.Tk() root.geometry('200x200+20+20') for x in range(10): w = tk.Frame(root, width=20, height=20,bg='red') w.grid(row=x, column=0, padx=5, pady=5) w = tk.Frame(root, width=20, height=20,bg='green', highlightthickness=1) w.grid(row=x, column=1, padx=5, pady=5) w = tk.Button(root, text=str(x)) w.grid(row=x, column=2, padx=5, pady=5) root.bind_all("", cb) root.mainloop() ## END CODE ## You will see that the first column of frames are recieving focus but you have no visual cues of that focus (due to a default setting). In the second column you get the visual cue since i set "highlightthicness=1". The third column is a button widget which by default has visual focus cues. Is this the problem? PS: Also check out the "w.bind_class()" method. > Incidentally, my source of inspiration for chaining event descriptors > was the New Mexico Tech Tkinter 8.4 reference, That's an excellent reference BTW. Keep it under your pillow. Effbot also has a great tutorial. From rantingrickjohnson at gmail.com Tue Jun 19 22:19:59 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Tue, 19 Jun 2012 19:19:59 -0700 (PDT) Subject: Tkinter binding question In-Reply-To: References: <7f22c54e-2cd1-4a7f-a9f6-a33b8f17eb23@googlegroups.com> Message-ID: <38e7661b-23ee-4cda-ac80-e189a017e3e9@googlegroups.com> On Tuesday, June 19, 2012 10:55:48 AM UTC-5, Frederic Rentsch wrote: > If I copy your event descriptors into my program, the button-release > callback still fails. It works in your code, not in mine. Here is what > my code now looks like. It is somewhat more complicated than yours, > because I bind Frames holding each a line (line_frame) and each frame > contains a few Labels side by side. The idea is to achieve a table with > vertically aligning columns each line of which I can click-select. (Is > there a better way?) > > for line_frame in ...: > line_frame.bind ('', self.color_selected) > line_frame.bind ('', self.color_selectable) > line_frame.bind ('', self.pick_record) > line_frame.bind ('', self.info_profile) > line_frame.grid (row = n+1, column = 0) > for i in self.range_n_fields: > field = Label (line_frame, width = ..., text = ... > field.grid (row = 0, column = i, sticky = W) > ... > > def color_selected (self, event): > print 'hit list.color_selected ()' > > def color_selectable (self, event): > print 'hit list.color_selectable ()' > > def pick_record (self, event): # Nver gets called > print 'hit list.pick_record ()' > > def info_profile (self, event): # Never gets called > print 'hit list.info_profile ()' Events only fire for the widget that currently has "focus". Frames, labels, and other widgets do not receive focus simply by hovering over them. You can set the focus manually by calling "w.focus_set()" -- where "w" is any Tkinter widget. I can't be sure because i don't have enough of your code to analyze, but I think you should bind (either globally or by class type) all "Enter" events to a callback that sets the focus of the current widget under the mouse. Experiment with this code and see if it is what you need: ## START CODE ## from __future__ import print_function import Tkinter as tk def cb(event): print(event.widget.winfo_class()) event.widget.focus_set() root = tk.Tk() root.geometry('200x200+20+20') for x in range(10): w = tk.Frame(root, width=20, height=20,bg='red') w.grid(row=x, column=0, padx=5, pady=5) w = tk.Frame(root, width=20, height=20,bg='green', highlightthickness=1) w.grid(row=x, column=1, padx=5, pady=5) w = tk.Button(root, text=str(x)) w.grid(row=x, column=2, padx=5, pady=5) root.bind_all("", cb) root.mainloop() ## END CODE ## You will see that the first column of frames are recieving focus but you have no visual cues of that focus (due to a default setting). In the second column you get the visual cue since i set "highlightthicness=1". The third column is a button widget which by default has visual focus cues. Is this the problem? PS: Also check out the "w.bind_class()" method. > Incidentally, my source of inspiration for chaining event descriptors > was the New Mexico Tech Tkinter 8.4 reference, That's an excellent reference BTW. Keep it under your pillow. Effbot also has a great tutorial. From aldrich.demata at gmail.com Wed Jun 20 02:55:16 2012 From: aldrich.demata at gmail.com (Aldrich DeMata) Date: Wed, 20 Jun 2012 01:55:16 -0500 Subject: Python equivalent to the "A" or "a" output conversions in C In-Reply-To: <4FE0D8DD.9040800@comcast.net> References: <4FE0A798.2010603@comcast.net> <4FE0D8DD.9040800@comcast.net> Message-ID: Use the binascii module: >>> import numpy as np >>> x = np.float32(3.14) >>> x.dtype dtype('float32') >>> binascii.hexlify(x) 'c3f54840' The final result is little endian so it should be read as 0x4048f5c3 instead. You can verify the conversion using the link below: http://gregstoll.dyndns.org/~gregstoll/floattohex/ aldrich On Tue, Jun 19, 2012 at 2:54 PM, Edward C. Jones wrote: > On 06/19/2012 12:41 PM, Hemanth H.M wrote: > > >>> float.hex(x) >> '0x1.5000000000000p+3' >> >> Some days I don't ask the brightest questions. Suppose x was a numpy > floating scalar (types numpy.float16, numpy.float32, numpy.float64, or > numpy.float128). Is there an easy way to write x in > binary or hex? > > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Wed Jun 20 04:12:00 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 20 Jun 2012 01:12:00 -0700 (PDT) Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <4fe10972$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3d725d3a-3159-4732-b5ae-17feedcf045d@k5g2000vbf.googlegroups.com> On Jun 20, 1:21?am, Steven D'Aprano wrote: > On Mon, 18 Jun 2012 07:00:01 -0700, jmfauth wrote: > > On 18 juin, 12:11, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: > >> On Mon, 18 Jun 2012 02:30:50 -0700, jmfauth wrote: > >> > On 18 juin, 10:28, Benjamin Kaplan wrote: > >> >> The u prefix is only there to > >> >> make it easier to port a codebase from Python 2 to Python 3. It > >> >> doesn't actually do anything. > > >> > It does. I shew it! > > >> Incorrect. You are assuming that Python 3 input eval's the input like > >> Python 2 does. That is wrong. All you show is that the one-character > >> string "a" is not equal to the four-character string "u'a'", which is > >> hardly a surprise. You wouldn't expect the string "3" to equal the > >> string "int('3')" would you? > > >> -- > >> Steven > > > A string is a string, a "piece of text", period. > > > I do not see why a unicode literal and an (well, I do not know how the > > call it) a "normal class " should behave differently in code source > > or as an answer to an input(). > > They do not. As you showed earlier, in Python 3.3 the literal strings > u'a' and 'a' have the same meaning: both create a one-character string > containing the Unicode letter LOWERCASE-A. > > Note carefully that the quotation marks are not part of the string. They > are delimiters. Python 3.3 allows you to create a string by using > delimiters: > > ' ' > " " > u' ' > u" " > > plus triple-quoted versions of the same. The delimiter is not part of the > string. They are only there to mark the start and end of the string in > source code so that Python can tell the difference between the string "a" > and the variable named "a". > > Note carefully that quotation marks can exist inside strings: > > my_string = "This string has 'quotation marks'." > > The " at the start and end of the string literal are delimiters, not part > of the string, but the internal ' characters *are* part of the string. > > When you read data from a file, or from the keyboard using input(), > Python takes the data and returns a string. You don't need to enter > delimiters, because there is no confusion between a string (all data you > read) and other programming tokens. > > For example: > > py> s = input("Enter a string: ") > Enter a string: 42 > py> print(s, type(s)) > 42 > > Because what I type is automatically a string, I don't need to enclose it > in quotation marks to distinguish it from the integer 42. > > py> s = input("Enter a string: ") > Enter a string: This string has 'quotation marks'. > py> print(s, type(s)) > This string has 'quotation marks'. > > What you type is exactly what you get, no more, no less. > > If you type 42, you get the two character string "42" and not the int 42. > > If you type [1, 2, 3], then you get the nine character string "[1, 2, 3]" > and not a list containing integers 1, 2 and 3. > > If you type 3**0.5 then you get the six character string "3**0.5" and not > the float 1.7320508075688772. > > If you type u'a' then you get the four character string "u'a'" and not > the single character 'a'. > > There is nothing new going on here. The behaviour of input() in Python 3, > and raw_input() in Python 2, has not changed. > > > Should a user write two derived functions? > > > input_for_entering_text() > > and > > input_if_you_are_entering_a_text_as_litteral() > > If you, the programmer, want to force the user to write input in Python > syntax, then yes, you have to write a function to do so. input() is very > simple: it just reads strings exactly as typed. It is up to you to > process those strings however you wish. > > -- > Steven Python 3.3.0a4 (v3.3.0a4:7c51388a3aa7+, May 31 2012, 20:15:21) [MSC v. 1600 32 bit (Intel)] on win32 >>> --- running smidzero.py... ...smidzero has been executed >>> --- input(':') :?l?phant '?l?phant' >>> --- input(':') :u'?l?phant' '?l?phant' >>> --- input(':') :u'\u00e9l\xe9phant' '?l?phant' >>> --- input(':') :u'\U000000e9l?phant' '?l?phant' >>> --- input(':') :\U000000e9l?phant '?l?phant' >>> --- >>> --- # this is expected >>> --- input(':') :b'?l?phant' "b'?l?phant'" >>> --- len(input(':')) :b'?l?phant' 11 --- Good news on the ru''/ur'' front: http://bugs.python.org/issue15096 --- Finally I'm just wondering if this unicode_literal reintroduction is not a bad idea. b'these_are_bytes' u'this_is_a_unicode_string' I wrote all my Py2 code in a "unicode mode" since ... Py2.3 (?). jmf From lists at cheimes.de Wed Jun 20 05:22:35 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 20 Jun 2012 11:22:35 +0200 Subject: Py3.3 unicode literal and input() In-Reply-To: References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> <44a6bacd-d4d7-4c1f-ae1a-8f9ce4a1abc9@d6g2000vbe.googlegroups.com> Message-ID: Am 18.06.2012 20:45, schrieb Terry Reedy: > The simultaneous reintroduction of 'ur', but with a different meaning > than in 2.7, *was* a problem and it should be removed in the next release. FYI: http://hg.python.org/cpython/rev/8e47e9af826e Christian From wxjmfauth at gmail.com Wed Jun 20 07:25:54 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 20 Jun 2012 04:25:54 -0700 (PDT) Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <28dfa0dd-a3b8-4295-a08b-a89aa33be745@q2g2000vbv.googlegroups.com> <44a6bacd-d4d7-4c1f-ae1a-8f9ce4a1abc9@d6g2000vbe.googlegroups.com> Message-ID: <4eab307e-4cfa-434f-b25b-801462f79959@6g2000vbv.googlegroups.com> On Jun 20, 11:22?am, Christian Heimes wrote: > Am 18.06.2012 20:45, schrieb Terry Reedy: > > > The simultaneous reintroduction of 'ur', but with a different meaning > > than in 2.7, *was* a problem and it should be removed in the next release. > > FYI:http://hg.python.org/cpython/rev/8e47e9af826e > > Christian I saw this, not the latest version. Anyway, thanks for the info. jmf From info at egenix.com Wed Jun 20 09:09:57 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 20 Jun 2012 15:09:57 +0200 Subject: ANN: Python Meeting =?ISO-8859-1?Q?D=FCsseldorf_-_17=2E07=2E?= =?ISO-8859-1?Q?2012?= Message-ID: <4FE1CBA5.3020200@egenix.com> [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG Python Meeting D?sseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Dienstag, 17.07.2012, 18:00 Uhr Clara Schumann Raum DJH D?sseldorf Diese Nachricht k?nnen Sie auch online lesen: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2012-07-17 ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf (http://pyddf.de/) ist eine neue lokale Veranstaltung in D?sseldorf, die sich an Python Begeisterte in der Region wendet. Wir starten bei den Treffen mit einer kurzen Einleitung und gehen dann zu einer Reihe Kurzvortr?gen (Lightning Talks) ?ber, bei denen die Anwesenden ?ber neue Projekte, interessante Probleme und sonstige Aktivit?ten rund um Python berichten k?nnen. Anschlie?end geht es in eine Gastst?tte, um die Gespr?che zu vertiefen. Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ________________________________________________________________________ ORT F?r das Python Meeting D?sseldorf haben wir den Clara Schumann Raum in der modernen Jugendherberge D?sseldorf angemietet: Jugendherberge D?sseldorf D?sseldorfer Str. 1 40545 D?sseldorf Telefon: +49 211 557310 http://www.duesseldorf.jugendherberge.de Die Jugendherberge verf?gt ?ber eine kostenpflichtige Tiefgarage (EUR 2,50 pro Stunde, maximal EUR 10,00). Es ist aber auch m?glich per Bus und Bahn anzureisen. Der Raum befindet sich im 1.OG links. ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus Open Space und Lightning Talks: Die Treffen starten mit einer kurzen Einleitung. Danach geht es weiter mit einer Lightning Talk Session, in der die Anwesenden Kurzvortr?ge von f?nf Minuten halten k?nnen. Hieraus ergeben sich dann meisten viele Ansatzpunkte f?r Diskussionen, die dann den Rest der verf?gbaren Zeit in Anspruch nehmen k?nnen. F?r 19:45 Uhr haben wir in einem nahegelegenen Restaurant Pl?tze reserviert, damit auch das leibliche Wohl nicht zu kurz kommt. Lightning Talks k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. Folien bitte als PDF auf USB Stick mitbringen. Lightning Talk Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ KOSTENBETEILIGUNG Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Da Tagungsraum, Beamer, Internet und Getr?nke Kosten produzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ________________________________________________________________________ ANMELDUNG Da wir nur f?r ca. 20 Personen Sitzpl?tze haben, m?chten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jun 20 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-07-17: Python Meeting Duesseldorf ... 27 days to go 2012-07-02: EuroPython 2012, Florence, Italy ... 12 days to go ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From mining.facts at googlemail.com Wed Jun 20 09:30:10 2012 From: mining.facts at googlemail.com (Christian) Date: Wed, 20 Jun 2012 06:30:10 -0700 (PDT) Subject: re.finditer with lookahead and lookbehind Message-ID: <889c09ab-d797-4bfc-a6cb-a692b3d81cf5@l5g2000vbo.googlegroups.com> Hi, i have some trouble to split a pattern like s. Even have this problems with the first and last match. Some greedy problems? Thanks in advance Christian import re s='v1=pattern1&v2=pattern2&v3=pattern3&v4=pattern4&v5=pattern5&x1=patternx' pattern =r'(?=[a-z0-9]+=)(.*?)(?<=&)' regex = re.compile(pattern,re.IGNORECASE) for match in regex.finditer(s): print match.group(1) My intention: pattern1 pattern2 pattern3 pattern4 pattern5 patternx From python at mrabarnett.plus.com Wed Jun 20 11:06:11 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 20 Jun 2012 16:06:11 +0100 Subject: re.finditer with lookahead and lookbehind In-Reply-To: <889c09ab-d797-4bfc-a6cb-a692b3d81cf5@l5g2000vbo.googlegroups.com> References: <889c09ab-d797-4bfc-a6cb-a692b3d81cf5@l5g2000vbo.googlegroups.com> Message-ID: <4FE1E6E3.4050708@mrabarnett.plus.com> On 20/06/2012 14:30, Christian wrote: > Hi, > > i have some trouble to split a pattern like s. Even have this > problems with the first and last match. Some greedy problems? > > Thanks in advance > Christian > > import re > > s='v1=pattern1&v2=pattern2&v3=pattern3&v4=pattern4&v5=pattern5&x1=patternx' > pattern =r'(?=[a-z0-9]+=)(.*?)(?<=&)' > regex = re.compile(pattern,re.IGNORECASE) > for match in regex.finditer(s): > print match.group(1) > > My intention: > pattern1 > pattern2 > pattern3 > pattern4 > pattern5 > patternx > You could do it like this: import re s = 'v1=pattern1&v2=pattern2&v3=pattern3&v4=pattern4&v5=pattern5&x1=patternx' pattern = r'=([^&]*)' regex = re.compile(pattern, re.IGNORECASE) for match in regex.finditer(s): print match.group(1) or avoid regex entirely: >>> values = [p.partition("=")[2] for p in s.split("&")] >>> values ['pattern1', 'pattern2', 'pattern3', 'pattern4', 'pattern5', 'patternx'] From rosuav at gmail.com Wed Jun 20 11:24:50 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Jun 2012 01:24:50 +1000 Subject: Is that safe to use ramdom.random() for key to encrypt? In-Reply-To: References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> Message-ID: On Thu, Jun 21, 2012 at 1:18 AM, wrote: > On 2012-06-17, Jon Clements wrote: >> I generally find a separate partition with an encrypted file-system >> (which is fairly straight forward on *nix systems or I think there's a >> product out there that works with Windows), is a lot easier and puts the >> load on the filesystem/OS instead of having to be handled in your >> application is a lot simpler. > > That assumes he is doing storage rather than communication. Well, for communication it's even easier. Pick up an SSL or SSH library and channel everything through that! Added bonus of SSL/TLS is that, with many languages/libraries, you can write all your code with a simple unencrypted session and test it with telnet, and then "turn on" encryption without changing any of your code outside of your initialization. Whatever platform you're targeting, there's a better option than writing your own encryption. Guaranteed. Even if it means writing glue code to interface to a C library. ChrisA From darcy at druid.net Wed Jun 20 11:25:06 2012 From: darcy at druid.net (D'Arcy Cain) Date: Wed, 20 Jun 2012 11:25:06 -0400 Subject: Is that safe to use ramdom.random() for key to encrypt? In-Reply-To: References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> Message-ID: <4FE1EB52.7020702@druid.net> On 12-06-20 11:18 AM, elvis-85496 at notatla.org.uk wrote: > On 2012-06-17, Jon Clements wrote: > >> Whatever you do - *do not* attempt to write your own algorithm. > > very true As "they" say, random number generation is too important to be left to chance. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net From lists at cheimes.de Wed Jun 20 11:58:48 2012 From: lists at cheimes.de (Christian Heimes) Date: Wed, 20 Jun 2012 17:58:48 +0200 Subject: Is that safe to use ramdom.random() for key to encrypt? In-Reply-To: <4FE1EB52.7020702@druid.net> References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> <4FE1EB52.7020702@druid.net> Message-ID: Am 20.06.2012 17:25, schrieb D'Arcy Cain: > As "they" say, random number generation is too important to be left > to chance. :-) Hilarious! You made my day! :) From anthra.norell at bluewin.ch Wed Jun 20 13:07:04 2012 From: anthra.norell at bluewin.ch (Frederic Rentsch) Date: Wed, 20 Jun 2012 19:07:04 +0200 Subject: Tkinter binding question In-Reply-To: <38e7661b-23ee-4cda-ac80-e189a017e3e9@googlegroups.com> References: <7f22c54e-2cd1-4a7f-a9f6-a33b8f17eb23@googlegroups.com> <38e7661b-23ee-4cda-ac80-e189a017e3e9@googlegroups.com> Message-ID: <1340212024.13812.62.camel@hatchbox-one> On Tue, 2012-06-19 at 19:19 -0700, rantingrickjohnson at gmail.com wrote: > On Tuesday, June 19, 2012 10:55:48 AM UTC-5, Frederic Rentsch wrote: > > If I copy your event descriptors into my program, the button-release > > callback still fails. It works in your code, not in mine. Here is what > > my code now looks like. It is somewhat more complicated than yours, > > because I bind Frames holding each a line (line_frame) and each frame > > contains a few Labels side by side. The idea is to achieve a table with > > vertically aligning columns each line of which I can click-select. (Is > > there a better way?) > > > > for line_frame in ...: > > line_frame.bind ('', self.color_selected) > > line_frame.bind ('', self.color_selectable) > > line_frame.bind ('', self.pick_record) > > line_frame.bind ('', self.info_profile) > > line_frame.grid (row = n+1, column = 0) > > for i in self.range_n_fields: > > field = Label (line_frame, width = ..., text = ... > > field.grid (row = 0, column = i, sticky = W) > > ... > > > > def color_selected (self, event): > > print 'hit list.color_selected ()' > > > > def color_selectable (self, event): > > print 'hit list.color_selectable ()' > > > > def pick_record (self, event): # Nver gets called > > print 'hit list.pick_record ()' > > > > def info_profile (self, event): # Never gets called > > print 'hit list.info_profile ()' > > Events only fire for the widget that currently has "focus". Frames, labels, and other widgets do not receive focus simply by hovering over them. You can set the focus manually by calling "w.focus_set()" -- where "w" is any Tkinter widget. I can't be sure because i don't have enough of your code to analyze, but I think you should bind (either globally or by class type) all "Enter" events to a callback that sets the focus of the current widget under the mouse. Experiment with this code and see if it is what you need: > > ## START CODE ## > from __future__ import print_function > import Tkinter as tk > > def cb(event): > print(event.widget.winfo_class()) > event.widget.focus_set() > > root = tk.Tk() > root.geometry('200x200+20+20') > for x in range(10): > w = tk.Frame(root, width=20, height=20,bg='red') > w.grid(row=x, column=0, padx=5, pady=5) > w = tk.Frame(root, width=20, height=20,bg='green', highlightthickness=1) > w.grid(row=x, column=1, padx=5, pady=5) > w = tk.Button(root, text=str(x)) > w.grid(row=x, column=2, padx=5, pady=5) > root.bind_all("", cb) > root.mainloop() > ## END CODE ## > > You will see that the first column of frames are recieving focus but you have no visual cues of that focus (due to a default setting). In the second column you get the visual cue since i set "highlightthicness=1". The third column is a button widget which by default has visual focus cues. > > Is this the problem? Yes, I was unaware of focus control. I understand that it is set either by a left mouse button click or the method focus_set (). > PS: Also check out the "w.bind_class()" method. > > > Incidentally, my source of inspiration for chaining event descriptors > > was the New Mexico Tech Tkinter 8.4 reference, > > That's an excellent reference BTW. Keep it under your pillow. Effbot also has a great tutorial. Thanks for this additional load af advice. Googling I chanced on an excellent introduction "Thinking in Tkinter" by Stephen Ferg. (http://www.ferg.org/thinking_in_tkinter/all_programs.html). He sets out identifying a common problem with tutorials: The problem is that the authors of the books want to rush into telling me about all of the widgets in the Tkinter toolbox, but never really pause to explain basic concepts. They don't explain how to "think in Tkinter". He then explains seventeen functionalities, one at a time, and illustrates them with a little piece of code ready to run. Working through the examples is a good way to acquire a basic understanding without falling victim to "brain clutter". I shall go through the examples very attentively and go on from there. Thanks again Frederic From david.garvey at gmail.com Wed Jun 20 14:17:52 2012 From: david.garvey at gmail.com (david.garvey at gmail.com) Date: Wed, 20 Jun 2012 11:17:52 -0700 Subject: fastest method Message-ID: I am looking for the fastest way to parse a log file. currently I have this... Can I speed this up any? The script is written to be a generic log file parser so I can't rely on some predictable pattern. def check_data(data,keywords): #get rid of duplicates unique_list = list(set(data)) string_list=' '.join(unique_list) #print string_list for keyword in keywords: if keyword in string_list: return True I am currently using file seek and maintaining a last byte count file: with open(filename) as f: print "Here is filename:%s" %filename f.seek(0, 2) eof = f.tell() print "Here is eof:%s" %eof if last is not None: print "Here is last:%s" %last # if last is less than current last = int(last) if (eof - last > 0): offset = eof - last offset = offset * -1 print "Here is new offset:%s" %offset f.seek(offset, 2) mylist = f.readlines() else: # if last doesn't exist or is greater than current f.seek(0) bof = f.tell() print "Here is bof:%s" %bof mylist = f.readlines() Thanks, -- David Garvey -------------- next part -------------- An HTML attachment was scrubbed... URL: From sverreodegard at gmail.com Wed Jun 20 14:24:02 2012 From: sverreodegard at gmail.com (Sverre) Date: Wed, 20 Jun 2012 11:24:02 -0700 (PDT) Subject: DirectX Screenshot with python possible? Message-ID: <060887b2-3e7d-4e3c-84bf-5bc387e29a81@googlegroups.com> I'm in need for a function that is able to make a screenshot from a directx full screen. PIL is only able to take a snapshot from the desktop, but not from any directx screen. Has someone a tip for an existing module? From Tom.KACVINSKY at 3ds.com Wed Jun 20 14:24:55 2012 From: Tom.KACVINSKY at 3ds.com (KACVINSKY Tom) Date: Wed, 20 Jun 2012 18:24:55 +0000 Subject: Custom build of Python Message-ID: I had reason to build Python 2.6.8 with Microsoft Visual Studio 2010. I was able to get the pcbuild solution to build, and I have the necessary exes/dlls/pyds in the amd64 build directory. What is not clear to is how to complete the build and make an installation. I could not find any documentation for this. Any help on this matter would be appreciated. Thanks, Tom This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. For other languages, go to http://www.3ds.com/terms/email-disclaimer -------------- next part -------------- An HTML attachment was scrubbed... URL: From david.garvey at gmail.com Wed Jun 20 14:26:30 2012 From: david.garvey at gmail.com (david.garvey at gmail.com) Date: Wed, 20 Jun 2012 11:26:30 -0700 Subject: fastest method In-Reply-To: References: Message-ID: I see one issue;) # if last doesn't exist or is greater than current This else doesn't catch the last greater than current: This is a little messy. with open(filename) as f: print "Here is filename:%s" %filename f.seek(0, 2) eof = f.tell() print "Here is eof:%s" %eof if last is not None: print "Here is last:%s" %last # if last is less than current last = int(last) if (eof - last > 0): offset = eof - last offset = offset * -1 print "Here is new offset:%s" %offset f.seek(offset, 2) mylist = f.readlines() else: f.seek(0) bof = f.tell() print "Here is bof:%s" %bof mylist = f.readlines() else: f.seek(0) bof = f.tell() print "Here is bof:%s" %bof mylist = f.readlines() On Wed, Jun 20, 2012 at 11:17 AM, david.garvey at gmail.com < david.garvey at gmail.com> wrote: > I am looking for the fastest way to parse a log file. > > > currently I have this... Can I speed this up any? The script is written to > be a generic log file parser so I can't rely on some predictable pattern. > > > def check_data(data,keywords): > #get rid of duplicates > unique_list = list(set(data)) > string_list=' '.join(unique_list) > #print string_list > for keyword in keywords: > if keyword in string_list: > return True > > > I am currently using file seek and maintaining a last byte count file: > > with open(filename) as f: > print "Here is filename:%s" %filename > f.seek(0, 2) > eof = f.tell() > print "Here is eof:%s" %eof > if last is not None: > print "Here is last:%s" %last > # if last is less than current > last = int(last) > if (eof - last > 0): > offset = eof - last > offset = offset * -1 > print "Here is new offset:%s" %offset > f.seek(offset, 2) > mylist = f.readlines() > else: > # if last doesn't exist or is greater than current > f.seek(0) > bof = f.tell() > print "Here is bof:%s" %bof > mylist = f.readlines() > > > > Thanks, > -- > David Garvey > -- David Garvey -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Wed Jun 20 14:32:42 2012 From: roy at panix.com (Roy Smith) Date: 20 Jun 2012 14:32:42 -0400 Subject: Is that safe to use ramdom.random() for key to encrypt? References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> Message-ID: In article , Chris Angelico wrote: > Well, for communication it's even easier. Pick up an SSL or SSH > library and channel everything through that! +1 on this. Actually, plus a whole bunch more than 1. I worked on a project which had rolled their own communication layer (including encryption). The decisions were made (long) before I got there, and may well have made sense at the time, but in the end it was a mess. I can't count how many person-years went into fixing hard-to-replicate bugs, not to mention lots of customer ill will when things broke at their sites The upside is I learned a lot about crypto that I probably would have never learned otherwise. That's cool and fun, but not a good justification for putting it in your product. > Added bonus of SSL/TLS is that, with many languages/libraries, you > can write all your code with a simple unencrypted session and test > it with telnet, and then "turn on" encryption without changing any > of your code outside of your initialization. Yup, this is a big win. There's another consideration. At some point, some large customer (or potential customer) may require that all your crypto be FIPS (or whatever national authority) certified. If you're using some standard crypto library, it's a lot easier to drop in a certified replacement than if you've rolled your own. > Whatever platform you're targeting, there's a better option than > writing your own encryption. Guaranteed. Even if it means writing glue > code to interface to a C library. What he said. From paul.nospam at rudin.co.uk Wed Jun 20 15:46:27 2012 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 20 Jun 2012 20:46:27 +0100 Subject: Is that safe to use ramdom.random() for key to encrypt? References: <2170dd93-e659-4031-aab3-280a6edaf563@f9g2000pbd.googlegroups.com> Message-ID: <87a9zx9370.fsf@no-fixed-abode.cable.virginmedia.net> elvis-85496 at notatla.org.uk writes: > On 2012-06-17, Jon Clements wrote: > >> Whatever you do - *do not* attempt to write your own algorithm. > > very true If everyone took that advice then we'd have a problem.... From steve+comp.lang.python at pearwood.info Wed Jun 20 15:51:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Jun 2012 19:51:09 GMT Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <4fe10972$0$29980$c3e8da3$5496439d@news.astraweb.com> <3d725d3a-3159-4732-b5ae-17feedcf045d@k5g2000vbf.googlegroups.com> Message-ID: <4fe229ad$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Jun 2012 01:12:00 -0700, jmfauth wrote: > Python 3.3.0a4 (v3.3.0a4:7c51388a3aa7+, May 31 2012, 20:15:21) [MSC v. > 1600 > 32 bit (Intel)] on win32 >>>> --- > running smidzero.py... > ...smidzero has been executed What is "smidzero.py", and what is it doing? >>>> --- > input(':') > :?l?phant > '?l?phant' Why are your input lines preceded by three dashes? >>>> --- > input(':') > :u'?l?phant' > '?l?phant' >>>> --- > input(':') > :u'\u00e9l\xe9phant' > '?l?phant' I cannot reproduce that behaviour. When I try it, I get the expected result: >>> input(': ') : u'\u00e9l\xe9phant' "u'\\u00e9l\\xe9phant'" I expect that the mysterious smidzero.py is monkey-patching the input builtin to do something silly. If that is the case, you are making a rod for your own back. -- Steven From holger at merlinux.eu Wed Jun 20 16:08:09 2012 From: holger at merlinux.eu (holger krekel) Date: Wed, 20 Jun 2012 20:08:09 +0000 Subject: execnet-1.1: cross-interpreter distributed execution library Message-ID: <20120620200809.GK11942@merlinux.eu> execnet-1.1 is a backward compatible beta release of the popular (>53000 pypi downloads of 1.0.9) cross-interpreter execution library. If you are in need of connecting Python2 and Python3 and/or want to throw PyPy in your deployment mix, then you might want to join Quora and many others and try out execnet. execnet provides a share-nothing model with channel-send/receive communication and distributed execution across many Python interpreters across version, platform and network barriers. See below for changes and see here for extensive documentation and tested examples: http://codespeak.net/execnet Particular thanks to Ronny Pfannschmidt for a lot of internal cleanups and to Alex Gaynor for providing feature patches. Have fun, holger 1.1 (compared to 1.0.9) -------------------------------- - introduce execnet.dumps/loads providing serialization between python interpreters, see http://codespeak.net/execnet/basics.html#dumps-loads - group.remote_exec now supports kwargs as well - support per channel string coercion configuration, helping with dealing with mixed Python2/Python3 environments. - Popen2IO.read now reads correct amounts of bytes from nonblocking fd's - added a ``dont_write_bytecode`` option to Popen gateways, this sets the ``sys.dont_write_bytecode`` flag on the spawned process, this only works on CPython 2.6 and higher. Thanks to Alex Gaynor. - added a pytest --broken-isp option to skip tests that assume DNS queries for unknown hosts actually are resolved as such (Thanks Alex Gaynor) - fix issue 1 - decouple string coercion of channels and gateway - fix issue #2 - properly reconfigure the channels string coercion for rsync, so it can send from python2 to python3 - refactor socketserver, so it can be directly remote_exec'd for starting a socket gateway on a remote From tjreedy at udel.edu Wed Jun 20 16:12:32 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 20 Jun 2012 16:12:32 -0400 Subject: Custom build of Python In-Reply-To: References: Message-ID: On 6/20/2012 2:24 PM, KACVINSKY Tom wrote: > I had reason to build Python 2.6.8 with Microsoft Visual Studio 2010. I > was able to get the pcbuild solution to build, and I have the necessary > exes/dlls/pyds in the amd64 build directory. What is not clear to is > how to complete the build and make an installation. I could not find > any documentation for this. If you mean 'make a .msi file', I am not sure that is not officially supported beyond the inclusion of msilib. > Any help on this matter would be appreciated. 3.3 is now being built with VS2010. Perhaps its repository has something that will help you. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jun 20 16:15:12 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 20 Jun 2012 16:15:12 -0400 Subject: DirectX Screenshot with python possible? In-Reply-To: <060887b2-3e7d-4e3c-84bf-5bc387e29a81@googlegroups.com> References: <060887b2-3e7d-4e3c-84bf-5bc387e29a81@googlegroups.com> Message-ID: On 6/20/2012 2:24 PM, Sverre wrote: > I'm in need for a function that is able to make a screenshot from a directx full screen. PIL is only able to take a snapshot from the desktop, but not from any directx screen. > > Has someone a tip for an existing module? Perhaps pygame has (or wraps) such a function. If not, someone on the pygame list must know how. (I am assuming that sdl library and hence pygame use directx.) -- Terry Jan Reedy From Tom.KACVINSKY at 3ds.com Wed Jun 20 16:29:00 2012 From: Tom.KACVINSKY at 3ds.com (KACVINSKY Tom) Date: Wed, 20 Jun 2012 20:29:00 +0000 Subject: Custom build of Python In-Reply-To: References: Message-ID: Terry, At this stage, I don't want or need an MSI. I just want something that will bundle the executables/dynamic load libraries + compiled Python files and stick them into a compliant directory structure. Regards, Tom -----Original Message----- From: python-list-bounces+tky=3ds.com at python.org [mailto:python-list-bounces+tky=3ds.com at python.org] On Behalf Of Terry Reedy Sent: Wednesday, June 20, 2012 4:13 PM To: python-list at python.org Subject: Re: Custom build of Python On 6/20/2012 2:24 PM, KACVINSKY Tom wrote: > I had reason to build Python 2.6.8 with Microsoft Visual Studio 2010. > I was able to get the pcbuild solution to build, and I have the > necessary exes/dlls/pyds in the amd64 build directory. What is not > clear to is how to complete the build and make an installation. I > could not find any documentation for this. If you mean 'make a .msi file', I am not sure that is not officially supported beyond the inclusion of msilib. > Any help on this matter would be appreciated. 3.3 is now being built with VS2010. Perhaps its repository has something that will help you. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. For other languages, go to http://www.3ds.com/terms/email-disclaimer From ian.g.kelly at gmail.com Wed Jun 20 16:46:15 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 20 Jun 2012 14:46:15 -0600 Subject: Py3.3 unicode literal and input() In-Reply-To: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> Message-ID: On Jun 18, 2012 8:07 AM, "jmfauth" wrote: > A string is a string, a "piece of text", period. > > I do not see why a unicode literal and an (well, I do not > know how the call it) a "normal class " should behave > differently in code source or as an answer to an input(). Strings are a data type that contains characters. String literals are *not* strings. They are a code syntax that is used to create actual string objects. Remember: strings are data, string literals are code. input() does not accept string literals because it is a runtime feature that reads data, not code. It does not parse unicode literals or bytes literals or "normal" string literals or integer literals or tuple literals or any other kind of literal. All that it reads is plain, uninterpreted string data. If you want to do any processing of that data, you need to specify it yourself. -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Wed Jun 20 18:14:27 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 20 Jun 2012 23:14:27 +0100 Subject: xlrd 0.7.9 released! Message-ID: <4FE24B43.8000009@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlrd 0.7.9: http://pypi.python.org/pypi/xlrd/0.7.9 This release fixes an annoying merge bug on my part that resulted in a "NameError: global name 'BYTES_X00' is not defined" error where opening certain Excel files. Barring any more brown bag issues, this will be the last release in the 0.7 series and the last release supporting Python 2.1 and 2.2. The next release, in a week or so if there are no further 0.7 problems, will be 0.8.0 targeting Python 2.6 and upwards and featuring support for reading data from .xlsx files (although not formatting, unless some sponsorship or patches turn up). If you're interested in this, it would be great if you could try out the master branch and let us know if you find any problems: https://github.com/python-excel/xlrd There's also details of all things Python and Excel related here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From gmspro at yahoo.com Wed Jun 20 19:30:36 2012 From: gmspro at yahoo.com (gmspro) Date: Wed, 20 Jun 2012 16:30:36 -0700 (PDT) Subject: Is python a interpreted or compiled language? Message-ID: <1340235036.44557.YahooMailClassic@web164605.mail.gq1.yahoo.com> Hi, Is python a interpreted or compiled language? What does happen after this command: python f.py I knew python makes file.pyc file to store the bytecode. For java , .class file is the bytecode file, someone can run that file from any machine. So is the .pyc file executale like java? Can anyone please explain/elaborate the process/order of executing python file with example? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Jun 20 20:26:41 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Jun 2012 00:26:41 GMT Subject: Jython and PYTHONSTARTUP Message-ID: <4fe26a41$0$29980$c3e8da3$5496439d@news.astraweb.com> Does Jython 2.5 honour the PYTHONSTARTUP environment variable? According to my testing, it doesn't. There used to be a page describing the differences between Jython and CPython here: http://www.jython.org/docs/differences.html but it appears to have been eaten by the 404 Monster. -- Steven From ian.g.kelly at gmail.com Wed Jun 20 20:27:53 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 20 Jun 2012 18:27:53 -0600 Subject: Is python a interpreted or compiled language? In-Reply-To: <1340235036.44557.YahooMailClassic@web164605.mail.gq1.yahoo.com> References: <1340235036.44557.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: On Wed, Jun 20, 2012 at 5:30 PM, gmspro wrote: > > Hi, > > Is python a interpreted or compiled language? Like other languages that use a VM bytecode, it's a little bit of both. The actual Python code is compiled into Python bytecode. The bytecode is interpreted. > What does happen after this command: python f.py > > I knew python makes file.pyc file to store the bytecode. For java , .class > file is the bytecode file, someone can run that file from any machine. So is > the .pyc file executale like java? Yes, Python is (mostly) able to run the .pyc file directly without the .py source (although tracebacks will be a bit less informative if the .py is not available). I say "mostly" because, while the bytecode is cross-platform, it is version dependent. A Python 3.x installation may or may not be able to run a bytecode compiled by Python 3.y. > Can anyone please explain/elaborate the process/order of executing python > file with example? Whenever a Python module is imported, the interpreter first checks whether a .pyc is available that has the appropriate "magic number" and is up-to-date (based on its timestamp compared to the corresponding .py file). If it can't find or can't use the .pyc file, then it recompiles the .py file into a .pyc file. Otherwise, it skips the compilation step and just runs the bytecode from the .pyc file. Note though that when a .py file is executed directly (not imported), it does not look for or generate a .pyc file; it just compiles the .py unconditionally in memory and runs the bytecode. If you're interested in the bytecode, you can use the dis module to disassemble functions and other code objects and examine it: >>> import dis >>> def f(x): ... return x + 1 ... >>> dis.dis(f) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (1) 6 BINARY_ADD 7 RETURN_VALUE Cheers, Ian From d at davea.name Wed Jun 20 20:53:33 2012 From: d at davea.name (Dave Angel) Date: Wed, 20 Jun 2012 20:53:33 -0400 Subject: Is python a interpreted or compiled language? In-Reply-To: <1340235036.44557.YahooMailClassic@web164605.mail.gq1.yahoo.com> References: <1340235036.44557.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: <4FE2708D.1030208@davea.name> On 06/20/2012 07:30 PM, gmspro wrote: > Hi, > > Is python a interpreted or compiled language? > What does happen after this command: python f.py > > I knew python makes file.pyc file to store the bytecode. For java , .class file is the bytecode file, someone can run that file from any machine. So is the .pyc file executale like java? > > Can anyone please explain/elaborate the process/order of executing python file with example? > > Thanks. > Ian has given you a good answer. But since you mention java, I'd like to point out a few things that are different between the two environments. He and I are describing CPython; jython and other implementations don't use .pyc files, and they behave differently. java has available a "runtime" environment, for those who don't want or need the compiler. CPython comes with the compiler and the runtime bundled together. Java's classfile remains stable over a number of compiler versions, while CPython doesn't seem to worry about that. Java's classfile has been targeted by a number of other byte code compilers, including jython. Code from any of those libraries may use the java libraries. With java, one has to explicitly compile the java code, while with CPython, the runtime logic compiles imported modules if they're not already compiled. -- DaveA From rantingrickjohnson at gmail.com Wed Jun 20 21:20:52 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Wed, 20 Jun 2012 18:20:52 -0700 (PDT) Subject: Tkinter binding question In-Reply-To: References: <7f22c54e-2cd1-4a7f-a9f6-a33b8f17eb23@googlegroups.com> <38e7661b-23ee-4cda-ac80-e189a017e3e9@googlegroups.com> Message-ID: <1ae365dc-a78e-4ebe-aec5-eea67dfbac16@googlegroups.com> On Wednesday, June 20, 2012 12:07:04 PM UTC-5, Frederic Rentsch wrote: > [...] > Googling I chanced on an excellent introduction "Thinking in > Tkinter" [...] He sets out identifying a common problem with > tutorials: The problem is that the authors of the books want to rush > into telling me about all of the widgets in the Tkinter toolbox, but > never really pause to explain basic concepts. They don't explain how > to "think in Tkinter". Well. I have not analyzed this tutorial myself but i can tell you one thing for sure; most of the confusion regarding Tkinter comes NOT from improperly written tutorials NO, it is a direct result of the poorly designed Tkinter API itself! ================================= Some of the main problems follow: ================================= *## 1. Failure to constrain event sequences:* Tkinter allows users to bind a virtual cornucopia of possible event sequences. Some say this is a good thing because it allows freedom, i say it is contributing to unreadable and unmaintainable code bases. There are literally thousands of possible combinations a user could bind. Sure, this "freedom" might make the user feel good, but i can guarantee his code will be a spaghetti mess! It is my firm belief, that only two Key Events and four Mouse Events should be allowed binding. Then, the callback should handle the dirty details -- which could include delegating details to one or many lower worker functions. In the real world you only need six possible events to process user input: * KeyPress(keyName) * KeyRelease(keyName) * MousePress(x, y, bNum) * MouseRelease(x, y, bNum) * MouseMotion(x, y, bNum) * MouseWheel(direction) Checking the state of modifiers like Control, Shift, or Alt should be handled via an event object. Actually, all events should be a subclass of an EventHandler object. *## Explicit parent/child relationships needs to be mandatory:* Tkinter allows users to be lazy and omit the parent of a widget to save a few keystrokes on tiny little throw away scripts. In the real world, and even in small GUI applications, you would never want to do such a thing. I believe this methodology does irreversible damage to a new users brain. He fails to see the app->subwin->widget hierarchy from day one. *## 2. Inconsistencies when constructing widgets:* Most widgets expect a "parent" argument as the first argument, but not the case for Dialogs and other classes which allow you to pass "parent=blah" as a kw option. Without a parent, a dialog can not set up a proper transient relationship OR position itself properly over the correct window. Allowing this slothful developer behavior contributes to many frustrating user experiences. *## 3. Inconsistencies between configuring widgets and configuring windows:* Windows don't have a config method for things like: "title", "size", "etc". Instead they have methods like win.title("Title") or win.geometry("wxh+x+y"); which again breaks the consistency that is so important in any API! Not to mention the unessesaryily cryptic nature of a few of these methods. *## 4. Failure to remove old tutorials from the web that are still teaching people to code Tkinter GUI's like it's 1991:* This is a sad result of a dead community. And the few people who are remaining have become so partisan that nothing can get accomplish except, well, nothing. Congratulations Guido, are you proud of what you have created? Or rather, or you proud of what this community had degenerated into? (BTW those are rhetorical questions.) I am still hoping beyond hope that some new blood will enter this community soon and inject some hope for the future. Guido is an old man. He has no passion anymore. I long for some new blood with a passion for consistency. People with the intuition required to create intuitive APIs. But most of all. People who have a "can do" community spirit. A boy can dream. From rantingrickjohnson at gmail.com Wed Jun 20 21:20:52 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Wed, 20 Jun 2012 18:20:52 -0700 (PDT) Subject: Tkinter binding question In-Reply-To: References: <7f22c54e-2cd1-4a7f-a9f6-a33b8f17eb23@googlegroups.com> <38e7661b-23ee-4cda-ac80-e189a017e3e9@googlegroups.com> Message-ID: <1ae365dc-a78e-4ebe-aec5-eea67dfbac16@googlegroups.com> On Wednesday, June 20, 2012 12:07:04 PM UTC-5, Frederic Rentsch wrote: > [...] > Googling I chanced on an excellent introduction "Thinking in > Tkinter" [...] He sets out identifying a common problem with > tutorials: The problem is that the authors of the books want to rush > into telling me about all of the widgets in the Tkinter toolbox, but > never really pause to explain basic concepts. They don't explain how > to "think in Tkinter". Well. I have not analyzed this tutorial myself but i can tell you one thing for sure; most of the confusion regarding Tkinter comes NOT from improperly written tutorials NO, it is a direct result of the poorly designed Tkinter API itself! ================================= Some of the main problems follow: ================================= *## 1. Failure to constrain event sequences:* Tkinter allows users to bind a virtual cornucopia of possible event sequences. Some say this is a good thing because it allows freedom, i say it is contributing to unreadable and unmaintainable code bases. There are literally thousands of possible combinations a user could bind. Sure, this "freedom" might make the user feel good, but i can guarantee his code will be a spaghetti mess! It is my firm belief, that only two Key Events and four Mouse Events should be allowed binding. Then, the callback should handle the dirty details -- which could include delegating details to one or many lower worker functions. In the real world you only need six possible events to process user input: * KeyPress(keyName) * KeyRelease(keyName) * MousePress(x, y, bNum) * MouseRelease(x, y, bNum) * MouseMotion(x, y, bNum) * MouseWheel(direction) Checking the state of modifiers like Control, Shift, or Alt should be handled via an event object. Actually, all events should be a subclass of an EventHandler object. *## Explicit parent/child relationships needs to be mandatory:* Tkinter allows users to be lazy and omit the parent of a widget to save a few keystrokes on tiny little throw away scripts. In the real world, and even in small GUI applications, you would never want to do such a thing. I believe this methodology does irreversible damage to a new users brain. He fails to see the app->subwin->widget hierarchy from day one. *## 2. Inconsistencies when constructing widgets:* Most widgets expect a "parent" argument as the first argument, but not the case for Dialogs and other classes which allow you to pass "parent=blah" as a kw option. Without a parent, a dialog can not set up a proper transient relationship OR position itself properly over the correct window. Allowing this slothful developer behavior contributes to many frustrating user experiences. *## 3. Inconsistencies between configuring widgets and configuring windows:* Windows don't have a config method for things like: "title", "size", "etc". Instead they have methods like win.title("Title") or win.geometry("wxh+x+y"); which again breaks the consistency that is so important in any API! Not to mention the unessesaryily cryptic nature of a few of these methods. *## 4. Failure to remove old tutorials from the web that are still teaching people to code Tkinter GUI's like it's 1991:* This is a sad result of a dead community. And the few people who are remaining have become so partisan that nothing can get accomplish except, well, nothing. Congratulations Guido, are you proud of what you have created? Or rather, or you proud of what this community had degenerated into? (BTW those are rhetorical questions.) I am still hoping beyond hope that some new blood will enter this community soon and inject some hope for the future. Guido is an old man. He has no passion anymore. I long for some new blood with a passion for consistency. People with the intuition required to create intuitive APIs. But most of all. People who have a "can do" community spirit. A boy can dream. From rosuav at gmail.com Wed Jun 20 21:27:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Jun 2012 11:27:02 +1000 Subject: Is python a interpreted or compiled language? In-Reply-To: <4FE2708D.1030208@davea.name> References: <1340235036.44557.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4FE2708D.1030208@davea.name> Message-ID: On Thu, Jun 21, 2012 at 10:53 AM, Dave Angel wrote: > With java, one has to explicitly compile the java code, while with > CPython, the runtime logic compiles imported modules if they're not > already compiled. Putting it another way: Java's bytecode and source code are two distinct languages, both well documented and separately usable (and with their own distinct limitations - there are things you can do in Java bytecode that you cannot do in Java source). With CPython, the bytecode is an implementation detail and an optimization (once it's parsed your .py file once, a .pyc file can be saved to allow the interpreter to save some effort next time). ChrisA From steve+comp.lang.python at pearwood.info Wed Jun 20 21:48:34 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Jun 2012 01:48:34 GMT Subject: Is python a interpreted or compiled language? References: <1340235036.44557.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: <4fe27d71$0$29980$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Jun 2012 18:27:53 -0600, Ian Kelly wrote: > On Wed, Jun 20, 2012 at 5:30 PM, gmspro wrote: >> >> Hi, >> >> Is python a interpreted or compiled language? > > Like other languages that use a VM bytecode, it's a little bit of both. > The actual Python code is compiled into Python bytecode. The bytecode > is interpreted. I should point out that the difference between interpreted and compiled is fairly arbitrary and less useful these days. The model for programming languages used to be: Interpreters go over the source code, line by line, executing each line as it is read. If you loop over a line twice, it gets read twice, interpreted twice, and executed twice. Compilers go over the source code once, line by line, interpreting the code once, building machine code which can be directly executed by the hardware. Even back in the 1970s this simple picture was not quite right: it hides a lot of detail. Many "compiled" languages would compile to assembly language for a virtual machine, rather than direct to hardware specific machine code. For example, some Pascal compilers would compile code for a virtual p-machine. Languages like Forth can switch from "compile" mode to "interpret" mode from one command to the next. And of course, machine code itself is interpreted by the hardware, and there are many ways of setting up the machine code (e.g. direct vs indirect threaded code) which may be faster or slower at the expense of more or less memory. So the distinction between compiled and interpreted has always been a bit fuzzy. These days it is a lot fuzzy. Any "compiled" language that includes an eval or exec function must include an interpreter; nearly all interpreters compile code to byte code, and the few that don't usually build a parse tree instead. And then there are Just In Time compilers, which compile to machine code instructions at runtime, giving the flexibility of interpreters with the speed of compilers. An interpreter with a clever enough JIT can be faster than a static compiler, which leads to cases where Python can be faster than C: http://morepypy.blogspot.com.au/2011/02/pypy-faster-than-c-on-carefully-crafted.html http://morepypy.blogspot.com.au/2011/08/pypy-is-faster-than-c-again-string.html -- Steven From driscoll at cs.wisc.edu Wed Jun 20 23:02:34 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Wed, 20 Jun 2012 22:02:34 -0500 Subject: Is python a interpreted or compiled language? In-Reply-To: <4FE2708D.1030208@davea.name> References: <1340235036.44557.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4FE2708D.1030208@davea.name> Message-ID: <4FE28ECA.90809@cs.wisc.edu> On 6/20/2012 19:53, Dave Angel wrote: > But since you mention java, I'd like > to point out a few things that are different between the two > environments. He and I are describing CPython; jython and other > implementations don't use .pyc files, and they behave differently. There's one more important difference, which is that the JVM does just-in-time (JIT) compilation of bytecode rather than straight interpretation like CPython does. This basically means that as a program is executing, the JVM will sometimes go through what is a more traditional compilation step and translate its bytecode into machine code rather than just interpret it. It will do this for things it discovers are "hot paths" through the program, where spending some extra time up front (while the program is still executing!) for the compilation and optimization steps is worth it in terms of the speedup. In fact, the JVM may transform a given piece of bytecode several times, applying new optimizations as it discovers that some block is not just important, but *really* important. :-) (Where "important" = "executed a lot.") By my understanding, CPython doesn't do any of this; it always executes the same byte code in the same way, and what it does to the bytecode looks more like an interpreter than a JIT compiler. On the other hand, Jython translates Python to Java bytecode and IronPython translates Python to .Net bytecode (MSIL), so if you use one of those implementations of Python, you are getting a JIT. (Nevertheless my understanding is both tend to be slower than CPython? Not sure about that, and don't know by how much or why.) The new kid on the block is PyPy, which is a JIT engine for Python written in Python itself. But the interesting point is that the (very) old view of "compiled or interpreted" breaks down a lot nowadays; it's closer to a continuum: - pure interpreted - compiled to bytecode, which is then interpreted - JIT compiler (almost always this has a bytecode compilation step though theoretically this isn't necessary) - pure compiled I'd say these categories tend to be qualitative "I know it when I see it" rather than hard divisions. Evan > > java has available a "runtime" environment, for those who don't want or > need the compiler. CPython comes with the compiler and the runtime > bundled together. > > Java's classfile remains stable over a number of compiler versions, > while CPython doesn't seem to worry about that. > > Java's classfile has been targeted by a number of other byte code > compilers, including jython. Code from any of those libraries may use > the java libraries. > > With java, one has to explicitly compile the java code, while with > CPython, the runtime logic compiles imported modules if they're not > already compiled. > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 552 bytes Desc: OpenPGP digital signature URL: From ian.g.kelly at gmail.com Thu Jun 21 00:52:09 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 20 Jun 2012 22:52:09 -0600 Subject: Is python a interpreted or compiled language? In-Reply-To: References: <1340235036.44557.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4FE2708D.1030208@davea.name> Message-ID: On Wed, Jun 20, 2012 at 7:27 PM, Chris Angelico wrote: > Java's bytecode and source code are two distinct languages, both well > documented and separately usable (and with their own distinct > limitations - there are things you can do in Java bytecode that you > cannot do in Java source). I can think of at least one thing you can do in Python 2.x bytecode that you cannot do in Python 2.x source -- writing to nonlocal variables. From stefan_ml at behnel.de Thu Jun 21 00:55:09 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 21 Jun 2012 06:55:09 +0200 Subject: Is python a interpreted or compiled language? In-Reply-To: <4FE2708D.1030208@davea.name> References: <1340235036.44557.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4FE2708D.1030208@davea.name> Message-ID: Dave Angel, 21.06.2012 02:53: > On 06/20/2012 07:30 PM, gmspro wrote: >> Is python a interpreted or compiled language? > > Ian has given you a good answer. But since you mention java, I'd like > to point out a few things that are different between the two > environments. He and I are describing CPython; jython and other > implementations don't use .pyc files, and they behave differently. In other words: it's not the language that is interpreted or compiled, it's an implementation that interprets or compiles a language. It may do so in various degrees of interpretation and compilation, such as JIT compilation of otherwise interpreted code. Stefan From howmuchistoday at gmail.com Thu Jun 21 01:05:42 2012 From: howmuchistoday at gmail.com (Yesterday Paid) Date: Wed, 20 Jun 2012 22:05:42 -0700 (PDT) Subject: Can parellelized program run slower than single process program? Message-ID: <1f833962-2fbf-4397-9d79-cc45a63e370f@km7g2000pbc.googlegroups.com> from multiprocessing import Pool from itertools import product def sym(lst): x,y=lst tmp=x*y if rec(tmp): return tmp else: return None def rec(num): num=str(num) if num == "".join(reversed(num)): return True else: return False if __name__ == "__main__": pool=Pool(processes=8) lst=product(xrange(100,1000),repeat=2) rst=pool.map(sym,lst) #rst=sym(lst) print max(rst) in my old computer(2006), when run it on single process, it takes 2 seconds but using multiprocessing.pool, it takes almost 8 or 9 seconds is it possible? From aldrich.demata at gmail.com Thu Jun 21 01:54:59 2012 From: aldrich.demata at gmail.com (Aldrich DeMata) Date: Thu, 21 Jun 2012 00:54:59 -0500 Subject: Can parellelized program run slower than single process program? In-Reply-To: <1f833962-2fbf-4397-9d79-cc45a63e370f@km7g2000pbc.googlegroups.com> References: <1f833962-2fbf-4397-9d79-cc45a63e370f@km7g2000pbc.googlegroups.com> Message-ID: The multiprocessing module allows the programmer to fully leverage *multiple * processors on a given machine (python docs). This allows the operating system to take advantage of any parallelism inherent in the hardware design. If you are using the module on non-multiprocessor machines, I think you are not using it to its full capability, and the module's overhead will just slow down your code. Aldrich On Thu, Jun 21, 2012 at 12:05 AM, Yesterday Paid wrote: > from multiprocessing import Pool > from itertools import product > > def sym(lst): > x,y=lst > tmp=x*y > if rec(tmp): > return tmp > else: > return None > > def rec(num): > num=str(num) > if num == "".join(reversed(num)): return True > else: return False > > if __name__ == "__main__": > pool=Pool(processes=8) > lst=product(xrange(100,1000),repeat=2) > rst=pool.map(sym,lst) > #rst=sym(lst) > print max(rst) > > > in my old computer(2006), > when run it on single process, it takes 2 seconds > but using multiprocessing.pool, it takes almost 8 or 9 seconds > is it possible? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Thu Jun 21 01:58:29 2012 From: d at davea.name (Dave Angel) Date: Thu, 21 Jun 2012 01:58:29 -0400 Subject: Can parellelized program run slower than single process program? In-Reply-To: <1f833962-2fbf-4397-9d79-cc45a63e370f@km7g2000pbc.googlegroups.com> References: <1f833962-2fbf-4397-9d79-cc45a63e370f@km7g2000pbc.googlegroups.com> Message-ID: <4FE2B805.4040206@davea.name> On 06/21/2012 01:05 AM, Yesterday Paid wrote: > from multiprocessing import Pool > from itertools import product > > def sym(lst): > x,y=lst > tmp=x*y > if rec(tmp): > return tmp > else: > return None > > def rec(num): > num=str(num) > if num == "".join(reversed(num)): return True > else: return False Those last two lines could be replaced by simply return num == num[::-1] which should be much faster. I haven't checked that, however. > if __name__ == "__main__": > pool=Pool(processes=8) > lst=product(xrange(100,1000),repeat=2) > rst=pool.map(sym,lst) > #rst=sym(lst) > print max(rst) > > > in my old computer(2006), > when run it on single process, it takes 2 seconds > but using multiprocessing.pool, it takes almost 8 or 9 seconds > is it possible? Sure, it's possible. Neither multithreading nor multiprocessing will help a CPU-bound program if you don' t have multiple processors to run it on. All you have is the overhead of all the pickling and unpickling, to get data between processes, with no reduction in useful processing time. I suspect that in your case, the amount of work you're giving each process is small, compared to the work that the multiprocessing module is doing getting the processes to cooperate. Now, if you had a quad CPU (8 hyperthreads), and if the work that each process were doing were non-trivial, then i'd expect the balance to go in the other direction. Or if the operation involved I/O or other non-CPU-intensive work. -- DaveA From bastian.ballmann at notch-interactive.com Thu Jun 21 04:03:35 2012 From: bastian.ballmann at notch-interactive.com (Bastian Ballmann) Date: Thu, 21 Jun 2012 10:03:35 +0200 Subject: Introspect imports from module Message-ID: <20120621100335.1a61a28b@pulsar.notch-interactive.lan> Hi all, I am trying to write a function that returns a list of imports a given module is doing. The "problem" is I dont want to get the imports of the imports, but that's the case with my current solution. import __builtin__ old_import = __builtin__.__import__ def import_hook(name, globals=None, locals=None, fromlist=None): if fromlist: for symbol in fromlist: print name + "." + symbol else: print name return old_import(name, globals, locals, fromlist) __builtin__.__import__ = import_hook import module.to.inspect Any suggestions how I could just get the import of module.to.inspect? Thanks && have a nice day! Basti -- Bastian Ballmann / Web Developer Notch Interactive GmbH / Badenerstrasse 571 / 8048 Z?rich Phone Phone +41 44 297 17 17 / www.notch-interactive.com CHECK OUR LATEST WORK: http://www.notch-interactive.com/projekte/ From andrea.crotti.0 at gmail.com Thu Jun 21 06:50:31 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 21 Jun 2012 11:50:31 +0100 Subject: using SQLalchemy Message-ID: We have a very chaotic database (on MySql) at the moment, with for example table names used as keys to query other tables (but that's just an example). We are going to redesign it but first I still have to replace the perl+vbscript system with only one Python program, so I still have to deal with the current state. I'm trying to use SQLalchemy and it looks absolutely great, but in general as a policy we don't use external dependencies.. To try to do an exception in this case: - are there any problems with SQLalchemy on Windows? - are there any possibly drawbacks of using SQLalchemy instead of the MySqlDB interface? For the second point I guess that we might have a bit less fine tuning, but the amount of data is not so much and speed is also not a bit issue (also because all the queries are extremely inefficient now). Any other possible issue? Thanks, Andrea From lists at cheimes.de Thu Jun 21 07:00:36 2012 From: lists at cheimes.de (Christian Heimes) Date: Thu, 21 Jun 2012 13:00:36 +0200 Subject: Introspect imports from module In-Reply-To: <20120621100335.1a61a28b@pulsar.notch-interactive.lan> References: <20120621100335.1a61a28b@pulsar.notch-interactive.lan> Message-ID: Am 21.06.2012 10:03, schrieb Bastian Ballmann: > Any suggestions how I could just get the import of module.to.inspect? > Thanks && have a nice day! You could try a completely different approach and use the compiler package to inspect the abstract syntrax tree of a compiled module. The approach has the nice side effect that you don't have to import a module to inspect its imports. This script may serve as an example for you: http://svn.zope.org/Zope3/trunk/utilities/importchecker.py?rev=113742&view=auto Christian From research at johnohagan.com Thu Jun 21 07:25:04 2012 From: research at johnohagan.com (John O'Hagan) Date: Thu, 21 Jun 2012 21:25:04 +1000 Subject: Generator vs functools.partial? Message-ID: <20120621212504.390acc1cc9aa064429f98580@johnohagan.com> Sometimes a function gets called repeatedly with the same expensive argument: def some_func(arg, i): (do_something with arg and i) same_old_arg = big_calculation() for i in lots_of_items: some_func(same_old_arg, i) A simple case like that looks OK, but it can get messy when groups of arguments are passed between functions, especially if the arguments are used by functions called within the functions they are passed to (by other functions!). Maybe that's a code smell, but it can be cleaned up with: import functools some_func = functools.partial(some_func, big_calculation()) for i in lots_of_items: some_func(i) But what about a generator? def some_func(): arg = big_calculation() while 1: i = yield (do_something with arg and i) some_gen = some_func() some_gen.send(None) for i in lots_of_items: some_gen.send(i) I like this because it encapsulates the calculation of the arguments inside the function that is using them without repeating it, and there are no restrictions on argument order like partial. But sending None is annoying. :) Old news? Thoughts, criticisms, theories? -- John From steve+comp.lang.python at pearwood.info Thu Jun 21 08:19:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Jun 2012 12:19:20 GMT Subject: Generator vs functools.partial? References: Message-ID: <4fe31147$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 21 Jun 2012 21:25:04 +1000, John O'Hagan wrote: > Sometimes a function gets called repeatedly with the same expensive > argument: > > def some_func(arg, i): > (do_something with arg and i) > > same_old_arg = big_calculation() Since big_calculation() is only called once, the cost of generating that expensive argument is only paid once. > for i in lots_of_items: > some_func(same_old_arg, i) Passing that same_old_arg to some_func is cheap. Once you've paid the cost of producing the value in the first place, there is absolutely no difference in cost between passing an "expensive" argument and a "cheap" argument. > A simple case like that looks OK, but it can get messy when groups of > arguments are passed between functions, especially if the arguments are > used by functions called within the functions they are passed to (by > other functions!). I'm not sure what you're trying to say here. Argument passing is cheap. Function call overhead is not quite so cheap, but unless you've carefully profiled your code and determined that the cost of function overhead is significant, you're better off using ignoring it. Likely the actual calculation within the function is hundreds or thousands of times more expensive than the function call itself. > Maybe that's a code smell, but it can be cleaned up with: > > import functools > some_func = functools.partial(some_func, big_calculation()) > for i in lots_of_items: > some_func(i) Have you actually measured this to see whether it *actually is* faster, or are you just assuming it will be faster? I expect that at best it will be no faster at all, and quite possibly slightly slower. The main reason is that instead of one function call (calling some_func directly with two arguments) you now have two (partial function called with one argument, which internally calls some_func with two). Possibly that internal call is implemented in C and may be a little faster than if it were implemented in Python bytecode, but still, two calls can't be faster than one. [...] > Old news? Thoughts, criticisms, theories? Premature optimization is the root of all evil. -- Steven From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Jun 21 08:20:23 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 21 Jun 2012 14:20:23 +0200 Subject: Generator vs functools.partial? In-Reply-To: References: Message-ID: Am 21.06.2012 13:25 schrieb John O'Hagan: > But what about a generator? Yes, but... > def some_func(): > arg = big_calculation() > while 1: > i = yield > (do_something with arg and i) > > some_gen = some_func() > some_gen.send(None) > for i in lots_of_items: > some_gen.send(i) rather def some_func(it): arg = big_calculation() for i in it: do_something(arg, i) some_func(lots_of_items) HTH, Thomas From nospam at nospam.com Thu Jun 21 08:24:45 2012 From: nospam at nospam.com (Gilles) Date: Thu, 21 Jun 2012 14:24:45 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> Message-ID: <6f46u7duqi0sj8qfqhan7ujgvr6jds7jn4@4ax.com> On Tue, 12 Jun 2012 11:39:50 +0200, Gilles wrote: >I'm an amateur programmer, and would like to know what the main >options are to build web applications in Python instead of PHP. When I need to host my Python application (preferably in Europe since my users will be located there), what are the options? Do Python hosters provide a VM so that it's just like a remote Linux server where I'm free to install whatever I want, or do they force users to use specific versions of Python and specific frameworks eg. Django? Thank you. From bastian.ballmann at notch-interactive.com Thu Jun 21 09:16:59 2012 From: bastian.ballmann at notch-interactive.com (Bastian Ballmann) Date: Thu, 21 Jun 2012 15:16:59 +0200 Subject: Introspect imports from module In-Reply-To: References: <20120621100335.1a61a28b@pulsar.notch-interactive.lan> Message-ID: <20120621151659.6580ed1e@pulsar.notch-interactive.lan> Hi, that's really great stuff! I love it! Thx :) Am Thu, 21 Jun 2012 13:00:36 +0200 schrieb Christian Heimes : > Am 21.06.2012 10:03, schrieb Bastian Ballmann: > > Any suggestions how I could just get the import of > > module.to.inspect? Thanks && have a nice day! > > You could try a completely different approach and use the compiler > package to inspect the abstract syntrax tree of a compiled module. The > approach has the nice side effect that you don't have to import a > module to inspect its imports. This script may serve as an example > for you: > > http://svn.zope.org/Zope3/trunk/utilities/importchecker.py?rev=113742&view=auto > > Christian > -- Bastian Ballmann / Web Developer Notch Interactive GmbH / Badenerstrasse 571 / 8048 Z?rich Phone Phone +41 44 297 17 17 / www.notch-interactive.com CHECK OUR LATEST WORK: http://www.notch-interactive.com/projekte/ From jeanmichel at sequans.com Thu Jun 21 09:59:01 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 21 Jun 2012 15:59:01 +0200 Subject: fastest method In-Reply-To: References: Message-ID: <4FE328A5.7030003@sequans.com> david.garvey at gmail.com wrote: > I am looking for the fastest way to parse a log file. > > > currently I have this... Can I speed this up any? The script is > written to be a generic log file parser so I can't rely on some > predictable pattern. > > > def check_data(data,keywords): > #get rid of duplicates > unique_list = list(set(data)) > string_list=' '.join(unique_list) > #print string_list > for keyword in keywords: > if keyword in string_list: > return True > > > I am currently using file seek and maintaining a last byte count file: > > with open(filename) as f: > print "Here is filename:%s" %filename > f.seek(0, 2) > eof = f.tell() > print "Here is eof:%s" %eof > if last is not None: > print "Here is last:%s" %last > # if last is less than current > last = int(last) > if (eof - last > 0): > offset = eof - last > offset = offset * -1 > print "Here is new offset:%s" %offset > f.seek(offset, 2) > mylist = f.readlines() > else: > # if last doesn't exist or is greater than current > f.seek(0) > bof = f.tell() > print "Here is bof:%s" %bof > mylist = f.readlines() > > > > Thanks, > -- > David Garvey I have a log parser that take action upon some log patterns. I rely on my system 'grep' program to do the hard work, i.e. find occurrences Of course that means it is system dependant, but I don't think you can beat grep's speed. def _grep(self, link, pattern): # return the number of occurences for the pattern in the file proc = subprocess.Popen(['grep', '-c', pattern, link], stdout=subprocess.PIPE) return int(proc.communicate()[0]) Cheers, JM From research at johnohagan.com Thu Jun 21 10:49:46 2012 From: research at johnohagan.com (John O'Hagan) Date: Fri, 22 Jun 2012 00:49:46 +1000 Subject: Generator vs functools.partial? In-Reply-To: <4fe31147$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <4fe31147$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120622004946.9bffc415966a8f4e32968585@johnohagan.com> On 21 Jun 2012 12:19:20 GMT Steven D'Aprano wrote: > On Thu, 21 Jun 2012 21:25:04 +1000, John O'Hagan wrote: > > > Sometimes a function gets called repeatedly with the same expensive > > argument: > > > > def some_func(arg, i): > > (do_something with arg and i) > > > > same_old_arg = big_calculation() > > Since big_calculation() is only called once, the cost of generating that > expensive argument is only paid once. > > > for i in lots_of_items: > > some_func(same_old_arg, i) > > Passing that same_old_arg to some_func is cheap. Once you've paid the > cost of producing the value in the first place, there is absolutely no > difference in cost between passing an "expensive" argument and a "cheap" > argument. > > > > A simple case like that looks OK, but it can get messy when groups of > > arguments are passed between functions, especially if the arguments are > > used by functions called within the functions they are passed to (by > > other functions!). > > I'm not sure what you're trying to say here. Argument passing is cheap. > Function call overhead is not quite so cheap, but unless you've carefully > profiled your code and determined that the cost of function overhead is > significant, you're better off using ignoring it. Likely the actual > calculation within the function is hundreds or thousands of times more > expensive than the function call itself. [...] What I neglected to say was that I'm looking to refactor for clarity and DRY to minimise the number of objects that get passed through a chain of functions before being used, rather than efficiency. I realise the different examples I gave (and the more obvious one in Thomas's reply) do more or less the same thing and that there would probably only be marginal efficiency differences. I'll try to come up with better examples to show what I mean. Or not: see my reply to Thomas. > > Premature optimization is the root of all evil. > 100% agreement. Thanks, -- John From research at johnohagan.com Thu Jun 21 10:56:20 2012 From: research at johnohagan.com (John O'Hagan) Date: Fri, 22 Jun 2012 00:56:20 +1000 Subject: Generator vs functools.partial? In-Reply-To: References: Message-ID: <20120622005620.21544b9d899194786ada6e29@johnohagan.com> On Thu, 21 Jun 2012 14:20:23 +0200 Thomas Rachel wrote: > Am 21.06.2012 13:25 schrieb John O'Hagan: > > > But what about a generator? > > Yes, but... > > > def some_func(): > > arg = big_calculation() > > while 1: > > i = yield > > (do_something with arg and i) > > > > some_gen = some_func() > > some_gen.send(None) > > for i in lots_of_items: > > some_gen.send(i) > > rather > > def some_func(it): > arg = big_calculation() > for i in it: > do_something(arg, i) > > some_func(lots_of_items) > Ah yes, this demonstrates that my examples were too simple to show what I'm trying to do. In my real code, several functions take the elements from an iterator, so I can't pass the whole iterator to each one. I have a feeling there is some bad factoring in my real code which will disappear if I manage to provide a clear example, which I'll now endevour to do. Thanks for the reply. -- John From sg552 at hotmail.co.uk Thu Jun 21 11:19:41 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 21 Jun 2012 16:19:41 +0100 Subject: Strange threading behaviour Message-ID: Hi all, I'm using Python 2.7.2 on Windows 7 and a module I've written is acting strangely. I can reproduce the behaviour in question with the following: --- begin bugtest.py --- import threading, Tkinter, os, pickle class savethread(threading.Thread): def __init__(self, value): threading.Thread.__init__(self) self.value = value def run(self): print 'Saving:', with open(os.path.join(os.getcwd(), 'bugfile'), 'wb') as f: pickle.dump(self.value, f) print 'saved' class myclass(object): def gui(self): root = Tkinter.Tk() root.grid() def save(event): savethread(self).start() root.bind('s', save) root.wait_window() m = myclass() m.gui() --- end bugtest.py --- Here's the problem: suppose I fire up Python and type >>> import bugtest and then click on the Tk window that spawns and press 's'. Then 'Saving:' gets printed, and an empty file named 'bugfile' appears in my current working directory. But nothing else happens until I close the Tk window; as soon as I do so the file is written to and 'saved' gets printed. If I subsequently type >>> bugtest.m.gui() and then click on the resulting window and press 's', then 'Saving: saved' gets printed and the file is written to immediately, exactly as I would expect. Similarly if I remove the call to m.gui from the module and just call it myself after importing then it all works fine. But it seems as if calling the gui within the module itself somehow stops savethread(self).run from finishing its job while the gui is still alive. Can anyone help? -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From inq1ltd at inqvista.com Thu Jun 21 11:34:30 2012 From: inq1ltd at inqvista.com (inq1ltd) Date: Thu, 21 Jun 2012 11:34:30 -0400 Subject: inno setup 5.5 Message-ID: <1953455.yl3vh2pZAA@mach-114-20> py help, Can someone let me know where to get help with inno setup. I get an error; Can't find _thinter Sounds like a path problem. Everything works until it is packaged with inno v5.5. jd -------------- next part -------------- An HTML attachment was scrubbed... URL: From ferdinandsousa at gmail.com Thu Jun 21 11:38:14 2012 From: ferdinandsousa at gmail.com (Ferdinand Sousa) Date: Thu, 21 Jun 2012 21:08:14 +0530 Subject: Parse command line output using textfsm Message-ID: Hi List, I am using python to run command line utilities on Linux machine. I came across textfsm and feel that it fits my requirements. Here is the structure of the output from the 2 utilities Command 1: Id Address Port Location State Tenant count Max tenants Description -- ---------- ---- -------- ------ ------------ ----------- ------------ 1 10.0.32.20 8443 - ACTIVE 7 12 - 2 10.0.32.21 8443 - ACTIVE 7 12 - 3 10.0.32.22 8443 - ACTIVE 7 12 - Command 2: 1 2012-04-04 19:54 00DD0000000q3di GOLD Company 1 CA360 ACTIVE Yes https://10.0.32.26:7000 8 50 17 2012-04-09 23:01 00Dd0000000efRF SILVER Company 2 CA360 ACTIVE Yes https://10.0.32.20:7014 1 440 27 2012-04-10 03:42 00Dd0000000efdS TRIAL Company 3 CA360 ACTIVE Yes https://10.0.32.23:7021 4 10 32 2012-04-11 11:24 00Dd0000000eiGb TRIAL Company 4 CA360 INACTIVE Yes https://10.0.32.21:7000 2 25 I found this link documenting how to parse tabular data: http://code.google.com/p/textfsm/wiki/TextFSMCodeLab#Parsing_tabular_data My question is, what is the syntax of the pattern matching used. Is it the same as python regexp? Any other documentation/examples available for this library? I'm also open to suggestions of using other libraries. Basically, I would like this to be semantically as close as possible to working with data extracted from a database. Thanks and regards, Ferdi -------------- next part -------------- An HTML attachment was scrubbed... URL: From inq1ltd at inqvista.com Thu Jun 21 11:46:30 2012 From: inq1ltd at inqvista.com (inq1ltd) Date: Thu, 21 Jun 2012 11:46:30 -0400 Subject: Strange threading behaviour In-Reply-To: References: Message-ID: <2425945.lsBAXOcXEd@mach-114-20> On Thursday, June 21, 2012 04:19:41 PM Rotwang wrote: > Hi all, I'm using Python 2.7.2 on Windows 7 and a module I've written is > acting strangely. I can reproduce the behaviour in question with the > following: > > --- begin bugtest.py --- > > import threading, Tkinter, os, pickle try this; from Tkinter import * take it out of the other import line jd > > class savethread(threading.Thread): > def __init__(self, value): > threading.Thread.__init__(self) > self.value = value > def run(self): > print 'Saving:', > with open(os.path.join(os.getcwd(), 'bugfile'), 'wb') as f: > pickle.dump(self.value, f) > print 'saved' > > class myclass(object): > def gui(self): > root = Tkinter.Tk() > root.grid() > def save(event): > savethread(self).start() > root.bind('s', save) > root.wait_window() > > m = myclass() > m.gui() > > --- end bugtest.py --- > > > Here's the problem: suppose I fire up Python and type > > >>> import bugtest > > and then click on the Tk window that spawns and press 's'. Then > 'Saving:' gets printed, and an empty file named 'bugfile' appears in my > current working directory. But nothing else happens until I close the Tk > window; as soon as I do so the file is written to and 'saved' gets > printed. If I subsequently type > > >>> bugtest.m.gui() > > and then click on the resulting window and press 's', then 'Saving: > saved' gets printed and the file is written to immediately, exactly as I > would expect. Similarly if I remove the call to m.gui from the module > and just call it myself after importing then it all works fine. But it > seems as if calling the gui within the module itself somehow stops > savethread(self).run from finishing its job while the gui is still alive. > > Can anyone help? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jcd at sdf.lonestar.org Thu Jun 21 12:15:08 2012 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Thu, 21 Jun 2012 12:15:08 -0400 Subject: Generator vs functools.partial? In-Reply-To: <20120621212504.390acc1cc9aa064429f98580@johnohagan.com> References: <20120621212504.390acc1cc9aa064429f98580@johnohagan.com> Message-ID: <1340295308.3395.5.camel@jcdyer-laptop> On Thu, 2012-06-21 at 21:25 +1000, John O'Hagan wrote: > Sometimes a function gets called repeatedly with the same expensive argument: > > def some_func(arg, i): > (do_something with arg and i) > > same_old_arg = big_calculation() > for i in lots_of_items: > some_func(same_old_arg, i) > Another possibility is to refactor this into a callable class. class DoesSomethingWithExpensiveData(object): def __init__(self, arg): self.arg = arg def __call__(self, operand): return sum([self.arg, operand]) func = DoesSomethingWithExpensiveData(big_calculation()): for thing in a_bunch_of_things: print func(thing) Or you can write a function factory: def get_func(arg): def inner(operand): return sum([arg, operand]) return inner func = get_func(big_calculation()) for thing in a_bunch_of_things: print func(thing) > A simple case like that looks OK, but it can get messy when groups of arguments > are passed between functions, especially if the arguments are used by functions > called within the functions they are passed to (by other functions!). > > Maybe that's a code smell, but it can be cleaned up with: > > import functools > some_func = functools.partial(some_func, big_calculation()) > for i in lots_of_items: > some_func(i) > > But what about a generator? > > def some_func(): > arg = big_calculation() > while 1: > i = yield > (do_something with arg and i) > > some_gen = some_func() > some_gen.send(None) > for i in lots_of_items: > some_gen.send(i) > > I like this because it encapsulates the calculation of the arguments > inside the function that is using them without repeating it, and there are no > restrictions on argument order like partial. But sending None is annoying. :) > > Old news? Thoughts, criticisms, theories? > > -- > > John From inq1ltd at inqvista.com Thu Jun 21 12:56:32 2012 From: inq1ltd at inqvista.com (inq1ltd) Date: Thu, 21 Jun 2012 12:56:32 -0400 Subject: Strange threading behaviour In-Reply-To: <2425945.lsBAXOcXEd@mach-114-20> References: <2425945.lsBAXOcXEd@mach-114-20> Message-ID: <1993691.GQ7Bvv0LIK@mach-114-20> On Thursday, June 21, 2012 11:46:30 AM inq1ltd wrote: > On Thursday, June 21, 2012 04:19:41 PM Rotwang wrote: > > Hi all, I'm using Python 2.7.2 on Windows 7 and a module I've written is > > acting strangely. I can reproduce the behaviour in question with the > > following: > > > > --- begin bugtest.py --- > > > > import threading, Tkinter, os, pickle > correct my last response to this, try this; from Tkinter import * import threading, Tkinter, os, pickle it works for me. #### my module included if __name__ == '__main__' : print '##open bugtest , 29\n' myclass() so I could run python bugtest.py in a shell jd > > > class savethread(threading.Thread): > > def __init__(self, value): > > threading.Thread.__init__(self) > > self.value = value > > > > def run(self): > > print 'Saving:', > > > > with open(os.path.join(os.getcwd(), 'bugfile'), 'wb') as f: > > pickle.dump(self.value, f) > > > > print 'saved' > > > > class myclass(object): > > def gui(self): > > root = Tkinter.Tk() > > root.grid() > > > > def save(event): > > savethread(self).start() > > > > root.bind('s', save) > > root.wait_window() > > > > m = myclass() > > m.gui() > > > > --- end bugtest.py --- > > > > > > Here's the problem: suppose I fire up Python and type > > > > >>> import bugtest > > > > and then click on the Tk window that spawns and press 's'. Then > > 'Saving:' gets printed, and an empty file named 'bugfile' appears in my > > current working directory. But nothing else happens until I close the Tk > > window; as soon as I do so the file is written to and 'saved' gets > > printed. If I subsequently type > > > > >>> bugtest.m.gui() > > > > and then click on the resulting window and press 's', then 'Saving: > > saved' gets printed and the file is written to immediately, exactly as I > > would expect. Similarly if I remove the call to m.gui from the module > > and just call it myself after importing then it all works fine. But it > > seems as if calling the gui within the module itself somehow stops > > savethread(self).run from finishing its job while the gui is still > > alive. > > > > Can anyone help? -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Thu Jun 21 13:07:02 2012 From: d at davea.name (Dave Angel) Date: Thu, 21 Jun 2012 13:07:02 -0400 Subject: Strange threading behaviour In-Reply-To: References: Message-ID: <4FE354B6.7090808@davea.name> On 06/21/2012 11:19 AM, Rotwang wrote: > Hi all, I'm using Python 2.7.2 on Windows 7 and a module I've written > is acting strangely. I can reproduce the behaviour in question with > the following: > > --- begin bugtest.py --- > > import threading, Tkinter, os, pickle > > class savethread(threading.Thread): > def __init__(self, value): > threading.Thread.__init__(self) > self.value = value > def run(self): > print 'Saving:', > with open(os.path.join(os.getcwd(), 'bugfile'), 'wb') as f: > pickle.dump(self.value, f) > print 'saved' > > class myclass(object): > def gui(self): > root = Tkinter.Tk() > root.grid() > def save(event): > savethread(self).start() > root.bind('s', save) > root.wait_window() > > m = myclass() > m.gui() > > --- end bugtest.py --- > > > Here's the problem: suppose I fire up Python and type > > >>> import bugtest > > and then click on the Tk window that spawns and press 's'. Then > 'Saving:' gets printed, and an empty file named 'bugfile' appears in > my current working directory. But nothing else happens until I close > the Tk window; as soon as I do so the file is written to and 'saved' > gets printed. If I subsequently type > > >>> bugtest.m.gui() > > and then click on the resulting window and press 's', then 'Saving: > saved' gets printed and the file is written to immediately, exactly as > I would expect. Similarly if I remove the call to m.gui from the > module and just call it myself after importing then it all works fine. > But it seems as if calling the gui within the module itself somehow > stops savethread(self).run from finishing its job while the gui is > still alive. > > Can anyone help? > > I did not study your code, as I'm not very familiar with tkinter. However, I think I know your problem: You do not want to try to start up threads from within a import. An import is special, and somehow blocks threading while it's running. Consequently, a module should not try to do anything too fancy from within its top-level code. Add in the traditional: def main(): m = myclass() m.gui() if __name__ == "__main__": main() and just run it from the command line, as python bugtest.py And if you want to run it from a interactive python session, do the call to main() after importing it: >>>> import bugtest >>>> bugtest.main() -- DaveA From Tom.KACVINSKY at 3ds.com Thu Jun 21 13:10:21 2012 From: Tom.KACVINSKY at 3ds.com (KACVINSKY Tom) Date: Thu, 21 Jun 2012 17:10:21 +0000 Subject: bdist_wininst [was: Custom build of Python] Message-ID: I found what I was looking for: python setup.py bdist_wininst But... I follow all of the instructions for building Python on Windows and then follow the instructions for using bdist_wininst, and I get this: C:\Users\tky\Python\Python-2.6.8>PCbuild\amd64\python.exe setup.py bdist_wininst running bdist_wininst running build running build_ext INFO: Can't locate Tcl/Tk libs and/or headers Traceback (most recent call last): File "setup.py", line 2049, in main() File "setup.py", line 2044, in main 'Lib/smtpd.py'] File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\core.py", line 152, in setup dist.run_commands() File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 975, in run_commands self.run_command(cmd) File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 995, in run_command cmd_obj.run() File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\command\bdist_wininst.py", line 125, in run self.run_command('build') File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\cmd.py", line 333, in run_command self.distribution.run_command(command) File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 995, in run_command cmd_obj.run() File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\command\build.py", line 134, in run self.run_command(cmd_name) File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\cmd.py", line 333, in run_command self.distribution.run_command(command) File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 995, in run_command cmd_obj.run() File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\command\build_ext.py", line 340, in run self.build_extensions() File "setup.py", line 167, in build_extensions raise ValueError("No source directory; cannot proceed.") ValueError: No source directory; cannot proceed. Does anyone know of a way to get bdist_wininst to work out of the box? I am not comfortable with hacking distutils. What do the maintainers do in this case? Thanks, Tom -----Original Message----- From: python-list-bounces+tky=3ds.com at python.org [mailto:python-list-bounces+tky=3ds.com at python.org] On Behalf Of KACVINSKY Tom Sent: Wednesday, June 20, 2012 4:29 PM To: python-list at python.org Subject: RE: Custom build of Python Terry, At this stage, I don't want or need an MSI. I just want something that will bundle the executables/dynamic load libraries + compiled Python files and stick them into a compliant directory structure. Regards, Tom -----Original Message----- From: python-list-bounces+tky=3ds.com at python.org [mailto:python-list-bounces+tky=3ds.com at python.org] On Behalf Of Terry Reedy Sent: Wednesday, June 20, 2012 4:13 PM To: python-list at python.org Subject: Re: Custom build of Python On 6/20/2012 2:24 PM, KACVINSKY Tom wrote: > I had reason to build Python 2.6.8 with Microsoft Visual Studio 2010. > I was able to get the pcbuild solution to build, and I have the > necessary exes/dlls/pyds in the amd64 build directory. What is not > clear to is how to complete the build and make an installation. I > could not find any documentation for this. If you mean 'make a .msi file', I am not sure that is not officially supported beyond the inclusion of msilib. > Any help on this matter would be appreciated. 3.3 is now being built with VS2010. Perhaps its repository has something that will help you. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. For other languages, go to http://www.3ds.com/terms/email-disclaimer -- http://mail.python.org/mailman/listinfo/python-list This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. For other languages, go to http://www.3ds.com/terms/email-disclaimer From lamialily at cleverpun.com Thu Jun 21 13:12:07 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Thu, 21 Jun 2012 10:12:07 -0700 Subject: Strange threading behaviour References: Message-ID: On Thu, 21 Jun 2012 16:19:41 +0100, Rotwang wrote: >Hi all, I'm using Python 2.7.2 on Windows 7 and a module I've written is >acting strangely. I can reproduce the behaviour in question with the >following: > >--- begin bugtest.py --- > >import threading, Tkinter, os, pickle > >class savethread(threading.Thread): > def __init__(self, value): > threading.Thread.__init__(self) > self.value = value > def run(self): > print 'Saving:', > with open(os.path.join(os.getcwd(), 'bugfile'), 'wb') as f: > pickle.dump(self.value, f) > print 'saved' > >class myclass(object): > def gui(self): > root = Tkinter.Tk() > root.grid() > def save(event): > savethread(self).start() > root.bind('s', save) > root.wait_window() > >m = myclass() >m.gui() > >--- end bugtest.py --- > > >Here's the problem: suppose I fire up Python and type > > >>> import bugtest > >and then click on the Tk window that spawns and press 's'. Then >'Saving:' gets printed, and an empty file named 'bugfile' appears in my >current working directory. But nothing else happens until I close the Tk >window; as soon as I do so the file is written to and 'saved' gets >printed. If I subsequently type > > >>> bugtest.m.gui() > >and then click on the resulting window and press 's', then 'Saving: >saved' gets printed and the file is written to immediately, exactly as I >would expect. Similarly if I remove the call to m.gui from the module >and just call it myself after importing then it all works fine. But it >seems as if calling the gui within the module itself somehow stops >savethread(self).run from finishing its job while the gui is still alive. > >Can anyone help? Try appending the dump command with f.flush() and os.fsync(). ~Temia -- The amazing programming device: fuelled entirely by coffee, it codes while awake and tests while asleep! From lamialily at cleverpun.com Thu Jun 21 13:23:11 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Thu, 21 Jun 2012 10:23:11 -0700 Subject: Strange threading behaviour References: Message-ID: On Thu, 21 Jun 2012 10:12:07 -0700, Temia Eszteri wrote: > >Try appending the dump command with f.flush() and os.fsync(). > >~Temia Actually, wait, no. The behavior you're describing is indicating that the thread in question isn't even getting a chance to execute at all. I'd recommend going with Dave's idea then, see how it pans out. Still, a good set of commands to keep in mind. ~Temia -- The amazing programming device: fuelled entirely by coffee, it codes while awake and tests while asleep! From dieter at handshake.de Thu Jun 21 13:26:59 2012 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 21 Jun 2012 19:26:59 +0200 Subject: Strange threading behaviour References: Message-ID: <87pq8swp7g.fsf@handshake.de> Rotwang writes: > Hi all, I'm using Python 2.7.2 on Windows 7 and a module I've written > is acting strangely. I can reproduce the behaviour in question with > the following: > > --- begin bugtest.py --- > > import threading, Tkinter, os, pickle > > class savethread(threading.Thread): > def __init__(self, value): > threading.Thread.__init__(self) > self.value = value > def run(self): > print 'Saving:', > with open(os.path.join(os.getcwd(), 'bugfile'), 'wb') as f: > pickle.dump(self.value, f) > print 'saved' > > class myclass(object): > def gui(self): > root = Tkinter.Tk() > root.grid() > def save(event): > savethread(self).start() > root.bind('s', save) > root.wait_window() > > m = myclass() > m.gui() > > --- end bugtest.py --- > > > Here's the problem: suppose I fire up Python and type > >>>> import bugtest > > and then click on the Tk window that spawns and press 's'. Then > 'Saving:' gets printed, and an empty file named 'bugfile' appears in > my current working directory. But nothing else happens until I close > the Tk window; as soon as I do so the file is written to and 'saved' > gets printed. If I subsequently type > >>>> bugtest.m.gui() > > and then click on the resulting window and press 's', then 'Saving: > saved' gets printed and the file is written to immediately, exactly as > I would expect. Similarly if I remove the call to m.gui from the > module and just call it myself after importing then it all works > fine. But it seems as if calling the gui within the module itself > somehow stops savethread(self).run from finishing its job while the > gui is still alive. > > Can anyone help? It looks as if some waiting operation in the "wait_window" call did not release the GIL (the "Global Interpreter Lock" which ensures that at most one Python thread can run at a given time and protects the Python data structures such as the reference counts and interpreter state). In this case, you could expect some non-deterministic behaviour. If your thread is fast enough to finish before the internal activity inside "wait_window" gets the GIL again, everything completes immediately; otherwise, things complete only after the internal waiting ends and Python code is again executed. It might well be possible that "TKinter" has not been designed for a multi threaded environment; alternatively, there might be a bug. If "TKinter" truely supports multithreaded applications, any call to "tk" would need to release the GIL and any callback into Python reacquire it. Strange things of the kind you observe could happen when this is forgotten at a single place. From no.email at nospam.invalid Thu Jun 21 13:44:08 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 21 Jun 2012 10:44:08 -0700 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <6f46u7duqi0sj8qfqhan7ujgvr6jds7jn4@4ax.com> Message-ID: <7x1ul8blw7.fsf@ruckus.brouhaha.com> Gilles writes: > Do Python hosters provide a VM so that it's just like a remote Linux > server where I'm free to install whatever I want, or do they force > users to use specific versions of Python and specific frameworks eg. > Django? There are both kinds. The first kind is called a Virtual Private Server (VPS). The second kind is called shared hosting. VPS is very flexible but shared hosting can be cheaper, and easier to use if you have no sysadmin skills. I'm assuming you don't have enough workload to want to rent a physical server (sometimes called a "dedi", short for dedicated server) or colo (colocation, meaning you buy your own hardware and install it in a rack slot that you rent at the data center). OVH (www.ovh.com/fr) is the biggest French hosting place and they have all three types of service, I think. Their low cost branch is www.kimsufi.fr which has extremely attractive prices. I have heard mixed things about them: you get a lot of resources for the money, but that they can be hard to deal with in various ways. So it sounds not great but not terrible. Kimsufi dedis are cheaper than anything comparable that we can get in the USA, so I have been interested in renting one for some of my own stuff, but I haven't pursued this yet. www.webhostingtalk.com and www.lowendbox.com are good places to research this sort of thing. lowendbox.com is specifically for cheap VPS's. From sg552 at hotmail.co.uk Thu Jun 21 14:03:37 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 21 Jun 2012 19:03:37 +0100 Subject: Strange threading behaviour In-Reply-To: References: Message-ID: On 21/06/2012 18:07, Dave Angel wrote: > On 06/21/2012 11:19 AM, Rotwang wrote: >> Hi all, I'm using Python 2.7.2 on Windows 7 and a module I've written >> is acting strangely. I can reproduce the behaviour in question with >> the following: >> >> --- begin bugtest.py --- >> >> import threading, Tkinter, os, pickle >> >> class savethread(threading.Thread): >> def __init__(self, value): >> threading.Thread.__init__(self) >> self.value = value >> def run(self): >> print 'Saving:', >> with open(os.path.join(os.getcwd(), 'bugfile'), 'wb') as f: >> pickle.dump(self.value, f) >> print 'saved' >> >> class myclass(object): >> def gui(self): >> root = Tkinter.Tk() >> root.grid() >> def save(event): >> savethread(self).start() >> root.bind('s', save) >> root.wait_window() >> >> m = myclass() >> m.gui() >> >> --- end bugtest.py --- >> >> >> Here's the problem: suppose I fire up Python and type >> >>>>> import bugtest >> >> and then click on the Tk window that spawns and press 's'. Then >> 'Saving:' gets printed, and an empty file named 'bugfile' appears in >> my current working directory. But nothing else happens until I close >> the Tk window; as soon as I do so the file is written to and 'saved' >> gets printed. If I subsequently type >> >>>>> bugtest.m.gui() >> >> and then click on the resulting window and press 's', then 'Saving: >> saved' gets printed and the file is written to immediately, exactly as >> I would expect. Similarly if I remove the call to m.gui from the >> module and just call it myself after importing then it all works fine. >> But it seems as if calling the gui within the module itself somehow >> stops savethread(self).run from finishing its job while the gui is >> still alive. >> >> Can anyone help? >> >> > > I did not study your code, as I'm not very familiar with tkinter. > However, I think I know your problem: > > You do not want to try to start up threads from within a import. An > import is special, and somehow blocks threading while it's running. That would explain it. > Consequently, a module should not try to do anything too fancy from > within its top-level code. Add in the traditional: > > def main(): > m = myclass() > m.gui() > > if __name__ == "__main__": > main() > > and just run it from the command line, as python bugtest.py In fact, running the module directly from the command line makes it work properly as-is. Thanks for your post. -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From sg552 at hotmail.co.uk Thu Jun 21 14:09:44 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 21 Jun 2012 19:09:44 +0100 Subject: Strange threading behaviour In-Reply-To: References: Message-ID: On 21/06/2012 18:23, Temia Eszteri wrote: > On Thu, 21 Jun 2012 10:12:07 -0700, Temia Eszteri > wrote: >> >> Try appending the dump command with f.flush() and os.fsync(). >> >> ~Temia > > Actually, wait, no. The behavior you're describing is indicating that > the thread in question isn't even getting a chance to execute at all. Surely not? The fact that it got as far as executing the first print statement and creating the file suggests that the problem happens somewhere between the dump command and leaving the with statement, doesn't it? The suggestion didn't make any difference, though. > I'd recommend going with Dave's idea then, see how it pans out. > > Still, a good set of commands to keep in mind. Thanks, will do. -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From sg552 at hotmail.co.uk Thu Jun 21 14:14:32 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 21 Jun 2012 19:14:32 +0100 Subject: Strange threading behaviour In-Reply-To: References: Message-ID: On 21/06/2012 18:26, Dieter Maurer wrote: > Rotwang writes: > >> [...] >> >> Can anyone help? > > It looks as if some waiting operation > in the "wait_window" call did not release the GIL (the "Global Interpreter > Lock" which ensures that at most one Python thread can run at a given > time and protects the Python data structures such as the reference counts > and interpreter state). > > In this case, you could expect some non-deterministic behaviour. > If your thread is fast enough to finish before the internal > activity inside "wait_window" gets the GIL again, > everything completes immediately; otherwise, things complete > only after the internal waiting ends and Python code is again executed. OK, that makes sense - it could certainly explain why the print and open commands worked fine but the thread got stuck at pickle.dump. Thanks. -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From santosh.ssit at gmail.com Thu Jun 21 14:16:49 2012 From: santosh.ssit at gmail.com (hisan) Date: Thu, 21 Jun 2012 11:16:49 -0700 (PDT) Subject: how to compare below 2 json structure in python Message-ID: sample_json1={{ "globalControlId": 72, "value": 0, "controlId": 2 }, { "globalControlId": 77, "value": 3, "controlId": 7 } } sample_json2={ { "globalControlId": 77, "value": 3, "controlId": 7 }, { "globalControlId": 72, "value": 0, "controlId": 2 } } From sg552 at hotmail.co.uk Thu Jun 21 14:24:13 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 21 Jun 2012 19:24:13 +0100 Subject: Strange threading behaviour In-Reply-To: References: Message-ID: On 21/06/2012 18:37, Dennis Lee Bieber wrote: > On Thu, 21 Jun 2012 16:19:41 +0100, Rotwang > declaimed the following in gmane.comp.python.general: > >> >> import threading, Tkinter, os, pickle >> >> class savethread(threading.Thread): >> def __init__(self, value): >> threading.Thread.__init__(self) >> self.value = value >> def run(self): >> print 'Saving:', >> with open(os.path.join(os.getcwd(), 'bugfile'), 'wb') as f: >> pickle.dump(self.value, f) >> print 'saved' >> >> class myclass(object): >> def gui(self): >> root = Tkinter.Tk() >> root.grid() >> def save(event): >> savethread(self).start() >> root.bind('s', save) > > Each time your "s" runs you are creating a NEW thread. Yes, that's the whole point: I want the object's state to be saved in the background while I can continue using the GUI without having to wait (in the original module where I noticed the problem, the thread pickles a copy of the object whose gui method created it, rather than the object itself - that way I can make changes to the object without interfering with the work being done by pickle.dump). > >> root.wait_window() >> >> m = myclass() >> m.gui() >> >> --- end bugtest.py --- >> >> >> Here's the problem: suppose I fire up Python and type >> >> >>> import bugtest >> > Running in the interpreter rather than as a program... > >> and then click on the Tk window that spawns and press 's'. Then >> 'Saving:' gets printed, and an empty file named 'bugfile' appears in my >> current working directory. But nothing else happens until I close the Tk >> window; as soon as I do so the file is written to and 'saved' gets >> printed. If I subsequently type >> >> >>> bugtest.m.gui() >> >> and then click on the resulting window and press 's', then 'Saving: >> saved' gets printed and the file is written to immediately, exactly as I >> would expect. Similarly if I remove the call to m.gui from the module >> and just call it myself after importing then it all works fine. But it >> seems as if calling the gui within the module itself somehow stops >> savethread(self).run from finishing its job while the gui is still alive. >> > Since you never kill the previous thread, you might have a binding > to left-over multiple threads; at the least, the Python scheduler may be > swapping between threads. Which previous thread do you mean? The problem happens when save has only been called once. > The task swapping probably gives the threads time to flush output. > With just the first run thread condition, the process may go back to the > Tk mainloop and not return to the thread to completely flush data. > > Especially with the use of .wait_window(), which is supposed to lock > the application until the window is destroyed. If overly aggressive, it > might even lock up swapping back to the thread to allow it to flush. > >> Can anyone help? > > Don't run from the interactive interpreter? Thanks. -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From d at davea.name Thu Jun 21 14:28:14 2012 From: d at davea.name (Dave Angel) Date: Thu, 21 Jun 2012 14:28:14 -0400 Subject: Strange threading behaviour In-Reply-To: References: Message-ID: <4FE367BE.8000702@davea.name> On 06/21/2012 02:03 PM, Rotwang wrote: > On 21/06/2012 18:07, Dave Angel wrote: >> On 06/21/2012 11:19 AM, Rotwang wrote: >>> Hi all, I'm using Python 2.7.2 on Windows 7 and a module I've written >>> is acting strangely. I can reproduce the behaviour in question with >>> the following: >>> >>> --- begin bugtest.py --- >>> >>> import threading, Tkinter, os, pickle >>> >>> class savethread(threading.Thread): >>> def __init__(self, value): >>> threading.Thread.__init__(self) >>> self.value = value >>> def run(self): >>> print 'Saving:', >>> with open(os.path.join(os.getcwd(), 'bugfile'), 'wb') as f: >>> pickle.dump(self.value, f) >>> print 'saved' >>> >>> class myclass(object): >>> def gui(self): >>> root = Tkinter.Tk() >>> root.grid() >>> def save(event): >>> savethread(self).start() >>> root.bind('s', save) >>> root.wait_window() >>> >>> m = myclass() >>> m.gui() >>> >>> --- end bugtest.py --- >>> >>> >>> Here's the problem: suppose I fire up Python and type >>> >>>>>> import bugtest >>> >>> and then click on the Tk window that spawns and press 's'. Then >>> 'Saving:' gets printed, and an empty file named 'bugfile' appears in >>> my current working directory. But nothing else happens until I close >>> the Tk window; as soon as I do so the file is written to and 'saved' >>> gets printed. If I subsequently type >>> >>>>>> bugtest.m.gui() >>> >>> and then click on the resulting window and press 's', then 'Saving: >>> saved' gets printed and the file is written to immediately, exactly as >>> I would expect. Similarly if I remove the call to m.gui from the >>> module and just call it myself after importing then it all works fine. >>> But it seems as if calling the gui within the module itself somehow >>> stops savethread(self).run from finishing its job while the gui is >>> still alive. >>> >>> Can anyone help? >>> >>> >> >> I did not study your code, as I'm not very familiar with tkinter. >> However, I think I know your problem: >> >> You do not want to try to start up threads from within a import. An >> import is special, and somehow blocks threading while it's running. > > That would explain it. > > >> Consequently, a module should not try to do anything too fancy from >> within its top-level code. Add in the traditional: >> >> def main(): >> m = myclass() >> m.gui() >> >> if __name__ == "__main__": >> main() >> >> and just run it from the command line, as python bugtest.py > > In fact, running the module directly from the command line makes it > work properly as-is. But if you leave it as-is, then you can't run it from the interactive interpreter. > > Thanks for your post. > just for completeness, see link; http://docs.python.org/library/threading.html " ... an import should not have the side effect of spawning a new thread and then waiting for that thread in any way..." -- DaveA From gordon at panix.com Thu Jun 21 15:06:40 2012 From: gordon at panix.com (John Gordon) Date: Thu, 21 Jun 2012 19:06:40 +0000 (UTC) Subject: how to compare below 2 json structure in python References: Message-ID: In hisan writes: > sample_json1={{ > "globalControlId": 72, > "value": 0, > "controlId": 2 > }, > { > "globalControlId": 77, > "value": 3, > "controlId": 7 > } > } > sample_json2={ > { > "globalControlId": 77, > "value": 3, > "controlId": 7 > }, > { > "globalControlId": 72, > "value": 0, > "controlId": 2 > } > } Assuming you have valid json strings (which these aren't), I think you could convert them into python objects with json.loads() and then compare the python objects. For example: >>> import json >>> json1 = '{"color": "blue", "amount": 10}' >>> json2 = '{"amount": 10, "color": "blue"}' >>> python1 = json.loads(json1) >>> python2 = json.loads(json2) >>> print python1 == python2 True >>> -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From python at mrabarnett.plus.com Thu Jun 21 15:20:01 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 21 Jun 2012 20:20:01 +0100 Subject: how to compare below 2 json structure in python In-Reply-To: References: Message-ID: <4FE373E1.40704@mrabarnett.plus.com> On 21/06/2012 19:16, hisan wrote: > sample_json1={{ > "globalControlId": 72, > "value": 0, > "controlId": 2 > }, > { > "globalControlId": 77, > "value": 3, > "controlId": 7 > } > } > > sample_json2={ > { > "globalControlId": 77, > "value": 3, > "controlId": 7 > }, > { > "globalControlId": 72, > "value": 0, > "controlId": 2 > } > } > That doesn't look like valid JSON. The only container types in JSON are list (delimited by "[" and "]") and dict (delimited by "{" and "}"). From sg552 at hotmail.co.uk Thu Jun 21 15:44:41 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 21 Jun 2012 20:44:41 +0100 Subject: Strange threading behaviour In-Reply-To: References: Message-ID: On 21/06/2012 19:28, Dave Angel wrote: > On 06/21/2012 02:03 PM, Rotwang wrote: >> [...] >> >> In fact, running the module directly from the command line makes it >> work properly as-is. > > But if you leave it as-is, then you can't run it from the interactive > interpreter. Right, thanks. >> Thanks for your post. >> > > just for completeness, see link; > http://docs.python.org/library/threading.html > > " ... an import should not have the side effect of spawning a new thread > and then waiting for that thread in any way..." Ah, I missed that. -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From ralf at systemexit.de Thu Jun 21 15:45:17 2012 From: ralf at systemexit.de (Ralf Schmitt) Date: Thu, 21 Jun 2012 21:45:17 +0200 Subject: [ANNOUNCE] greenlet 0.4.0 Message-ID: <87hau4motu.fsf@myhost.lan> Hi, I have uploaded greenlet 0.4.0 to PyPI: http://pypi.python.org/pypi/greenlet What is it? ----------- The greenlet module provides coroutines for python. coroutines allow suspending and resuming execution at certain locations. concurrence[1], eventlet[2] and gevent[3] use the greenlet module in order to implement concurrent network applications. Documentation can be found here: http://greenlet.readthedocs.org The code is hosted on github: https://github.com/python-greenlet/greenlet Changes in version 0.4.0 ------------------------ The NEWS file lists these changes for release 0.4.0: * Greenlet has an instance dictionary now, which means it can be used for implementing greenlet local storage, etc. However, this might introduce incompatibility if subclasses have __dict__ in their __slots__. Classes like that will fail, because greenlet already has __dict__ out of the box. * Greenlet no longer leaks memory after thread termination, as long as terminated thread has no running greenlets left at the time. * Add support for debian sparc and openbsd5-sparc64 * Add support for ppc64 linux * Don't allow greenlets to be copied with copy.copy/deepcopy * Fix arm32/thumb support * Restore greenlet's parent after kill * Add experimental greenlet tracing Many thanks to Alexey Borzenkov, who spent a lot of time on this release and everyone else that helped make this release happen. [1] http://opensource.hyves.org/concurrence/ [2] http://eventlet.net/ [3] http://www.gevent.org/ -- Cheers Ralf Schmitt From dreadpiratejeff at gmail.com Thu Jun 21 17:47:37 2012 From: dreadpiratejeff at gmail.com (J) Date: Thu, 21 Jun 2012 17:47:37 -0400 Subject: Help me with a bytes decoding problem in python 3 Message-ID: I have a bit of a problem I hope you could help me sort out with some code I'm porting from 2.x to 3. I have a program with a wrapper for Popen that is called to run certain linux shell commands and gather system info. Essentially the code looks something like this: process = subprocess.Popen(command_str,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) result = process.communicate() stdout,stderr = result message = ['Output:\n' '- returncode:\n{0}'.format(self.process.returncode)] if stdout: if type(stdout) is bytes: stdout = stdout.decode() message.append('- stdout:\n{0}'.format(stdout)) if stderr: if type(stderr) is bytes: stderr = stderr.decode() message.append('- stderr:\n{0}'.format(stderr)) logging.debug('\n'.join(message)) So what essentially happens is that command_str is passed to this function and is a string like this: 'lspci | grep Network' or 'xinput list' using the first command string, I get output like this: In [12]: command = 'lspci |grep Network' In [13]: process = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) In [14]: result = process.communicate() In [15]: stdout,stderr = result In [16]: result Out[16]: (b'00:19.0 Ethernet controller: Intel Corporation 82577LC Gigabit Network Connection (rev 06)\n07:00.0 Network controller: Intel Corporation Ultimate N WiFi Link 5300\n', b'') Which is a bytes object that is very easily converted to text by the decode() call prior to sending "message" to the logger. However, the program seems to now be hanging up when running the second command_str because it's actually returning bytecode inside the bytes object: In [18]: command = 'xinput list' In [19]: process = subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) In [20]: result = process.communicate() In [21]: stdout,stderr = result In [22]: result Out[22]: (b'\xe2\x8e\xa1 Virtual core pointer \tid=2\t[master pointer (3)]\n\xe2\x8e\x9c \xe2\x86\xb3 Virtual core XTEST pointer \tid=4\t[slave pointer (2)]\n\xe2\x8e\x9c \xe2\x86\xb3 Logitech Unifying Device. Wireless PID:1017\tid=9\t[slave pointer (2)]\n\xe2\x8e\x9c \xe2\x86\xb3 SynPS/2 Synaptics TouchPad \tid=12\t[slave pointer (2)]\n\xe2\x8e\x9c \xe2\x86\xb3 MCE IR Keyboard/Mouse (ite-cir) \tid=14\t[slave pointer (2)]\n\xe2\x8e\xa3 Virtual core keyboard \tid=3\t[master keyboard (2)]\n \xe2\x86\xb3 Virtual core XTEST keyboard \tid=5\t[slave keyboard (3)]\n \xe2\x86\xb3 Power Button \tid=6\t[slave keyboard (3)]\n \xe2\x86\xb3 Video Bus \tid=7\t[slave keyboard (3)]\n \xe2\x86\xb3 Laptop_Integrated_Webcam_2M \tid=8\t[slave keyboard (3)]\n \xe2\x86\xb3 HID 413c:8157 \tid=10\t[slave keyboard (3)]\n \xe2\x86\xb3 AT Translated Set 2 keyboard \tid=11\t[slave keyboard (3)]\n \xe2\x86\xb3 Dell WMI hotkeys \tid=13\t[slave keyboard (3)]\n \xe2\x86\xb3 ITE8708 CIR transceiver \tid=15\t[slave keyboard (3)]\n', b'') Unfortunately, what's happening here is all that extra formatting stuff that xinput injects is also converted when doing bytes.decode() on result[0]. In [24]: result[0].decode() Out[24]: '? Virtual core pointer \tid=2\t[master pointer (3)]\n? ? Virtual core XTEST pointer \tid=4\t[slave pointer (2)]\n? ? Logitech Unifying Device. Wireless PID:1017\tid=9\t[slave pointer (2)]\n? ? SynPS/2 Synaptics TouchPad \tid=12\t[slave pointer (2)]\n? ? MCE IR Keyboard/Mouse (ite-cir) \tid=14\t[slave pointer (2)]\n? Virtual core keyboard \tid=3\t[master keyboard (2)]\n ? Virtual core XTEST keyboard \tid=5\t[slave keyboard (3)]\n ? Power Button \tid=6\t[slave keyboard (3)]\n ? Video Bus \tid=7\t[slave keyboard (3)]\n ? Laptop_Integrated_Webcam_2M \tid=8\t[slave keyboard (3)]\n ? HID 413c:8157 \tid=10\t[slave keyboard (3)]\n ? AT Translated Set 2 keyboard \tid=11\t[slave keyboard (3)]\n ? Dell WMI hotkeys \tid=13\t[slave keyboard (3)]\n ? ITE8708 CIR transceiver \tid=15\t[slave keyboard (3)]\n' And so I believe that when that decoded string is being pushed to the logger, the logger is choking, causing the program to just hang waiting on something... not sure which. Though when doing this manually via ipython3, logger seems to handle it just fine: In [37]: message = ['Output:\n' '- returncode:\n{0}'.format(process.returncode)] In [38]: message.append('- stdout:\n{0}'.format(stdout.decode())) In [39]: logging.debug('\n'.join(message)) DEBUG:root:Output: - returncode: 0 - stdout: ? Virtual core pointer id=2 [master pointer (3)] ? ? Virtual core XTEST pointer id=4 [slave pointer (2)] ? ? Logitech Unifying Device. Wireless PID:1017 id=9 [slave pointer (2)] ? ? SynPS/2 Synaptics TouchPad id=12 [slave pointer (2)] ? ? MCE IR Keyboard/Mouse (ite-cir) id=14 [slave pointer (2)] ? Virtual core keyboard id=3 [master keyboard (2)] ? Virtual core XTEST keyboard id=5 [slave keyboard (3)] ? Power Button id=6 [slave keyboard (3)] ? Video Bus id=7 [slave keyboard (3)] ? Laptop_Integrated_Webcam_2M id=8 [slave keyboard (3)] ? HID 413c:8157 id=10 [slave keyboard (3)] ? AT Translated Set 2 keyboard id=11 [slave keyboard (3)] ? Dell WMI hotkeys id=13 [slave keyboard (3)] ? ITE8708 CIR transceiver id=15 [slave keyboard (3)] outside of ipython3, I'm running this and looking at the log file the actual program generates and it always hangs up on the output from 'xinput list'. Interestingly though, it gathers this info both before and after the reboot action this script performs... :( I tried attaching the actual program, but apparently it's too big :( From rosuav at gmail.com Thu Jun 21 17:54:26 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jun 2012 07:54:26 +1000 Subject: Help me with a bytes decoding problem in python 3 In-Reply-To: References: Message-ID: On Fri, Jun 22, 2012 at 7:47 AM, J wrote: > \xe2\x86\xb3 This is the UTF-8 encoded form of U+21B3, which is the DOWNWARDS ARROW WITH TIP RIGHTWARDS character that you're showing. That's what the "bytecode" you're seeing is. You may be able to ask the underlying program to make its output in a cleaner format - try looking for a --porcelain option or similar - but as I see it, everything in Python is doing what it ought to do. Or am I misunderstanding your question? ChrisA From nospam at nospam.com Thu Jun 21 17:58:02 2012 From: nospam at nospam.com (Gilles) Date: Thu, 21 Jun 2012 23:58:02 +0200 Subject: [newbie] Equivalent to PHP? References: <0l0et7hrlre0v3cuvuhh7cdhg8019me56s@4ax.com> <6f46u7duqi0sj8qfqhan7ujgvr6jds7jn4@4ax.com> <7x1ul8blw7.fsf@ruckus.brouhaha.com> Message-ID: On Thu, 21 Jun 2012 10:44:08 -0700, Paul Rubin wrote: >There are both kinds. The first kind is called a Virtual Private Server >(VPS). The second kind is called shared hosting. Thanks much for the infos. From rosuav at gmail.com Thu Jun 21 18:30:16 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jun 2012 08:30:16 +1000 Subject: inno setup 5.5 In-Reply-To: <1953455.yl3vh2pZAA@mach-114-20> References: <1953455.yl3vh2pZAA@mach-114-20> Message-ID: On Fri, Jun 22, 2012 at 1:34 AM, inq1ltd wrote: > Can't find _thinter Is this supposed to be _tkinter? Try copying and pasting the entire error message, including traceback. That often helps. At the moment, I can't know whether the error is in your transcription of the message or if in a source file somewhere (a misspelled import, for instance). Chris Angelico From dreadpiratejeff at gmail.com Thu Jun 21 18:30:48 2012 From: dreadpiratejeff at gmail.com (J) Date: Thu, 21 Jun 2012 18:30:48 -0400 Subject: Help me with a bytes decoding problem in python 3 In-Reply-To: References: Message-ID: On Thu, Jun 21, 2012 at 5:54 PM, Chris Angelico wrote: > On Fri, Jun 22, 2012 at 7:47 AM, J wrote: >> \xe2\x86\xb3 > > This is the UTF-8 encoded form of U+21B3, which is the DOWNWARDS ARROW > WITH TIP RIGHTWARDS character that you're showing. That's what the > "bytecode" you're seeing is. You may be able to ask the underlying > program to make its output in a cleaner format - try looking for a > --porcelain option or similar - but as I see it, everything in Python > is doing what it ought to do. > > Or am I misunderstanding your question? > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list No, that's exactly what was choking my python program... And you hit the nail on the head. Apparently, if I run xinput using default output (what we were doing originally) you get those characters. If you run it like so: xinput list --name-only you get a clean, text only list of only the names of the various input devices found. So doing that, after an afternoon of pulling my hair out over this mess, makes the program work as it's supposed to. What confuses me though, is that the program calls that function twice, and this works fine the first time around, but fails the second. The function is called before rebooting the machine, then is called again after rebooting the machine and compares the output of various system info commands to make sure no hardware disappeared after a reboot. This was not an issue in Python 2.x, it's only on the Python 3 conversion this occurred. :/ In fact, if I change the shebang from python3 back to python2.7, it works beautifully. In the log file, this appears the first time that the xinput command is run: 2012-06-21 18:02:43,043 INFO Gathering hardware information... 2012-06-21 18:02:43,043 DEBUG Executing: 'xinput list'... 2012-06-21 18:02:43,052 DEBUG Output: - returncode: 0 - stdout: ? Virtual core pointer id=2 [master pointer (3)] ? ? Virtual core XTEST pointer id=4 [slave pointer (2)] ? ? Logitech Unifying Device. Wireless PID:1017 id=9 [slave pointer (2)] ? ? SynPS/2 Synaptics TouchPad id=12 [slave pointer (2)] ? ? MCE IR Keyboard/Mouse (ite-cir) id=14 [slave pointer (2)] ? Virtual core keyboard id=3 [master keyboard (2)] ? Virtual core XTEST keyboard id=5 [slave keyboard (3)] ? Power Button id=6 [slave keyboard (3)] ? Video Bus id=7 [slave keyboard (3)] ? Laptop_Integrated_Webcam_2M id=8 [slave keyboard (3)] ? HID 413c:8157 id=10 [slave keyboard (3)] ? AT Translated Set 2 keyboard id=11 [slave keyboard (3)] ? Dell WMI hotkeys id=13 [slave keyboard (3)] ? ITE8708 CIR transceiver id=15 [slave keyboard (3)] 2012-06-21 18:02:43,053 DEBUG Touchpad and Keyboard: ? Virtual core pointer id=2 [master pointer (3)] ? ? Virtual core XTEST pointer id=4 [slave pointer (2)] ? ? Logitech Unifying Device. Wireless PID:1017 id=9 [slave pointer (2)] ? ? SynPS/2 Synaptics TouchPad id=12 [slave pointer (2)] ? ? MCE IR Keyboard/Mouse (ite-cir) id=14 [slave pointer (2)] ? Virtual core keyboard id=3 [master keyboard (2)] ? Virtual core XTEST keyboard id=5 [slave keyboard (3)] ? Power Button id=6 [slave keyboard (3)] ? Video Bus id=7 [slave keyboard (3)] ? Laptop_Integrated_Webcam_2M id=8 [slave keyboard (3)] ? HID 413c:8157 id=10 [slave keyboard (3)] ? AT Translated Set 2 keyboard id=11 [slave keyboard (3)] ? Dell WMI hotkeys id=13 [slave keyboard (3)] ? ITE8708 CIR transceiver id=15 [slave keyboard (3)] (it appears twice because I ran it in debug mode) but after the reboot, it chokes: 2012-06-21 18:03:56,396 INFO reboot operations remaining: 0 2012-06-21 18:03:56,396 INFO Reboot time: 0:01:13.396280 2012-06-21 18:04:27,201 INFO Gathering hardware information... 2012-06-21 18:04:27,201 DEBUG Executing: 'xinput list'... 2012-06-21 18:07:22,985 DEBUG Removing desktop file ('/home/bladernr/.config/autostart/pm_test.desktop')... 2012-06-21 18:07:22,986 DEBUG Restoring sudoers configuration... 2012-06-21 18:07:22,986 DEBUG Executing: "sed -i -e '/# Automatically added by pm.py/,+1d' /etc/sudoers"... 2012-06-21 18:07:22,993 DEBUG Restoring autologin configuration... 2012-06-21 18:07:23,013 INFO Reboot test cancelled by user Everything after "Executing: 'xinput list'..." is where I manually cancelled the run because it stuck. I'm wondering now... the way it works is that the program is run from a user terminal/console. however, on the other side (after the reboot is done) it runs via an autostart script after the user is logged in, and thus runs outside of the terminal. So I wonder if THAT could be the root cause of this headache... maybe there's something about the program being run outside of a user shell and generating those characters that causes the hang. At this point it's more an academic excercise, since I've got a viable workaround... in anycase, I was able to change the output of xinput and that fixed the problem in a rather simple manner. From rosuav at gmail.com Thu Jun 21 18:36:25 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jun 2012 08:36:25 +1000 Subject: Help me with a bytes decoding problem in python 3 In-Reply-To: References: Message-ID: On Fri, Jun 22, 2012 at 8:30 AM, J wrote: > I'm wondering now... the way it works is that the program is run from > a user terminal/console. ?however, on the other side (after the reboot > is done) it runs via an autostart script after the user is logged in, > and thus runs outside of the terminal. ?So I wonder if THAT could be > the root cause of this headache... ?maybe there's something about the > program being run outside of a user shell and generating those > characters that causes the hang. It may be a difference in the default encoding of STDIN/STDOUT. When you're running in a terminal, they're probably being set to UTF-8, so Python's reading and writing will be in Unicode; possibly it's set to ASCII import sys print(sys.stdin.encoding) There are many potential differences between TTY access and whatever happens on startup. How is your script being invoked? Is it through Upstart? I know you can arrange where stdio go in Upstart scripts. ChrisA From inq1ltd at inqvista.com Thu Jun 21 19:03:03 2012 From: inq1ltd at inqvista.com (inq1ltd) Date: Thu, 21 Jun 2012 19:03:03 -0400 Subject: inno setup 5.5 In-Reply-To: References: <1953455.yl3vh2pZAA@mach-114-20> Message-ID: <1485253.19C6f2rxD2@mach-114-20> On Friday, June 22, 2012 08:30:16 AM Chris Angelico wrote: > On Fri, Jun 22, 2012 at 1:34 AM, inq1ltd wrote: > > Can't find _thinter > > Is this supposed to be _tkinter? > > Try copying and pasting the entire error message, including traceback. > That often helps. At the moment, I can't know whether the error is in > your transcription of the message or if in a source file somewhere (a > misspelled import, for instance). > > Chris Angelico Thanks for responding, The following is as it is in the exe text doc. Traceback (most recent call last): File "INQVISTA.py", line 23, in File "INQVISTA.py", line 19, in __init__ File "INQVISTA_0.pyc", line 23, in __init__ File "INQVISTA_0.pyc", line 75, in __init__ File "INQVISTA_0.pyc", line 78, in FmakeBox File "Tkinter.pyc", line 1643, in __init__ _tkinter.TclError: Can't find a usable init.tcl in the following directories: {C:/Program Files/lib/tcl8.5} {C:/Program Files/lib/tcl8.5} C:/lib/tcl8.5 {C:/Program Files/library} C:/library C:/tcl8.5.2/library C:/tcl8.5.2/library This probably means that Tcl wasn't installed properly. ----//---- the line of code that the error msg refers to is: Mwelc = Tk () jd -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Thu Jun 21 21:37:37 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 22 Jun 2012 11:37:37 +1000 Subject: bdist_wininst [was: Custom build of Python] In-Reply-To: References: Message-ID: <4FE3CC61.2050805@gmail.com> On 22/06/2012 3:10 AM, KACVINSKY Tom wrote: > I found what I was looking for: > > python setup.py bdist_wininst bdist_wininst is for creating installers for Python packages which install into an existing Python directory structure. It isn't used to create a installer for Python itself (which unless I misunderstand, seems what you are trying to do). Apart from generating an "official" MSI like Python itself ships as, IIUC, there is no other way to take a built tree and create an installer. On the other hand though, a built tree will generally work fine if transplanted somewhere else, so long as a couple of registry entries are created. So you could do something like creating an inno installer script that takes your built tree and generates a custom installer for your build. Mark > > But... I follow all of the instructions for building Python on Windows and then follow the instructions for using bdist_wininst, and I get this: > > C:\Users\tky\Python\Python-2.6.8>PCbuild\amd64\python.exe setup.py bdist_wininst > running bdist_wininst > running build > running build_ext > INFO: Can't locate Tcl/Tk libs and/or headers > Traceback (most recent call last): > File "setup.py", line 2049, in > main() > File "setup.py", line 2044, in main > 'Lib/smtpd.py'] > File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\core.py", line 152, in setup > dist.run_commands() > File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 975, in run_commands > self.run_command(cmd) > File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 995, in run_command > cmd_obj.run() > File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\command\bdist_wininst.py", line 125, in run > self.run_command('build') > File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\cmd.py", line 333, in run_command > self.distribution.run_command(command) > File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 995, in run_command > cmd_obj.run() > File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\command\build.py", line 134, in run > self.run_command(cmd_name) > File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\cmd.py", line 333, in run_command > self.distribution.run_command(command) > File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\dist.py", line 995, in run_command > cmd_obj.run() > File "C:\Users\tky\Python\Python-2.6.8\lib\distutils\command\build_ext.py", line 340, in run > self.build_extensions() > File "setup.py", line 167, in build_extensions > raise ValueError("No source directory; cannot proceed.") > ValueError: No source directory; cannot proceed. > > Does anyone know of a way to get bdist_wininst to work out of the box? I am not comfortable with hacking distutils. What do the maintainers do in this case? > > Thanks, > > Tom > > -----Original Message----- > From: python-list-bounces+tky=3ds.com at python.org [mailto:python-list-bounces+tky=3ds.com at python.org] On Behalf Of KACVINSKY Tom > Sent: Wednesday, June 20, 2012 4:29 PM > To: python-list at python.org > Subject: RE: Custom build of Python > > Terry, > > At this stage, I don't want or need an MSI. I just want something that will bundle the executables/dynamic load libraries + compiled Python files and stick them into a compliant directory structure. > > Regards, > > Tom > -----Original Message----- > From: python-list-bounces+tky=3ds.com at python.org [mailto:python-list-bounces+tky=3ds.com at python.org] On Behalf Of Terry Reedy > Sent: Wednesday, June 20, 2012 4:13 PM > To: python-list at python.org > Subject: Re: Custom build of Python > > On 6/20/2012 2:24 PM, KACVINSKY Tom wrote: >> I had reason to build Python 2.6.8 with Microsoft Visual Studio 2010. >> I was able to get the pcbuild solution to build, and I have the >> necessary exes/dlls/pyds in the amd64 build directory. What is not >> clear to is how to complete the build and make an installation. I >> could not find any documentation for this. > > If you mean 'make a .msi file', I am not sure that is not officially supported beyond the inclusion of msilib. > >> Any help on this matter would be appreciated. > > 3.3 is now being built with VS2010. Perhaps its repository has something that will help you. > > -- > Terry Jan Reedy > > > > -- > http://mail.python.org/mailman/listinfo/python-list > This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. > > If you are not one of the named recipients or have received this email in error, > > (i) you should not read, disclose, or copy it, > > (ii) please notify sender of your receipt by reply email and delete this email and all attachments, > > (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. > > For other languages, go to http://www.3ds.com/terms/email-disclaimer > -- > http://mail.python.org/mailman/listinfo/python-list > This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. > > If you are not one of the named recipients or have received this email in error, > > (i) you should not read, disclose, or copy it, > > (ii) please notify sender of your receipt by reply email and delete this email and all attachments, > > (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. > > For other languages, go to http://www.3ds.com/terms/email-disclaimer > From xrsolis at gmail.com Thu Jun 21 23:42:28 2012 From: xrsolis at gmail.com (Xander Solis) Date: Fri, 22 Jun 2012 11:42:28 +0800 Subject: None shown in output Message-ID: Hello Python list, Noob here with a newbie question. I'm reading and working on the exercise of the book, Learn Python the Hard way 2.0. When I use this code, I get "None" on the output. My question is why does this happen? def get_numbers(first_num, second_num, operator): if operator == 'add': print first_num + second_num elif operator == 'minus': print first_num - second_num elif operator == 'divide': print first_num / second_num elif operator == 'multiply': print first_num * second_num print "%r" % (get_numbers(1, 2, 'minus')) print "%r" % (get_numbers(1+3, 2+9, 'add')) print "%r" % (get_numbers(10, 2, 'divide')) Output: C:\code\python>ex19.py -1 None 15 None 5 None 7.5 -- Thanks in advance for your help. Regards, Xander -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at tombstonezero.net Fri Jun 22 00:15:25 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Thu, 21 Jun 2012 21:15:25 -0700 Subject: None shown in output In-Reply-To: References: Message-ID: <20120621211525.06546ebf@particle> On Fri, 22 Jun 2012 11:42:28 +0800 Xander Solis wrote: > Noob here with a newbie question. I'm reading and working on the > exercise of the book, Learn Python the Hard way 2.0. When I use this > code, I get "None" on the output. My question is why does this happen? > > def get_numbers(first_num, second_num, operator): > > if operator == 'add': > print first_num + second_num > elif operator == 'minus': > print first_num - second_num > elif operator == 'divide': > print first_num / second_num > elif operator == 'multiply': > print first_num * second_num This function prints a result, but doesn't return anything. > print "%r" % (get_numbers(1, 2, 'minus')) > print "%r" % (get_numbers(1+3, 2+9, 'add')) > print "%r" % (get_numbers(10, 2, 'divide')) This: (get_numbers(1, 2, 'minus')) calls get_numbers and evaluates to None (because get_numbers doesn't return anything). Then this: "%r" % (get_numbers(1, 2, 'minus')) formats that None into the string "None." Finally, this: print "%r" % (get_numbers(1, 2, 'minus')) prints that string. > Output: > > C:\code\python>ex19.py > -1 This "-1" comes from get_numbers. > None This "None" comes from the print statement that called get_numbers. Contrast your code with this snippet: def add(x, y): return x + y print "%r" % (add(3, 2)) HTH, Dan -- ?? ??? ???? ??????? ??????? -- ????????? Do not disturb my circles. -- Archimedes Dan Sommers, http://www.tombstonezero.net/dan From mhrivnak at hrivnak.org Fri Jun 22 00:21:49 2012 From: mhrivnak at hrivnak.org (Michael Hrivnak) Date: Fri, 22 Jun 2012 00:21:49 -0400 Subject: None shown in output In-Reply-To: References: Message-ID: The last three lines print the return value from the "get_numbers" function, which isn't returning anything. In python, the default return value is None, and that's why you're seeing it. Michael On Thu, Jun 21, 2012 at 11:42 PM, Xander Solis wrote: > Hello Python list, > > Noob here with a newbie question. I'm reading and working on the exercise of > the book, Learn Python the Hard way 2.0. When I use this code, I get "None" > on the output. My question is why does this happen? > > def get_numbers(first_num, second_num, operator): > > ??? if operator == 'add': > ??? ??? print first_num + second_num > ??? elif operator == 'minus': > ??? ??? print first_num - second_num > ??? elif operator == 'divide': > ??? ??? print first_num / second_num > ??? elif operator == 'multiply': > ??? ??? print first_num * second_num > > print "%r" % (get_numbers(1, 2, 'minus')) > print "%r" % (get_numbers(1+3, 2+9, 'add')) > print "%r" % (get_numbers(10, 2, 'divide')) > > Output: > > C:\code\python>ex19.py > -1 > None > 15 > None > 5 > None > 7.5 > > -- > > Thanks in advance for your help. > > Regards, > > Xander > > -- > http://mail.python.org/mailman/listinfo/python-list > From bahamutzero8825 at gmail.com Fri Jun 22 00:23:59 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 21 Jun 2012 23:23:59 -0500 Subject: None shown in output In-Reply-To: References: Message-ID: <4FE3F35F.5060405@gmail.com> On 6/21/2012 10:42 PM, Xander Solis wrote: > Hello Python list, > > Noob here with a newbie question. I'm reading and working on the > exercise of the book, Learn Python the Hard way 2.0. When I use this > code, I get "None" on the output. My question is why does this happen? Your function prints the number and then returns None (you have no return statement in the function to change this) to the print statement. If you want to have the function return a value, use the return statement instead of print inside the function: def func(some_value): return some_value x = func(5) print x will print 5. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From benjamin.kaplan at case.edu Fri Jun 22 00:24:26 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 21 Jun 2012 21:24:26 -0700 Subject: None shown in output In-Reply-To: References: Message-ID: On Thu, Jun 21, 2012 at 8:42 PM, Xander Solis wrote: > Hello Python list, > > Noob here with a newbie question. I'm reading and working on the exercise of > the book, Learn Python the Hard way 2.0. When I use this code, I get "None" > on the output. My question is why does this happen? > > def get_numbers(first_num, second_num, operator): > > ??? if operator == 'add': > ??? ??? print first_num + second_num > ??? elif operator == 'minus': > ??? ??? print first_num - second_num > ??? elif operator == 'divide': > ??? ??? print first_num / second_num > ??? elif operator == 'multiply': > ??? ??? print first_num * second_num > > print "%r" % (get_numbers(1, 2, 'minus')) > print "%r" % (get_numbers(1+3, 2+9, 'add')) > print "%r" % (get_numbers(10, 2, 'divide')) > > Output: > > C:\code\python>ex19.py > -1 > None > 15 > None > 5 > None > 7.5 > > -- > > Thanks in advance for your help. > > Regards, > > Xander > printing something just writes the value to th From benjamin.kaplan at case.edu Fri Jun 22 00:25:48 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 21 Jun 2012 21:25:48 -0700 Subject: None shown in output In-Reply-To: References: Message-ID: damn On Thu, Jun 21, 2012 at 9:24 PM, Benjamin Kaplan wrote: > On Thu, Jun 21, 2012 at 8:42 PM, Xander Solis wrote: >> Hello Python list, >> >> Noob here with a newbie question. I'm reading and working on the exercise of >> the book, Learn Python the Hard way 2.0. When I use this code, I get "None" >> on the output. My question is why does this happen? >> >> def get_numbers(first_num, second_num, operator): >> >> ??? if operator == 'add': >> ??? ??? print first_num + second_num >> ??? elif operator == 'minus': >> ??? ??? print first_num - second_num >> ??? elif operator == 'divide': >> ??? ??? print first_num / second_num >> ??? elif operator == 'multiply': >> ??? ??? print first_num * second_num >> >> print "%r" % (get_numbers(1, 2, 'minus')) >> print "%r" % (get_numbers(1+3, 2+9, 'add')) >> print "%r" % (get_numbers(10, 2, 'divide')) >> >> Output: >> >> C:\code\python>ex19.py >> -1 >> None >> 15 >> None >> 5 >> None >> 7.5 >> >> -- >> >> Thanks in advance for your help. >> >> Regards, >> >> Xander >> > > printing something just writes the value to th I hate when I accidentally hit send early. Anyway, Michael already gave you the reason- print and return two different things. From xrsolis at gmail.com Fri Jun 22 00:33:06 2012 From: xrsolis at gmail.com (Xander Solis) Date: Fri, 22 Jun 2012 12:33:06 +0800 Subject: None shown in output In-Reply-To: <4FE3F35F.5060405@gmail.com> References: <4FE3F35F.5060405@gmail.com> Message-ID: Thanks Andrew and Michael!. That did the trick. def get_numbers(first_num, second_num, operator): if operator == 'add': value = first_num + second_num elif operator == 'minus': value = first_num - second_num elif operator == 'divide': value = first_num / second_num elif operator == 'multiply': value = first_num * second_num return value print "%r" % (get_numbers(1, 2, 'minus')) print "%r" % (get_numbers(1+3, 2+9, 'add')) print "%r" % (get_numbers(10, 2, 'divide')) output: -1 15 5 On Fri, Jun 22, 2012 at 12:23 PM, Andrew Berg wrote: > On 6/21/2012 10:42 PM, Xander Solis wrote: > > Hello Python list, > > > > Noob here with a newbie question. I'm reading and working on the > > exercise of the book, Learn Python the Hard way 2.0. When I use this > > code, I get "None" on the output. My question is why does this happen? > Your function prints the number and then returns None (you have no > return statement in the function to change this) to the print statement. > If you want to have the function return a value, use the return > statement instead of print inside the function: > > def func(some_value): > return some_value > x = func(5) > print x > > will print 5. > > -- > CPython 3.3.0a4 | Windows NT 6.1.7601.17803 > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Jun 22 00:33:37 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 22 Jun 2012 00:33:37 -0400 Subject: None shown in output In-Reply-To: References: Message-ID: On 6/21/2012 11:42 PM, Xander Solis wrote: > Hello Python list, > > Noob here with a newbie question. I'm reading and working on the > exercise of the book, Learn Python the Hard way 2.0. When I use this > code, I get "None" on the output. My question is why does this happen? None is the default return value for python-coded functions and python prints the value of expressions in interactive mode. Hmmm. But you seem to be running in batch mode. But where is 7.5 from. You must be doing more than shown. Regardless, in my opinion, instead of printing, the function should return the computed value. You can then print the returned value. Real software should generally work that way. If nothing else, so you can automate tests instead of checking screen output. > def get_numbers(first_num, second_num, operator): > > if operator == 'add': > print first_num + second_num > elif operator == 'minus': > print first_num - second_num > elif operator == 'divide': > print first_num / second_num > elif operator == 'multiply': > print first_num * second_num > > print "%r" % (get_numbers(1, 2, 'minus')) > print "%r" % (get_numbers(1+3, 2+9, 'add')) > print "%r" % (get_numbers(10, 2, 'divide')) > > Output: > > C:\code\python>ex19.py > -1 > None > 15 > None > 5 > None > 7.5 -- Terry Jan Reedy From xrsolis at gmail.com Fri Jun 22 00:39:00 2012 From: xrsolis at gmail.com (Xander Solis) Date: Fri, 22 Jun 2012 12:39:00 +0800 Subject: None shown in output In-Reply-To: References: Message-ID: Thanks for replying still! Appreciate the help. On Fri, Jun 22, 2012 at 12:25 PM, Benjamin Kaplan wrote: > damn > > On Thu, Jun 21, 2012 at 9:24 PM, Benjamin Kaplan > wrote: > > On Thu, Jun 21, 2012 at 8:42 PM, Xander Solis wrote: > >> Hello Python list, > >> > >> Noob here with a newbie question. I'm reading and working on the > exercise of > >> the book, Learn Python the Hard way 2.0. When I use this code, I get > "None" > >> on the output. My question is why does this happen? > >> > >> def get_numbers(first_num, second_num, operator): > >> > >> if operator == 'add': > >> print first_num + second_num > >> elif operator == 'minus': > >> print first_num - second_num > >> elif operator == 'divide': > >> print first_num / second_num > >> elif operator == 'multiply': > >> print first_num * second_num > >> > >> print "%r" % (get_numbers(1, 2, 'minus')) > >> print "%r" % (get_numbers(1+3, 2+9, 'add')) > >> print "%r" % (get_numbers(10, 2, 'divide')) > >> > >> Output: > >> > >> C:\code\python>ex19.py > >> -1 > >> None > >> 15 > >> None > >> 5 > >> None > >> 7.5 > >> > >> -- > >> > >> Thanks in advance for your help. > >> > >> Regards, > >> > >> Xander > >> > > > > printing something just writes the value to th > > I hate when I accidentally hit send early. Anyway, Michael already > gave you the reason- print and return two different things. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From davecotefilm at gmail.com Fri Jun 22 07:27:41 2012 From: davecotefilm at gmail.com (davecotefilm at gmail.com) Date: Fri, 22 Jun 2012 04:27:41 -0700 (PDT) Subject: use Python to post image to Facebook In-Reply-To: References: Message-ID: <5d93df3b-a0d6-4604-9dbc-3988a06c0317@googlegroups.com> On Monday, 9 April 2012 20:24:54 UTC-7, CM wrote: > Shot in the dark here: has any who reads this group been successful > with getting Python to programmatically post an image to Facebook? > > I've tried using fbconsole[1] and facepy[2], both of which apparently > work fine for their authors and others and although I have an > authorization code, publish permissions, a Facebook app, I get back > these unhelpful errors when I try this (like "an unknown error > occurred"). > > If anyone has been able to do this, maybe you can help me figure out > what I am doing wrong. Hi, I am not sure, but have a similar question. How can I post (upload) an image to google images and return the resulting page..? In python? If you can help I would appreciate it ever so much, Dave:) From ramit.prasad at jpmorgan.com Fri Jun 22 10:12:52 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 22 Jun 2012 14:12:52 +0000 Subject: Jython and PYTHONSTARTUP In-Reply-To: <4fe26a41$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <4fe26a41$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF47413242117@SCACMX008.exchad.jpmchase.net> > Does Jython 2.5 honour the PYTHONSTARTUP environment variable? According > to my testing, it doesn't. > > There used to be a page describing the differences between Jython and > CPython here: > > http://www.jython.org/docs/differences.html > > but it appears to have been eaten by the 404 Monster. Maybe the outdated version will help: http://www.jython.org/archive/21/docs/differences.html For your specific question I see this in the docs, """ The Interactive Startup File When you use Python interactively, it is frequently handy to have some standard commands executed every time the interpreter is started. You can do this by setting an environment variable named PYTHONSTARTUP to the name of a file containing your start-up commands. This is similar to the .profile feature of the Unix shells. This file is only read in interactive sessions, not when Python reads commands from a script, and not when /dev/tty is given as the explicit source of commands (which otherwise behaves like an interactive session). It is executed in the same namespace where interactive commands are executed, so that objects that it defines or imports can be used without qualification in the interactive session. You can also change the prompts sys.ps1 and sys.ps2 in this file. If you want to read an additional start-up file from the current directory, you can program this in the global start-up file using code like if os.path.isfile('.pythonrc.py'): execfile('.pythonrc.py'). If you want to use the startup file in a script, you must do this explicitly in the script: import os filename = os.environ.get('PYTHONSTARTUP') if filename and os.path.isfile(filename): execfile(filename) """ http://www.jython.org/docs/tutorial/interpreter.html?highlight=pythonstartup Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From jerry.rocteur at gmail.com Fri Jun 22 10:28:18 2012 From: jerry.rocteur at gmail.com (Jerry Rocteur) Date: Fri, 22 Jun 2012 16:28:18 +0200 Subject: Python and Facebook Message-ID: Hi, I've done a bit of searching on this but I can find nothing really up to date and a lot of conflicting information about using Python and Facebook. I'd like to automate some tasks in Facebook, for example I'd like to connect to a group I'm admin of and take a copy of all photos, a list of all members and member's info, I'd also like to connect every day and take all the days posts and save them as it is so hard to find back things in groups. I'd like to use Python to do this but I can't find what is the best module to do this or even how to go about doing it. Can someone please put me in the right direction. Thanks in advance, -- Jerry Rocteur jerry at rocteur.com Contact me: Google Talk/jerry.rocteur at gmail.com, Skype/rocteur -------------- next part -------------- An HTML attachment was scrubbed... URL: From spyder.tarsylia at gmail.com Fri Jun 22 10:42:06 2012 From: spyder.tarsylia at gmail.com (=?UTF-8?B?5ZGo6YeR5a6H?=) Date: Fri, 22 Jun 2012 22:42:06 +0800 Subject: bdist_wininst [was: Custom build of Python] In-Reply-To: References: Message-ID: > > INFO: Can't locate Tcl/Tk libs and/or headers > install Tcl/Tk library -------------- next part -------------- An HTML attachment was scrubbed... URL: From albert at spenarnc.xs4all.nl Fri Jun 22 11:53:01 2012 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 Jun 2012 15:53:01 GMT Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la_Interface_Builder_=28Re=3A_what_g?= =?ISO-8859-1?Q?ui_designer_is_everyone_using=29?= References: <20120611140116.001241a2.feliphil@gmx.net> Message-ID: In article , Kevin Walzer wrote: >On 6/11/12 8:01 AM, Wolfgang Keller wrote: >> Tkinter is imho honestly the very best "argument" if you want to make >> potential new users turn their backs away from Python for good. Just >> show them one GUI implemented with it and, hey, wait, where are you >> running to... > >Yes, Tkinter GUI's are very ugly. > >http://www.codebykevin.com/phynchronicity-running.png I looked it up. What you find ugly, I find unconfusing and clear. If I compare it to usual on the web, it is the difference between a waterfall side and an airport where the personell is on strike. (Oh the noise, the noise is unbearable!). I have not, nor intend to write gui things in Python, I just give an impression. [ I want my gui's to be functional, not beautiful. ] > >http://www.codebykevin.com/quickwho-main.png >-- >Kevin Walzer Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From buzzard at urubu.freeserve.co.uk Fri Jun 22 11:58:23 2012 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Fri, 22 Jun 2012 16:58:23 +0100 Subject: emded revision control in Python application? Message-ID: <3B0Fr.226421$MP5.219801@fx27.am4> Hello, I have an application that would benefit from collaborative working. Over time users construct a "data environment" which is a number of files in JSON format contained in a few directories (in the future I'll probably place these in a zip so the environment is contained within a single file). At the moment there is one individual constructing the data environment, and me occasionally applying corrections after being e-mailed the files. But in the future there might be several individuals in various locations. As a minimum requirement I need to embed some sort of version control, so that changes committed by one individual will be seen in the local environments of the others. Some of the work involves editing graphs which have restrictions on their structure. In this case it would be useful for edits to be committed / seen in real time. The users will not be particularly technical, so the version control will have to happen relatively quietly in the background. My immediate thoughts are to (somehow) embed Mercurial or Subversion. It would certainly be useful to be able to revert to a previous version of the data environment if an individual does something silly. But I'm not actually convinced that this is the whole solution for collaborative working. Any advice regarding the embedding of a version control system or alternative approaches would be appreciated. I haven't tried anything like this before. The desktop application is written in Python (2.6) with a wxPython (2.8) GUI. Given the nature of the application / data the machines involved might be locally networked but without web access (if this makes a difference). TIA. Duncan From emile at fenx.com Fri Jun 22 12:42:25 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 22 Jun 2012 09:42:25 -0700 Subject: emded revision control in Python application? In-Reply-To: <3B0Fr.226421$MP5.219801@fx27.am4> References: <3B0Fr.226421$MP5.219801@fx27.am4> Message-ID: On 6/22/2012 8:58 AM duncan smith said... > Hello, > I have an application that would benefit from collaborative working. > Over time users construct a "data environment" which is a number of > files in JSON format contained in a few directories You don't say what your target platform is, but on linux I've done some testing with python-fuse that allows interception on file access to take whatever actions you like, in your case archive prior upon write. Might be worth a look. Emile From ramit.prasad at jpmorgan.com Fri Jun 22 12:48:04 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 22 Jun 2012 16:48:04 +0000 Subject: emded revision control in Python application? In-Reply-To: <3B0Fr.226421$MP5.219801@fx27.am4> References: <3B0Fr.226421$MP5.219801@fx27.am4> Message-ID: <5B80DD153D7D744689F57F4FB69AF47413242327@SCACMX008.exchad.jpmchase.net> > I have an application that would benefit from collaborative > working. Over time users construct a "data environment" which is a > number of files in JSON format contained in a few directories (in the > future I'll probably place these in a zip so the environment is > contained within a single file). At the moment there is one individual > constructing the data environment, and me occasionally applying > corrections after being e-mailed the files. But in the future there > might be several individuals in various locations. > > As a minimum requirement I need to embed some sort of version control, > so that changes committed by one individual will be seen in the local > environments of the others. Some of the work involves editing graphs > which have restrictions on their structure. In this case it would be > useful for edits to be committed / seen in real time. The users will not > be particularly technical, so the version control will have to happen > relatively quietly in the background. > > My immediate thoughts are to (somehow) embed Mercurial or Subversion. It > would certainly be useful to be able to revert to a previous version of > the data environment if an individual does something silly. But I'm not > actually convinced that this is the whole solution for collaborative > working. Any advice regarding the embedding of a version control system > or alternative approaches would be appreciated. I haven't tried anything > like this before. The desktop application is written in Python (2.6) > with a wxPython (2.8) GUI. Given the nature of the application / data > the machines involved might be locally networked but without web access > (if this makes a difference). TIA. Why not just stick the configs (binary blob or JSON string) in something like a sqlite database and store that database centrally accessible[1]? Something like subversion might be overkill. A table like the following would work if you want to track each file separately: table_name( revision_number, file/config name, data, username, timestamp ). Otherwise, if you want to track "environments" and not files: table_name( revision_number, data, username, timestamp ). Where revision number can be a sequence used to track / change current configuration. I recommend storing each file separately in the database. [1] http://www.sqlite.org/faq.html#q5 Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From kushaldas at gmail.com Fri Jun 22 13:54:00 2012 From: kushaldas at gmail.com (Kushal Das) Date: Fri, 22 Jun 2012 23:24:00 +0530 Subject: A question on os.path.join in POSIX systems Message-ID: Hi all, There is a comment on posixpath.join saying "Ignore the previous parts if a part is absolute." Is this defined in the POSIX spec ? If yes, then can someone please point me to a link where I can read about it ? Kushal -- http://fedoraproject.org http://kushaldas.in From chris at python.org Fri Jun 22 14:08:49 2012 From: chris at python.org (Chris Withers) Date: Fri, 22 Jun 2012 19:08:49 +0100 Subject: using SQLalchemy In-Reply-To: References: Message-ID: <4FE4B4B1.40302@python.org> On 21/06/2012 11:50, andrea crotti wrote: > We have a very chaotic database (on MySql) at the moment, with for > I'm trying to use SQLalchemy and it looks absolutely great, but in > general as a policy we don't use external dependencies.. That's a very foolish general policy, a lot of the power of python is in the huge array of excellent third party libraries and frameworks, but each to their own... > To try to do an exception in this case: > - are there any problems with SQLalchemy on Windows? No. > - are there any possibly drawbacks of using SQLalchemy instead of the > MySqlDB interface? You won't be using it instead of mysqldb, you'll be using it as a layer over mysqldb. > For the second point I guess that we might have a bit less fine > tuning, Not so, any tuning you can do direct against the dbapi driver can still be done through SQLAalchemy. > Any other possible issue? If you have problems, I'd suggest asking on the sqlalchemy mailing list: http://groups.google.com/group/sqlalchemy cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From buzzard at urubu.freeserve.co.uk Fri Jun 22 14:19:57 2012 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Fri, 22 Jun 2012 19:19:57 +0100 Subject: emded revision control in Python application? In-Reply-To: References: <3B0Fr.226421$MP5.219801@fx27.am4> Message-ID: On 22/06/12 17:42, Emile van Sebille wrote: > On 6/22/2012 8:58 AM duncan smith said... >> Hello, >> I have an application that would benefit from collaborative working. >> Over time users construct a "data environment" which is a number of >> files in JSON format contained in a few directories > > You don't say what your target platform is, but on linux I've done some > testing with python-fuse that allows interception on file access to take > whatever actions you like, in your case archive prior upon write. > > Might be worth a look. > > Emile > I develop on Linux, but most users would be running some flavour of Windows. Initially I'd like to get something up and running that would allow me to collaborate from an Ubuntu box at home with someone using a Windows machine (not sure which version) in an office at the University of Manchester. The most likely end users would (probably) be running Windows machines on a local network with no internet access. I expect it would generally be possible to have an always-on server, but I'm also thinking about peer to peer style communication (information might not always be completely available, but it's better than being totally unaware of changes being made by others). I don't have much experience getting applications to communicate across a network, particularly in a reasonably secure fashion. Someone I know also suggested RabbitMQ. Any pointers that help me to reduce the options to a manageable number of candidates will be appreciated. A shallow learning curve would also be good (given that ATM this is an idea I want to try out rather than paid work). I am looking at fuse at the moment. Thanks. Duncan From dieter at handshake.de Fri Jun 22 14:25:08 2012 From: dieter at handshake.de (Dieter Maurer) Date: Fri, 22 Jun 2012 20:25:08 +0200 Subject: A question on os.path.join in POSIX systems References: Message-ID: <87y5nfjjaz.fsf@handshake.de> Kushal Das writes: > There is a comment on posixpath.join saying "Ignore the previous parts > if a part is absolute." It means: "join(something, abspath) == abspath" whenever "abspath" is an absolute path. > Is this defined in the POSIX spec ? If yes, then can someone please > point me to a link where I can read about it ? It has nothing to do with POSIX. It just describes a senseful behavior of "join". From emile at fenx.com Fri Jun 22 16:34:15 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 22 Jun 2012 13:34:15 -0700 Subject: emded revision control in Python application? In-Reply-To: References: <3B0Fr.226421$MP5.219801@fx27.am4> Message-ID: On 6/22/2012 11:19 AM duncan smith said... > On 22/06/12 17:42, Emile van Sebille wrote: >> On 6/22/2012 8:58 AM duncan smith said... >>> Hello, >>> I have an application that would benefit from collaborative working. >>> Over time users construct a "data environment" which is a number of >>> files in JSON format contained in a few directories So, will the users modify their local environment and you'd push the revisions to a known location for redistribution? How might peer-to-peer work? How would you know which peers get the change, or would all peers get the change? I've been working with rpyc (in as much spare time as I can manage) on some similar sounding issues and am now settling on a central system which provides convenient administration and potential relaying or pulling. See http://rpyc.sourceforge.net/ I just tested my in-process development status and find 64 remote machines up and 5 non-responsive which in my case are likely machines that are not yet configured properly. As this has been on the back burner the past two months I'm pleased with how it's fared in the face of neglect. At least with rpyc (which does have a low learning curve) you'll be fully in python. Emile >> >> You don't say what your target platform is, but on linux I've done some >> testing with python-fuse that allows interception on file access to take >> whatever actions you like, in your case archive prior upon write. >> >> Might be worth a look. >> >> Emile >> > > I develop on Linux, but most users would be running some flavour of > Windows. Initially I'd like to get something up and running that would > allow me to collaborate from an Ubuntu box at home with someone using a > Windows machine (not sure which version) in an office at the University > of Manchester. The most likely end users would (probably) be running > Windows machines on a local network with no internet access. > > I expect it would generally be possible to have an always-on server, but > I'm also thinking about peer to peer style communication (information > might not always be completely available, but it's better than being > totally unaware of changes being made by others). > > I don't have much experience getting applications to communicate across > a network, particularly in a reasonably secure fashion. Someone I know > also suggested RabbitMQ. Any pointers that help me to reduce the options > to a manageable number of candidates will be appreciated. A shallow > learning curve would also be good (given that ATM this is an idea I want > to try out rather than paid work). I am looking at fuse at the moment. > Thanks. > > Duncan From ramit.prasad at jpmorgan.com Fri Jun 22 16:49:57 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 22 Jun 2012 20:49:57 +0000 Subject: using SQLalchemy In-Reply-To: <4FE4B4B1.40302@python.org> References: <4FE4B4B1.40302@python.org> Message-ID: <5B80DD153D7D744689F57F4FB69AF474132429FF@SCACMX008.exchad.jpmchase.net> > > We have a very chaotic database (on MySql) at the moment, with for > > I'm trying to use SQLalchemy and it looks absolutely great, but in > > general as a policy we don't use external dependencies.. > > That's a very foolish general policy, a lot of the power of python is in > the huge array of excellent third party libraries and frameworks, but > each to their own... That applies to Perl, Python, Java and probably most major languages. I do not know about you, but I do not want to be writing everything from scratch and language developers have better things to do than implementing a dozen (or more) major libraries like lxml and xlwt just to name a few. For that matter, I do not think mysqldb is a built-in Python package. :) Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From tjreedy at udel.edu Fri Jun 22 17:38:25 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 22 Jun 2012 17:38:25 -0400 Subject: Pythonic cross-platform GUI desingers =?UTF-8?B?w6AgbGEgSW50?= =?UTF-8?B?ZXJmYWNlIEJ1aWxkZXIgKFJlOiB3aGF0IGd1aSBkZXNpZ25lciBpcyBldmVyeW8=?= =?UTF-8?B?bmUgdXNpbmcp?= In-Reply-To: References: <20120611140116.001241a2.feliphil@gmx.net> Message-ID: On 6/22/2012 11:53 AM, Albert van der Horst wrote: > In article , > Kevin Walzer wrote: >> On 6/11/12 8:01 AM, Wolfgang Keller wrote: >>> Tkinter is imho honestly the very best "argument" if you want to make >>> potential new users turn their backs away from Python for good. Just >>> show them one GUI implemented with it and, hey, wait, where are you >>> running to... >> >> Yes, Tkinter GUI's are very ugly. >> http://www.codebykevin.com/phynchronicity-running.png > > I looked it up. > > What you find ugly, I find unconfusing and clear. Kevin Walzer is a tk expert. Perhaps you missing the sarcastic irony in what he intended to be a refutation of Wolfgang Keller's comment ;-). -- Terry Jan Reedy From hansmu at xs4all.nl Fri Jun 22 19:46:30 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Sat, 23 Jun 2012 01:46:30 +0200 Subject: Jython and PYTHONSTARTUP In-Reply-To: <4fe26a41$0$29980$c3e8da3$5496439d@news.astraweb.com> References: <4fe26a41$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4fe503d6$0$6981$e4fe514c@news2.news.xs4all.nl> On 21/06/12 02:26:41, Steven D'Aprano wrote: > There used to be a page describing the differences between Jython and > CPython here: > > http://www.jython.org/docs/differences.html > > but it appears to have been eaten by the 404 Monster. It has been moved to: http://www.jython.org/archive/21/docs/differences.html Hope this helps, -- HansM From buzzard at urubu.freeserve.co.uk Fri Jun 22 21:45:06 2012 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Sat, 23 Jun 2012 02:45:06 +0100 Subject: emded revision control in Python application? In-Reply-To: References: <3B0Fr.226421$MP5.219801@fx27.am4> Message-ID: <2b9Fr.304345$ME5.297388@fx22.am4> On 22/06/12 21:34, Emile van Sebille wrote: > On 6/22/2012 11:19 AM duncan smith said... >> On 22/06/12 17:42, Emile van Sebille wrote: >>> On 6/22/2012 8:58 AM duncan smith said... >>>> Hello, >>>> I have an application that would benefit from collaborative working. >>>> Over time users construct a "data environment" which is a number of >>>> files in JSON format contained in a few directories > > So, will the users modify their local environment and you'd push the > revisions to a known location for redistribution? Yes. My rough idea is that each time a user opens the application it will connect to a server and download the current data environment (or preferably just the changes made since the application was last connected). Thus the user can start with an up to date environment. As the application is used to make changes to the data environment any changes are uploaded to the server for immediate redistribution to other connected application instances. Part of the application involves the construction of directed acyclic graphs. If I add an edge to a graph I want anyone else editing the same graph to be able to see the edge in something approaching real time so that cycles are avoided. (Being able to lock the file so that only one user can edit it concurrently might be another solution to this specific issue.) How might peer-to-peer > work? How would you know which peers get the change, or would all peers > get the change? > All peers. I'm not sure about the peer to peer thing though. It would be better if the user could be guaranteed that the environment they see is current, rather than having changes residing on someone else's machine that happens to be switched off. I suppose the alternative must be that the information is sat on a server somewhere. > I've been working with rpyc (in as much spare time as I can manage) on > some similar sounding issues and am now settling on a central system > which provides convenient administration and potential relaying or > pulling. See http://rpyc.sourceforge.net/ > > I just tested my in-process development status and find 64 remote > machines up and 5 non-responsive which in my case are likely machines > that are not yet configured properly. As this has been on the back > burner the past two months I'm pleased with how it's fared in the face > of neglect. > > At least with rpyc (which does have a low learning curve) you'll be > fully in python. > Yes, it looks very interesting. Cheers. Duncan From dihedral88888 at googlemail.com Fri Jun 22 22:52:45 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 22 Jun 2012 19:52:45 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_?= =?ISO-8859-1?Q?Interface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= In-Reply-To: References: <20120611140116.001241a2.feliphil@gmx.net> Message-ID: Albert van der Horst? 2012?6?22????UTC+8??11?53?01???? > In article , > Kevin Walzer wrote: > >On 6/11/12 8:01 AM, Wolfgang Keller wrote: > >> Tkinter is imho honestly the very best "argument" if you want to make > >> potential new users turn their backs away from Python for good. Just > >> show them one GUI implemented with it and, hey, wait, where are you > >> running to... > > > >Yes, Tkinter GUI's are very ugly. > > > >http://www.codebykevin.com/phynchronicity-running.png > > I looked it up. > > What you find ugly, I find unconfusing and clear. > If I compare it to usual on the web, it is the difference > between a waterfall side and an airport where the personell > is on strike. (Oh the noise, the noise is unbearable!). > I have not, nor intend to write gui things in Python, > I just give an impression. > > [ I want my gui's to be functional, not beautiful. ] > > > > > >http://www.codebykevin.com/quickwho-main.png > > >-- > >Kevin Walzer > > Groetjes Albert > > > > -- > -- > Albert van der Horst, UTRECHT,THE NETHERLANDS > Economic growth -- being exponential -- ultimately falters. > albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst I suggest you can use Python with QT to build some GUI and C++ with QT for similar jobs of the commercial versions in order to test the tools. Nowadays the GUI part is so cheap to build with so manny code generation tools, it is not the same as in the years before 2000. From putilovr at gmail.com Sat Jun 23 01:00:36 2012 From: putilovr at gmail.com (Putilov Roman) Date: Sat, 23 Jun 2012 11:00:36 +0600 Subject: use Python to post image to Facebook In-Reply-To: <5d93df3b-a0d6-4604-9dbc-3988a06c0317@googlegroups.com> References: <5d93df3b-a0d6-4604-9dbc-3988a06c0317@googlegroups.com> Message-ID: <4FE54D74.6090008@gmail.com> Try to use http://pycurl.sourceforge.net/ I don't test it, but there is no problem interact with google services. 22.06.12 17:27, davecotefilm at gmail.com ?????: > On Monday, 9 April 2012 20:24:54 UTC-7, CM wrote: >> Shot in the dark here: has any who reads this group been successful >> with getting Python to programmatically post an image to Facebook? >> >> I've tried using fbconsole[1] and facepy[2], both of which apparently >> work fine for their authors and others and although I have an >> authorization code, publish permissions, a Facebook app, I get back >> these unhelpful errors when I try this (like "an unknown error >> occurred"). >> >> If anyone has been able to do this, maybe you can help me figure out >> what I am doing wrong. > Hi, I am not sure, but have a similar question. How can I post (upload) an image to google images and return the resulting page..? In python? > If you can help I would appreciate it ever so much, > Dave:) From rustompmody at gmail.com Sat Jun 23 01:45:07 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 22 Jun 2012 22:45:07 -0700 (PDT) Subject: emded revision control in Python application? References: <3B0Fr.226421$MP5.219801@fx27.am4> Message-ID: On Jun 22, 8:58?pm, duncan smith wrote: > Hello, > ? ? ? ?I have an application that would benefit from collaborative > working. Over time users construct a "data environment" which is a > number of files in JSON format contained in a few directories (in the > future I'll probably place these in a zip so the environment is > contained within a single file). At the moment there is one individual > constructing the data environment, and me occasionally applying > corrections after being e-mailed the files. But in the future there > might be several individuals in various locations. > > As a minimum requirement I need to embed some sort of version control, > so that changes committed by one individual will be seen in the local > environments of the others. Some of the work involves editing graphs > which have restrictions on their structure. In this case it would be > useful for edits to be committed / seen in real time. The users will not > be particularly technical, so the version control will have to happen > relatively quietly in the background. > > My immediate thoughts are to (somehow) embed Mercurial or Subversion. It > would certainly be useful to be able to revert to a previous version of > the data environment if an individual does something silly. But I'm not > actually convinced that this is the whole solution for collaborative > working. Any advice regarding the embedding of a version control system > or alternative approaches would be appreciated. I haven't tried anything > like this before. The desktop application is written in Python (2.6) > with a wxPython (2.8) GUI. Given the nature of the application / data > the machines involved might be locally networked but without web access > (if this makes a difference). TIA. > > Duncan If you are looking at mercurial and subversion you may want to look at git also. >From http://en.wikipedia.org/wiki/Git_%28software%29#Implementation (quoting Linus Torvalds) --------------------------- In many ways you can just see git as a filesystem ? it's content- addressable, and it has a notion of versioning, but I really really designed it coming at the problem from the viewpoint of a filesystem person (hey, kernels is what I do), and I actually have absolutely zero interest in creating a traditional SCM system. More details https://git.wiki.kernel.org/index.php/Git#Design ------------------------- Of course its good to say upfront that git is mostly C+shell ie its not python There is gitpython http://packages.python.org/GitPython/0.1/tutorial.html but I know nothing about it From gmspro at yahoo.com Sat Jun 23 03:02:50 2012 From: gmspro at yahoo.com (gmspro) Date: Sat, 23 Jun 2012 00:02:50 -0700 (PDT) Subject: Can't understand python C apis Message-ID: <1340434970.47291.YahooMailClassic@web164604.mail.gq1.yahoo.com> I'm trying to understand the source code of python and how it works internally. But i can't understand the python C apis. Too much macro calling there and python C api. I can't understand those. I've also read the doc for python C api. What should i do? Which file's code should i read to understand those PyObject or other type and other C apis? Any answer would be highly appreciated. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sat Jun 23 03:45:33 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 23 Jun 2012 09:45:33 +0200 Subject: Can't understand python C apis In-Reply-To: <1340434970.47291.YahooMailClassic@web164604.mail.gq1.yahoo.com> References: <1340434970.47291.YahooMailClassic@web164604.mail.gq1.yahoo.com> Message-ID: gmspro, 23.06.2012 09:02: > I'm trying to understand the source code of python and how it works internally. > But i can't understand the python C apis. > Too much macro calling there and python C api. > I can't understand those. > I've also read the doc for python C api. > > What should i do? Which file's code should i read to understand those PyObject or other type and other C apis? The first thing to ask yourself is: why do you want to understand it? What is the thing you are trying to do with it? Once you've answered that, it'll be easy to tell you where to look. Stefan From dieter at handshake.de Sat Jun 23 05:14:35 2012 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 23 Jun 2012 11:14:35 +0200 Subject: Can't understand python C apis References: <1340434970.47291.YahooMailClassic@web164604.mail.gq1.yahoo.com> Message-ID: <87lijel79g.fsf@handshake.de> gmspro writes: > I'm trying to understand the source code of python and how it works internally. > But i can't understand the python C apis. Usually, you try to understand the Python C api in order to write extensions for Python in C (e.g. to interface with an existing C library or to optimize a tight loop). If this is the case for you, then there is an alternative: "Cython". "Cython" actually is a compiler which compiles an extended Python source language (Python + type/variable declarations + extension types) into "C". With its help, you can create C extensions for Python without a need to know all the details of the Python C API. It might still be necessary at some point to understand more of the API but highly likely it will take considerable time to reach that point -- and then you might already be more familiar and the understanding might be easier. From sg552 at hotmail.co.uk Sat Jun 23 11:34:00 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Sat, 23 Jun 2012 16:34:00 +0100 Subject: cPickle - sharing pickled objects between scripts and imports Message-ID: Hi all, I have a module that saves and loads data using cPickle, and I've encountered a problem. Sometimes I want to import the module and use it in the interactive Python interpreter, whereas sometimes I want to run it as a script. But objects that have been pickled by running the module as a script can't be correctly unpickled by the imported module and vice-versa, since how they get pickled depends on whether the module's __name__ is '__main__' or 'mymodule' (say). I've tried to get around this by adding the following to the module, before any calls to cPickle.load: if __name__ == '__main__': import __main__ def load(f): p = cPickle.Unpickler(f) def fg(m, c): if m == 'mymodule': return getattr(__main__, c) else: m = __import__(m, fromlist = [c]) return getattr(m, c) p.find_global = fg return p.load() else: def load(f): p = cPickle.Unpickler(f) def fg(m, c): if m == '__main__': return globals()[c] else: m = __import__(m, fromlist = [c]) return getattr(m, c) p.find_global = fg return p.load() cPickle.load = load del load It seems to work as far as I can tell, but I'll be grateful if anyone knows of any circumstances where it would fail, or can suggest something less hacky. Also, do cPickle.Pickler instances have some attribute corresponding to find_global that lets one determine how instances get pickled? I couldn't find anything about this in the docs. -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From __peter__ at web.de Sat Jun 23 12:13:56 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 23 Jun 2012 18:13:56 +0200 Subject: cPickle - sharing pickled objects between scripts and imports References: Message-ID: Rotwang wrote: > Hi all, I have a module that saves and loads data using cPickle, and > I've encountered a problem. Sometimes I want to import the module and > use it in the interactive Python interpreter, whereas sometimes I want > to run it as a script. But objects that have been pickled by running the > module as a script can't be correctly unpickled by the imported module > and vice-versa, since how they get pickled depends on whether the > module's __name__ is '__main__' or 'mymodule' (say). I've tried to get > around this by adding the following to the module, before any calls to > cPickle.load: > > if __name__ == '__main__': > import __main__ > def load(f): > p = cPickle.Unpickler(f) > def fg(m, c): > if m == 'mymodule': > return getattr(__main__, c) > else: > m = __import__(m, fromlist = [c]) > return getattr(m, c) > p.find_global = fg > return p.load() > else: > def load(f): > p = cPickle.Unpickler(f) > def fg(m, c): > if m == '__main__': > return globals()[c] > else: > m = __import__(m, fromlist = [c]) > return getattr(m, c) > p.find_global = fg > return p.load() > cPickle.load = load > del load > > > It seems to work as far as I can tell, but I'll be grateful if anyone > knows of any circumstances where it would fail, or can suggest something > less hacky. Also, do cPickle.Pickler instances have some attribute > corresponding to find_global that lets one determine how instances get > pickled? I couldn't find anything about this in the docs. if __name__ == "__main__": from mymodule import * But I think it would be cleaner to move the classes you want to pickle into another module and import that either from your main script or the interpreter. That may also spare you some fun with unexpected isinstance() results. From buzzard at urubu.freeserve.co.uk Sat Jun 23 12:27:51 2012 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Sat, 23 Jun 2012 17:27:51 +0100 Subject: emded revision control in Python application? In-Reply-To: References: <3B0Fr.226421$MP5.219801@fx27.am4> Message-ID: On 23/06/12 06:45, rusi wrote: > On Jun 22, 8:58 pm, duncan smith > wrote: >> Hello, >> I have an application that would benefit from collaborative >> working. Over time users construct a "data environment" which is a >> number of files in JSON format contained in a few directories (in the >> future I'll probably place these in a zip so the environment is >> contained within a single file). At the moment there is one individual >> constructing the data environment, and me occasionally applying >> corrections after being e-mailed the files. But in the future there >> might be several individuals in various locations. >> >> As a minimum requirement I need to embed some sort of version control, >> so that changes committed by one individual will be seen in the local >> environments of the others. Some of the work involves editing graphs >> which have restrictions on their structure. In this case it would be >> useful for edits to be committed / seen in real time. The users will not >> be particularly technical, so the version control will have to happen >> relatively quietly in the background. >> >> My immediate thoughts are to (somehow) embed Mercurial or Subversion. It >> would certainly be useful to be able to revert to a previous version of >> the data environment if an individual does something silly. But I'm not >> actually convinced that this is the whole solution for collaborative >> working. Any advice regarding the embedding of a version control system >> or alternative approaches would be appreciated. I haven't tried anything >> like this before. The desktop application is written in Python (2.6) >> with a wxPython (2.8) GUI. Given the nature of the application / data >> the machines involved might be locally networked but without web access >> (if this makes a difference). TIA. >> >> Duncan > > If you are looking at mercurial and subversion you may want to look at > git also. > > From http://en.wikipedia.org/wiki/Git_%28software%29#Implementation > (quoting Linus Torvalds) > --------------------------- > In many ways you can just see git as a filesystem ? it's content- > addressable, and it has a notion of versioning, but I really really > designed it coming at the problem from the viewpoint of a filesystem > person (hey, kernels is what I do), and I actually have absolutely > zero interest in creating a traditional SCM system. > > More details https://git.wiki.kernel.org/index.php/Git#Design > ------------------------- > Of course its good to say upfront that git is mostly C+shell ie its > not python > There is gitpython http://packages.python.org/GitPython/0.1/tutorial.html > but I know nothing about it Thanks. I'm trying to figure out whether I'm better of with a version control system, a virtual filesystem (e.g. http://code.google.com/p/pyfilesystem/), remote procedure calls or some combination of these. What I really need is a flexible framework that I can experiment with, as it's not clear what the best strategy for collaborative working might be. e.g. It might be best to restrict working on certain elements of the data environment to a single individual. Cheers. Duncan From gundlach at gmail.com Sat Jun 23 13:29:37 2012 From: gundlach at gmail.com (Michael Gundlach) Date: Sat, 23 Jun 2012 13:29:37 -0400 Subject: SSL handshake hanging, despite bugfix in stdlib Message-ID: Hello, http://bugs.python.org/issue5103 fixed a bug in Python2.6 where SSL's handshake would hang indefinitely if the remote end hangs. However, I'm getting hanging behavior in an IMAP script. When I Ctrl-C it after hours of hanging, I get the same stacktrace as reported in http://bugs.python.org/issue1251#msg72363 , though Antoine said that r80452 fixed issue 5103 as well as this bug. This script sends automatic response emails. Every 10 seconds it uses IMAP to check for unread messages in a GMail label, then replies via SMTP and marks the message as read. The script seems to work the first time an unread message is found; the next time there's a message to be had, it hangs trying to complete the SSL handshake. File "./main.py", line 21, in thank_new_signups the_emails = list(emails.messages('(UNSEEN)')) File "./emails.py", line 129, in messages for chunk in chunks_of_length(32, messages): File "./chunks.py", line 9, in chunks_of_length for item in iterable: File "./emails.py", line 90, in email_messages m = open_mailbox(label, readonly=True) File "./emails.py", line 30, in open_mailbox m = imaplib.IMAP4_SSL('imap.gmail.com', 993) File "/usr/lib64/python2.6/imaplib.py", line 1138, in __init__ IMAP4.__init__(self, host, port) File "/usr/lib64/python2.6/imaplib.py", line 163, in __init__ self.open(host, port) File "/usr/lib64/python2.6/imaplib.py", line 1150, in open self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) File "/usr/lib64/python2.6/ssl.py", line 338, in wrap_socket suppress_ragged_eofs=suppress_ragged_eofs) File "/usr/lib64/python2.6/ssl.py", line 120, in __init__ self.do_handshake() File "/usr/lib64/python2.6/ssl.py", line 279, in do_handshake self._sslobj.do_handshake() KeyboardInterrupt (This behavior started only in the last couple of weeks after a longer period working correctly, so I suspect something changed on GMail's end to trigger the bug.) Am I do something wrong, or is this bug still not fixed? Any pointers would be appreciated. Python 2.6.6 (r266:84292, Dec 7 2011, 20:48:22) on 64-bit Linux 2.6.32. Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Sat Jun 23 13:31:38 2012 From: d at davea.name (Dave Angel) Date: Sat, 23 Jun 2012 13:31:38 -0400 Subject: cPickle - sharing pickled objects between scripts and imports In-Reply-To: References: Message-ID: <4FE5FD7A.8050509@davea.name> On 06/23/2012 12:13 PM, Peter Otten wrote: > Rotwang wrote: > >> Hi all, I have a module that saves and loads data using cPickle, and >> I've encountered a problem. Sometimes I want to import the module and >> use it in the interactive Python interpreter, whereas sometimes I want >> to run it as a script. But objects that have been pickled by running the >> module as a script can't be correctly unpickled by the imported module >> and vice-versa, since how they get pickled depends on whether the >> module's __name__ is '__main__' or 'mymodule' (say). I've tried to get >> around this by adding the following to the module, before any calls to >> cPickle.load: >> >> if __name__ == '__main__': >> import __main__ >> def load(f): >> p = cPickle.Unpickler(f) >> def fg(m, c): >> if m == 'mymodule': >> return getattr(__main__, c) >> else: >> m = __import__(m, fromlist = [c]) >> return getattr(m, c) >> p.find_global = fg >> return p.load() >> else: >> def load(f): >> p = cPickle.Unpickler(f) >> def fg(m, c): >> if m == '__main__': >> return globals()[c] >> else: >> m = __import__(m, fromlist = [c]) >> return getattr(m, c) >> p.find_global = fg >> return p.load() >> cPickle.load = load >> del load >> >> >> It seems to work as far as I can tell, but I'll be grateful if anyone >> knows of any circumstances where it would fail, or can suggest something >> less hacky. Also, do cPickle.Pickler instances have some attribute >> corresponding to find_global that lets one determine how instances get >> pickled? I couldn't find anything about this in the docs. > if __name__ == "__main__": > from mymodule import * > > But I think it would be cleaner to move the classes you want to pickle into > another module and import that either from your main script or the > interpreter. That may also spare you some fun with unexpected isinstance() > results. > > I would second the choice to just move the code to a separately loaded module, and let your script simply consist of an import and a call into that module. It can be very dangerous to have the same module imported two different ways (as __main__ and as mymodule), so i'd avoid anything that came close to that notion. Your original problem is probably that you have classes with two leading underscores, which causes the names to be mangled with the module name. You could simply remove one of the underscores for all such names, and see if the pickle problem goes away. -- DaveA From sg552 at hotmail.co.uk Sat Jun 23 13:51:43 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Sat, 23 Jun 2012 18:51:43 +0100 Subject: cPickle - sharing pickled objects between scripts and imports In-Reply-To: References: Message-ID: On 23/06/2012 17:13, Peter Otten wrote: > Rotwang wrote: > >> Hi all, I have a module that saves and loads data using cPickle, and >> I've encountered a problem. Sometimes I want to import the module and >> use it in the interactive Python interpreter, whereas sometimes I want >> to run it as a script. But objects that have been pickled by running the >> module as a script can't be correctly unpickled by the imported module >> and vice-versa, since how they get pickled depends on whether the >> module's __name__ is '__main__' or 'mymodule' (say). I've tried to get >> around this by adding the following to the module, before any calls to >> cPickle.load: >> >> if __name__ == '__main__': >> import __main__ >> def load(f): >> p = cPickle.Unpickler(f) >> def fg(m, c): >> if m == 'mymodule': >> return getattr(__main__, c) >> else: >> m = __import__(m, fromlist = [c]) >> return getattr(m, c) >> p.find_global = fg >> return p.load() >> else: >> def load(f): >> p = cPickle.Unpickler(f) >> def fg(m, c): >> if m == '__main__': >> return globals()[c] >> else: >> m = __import__(m, fromlist = [c]) >> return getattr(m, c) >> p.find_global = fg >> return p.load() >> cPickle.load = load >> del load >> >> >> It seems to work as far as I can tell, but I'll be grateful if anyone >> knows of any circumstances where it would fail, or can suggest something >> less hacky. Also, do cPickle.Pickler instances have some attribute >> corresponding to find_global that lets one determine how instances get >> pickled? I couldn't find anything about this in the docs. > > if __name__ == "__main__": > from mymodule import * > > But I think it would be cleaner to move the classes you want to pickle into > another module and import that either from your main script or the > interpreter. That may also spare you some fun with unexpected isinstance() > results. Thanks. -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From sg552 at hotmail.co.uk Sat Jun 23 14:14:43 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Sat, 23 Jun 2012 19:14:43 +0100 Subject: cPickle - sharing pickled objects between scripts and imports In-Reply-To: References: Message-ID: On 23/06/2012 18:31, Dave Angel wrote: > On 06/23/2012 12:13 PM, Peter Otten wrote: >> Rotwang wrote: >> >>> Hi all, I have a module that saves and loads data using cPickle, and >>> I've encountered a problem. Sometimes I want to import the module and >>> use it in the interactive Python interpreter, whereas sometimes I want >>> to run it as a script. But objects that have been pickled by running the >>> module as a script can't be correctly unpickled by the imported module >>> and vice-versa, since how they get pickled depends on whether the >>> module's __name__ is '__main__' or 'mymodule' (say). I've tried to get >>> around this by adding the following to the module, before any calls to >>> cPickle.load: >>> >>> if __name__ == '__main__': >>> import __main__ >>> def load(f): >>> p = cPickle.Unpickler(f) >>> def fg(m, c): >>> if m == 'mymodule': >>> return getattr(__main__, c) >>> else: >>> m = __import__(m, fromlist = [c]) >>> return getattr(m, c) >>> p.find_global = fg >>> return p.load() >>> else: >>> def load(f): >>> p = cPickle.Unpickler(f) >>> def fg(m, c): >>> if m == '__main__': >>> return globals()[c] >>> else: >>> m = __import__(m, fromlist = [c]) >>> return getattr(m, c) >>> p.find_global = fg >>> return p.load() >>> cPickle.load = load >>> del load >>> >>> >>> It seems to work as far as I can tell, but I'll be grateful if anyone >>> knows of any circumstances where it would fail, or can suggest something >>> less hacky. Also, do cPickle.Pickler instances have some attribute >>> corresponding to find_global that lets one determine how instances get >>> pickled? I couldn't find anything about this in the docs. >> if __name__ == "__main__": >> from mymodule import * >> >> But I think it would be cleaner to move the classes you want to pickle into >> another module and import that either from your main script or the >> interpreter. That may also spare you some fun with unexpected isinstance() >> results. >> >> > > > > I would second the choice to just move the code to a separately loaded > module, and let your script simply consist of an import and a call into > that module. > > It can be very dangerous to have the same module imported two different > ways (as __main__ and as mymodule), so i'd avoid anything that came > close to that notion. OK, thanks. > Your original problem is probably that you have classes with two leading > underscores, which causes the names to be mangled with the module name. > You could simply remove one of the underscores for all such names, and > see if the pickle problem goes away. No, I don't have any such classes. The problem is that if the object was pickled by the module run as a script and then unpickled by the imported module, the unpickler looks in __main__ rather than mymodule for the object's class, and doesn't find it. Conversely if the object was pickled by the imported module and then unpickled by the module run as a script then the unpickler reloads the module and makes objects referenced by the original object into instances of mymodule.oneofmyclasses, whereas (for reasons unknown to me) the object itself is an instance of __main__.anotheroneofmyclasses. This means that any method of anotheroneofmyclasses that calls isinstance(attribute, oneofmyclasses) doesn't work the way it should. -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From steve+comp.lang.python at pearwood.info Sat Jun 23 19:17:55 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Jun 2012 23:17:55 GMT Subject: cPickle - sharing pickled objects between scripts and imports References: Message-ID: <4fe64ea3$0$29981$c3e8da3$5496439d@news.astraweb.com> On Sat, 23 Jun 2012 19:14:43 +0100, Rotwang wrote: > The problem is that if the object was > pickled by the module run as a script and then unpickled by the imported > module, the unpickler looks in __main__ rather than mymodule for the > object's class, and doesn't find it. Possibly the solution is as simple as aliasing your module and __main__. Untested: # When running as a script import __main__ sys['mymodule'] = __main__ # When running interactively import mymodule __main__ = mymodule of some variation thereof. Note that a full solution to this problem actually requires you to deal with three cases: 1) interactive interpreter, __main__ normally would be the interpreter global scope 2) running as a script, __main__ is your script 3) imported into another module which is running as a script, __main__ would be that module. In the last case, monkey-patching __main__ may very well break that script. -- Steven From gmspro at yahoo.com Sat Jun 23 20:16:39 2012 From: gmspro at yahoo.com (gmspro) Date: Sat, 23 Jun 2012 17:16:39 -0700 (PDT) Subject: Why is python source code not available on github? Message-ID: <1340496999.60745.YahooMailClassic@web164602.mail.gq1.yahoo.com> Why is python source code not available on github? Make it available on github so that we can git clone and work on source code. -------------- next part -------------- An HTML attachment was scrubbed... URL: From georger.silva at gmail.com Sat Jun 23 20:23:03 2012 From: georger.silva at gmail.com (George Silva) Date: Sat, 23 Jun 2012 21:23:03 -0300 Subject: Why is python source code not available on github? In-Reply-To: <1340496999.60745.YahooMailClassic@web164602.mail.gq1.yahoo.com> References: <1340496999.60745.YahooMailClassic@web164602.mail.gq1.yahoo.com> Message-ID: http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 On Sat, Jun 23, 2012 at 9:16 PM, gmspro wrote: > Why is python source code not available on github? > > Make it available on github so that we can git clone and work on source > code. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- George R. C. Silva Desenvolvimento em GIS http://geoprocessamento.net http://blog.geoprocessamento.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Sat Jun 23 20:28:25 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 23 Jun 2012 19:28:25 -0500 Subject: Why is python source code not available on github? In-Reply-To: <1340496999.60745.YahooMailClassic@web164602.mail.gq1.yahoo.com> References: <1340496999.60745.YahooMailClassic@web164602.mail.gq1.yahoo.com> Message-ID: <4FE65F29.1080705@gmail.com> On 6/23/2012 7:16 PM, gmspro wrote: > Why is python source code not available on github? If you mean CPython, it's because the devs use Mercurial and have their own hosting on python.org. hg clone http://hg.python.org/cpython http://docs.python.org/devguide/setup.html github is far from the only place to host an open source project. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From rosuav at gmail.com Sat Jun 23 20:30:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jun 2012 10:30:20 +1000 Subject: Why is python source code not available on github? In-Reply-To: <1340496999.60745.YahooMailClassic@web164602.mail.gq1.yahoo.com> References: <1340496999.60745.YahooMailClassic@web164602.mail.gq1.yahoo.com> Message-ID: On Sun, Jun 24, 2012 at 10:16 AM, gmspro wrote: > > Why is python source code not available on github? > > Make it available on github so that we can git clone and work on source > code. It's done with Mercurial, not git, but the same can be done: hg clone http://hg.python.org/cpython ChrisA From gmspro at yahoo.com Sat Jun 23 20:34:29 2012 From: gmspro at yahoo.com (gmspro) Date: Sat, 23 Jun 2012 17:34:29 -0700 (PDT) Subject: Why is python source code not available on github? In-Reply-To: Message-ID: <1340498069.15460.YahooMailClassic@web164606.mail.gq1.yahoo.com> No, I can download as .tar.bz2, but i'm talking about using git. git clone, git add ., git commit -a, git push is easier to keep track of my code. Then for git pull request. --- On Sat, 6/23/12, George Silva wrote: From: George Silva Subject: Re: Why is python source code not available on github? To: "gmspro" Cc: python-list at python.org Date: Saturday, June 23, 2012, 7:23 PM http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 On Sat, Jun 23, 2012 at 9:16 PM, gmspro wrote: Why is python source code not available on github? Make it available on github so that we can git clone and work on source code. -- http://mail.python.org/mailman/listinfo/python-list -- George R. C. Silva Desenvolvimento em GIS http://geoprocessamento.net http://blog.geoprocessamento.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Jun 23 20:42:10 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jun 2012 10:42:10 +1000 Subject: Why is python source code not available on github? In-Reply-To: <1340498069.15460.YahooMailClassic@web164606.mail.gq1.yahoo.com> References: <1340498069.15460.YahooMailClassic@web164606.mail.gq1.yahoo.com> Message-ID: On Sun, Jun 24, 2012 at 10:34 AM, gmspro wrote: > > No, > I can download as .tar.bz2, but i'm talking about using git. > git clone, git add ., git commit -a, git push is easier to keep track of > my code. Then for git pull request. Mercurial can do all that. I'm not as familiar with it as I am with git, so I can't quote the commands, but certainly you can do all the same clone/add/commit/etc with it. I build my cpython straight from hg, mainly because I like living on the edge :) ChrisA From gmspro at yahoo.com Sat Jun 23 20:54:25 2012 From: gmspro at yahoo.com (gmspro) Date: Sat, 23 Jun 2012 17:54:25 -0700 (PDT) Subject: Filenames started with _(underscore) in Modules/ why? Message-ID: <1340499265.33518.YahooMailClassic@web164601.mail.gq1.yahoo.com> There are some files whose filename is started with _(underscore). Why are they started with a underscore? -------------- next part -------------- An HTML attachment was scrubbed... URL: From t at jollybox.de Sat Jun 23 21:45:12 2012 From: t at jollybox.de (Thomas Jollans) Date: Sun, 24 Jun 2012 03:45:12 +0200 Subject: Filenames started with _(underscore) in Modules/ why? In-Reply-To: <1340499265.33518.YahooMailClassic@web164601.mail.gq1.yahoo.com> References: <1340499265.33518.YahooMailClassic@web164601.mail.gq1.yahoo.com> Message-ID: <4FE67128.1010506@jollybox.de> On 06/24/2012 02:54 AM, gmspro wrote: > There are some files whose filename is started with _(underscore). Why > are they started with > a underscore? By convention, a leading underscore means private/internal. A module with a leading underscore is typically an implementation detail of another module with a public API, and should be ignored. From Joshua.R.English at gmail.com Sat Jun 23 21:58:11 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Sat, 23 Jun 2012 18:58:11 -0700 (PDT) Subject: Getting lazy with decorators Message-ID: <9d0c01f4-4430-4a45-8776-20d8dede9e14@googlegroups.com> I'm creating a cmd.Cmd class, and I have developed a helper method to easily handle help_xxx methods. I'm trying to figure out if there is an even lazier way I could do this with decorators. Here is the code: ********************* import cmd def add_help(func): if not hasattr(func, 'im_class'): return func #probably should raise an error cls = func.im_class setattr(cls, func.im_func.__name__.replace("do","help"), None) return func class BaseCmd(cmd.Cmd): def __init__(self, *args, **kwargs): cmd.Cmd.__init__(self, *args, **kwargs) def show_help(self, func): print "\n".join((line.strip() for line in func.__doc__.splitlines())) @add_help def do_done(self, line): """done Quits this and goes to higher level or quits the application. I mean, what else do you expect? """ return True if __name__=='__main__': c = BaseCmd() print c.help_done ********************* This generates "AttributeError: BaseCmd instance has no attribute 'help_done'" The show_help method is the shortcut I want to use (I'm pretty sure it's from Doug Hellman's site). I'm wondering if it's possible to use a decorator such as add_help to automatically create the appropriate help_xxx function. In the decorator, I can get the function and the name of the class, but I can't find the instance of the class that the method is attached to. Maybe this is just one step of lazy too far. Am I right in thinking that I can't do this? There is no way to access the class instance from the method? From gmspro at yahoo.com Sat Jun 23 22:23:16 2012 From: gmspro at yahoo.com (gmspro) Date: Sat, 23 Jun 2012 19:23:16 -0700 (PDT) Subject: How can i call array_length to get the length of array object? Message-ID: <1340504596.65359.YahooMailClassic@web164606.mail.gq1.yahoo.com> Hi, I tried this, >>> import array >>> from array import array >>> arr=array('i',[5,7,8]) >>> arr.sg_length Traceback (most recent call last): ? File "", line 1, in AttributeError: 'array.array' object has no attribute 'sg_length' >>> arr=array('i'[5,8,7]) Traceback (most recent call last): ? File "", line 1, in TypeError: string indices must be integers >>> arr=array('i',[5,8,7]) >>> arr.length Traceback (most recent call last): ? File "", line 1, in AttributeError: 'array.array' object has no attribute 'length' >>> arr.length() Traceback (most recent call last): ? File "", line 1, in AttributeError: 'array.array' object has no attribute 'length' >>> length(arr) Traceback (most recent call last): ? File "", line 1, in NameError: name 'length' is not defined >>> array_length(arr) Traceback (most recent call last): ? File "", line 1, in NameError: name 'array_length' is not defined >>> arr.array_length() Traceback (most recent call last): ? File "", line 1, in AttributeError: 'array.array' object has no attribute 'array_length' >>> arr.array_length Traceback (most recent call last): ? File "", line 1, in AttributeError: 'array.array' object has no attribute 'array_length' I'm trying to call this function, http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 Is that possible to call that function? I know it's possible to do: >>>len(arr) >>>arr.itemsize Any asnwer will be highly appreciated. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ignacio.mondino at gmail.com Sat Jun 23 23:34:09 2012 From: ignacio.mondino at gmail.com (Ignacio Mondino) Date: Sun, 24 Jun 2012 00:34:09 -0300 Subject: How can i call array_length to get the length of array object? In-Reply-To: <1340504596.65359.YahooMailClassic@web164606.mail.gq1.yahoo.com> References: <1340504596.65359.YahooMailClassic@web164606.mail.gq1.yahoo.com> Message-ID: On Sat, Jun 23, 2012 at 11:23 PM, gmspro wrote: > > Hi, > > I tried this, > >>> import array > >>> from array import array > >>> arr=array('i',[5,7,8]) > >>> arr.sg_length > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'array.array' object has no attribute 'sg_length' > >>> arr=array('i'[5,8,7]) > Traceback (most recent call last): > ? File "", line 1, in > TypeError: string indices must be integers > >>> arr=array('i',[5,8,7]) > >>> arr.length > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'array.array' object has no attribute 'length' > >>> arr.length() > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'array.array' object has no attribute 'length' > >>> length(arr) > Traceback (most recent call last): > ? File "", line 1, in > NameError: name 'length' is not defined > >>> array_length(arr) > Traceback (most recent call last): > ? File "", line 1, in > NameError: name 'array_length' is not defined > >>> arr.array_length() > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'array.array' object has no attribute 'array_length' > >>> arr.array_length > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'array.array' object has no attribute 'array_length' > > I'm trying to call this function, http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 > > Is that possible to call that function? > > I know it's possible to do: > >>>len(arr) > >>>arr.itemsize > > Any asnwer will be highly appreciated. > > Thanks. > > -- > http://mail.python.org/mailman/listinfo/python-list Hi, something along the lines >>> s = 'supercalifragilisticexpialidocious' >>> len(s) 34 check http://docs.python.org/ for more on this. Ignacio From gmspro at yahoo.com Sat Jun 23 23:40:54 2012 From: gmspro at yahoo.com (gmspro) Date: Sat, 23 Jun 2012 20:40:54 -0700 (PDT) Subject: How can i call array_length to get the length of array object? In-Reply-To: Message-ID: <1340509254.12271.YahooMailClassic@web164601.mail.gq1.yahoo.com> @Ignacio Mondino, Doesn't it call this : http://hg.python.org/cpython/file/c0eab397f098/Python/bltinmodule.c#l1283 instead of this: http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 --- On Sat, 6/23/12, Ignacio Mondino wrote: From: Ignacio Mondino Subject: Re: How can i call array_length to get the length of array object? To: "gmspro" Cc: "python-list" Date: Saturday, June 23, 2012, 10:34 PM On Sat, Jun 23, 2012 at 11:23 PM, gmspro wrote: > > Hi, > > I tried this, > >>> import array > >>> from array import array > >>> arr=array('i',[5,7,8]) > >>> arr.sg_length > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'array.array' object has no attribute 'sg_length' > >>> arr=array('i'[5,8,7]) > Traceback (most recent call last): > ? File "", line 1, in > TypeError: string indices must be integers > >>> arr=array('i',[5,8,7]) > >>> arr.length > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'array.array' object has no attribute 'length' > >>> arr.length() > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'array.array' object has no attribute 'length' > >>> length(arr) > Traceback (most recent call last): > ? File "", line 1, in > NameError: name 'length' is not defined > >>> array_length(arr) > Traceback (most recent call last): > ? File "", line 1, in > NameError: name 'array_length' is not defined > >>> arr.array_length() > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'array.array' object has no attribute 'array_length' > >>> arr.array_length > Traceback (most recent call last): > ? File "", line 1, in > AttributeError: 'array.array' object has no attribute 'array_length' > > I'm trying to call this function, http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 > > Is that possible to call that function? > > I know it's possible to do: > >>>len(arr) > >>>arr.itemsize > > Any asnwer will be highly appreciated. > > Thanks. > > -- > http://mail.python.org/mailman/listinfo/python-list Hi, something along the lines >>> s = 'supercalifragilisticexpialidocious' >>> len(s) 34 check http://docs.python.org/ for more on this. Ignacio -------------- next part -------------- An HTML attachment was scrubbed... URL: From gmspro at yahoo.com Sat Jun 23 23:46:44 2012 From: gmspro at yahoo.com (gmspro) Date: Sat, 23 Jun 2012 20:46:44 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? Message-ID: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> Hi, Why has python3 been created as a seperate language where there is still python2.7 ? What's the benifit to make python3 over python2.7 ? I have read this though: http://docs.python.org/release/3.0.1/whatsnew/3.0.html What's wrong editing/customizing/changin python2.7 instead of making a seperate language? What's wrong working with python2.7? As python3 is not backward compatible, so many packages built on python2.7 will be gone someday. Or you have to re-write/upgrade to python3. That's a tedious/labourious task. So after 5 years will we get another python4 as seperate language? Any answer will be highly appreciated. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Jun 24 01:12:56 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 24 Jun 2012 01:12:56 -0400 Subject: SSL handshake hanging, despite bugfix in stdlib In-Reply-To: References: Message-ID: On 6/23/2012 1:29 PM, Michael Gundlach wrote: > Hello, > > http://bugs.python.org/issue5103 fixed a bug in Python2.6 where SSL's I believe the fix first appeared in 2.6.6. > handshake would hang indefinitely if the remote end hangs. > > However, I'm getting hanging behavior in an IMAP script. When I Ctrl-C > it after hours of hanging, I get the same stacktrace as reported in > http://bugs.python.org/issue1251#msg72363 , though Antoine said that > r80452 fixed issue 5103 as well as this bug. He claimed that it should fix 1251, but I cannot see that there was a dependable code for making the problem appear. > (This behavior started only in the last couple of weeks after a longer > period working correctly, so I suspect something changed on GMail's end > to trigger the bug.) Possible. > Am I do something wrong, or is this bug still not fixed? Any pointers > would be appreciated. Python 2.6.6 (r266:84292, Dec 7 2011, 20:48:22) > on 64-bit Linux 2.6.32. > Michael If you want any attention from developers, you will have to show a problem with 2.7.3 or latest 3.2+. I do not know that there is much change in 2.7, but I know there is more in change in 3.3 (the do_handshake call is moved and has a different context. -- Terry Jan Reedy From ian.g.kelly at gmail.com Sun Jun 24 01:34:26 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 23 Jun 2012 23:34:26 -0600 Subject: How can i call array_length to get the length of array object? In-Reply-To: <1340504596.65359.YahooMailClassic@web164606.mail.gq1.yahoo.com> References: <1340504596.65359.YahooMailClassic@web164606.mail.gq1.yahoo.com> Message-ID: On Sat, Jun 23, 2012 at 8:23 PM, gmspro wrote: > I'm trying to call this function, http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 > > Is that possible to call that function? > > I know it's possible to do: > >>>len(arr) You call it just like that. array_length is the C implementation of __len__ for arrays. > Doesn't it call this : > http://hg.python.org/cpython/file/c0eab397f098/Python/bltinmodule.c#l1283 > instead of this: > http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 Yes, and builtin_len calls PyObject_Size, which in turn calls the object's sq_length method, which is defined to be array_length for arrays. From gmspro at yahoo.com Sun Jun 24 04:01:53 2012 From: gmspro at yahoo.com (gmspro) Date: Sun, 24 Jun 2012 01:01:53 -0700 (PDT) Subject: How can i call array_length to get the length of array object? In-Reply-To: Message-ID: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> Why are some methods/functions named in this way in python? __len__ underscoreunderscoreNAMEunderscoreunderscore Is there any speciality of naming such methods? --- On Sun, 6/24/12, Ian Kelly wrote: From: Ian Kelly Subject: Re: How can i call array_length to get the length of array object? To: "gmspro" Cc: "python-list" Date: Sunday, June 24, 2012, 12:34 AM On Sat, Jun 23, 2012 at 8:23 PM, gmspro wrote: > I'm trying to call this function, http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 > > Is that possible to call that function? > > I know it's possible to do: > >>>len(arr) You call it just like that.? array_length is the C implementation of __len__ for arrays. > Doesn't it call this : > http://hg.python.org/cpython/file/c0eab397f098/Python/bltinmodule.c#l1283 > instead of this: > http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 Yes, and builtin_len calls PyObject_Size, which in turn calls the object's sq_length method, which is defined to be array_length for arrays. -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sun Jun 24 04:07:45 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 24 Jun 2012 10:07:45 +0200 Subject: Getting lazy with decorators References: <9d0c01f4-4430-4a45-8776-20d8dede9e14@googlegroups.com> Message-ID: Josh English wrote: > I'm creating a cmd.Cmd class, and I have developed a helper method to > easily handle help_xxx methods. > > I'm trying to figure out if there is an even lazier way I could do this > with decorators. > > Here is the code: > ********************* > import cmd > > > def add_help(func): > if not hasattr(func, 'im_class'): > return func #probably should raise an error > cls = func.im_class > setattr(cls, func.im_func.__name__.replace("do","help"), None) > > return func > > > class BaseCmd(cmd.Cmd): > def __init__(self, *args, **kwargs): > cmd.Cmd.__init__(self, *args, **kwargs) > > def show_help(self, func): > print "\n".join((line.strip() for line in > func.__doc__.splitlines())) > > @add_help > def do_done(self, line): > """done > Quits this and goes to higher level or quits the application. > I mean, what else do you expect? > """ > return True > > if __name__=='__main__': > c = BaseCmd() > > print c.help_done > > > ********************* > > This generates "AttributeError: BaseCmd instance has no attribute > 'help_done'" > > The show_help method is the shortcut I want to use (I'm pretty sure it's > from Doug Hellman's site). I'm wondering if it's possible to use a > decorator such as add_help to automatically create the appropriate > help_xxx function. > > In the decorator, I can get the function and the name of the class, but I > can't find the instance of the class that the method is attached to. > Maybe this is just one step of lazy too far. > > > Am I right in thinking that I can't do this? There is no way to access the > class instance from the method? You cannot access a class instance because even the class itself doesn't exist yet. You could get hold of the class namespace with sys._getframe(), def add_help(f): exec """\ def help_%s(self): f = getattr(self, %r) self.show_help(f) """ % (f.__name__[3:], f.__name__) in sys._getframe(1).f_locals return f but here's a simpler approach: import cmd def add_help(f): def help(self): self.show_help(f) f.help = help return f class BaseCmd(cmd.Cmd): def __init__(self, *args, **kwargs): cmd.Cmd.__init__(self, *args, **kwargs) def show_help(self, func): print "\n".join((line.strip() for line in func.__doc__.splitlines())) def __getattr__(self, name): if name.startswith("help_"): helpfunc = getattr(self, "do_" + name[5:]).help setattr(self.__class__, name, helpfunc) return getattr(self, name) raise AttributeError @add_help def do_done(self, line): """done Quits this and goes to higher level or quits the application. I mean, what else do you expect? """ return True if __name__=='__main__': c = BaseCmd() c.cmdloop() From gmspro at yahoo.com Sun Jun 24 04:15:04 2012 From: gmspro at yahoo.com (gmspro) Date: Sun, 24 Jun 2012 01:15:04 -0700 (PDT) Subject: How can i call array_length to get the length of array object? In-Reply-To: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> Message-ID: <1340525704.2880.YahooMailClassic@web164605.mail.gq1.yahoo.com> @Ian, The function name in arraymodule.c file is array_len but you have to call something like: , why? >>>arr=array('i',[5,8,7]) >>>lg=arr.__len__() >>>print(lg) Why __len__() where the original name if array_length? Why is method names like __NAME__ ? --- On Sun, 6/24/12, gmspro wrote: From: gmspro Subject: Re: How can i call array_length to get the length of array object? To: "Ian Kelly" Cc: "python-list" Date: Sunday, June 24, 2012, 3:01 AM Why are some methods/functions named in this way in python? __len__ underscoreunderscoreNAMEunderscoreunderscore Is there any speciality of naming such methods? --- On Sun, 6/24/12, Ian Kelly wrote: From: Ian Kelly Subject: Re: How can i call array_length to get the length of array object? To: "gmspro" Cc: "python-list" Date: Sunday, June 24, 2012, 12:34 AM On Sat, Jun 23, 2012 at 8:23 PM, gmspro wrote: > I'm trying to call this function, http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 > > Is that possible to call that function? > > I know it's possible to do: > >>>len(arr) You call it just like that.? array_length is the C implementation of __len__ for arrays. > Doesn't it call this : > http://hg.python.org/cpython/file/c0eab397f098/Python/bltinmodule.c#l1283 > instead of this: > http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 Yes, and builtin_len calls PyObject_Size, which in turn calls the object's sq_length method, which is defined to be array_length for arrays. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gmspro at yahoo.com Sun Jun 24 04:19:20 2012 From: gmspro at yahoo.com (gmspro) Date: Sun, 24 Jun 2012 01:19:20 -0700 (PDT) Subject: How can i call array_length to get the length of array object? In-Reply-To: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> Message-ID: <1340525960.96299.YahooMailClassic@web164605.mail.gq1.yahoo.com> @Ian, The function name in arraymodule.c file is array_len but you have to call something like: , why? >>>arr=array('i',[5,8,7]) >>>lg=arr.__len__() >>>print(lg) Why __len__() where the original name if array_length? Why is method named like __NAME__ ? --- On Sun, 6/24/12, gmspro wrote: From: gmspro Subject: Re: How can i call array_length to get the length of array object? To: "Ian Kelly" Cc: "python-list" Date: Sunday, June 24, 2012, 3:01 AM Why are some methods/functions named in this way in python? __len__ underscoreunderscoreNAMEunderscoreunderscore Is there any speciality of naming such methods? --- On Sun, 6/24/12, Ian Kelly wrote: From: Ian Kelly Subject: Re: How can i call array_length to get the length of array object? To: "gmspro" Cc: "python-list" Date: Sunday, June 24, 2012, 12:34 AM On Sat, Jun 23, 2012 at 8:23 PM, gmspro wrote: > I'm trying to call this function, http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 > > Is that possible to call that function? > > I know it's possible to do: > >>>len(arr) You call it just like that.? array_length is the C implementation of __len__ for arrays. > Doesn't it call this : > http://hg.python.org/cpython/file/c0eab397f098/Python/bltinmodule.c#l1283 > instead of this: > http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657 Yes, and builtin_len calls PyObject_Size, which in turn calls the object's sq_length method, which is defined to be array_length for arrays. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gmspro at yahoo.com Sun Jun 24 04:24:04 2012 From: gmspro at yahoo.com (gmspro) Date: Sun, 24 Jun 2012 01:24:04 -0700 (PDT) Subject: Help to make a simple web page to do form post using python3 and get the value from form and display it on webpage Message-ID: <1340526244.86109.YahooMailClassic@web164606.mail.gq1.yahoo.com> Hi,
??? ???
Now how can i write the p.py to take the username after submit button click and display on webpage? How to run web server too? How can i make it work under apache2 ? #!/path/to/python3 ....... Any answer will be highly appreciated. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gmspro at yahoo.com Sun Jun 24 04:42:12 2012 From: gmspro at yahoo.com (gmspro) Date: Sun, 24 Jun 2012 01:42:12 -0700 (PDT) Subject: Why are these files names started with underscore? Message-ID: <1340527332.41345.YahooMailClassic@web164602.mail.gq1.yahoo.com> Hi, I see there are some files here started with underscore(_) , is there any convention of something for it? http://hg.python.org/cpython/file/3b7230997425/Modules _bisectmodule.c _bz2module.c _codecsmodule.c _collectionsmodule.c _cryptmodule.c _csv.c _curses_panel.c _cursesmodule.c _datetimemodule.c _dbmmodule.c _elementtree.c _freeze_importlib.c _functoolsmodule.c _gdbmmodule.c _gestalt.c _hashopenssl.c _heapqmodule.c _json.c _localemodule.c _lsprof.c _lzmamodule.c _math.c _math.h _pickle.c _posixsubprocess.c _randommodule.c _scproxy.c _sre.c _ssl.c _ssl_data.h _struct.c _testbuffer.c _testcapimodule.c _testembed.c _threadmodule.c _tkinter.c _weakref.c _winapi.c Is there any convention or something? Any answer will be highly appreciated. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clickfirm2007 at gmail.com Sun Jun 24 04:47:55 2012 From: clickfirm2007 at gmail.com (Mohamed Gad) Date: Sun, 24 Jun 2012 01:47:55 -0700 (PDT) Subject: Weight Loss Calculator .. Down.load F.ree Message-ID: ATTENTION: Limited Time OFFER For F.REE!! * You will be shocked With This Amazign OFFER!! * Weight Loss Calculator .. Down.load F.ree >> http://www.book-mall.com/offers/weightloss-calculator/ - The weight loss calculator allows you to estimate your weekly and monthly weight loss. Just enter your daily energy expenditure and the caloric content of your diet. Don't Miss .. FREE Bonus .. Amazing Weight loss & Health Tips .. 4F.ree Too .. Enjoy :) >> http://www.book-mall.com/offers/weightloss-calculator/ From stefan_ml at behnel.de Sun Jun 24 04:48:20 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 24 Jun 2012 10:48:20 +0200 Subject: How can i call array_length to get the length of array object? In-Reply-To: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> References: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> Message-ID: gmspro, 24.06.2012 10:01: > Why are some methods/functions named in this way in python? __len__ > > underscoreunderscoreNAMEunderscoreunderscore > > Is there any speciality of naming such methods? Yes. Look up "special methods" in the documentation. You may have noticed the correspondence between len() and __len__(). That is Python's way of allowing you to implement this kind of generic functionality (sometimes referred to as a protocol). You also asked why len() is a function instead of a method. Don't you find it much easier to use one function for everything than to look up and sometimes even learn one method for each kind of object you are dealing with? Python prefers simplicity here. You want the length? Use len(). Stefan From stefan_ml at behnel.de Sun Jun 24 04:55:28 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 24 Jun 2012 10:55:28 +0200 Subject: Why are these files names started with underscore? In-Reply-To: <1340527332.41345.YahooMailClassic@web164602.mail.gq1.yahoo.com> References: <1340527332.41345.YahooMailClassic@web164602.mail.gq1.yahoo.com> Message-ID: gmspro, 24.06.2012 10:42: > I see there are some files here started with underscore(_) , is there any convention of something for it? > > http://hg.python.org/cpython/file/3b7230997425/Modules > > _bisectmodule.c > [...] > _winapi.c > > Is there any convention or something? Yes. Please read the CPython developer guide (click on "core development" on the Python front page). Stefan From rosuav at gmail.com Sun Jun 24 04:55:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jun 2012 18:55:29 +1000 Subject: Why are these files names started with underscore? In-Reply-To: <1340527332.41345.YahooMailClassic@web164602.mail.gq1.yahoo.com> References: <1340527332.41345.YahooMailClassic@web164602.mail.gq1.yahoo.com> Message-ID: On Sun, Jun 24, 2012 at 6:42 PM, gmspro wrote: > > Hi, > > I see there are some files here started with underscore(_) , is there any > convention of something for it? > > Is there any convention or something? They're private implementations of public APIs. You can ignore them as implementation details. For using Python, I strongly recommend reading the docs, not the source. Among other things, that'll help you avoid the trap of writing to a CPython implementation detail. ChrisA From stefan_ml at behnel.de Sun Jun 24 04:59:43 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 24 Jun 2012 10:59:43 +0200 Subject: Why is python source code not available on github? In-Reply-To: <1340496999.60745.YahooMailClassic@web164602.mail.gq1.yahoo.com> References: <1340496999.60745.YahooMailClassic@web164602.mail.gq1.yahoo.com> Message-ID: gmspro, 24.06.2012 02:16: > Why is python source code not available on github? > > Make it available on github so that we can git clone and work on source code. github != git. You can use git to work on the sources if you wish. Just install a Mercurial plugin for it and clone the code from the source repository. However, if you want to contribute to the project, it's still worth considering to work with Mercurial. Stefan From __peter__ at web.de Sun Jun 24 05:52:39 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 24 Jun 2012 11:52:39 +0200 Subject: Why is python source code not available on github? References: <1340496999.60745.YahooMailClassic@web164602.mail.gq1.yahoo.com> Message-ID: gmspro wrote: > Why is python source code not available on github? > > Make it available on github so that we can git clone and work on source > code. http://thread.gmane.org/gmane.comp.python.devel/121885/focus=122111 From stefan-usenet at bytereef.org Sun Jun 24 06:34:20 2012 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Sun, 24 Jun 2012 12:34:20 +0200 Subject: Why is python source code not available on github? In-Reply-To: References: <1340496999.60745.YahooMailClassic@web164602.mail.gq1.yahoo.com> Message-ID: <20120624103420.GA30184@sleipnir.bytereef.org> Peter Otten <__peter__ at web.de> wrote: > gmspro wrote: > > Why is python source code not available on github? Why should every free software project be available on a single proprietary platform? Also, see: http://arstechnica.com/business/2012/03/hacker-commandeers-github-to-prove-vuln-in-ruby/ Stefan Krah From stefan at epy.co.at Sun Jun 24 06:44:22 2012 From: stefan at epy.co.at (Stefan H. Holek) Date: Sun, 24 Jun 2012 12:44:22 +0200 Subject: Getting lazy with decorators In-Reply-To: <9d0c01f4-4430-4a45-8776-20d8dede9e14@googlegroups.com> References: <9d0c01f4-4430-4a45-8776-20d8dede9e14@googlegroups.com> Message-ID: <2768E1CE-B75A-4BF6-95F9-8C077C719847@epy.co.at> On 24.06.2012, at 03:58, Josh English wrote: > I'm creating a cmd.Cmd class, and I have developed a helper method to easily handle help_xxx methods. When I need custom help processing I tend to simply override do_help(). Stefan http://pypi.python.org/pypi/kmd -- Stefan H. Holek stefan at epy.co.at From breamoreboy at yahoo.co.uk Sun Jun 24 08:45:40 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 24 Jun 2012 13:45:40 +0100 Subject: How can i call array_length to get the length of array object? In-Reply-To: <1340525704.2880.YahooMailClassic@web164605.mail.gq1.yahoo.com> References: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> <1340525704.2880.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: On 24/06/2012 09:15, gmspro wrote: > Why __len__() where the original name if array_length? Why is method names like __NAME__ ? > Why are you too bloody lazy to do any research before you post questions? -- Cheers. Mark Lawrence. From gundlach at gmail.com Sun Jun 24 09:34:10 2012 From: gundlach at gmail.com (Michael Gundlach) Date: Sun, 24 Jun 2012 09:34:10 -0400 Subject: SSL handshake hanging, despite bugfix in stdlib In-Reply-To: References: Message-ID: Thanks for your reply, Terry. On Sun, Jun 24, 2012 at 1:12 AM, Terry Reedy wrote: > On 6/23/2012 1:29 PM, Michael Gundlach wrote: > >> Am I do something wrong, or is this bug still not fixed? Any pointers > > would be appreciated. Python 2.6.6 (r266:84292, Dec 7 2011, 20:48:22) >> on 64-bit Linux 2.6.32. >> Michael >> > > If you want any attention from developers, you will have to show a problem > with 2.7.3 or latest 3.2+. I do not know that there is much change in 2.7, > but I know there is more in change in 3.3 (the do_handshake call is moved > and has a different context. I've now changed to 2.7.3, and if I don't write back in the next few days, it means that that fixed the problem -- thanks for your help! :) Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: From jerry.rocteur at gmail.com Sun Jun 24 11:16:09 2012 From: jerry.rocteur at gmail.com (Jerry Rocteur) Date: Sun, 24 Jun 2012 17:16:09 +0200 Subject: Python and Facebook In-Reply-To: References: Message-ID: Hi, I posted this mail on Friday and received no replies.. I'm curious.. Is it because 1) Python is not the language to use for Facebook, use Javascript or XXX ?? instead ? Please tell. 2) I've missed the point and this is very well documented so RTFM (I couldn't find it) 3) You guys don't use Facebook, you have a life .. Can someone please point me in the right direction.. Thanks in advance, Jerry On Fri, Jun 22, 2012 at 4:28 PM, Jerry Rocteur wrote: > Hi, > > I've done a bit of searching on this but I can find nothing really up to > date and a lot of conflicting information about using Python and Facebook. > > I'd like to automate some tasks in Facebook, for example I'd like to > connect to a group I'm admin of and take a copy of all photos, a list of > all members and member's info, I'd also like to connect every day and take > all the days posts and save them as it is so hard to find back things in > groups. > > I'd like to use Python to do this but I can't find what is the best module > to do this or even how to go about doing it. > > Can someone please put me in the right direction. > > Thanks in advance, > > -- > Jerry Rocteur > jerry at rocteur.com > Contact me: Google Talk/jerry.rocteur at gmail.com, Skype/rocteur > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Jun 24 11:35:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jun 2012 01:35:18 +1000 Subject: Python and Facebook In-Reply-To: References: Message-ID: On Mon, Jun 25, 2012 at 1:16 AM, Jerry Rocteur wrote: > > Hi, > > I posted this mail on Friday and received no replies.. > > I'm curious.. > > Is it because > > 1) Python is not the language to use for Facebook, use Javascript or XXX > ?? instead ? Please tell. > 2) I've missed the point and this is very well documented so RTFM (I > couldn't find it) > 3) You guys don't use Facebook, you have a life .. I personally don't use Facebook, but I don't have much of a life either..... But I've never heard of a specific Python-Facebook module, until just now when I googled it and found a couple of things. Two points: 1) Python's pretty good at networking. If all else fails, you can always just implement whatever Facebook's API is (the Google snippets suggest it's REST, ie all HTTP, which Python does admirably), and go from there. 2) An active Python-Facebook module will have active developers who probably know far more about how to use their module than random people like me who happen to read all of python-list :) There may well be such people on this list, but since you've received no replies, it's possible there aren't. (It's also possible that they don't monitor this list on weekends, though. You never know.) 3) What do Facebook think of you downloading all their content and viewing it without their ads? Not that I particularly care, but it may be something to consider, since you're effectively going to get everything that Facebook offers you (ie posts/pics/etc) without everything that Facebook steals from you and sells (page views, ad impressions, etc). (Among our points are such diverse elements as... wrong Pythons, but whatever.) There's no official Python-Facebook module (afaik!!), but a quick web search for 'python facebook' should get you to the couple that I saw, and possibly others. The next question is, do you trust any of them... Good luck with that one! :) Chris Angelico From laurent.pointal at free.fr Sun Jun 24 11:57:31 2012 From: laurent.pointal at free.fr (Laurent Pointal) Date: Sun, 24 Jun 2012 17:57:31 +0200 Subject: use Python to post image to Facebook References: <5d93df3b-a0d6-4604-9dbc-3988a06c0317@googlegroups.com> Message-ID: <4fe738eb$0$1711$426a74cc@news.free.fr> davecotefilm at gmail.com wrote: > On Monday, 9 April 2012 20:24:54 UTC-7, CM wrote: >> Shot in the dark here: has any who reads this group been successful >> with getting Python to programmatically post an image to Facebook? >> >> I've tried using fbconsole[1] and facepy[2], both of which apparently >> work fine for their authors and others and although I have an >> authorization code, publish permissions, a Facebook app, I get back >> these unhelpful errors when I try this (like "an unknown error >> occurred"). >> >> If anyone has been able to do this, maybe you can help me figure out >> what I am doing wrong. > > Hi, I am not sure, but have a similar question. How can I post (upload) > an image to google images and return the resulting page..? In python? If > you can help I would appreciate it ever so much, Dave:) Note: if you develop such a tool, make it a "Web Out Of Browser" module. http://weboob.org/ -- Laurent POINTAL - laurent.pointal at laposte.net From alec.taylor6 at gmail.com Sun Jun 24 12:16:05 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Mon, 25 Jun 2012 02:16:05 +1000 Subject: Python and Facebook In-Reply-To: References: Message-ID: This is the most active one, forked from the official facebook one (when they used to maintain it themselves): https://github.com/pythonforfacebook/facebook-sdk On Mon, Jun 25, 2012 at 1:35 AM, Chris Angelico wrote: > On Mon, Jun 25, 2012 at 1:16 AM, Jerry Rocteur wrote: >> >> Hi, >> >> I posted this mail on Friday and received no replies.. >> >> I'm curious.. >> >> Is it because >> >> 1) Python is not the language to use for Facebook, use Javascript or XXX >> ?? instead ? Please tell. >> 2) I've missed the point and this is very well documented so RTFM (I >> couldn't find it) >> 3) You guys don't use Facebook, you have a life .. > > I personally don't use Facebook, but I don't have much of a life > either..... But I've never heard of a specific Python-Facebook module, > until just now when I googled it and found a couple of things. > > Two points: > > 1) Python's pretty good at networking. If all else fails, you can > always just implement whatever Facebook's API is (the Google snippets > suggest it's REST, ie all HTTP, which Python does admirably), and go > from there. > > 2) An active Python-Facebook module will have active developers who > probably know far more about how to use their module than random > people like me who happen to read all of python-list :) There may well > be such people on this list, but since you've received no replies, > it's possible there aren't. (It's also possible that they don't > monitor this list on weekends, though. You never know.) > > 3) What do Facebook think of you downloading all their content and > viewing it without their ads? Not that I particularly care, but it may > be something to consider, since you're effectively going to get > everything that Facebook offers you (ie posts/pics/etc) without > everything that Facebook steals from you and sells (page views, ad > impressions, etc). > > (Among our points are such diverse elements as... wrong Pythons, but whatever.) > > There's no official Python-Facebook module (afaik!!), but a quick web > search for 'python facebook' should get you to the couple that I saw, > and possibly others. The next question is, do you trust any of them... > Good luck with that one! :) > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list From bv8bv8bv8 at gmail.com Sun Jun 24 14:19:24 2012 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sun, 24 Jun 2012 11:19:24 -0700 (PDT) Subject: The Quran on Human Embryonic Development Message-ID: The Quran on Human Embryonic Development In the Holy Quran, God speaks about the stages of man?s embryonic development: ?We created man from an extract of clay. Then We made him as a drop in a place of settlement, firmly fixed. Then We made the drop into an alaqah(leech, suspended thing, and blood clot), then We made the alaqah into amudghah (chewed substance)?? (Quran 23:12-14) Literally, the Arabic word alaqah has three meanings: (1) leech, (2) suspended thing, and (3) blood clot. In comparing a leech to an embryo in the alaqah stage, we find similarity between the two[1] as we can see in figure 1. Also, the embryo at this stage obtains nourishment from the blood of the mother, similar to the leech, which feeds on the blood of others.[2] http://www.islamreligion.com/articles/images/The_Quran_on_Human_Embryonic_Development_001.jpg Figure 1: Drawings illustrating the similarities in appearance between a leech and a human embryo at the alaqah stage. (Leech drawing from Human Development as Described in the Quran and Sunnah, Moore and others, p. 37, modified from Integrated Principles of Zoology, Hickman and others. Embryo drawing from The Developing Human, Moore and Persaud, 5th ed., p. 73.) The second meaning of the word alaqah is ?suspended thing.? This is what we can see in figures 2 and 3, the suspension of the embryo, during the alaqah stage, in the womb of the mother. http://www.islamreligion.com/articles/images/The_Quran_on_Human_Embryonic_Development_002.jpg Figure 2: We can see in this diagram the suspension of an embryo during the alaqah stage in the womb (uterus) of the mother. (The Developing Human, Moore and Persaud, 5th ed., p. 66.) http://www.islamreligion.com/articles/images/The_Quran_on_Human_Embryonic_Development_003.jpg Figure 3: In this photomicrograph, we can see the suspension of an embryo (marked B) during the alaqah stage (about 15 days old) in the womb of the mother. The actual size of the embryo is about 0.6 mm. (The Developing Human, Moore, 3rd ed., p. 66, from Histology, Leeson and Leeson.) The third meaning of the word alaqah is ?blood clot.? We find that the external appearance of the embryo and its sacs during the alaqah stage is similar to that of a blood clot. This is due to the presence of relatively large amounts of blood present in the embryo during this stage[3] (see figure 4). Also during this stage, the blood in the embryo does not circulate until the end of the third week.[4] Thus, the embryo at this stage is like a clot of blood. http://www.islamreligion.com/articles/images/The_Quran_on_Human_Embryonic_Development_004.jpg Figure 4: Diagram of the primitive cardiovascular system in an embryo during the alaqah stage. The external appearance of the embryo and its sacs is similar to that of a blood clot, due to the presence of relatively large amounts of blood present in the embryo. (The Developing Human, Moore, 5th ed., p. 65.) So the three meanings of the word alaqah correspond accurately to the descriptions of the embryo at the alaqah stage. The next stage mentioned in the verse is the mudghah stage. The Arabic word mudghah means ?chewed substance.? If one were to take a piece of gum and chew it in his or her mouth and then compare it with an embryo at the mudghah stage, we would conclude that the embryo at the mudghah stage acquires the appearance of a chewed substance. This is because of the somites at the back of the embryo that ?somewhat resemble teethmarks in a chewed substance.?[5] (see figures 5 and 6). http://www.islamreligion.com/articles/images/The_Quran_on_Human_Embryonic_Development_005.jpg Figure 5: Photograph of an embryo at the mudghah stage (28 days old). The embryo at this stage acquires the appearance of a chewed substance, because the somites at the back of the embryo somewhat resemble teeth marks in a chewed substance. The actual size of the embryo is 4 mm. (The Developing Human, Moore and Persaud, 5th ed., p. 82, from Professor Hideo Nishimura, Kyoto University, Kyoto, Japan.) http://www.islamreligion.com/articles/images/The_Quran_on_Human_Embryonic_Development_006.jpg Figure 6: When comparing the appearance of an embryo at the mudghah stage with a piece of gum that has been chewed, we find similarity between the two. A) Drawing of an embryo at the mudghah stage. We can see here the somites at the back of the embryo that look like teeth marks. (The Developing Human, Moore and Persaud, 5th ed., p. 79.) B) Photograph of a piece of gum that has been chewed. How could Muhammad, may the mercy and blessings of God be upon him, have possibly known all this 1400 years ago, when scientists have only recently discovered this using advanced equipment and powerful microscopes which did not exist at that time? Hamm and Leeuwenhoek were the first scientists to observe human sperm cells (spermatozoa) using an improved microscope in 1677 (more than 1000 years after Muhammad). They mistakenly thought that the sperm cell contained a miniature preformed human being that grew when it was deposited in the female genital tract.[6] Professor Emeritus Keith L. Moore[7] is one of the world?s most prominent scientists in the fields of anatomy and embryology and is the author of the book entitled The Developing Human, which has been translated into eight languages. This book is a scientific reference work and was chosen by a special committee in the United States as the best book authored by one person. Dr. Keith Moore is Professor Emeritus of Anatomy and Cell Biology at the University of Toronto, Toronto, Canada. There, he was Associate Dean of Basic Sciences at the Faculty of Medicine and for 8 years was the Chairman of the Department of Anatomy. In 1984, he received the most distinguished award presented in the field of anatomy in Canada, the J.C.B. Grant Award from the Canadian Association of Anatomists. He has directed many international associations, such as the Canadian and American Association of Anatomists and the Council of the Union of Biological Sciences. In 1981, during the Seventh Medical Conference in Dammam, Saudi Arabia, Professor Moore said: ?It has been a great pleasure for me to help clarify statements in the Quran about human development. It is clear to me that these statements must have come to Muhammad from God, because almost all of this knowledge was not discovered until many centuries later. This proves to me that Muhammad must have been a messenger of God.?[8] (To view the RealPlayer video of this comment click here). Consequently, Professor Moore was asked the following question: ?Does this mean that you believe that the Quran is the word of God?? He replied: ?I find no difficulty in accepting this.?[9] During one conference, Professor Moore stated: ?....Because the staging of human embryos is complex, owing to the continuous process of change during development, it is proposed that a new system of classification could be developed using the terms mentioned in the Quran and Sunnah (what Muhammad, may the mercy and blessings of God be upon him, said, did, or approved of). The proposed system is simple, comprehensive, and conforms with present embryological knowledge. The intensive studies of the Quran and hadeeth (reliably transmitted reports by the Prophet Muhammad?s companions of what he said, did, or approved of) in the last four years have revealed a system for classifying human embryos that is amazing since it was recorded in the seventh century A.D. Although Aristotle, the founder of the science of embryology, realized that chick embryos developed in stages from his studies of hen?s eggs in the fourth century B.C., he did not give any details about these stages. As far as it is known from the history of embryology, little was known about the staging and classification of human embryos until the twentieth century. For this reason, the descriptions of the human embryo in the Quran cannot be based on scientific knowledge in the seventh century. The only reasonable conclusion is: these descriptions were revealed to Muhammad from God. He could not have known such details because he was an illiterate man with absolutely no scientific training.?[10] (View the RealPlayer video of this comment). Footnotes: [1] The Developing Human, Moore and Persaud, 5th ed., p. 8. [2] Human Development as Described in the Quran and Sunnah, Moore and others, p. 36. [3] Human Development as Described in the Quran and Sunnah, Moore and others, pp. 37-38. [4] The Developing Human, Moore and Persaud, 5th ed., p. 65. [5] The Developing Human, Moore and Persaud, 5th ed., p. 8. [6] The Developing Human, Moore and Persaud, 5th ed., p. 9. [7] Note: The occupations of all the scientists mentioned in this web site were last updated in 1997. [8] The reference for this saying is This is the Truth (videotape). For a copy of this videotape, please visit www.islam-guide.com/truth.htm [9] This is the Truth (videotape). [10] This is the Truth (videotape). For a copy, see footnote no. 9. The web address of this article: http://www.islamreligion.com/articles/216/ From tlgraffa at gmail.com Sun Jun 24 14:49:05 2012 From: tlgraffa at gmail.com (TG) Date: Sun, 24 Jun 2012 11:49:05 -0700 (PDT) Subject: Grok vs. Django for RESTful API? Message-ID: <8394afdf-e0f4-4a56-abac-8e966a86dc64@googlegroups.com> Just hoping to get some opinions: Grok vs Django for REST? I've started evaluating TastyPie with Django. Is there something similar for Grok? I'm working on a project that will mostly be mobile-app based. Though there will be a web interface, the mobile part is more important to us. Our data model is pretty straight-forward so far (it's a social networking type app), but may become a bit more involved if we begin to add information/event streams. So finding a framework that works well with a dynamically changing data model is somewhat important (hopefully we won't change it too often). Having a good security/authentication/authorization framework is important too. I consider myself pretty strong with Python and other languages, but web programming is new to me. I'm comfortable though with HTTP/SQL/etc. From tismer at stackless.com Sun Jun 24 15:57:43 2012 From: tismer at stackless.com (Christian Tismer) Date: Sun, 24 Jun 2012 21:57:43 +0200 Subject: tiffany 0.5 released Message-ID: <4FE77137.7050103@stackless.com> Tiffany - Read/Write Multipage-Tiff with PIL without PIL ======================================================== Tiffany stands for any tiff. The tiny module solves a large set of problems, has no dependencies and just works wherever Python works. Tiffany was developed in the course of the *DiDoCa* project and will always appear on PyPi. Version 0.5 ----------- This is a compatibility update for Python 3.2. Tiffany now works on Python 2.6, 2.7 and 3.2. This version also reduces the needed PIL files to four * 2. The final reduction to a single source is almost ready and will be 0.6 . Please let me know if this stuff works for you, and send requests to or use the links in the bitbucket website: https://bitbucket.org/didoca/tiffany cheers -- Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From not_here at no-where.net Sun Jun 24 17:11:29 2012 From: not_here at no-where.net (Brian) Date: Sun, 24 Jun 2012 14:11:29 -0700 Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross-platform_GUI_desinge?= =?ISO-8859-1?Q?rs_=E0_la__Interface_Builder_=28Re=3A_what_?= =?ISO-8859-1?Q?gui_designer_is_everyone_using=29?= In-Reply-To: <20120619150716.263fc70d.feliphil@gmx.net> References: <4FD4F75D.40602@schwertberger.de> <20120613144931.adbb2c52.feliphil@gmx.net> <20120619150716.263fc70d.feliphil@gmx.net> Message-ID: On 6/19/2012 6:07 AM, Wolfgang Keller wrote: > And the lack of success of Python so far to replace, in your > application case, Labview, or, in my application case, all those > proprietary 4GL IDEs/frameworks/GUI builders (just check the success > that Realbasic has) proves imho that the Python community has totally > missed to address the vast crowd of potential users who are domain > experts in other domains than software development. > > Sincerely, > > Wolfgang I have been compelled to occasionally use LV by my current employer. I do not know if LabView is the disease or is a symptom. It is an evil parasite and has resulted in a disaster at my place of employment and another that I am aware. As for 'designers' and 'builders', the discussion threads on Python gui builders is legion. In the end, the consensus is always to learn one and write the gui. Regardless of the multitude of clever gui libraries, event code in this language seems a bit contrived, and is attractive only to professional programmers. But the community must know that the language is used by hundreds of thousands of scientists and engineers that have a job to do, and do not have the time and have no interest in learning the frameworks du jour. This is why I see test and manufacturing engineers refuse to give up VB6 where Windows is required. I disagree with those that say Python can be used as a VB6 replacement. And the touted 'interactive' feature of Python does nothing for gui coding. It would not be difficult to convince me to commit homicide for a Delphi-like Python gui machine that runs on a Linux box. I have played with many - Boa, WxDes, Glade, Tk, Dabo, QtDesigner, Card, etc. Am currently experimenting with IronPython, because the factory boss says no more Linux boxes on his production lines. And the person that said Python is best tool for data acq/hw control needs to get out more. Very dangerous. C first, Python second. This is why I insist on only C and Python for the engineering lab, and use one of three proven pre-coded Tk-based GUIs for production and ATE drivers. You want to argue with me? First come visit my employer's TJ factory and watch the boys test 600kVA transformers or 250kVA inverters. 150,000 A of fault current. Brian From dncarac at gmail.com Sun Jun 24 17:19:20 2012 From: dncarac at gmail.com (dncarac at gmail.com) Date: Sun, 24 Jun 2012 14:19:20 -0700 (PDT) Subject: The Quran on Human Embryonic Development In-Reply-To: References: Message-ID: Well, I use wxFormBuilder for my embryonic GUIs, but I have no qualms (or is that quorans) about changing the generated code to make it more efficient. From charleshixsn at earthlink.net Sun Jun 24 18:26:59 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Sun, 24 Jun 2012 15:26:59 -0700 Subject: exception problem Message-ID: <4FE79433.8020704@earthlink.net> The code: print ("pre-chunkLine") chunks = [] try: chunks = self.chunkLine (l) except: print ("caught exception") print (sys.exc_info()[:2]) finally: print ("at finally") print ("chunks =") print (repr(chunks), ".", end = ":") produces this result: . . ., by pre-chunkLine caught exception at finally path 3... Any suggestions as to what's wrong with the code? FWIW, chunkLine begins: def chunkLine (self, line): print ("chunkLine: ") print ("line = ", line) if line == None: return [] assert (isinstance (line, str) ) -- Charles Hixson From charleshixsn at earthlink.net Sun Jun 24 18:30:09 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Sun, 24 Jun 2012 15:30:09 -0700 Subject: exception problem In-Reply-To: <4FE79433.8020704@earthlink.net> References: <4FE79433.8020704@earthlink.net> Message-ID: <4FE794F1.6000202@earthlink.net> Sorry, I left out: er$ python3 --version Python 3.2.3rc1 On 06/24/2012 03:26 PM, Charles Hixson wrote: > The code: > print ("pre-chunkLine") > chunks = [] > try: > chunks = self.chunkLine (l) > except: > print ("caught exception") > print (sys.exc_info()[:2]) > finally: > print ("at finally") > print ("chunks =") > print (repr(chunks), ".", end = ":") > produces this result: > . . ., by > pre-chunkLine > caught exception > at finally > path 3... > > Any suggestions as to what's wrong with the code? > FWIW, chunkLine begins: > def chunkLine (self, line): > print ("chunkLine: ") > print ("line = ", line) > if line == None: > return [] > assert (isinstance (line, str) ) > -- Charles Hixson From rosuav at gmail.com Sun Jun 24 18:36:11 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jun 2012 08:36:11 +1000 Subject: exception problem In-Reply-To: <4FE79433.8020704@earthlink.net> References: <4FE79433.8020704@earthlink.net> Message-ID: On Mon, Jun 25, 2012 at 8:26 AM, Charles Hixson wrote: > The code: > ? ? ? ? ? ? ? ?finally: > ? ? ? ? ? ? ? ? ? ?print ("at finally") > ? ? ? ? ? ? ? ?print ("chunks =") > produces this result: > path ?3... Can you state more clearly the problem, please? I'm seeing output that can't have come from the code posted (for instance, immediately after the "at finally", I'm expecting to see the "chunks =" line), and I'm not seeing any exception information, so I can't even hazard a guess as to what's throwing the exception. Presumably these are two methods in the same class, since you're calling it as "self.chunkLine", but beyond that, it's hard to know. Take off the try/except and let your exception go to console, that's usually the easiest thing to deal with. Chris Angelico From python at mrabarnett.plus.com Sun Jun 24 18:43:56 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 24 Jun 2012 23:43:56 +0100 Subject: exception problem In-Reply-To: <4FE79433.8020704@earthlink.net> References: <4FE79433.8020704@earthlink.net> Message-ID: <4FE7982C.5020708@mrabarnett.plus.com> On 24/06/2012 23:26, Charles Hixson wrote: > The code: > print ("pre-chunkLine") > chunks = [] > try: > chunks = self.chunkLine (l) > except: > print ("caught exception") > print (sys.exc_info()[:2]) > finally: > print ("at finally") > print ("chunks =") > print (repr(chunks), ".", end = ":") > produces this result: > . . ., by > pre-chunkLine > caught exception > at finally > path 3... > > Any suggestions as to what's wrong with the code? > FWIW, chunkLine begins: > def chunkLine (self, line): > print ("chunkLine: ") > print ("line = ", line) > if line == None: > return [] > assert (isinstance (line, str) ) > Don't use a bare "except"; it'll catch _any__exception. Catch only what you expect. For all I know, it could be that the name "l" doesn't exist. From d at davea.name Sun Jun 24 18:45:45 2012 From: d at davea.name (Dave Angel) Date: Sun, 24 Jun 2012 18:45:45 -0400 Subject: exception problem In-Reply-To: <4FE794F1.6000202@earthlink.net> References: <4FE79433.8020704@earthlink.net> <4FE794F1.6000202@earthlink.net> Message-ID: <4FE79899.1040701@davea.name> On 06/24/2012 06:30 PM, Charles Hixson wrote: > Sorry, I left out: > er$ python3 --version > Python 3.2.3rc1 > > On 06/24/2012 03:26 PM, Charles Hixson wrote: >> The code: >> print ("pre-chunkLine") >> chunks = [] >> try: >> chunks = self.chunkLine (l) >> except: >> print ("caught exception") >> print (sys.exc_info()[:2]) >> finally: >> print ("at finally") >> print ("chunks =") >> print (repr(chunks), ".", end = ":") >> produces this result: >> . . ., by >> pre-chunkLine >> caught exception >> at finally >> path 3... >> >> Any suggestions as to what's wrong with the code? >> FWIW, chunkLine begins: >> def chunkLine (self, line): >> print ("chunkLine: ") >> print ("line = ", line) >> if line == None: >> return [] >> assert (isinstance (line, str) ) >> > > On your except line, you forgot both the type of exception you're expecting and the variable to receive its value. So you're masking all errors, including a name error finding chunkline(). You don't include enough code to make the fragment executable, so I'd have to just guess. I'm guessing that chunkline() is not defined in the same class as that first method, whatever it was called. If this were my problem, probably first thing I'd try is to remove the try and catch, and see what it shows. Bare exceptions are the bane of programming; Using it is like trying to learn to drive while blindfolded. -- DaveA From python at mrabarnett.plus.com Sun Jun 24 18:59:18 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 24 Jun 2012 23:59:18 +0100 Subject: exception problem In-Reply-To: References: <4FE79433.8020704@earthlink.net> Message-ID: <4FE79BC6.7040702@mrabarnett.plus.com> On 24/06/2012 23:36, Chris Angelico wrote: > On Mon, Jun 25, 2012 at 8:26 AM, Charles Hixson > wrote: >> The code: >> finally: >> print ("at finally") >> print ("chunks =") >> produces this result: >> path 3... > > Can you state more clearly the problem, please? I'm seeing output that > can't have come from the code posted (for instance, immediately after > the "at finally", I'm expecting to see the "chunks =" line), and I'm > not seeing any exception information, so I can't even hazard a guess > as to what's throwing the exception. > I'd expect the output of: print (sys.exc_info()[:2]) between these two lines: caught exception at finally That suggests to me that "sys" hasn't been imported and that's there's another exception somewhere that we're not seeing. > Presumably these are two methods in the same class, since you're > calling it as "self.chunkLine", but beyond that, it's hard to know. > Take off the try/except and let your exception go to console, that's > usually the easiest thing to deal with. > From charleshixsn at earthlink.net Sun Jun 24 19:16:25 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Sun, 24 Jun 2012 16:16:25 -0700 Subject: exception problem In-Reply-To: <4FE7982C.5020708@mrabarnett.plus.com> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> Message-ID: <4FE79FC9.5050404@earthlink.net> On 06/24/2012 03:43 PM, MRAB wrote: > On 24/06/2012 23:26, Charles Hixson wrote: >> The code: >> print ("pre-chunkLine") >> chunks = [] >> try: >> chunks = self.chunkLine (l) >> except: >> print ("caught exception") >> print (sys.exc_info()[:2]) >> finally: >> print ("at finally") >> print ("chunks =") >> print (repr(chunks), ".", end = ":") >> produces this result: >> . . ., by >> pre-chunkLine >> caught exception >> at finally >> path 3... >> >> Any suggestions as to what's wrong with the code? >> FWIW, chunkLine begins: >> def chunkLine (self, line): >> print ("chunkLine: ") >> print ("line = ", line) >> if line == None: >> return [] >> assert (isinstance (line, str) ) >> > Don't use a bare "except"; it'll catch _any__exception. Catch only what > you expect. > > For all I know, it could be that the name "l" doesn't exist. But what I wanted was to catch any exception. A problem was happening and I had no clue as to what it was. (It turned out to be "self is not defined". A silly mistake, but a real one.) The odd thing was that if I ran it without the try block, I didn't get any exceptions at all. (Which I clearly should have, except that since self wasn't defined, I'd usually expect the interpreter to detect the error before trying to execute the code.) -- Charles Hixson From rosuav at gmail.com Sun Jun 24 19:51:15 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jun 2012 09:51:15 +1000 Subject: exception problem In-Reply-To: <4FE79FC9.5050404@earthlink.net> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> Message-ID: On Mon, Jun 25, 2012 at 9:16 AM, Charles Hixson wrote: > But what I wanted was to catch any exception. ?A problem was happening and I > had no clue as to what it was. ?(It turned out to be "self is not defined". > ?A silly mistake, but a real one.) > > The odd thing was that if I ran it without the try block, I didn't get any > exceptions at all. ?(Which I clearly should have, except that since self > wasn't defined, I'd usually expect the interpreter to detect the error > before trying to execute the code.) Python, not having any concept of declared variables, can't detect such errors prior to execution. The error isn't like in C where you're trying to use a variable that's not declared; the error is that, at run time, there's no global with the name "self". That's why it's an exception, not a compile-time error. But the real question is: Why do you get no exception traceback if you remove the try/except? Is something else swallowing everything thrown? This is something that you will need to solve. (And it's a pretty annoying issue. We had the same thing here at work, though in Javascript not Python; a framework was swallowing exceptions, so all sorts of work was being done blindfolded. Legacy code is not fun. Life got a lot easier for us last Friday when I found and excised the offending try/catch.) Hunt around and see if exceptions are getting logged someplace other than your console - not uncommon if, for instance, you're running in a web server. This is not going to be the only time when you get an exception that could be massively helpful. Mind you, I think every programmer should spend some time debugging blind. It gives you such an appreciation for interactive debuggers. Plus, it's an exercise in making your problems reproducible, if you have to start your program over every time you add some more information to it :) ChrisA From d at davea.name Sun Jun 24 21:02:29 2012 From: d at davea.name (Dave Angel) Date: Sun, 24 Jun 2012 21:02:29 -0400 Subject: exception problem In-Reply-To: <4FE79FC9.5050404@earthlink.net> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> Message-ID: <4FE7B8A5.7060706@davea.name> On 06/24/2012 07:16 PM, Charles Hixson wrote: > On 06/24/2012 03:43 PM, MRAB wrote: >> On 24/06/2012 23:26, Charles Hixson wrote: >>> >>> >>> >> Don't use a bare "except"; it'll catch _any__exception. Catch only what >> you expect. >> >> For all I know, it could be that the name "l" doesn't exist. > But what I wanted was to catch any exception. A problem was happening > and I had no clue as to what it was. (It turned out to be "self is > not defined". A silly mistake, but a real one.) > If you don't get anything else out of this thread, get this point. A bare except is exactly the opposite of what you want to debug an exception. It swallows all the information that python would have displayed for you. Four or five of us have made the same point, so please listen. -- DaveA From ben+python at benfinney.id.au Sun Jun 24 21:17:32 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 25 Jun 2012 11:17:32 +1000 Subject: How can i call array_length to get the length of array object? References: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> <1340525704.2880.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: <87pq8orxzn.fsf@benfinney.id.au> Mark Lawrence writes: > On 24/06/2012 09:15, gmspro wrote: > > > Why __len__() where the original name if array_length? Why is method > > names like __NAME__ ? These are questions answered by getting a thorough grounding in the fundamentals of Python. Please follow the Python tutorial , from beginning to end, to learn about the basics like this. > Why are you too bloody lazy to do any research before you post > questions? I understand your frustration in this case, but there's no call for such vitriol. Please keep it off this forum. -- \ ?Pinky, are you pondering what I'm pondering?? ?Wuh, I think | `\ so, Brain, but wouldn't anything lose its flavor on the bedpost | _o__) overnight?? ?_Pinky and The Brain_ | Ben Finney From tismer at stackless.com Sun Jun 24 21:44:24 2012 From: tismer at stackless.com (Christian Tismer) Date: Mon, 25 Jun 2012 03:44:24 +0200 Subject: tiffany 0.5 released Message-ID: <4FE7C278.7090604@stackless.com> Tiffany - Read/Write Multipage-Tiff with PIL without PIL ======================================================== Tiffany stands for any tiff. The tiny module solves a large set of problems, has no dependencies and just works wherever Python works. Tiffany was developed in the course of the *DiDoCa* project and will always appear on PyPi. Version 0.6 ----------- This is a compatibility update for Python 3.2. Tiffany now works on Python 2.6, 2.7 and 3.2. This version also reduces the needed PIL files to only four. The same files work for python2 and python3. You can help me by sending some tiff files with different encoding and larger file size for testing. I'm also thinking of - an interface to Qt (without adding a dependency) - a command line interface, to make tiffany into a new tiff tool, - support for other toolkits that need to handle tiff files. Ideas about this are most welcome. Please let me know if this stuff works for you, and send requests to or use the links in the bitbucket website: https://bitbucket.org/didoca/tiffany cheers -- Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ -- http://mail.python.org/mailman/listinfo/python-list From tismer at stackless.com Sun Jun 24 21:46:41 2012 From: tismer at stackless.com (Christian Tismer) Date: Mon, 25 Jun 2012 03:46:41 +0200 Subject: tiffany 0.6 released Message-ID: <4FE7C301.6010101@stackless.com> Tiffany - Read/Write Multipage-Tiff with PIL without PIL ======================================================== Tiffany stands for any tiff. The tiny module solves a large set of problems, has no dependencies and just works wherever Python works. Tiffany was developed in the course of the *DiDoCa* project and will always appear on PyPi. Version 0.6 ----------- This is a compatibility update for Python 3.2. Tiffany now works on Python 2.6, 2.7 and 3.2. This version also reduces the needed PIL files to only four. The same files work for python2 and python3. You can help me by sending some tiff files with different encoding and larger file size for testing. I'm also thinking of - an interface to Qt (without adding a dependency) - a command line interface, to make tiffany into a new tiff tool, - support for other toolkits that need to handle tiff files. Ideas about this are most welcome. Please let me know if this stuff works for you, and send requests to or use the links in the bitbucket website: https://bitbucket.org/didoca/tiffany cheers -- Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ -- http://mail.python.org/mailman/listinfo/python-list From lepto.python at gmail.com Sun Jun 24 22:16:41 2012 From: lepto.python at gmail.com (oyster) Date: Mon, 25 Jun 2012 10:16:41 +0800 Subject: image lib supports arbitrary canvas coordinate Message-ID: Can any image(not for line plot, but for pixel set) lib behaves like a person? that is to say: when we are doing image processing( for exapmle, http://www.freebasic.net/forum/viewtopic.php?f=17&t=20057&p=176300#p176300) , the new image maybe have a bigger canvas size than the original image's, and sometimes, nagative coordinate is needed from the math-side viewpoint, Of cause, we can do which by pre-caculating the proper canvas size, coordinate translation in code, but that is tedious Any lib can support some code like followings? thanks [psedu-code] newImg=Image.new('RGB', (200,300)) #begin with a canvas size=200*300, so the x is between[0, 199], y is between [0, 299] newImg.putpixel((500, 600), 'black') #the lib expands the canvas automatically, so till now the canvas size=501* 601 newImage.save('fin.jpg', border=(top=10, bottom=20, left=30, right=40)) #size of fin.jpg is (501+30+40)*(601+10+20) [/code] From kelebrinir at gmail.com Sun Jun 24 22:18:07 2012 From: kelebrinir at gmail.com (Roman Putilov) Date: Mon, 25 Jun 2012 08:18:07 +0600 Subject: Grok vs. Django for RESTful API? In-Reply-To: <8394afdf-e0f4-4a56-abac-8e966a86dc64@googlegroups.com> References: <8394afdf-e0f4-4a56-abac-8e966a86dc64@googlegroups.com> Message-ID: You could implement REST protocol for Grok using http://pypi.python.org/pypi/restkit/ 2012/6/25 TG > Just hoping to get some opinions: Grok vs Django for REST? I've started > evaluating TastyPie with Django. Is there something similar for Grok? > > I'm working on a project that will mostly be mobile-app based. Though > there will be a web interface, the mobile part is more important to us. Our > data model is pretty straight-forward so far (it's a social networking type > app), but may become a bit more involved if we begin to add > information/event streams. > So finding a framework that works well with a dynamically changing data > model is somewhat important (hopefully we won't change it too often). > Having a good security/authentication/authorization framework is important > too. > > I consider myself pretty strong with Python and other languages, but web > programming is new to me. I'm comfortable though with HTTP/SQL/etc. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skabra at gmail.com Sun Jun 24 23:37:59 2012 From: skabra at gmail.com (Saurabh Kabra) Date: Mon, 25 Jun 2012 13:37:59 +1000 Subject: Faster way to map numpy arrays Message-ID: I have written a script to map a 2D numpy array(A) onto another array(B) of different dimension. more than one element (of array A) are summed and mapped to each element of array B. To achieve this I create a list where I store the index of array A to be mapped to array B. The list is the dimension of array B (if one can technically say that) and each element is a list of indices to be summed. Then I parse this list with a nested loop and compute each element of array B. Because of the nested loop and the big arrays the process takes a minute or so. My question is: is there a more elegant and significantly faster way of doing this in python? Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From Shambhu.Rajak at kpitcummins.com Mon Jun 25 01:19:17 2012 From: Shambhu.Rajak at kpitcummins.com (Shambhu Rajak) Date: Mon, 25 Jun 2012 05:19:17 +0000 Subject: exception problem In-Reply-To: <4FE7982C.5020708@mrabarnett.plus.com> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> Message-ID: <408F64D89899604FB24015E64E10490C3B7CC97D@KCHJEXMB02.kpit.com> If you are not sure about the Exception, You can adopt a generic way of handling exception. try: .... except Exception,e: print str(e) -Shambhu -----Original Message----- From: MRAB [mailto:python at mrabarnett.plus.com] Sent: 25/06/2012 4:14 AM To: python-list at python.org Subject: Re: exception problem On 24/06/2012 23:26, Charles Hixson wrote: > The code: > print ("pre-chunkLine") > chunks = [] > try: > chunks = self.chunkLine (l) > except: > print ("caught exception") > print (sys.exc_info()[:2]) > finally: > print ("at finally") > print ("chunks =") > print (repr(chunks), ".", end = ":") > produces this result: > . . ., by > pre-chunkLine > caught exception > at finally > path 3... > > Any suggestions as to what's wrong with the code? > FWIW, chunkLine begins: > def chunkLine (self, line): > print ("chunkLine: ") > print ("line = ", line) > if line == None: > return [] > assert (isinstance (line, str) ) > Don't use a bare "except"; it'll catch _any__exception. Catch only what you expect. For all I know, it could be that the name "l" doesn't exist. From charleshixsn at earthlink.net Mon Jun 25 01:27:40 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Sun, 24 Jun 2012 22:27:40 -0700 Subject: exception problem In-Reply-To: References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> Message-ID: <4FE7F6CC.2050704@earthlink.net> On 06/24/2012 03:43 PM, Charles Hixson wrote: > On 06/24/2012 03:36 PM, Chris Angelico wrote: >> On Mon, Jun 25, 2012 at 8:26 AM, Charles Hixson >> wrote: >>> The code: >>> finally: >>> print ("at finally") >>> print ("chunks =") >>> produces this result: >>> path 3... >> Can you state more clearly the problem, please? I'm seeing output that >> can't have come from the code posted (for instance, immediately after >> the "at finally", I'm expecting to see the "chunks =" line), and I'm >> not seeing any exception information, so I can't even hazard a guess >> as to what's throwing the exception. >> >> Presumably these are two methods in the same class, since you're >> calling it as "self.chunkLine", but beyond that, it's hard to know. >> Take off the try/except and let your exception go to console, that's >> usually the easiest thing to deal with. >> >> Chris Angelico > Sorry, but it *DID* come from the code posted. Which is why I was so > confused. I finally tracked it down to "self was not defined" by > altering the except section to read: > except BaseException as ex: > print ("caught exception") > print (ex) > finally: > print ("at finally") > The documentation section covering the except statement could stand to be a *LOT* clearer. I read the sections on the except statement and exception handlers several times and couldn't figure out was the "as" argument of the except statement was for. "Target" doesn't communicate much to me. The one I finally used as indicated above was modified from some code that I found through Google. I still don't really know what "as" means, except that if you use it, and you print out the "target", you'll get some kind of informative message. (The one that I got said "self was not defined" .. that's a paraphrase. I can't remember the precise wording.) And that interpretation is based on what the result was, not on anything said in the documentation. IIRC, the Python2 documentation used code examples to indicate what was the right way to write an exception handler. I realize that Python3 is much different, but that approach was a very good one. > -- Charles Hixson From bahamutzero8825 at gmail.com Mon Jun 25 02:23:52 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 25 Jun 2012 01:23:52 -0500 Subject: exception problem In-Reply-To: <4FE7F6CC.2050704@earthlink.net> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> <4FE7F6CC.2050704@earthlink.net> Message-ID: <4FE803F8.3050207@gmail.com> On 6/25/2012 12:27 AM, Charles Hixson wrote: > The documentation section covering the except statement could stand to > be a *LOT* clearer. I read the sections on the except statement and > exception handlers several times and couldn't figure out was the "as" > argument of the except statement was for. I agree that the tutorial doesn't explain the use of "as" very well, but it does cover that a bare except is not normally good to use: "The last except clause may omit the exception name(s), to serve as a wildcard. Use this with extreme caution, since it is easy to mask a real programming error in this way!" > I still don't really know what > "as" means, except that if you use it, and you print out the "target", > you'll get some kind of informative message. "as" lets you refer to the exception object that was caught. I find this useful mainly for exceptions that have attributes (most built-in exceptions don't, but many user-defined exceptions do). A full traceback is much more useful for debugging than what a simple print(exc) will give. There are a few different ways to get traceback information without letting the exception simply propagate and terminate the program. You can get some simple information from sys.exc_info() (and you can feed the traceback object to a function in the traceback module), or you can log it with the logging.exception() function or the exception() method of a Logger from the same module. I recommend using logging. However, it's generally best to just let any unexpected exceptions propagate unless the program absolutely must continue, especially when debugging. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From stefan_ml at behnel.de Mon Jun 25 03:24:52 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 25 Jun 2012 09:24:52 +0200 Subject: Faster way to map numpy arrays In-Reply-To: References: Message-ID: Saurabh Kabra, 25.06.2012 05:37: > I have written a script to map a 2D numpy array(A) onto another array(B) of > different dimension. more than one element (of array A) are summed and > mapped to each element of array B. To achieve this I create a list where I > store the index of array A to be mapped to array B. The list is the > dimension of array B (if one can technically say that) and each element is > a list of indices to be summed. Then I parse this list with a nested loop > and compute each element of array B. > > Because of the nested loop and the big arrays the process takes a minute or > so. My question is: is there a more elegant and significantly faster way of > doing this in python? I'm sure there's a way to do this kind of transformation more efficiently in NumPy. I faintly recall that you can use one array to index into another, something like that might do the trick already. In any case, using a NumPy array also for the mapping matrix sounds like a straight forward thing to try. But you might also want to take a look at Cython. It sounds like a problem where a trivial Cython implementation would seriously boost the performance. http://docs.cython.org/src/tutorial/numpy.html Stefan From steve+comp.lang.python at pearwood.info Mon Jun 25 03:40:17 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Jun 2012 07:40:17 GMT Subject: exception problem References: <4FE79433.8020704@earthlink.net> <4FE794F1.6000202@earthlink.net> Message-ID: <4fe815e0$0$29866$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Jun 2012 18:45:45 -0400, Dave Angel wrote: > Bare exceptions are the bane of > programming; Using it is like trying to learn to drive while > blindfolded. +1 QOTW I really wish bare exceptions were removed from Python 3. There's no point to try...except any longer, and it's just an attractive nuisance to beginners. -- Steven From steve+comp.lang.python at pearwood.info Mon Jun 25 03:48:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Jun 2012 07:48:35 GMT Subject: exception problem References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> Message-ID: <4fe817d3$0$29866$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Jun 2012 16:16:25 -0700, Charles Hixson wrote: > But what I wanted was to catch any exception. Be careful of what you ask for, since you might get it. "Catch any exception" is almost certainly the wrong thing to do, almost always. The one good reason I've seen for a bare except is to wrap the top level of an application in order to redirect uncaught exceptions to something other than the console (such as a GUI error dialog box). And even then, you probably don't want to catch *all* exceptions, but only those that inherit from Exception: try: main() # run my application except Exception as err: display_error_dialog(err) # or log to a file, or something... -- Steven From steve+comp.lang.python at pearwood.info Mon Jun 25 03:49:50 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Jun 2012 07:49:50 GMT Subject: exception problem References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> Message-ID: <4fe8181e$0$29866$c3e8da3$5496439d@news.astraweb.com> On Mon, 25 Jun 2012 09:51:15 +1000, Chris Angelico wrote: > Mind you, I think every programmer should spend some time debugging > blind. You're a cruel, cruel man. I suppose next you're going to say that every programmer should spend some time programming using Notepad as their only editor. -- Steven From rosuav at gmail.com Mon Jun 25 04:08:07 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jun 2012 18:08:07 +1000 Subject: exception problem In-Reply-To: <4fe8181e$0$29866$c3e8da3$5496439d@news.astraweb.com> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> <4fe8181e$0$29866$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jun 25, 2012 at 5:49 PM, Steven D'Aprano wrote: > On Mon, 25 Jun 2012 09:51:15 +1000, Chris Angelico wrote: > >> Mind you, I think every programmer should spend some time debugging >> blind. > > You're a cruel, cruel man. > > I suppose next you're going to say that every programmer should spend > some time programming using Notepad as their only editor. No no, that's just *too* nasty. But there are times now and then when, perhaps, you're working remotely, and you have to figure out what's wrong without exception tracebacks. Sure, 95% of programmers will never be in that situation, but it's a good skill to have. And when that disaster _does_ strike and you're stuck with just a file uploader and a crashing script, you'll look awesome for being able to fix it in five minutes flat :) ChrisA From stefan_ml at behnel.de Mon Jun 25 04:36:28 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 25 Jun 2012 10:36:28 +0200 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: gmspro, 24.06.2012 05:46: > Why has python3 been created as a seperate language where there is still python2.7 ? > > What's the benifit to make python3 over python2.7 ? I have read this though: http://docs.python.org/release/3.0.1/whatsnew/3.0.html > > What's wrong editing/customizing/changin python2.7 instead of making a seperate language? > > What's wrong working with python2.7? > > As python3 is not backward compatible, so many packages built on python2.7 will be gone someday. Or you have to re-write/upgrade to python3. That's a tedious/labourious task. > > So after 5 years will we get another python4 as seperate language? > > Any answer will be highly appreciated. Note that this topic has been discussed in full and overly full length several times on this list. You may want to read up on it in the archives. I'm not sure if you're just trolling (posting suggestive questions with well-known answers is a well established troll metier) or if you really want an answer to your questions, but here's a short answer anyway. The intention of Py3 was to deliberately break backwards compatibility in order to clean up the language. The situation is not as bad as you seem to think, a huge amount of packages have been ported to Python 3 already and/or work happily with both language dialects. It's not an either-or kind of thing, you can have both with a little effort. And, no, there won't be a Py4 in 5 years. The established release time frame is way longer. Stefan From bahamutzero8825 at gmail.com Mon Jun 25 04:48:02 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 25 Jun 2012 03:48:02 -0500 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: <4FE825C2.4010604@gmail.com> On 6/23/2012 10:46 PM, gmspro wrote: > What's wrong editing/customizing/changin python2.7 instead of making a > seperate language? py3k is not a separate language. In fact, it is possible to maintain a codebase that supports 2.2 (maybe even older), 3.3, and every version in between. > What's wrong working with python2.7? A lot. Off the top of my head: In 2.7, the print statement has arbitrary and unobvious syntax. The print() function has arguments. In 2.7, input() evaluates incoming strings, which is almost always not appropriate and can lead to exploits. In py3k, input() doesn't do this. It returns exactly what it receives. I barely work with 2.x at all; others will be able to list many more in much more detail. > As python3 is not backward compatible, so many packages built on > python2.7 will be gone someday. Or you have to re-write/upgrade to > python3. That's a tedious/labourious task. Indeed. Backward compatibility is important, but it should not be king. Python had (and arguably still has) major issues that could only be fixed by breaking backward compatibility. AFAIK, people use 2.x mainly because they depend on libraries that are not compatible with py3k yet (e.g., Twisted) or because their preferred implementation does not implement 3.x (e.g., Jython, PyPy). > So after 5 years will we get another python4 as seperate language? No, but there may be changes that aren't backward compatible. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From k.sahithi2862 at gmail.com Mon Jun 25 05:53:32 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Mon, 25 Jun 2012 02:53:32 -0700 (PDT) Subject: ACTRESS HOT PHOTOS & VIDEOS Message-ID: <4deccf34-2ff1-45f8-adf6-38b9ec0fa614@f8g2000pbf.googlegroups.com> ALL INTERVIEW QUESTIONS& STUDY MATERIAL http://newdotnetinterviewquestions.blogspot.in/ TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR LATEST MOVIE UPDATED LINKS ACTRESS HOT STILLS IN SIIMA AWARDS 2012 http://actressgallery-kalyani.blogspot.in/2012/06/actress-siima-awards-2012-stills.html EM BABU LADDU KAVALA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/06/em-babu-laddu-kavala-movie-stills.html SRMANARAYANA MOVIE HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/06/srimannarayana-movie-stills.html KAJAL AGARWAL LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/06/kajal-agarwal-latest-stills.html SANA KHAN LATEST HOT PHOTO GALLERY http://actressgallery-kalyani.blogspot.in/2012/06/sana-khan-latest-stills.html COOL BOYS HOT GIRLS MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/06/cool-boys-hot-girls-movie-stills.html MITAAYI MOVIE LATEST GALLERY http://actressgallery-kalyani.blogspot.in/2012/06/mitaayi-movie-stills.html NAGARJUNA DAMARUKAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/damarukam-movie-stills.html ALLU ARJUN JULAYI MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/julayi-movie-stills.html SUDIGADU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/sudigadu-movie-stills.html MR 7 MOVIE FILM GALLERY http://actressgallery-kalyani.blogspot.in/2012/05/mr7-movie-stills.html ALL THE BEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/all-best-movie-stills.html Midatha Telugu movie Hot Namitha Stills http://actressgallery-kalyani.blogspot.com/2012/05/midatha-movie-stills.html OKA COLLEGE LOVE STORY MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/oka-college-love-story-movie-stills.html KATRINA KAIF LATEST UNSEENED PHOTOS http://actressgallery-kalyani.blogspot.com/2012/05/katrina-kaif-latest-pics.html TAMIL ACTRESS ARUNDHATI HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/05/arundhati-tamil-actress.html THANDHAVAM MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/05/thandavam-movie-stills.html KHO KHO LATEST MOVIE SPICY STILLS http://actressgallery-kalyani.blogspot.com/2012/05/kho-kho-movie-stills.html Oh My Love Movie Latest Photo Gallery http://actressgallery-kalyani.blogspot.com/2012/04/oh-my-love-movie-stills.html Oka Romantic Crime katha Movie stills http://actressgallery-kalyani.blogspot.in/2012/04/oka-romantic-crime-katha-movie-stills.html DARUVU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/03/daruvu-movie-stills.html Pavan Kalyan,Shruthi Hasan Gabbar Singh Movie Photos http://actressgallery-kalyani.blogspot.in/2012/04/gabbar-singh-movie-stills.html Good Morning Latest Movie Stills http://actressgallery-kalyani.blogspot.com/2012/04/good-morning-movie-stills.html EEGA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/04/eega-movie-stills.html Mem Vayasuku Vacham Latest Hot Stills http://actressgallery-kalyani.blogspot.com/2012/04/mem-vayasuku-vacham-stills.html DAMMU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/04/dammu-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html HOT LINKS FOR YOUTH ONLY PRANEETHA HOT SPICY IMAGES http://actressimages-9.blogspot.in/2012/06/praneetha-latest-stills.html SHRUTHI HASSAN HALF SAREE STILLS http://actressimages-9.blogspot.in/2012/05/shruti-hassan-half-saree-stills.html TAMANNA HOT NAVEL PHOTOS http://actressimages-9.blogspot.in/2012/05/tamanna-navel-photos.html TRISHA LATEST HOT STILLS http://actressgallery9.blogspot.in/2012/05/trisha.html MONIKA LATEST HOT HD STLLS http://actressgallery9.blogspot.in/2012/05/monika-stills.html MALLIKA KAPOOR HOT SIZZLING STILLS http://actressimages-9.blogspot.in/2012/05/mallika-kapoor.html Richa Panai Stills http://actressimages-9.blogspot.com/2012/04/richa-panai-stills.html MADHAVI LATHA LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/04/madhavi-latha-stills.html KRITI KHARBANDA HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/kriti-kharbanda.html NEELAM UPADHYAY HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/neelam-upadhyay.html SAMANTHA LATEST HOT ROMANTIC STILLS http://actressimages-9.blogspot.in/2012/03/samantha-latest-stills.html NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html From motoom at xs4all.nl Mon Jun 25 06:10:47 2012 From: motoom at xs4all.nl (Michiel Overtoom) Date: Mon, 25 Jun 2012 12:10:47 +0200 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: <8BEC6AEF-B22C-4F58-BDDD-297ED506D541@xs4all.nl> On Jun 24, 2012, at 05:46, gmspro wrote: > Why has python3 been created as a seperate language where there is still python2.7? It has not. Python2 and Python3 are very similar. It's not like if you learn Python using version 2, you have to relearn the language when you want to switch Python3. The syntax is the same, only 'print' is a function instead of a statement. Other improvements are unicode strings, cleanups in the library, lazy iterators, new-style classes by default etc... mostly background stuff you won't even notice in daily Python use. Greetings, -- Test your knowledge of flowers! http://www.learn-the-flowers.com or http://www.leer-de-bloemen.nl for the Dutch version. Test je kennis van bloemen! http://www.leer-de-bloemen.nl of http://www.learn-the-flowers.com voor de Engelse versie. From wxjmfauth at gmail.com Mon Jun 25 07:17:00 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 25 Jun 2012 04:17:00 -0700 (PDT) Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <4fe10972$0$29980$c3e8da3$5496439d@news.astraweb.com> <3d725d3a-3159-4732-b5ae-17feedcf045d@k5g2000vbf.googlegroups.com> <4fe229ad$0$29980$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4599dbd9-7252-4517-bf7f-fb4afb48a068@m3g2000vbl.googlegroups.com> Mea culpa. I had not my head on my shoulders. Inputing if working fine, it returns "text" correctly. However, and this is something different, I'm a little bit surprised, input() does not handle escaped characters (\u, \U). Workaround: encode() and decode() as "raw-unicode-escape". jmf From oscar.j.benjamin at gmail.com Mon Jun 25 07:29:12 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 25 Jun 2012 12:29:12 +0100 Subject: Faster way to map numpy arrays In-Reply-To: References: Message-ID: On 25 June 2012 08:24, Stefan Behnel wrote: > Saurabh Kabra, 25.06.2012 05:37: > > I have written a script to map a 2D numpy array(A) onto another array(B) > of > > different dimension. more than one element (of array A) are summed and > > mapped to each element of array B. To achieve this I create a list > where I > > store the index of array A to be mapped to array B. The list is the > > dimension of array B (if one can technically say that) and each element > is > > a list of indices to be summed. Then I parse this list with a nested loop > > and compute each element of array B. > > > > Because of the nested loop and the big arrays the process takes a minute > or > > so. My question is: is there a more elegant and significantly faster way > of > > doing this in python? > > I'm sure there's a way to do this kind of transformation more efficiently > in NumPy. I faintly recall that you can use one array to index into > another, something like that might do the trick already. In any case, using > a NumPy array also for the mapping matrix sounds like a straight forward > thing to try. > I can't tell from the description of the problem what you're trying to do but for the special case of summing along one axis of a numpy array of dimension N to produce a new numpy array of dimension N-1, there is fast builtin support in numpy: >>> import numpy >>> a = numpy.array([[1, 2], [3, 4]]) >>> a array([[1, 2], [3, 4]]) >>> a.sum() # sum of all elements 10 >>> a.sum(axis=1) # sum of each row array([3, 7]) >>> a.sum(axis=0) # sum of each column array([4, 6]) If your problem is not in this form, you can use numpy's fancy indexing to convert it to this form, provided the number of elements summed from A is the same for each element of B (i.e. if each element of B is the result of summing exactly 10 elements chosen from A). > But you might also want to take a look at Cython. It sounds like a problem > where a trivial Cython implementation would seriously boost the > performance. > > http://docs.cython.org/src/tutorial/numpy.html > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jun 25 07:51:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jun 2012 21:51:33 +1000 Subject: Py3.3 unicode literal and input() In-Reply-To: <4599dbd9-7252-4517-bf7f-fb4afb48a068@m3g2000vbl.googlegroups.com> References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <4fe10972$0$29980$c3e8da3$5496439d@news.astraweb.com> <3d725d3a-3159-4732-b5ae-17feedcf045d@k5g2000vbf.googlegroups.com> <4fe229ad$0$29980$c3e8da3$5496439d@news.astraweb.com> <4599dbd9-7252-4517-bf7f-fb4afb48a068@m3g2000vbl.googlegroups.com> Message-ID: On Mon, Jun 25, 2012 at 9:17 PM, jmfauth wrote: > Mea culpa. I had not my head on my shoulders. > Inputing if working fine, it returns "text" correctly. > > However, and this is something different, I'm a little > bit surprised, input() does not handle escaped characters > (\u, \U). > Workaround: encode() and decode() as "raw-unicode-escape". It's the exact same thing. They're a backslash followed by a letter U. However, if your stdin is set to (say) UTF-8, then bytes that represent non-ASCII characters will be correctly translated, eliminating any need for code-style escapes. Allowing your users to put escaped Unicode characters into their input opens up a huge morass - do they have to double every backslash? what if they actually wanted "\", "u", etc? etc? etc? ChrisA From steve+comp.lang.python at pearwood.info Mon Jun 25 08:08:38 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Jun 2012 12:08:38 GMT Subject: Py3.3 unicode literal and input() References: <3cbb7549-dd1a-4139-a2e4-b4fd7a8010c6@n5g2000vbb.googlegroups.com> <4fdefed0$0$29980$c3e8da3$5496439d@news.astraweb.com> <73836101-3354-4dc9-8c24-ffa53b2e564b@a16g2000vby.googlegroups.com> <4fe10972$0$29980$c3e8da3$5496439d@news.astraweb.com> <3d725d3a-3159-4732-b5ae-17feedcf045d@k5g2000vbf.googlegroups.com> <4fe229ad$0$29980$c3e8da3$5496439d@news.astraweb.com> <4599dbd9-7252-4517-bf7f-fb4afb48a068@m3g2000vbl.googlegroups.com> Message-ID: <4fe854c6$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 25 Jun 2012 04:17:00 -0700, jmfauth wrote: > Mea culpa. I had not my head on my shoulders. Inputing if working fine, > it returns "text" correctly. > > However, and this is something different, I'm a little bit surprised, > input() does not handle escaped characters (\u, \U). No, it is not different, it is exactly the same. input always returns the exact characters you type. If you type a b c space d, input returns "abc d". If you type a b c backslash u, input returns "abc\u". input does not treat the text as anything special. If you want to treat the text "1234" as an int, you have to convert it into an int using the int() function. If you want to treat the text as a list, you have to parse it as a list. If you want to treat it as Python source code, you have to parse it as Python source code. And if you want to treat it as a Python string literal format using escape characters, you have to parse it as Python string literal format. -- Steven From gundlach at gmail.com Mon Jun 25 08:34:37 2012 From: gundlach at gmail.com (Michael Gundlach) Date: Mon, 25 Jun 2012 08:34:37 -0400 Subject: SSL handshake hanging, despite bugfix in stdlib In-Reply-To: References: Message-ID: Hello again Terry (and mailing list), On Sun, Jun 24, 2012 at 9:34 AM, Michael Gundlach wrote: > I've now changed to 2.7.3, and if I don't write back in the next few days, > it means that that fixed the problem -- thanks for your help! :) > The problem still exists in Python 2.7.3: File "/usr/local/lib/python2.7/imaplib.py", line 1148, in __init__ IMAP4.__init__(self, host, port) File "/usr/local/lib/python2.7/imaplib.py", line 163, in __init__ self.open(host, port) File "/usr/local/lib/python2.7/imaplib.py", line 1160, in open self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) File "/usr/local/lib/python2.7/ssl.py", line 381, in wrap_socket ciphers=ciphers) File "/usr/local/lib/python2.7/ssl.py", line 143, in __init__ self.do_handshake() File "/usr/local/lib/python2.7/ssl.py", line 305, in do_handshake self._sslobj.do_handshake() KeyboardInterrupt What should I do next? File a bug? Thanks for your help! Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Jun 25 08:54:18 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 25 Jun 2012 13:54:18 +0100 Subject: How can i call array_length to get the length of array object? In-Reply-To: <87pq8orxzn.fsf@benfinney.id.au> References: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> <1340525704.2880.YahooMailClassic@web164605.mail.gq1.yahoo.com> <87pq8orxzn.fsf@benfinney.id.au> Message-ID: On 25/06/2012 02:17, Ben Finney wrote: > Mark Lawrence writes: > >> On 24/06/2012 09:15, gmspro wrote: >> >>> Why __len__() where the original name if array_length? Why is method >>> names like __NAME__ ? > > These are questions answered by getting a thorough grounding in the > fundamentals of Python. Please follow the Python tutorial > , from beginning to end, to learn > about the basics like this. > >> Why are you too bloody lazy to do any research before you post >> questions? > > I understand your frustration in this case, but there's no call for such > vitriol. Please keep it off this forum. > From http://www.thefreedictionary.com/vitriol - "Bitterly abusive feeling or expression." I do not believe that my comment above deserves the term vitriol. -- Cheers. Mark Lawrence. From excel at pharcyde.org Mon Jun 25 09:44:50 2012 From: excel at pharcyde.org (Andrew D'Angelo) Date: Mon, 25 Jun 2012 08:44:50 -0500 Subject: The Quran on Human Embryonic Development References: Message-ID: *Rimshot* wrote in message news:af4928a3-5613-48aa-96df-997b7a455a5f at googlegroups.com... > Well, I use wxFormBuilder for my embryonic GUIs, but I have no qualms (or > is that quorans) about changing the generated code to make it more > efficient. From antoon.pardon at rece.vub.ac.be Mon Jun 25 09:48:50 2012 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 25 Jun 2012 15:48:50 +0200 Subject: How can i call array_length to get the length of array object? In-Reply-To: References: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> Message-ID: <4FE86C42.4090601@rece.vub.ac.be> On 06/24/12 10:48, Stefan Behnel wrote: > gmspro, 24.06.2012 10:01: > >> Why are some methods/functions named in this way in python? __len__ >> >> underscoreunderscoreNAMEunderscoreunderscore >> >> Is there any speciality of naming such methods? >> > Yes. Look up "special methods" in the documentation. > > You may have noticed the correspondence between len() and __len__(). That > is Python's way of allowing you to implement this kind of generic > functionality (sometimes referred to as a protocol). > > You also asked why len() is a function instead of a method. Don't you find > it much easier to use one function for everything than to look up and > sometimes even learn one method for each kind of object you are dealing > with? Python prefers simplicity here. You want the length? Use len(). > > Stefan What does this have to do with using a function vs a method? In the python 2.x series, the iterator protocol, proscribe you need to define a "next" method, which you can call directly or which is called in for statements. Now in python 3.x the method is called "__next__" and there is a next-function which will call this __next__ method. I see no difference in difficulty between item = iter.next() and item = next(iter). Neither do I see a difference in difficulty between size = len(seq) or size = seq.len(). Sure it is possible for someone feeling uncooperative to write a class in which method giving the length of the object was named something different from "len". But that is now also possible. From sg552 at hotmail.co.uk Mon Jun 25 10:48:54 2012 From: sg552 at hotmail.co.uk (Rotwang) Date: Mon, 25 Jun 2012 15:48:54 +0100 Subject: cPickle - sharing pickled objects between scripts and imports In-Reply-To: <4fe64ea3$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4fe64ea3$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/06/2012 00:17, Steven D'Aprano wrote: > On Sat, 23 Jun 2012 19:14:43 +0100, Rotwang wrote: > >> The problem is that if the object was >> pickled by the module run as a script and then unpickled by the imported >> module, the unpickler looks in __main__ rather than mymodule for the >> object's class, and doesn't find it. > > Possibly the solution is as simple as aliasing your module and __main__. > Untested: > > # When running as a script > import __main__ > sys['mymodule'] = __main__ ??? What is "sys" here? > # When running interactively > import mymodule > __main__ = mymodule > > > of some variation thereof. > > Note that a full solution to this problem actually requires you to deal > with three cases: > > 1) interactive interpreter, __main__ normally would be the interpreter > global scope > > 2) running as a script, __main__ is your script > > 3) imported into another module which is running as a script, __main__ > would be that module. I had not thought of that. > In the last case, monkey-patching __main__ may very well break that > script. My original solution will also cause problems in this case. Thanks. -- Hate music? Then you'll hate this: http://tinyurl.com/psymix From charleshixsn at earthlink.net Mon Jun 25 11:14:04 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 25 Jun 2012 08:14:04 -0700 Subject: exception problem In-Reply-To: <4FE803F8.3050207@gmail.com> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> <4FE7F6CC.2050704@earthlink.net> <4FE803F8.3050207@gmail.com> Message-ID: <4FE8803C.3020108@earthlink.net> On 06/24/2012 11:23 PM, Andrew Berg wrote: > On 6/25/2012 12:27 AM, Charles Hixson wrote: > >> The documentation section covering the except statement could stand to >> be a *LOT* clearer. I read the sections on the except statement and >> exception handlers several times and couldn't figure out was the "as" >> argument of the except statement was for. >> > I agree that the tutorial doesn't explain the use of "as" very well, but > it does cover that a bare except is not normally good to use: > "The last except clause may omit the exception name(s), to serve as a > wildcard. Use this with extreme caution, since it is easy to mask a real > programming error in this way!" > > >> I still don't really know what >> "as" means, except that if you use it, and you print out the "target", >> you'll get some kind of informative message. >> > "as" lets you refer to the exception object that was caught. I find this > useful mainly for exceptions that have attributes (most built-in > exceptions don't, but many user-defined exceptions do). A full traceback > is much more useful for debugging than what a simple print(exc) will give. > There are a few different ways to get traceback information without > letting the exception simply propagate and terminate the program. You > can get some simple information from sys.exc_info() (and you can feed > the traceback object to a function in the traceback module), or you can > log it with the logging.exception() function or the exception() method > of a Logger from the same module. I recommend using logging. However, > it's generally best to just let any unexpected exceptions propagate > unless the program absolutely must continue, especially when debugging. > I read that that would happen, but " print (sys.exc_info()[:2]) " didn't even yield a blank line. It must have executed, because the print statement on the line before it executed, and there wasn't a loop or a jump (and also execution continued "normally" [the code still has bugs] afterward even if the finally isn't included). -- Charles Hixson From rosuav at gmail.com Mon Jun 25 11:22:08 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Jun 2012 01:22:08 +1000 Subject: exception problem In-Reply-To: <4FE8803C.3020108@earthlink.net> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> <4FE7F6CC.2050704@earthlink.net> <4FE803F8.3050207@gmail.com> <4FE8803C.3020108@earthlink.net> Message-ID: On Tue, Jun 26, 2012 at 1:14 AM, Charles Hixson wrote: > I read that that would happen, but " ?print (sys.exc_info()[:2]) " didn't > even yield a blank line. ?It must have executed, because the print statement > on the line before it executed, and there wasn't a loop or a jump (and also > execution continued "normally" [the code still has bugs] afterward even if > the finally isn't included). Unless it threw an exception, such as NameError if you haven't imported sys. In that case, execution will continue through the 'finally' clause and then raise the exception (at least, I think that's how it goes - raising exceptions in exception handlers is not something I've made a study of). ChrisA From santosh.ssit at gmail.com Mon Jun 25 13:21:13 2012 From: santosh.ssit at gmail.com (hisan) Date: Mon, 25 Jun 2012 10:21:13 -0700 (PDT) Subject: How keep python socket alive for ever by setting Keep alive flag. Message-ID: <44c35921-ff32-4e80-b8fd-4dd2f3960a21@googlegroups.com> Hi All, I want to open a socket connection and keep it alive for ever or until i explicitly close the socket connection. below is my code though i have set keep alive flag the socket gets closed after some time .please help me out here sb_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,socket.SOL_TCP) sb_sock.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) sb_sock.connect((msg_host, host_port)) sb_sock.send(reg_msg) From drsalists at gmail.com Mon Jun 25 13:30:41 2012 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 25 Jun 2012 17:30:41 +0000 Subject: How keep python socket alive for ever by setting Keep alive flag. In-Reply-To: <44c35921-ff32-4e80-b8fd-4dd2f3960a21@googlegroups.com> References: <44c35921-ff32-4e80-b8fd-4dd2f3960a21@googlegroups.com> Message-ID: http://www.unixguide.net/network/socketfaq/4.7.shtml It's better to add the ability to recreate a socket if it encounters trouble. SO_KEEPALIVE is there to help you detect if the other end of your connection has disappeared. Network programming has relatively few absolutes - it's best to build in error checking and sometimes, error responses that go beyond mere error messages. On Mon, Jun 25, 2012 at 5:21 PM, hisan wrote: > Hi All, > > I want to open a socket connection and keep it alive for ever or until i explicitly close the socket connection. > > below is my code though i have set keep alive flag the socket gets closed after some time .please help me out here > > ? ? ? ? ? ?sb_sock = socket.socket(socket.AF_INET, > socket.SOCK_STREAM,socket.SOL_TCP) > ? ? ? ? ? ?sb_sock.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) > ? ? ? ? ? ?sb_sock.connect((msg_host, host_port)) > ? ? ? ? ? ?sb_sock.send(reg_msg) > -- > http://mail.python.org/mailman/listinfo/python-list From dthomas86 at me.com Mon Jun 25 14:19:54 2012 From: dthomas86 at me.com (David Thomas) Date: Mon, 25 Jun 2012 11:19:54 -0700 (PDT) Subject: Executing Python Scripts on Mac using Python Launcher Message-ID: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> Hello, This is my first post so go easy on me. I am just beginning to program using Python on Mac. When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same piece of code and run it in windows it seems to execute as exactly intended. How can I make my python script to open up correctly using Python Launcher? I am running 10.7 on my Mac. I would upload a photo with the error I get but I can't seem to find the upload feature in this group. Thanks From excel at pharcyde.org Mon Jun 25 15:10:10 2012 From: excel at pharcyde.org (Andrew D'Angelo) Date: Mon, 25 Jun 2012 14:10:10 -0500 Subject: vBulletin scraper -- feasible? Message-ID: Taking a look through vBulletin's HTML, I was wondering whether it would be overly difficult to parse it into nice, manipulatible data. I'd suppose my ultimate goal would be to dynamically parse a vBulletin and feed it into a locally hosted NNTP server. From cmpython at gmail.com Mon Jun 25 15:39:12 2012 From: cmpython at gmail.com (CM) Date: Mon, 25 Jun 2012 12:39:12 -0700 (PDT) Subject: Python and Facebook References: Message-ID: On Jun 24, 12:16?pm, Alec Taylor wrote: > This is the most active one, forked from the official facebook one > (when they used to maintain it themselves):https://github.com/pythonforfacebook/facebook-sdk > > > > > > > > On Mon, Jun 25, 2012 at 1:35 AM, Chris Angelico wrote: > > On Mon, Jun 25, 2012 at 1:16 AM, Jerry Rocteur wrote: > > >> Hi, > > >> I posted this mail on Friday and received no replies.. > > >> I'm curious.. > > >> Is it because > > >> 1) Python is not the language to use for Facebook, use Javascript or XXX > >> ?? instead ? Please tell. > >> 2) I've missed the point and this is very well documented so RTFM (I > >> couldn't find it) > >> 3) You guys don't use Facebook, you have a life .. > > > I personally don't use Facebook, but I don't have much of a life > > either..... But I've never heard of a specific Python-Facebook module, > > until just now when I googled it and found a couple of things. > > > Two points: > > > 1) Python's pretty good at networking. If all else fails, you can > > always just implement whatever Facebook's API is (the Google snippets > > suggest it's REST, ie all HTTP, which Python does admirably), and go > > from there. > > > 2) An active Python-Facebook module will have active developers who > > probably know far more about how to use their module than random > > people like me who happen to read all of python-list :) There may well > > be such people on this list, but since you've received no replies, > > it's possible there aren't. (It's also possible that they don't > > monitor this list on weekends, though. You never know.) > > > 3) What do Facebook think of you downloading all their content and > > viewing it without their ads? Not that I particularly care, but it may > > be something to consider, since you're effectively going to get > > everything that Facebook offers you (ie posts/pics/etc) without > > everything that Facebook steals from you and sells (page views, ad > > impressions, etc). > > > (Among our points are such diverse elements as... wrong Pythons, but whatever.) > > > There's no official Python-Facebook module (afaik!!), but a quick web > > search for 'python facebook' should get you to the couple that I saw, > > and possibly others. The next question is, do you trust any of them... > > Good luck with that one! :) > > > Chris Angelico > > -- > >http://mail.python.org/mailman/listinfo/python-list FWOW. I tried for about a week every Python Facebook module out there I could find (including that one), with Python 2.5 or 2.7, and for whatever reason was unsuccessful in uploading a photo and quit trying. Frustrating. From nick.cash at npcinternational.com Mon Jun 25 15:44:10 2012 From: nick.cash at npcinternational.com (Nick Cash) Date: Mon, 25 Jun 2012 19:44:10 +0000 Subject: vBulletin scraper -- feasible? In-Reply-To: References: Message-ID: <846C3A8E860C4344B567D813B63AA51D0AE23226@CH1PRD0610MB356.namprd06.prod.outlook.com> You may want to look into http://www.crummy.com/software/BeautifulSoup/ It's made for parsing (potentially bad) HTML, and is quite easy to use. I'd say it's quite feasible. Thanks, Nick Cash NPC International -----Original Message----- From: python-list-bounces+nick.cash=npcinternational.com at python.org [mailto:python-list-bounces+nick.cash=npcinternational.com at python.org] On Behalf Of Andrew D'Angelo Sent: Monday, June 25, 2012 14:10 To: python-list at python.org Subject: vBulletin scraper -- feasible? Taking a look through vBulletin's HTML, I was wondering whether it would be overly difficult to parse it into nice, manipulatible data. I'd suppose my ultimate goal would be to dynamically parse a vBulletin and feed it into a locally hosted NNTP server. -- http://mail.python.org/mailman/listinfo/python-list From benjamin.kaplan at case.edu Mon Jun 25 15:49:07 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 25 Jun 2012 12:49:07 -0700 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> Message-ID: On Mon, Jun 25, 2012 at 11:19 AM, David Thomas wrote: > Hello, > This is my first post so go easy on me. ?I am just beginning to program using Python on Mac. ?When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same piece of code and run it in windows it seems to execute as exactly intended. > ?How can I make my python script to open up correctly using Python Launcher? ?I am running 10.7 on my Mac. ?I would upload a photo with the error I get but I can't seem to find the upload feature in this group. > > Thanks > -- You can't find the upload feature because this isn't a Google Group. It's a Usenet newsgroup that Google Groups provides access to that's also available as a mailing list. If you want to provide an image, use an image host and link to the image. As to your question, I have a few questions of my own. What version of Python are you using? Is it the version included in Mac OS X, installed from a python.org binary, compiled by source, or installed through a package manager? What happens if you call the script from the command line instead of using the Launcher application? From Joshua.R.English at gmail.com Mon Jun 25 16:04:32 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Mon, 25 Jun 2012 13:04:32 -0700 (PDT) Subject: Getting lazy with decorators In-Reply-To: References: <9d0c01f4-4430-4a45-8776-20d8dede9e14@googlegroups.com> Message-ID: <513d25ea-e977-4b84-b388-bfb23c171aae@googlegroups.com> On Sunday, June 24, 2012 1:07:45 AM UTC-7, Peter Otten wrote: > > You cannot access a class instance because even the class itself doesn't > exist yet. You could get hold of the class namespace with sys._getframe(), > > def add_help(f): > exec """\ > def help_%s(self): > f = getattr(self, %r) > self.show_help(f) > """ % (f.__name__[3:], f.__name__) in sys._getframe(1).f_locals > return f > > but here's a simpler approach: > > import cmd > > def add_help(f): > def help(self): > self.show_help(f) > f.help = help > return f > > > class BaseCmd(cmd.Cmd): > def __init__(self, *args, **kwargs): > cmd.Cmd.__init__(self, *args, **kwargs) > > def show_help(self, func): > print "\n".join((line.strip() for line in > func.__doc__.splitlines())) > > def __getattr__(self, name): > if name.startswith("help_"): > helpfunc = getattr(self, "do_" + name[5:]).help > setattr(self.__class__, name, helpfunc) > return getattr(self, name) > raise AttributeError > > @add_help > def do_done(self, line): > """done > Quits this and goes to higher level or quits the application. > I mean, what else do you expect? > """ > return True > > if __name__=='__main__': > c = BaseCmd() > c.cmdloop() Okay. If I understand this, you are adding a help attribute to the class method. The help attribute is itself a function. There is nothing in the documentation (that I have found) that points to this solution. Even after reading the do_help method in the cmd.Cmd source, I don't see this as working. Yet it works. How? From Joshua.R.English at gmail.com Mon Jun 25 16:04:32 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Mon, 25 Jun 2012 13:04:32 -0700 (PDT) Subject: Getting lazy with decorators In-Reply-To: References: <9d0c01f4-4430-4a45-8776-20d8dede9e14@googlegroups.com> Message-ID: <513d25ea-e977-4b84-b388-bfb23c171aae@googlegroups.com> On Sunday, June 24, 2012 1:07:45 AM UTC-7, Peter Otten wrote: > > You cannot access a class instance because even the class itself doesn't > exist yet. You could get hold of the class namespace with sys._getframe(), > > def add_help(f): > exec """\ > def help_%s(self): > f = getattr(self, %r) > self.show_help(f) > """ % (f.__name__[3:], f.__name__) in sys._getframe(1).f_locals > return f > > but here's a simpler approach: > > import cmd > > def add_help(f): > def help(self): > self.show_help(f) > f.help = help > return f > > > class BaseCmd(cmd.Cmd): > def __init__(self, *args, **kwargs): > cmd.Cmd.__init__(self, *args, **kwargs) > > def show_help(self, func): > print "\n".join((line.strip() for line in > func.__doc__.splitlines())) > > def __getattr__(self, name): > if name.startswith("help_"): > helpfunc = getattr(self, "do_" + name[5:]).help > setattr(self.__class__, name, helpfunc) > return getattr(self, name) > raise AttributeError > > @add_help > def do_done(self, line): > """done > Quits this and goes to higher level or quits the application. > I mean, what else do you expect? > """ > return True > > if __name__=='__main__': > c = BaseCmd() > c.cmdloop() Okay. If I understand this, you are adding a help attribute to the class method. The help attribute is itself a function. There is nothing in the documentation (that I have found) that points to this solution. Even after reading the do_help method in the cmd.Cmd source, I don't see this as working. Yet it works. How? From tjreedy at udel.edu Mon Jun 25 16:19:52 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 25 Jun 2012 16:19:52 -0400 Subject: SSL handshake hanging, despite bugfix in stdlib In-Reply-To: References: Message-ID: On 6/25/2012 8:34 AM, Michael Gundlach wrote: > Hello again Terry (and mailing list), > > On Sun, Jun 24, 2012 at 9:34 AM, Michael Gundlach > wrote: > > I've now changed to 2.7.3, and if I don't write back in the next few > days, it means that that fixed the problem -- thanks for your help! :) > > > The problem still exists in Python 2.7.3: > > File "/usr/local/lib/python2.7/imaplib.py", line 1148, in __init__ > IMAP4.__init__(self, host, port) > File "/usr/local/lib/python2.7/imaplib.py", line 163, in __init__ > self.open(host, port) > File "/usr/local/lib/python2.7/imaplib.py", line 1160, in open > self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) > File "/usr/local/lib/python2.7/ssl.py", line 381, in wrap_socket > ciphers=ciphers) > File "/usr/local/lib/python2.7/ssl.py", line 143, in __init__ > self.do_handshake() > File "/usr/local/lib/python2.7/ssl.py", line 305, in do_handshake > self._sslobj.do_handshake() > KeyboardInterrupt > > What should I do next? File a bug? Issue x ended with the message that the patch to issue y presumably fixed issue x as well. I see two choices. (WHere I forget x and y, but they were defined in previous posts.) 1. Post to issue x something like "I recently started getting what appears to be the same bug in 2.6.6 and 2.7.3 when connecting to Google. Should this be reopened or should I file a new report?" and wait for a response. 2. Open new issue z, mentioning issue x and then post to issue x "I opened an issue about the same or related bug in #z." You should give the actual IMAP call that caused the problem. Does is bomb when given in isolation, or does it have to be embedded in other code that would be affecting the context somehow (probably improperly). -- Terry Jan Reedy From tjreedy at udel.edu Mon Jun 25 16:20:58 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 25 Jun 2012 16:20:58 -0400 Subject: How can i call array_length to get the length of array object? In-Reply-To: References: <1340524913.38366.YahooMailClassic@web164603.mail.gq1.yahoo.com> <1340525704.2880.YahooMailClassic@web164605.mail.gq1.yahoo.com> <87pq8orxzn.fsf@benfinney.id.au> Message-ID: On 6/25/2012 8:54 AM, Mark Lawrence wrote: > On 25/06/2012 02:17, Ben Finney wrote: >> Mark Lawrence writes: >> >>> On 24/06/2012 09:15, gmspro wrote: >>> >>>> Why __len__() where the original name if array_length? Why is method >>>> names like __NAME__ ? >> >> These are questions answered by getting a thorough grounding in the >> fundamentals of Python. Please follow the Python tutorial >> , from beginning to end, to learn >> about the basics like this. >> >>> Why are you too bloody lazy to do any research before you post >>> questions? >> >> I understand your frustration in this case, but there's no call for such >> vitriol. Please keep it off this forum. >> > > From http://www.thefreedictionary.com/vitriol - "Bitterly abusive > feeling or expression." I do not believe that my comment above deserves > the term vitriol. I saw it more as sarcasm and an expression of frustration. -- Terry Jan Reedy From gogala.mladen at gmail.com Mon Jun 25 17:20:25 2012 From: gogala.mladen at gmail.com (Mladen Gogala) Date: Mon, 25 Jun 2012 21:20:25 +0000 (UTC) Subject: Perl __DATA__ construct. Message-ID: I have a script in Perl that I need to rewrite to Python. The script contains __DATA__ at the end of the script, which enables Perl to access all the data after that through a file descriptor, like this: usage() if ( !$stat or !defined($home) or !defined($base) or !defined ($sid) ); while () { s/%OB/$base/; if ( length($home) > 0 ) { s/%OH/$home/; } else { s/\/%OH$//; } if ( length($sid) > 0 && /%OS/ ) { s/%OS/$sid/; } elsif (/%OS/) { next; } s/%VR/$ver/; print; } __DATA__ # .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi set -a # User specific aliases and functions export PATH=/sbin:/bin:/usr/sbin:$PATH export EDITOR=vi export ORACLE_BASE=%OB export ORACLE_HOME=$ORACLE_BASE/product/%VR/%OH export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/opt/odbc/lib:$ORACLE_HOME/lib32 export CLASSPATH=/opt/java/lib/tools.jar:$ORACLE_HOME/jdbc/lib/ ojdbc14.jar:. ...... How do I do the same thing in Python? Alternatively, in Perl I can put an entire file into a string by using something like: $str=< References: <4FE7C301.6010101@stackless.com> Message-ID: <4FE8D9FB.8010101@stackless.com> Abour tiffany... On 6/25/12 3:46 AM, Christian Tismer wrote: > Tiffany - Read/Write Multipage-Tiff with PIL without PIL > ======================================================== > > Tiffany stands for any tiff. The tiny module solves a large set of > problems, has no dependencies and just works wherever Python works. > Tiffany was developed in the course of the *DiDoCa* project and will > always appear on PyPi. > > Version 0.6 > ----------- > > This is a compatibility update for Python 3.2. > > Tiffany now works on Python 2.6, 2.7 and 3.2. > > This version also reduces the needed PIL files to only four. The > same files work for python2 and python3. > > You can help me by sending some tiff files with different encoding > and larger file size for testing. > > I'm also thinking of > > - an interface to Qt (without adding a dependency) > > - a command line interface, to make tiffany into a new tiff tool, > > - support for other toolkits that need to handle tiff files. > > Ideas about this are most welcome. > > Please let me know if this stuff works for you, and send requests to > or use the links in the bitbucket website: > > https://bitbucket.org/didoca/tiffany > > cheers -- Chris > Howdy. I saw quite a lot of downloads of this package now, but not a single reaction or any feedback. How can I get more than just down-loaders? I would like to know, if - this module is of use for you - if there are wishes to get more functionality - if it makes sense at all - if there are feature requests. I could stop right now, freeze development as the stuff does what is supposed to do in the relevant Python versions, name it 1.0 and forget about it. But I don't want to. Can somebody please give me some feedback? Criticism? Helpful, useless, boring, whatsoever? thanks -- cheers - Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship*http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today?http://www.stackless.com/ From benjamin.kaplan at case.edu Mon Jun 25 17:41:52 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 25 Jun 2012 14:41:52 -0700 Subject: Perl __DATA__ construct. In-Reply-To: References: Message-ID: On Mon, Jun 25, 2012 at 2:20 PM, Mladen Gogala wrote: > I have a script in Perl that I need to rewrite to Python. The script > contains __DATA__ at the end of the script, which enables Perl to access > all the data after that through a file descriptor, like this: > > usage() if ( !$stat or !defined($home) or !defined($base) or !defined > ($sid) ); > while () { > ? ?s/%OB/$base/; > ? ?if ( length($home) > 0 ) { > ? ? ? ?s/%OH/$home/; > ? ?} > ? ?else { > ? ? ? ?s/\/%OH$//; > ? ?} > ? ?if ( length($sid) > 0 && /%OS/ ) { > ? ? ? ?s/%OS/$sid/; > ? ?} > ? ?elsif (/%OS/) { > ? ? ? ?next; > ? ?} > ? ?s/%VR/$ver/; > ? ?print; > } > __DATA__ > # .bashrc > # Source global definitions > if [ -f /etc/bashrc ]; then > ? ? ? ?. /etc/bashrc > fi > set -a > > # User specific aliases and functions > export PATH=/sbin:/bin:/usr/sbin:$PATH > export EDITOR=vi > export ORACLE_BASE=%OB > export ORACLE_HOME=$ORACLE_BASE/product/%VR/%OH > export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/opt/odbc/lib:$ORACLE_HOME/lib32 > export CLASSPATH=/opt/java/lib/tools.jar:$ORACLE_HOME/jdbc/lib/ > ojdbc14.jar:. > > ...... > > > > How do I do the same thing in Python? Alternatively, in Perl I can put an > entire file into a string by using something like: > > $str=< This is all a single string, > no matter how many lines do > I put in it, but I do have to > escape the special character > EOF > ; > > Is there a way to do the same thing in Python? The idea of the script is > to generate $HOME/.bashrc for any automagically provisioned Oracle > installation. > either escape the new-line 'hello \ world' or use triple-quoted strings """hello world""" http://docs.python.org/tutorial/introduction.html#strings From miki.tebeka at gmail.com Mon Jun 25 17:50:03 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 25 Jun 2012 14:50:03 -0700 (PDT) Subject: Perl __DATA__ construct. In-Reply-To: References: Message-ID: <194157d2-d2bf-430a-ad6c-19a05a81a39f@googlegroups.com> > Is there a way to do the same thing in Python? Not without some clever tricks. Either you store data at the beginning of the file or you have another file with the data. If you really need one file and data at the end, you can roll your own. Something like: def data(): with open(__file__) as fo: for line in fo: if line.startswith('# __data__'): return ''.join(line[2:] for line in fo) def main(): print(data()) if __name__ == '__main__': main() # __data__ # blah # blah # blah From cmpython at gmail.com Mon Jun 25 18:15:31 2012 From: cmpython at gmail.com (CM) Date: Mon, 25 Jun 2012 15:15:31 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <4FD4F75D.40602@schwertberger.de> <20120613144931.adbb2c52.feliphil@gmx.net> <20120619150716.263fc70d.feliphil@gmx.net> Message-ID: > It would not be difficult to convince me to commit homicide for > a Delphi-like Python gui machine that runs on a Linux box. I > have played with many - Boa, WxDes, Glade, Tk, Dabo, QtDesigner, > Card, etc. Not sure whether you tried it enough on Linux, but Boa (which was intended to be kind of Delphi for Python) *almost* runs OK on Linux. There are a few workarounds to some of the problems and I have a list of the remaining issues. But yes, it's not ideal to use on Linux yet (I have done sort of OK with developing with it on Windows and then using it on Linux to tidy up cross platform incompatibilities in wxPython apps between Win and Linux). From sonika.sardana at talentburst.com Mon Jun 25 20:34:50 2012 From: sonika.sardana at talentburst.com (Sonika Sardana) Date: Mon, 25 Jun 2012 20:34:50 -0400 Subject: JOB Message-ID: <41B27E7C2DF66246A1DEC2BD9988B38D04C2344C4D@MAILR018.mail.lan> `TalentBurst.com`__ (San Francisco, CA, USA) ======================================================================================= **Job Description**: Short description of position Looking for a strong PHP developer who is comfortable with some Linux administration and open to learning Python and Java too. Senior Software Engineer Mountain View, CA Citizens OR Green Card card holders only Pay rate: Open Contract length: 3 months. Will become a permanent position for the right candidate REQUIRED: Strong skills with PHP and some system administration skills around Linux Looking for a dedicated engineer to join the IT Application Development team to work with the Office of the CIO, who are focused on driving the entire enterprise technology strategy, roadmap and alignment of all future enterprise technology deployments. You will be part of team focused on implementing custom solutions with 3rd party applications and working directly with teams that require microsite development. It is a unique position ideal for those who believe in software as a solution. **Requirements** * Versatile with an assortment of web based languages, Java, PHP, Python, HTML, CSS * Ability to learn and integrate third party applications * Experience with a CMS tool, such as Drupal, Wordpress, or Adobe CQ a plus * Knowledge and understanding of RESTful APIs * Experienced administrating tools ensuring uptime and security * Experienced with relational databases (MySQL) * Experienced with Linux (commands and network setup) * Ability to work in an Agile/Scrum environment * B.S. in Computer Science or related discipline * Excellent communication skills 1. **Contact Info:** 2. 3. * **Contact**: Sonika Sardana 4. * **E-mail contact**: sonika.sardana at talentburst.com 5. * **Other Contact Info**: 954 237 7023 6. * **Web**: http://www.example.com/your/job/page.html 7. * **No telecommuting** -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at brasko.net Mon Jun 25 20:51:09 2012 From: bob at brasko.net (Bob Rossi) Date: Mon, 25 Jun 2012 20:51:09 -0400 Subject: uninitialize PyEval_InitThreads() Message-ID: <20120626005109.GA21146@brasko> Hi, I see that I can initialize python for multi thread support by calling PyEval_InitThreads(). I'm under the impression that when the GIL is turned on, python can slow down a measurable amount. Since I only need to use multiple threads for a portion of my program, after I call PyEval_InitThreads() and use the threads, is there a way to disable multi threading support in python? (I noticed that _PyEval_FiniThreads was undocumented and presumably shouldn't be called) I would only want to do this if it would increase run time performance in the main thread. So if that assumption is wrong, please let me know. Thanks, Bob From steve+comp.lang.python at pearwood.info Mon Jun 25 22:18:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Jun 2012 02:18:16 GMT Subject: tiffany 0.6 released References: <4FE7C301.6010101@stackless.com> Message-ID: <4fe91be7$0$29978$c3e8da3$5496439d@news.astraweb.com> On Mon, 25 Jun 2012 23:36:59 +0200, Christian Tismer wrote: > I saw quite a lot of downloads of this package now, but not a single > reaction or any feedback. Feel fortunate that you are getting any downloads at all :) In my experience, if you are really lucky, perhaps one in a hundred people who download a package will comment about it. > How can I get more than just down-loaders? I would like to know, if > > - this module is of use for you > - if there are wishes to get more functionality - if it makes sense at > all > - if there are feature requests. You can't force people to comment. Do you have a blog where you can report new functionality or bug fixes? That might help drive interest. > I could stop right now, freeze development as the stuff does what is > supposed to do in the relevant Python versions, name it 1.0 and forget > about it. Sure, why not? If the package is feature complete, then why keep making changes to it just for the sake of change? > But I don't want to. > Can somebody please give me some feedback? Criticism? > Helpful, useless, boring, whatsoever? As frustrating as it is, you should expect that unless you have thousands of users, or tens of thousands, you won't get much feedback. If you are writing software for fame and attention, you're in the wrong industry :) BTW, I have no need for your software, but that doesn't mean it isn't a good and valuable piece of work. Thank you for sharing it with the community, even if only a few people find it useful. -- Steven From rantingrickjohnson at gmail.com Mon Jun 25 22:28:01 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Mon, 25 Jun 2012 19:28:01 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: <2b6eb040-711e-4af7-a7a9-dd91a10dd3f6@googlegroups.com> On Monday, June 25, 2012 5:10:47 AM UTC-5, Michiel Overtoom wrote: > It has not. Python2 and Python3 are very similar. It's not like if > you learn Python using version 2, you have to relearn the language > when you want to switch Python3. The syntax is the same, only > 'print' is a function instead of a statement. However, there is something to be said for "old habits die hard". I myself lament every time i must type->(, then blah, then->) AGAIN!. My fingers are hardwired for the old print statement. Damned that Guido and his mind games! http://www.youtube.com/watch?v=-Ny42Mdg5qo From rantingrickjohnson at gmail.com Mon Jun 25 22:28:01 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Mon, 25 Jun 2012 19:28:01 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: <2b6eb040-711e-4af7-a7a9-dd91a10dd3f6@googlegroups.com> On Monday, June 25, 2012 5:10:47 AM UTC-5, Michiel Overtoom wrote: > It has not. Python2 and Python3 are very similar. It's not like if > you learn Python using version 2, you have to relearn the language > when you want to switch Python3. The syntax is the same, only > 'print' is a function instead of a statement. However, there is something to be said for "old habits die hard". I myself lament every time i must type->(, then blah, then->) AGAIN!. My fingers are hardwired for the old print statement. Damned that Guido and his mind games! http://www.youtube.com/watch?v=-Ny42Mdg5qo From skabra at gmail.com Mon Jun 25 23:20:58 2012 From: skabra at gmail.com (Saurabh Kabra) Date: Tue, 26 Jun 2012 13:20:58 +1000 Subject: Faster way to map numpy arrays Message-ID: Thanks guys I implemented a numpy array with fancy indices and got rid of the list and the loops. The time to do the mapping improved ~10x. As a matter of fact, the number of elements in array A to be summed and mapped was different for each element in B (which was the reason I was using lists). But I solved that problem by simply adding zero elements to make a regular 3D numpy array out of the list. Saurabh On 25 June 2012 08:24, Stefan Behnel wrote: > Saurabh Kabra, 25.06.2012 05:37: > > I have written a script to map a 2D numpy array(A) onto another array(B) > of > > different dimension. more than one element (of array A) are summed and > > mapped to each element of array B. To achieve this I create a list > where I > > store the index of array A to be mapped to array B. The list is the > > dimension of array B (if one can technically say that) and each element > is > > a list of indices to be summed. Then I parse this list with a nested loop > > and compute each element of array B. > > > > Because of the nested loop and the big arrays the process takes a minute > or > > so. My question is: is there a more elegant and significantly faster way > of > > doing this in python? > > I'm sure there's a way to do this kind of transformation more efficiently > in NumPy. I faintly recall that you can use one array to index into > another, something like that might do the trick already. In any case, using > a NumPy array also for the mapping matrix sounds like a straight forward > thing to try. > I can't tell from the description of the problem what you're trying to do but for the special case of summing along one axis of a numpy array of dimension N to produce a new numpy array of dimension N-1, there is fast builtin support in numpy: >>> import numpy >>> a = numpy.array([[1, 2], [3, 4]]) >>> a array([[1, 2], [3, 4]]) >>> a.sum() # sum of all elements 10 >>> a.sum(axis=1) # sum of each row array([3, 7]) >>> a.sum(axis=0) # sum of each column array([4, 6]) If your problem is not in this form, you can use numpy's fancy indexing to convert it to this form, provided the number of elements summed from A is the same for each element of B (i.e. if each element of B is the result of summing exactly 10 elements chosen from A). > But you might also want to take a look at Cython. It sounds like a problem > where a trivial Cython implementation would seriously boost the > performance. > > http://docs.cython.org/src/tutorial/numpy.html > > Stefan > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Mon Jun 25 23:35:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Jun 2012 03:35:14 GMT Subject: Why has python3 been created as a seperate language where there is still python2.7 ? References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> (Rick, don't make me regret communicating with you again.) On Mon, 25 Jun 2012 19:28:01 -0700, rantingrickjohnson wrote: > However, there is something to be said for "old habits die hard". I > myself lament every time i must type->(, then blah, then->) AGAIN!. My > fingers are hardwired for the old print statement. Damned that Guido and > his mind games! There's no real difference between typing print(...) and all the other functions in Python. Do you lament having to type len(obj) instead of "len obj" or list(zip(a, b, c)) instead of "list zip a b c"? Making print a statement in the first place was a mistake, but fortunately it was a simple enough mistake to rectify once the need for backward compatibility was relaxed. -- Steven From tjreedy at udel.edu Tue Jun 26 00:33:48 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 26 Jun 2012 00:33:48 -0400 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 6/25/2012 11:35 PM, Steven D'Aprano wrote: > (Rick, don't make me regret communicating with you again.) > > On Mon, 25 Jun 2012 19:28:01 -0700, rantingrickjohnson wrote: > >> However, there is something to be said for "old habits die hard". I >> myself lament every time i must type->(, then blah, then->) AGAIN!. My >> fingers are hardwired for the old print statement. Damned that Guido and >> his mind games! > > There's no real difference between typing print(...) and all the other > functions in Python. Yes there is ... as Rick said, habit. I still sometimes forget ;-( > Do you lament having to type len(obj) instead of > "len obj" or list(zip(a, b, c)) instead of "list zip a b c"? No. > Making print a statement in the first place was a mistake, but > fortunately it was a simple enough mistake to rectify once the need for > backward compatibility was relaxed. Complete agreed. I have used all of sep=, end=, and file= at various times. -- Terry Jan Reedy From jeremiah.dodds at gmail.com Tue Jun 26 01:04:58 2012 From: jeremiah.dodds at gmail.com (Jeremiah Dodds) Date: Tue, 26 Jun 2012 01:04:58 -0400 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <2b6eb040-711e-4af7-a7a9-dd91a10dd3f6@googlegroups.com> (rantingrickjohnson@gmail.com's message of "Mon, 25 Jun 2012 19:28:01 -0700 (PDT)") References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <2b6eb040-711e-4af7-a7a9-dd91a10dd3f6@googlegroups.com> Message-ID: <87ehp2fyth.fsf@friendface.gateway.2wire.net> rantingrickjohnson at gmail.com writes: > On Monday, June 25, 2012 5:10:47 AM UTC-5, Michiel Overtoom wrote: >> It has not. Python2 and Python3 are very similar. It's not like if >> you learn Python using version 2, you have to relearn the language >> when you want to switch Python3. The syntax is the same, only >> 'print' is a function instead of a statement. > > However, there is something to be said for "old habits die hard". I myself > lament every time i must type->(, then blah, then->) AGAIN!. My fingers are > hardwired for the old print statement. Damned that Guido and his mind games! > > http://www.youtube.com/watch?v=-Ny42Mdg5qo I'm of the opinion that the solution to this involves configuring your editor. From jeanpierreda at gmail.com Tue Jun 26 02:15:17 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 26 Jun 2012 02:15:17 -0400 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jun 25, 2012 at 11:35 PM, Steven D'Aprano wrote: > There's no real difference between typing print(...) and all the other > functions in Python. Do you lament having to type len(obj) instead of > "len obj" or list(zip(a, b, c)) instead of "list zip a b c"? Surely you mean "list $ zip a b c"? ;) But yes, it's really not a big deal. It's a trivial change, and one that 2to3 can handle really easily. > > Making print a statement in the first place was a mistake, but > fortunately it was a simple enough mistake to rectify once the need for > backward compatibility was relaxed. Hmmm, why is the function so much better than the statement? You like using it in expressions? Or is it that you like passing it in as a callback? -- Devin From stefan_ml at behnel.de Tue Jun 26 02:24:43 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 26 Jun 2012 08:24:43 +0200 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <87ehp2fyth.fsf@friendface.gateway.2wire.net> References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <2b6eb040-711e-4af7-a7a9-dd91a10dd3f6@googlegroups.com> <87ehp2fyth.fsf@friendface.gateway.2wire.net> Message-ID: Jeremiah Dodds, 26.06.2012 07:04: > rantingrickjohnson at gmail.com writes: > >> On Monday, June 25, 2012 5:10:47 AM UTC-5, Michiel Overtoom wrote: >>> It has not. Python2 and Python3 are very similar. It's not like if >>> you learn Python using version 2, you have to relearn the language >>> when you want to switch Python3. The syntax is the same, only >>> 'print' is a function instead of a statement. >> >> However, there is something to be said for "old habits die hard". I myself >> lament every time i must type->(, then blah, then->) AGAIN!. My fingers are >> hardwired for the old print statement. Damned that Guido and his mind games! >> >> http://www.youtube.com/watch?v=-Ny42Mdg5qo > > I'm of the opinion that the solution to this involves configuring your editor. But wasn't the whole idea behind Python to be accessible for innocent users? Isn't the one and only acceptable goal of a language cleanup that those who do not have the expert knowledge to configure the editor of their choice should finally be able to wholeheartedly type down their Pythonish code without having the parser allude them to the one holy way from time to time? It clearly cannot have achieved that goal, given the amount of traffic on this list, can it? Maybe we should add a remote error reporting mode to Python that sends all syntax error messages not only to the local screen but also directly to the PSF so that they can fund developers who are able to delete that error message from the interpreter based on real world statistical evidence. That would eventually make the language match the powerset of what all users have in their fingers. A very worthy goal, if you ask me. Stefan From stefan_ml at behnel.de Tue Jun 26 02:34:03 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 26 Jun 2012 08:34:03 +0200 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Devin Jeanpierre, 26.06.2012 08:15: > On Mon, Jun 25, 2012 at 11:35 PM, Steven D'Aprano >> Making print a statement in the first place was a mistake, but >> fortunately it was a simple enough mistake to rectify once the need for >> backward compatibility was relaxed. > > Hmmm, why is the function so much better than the statement? You like > using it in expressions? Or is it that you like passing it in as a > callback? First of all, the statement has a rather special syntax that is not obvious and practically non-extensible. It also has hidden semantics that are hard to explain and mixes formatting with output - soft-space, anyone? The function is straight forward, configurable, does one thing, works with help() and doesn't get in the way. And something as rarely[1] used as a print simply doesn't deserve special syntax. Oh, and, yes, you can even pass it into some code as callback, although I rarely had a need for that. Stefan [1] Seriously, it's not very helpful in interactive mode and too simplistic to be used in application code. Even scripts often work better with logging than with prints. From __peter__ at web.de Tue Jun 26 02:57:39 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Jun 2012 08:57:39 +0200 Subject: Getting lazy with decorators References: <9d0c01f4-4430-4a45-8776-20d8dede9e14@googlegroups.com> <513d25ea-e977-4b84-b388-bfb23c171aae@googlegroups.com> Message-ID: Josh English wrote: > On Sunday, June 24, 2012 1:07:45 AM UTC-7, Peter Otten wrote: >> >> You cannot access a class instance because even the class itself doesn't >> exist yet. You could get hold of the class namespace with >> sys._getframe(), >> >> def add_help(f): >> exec """\ >> def help_%s(self): >> f = getattr(self, %r) >> self.show_help(f) >> """ % (f.__name__[3:], f.__name__) in sys._getframe(1).f_locals >> return f >> >> but here's a simpler approach: >> >> import cmd >> >> def add_help(f): >> def help(self): >> self.show_help(f) >> f.help = help >> return f >> >> >> class BaseCmd(cmd.Cmd): >> def __init__(self, *args, **kwargs): >> cmd.Cmd.__init__(self, *args, **kwargs) >> >> def show_help(self, func): >> print "\n".join((line.strip() for line in >> func.__doc__.splitlines())) >> >> def __getattr__(self, name): >> if name.startswith("help_"): >> helpfunc = getattr(self, "do_" + name[5:]).help >> setattr(self.__class__, name, helpfunc) >> return getattr(self, name) >> raise AttributeError >> >> @add_help >> def do_done(self, line): >> """done >> Quits this and goes to higher level or quits the application. >> I mean, what else do you expect? >> """ >> return True >> >> if __name__=='__main__': >> c = BaseCmd() >> c.cmdloop() > > > Okay. If I understand this, you are adding a help attribute to the class > method. The help attribute is itself a function. > > There is nothing in the documentation (that I have found) that points to > this solution. That's because I "invented" it. @deco def func(...): ... is equivalent to def func(...): ... func = deco(func) so only one assignment is ever made in the enclosing namespace. If you have more targets you have to put them somewhere else. Making the help_xxx() function an attribute of do_xxx() seemed the obvious choice. > Even after reading the do_help method in the cmd.Cmd > source, I don't see this as working. do_help(name) looks up a "help_" + name method and invokes it if that lookup succeeds. > Yet it works. In the example above do_help() looks for a help_done attribute which doesn't exist. As a fallback the __getattr__() method is invoked with the "help_done" argument, finds that the name starts with "help_" and proceeds with >> helpfunc = getattr(self, "do_" + name[5:]).help i. e. it looks for getattr(self, "do_help") which does exist and then stores its help attribute (if that doesn't exist an AttributeError is implicitly raised) in helpfunc. helpfunc is then added as "help_done" to the class >> setattr(self.__class__, name, helpfunc) and looked up again in the instance: >> return getattr(self, name) This time it exists and from the class attribute help_done an instance method is created, returned from __getattr__() and invoked by do_help(). PS: Stefan is probably right that you should just override do_help() From __peter__ at web.de Tue Jun 26 03:03:45 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Jun 2012 09:03:45 +0200 Subject: Getting lazy with decorators References: <9d0c01f4-4430-4a45-8776-20d8dede9e14@googlegroups.com> <513d25ea-e977-4b84-b388-bfb23c171aae@googlegroups.com> Message-ID: Peter Otten wrote: >>>helpfunc = getattr(self, "do_" + name[5:]).help > > i. e. it looks for getattr(self, "do_help") which does exist and then Sorry that should be getattr(self, "do_done"). From steve+comp.lang.python at pearwood.info Tue Jun 26 03:40:40 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Jun 2012 07:40:40 GMT Subject: Why has python3 been created as a seperate language where there is still python2.7 ? References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4fe96777$0$29978$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Jun 2012 02:15:17 -0400, Devin Jeanpierre wrote: >> Making print a statement in the first place was a mistake, but >> fortunately it was a simple enough mistake to rectify once the need for >> backward compatibility was relaxed. > > Hmmm, why is the function so much better than the statement? You like > using it in expressions? Or is it that you like passing it in as a > callback? Simplicity: there doesn't seem to be anything special about print that requires it to be syntax instead of just a built-in function. Nearly everything else which is handled by syntax is special: assignment, deletion, imports, flow control. (Decorators are the obvious exception, but they are pure syntactic sugar.) Consistency: print as a function isn't a special case to be learned. There's no need to memorise magic syntax to control it, you just pass ordinary arguments using ordinary syntax. Instead of arcane and bizarre special cases like this: print >>sys.stderr, spam, ham, eggs, you just use: print(spam, ham, eggs, file=sys.stderr, end='') While it's a tad longer, there's no special syntax to be learned. Practicality: as a function, you can use print anywhere you can use other functions. You can bind it to another name, pass it as argument to another function such as help(), store it in a list, use it as a callback, or monkey-patch it, without needing to write a wrapper "print_" (or "prnt", "pr", etc.) around it. Compare that to print as a statement, which only has one argument in favour: backwards compatibility. -- Steven From k.sahithi2862 at gmail.com Tue Jun 26 04:54:23 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Tue, 26 Jun 2012 01:54:23 -0700 (PDT) Subject: ACTRESS UNSEENED LATEST HOT PICS Message-ID: <90635e11-8a69-4ac7-9353-c384a5b4515d@g4g2000pbn.googlegroups.com> ALL INTERVIEW QUESTIONS& STUDY MATERIAL http://newdotnetinterviewquestions.blogspot.in/ TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR LATEST MOVIE UPDATED LINKS ACTRESS YAMI GOUTHAM LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/06/yami-gautam-actress.html ACTRESS HOT STILLS IN SIIMA AWARDS 2012 http://actressgallery-kalyani.blogspot.in/2012/06/actress-siima-awards-2012-stills.html EM BABU LADDU KAVALA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/06/em-babu-laddu-kavala-movie-stills.html SRMANARAYANA MOVIE HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/06/srimannarayana-movie-stills.html KAJAL AGARWAL LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/06/kajal-agarwal-latest-stills.html SANA KHAN LATEST HOT PHOTO GALLERY http://actressgallery-kalyani.blogspot.in/2012/06/sana-khan-latest-stills.html COOL BOYS HOT GIRLS MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/06/cool-boys-hot-girls-movie-stills.html MITAAYI MOVIE LATEST GALLERY http://actressgallery-kalyani.blogspot.in/2012/06/mitaayi-movie-stills.html NAGARJUNA DAMARUKAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/damarukam-movie-stills.html ALLU ARJUN JULAYI MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/julayi-movie-stills.html SUDIGADU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/sudigadu-movie-stills.html MR 7 MOVIE FILM GALLERY http://actressgallery-kalyani.blogspot.in/2012/05/mr7-movie-stills.html ALL THE BEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/all-best-movie-stills.html Midatha Telugu movie Hot Namitha Stills http://actressgallery-kalyani.blogspot.com/2012/05/midatha-movie-stills.html OKA COLLEGE LOVE STORY MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/oka-college-love-story-movie-stills.html KATRINA KAIF LATEST UNSEENED PHOTOS http://actressgallery-kalyani.blogspot.com/2012/05/katrina-kaif-latest-pics.html TAMIL ACTRESS ARUNDHATI HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/05/arundhati-tamil-actress.html THANDHAVAM MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/05/thandavam-movie-stills.html KHO KHO LATEST MOVIE SPICY STILLS http://actressgallery-kalyani.blogspot.com/2012/05/kho-kho-movie-stills.html Oh My Love Movie Latest Photo Gallery http://actressgallery-kalyani.blogspot.com/2012/04/oh-my-love-movie-stills.html Oka Romantic Crime katha Movie stills http://actressgallery-kalyani.blogspot.in/2012/04/oka-romantic-crime-katha-movie-stills.html DARUVU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/03/daruvu-movie-stills.html Pavan Kalyan,Shruthi Hasan Gabbar Singh Movie Photos http://actressgallery-kalyani.blogspot.in/2012/04/gabbar-singh-movie-stills.html Good Morning Latest Movie Stills http://actressgallery-kalyani.blogspot.com/2012/04/good-morning-movie-stills.html EEGA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/04/eega-movie-stills.html Mem Vayasuku Vacham Latest Hot Stills http://actressgallery-kalyani.blogspot.com/2012/04/mem-vayasuku-vacham-stills.html DAMMU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/04/dammu-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html HOT LINKS FOR YOUTH ONLY PRANEETHA HOT SPICY IMAGES http://actressimages-9.blogspot.in/2012/06/praneetha-latest-stills.html SHRUTHI HASSAN HALF SAREE STILLS http://actressimages-9.blogspot.in/2012/05/shruti-hassan-half-saree-stills.html TAMANNA HOT NAVEL PHOTOS http://actressimages-9.blogspot.in/2012/05/tamanna-navel-photos.html TRISHA LATEST HOT STILLS http://actressgallery9.blogspot.in/2012/05/trisha.html MONIKA LATEST HOT HD STLLS http://actressgallery9.blogspot.in/2012/05/monika-stills.html MALLIKA KAPOOR HOT SIZZLING STILLS http://actressimages-9.blogspot.in/2012/05/mallika-kapoor.html Richa Panai Stills http://actressimages-9.blogspot.com/2012/04/richa-panai-stills.html MADHAVI LATHA LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/04/madhavi-latha-stills.html KRITI KHARBANDA HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/kriti-kharbanda.html NEELAM UPADHYAY HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/neelam-upadhyay.html SAMANTHA LATEST HOT ROMANTIC STILLS http://actressimages-9.blogspot.in/2012/03/samantha-latest-stills.html NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html From jeanmichel at sequans.com Tue Jun 26 05:10:47 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 26 Jun 2012 11:10:47 +0200 Subject: tiffany 0.6 released In-Reply-To: <4FE8D9FB.8010101@stackless.com> References: <4FE7C301.6010101@stackless.com> <4FE8D9FB.8010101@stackless.com> Message-ID: <4FE97C97.2060401@sequans.com> Christian Tismer wrote: > Abour tiffany... > > On 6/25/12 3:46 AM, Christian Tismer wrote: >> Tiffany - Read/Write Multipage-Tiff with PIL without PIL >> ======================================================== >> >> Tiffany stands for any tiff. The tiny module solves a large set of >> problems, has no dependencies and just works wherever Python works. >> Tiffany was developed in the course of the *DiDoCa* project and will >> always appear on PyPi. >> >> Version 0.6 >> ----------- >> >> This is a compatibility update for Python 3.2. >> >> Tiffany now works on Python 2.6, 2.7 and 3.2. >> >> This version also reduces the needed PIL files to only four. The >> same files work for python2 and python3. >> >> You can help me by sending some tiff files with different encoding >> and larger file size for testing. >> >> I'm also thinking of >> >> - an interface to Qt (without adding a dependency) >> >> - a command line interface, to make tiffany into a new tiff tool, >> >> - support for other toolkits that need to handle tiff files. >> >> Ideas about this are most welcome. >> >> Please let me know if this stuff works for you, and send requests to >> or use the links in the bitbucket website: >> >> https://bitbucket.org/didoca/tiffany >> >> cheers -- Chris >> > > Howdy. > > I saw quite a lot of downloads of this package now, but not > a single reaction or any feedback. > > How can I get more than just down-loaders? > I would like to know, if > > - this module is of use for you > - if there are wishes to get more functionality > - if it makes sense at all > - if there are feature requests. > > I could stop right now, freeze development as the stuff does what is > supposed to do in the relevant Python versions, name it 1.0 and forget > about it. > > But I don't want to. > Can somebody please give me some feedback? > Criticism? > Helpful, useless, boring, whatsoever? > > thanks -- cheers - Chris > Well, multi page tiff looks like a niche to me. Anyway, the word play tiff-any is clever, that's all I can say :D JM From oscar.benjamin at bristol.ac.uk Tue Jun 26 09:51:38 2012 From: oscar.benjamin at bristol.ac.uk (Oscar Benjamin) Date: Tue, 26 Jun 2012 14:51:38 +0100 Subject: Faster way to map numpy arrays In-Reply-To: References: Message-ID: On 26 June 2012 04:20, Saurabh Kabra wrote: > Thanks guys > > I implemented a numpy array with fancy indices and got rid of the list and > the loops. The time to do the mapping improved ~10x. As a matter of fact, > the number of elements in array A to be summed and mapped was different for > each element in B (which was the reason I was using lists). But I solved > that problem by simply adding zero elements to make a regular 3D numpy > array out of the list. > Is that good enough, or are you looking for more speedup? Padding with zeros to create the larger-than-needed array may be less time-efficient (and is definitely less memory efficient) than extracting each subarray in a loop. Consider the following: >>> import numpy >>> a = numpy.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> a array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> af = a.flatten() >>> af array([1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> indices = [[1, 7, 8], [0, 1], [8, 4]] >>> indices = [numpy.array(inds) for inds in indices] >>> indices [array([1, 7, 8]), array([0, 1]), array([8, 4])] >>> for inds in indices: ... print inds, af[inds], af[inds].sum() ... [1 7 8] [2 8 9] 19 [0 1] [1 2] 3 [8 4] [9 5] 14 Knowing the most efficient way depends on a number of things. The first would be whether or not the operation you're describing is repeated. If, for example, you keep doing this for the same indices but each time changing the array A then you should try precomputing all the indices as a list of numpy arrays (as shown above). On the other hand, if you're repeating with the same matrix A but different sets of indices, you'll need to think about how you are generating the indices. In my experience the fastest way to do something like this would be to use cython as suggested above by Stefan. Oscar. > > Saurabh > > > > > > On 25 June 2012 08:24, Stefan Behnel > wrote: > > Saurabh Kabra, 25.06.2012 05:37: >> > I have written a script to map a 2D numpy array(A) onto another >> array(B) of >> > different dimension. more than one element (of array A) are summed and >> > mapped to each element of array B. To achieve this I create a list >> where I >> > store the index of array A to be mapped to array B. The list is the >> > dimension of array B (if one can technically say that) and each element >> is >> > a list of indices to be summed. Then I parse this list with a nested >> loop >> > and compute each element of array B. >> > > >> > Because of the nested loop and the big arrays the process takes a >> minute or >> > so. My question is: is there a more elegant and significantly faster >> way of >> > doing this in python? >> >> I'm sure there's a way to do this kind of transformation more efficiently >> in NumPy. I faintly recall that you can use one array to index into >> another, something like that might do the trick already. In any case, >> using >> a NumPy array also for the mapping matrix sounds like a straight forward >> thing to try. >> > > I can't tell from the description of the problem what you're trying to do > but for the special case of summing along one axis of a numpy array of > dimension N to produce a new numpy array of dimension N-1, there is fast > builtin support in numpy: > > >>> import numpy > >>> a = numpy.array([[1, 2], [3, 4]]) > >>> a > array([[1, 2], > [3, 4]]) > >>> a.sum() # sum of all elements > 10 > >>> a.sum(axis=1) # sum of each row > array([3, 7]) > >>> a.sum(axis=0) # sum of each column > array([4, 6]) > > If your problem is not in this form, you can use numpy's fancy indexing to > convert it to this form, provided the number of elements summed from A is > the same for each element of B (i.e. if each element of B is the result of > summing exactly 10 elements chosen from A). > > >> But you might also want to take a look at Cython. It sounds like a problem >> where a trivial Cython implementation would seriously boost the >> performance. >> >> http://docs.cython.org/src/tutorial/numpy.html > > >> >> Stefan >> > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From excel at pharcyde.org Tue Jun 26 11:20:01 2012 From: excel at pharcyde.org (Andrew D'Angelo) Date: Tue, 26 Jun 2012 10:20:01 -0500 Subject: vBulletin scraper -- feasible? References: Message-ID: Thanks, this seems to be just what I need. From chris at python.org Tue Jun 26 11:59:54 2012 From: chris at python.org (Chris Withers) Date: Tue, 26 Jun 2012 16:59:54 +0100 Subject: JOB In-Reply-To: <41B27E7C2DF66246A1DEC2BD9988B38D04C2344C4D@MAILR018.mail.lan> References: <41B27E7C2DF66246A1DEC2BD9988B38D04C2344C4D@MAILR018.mail.lan> Message-ID: <4FE9DC7A.4000001@python.org> Sonika, On 26/06/2012 01:34, Sonika Sardana wrote: > ` > > ======================================================================================= > > **Job Description**: > > Short description of position Looking for a strong PHP developer who is > comfortable with some Linux administration and open to learning Python > and Java too. Please do not spam the lists, especially with jobs that aren't even python focused... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From dreadpiratejeff at gmail.com Tue Jun 26 12:30:15 2012 From: dreadpiratejeff at gmail.com (J) Date: Tue, 26 Jun 2012 12:30:15 -0400 Subject: Frustrating circular bytes issue Message-ID: This is driving me batty... more enjoyment with the Python3 "Everything must be bytes" thing... sigh... I have a file that contains a class used by other scripts. The class is fed either a file, or a stream of output from another command, then interprets that output and returns a set that the main program can use... confusing, perhaps, but not necessarily important. The class is created and then called with the load_filename method: def load_filename(self, filename): logging.info("Loading elements from filename: %s", filename) file = open(filename, "rb", encoding="utf-8") return self.load_file(file, filename) As you can see, this calls the load_file method, by passing the filehandle and filename (in common use, filename is actually an IOStream object). load_file starts out like this: def load_file(self, file, filename=""): elements = [] for string in self._reader(file): if not string: break element = {} Note that it now calls the private _reader() passing along the filehandle further in. THIS is where I'm failing: This is the private _reader function: def _reader(self, file, size=4096, delimiter=r"\n{2,}"): buffer_old = "" while True: buffer_new = file.read() print(type(buffer_new)) if not buffer_new: break lines = re.split(delimiter, buffer_old + buffer_new) buffer_old = lines.pop(-1) for line in lines: yield line yield buffer_old (the print statement is something I put in to verify the problem. So stepping through this, when _reader executes, it executes read() on the opened filehandle. Originally, it read in 4096 byte chunks, I removed that to test a theory. It creates buffer_new with the output of the read. Running type() on buffer_new tells me that it's a bytes object. However no matter what I do: file.read().decode() buffer_new.decode() in the lines = re.split() statement buffer_str = buffer_new.decode() I always get a traceback telling me that the str object has no decoe() method. If I remove the decode attempts, I get a traceback telling me that it can't implicitly convert a bytes_object to a str object. So I'm stuck in a vicious circle and can't see a way out. here's sample error messages: When using the decode() method to attempt to convert the bytes object: Traceback (most recent call last): File "./filter_templates", line 134, in sys.exit(main(sys.argv[1:])) File "./filter_templates", line 126, in main options.whitelist, options.blacklist) File "./filter_templates", line 77, in parse_file matches = match_elements(template.load_file(file), *args, **kwargs) File "/usr/lib/python3/dist-packages/checkbox/lib/template.py", line 73, in load_file for string in self._reader(file): File "/usr/lib/python3/dist-packages/checkbox/lib/template.py", line 35, in _reader lines = re.split(delimiter, buffer_old + buffer_new.decode()) AttributeError: 'str' object has no attribute 'decode' It's telling me that buffer_new is a str object. so if I remove the decode(): Traceback (most recent call last): File "./run_templates", line 142, in sys.exit(main(sys.argv[1:])) File "./run_templates", line 137, in main runner.process(args, options.shell) File "./run_templates", line 39, in process records = self.process_output(process.stdout) File "./run_templates", line 88, in process_output return template.load_file(output) File "/usr/lib/python3/dist-packages/checkbox/lib/template.py", line 73, in load_file for string in self._reader(file): File "/usr/lib/python3/dist-packages/checkbox/lib/template.py", line 35, in _reader lines = re.split(delimiter, buffer_old + buffer_new) TypeError: Can't convert 'bytes' object to str implicitly now it's complaining that buffer_new is a bytes object and can't be implicitly converted to str. This is a bug introduced in our conversion from Python 2 to Python 3. I am really, really starting to dislike some of the things Python3 does... or just am really, really frustrated. From robert.kern at gmail.com Tue Jun 26 12:53:24 2012 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 26 Jun 2012 17:53:24 +0100 Subject: Frustrating circular bytes issue In-Reply-To: References: Message-ID: On 6/26/12 5:30 PM, J wrote: > This is driving me batty... more enjoyment with the Python3 > "Everything must be bytes" thing... sigh... > I have a file that contains a class used by other scripts. The class > is fed either a file, or a stream of output from another command, then > interprets that output and returns a set that the main program can > use... confusing, perhaps, but not necessarily important. > > The class is created and then called with the load_filename method: > > > def load_filename(self, filename): > logging.info("Loading elements from filename: %s", filename) > > file = open(filename, "rb", encoding="utf-8") > return self.load_file(file, filename) I get this with Python 3.2: Traceback (most recent call last): File "bytes_unicode.py", line 32, in d.load_filename(__file__) File "bytes_unicode.py", line 6, in load_filename file = open(filename, "rb", encoding="utf-8") ValueError: binary mode doesn't take an encoding argument Are you sure you are copy-pasting the code that is actually running? Can you reduce your test case down to a small self-contained example that runs and demonstrates the problem? I suspect that there is some other detail that is causing things to fail. The following code works fine for me: #!/usr/bin/env python # -*- coding: UTF-8 -*- import re class Dummy(object): """ This is a dummy file. ???????? ??????? """ def load_filename(self, filename): file = open(filename, "r", encoding="utf-8") return self.load_file(file, filename) def load_file(self, file, filename=""): for string in self._reader(file): print(string) if not string: break def _reader(self, file, size=4096, delimiter=r"\n{2,}"): buffer_old = "" while True: buffer_new = file.read() print(type(buffer_new)) if not buffer_new: break lines = re.split(delimiter, buffer_old + buffer_new) buffer_old = lines.pop(-1) for line in lines: yield line yield buffer_old if __name__ == '__main__': d = Dummy() d.load_filename(__file__) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From dthomas86 at me.com Tue Jun 26 13:19:45 2012 From: dthomas86 at me.com (David Thomas) Date: Tue, 26 Jun 2012 10:19:45 -0700 (PDT) Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> Message-ID: <347d6190-1bfc-4117-85ff-4abaa0966710@googlegroups.com> I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. Thanks http://www.freeimagehosting.net/ilbqt http://www.freeimagehosting.net/r5ars On Monday, June 25, 2012 8:49:07 PM UTC+1, Benjamin Kaplan wrote: > On Mon, Jun 25, 2012 at 11:19 AM, David Thomas wrote: > > Hello, > > This is my first post so go easy on me. ?I am just beginning to program using Python on Mac. ?When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same piece of code and run it in windows it seems to execute as exactly intended. > > ?How can I make my python script to open up correctly using Python Launcher? ?I am running 10.7 on my Mac. ?I would upload a photo with the error I get but I can't seem to find the upload feature in this group. > > > > Thanks > > -- > > You can't find the upload feature because this isn't a Google Group. > It's a Usenet newsgroup that Google Groups provides access to that's > also available as a mailing list. If you want to provide an image, use > an image host and link to the image. > > As to your question, I have a few questions of my own. What version of > Python are you using? Is it the version included in Mac OS X, > installed from a python.org binary, compiled by source, or installed > through a package manager? What happens if you call the script from > the command line instead of using the Launcher application? From dthomas86 at me.com Tue Jun 26 13:19:45 2012 From: dthomas86 at me.com (David Thomas) Date: Tue, 26 Jun 2012 10:19:45 -0700 (PDT) Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> Message-ID: <347d6190-1bfc-4117-85ff-4abaa0966710@googlegroups.com> I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. Thanks http://www.freeimagehosting.net/ilbqt http://www.freeimagehosting.net/r5ars On Monday, June 25, 2012 8:49:07 PM UTC+1, Benjamin Kaplan wrote: > On Mon, Jun 25, 2012 at 11:19 AM, David Thomas wrote: > > Hello, > > This is my first post so go easy on me. ?I am just beginning to program using Python on Mac. ?When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same piece of code and run it in windows it seems to execute as exactly intended. > > ?How can I make my python script to open up correctly using Python Launcher? ?I am running 10.7 on my Mac. ?I would upload a photo with the error I get but I can't seem to find the upload feature in this group. > > > > Thanks > > -- > > You can't find the upload feature because this isn't a Google Group. > It's a Usenet newsgroup that Google Groups provides access to that's > also available as a mailing list. If you want to provide an image, use > an image host and link to the image. > > As to your question, I have a few questions of my own. What version of > Python are you using? Is it the version included in Mac OS X, > installed from a python.org binary, compiled by source, or installed > through a package manager? What happens if you call the script from > the command line instead of using the Launcher application? From stefan_ml at behnel.de Tue Jun 26 13:22:24 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 26 Jun 2012 19:22:24 +0200 Subject: Frustrating circular bytes issue In-Reply-To: References: Message-ID: J, 26.06.2012 18:30: > def _reader(self, file, size=4096, delimiter=r"\n{2,}"): > buffer_old = "" > while True: > buffer_new = file.read() > print(type(buffer_new)) > if not buffer_new: > break > lines = re.split(delimiter, buffer_old + buffer_new) "delimiter" is a Unicode string, which makes the regular expression a Unicode regex that can't work on a byte string. > buffer_old = lines.pop(-1) > > for line in lines: > yield line > > yield buffer_old > > > (the print statement is something I put in to verify the problem. > > So stepping through this, when _reader executes, it executes read() on > the opened filehandle. Originally, it read in 4096 byte chunks, I > removed that to test a theory. It creates buffer_new with the output > of the read. > > Running type() on buffer_new tells me that it's a bytes object. Stefan From hansmu at xs4all.nl Tue Jun 26 13:33:46 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 26 Jun 2012 19:33:46 +0200 Subject: Frustrating circular bytes issue In-Reply-To: References: Message-ID: <4fe9f27b$0$6990$e4fe514c@news2.news.xs4all.nl> On 26/06/12 18:30:15, J wrote: > This is driving me batty... more enjoyment with the Python3 > "Everything must be bytes" thing... sigh... > I have a file that contains a class used by other scripts. The class > is fed either a file, or a stream of output from another command, then > interprets that output and returns a set that the main program can > use... confusing, perhaps, but not necessarily important. It would help if you could post an extract that we can actually run, to see for ourselves what happens. > The class is created and then called with the load_filename method: > > > def load_filename(self, filename): > logging.info("Loading elements from filename: %s", filename) > > file = open(filename, "rb", encoding="utf-8") When I try this in Python3, I get an error message: ValueError: binary mode doesn't take an encoding argument You'll have to decide for yourself whether you want to read strings or bytes. If you want strings, you'll have to open the file in text mode: file = open(filename, "rt", encoding="utf-8") Alternatively, if you want bytes, you must leave off the encoding: file = open(filename, "rb") > return self.load_file(file, filename) > > As you can see, this calls the load_file method, by passing the > filehandle and filename (in common use, filename is actually an > IOStream object). > > load_file starts out like this: > > > def load_file(self, file, filename=""): > elements = [] > for string in self._reader(file): > if not string: > break > > element = {} > > > Note that it now calls the private _reader() passing along the > filehandle further in. THIS is where I'm failing: > > This is the private _reader function: > > > def _reader(self, file, size=4096, delimiter=r"\n{2,}"): > buffer_old = "" > while True: > buffer_new = file.read() > print(type(buffer_new)) > if not buffer_new: > break > lines = re.split(delimiter, buffer_old + buffer_new) > buffer_old = lines.pop(-1) > > for line in lines: > yield line > > yield buffer_old > > > (the print statement is something I put in to verify the problem. > > So stepping through this, when _reader executes, it executes read() on > the opened filehandle. Originally, it read in 4096 byte chunks, I > removed that to test a theory. It creates buffer_new with the output > of the read. > > Running type() on buffer_new tells me that it's a bytes object. > > However no matter what I do: > > file.read().decode() > buffer_new.decode() in the lines = re.split() statement > buffer_str = buffer_new.decode() > > I always get a traceback telling me that the str object has no decoe() method. > > If I remove the decode attempts, I get a traceback telling me that it > can't implicitly convert a bytes_object to a str object. > > So I'm stuck in a vicious circle and can't see a way out. > > here's sample error messages: > When using the decode() method to attempt to convert the bytes object: > Traceback (most recent call last): > File "./filter_templates", line 134, in > sys.exit(main(sys.argv[1:])) > File "./filter_templates", line 126, in main > options.whitelist, options.blacklist) > File "./filter_templates", line 77, in parse_file > matches = match_elements(template.load_file(file), *args, **kwargs) > File "/usr/lib/python3/dist-packages/checkbox/lib/template.py", line > 73, in load_file > for string in self._reader(file): > File "/usr/lib/python3/dist-packages/checkbox/lib/template.py", line > 35, in _reader > lines = re.split(delimiter, buffer_old + buffer_new.decode()) > AttributeError: 'str' object has no attribute 'decode' Look carefulle at the traceback: this line looks deceptively like a line in your code, except the file name is different. Your file is called "./filter_template" and this line is from a file named "/usr/lib/python3/dist-packages/checkbox/lib/template.py". At line 77 in your code, your calling the "load_file" method on an instance of a class defined in that file. Your description sounds as if you meant to call the "load_file" method on an instance of your own class. In other words, it sounds like you're instantiating the wrong class. I can't say for certain, because you've left out that bit of your code. > It's telling me that buffer_new is a str object. > > so if I remove the decode(): > > Traceback (most recent call last): > File "./run_templates", line 142, in > sys.exit(main(sys.argv[1:])) > File "./run_templates", line 137, in main > runner.process(args, options.shell) > File "./run_templates", line 39, in process > records = self.process_output(process.stdout) > File "./run_templates", line 88, in process_output > return template.load_file(output) > File "/usr/lib/python3/dist-packages/checkbox/lib/template.py", line > 73, in load_file > for string in self._reader(file): > File "/usr/lib/python3/dist-packages/checkbox/lib/template.py", line > 35, in _reader > lines = re.split(delimiter, buffer_old + buffer_new) > TypeError: Can't convert 'bytes' object to str implicitly > > now it's complaining that buffer_new is a bytes object and can't be > implicitly converted to str. > > This is a bug introduced in our conversion from Python 2 to Python 3. > I am really, really starting to dislike some of the things Python3 > does... or just am really, really frustrated. Try creating a script that we can all run that shows the problem. Then shorten it by cutting out bits that shouldn't matter for your problem. After each cut, run the script, to make sure you still have to problem. If the problem goes away, you've cut out the line with the bug. Put that line back in, and try to figure out what's wrong with it. You might be able to solve your own problem without even posting the script to this forum. Hope this helps, -- HansM From d at davea.name Tue Jun 26 13:37:42 2012 From: d at davea.name (Dave Angel) Date: Tue, 26 Jun 2012 13:37:42 -0400 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: <347d6190-1bfc-4117-85ff-4abaa0966710@googlegroups.com> References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <347d6190-1bfc-4117-85ff-4abaa0966710@googlegroups.com> Message-ID: <4FE9F366.8000305@davea.name> On 06/26/2012 01:19 PM, David Thomas wrote: > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > Thanks Assuming python is on your PATH within that terminal, you'd normally do something like: cd /fullpathtoscript (the location of your script) python myscript.py (or whatever your script is called) If that doesn't work for you, please be specific about what happens. Best way to do that is to copy/paste the text (showing in terminal) into your reply here. Also, please don't top-post. Put your new text AFTER the part you've quoted from earlier messages. -- DaveA From dthomas86 at me.com Tue Jun 26 14:09:54 2012 From: dthomas86 at me.com (David Thomas) Date: Tue, 26 Jun 2012 11:09:54 -0700 (PDT) Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <347d6190-1bfc-4117-85ff-4abaa0966710@googlegroups.com> Message-ID: <5d9bb673-0e93-4fcc-a21b-e56f2aa2bb0f@googlegroups.com> On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA Hi On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA From dthomas86 at me.com Tue Jun 26 14:09:54 2012 From: dthomas86 at me.com (David Thomas) Date: Tue, 26 Jun 2012 11:09:54 -0700 (PDT) Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <347d6190-1bfc-4117-85ff-4abaa0966710@googlegroups.com> Message-ID: <5d9bb673-0e93-4fcc-a21b-e56f2aa2bb0f@googlegroups.com> On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA Hi On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: > On 06/26/2012 01:19 PM, David Thomas wrote: > > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > > How can I execute the script from Terminal? I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > > > Thanks > > Assuming python is on your PATH within that terminal, you'd normally do > something like: > > cd /fullpathtoscript (the location of your script) > python myscript.py (or whatever your script is called) > > > If that doesn't work for you, please be specific about what happens. > Best way to do that is to copy/paste the text (showing in terminal) > into your reply here. > > Also, please don't top-post. Put your new text AFTER the part you've > quoted from earlier messages. > > -- > > DaveA From dthomas86 at me.com Tue Jun 26 14:11:51 2012 From: dthomas86 at me.com (David Thomas) Date: Tue, 26 Jun 2012 11:11:51 -0700 (PDT) Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> Message-ID: On Monday, June 25, 2012 7:19:54 PM UTC+1, David Thomas wrote: > Hello, > This is my first post so go easy on me. I am just beginning to program using Python on Mac. When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same piece of code and run it in windows it seems to execute as exactly intended. > How can I make my python script to open up correctly using Python Launcher? I am running 10.7 on my Mac. I would upload a photo with the error I get but I can't seem to find the upload feature in this group. > > Thanks Thank you for the fast response. How can I tell if Python is in the same path as Terminal? Is this located in the /usr folder? Thanks again From d at davea.name Tue Jun 26 14:32:53 2012 From: d at davea.name (Dave Angel) Date: Tue, 26 Jun 2012 14:32:53 -0400 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <347d6190-1bfc-4117-85ff-4abaa0966710@googlegroups.com> Message-ID: <4FEA0055.1040301@davea.name> (You forgot to include the list on this message, but I'm including them in my reply) On 06/26/2012 02:07 PM, David Thomas wrote: > > > On Tuesday, June 26, 2012 6:37:42 PM UTC+1, Dave Angel wrote: >> >> On 06/26/2012 01:19 PM, David Thomas wrote: >>> I have installed Python 2.7.3 from Python.org also in Terminal it states >> that I have 2.7.3. >>> How can I execute the script from Terminal? I've tried typing python >> into the window and then dragging the file to terminal but I get a syntax >> error. Sorry I am new to Python and just want to know how I can open such >> a file using 10.7. >>> >>> >> >> > Thanks for the fast response how can I find out if Python is on the same > path as Terminal? > > Is this located in the /usr Folder? > > Thanks > Looks like you're new to Unix as well. (the following applies to Unix, Linux, OS/X, and with modifications, to Windows) Terminal is a program. PATH is an environment variable. You normally set it globally, but it's sometimes modified by various scripts. To see what it is in a given Terminal session, simply issue the command: echo $PATH To see all your environment variables, use printenv Anyway, PATH is a list of directories that bash (or whatever shell you're using) will search. If you can run python with the simple command: python then it IS on your PATH. That means that you do NOT want to cd to the directory of python, but to the directory where your script is located. cd /fullpathtoscript (the location of your script) python myscript.py (or whatever your script is called) -- DaveA From benjamin.kaplan at case.edu Tue Jun 26 14:56:34 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 26 Jun 2012 11:56:34 -0700 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: <347d6190-1bfc-4117-85ff-4abaa0966710@googlegroups.com> References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <347d6190-1bfc-4117-85ff-4abaa0966710@googlegroups.com> Message-ID: On Tue, Jun 26, 2012 at 10:19 AM, David Thomas wrote: > I have installed Python 2.7.3 from Python.org also in Terminal it states that I have 2.7.3. > How can I execute the script from Terminal? ?I've tried typing python into the window and then dragging the file to terminal but I get a syntax error. ?Sorry I am new to Python and just want to know how I can open such a file using 10.7. > > Thanks > > http://www.freeimagehosting.net/ilbqt > http://www.freeimagehosting.net/r5ars My guess would be that you're getting a SyntaxError when you run it through the Launcher too. WIthout seeing the script, I don't know why that would is. I can tell you one thing you're doing wrong. Never, ever, use input() in Python 2. If you do, all someone has to do is type in __import__('os').remove(__file__) and stuff starts getting deleted. "input" interprets what it reads in. Use raw_input() instead, which always returns a string. From hansmu at xs4all.nl Tue Jun 26 15:16:11 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 26 Jun 2012 21:16:11 +0200 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> Message-ID: <4fea0a7b$0$6942$e4fe514c@news2.news.xs4all.nl> On 26/06/12 20:11:51, David Thomas wrote: > On Monday, June 25, 2012 7:19:54 PM UTC+1, David Thomas wrote: >> Hello, >> This is my first post so go easy on me. I am just beginning to program using Python on Mac. When I try to execute a file using Python Launcher my code seems to cause an error in terminal, when I execute the exact same piece of code and run it in windows it seems to execute as exactly intended. >> How can I make my python script to open up correctly using Python Launcher? I am running 10.7 on my Mac. I would upload a photo with the error I get but I can't seem to find the upload feature in this group. >> >> Thanks > > Thank you for the fast response. How can I tell if Python is in the same path as Terminal? It isn't. Terminal is an application and is located in /Applications/Utilities . Python is an executable, and is typically located in a "bin" directory. To find out where it is, type type python at the shell prompt (that's the first prompt you get if you open a Terminal window). Possible answers include: /usr/bin/python This is the Python shipped by Apple /Library/Frameworks/Python.framework/Versions/2.7/bin/python This is a Python from python.org /opt/local/bin/python This is a Python from macports > Is this located in the /usr folder? If you mean /usr/bin, that's the Python that came with your Mac. If you haven't installed any other Pythons, then yes, you must be using that one. Hope this helps, -- HansM From hansmu at xs4all.nl Tue Jun 26 16:12:54 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 26 Jun 2012 22:12:54 +0200 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <347d6190-1bfc-4117-85ff-4abaa0966710@googlegroups.com> Message-ID: <4fea17c6$0$6940$e4fe514c@news2.news.xs4all.nl> On 26/06/12 21:51:41, Dennis Lee Bieber wrote: > On Tue, 26 Jun 2012 10:19:45 -0700 (PDT), David Thomas > declaimed the following in gmane.comp.python.general: > > >> http://www.freeimagehosting.net/ilbqt > > That's an interesting configuration... > > "pythonw.exe" is a version of the Python interpreter designed to NOT > OPEN a console -- so you've got a configuration saying "open a console > to run a no-console interpreter". That's on Windows; on the Mac python and pythonw are identical. In fact, they're hard links to the same file. > Normally pythonw.exe is used with scripts having .pyw extension; > these are scripts that use tkinter, wxPython, or other GUI system to > create a graphical environment and don't want a console (terminal) > window cluttering the screen when they don't use text I/O. > > Console based programs (.py) should be run using python.exe; adjust > your settings. That shouldn't matter on a Mac. You may want to check "allow #! to override", though. I mean, if there is a #! in a file pointing to a specific version of python, then it's probably there for a reason. For example, the script might use a third party module installed only in that Python install. >> http://www.freeimagehosting.net/r5ars > > And this is to be expected... In Python 2.x, "input()" attempts to > evaluate the input data, and you didn't supply anything -- hence EOF. > For your usage, you want "raw_input()", which just grabs the next line > of text and returns it as a string. What he says. > As for how to run if you've opened a console (shell [bash]) window, > the way to run a script is to type > > python .py Hope this helps, -- HansM From Tom.KACVINSKY at 3ds.com Tue Jun 26 16:24:05 2012 From: Tom.KACVINSKY at 3ds.com (KACVINSKY Tom) Date: Tue, 26 Jun 2012 20:24:05 +0000 Subject: distutils that supports msvc10 and that can be backfitted into Python 2.6 Message-ID: Hi, I have need for a distutils that supports msvc10, and which can be back-fitted into Python 2.6. Is there such a beast? Thanks in advance, Tom This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. For other languages, go to http://www.3ds.com/terms/email-disclaimer -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Tue Jun 26 16:41:59 2012 From: d at davea.name (Dave Angel) Date: Tue, 26 Jun 2012 16:41:59 -0400 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: <4fea0a7b$0$6942$e4fe514c@news2.news.xs4all.nl> References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <4fea0a7b$0$6942$e4fe514c@news2.news.xs4all.nl> Message-ID: <4FEA1E97.9000409@davea.name> On 06/26/2012 03:16 PM, Hans Mulder wrote: > > > Python is an executable, and is > typically located in a "bin" directory. To find out where > it is, type > > type python > > at the shell prompt (that's the first prompt you get if you > open a Terminal window). > > That's a typo. You presumably meant: which python -- DaveA From nagle at animats.com Tue Jun 26 17:08:43 2012 From: nagle at animats.com (John Nagle) Date: Tue, 26 Jun 2012 14:08:43 -0700 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: On 6/25/2012 1:36 AM, Stefan Behnel wrote: > gmspro, 24.06.2012 05:46: >> Why has python3 been created as a seperate language where there is still python2.7 ? > The intention of Py3 was to deliberately break backwards compatibility in > order to clean up the language. The situation is not as bad as you seem to > think, a huge amount of packages have been ported to Python 3 already > and/or work happily with both language dialects. The syntax changes in Python 3 are a minor issue for serious programmers. The big headaches come from packages that aren't being ported to Python 3 at all. In some cases, there's a replacement package from another author that performs the same function, but has a different API. Switching packages involves debugging some new package with, probably, one developer and a tiny user community. The Python 3 to MySQL connection is still a mess. The original developer of MySQLdb doesn't want to support Python 3. There's "pymysql", but it hasn't been updated since 2010 and has a long list of unfixed bugs. There was a "MySQL-python-1.2.3-py3k" port by a third party, but the domain that hosted it ("http://www.elecmor.mooo.com/python/MySQL-python-1.2.3-py3k.zip") is dead. There's MySQL for Python 3 (https://github.com/davispuh/MySQL-for-Python-3) but it doesn't work on Windows. MySQL Connector (https://code.launchpad.net/myconnpy) hasn't been updated in a while, but at least has some users. OurSQL has a different API than MySQLdb, and isn't quite ready for prime time yet. That's why I'm still on Python 2.7. John Nagle From rosuav at gmail.com Tue Jun 26 17:36:09 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Jun 2012 07:36:09 +1000 Subject: exception problem In-Reply-To: <4FEA0CC5.9050203@earthlink.net> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> <4FE7F6CC.2050704@earthlink.net> <4FE803F8.3050207@gmail.com> <4FE8803C.3020108@earthlink.net> <4FEA0CC5.9050203@earthlink.net> Message-ID: (You posted privately to me again; I hope you don't mind my responding on-list as this appears to have been merely oversight.) On Wed, Jun 27, 2012 at 5:25 AM, Charles Hixson wrote: > Only thing is, this whole mess started when I was trying to trace down and > expected error. ?(Which turned out to be "self.chunkLine(..." where self > wasn't defined.) ?It was running without ANY error being displayed. ?Though > as I look an outer loop is inclosed in a try:except:finally: ?It still has > an unlabelled except, because I don't remember what exception is thrown when > a file reads an unintelligible character ?(i.e., it isn't really a utf-8 > file). ?Currently I've fixed all the files so that they're either utf-8 or > just ASCII, so currently it isn't getting triggered, but it's still there. > ?So that's probably the explanation. ?I think I'll fix that now. ?(I can, I > guess, assume that any exception will be caught by except BasicException:) That's the problem, your blanket try/except. Don't do it! It blinds you. Same goes for catching Exception or BaseException. Catch what you really need to catch, and reserve catch-all statements for special cases where you don't have access to the console. ChrisA From rosuav at gmail.com Tue Jun 26 17:39:42 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Jun 2012 07:39:42 +1000 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: On Wed, Jun 27, 2012 at 7:08 AM, John Nagle wrote: > ? ?The Python 3 to MySQL connection is still a mess. > The original developer of MySQLdb doesn't want to support > Python 3. This is where I would start asking: How hard is it to migrate to another SQL database (eg Postgres)? That is, assuming that there's one with proper Py3 support. But I would find it hard to believe that there's _no_ good database with a Python 3 access module. ChrisA From hansmu at xs4all.nl Tue Jun 26 17:48:22 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 26 Jun 2012 23:48:22 +0200 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <4fea0a7b$0$6942$e4fe514c@news2.news.xs4all.nl> Message-ID: <4fea2e26$0$6883$e4fe514c@news2.news.xs4all.nl> On 26/06/12 22:41:59, Dave Angel wrote: > On 06/26/2012 03:16 PM, Hans Mulder wrote: >> >> >> Python is an executable, and is >> typically located in a "bin" directory. To find out where >> it is, type >> >> type python >> >> at the shell prompt (that's the first prompt you get if you >> open a Terminal window). >> >> > > That's a typo. You presumably meant: > > which python > No, I meant: $ type python python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python 'type' is a bash builtin that tells you how bash would interpret a command. 'which' is a separate program, which tells you how csh would interpret a command. For a 'bash' user, 'type' is more accurate than 'which'. For example, 'type' recognizes 'bash' builtins. -- HansM From python at mrabarnett.plus.com Tue Jun 26 18:30:46 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 26 Jun 2012 23:30:46 +0100 Subject: exception problem In-Reply-To: References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4FE79FC9.5050404@earthlink.net> <4FE7F6CC.2050704@earthlink.net> <4FE803F8.3050207@gmail.com> <4FE8803C.3020108@earthlink.net> <4FEA0CC5.9050203@earthlink.net> Message-ID: <4FEA3816.5030404@mrabarnett.plus.com> On 26/06/2012 22:36, Chris Angelico wrote: > (You posted privately to me again; I hope you don't mind my responding > on-list as this appears to have been merely oversight.) > > On Wed, Jun 27, 2012 at 5:25 AM, Charles Hixson > wrote: >> Only thing is, this whole mess started when I was trying to trace down and >> expected error. (Which turned out to be "self.chunkLine(..." where self >> wasn't defined.) It was running without ANY error being displayed. Though >> as I look an outer loop is inclosed in a try:except:finally: It still has >> an unlabelled except, because I don't remember what exception is thrown when >> a file reads an unintelligible character (i.e., it isn't really a utf-8 >> file). Currently I've fixed all the files so that they're either utf-8 or >> just ASCII, so currently it isn't getting triggered, but it's still there. >> So that's probably the explanation. I think I'll fix that now. (I can, I >> guess, assume that any exception will be caught by except BasicException:) > > That's the problem, your blanket try/except. Don't do it! It blinds > you. Same goes for catching Exception or BaseException. Catch what you > really need to catch, and reserve catch-all statements for special > cases where you don't have access to the console. > If you can't remember what exception is raised, just try raising it deliberately. Python _can_ be used interactively, after all. Even a short script to test it won't take you very long! From nobody at someplace.invalid Tue Jun 26 18:37:23 2012 From: nobody at someplace.invalid (HoneyMonster) Date: Tue, 26 Jun 2012 22:37:23 +0000 (UTC) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: On Wed, 27 Jun 2012 07:39:42 +1000, Chris Angelico wrote: > On Wed, Jun 27, 2012 at 7:08 AM, John Nagle wrote: >> ? ?The Python 3 to MySQL connection is still a mess. >> The original developer of MySQLdb doesn't want to support Python 3. > > This is where I would start asking: How hard is it to migrate to another > SQL database (eg Postgres)? That is, assuming that there's one with > proper Py3 support. But I would find it hard to believe that there's > _no_ good database with a Python 3 access module. psycopg2 (Python interface to PostgreSQL) supports Python 3.1 and 3.2 as well as Python 2. It works superbly. PostgreSQL is a far better database then MySQL anyway. From breamoreboy at yahoo.co.uk Tue Jun 26 19:13:42 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 27 Jun 2012 00:13:42 +0100 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <347d6190-1bfc-4117-85ff-4abaa0966710@googlegroups.com> <4fea17c6$0$6940$e4fe514c@news2.news.xs4all.nl> Message-ID: On 26/06/2012 23:35, Dennis Lee Bieber wrote: > > (And, on Windows at least, #! lines don't do > anything) > New for Python 3.3 http://www.python.org/dev/peps/pep-0397/ -- Cheers. Mark Lawrence. From tismer at stackless.com Tue Jun 26 20:34:03 2012 From: tismer at stackless.com (Christian Tismer) Date: Wed, 27 Jun 2012 02:34:03 +0200 Subject: tiffany 0.6 released In-Reply-To: <4fe91be7$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <4FE7C301.6010101@stackless.com> <4fe91be7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FEA54FB.4050108@stackless.com> Hi Steven, On 26.06.12 04:18, Steven D'Aprano wrote: > On Mon, 25 Jun 2012 23:36:59 +0200, Christian Tismer wrote: > >> I saw quite a lot of downloads of this package now, but not a single >> reaction or any feedback. > Feel fortunate that you are getting any downloads at all :) > > In my experience, if you are really lucky, perhaps one in a hundred > people who download a package will comment about it. > Ok, good to know. This is my first little package (funny, eh? Did much larger things), and this is new to me. >> How can I get more than just down-loaders? I would like to know, if >> >> - this module is of use for you >> - if there are wishes to get more functionality - if it makes sense at >> all >> - if there are feature requests. > You can't force people to comment. Do you have a blog where you can > report new functionality or bug fixes? That might help drive interest. Good input. I was trying to blog several times, but somehow lost it, again. Thanks a lot, I will force myself to blog. (but I'm more into email conversations, maybe doing stuff for too long ? ) > ... > If you are writing software for fame and attention, you're in the wrong > industry :) I assume not, at least I think. I want to do things right, and to see if they are right or if I'm on the wrong track, that's why I want the feedback. And I got quite some feedback on Stackless Python, but tiffany is a small niche project for probably orders of magnitude less people. > BTW, I have no need for your software, but that doesn't mean it isn't a > good and valuable piece of work. Thank you for sharing it with the > community, even if only a few people find it useful. Thanks for the adjustment. Now I'm feeling fine and will move on to other targets ;-) cheers -- Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From d at davea.name Tue Jun 26 22:38:54 2012 From: d at davea.name (Dave Angel) Date: Tue, 26 Jun 2012 22:38:54 -0400 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: <4fea2e26$0$6883$e4fe514c@news2.news.xs4all.nl> References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <4fea0a7b$0$6942$e4fe514c@news2.news.xs4all.nl> <4fea2e26$0$6883$e4fe514c@news2.news.xs4all.nl> Message-ID: <4FEA723E.9090909@davea.name> On 06/26/2012 05:48 PM, Hans Mulder wrote: > On 26/06/12 22:41:59, Dave Angel wrote: > > No, I meant: $ type python python is > /Library/Frameworks/Python.framework/Versions/2.7/bin/python 'type' is > a bash builtin that tells you how bash would interpret a command. > 'which' is a separate program, which tells you how csh would interpret > a command. For a 'bash' user, 'type' is more accurate than 'which'. > For example, 'type' recognizes 'bash' builtins. -- HansM Thanks for the information. "which" has worked on every unix-like system I've used for 25 years. I never knew that bash had its own extension. -- DaveA From adam at no_thanks.com Wed Jun 27 00:12:42 2012 From: adam at no_thanks.com (Adam) Date: Tue, 26 Jun 2012 21:12:42 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help Message-ID: Host OS: Ubuntu 10.04 LTS Guest OS: Windows XP Pro SP3 I am able to open port COM4 with Terminal emulator. So, what can cause PySerial to generate the following error ... C:\Wattcher>python wattcher.py Traceback (most recent call last): File "wattcher.py", line 56, in ser.open() File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, in open raise SerialException("could not open port %s: %s" % (self.portstr, ctypes.WinError())) serial.serialutil.SerialException: could not open port COM4: [Error 5] Access is denied. From nagle at animats.com Wed Jun 27 01:33:57 2012 From: nagle at animats.com (John Nagle) Date: Tue, 26 Jun 2012 22:33:57 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help In-Reply-To: References: Message-ID: On 6/26/2012 9:12 PM, Adam wrote: > Host OS: Ubuntu 10.04 LTS > Guest OS: Windows XP Pro SP3 > > > I am able to open port COM4 with Terminal emulator. > > So, what can cause PySerial to generate the following error ... > > C:\Wattcher>python wattcher.py > Traceback (most recent call last): > File "wattcher.py", line 56, in > ser.open() > File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, in > open > raise SerialException("could not open port %s: %s" % (self.portstr, > ctypes.WinError())) > serial.serialutil.SerialException: could not open port COM4: [Error 5] > Access is denied. Are you trying to access serial ports from a virtual machine? Which virtual machine environment? Xen? VMware? QEmu? VirtualBox? I wouldn't expect that to work in most of those. What is "COM4", anyway? Few machines today actually have four serial ports. Is some device emulating a serial port? John Nagle From georg at python.org Wed Jun 27 02:10:26 2012 From: georg at python.org (Georg Brandl) Date: Wed, 27 Jun 2012 08:10:26 +0200 Subject: [RELEASED] Python 3.3.0 beta 1 Message-ID: <4FEAA3D2.8080007@python.org> On behalf of the Python development team, I'm happy to announce the first beta release of Python 3.3.0. This is a preview release, and its use is not recommended in production settings. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. Major new features and changes in the 3.3 release series are: * PEP 380, syntax for delegating to a subgenerator ("yield from") * PEP 393, flexible string representation (doing away with the distinction between "wide" and "narrow" Unicode builds) * A C implementation of the "decimal" module, with up to 80x speedup for decimal-heavy applications * The import system (__import__) now based on importlib by default * The new "lzma" module with LZMA/XZ support * PEP 397, a Python launcher for Windows * PEP 405, virtual environment support in core * PEP 420, namespace package support * PEP 3151, reworking the OS and IO exception hierarchy * PEP 3155, qualified name for classes and functions * PEP 409, suppressing exception context * PEP 414, explicit Unicode literals to help with porting * PEP 418, extended platform-independent clocks in the "time" module * PEP 412, a new key-sharing dictionary implementation that significantly saves memory for object-oriented code * PEP 362, the function-signature object * The new "faulthandler" module that helps diagnosing crashes * The new "unittest.mock" module * The new "ipaddress" module * The "sys.implementation" attribute * A policy framework for the email package, with a provisional (see PEP 411) policy that adds much improved unicode support for email header parsing * A "collections.ChainMap" class for linking mappings to a single unit * Wrappers for many more POSIX functions in the "os" and "signal" modules, as well as other useful functions such as "sendfile()" * Hash randomization, introduced in earlier bugfix releases, is now switched on by default In total, almost 500 API items are new or improved in Python 3.3. For a more extensive list of changes in 3.3.0, see http://docs.python.org/3.3/whatsnew/3.3.html (*) To download Python 3.3.0 visit: http://www.python.org/download/releases/3.3.0/ Please consider trying Python 3.3.0 with your code and reporting any bugs you may notice to: http://bugs.python.org/ Enjoy! (*) Please note that this document is usually finalized late in the release cycle and therefore may have stubs and missing entries at this point. -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) From adam at no_thanks.com Wed Jun 27 05:10:24 2012 From: adam at no_thanks.com (Adam) Date: Wed, 27 Jun 2012 02:10:24 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: "John Nagle" wrote in message news:jse604$1cq$1 at dont-email.me... > On 6/26/2012 9:12 PM, Adam wrote: >> Host OS: Ubuntu 10.04 LTS >> Guest OS: Windows XP Pro SP3 >> >> >> I am able to open port COM4 with Terminal emulator. >> >> So, what can cause PySerial to generate the following error ... >> >> C:\Wattcher>python wattcher.py >> Traceback (most recent call last): >> File "wattcher.py", line 56, in >> ser.open() >> File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, >> in >> open >> raise SerialException("could not open port %s: %s" % (self.portstr, >> ctypes.WinError())) >> serial.serialutil.SerialException: could not open port COM4: [Error 5] >> Access is denied. > > Are you trying to access serial ports from a virtual machine? > Which virtual machine environment? Xen? VMware? QEmu? VirtualBox? > I wouldn't expect that to work in most of those. > > What is "COM4", anyway? Few machines today actually have four > serial ports. Is some device emulating a serial port? > > John Nagle > Thanks, and yes, I am using VirtualBox. My laptop does not have a serial port so I use a USB-to-serial converter, which is assigned COM4. From tismer at stackless.com Wed Jun 27 06:25:56 2012 From: tismer at stackless.com (Christian Tismer) Date: Wed, 27 Jun 2012 12:25:56 +0200 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FEADFB4.5090301@stackless.com> On 26.06.12 08:34, Stefan Behnel wrote: > Devin Jeanpierre, 26.06.2012 08:15: >> On Mon, Jun 25, 2012 at 11:35 PM, Steven D'Aprano >>> Making print a statement in the first place was a mistake, but >>> fortunately it was a simple enough mistake to rectify once the need for >>> backward compatibility was relaxed. >> Hmmm, why is the function so much better than the statement? You like >> using it in expressions? Or is it that you like passing it in as a >> callback? > First of all, the statement has a rather special syntax that is not obvious > and practically non-extensible. It also has hidden semantics that are hard > to explain and mixes formatting with output - soft-space, anyone? > > The function is straight forward, configurable, does one thing, works with > help() and doesn't get in the way. And something as rarely[1] used as a > print simply doesn't deserve special syntax. Oh, and, yes, you can even > pass it into some code as callback, although I rarely had a need for that. > I agree, and I don't want to revive an old discussion of the print statement. I just still don't see the point why the transition is made so uni-directional? With python2.7, it is great that "from __future__ import print_function" exists. But porting old code (PIL for instance) imposes a lot of changes which don't make sense, but produce overhead. Some are simple things like the print statement, which is used only in the debugging code. Enforcing the syntax change enforces changing many modules, which could otherwise work just fine as they are. I think, for the small importance of the print statement in code, it would have made the transition easier, if python 3 was as flexible as python 2.7, with a symmetric "from __past__ import print_statement" construct. That would have at least my acceptance much quicker, because the necessity of modifying stuff would reduce to the few changes which are important in a few modules. So right now, I try to use python 3, but the flexibility is right now in python2.7 . cheers - Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From rosuav at gmail.com Wed Jun 27 07:02:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Jun 2012 21:02:35 +1000 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <4FEADFB4.5090301@stackless.com> References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: On Wed, Jun 27, 2012 at 8:25 PM, Christian Tismer wrote: > I think, for the small importance of the print statement in code, it > would have made the transition easier, if python 3 was as flexible > as python 2.7, with a symmetric > > "from __past__ import print_statement" construct. > For how long? Will Python require, in perpetuity, the code to support this? Must the print statement be enhanced when the print function is? What about bug fixes? How much dev time is required to enable backward compatibility past a boundary across which backward compatibility was not promised? And if there's a limit to the duration of this __past__ directive, when should it be and what should happen after that point? Much easier to simply say no. ChrisA From stefan_ml at behnel.de Wed Jun 27 07:22:41 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 27 Jun 2012 13:22:41 +0200 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: Chris Angelico, 27.06.2012 13:02: > On Wed, Jun 27, 2012 at 8:25 PM, Christian Tismer wrote: >> I think, for the small importance of the print statement in code, it >> would have made the transition easier, if python 3 was as flexible >> as python 2.7, with a symmetric >> >> "from __past__ import print_statement" construct. > > For how long? Will Python require, in perpetuity, the code to support > this? Must the print statement be enhanced when the print function is? > What about bug fixes? How much dev time is required to enable backward > compatibility past a boundary across which backward compatibility was > not promised? And if there's a limit to the duration of this __past__ > directive, when should it be and what should happen after that point? > > Much easier to simply say no. I concur. For supporting something that shouldn't have been there in the first place, such as a print statement in production code, it's way too much overhead to keep it working despite of significant changes in the I/O layer that went into Python 3.x, including the removal of the soft-space "feature". For comparison, the revival of the "u" string prefix in Py3.3 is a simple change in the parser grammar that's easy to maintain but that has a huge impact on the Py3 compatibility of code that accepts to drop support for Py2.5 and earlier (as well as Py3.[012]) but wants to keep working in Py2.[67] (which supports the opposite "b" prefix). We've been supporting that in Cython for a while and it worked out really well so far. Stefan From jeanpierreda at gmail.com Wed Jun 27 07:24:41 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 27 Jun 2012 07:24:41 -0400 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: On Wed, Jun 27, 2012 at 7:02 AM, Chris Angelico wrote: > Much easier to simply say no. It's also easier to cease developing Python at all. By which I mean: just because something is hard doesn't mean it shouldn't be done. Lots of things Python does are hard, but they make users' lives easier. The question should probably be where developer effort is best spent, not where developers spend the least effort. -- Devin From roy at panix.com Wed Jun 27 07:45:46 2012 From: roy at panix.com (Roy Smith) Date: Wed, 27 Jun 2012 07:45:46 -0400 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> Message-ID: In article , rantingrickjohnson at gmail.com wrote: > On Monday, June 25, 2012 5:10:47 AM UTC-5, Michiel Overtoom wrote: > > It has not. Python2 and Python3 are very similar. It's not like if > > you learn Python using version 2, you have to relearn the language > > when you want to switch Python3. The syntax is the same, only > > 'print' is a function instead of a statement. > > However, there is something to be said for "old habits die hard". I myself > lament every time i must type->(, then blah, then->) AGAIN!. My fingers are > hardwired for the old print statement. Damned that Guido and his mind games! On the other hand, I hate it (in P2) when I want to change a print to a pprint and have to add the parens, then take them back out when I want to go back to plain print. From rosuav at gmail.com Wed Jun 27 08:05:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Jun 2012 22:05:17 +1000 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: On Wed, Jun 27, 2012 at 9:24 PM, Devin Jeanpierre wrote: > On Wed, Jun 27, 2012 at 7:02 AM, Chris Angelico wrote: >> Much easier to simply say no. > > It's also easier to cease developing Python at all. > > By which I mean: just because something is hard doesn't mean it > shouldn't be done. Lots of things Python does are hard, but they make > users' lives easier. The question should probably be where developer > effort is best spent, not where developers spend the least effort. Of course, of course. Easier doesn't necessarily mean better. But there's a much larger cost to this kind of backward compatibility than many people realize. ChrisA From jeandupont115 at gmail.com Wed Jun 27 08:24:42 2012 From: jeandupont115 at gmail.com (Jean Dupont) Date: Wed, 27 Jun 2012 05:24:42 -0700 (PDT) Subject: [newbie] problem with data (different behaviour between batch and interactive use) Message-ID: I have some data which is presented in the following format to me: +3.874693E-01,+9.999889E-03,+9.910000E+37,+1.876595E+04,+3.994000E+04 I'm only interested in the first two fields i.e. +3.874693E-01,+9.999889E-03 If I start python interactively I can separate the fields as follows: >measurement=+3.874693E01,+9.999889E03,+9.910000E+37,+1.876595E+04,+3.994000E+04 >print measurement[0] 0.3874693 >print measurement[1] 0.009999889 If however I run a script with the same commands I get something different: The script does this: measurement=serkeith.readline().replace('\x11','').replace('\x13','').replace('\x0d','\n') print measurement[0] + print measurement[1] 3 can anyone here tell me what I'm doing wrong and how to do it correctly thanks jean From nospam at needed.com Wed Jun 27 08:28:26 2012 From: nospam at needed.com (Paul) Date: Wed, 27 Jun 2012 08:28:26 -0400 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help In-Reply-To: References: Message-ID: Adam wrote: > "John Nagle" wrote in message > news:jse604$1cq$1 at dont-email.me... >> On 6/26/2012 9:12 PM, Adam wrote: >>> Host OS: Ubuntu 10.04 LTS >>> Guest OS: Windows XP Pro SP3 >>> >>> >>> I am able to open port COM4 with Terminal emulator. >>> >>> So, what can cause PySerial to generate the following error ... >>> >>> C:\Wattcher>python wattcher.py >>> Traceback (most recent call last): >>> File "wattcher.py", line 56, in >>> ser.open() >>> File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, >>> in >>> open >>> raise SerialException("could not open port %s: %s" % (self.portstr, >>> ctypes.WinError())) >>> serial.serialutil.SerialException: could not open port COM4: [Error 5] >>> Access is denied. >> Are you trying to access serial ports from a virtual machine? >> Which virtual machine environment? Xen? VMware? QEmu? VirtualBox? >> I wouldn't expect that to work in most of those. >> >> What is "COM4", anyway? Few machines today actually have four >> serial ports. Is some device emulating a serial port? >> >> John Nagle >> > > Thanks, and yes, I am using VirtualBox. My laptop does not have a serial > port so > I use a USB-to-serial converter, which is assigned COM4. > > Doesn't VirtualBox allow "remapping" serial ports ? I thought you could have COM 4 in the host OS, and make it COM 1 or COM 2 in the guest. Something like that. http://virtuatopia.com/images/6/60/Virtualbox_serial_port_settings.jpg Also, Windows (as a host), is notorious for stealing control of COM ports. Even Windows software, when you run it, would report "COM 4 is busy". Then, you have to track down *why* it's busy. Is it that FAX software you installed ? The GPS software that talks to your GPS serial interface ? In theory, the "Handle" program is supposed to identify what is keeping a COM port busy, but I don't get the desired results from it very often. You need to know the naming convention for virtual COM ports (COM4 via USB to serial, is more virtual than physical). That's what makes it harder to track down. These are some names for COM ports, in Windows. The last two entries, are my USB to serial adapters. VCP1 functions as COM3. VCP0 functions as COM4. The VCP part is what would be listed in "Handle" from Sysinternals. The \device\serial format, is more likely to be used with true "native" motherboard serial ports. \device\serial ups.exe pid: 1072 NT AUTHORITY\SYSTEM 98: File (---) \Device\VCP0 hypertrm.exe pid: 3404 ComputerName\UserID (claims to use COM3) E0: File (---) \Device\VCP1 You can download "Handle" and play with it here. http://technet.microsoft.com/en-us/sysinternals/bb896655 Note that, in my Handle results, at the time I was running the Windows provided ups.exe to talk to my external UPS (uninterruptible power supply). So that's what that reference is. The "hypertrm" one, is me using the built-in Windows terminal software, to talk to COM3, to keep the port artificially busy for the purposes of testing. If things were working well in your case, you *might* see something of this form. If not, you'd instead see the name of the process that has "stolen" the com port. virtualbox.exe pid: 1234 ComputerName\UserID E0: File (---) \Device\VCP0 HTH, Paul From DLipman~nospam~ at Verizon.Net Wed Jun 27 08:28:49 2012 From: DLipman~nospam~ at Verizon.Net (David H. Lipman) Date: Wed, 27 Jun 2012 08:28:49 -0400 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help In-Reply-To: References: Message-ID: From: "Adam" > > "John Nagle" wrote in message > news:jse604$1cq$1 at dont-email.me... >> On 6/26/2012 9:12 PM, Adam wrote: >>> Host OS: Ubuntu 10.04 LTS >>> Guest OS: Windows XP Pro SP3 >>> >>> I am able to open port COM4 with Terminal emulator. >>> >>> So, what can cause PySerial to generate the following error ... >>> >>> C:\Wattcher>python wattcher.py >>> Traceback (most recent call last): >>> File "wattcher.py", line 56, in >>> ser.open() >>> File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, >>> in >>> open >>> raise SerialException("could not open port %s: %s" % (self.portstr, >>> ctypes.WinError())) >>> serial.serialutil.SerialException: could not open port COM4: [Error 5] >>> Access is denied. >> >> Are you trying to access serial ports from a virtual machine? >> Which virtual machine environment? Xen? VMware? QEmu? VirtualBox? >> I wouldn't expect that to work in most of those. >> >> What is "COM4", anyway? Few machines today actually have four >> serial ports. Is some device emulating a serial port? >> >> John Nagle >> > Thanks, and yes, I am using VirtualBox. My laptop does not have a serial > port so > I use a USB-to-serial converter, which is assigned COM4. > Then it is a Virtual COM port. Often software will want to communicate directly to the COM4 port which is usually at: IRQ3 and I/O 2E8h. -- Dave Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk http://www.pctipp.ch/downloads/dl/35905.asp From roy at panix.com Wed Jun 27 08:45:48 2012 From: roy at panix.com (Roy Smith) Date: Wed, 27 Jun 2012 08:45:48 -0400 Subject: json.loads() should return a more specific error Message-ID: Before I go open an enhancement request, what do people think of the idea that json.load() should return something more specific than ValueError? I've got some code that looks like try: response = requests.get(url) except RequestException as ex: logger.exception(ex) return [] data = response.text try: events = json.loads(data) except ValueError as ex: logger.error("%s: %r", ex, data) return [] This would be so much neater if json would return something I could identify as a json error. It would all just collapse into: try: events = requests.get(url).json except (RequestException, JSONDecodeError) as ex: logger.exception(ex) return [] We could make JSONDecodeError a subclass of ValueError so existing code would continue to work. From jpiitula at ling.helsinki.fi Wed Jun 27 08:46:39 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 27 Jun 2012 15:46:39 +0300 Subject: [newbie] problem with data (different behaviour between batch and interactive use) References: Message-ID: Jean Dupont writes: > If I start python interactively I can separate the fields as > follows: > >measurement=+3.874693E01,+9.999889E03,+9.910000E+37,+1.876[...] > >print measurement[0] > 0.3874693 [...] > The script does this: > measurement=serkeith.readline().replace('\x11','').replace([...] > print measurement[0] > + [...] > can anyone here tell me what I'm doing wrong and how to do it > correctly When you index a string, you get characters. Your script handles a line as a string. Interact with Python using a string for your data to learn how it behaves and what to do: split the string into a list of written forms of the numbers as strings, then convert that into a list of those numbers, and index the list. This way: >>> measurement = "+3.874693E01,+9.999889E03,+9.910000E+37" >>> measurement '+3.874693E01,+9.999889E03,+9.910000E+37' >>> measurement.split(',') ['+3.874693E01', '+9.999889E03', '+9.910000E+37'] >>> measurement.split(',')[0] '+3.874693E01' >>> float(measurement.split(',')[0]) 38.746929999999999 >>> map(float, measurement.split(',')) [38.746929999999999, 9999.8889999999992, 9.9100000000000005e+37] >>> map(float, measurement.split(','))[0] 38.746929999999999 >>> In your previous interactive session you created a tuple of numbers, which is as good as a list in this context. The comma does that, parentheses not required: >>> measurement = +3.874693E01,+9.999889E03,+9.910000E+37 >>> measurement (38.746929999999999, 9999.8889999999992, 9.9100000000000005e+37) From prakash.stack at gmail.com Wed Jun 27 09:07:52 2012 From: prakash.stack at gmail.com (prakash jp) Date: Wed, 27 Jun 2012 18:37:52 +0530 Subject: cmd i/o stream module Message-ID: Hi All, I am interested to interact with the command prompt, is there a module to control the input/output stream. Thanks in advance for the pointers Thanks Prakash -------------- next part -------------- An HTML attachment was scrubbed... URL: From tismer at stackless.com Wed Jun 27 09:15:42 2012 From: tismer at stackless.com (Christian Tismer) Date: Wed, 27 Jun 2012 15:15:42 +0200 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: <4FEB077E.1010607@stackless.com> On 27.06.12 13:02, Chris Angelico wrote: > On Wed, Jun 27, 2012 at 8:25 PM, Christian Tismer wrote: >> I think, for the small importance of the print statement in code, it >> would have made the transition easier, if python 3 was as flexible >> as python 2.7, with a symmetric >> >> "from __past__ import print_statement" construct. >> > For how long? Will Python require, in perpetuity, the code to support > this? Must the print statement be enhanced when the print function is? > What about bug fixes? How much dev time is required to enable backward > compatibility past a boundary across which backward compatibility was > not promised? And if there's a limit to the duration of this __past__ > directive, when should it be and what should happen after that point? > > Much easier to simply say no. Just as a note: It is not that I'm lazy or against python3 or anything. The opposite is true, as I'm a long-term developer and python evangelist. My argument simply addresses to get as much acceptance of python3 as quickly as possible, and some hard work put into a backward feature would IMHO have been better for python3. I would even like much more drastic changes that python3 actually does, to make the move really worth moving. What happened was a bit the opposite: huge effort for making a really useful python 2.7. My strategy would have put less effort into that, and more to make python3 clearly the thing that people want and need. Right now I think python 2.7 is simply too good. ----- And especially for the print statement: It is a bad idea that the print statement _must_ create a syntax error. It is IMHO not important to support it really and could just work more or less, with no new features, because as said: print, function or not, is not important enough to enforce a rewrite everywhere because of syntax error. That hides the real semantic changes which _are_ important. So what I would have done is to let it work in an imperfect way. People then have the chance to rewrite with the print function, where it makes sense. But old packages which need to be changed, only because they have lots of if DEBUG: print xxx, yyy, ... could just stay unchanged or migrated later after the real meat has been properly tested etc. Well, I missed the right time to discuss that, so this is just a useless note about history. cheers -- Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From cousinstanley at gmail.com Wed Jun 27 09:23:34 2012 From: cousinstanley at gmail.com (Cousin Stanley) Date: Wed, 27 Jun 2012 13:23:34 +0000 (UTC) Subject: [newbie] problem with data (different behaviour between batch and interactive use) References: Message-ID: Jean Dupont wrote: > I have some data which is presented > in the following format to me : > > +3.874693E-01,+9.999889E-03,+9.910000E+37,+1.876595E+04,+3.994000E+04 > > I'm only interested in the first two fields i.e. > > +3.874693E-01,+9.999889E-03 > .... The following program will read lines of comma-separated data from a text file and add each line as a row in a list of lists .... The first two items in each row could be accessed by their indexes .... # -------------------------------------------------- #!/usr/bin/env python fsource = open( 'edata.txt' ) ltarget = [ ] for this_line in fsource : this_list = this_line.strip().split( ',' ) that_list = [ float( x ) for x in this_list ] ltarget.append( that_list ) for this_row in ltarget : print ' %e' % this_row[ 0 ] print ' %e' % this_row[ 1 ] print fsource.close() # ----------------------------------------------------- # # edata.txt +3.874693E01,+9.999889E03,+9.910000E+37,+1.876595E+04,+3.994000E+04 1e01,2e02,3e03,4e04,5e05 5e-05,4e-04,3e-03,2e-02,1e-01 -- Stanley C. Kitching Human Being Phoenix, Arizona From tismer at stackless.com Wed Jun 27 09:24:21 2012 From: tismer at stackless.com (Christian Tismer) Date: Wed, 27 Jun 2012 15:24:21 +0200 Subject: tiffany 0.6 released In-Reply-To: <4FEA54FB.4050108@stackless.com> References: <4FE7C301.6010101@stackless.com> <4fe91be7$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEA54FB.4050108@stackless.com> Message-ID: <4FEB0985.8020607@stackless.com> ... > Thanks for the adjustment. Now I'm feeling fine and will move on to > other targets ;-) By the way: Our conversation seems to have a real effect on downloads. :-) It has been quite a boost since 20 hours from some 25-40 to now over 200. cheers -- chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From tismer at stackless.com Wed Jun 27 09:32:35 2012 From: tismer at stackless.com (Christian Tismer) Date: Wed, 27 Jun 2012 15:32:35 +0200 Subject: tiffany 0.6 released In-Reply-To: <4FEB0985.8020607@stackless.com> References: <4FE7C301.6010101@stackless.com> <4fe91be7$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEA54FB.4050108@stackless.com> <4FEB0985.8020607@stackless.com> Message-ID: <4FEB0B73.503@stackless.com> On 27.06.12 15:24, Christian Tismer wrote: > ... >> Thanks for the adjustment. Now I'm feeling fine and will move on to >> other targets ;-) > > By the way: > Our conversation seems to have a real effect on downloads. :-) > > It has been quite a boost since 20 hours from some 25-40 to now > over 200. but it _may_ be that this is also an effect of supporting python 3.2, which probably made quite much sense, after all. -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From jerry.rocteur at gmail.com Wed Jun 27 09:40:42 2012 From: jerry.rocteur at gmail.com (Jerry Rocteur) Date: Wed, 27 Jun 2012 15:40:42 +0200 Subject: Python and Facebook In-Reply-To: References: Message-ID: > > > > > (Among our points are such diverse elements as... wrong Pythons, but > whatever.) > > > > > There's no official Python-Facebook module (afaik!!), but a quick web > > > search for 'python facebook' should get you to the couple that I saw, > > > and possibly others. The next question is, do you trust any of them... > > > Good luck with that one! :) > > > > > Chris Angelico > > > -- > > >http://mail.python.org/mailman/listinfo/python-list > > FWOW. I tried for about a week every Python Facebook module out there > I could find (including that one), with Python 2.5 or 2.7, and for > whatever reason was unsuccessful in uploading a photo and quit > trying. Frustrating. > > That is sad to read.. When I see what TheSocialFixed does with Javascript in Facebook I think I'll give Javascript it a go... Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Jun 27 09:44:53 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 27 Jun 2012 15:44:53 +0200 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <4FEB077E.1010607@stackless.com> References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> <4FEB077E.1010607@stackless.com> Message-ID: Christian Tismer, 27.06.2012 15:15: > print, function or not, is not important enough to enforce a rewrite > everywhere because of syntax error. That hides the real semantic > changes which _are_ important. > > So what I would have done is to let it work in an imperfect way. People > then have the chance to rewrite with the print function, where it makes > sense. But old packages which need to be changed, only because they > have lots of > > if DEBUG: > print xxx, yyy, ... > > could just stay unchanged or migrated later after the real meat has > been properly tested etc. Well, at least a SyntaxError makes it easy to find. And even if you don't intend to use 2to3, you can still run it once to generate a patch for you that only fixes up "print". In many cases, that will also make it work in Py2 in such an "imperfect" way, either by doing the right thing already or by printing out a tuple instead of a space separated string. If it's only for debug output (which, as I said, would better be served by the logging module), I can't see why that would be all that unacceptable. Stefan From rosuav at gmail.com Wed Jun 27 09:44:54 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Jun 2012 23:44:54 +1000 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <4FEB077E.1010607@stackless.com> References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> <4FEB077E.1010607@stackless.com> Message-ID: On Wed, Jun 27, 2012 at 11:15 PM, Christian Tismer wrote: > So what I would have done is to let it work in an imperfect way. People > then have the chance to rewrite with the print function, where it makes > sense. But old packages which need to be changed, only because they > have lots of > > ? ?if DEBUG: > ? ? ? ?print xxx, yyy, ... > > could just stay unchanged or migrated later after the real meat has > been properly tested etc. Far as I can tell, these sorts of things ought all to be handled by 2to3. No problem once you're looking at migrating. ChrisA From barber.justin at gmail.com Wed Jun 27 10:09:52 2012 From: barber.justin at gmail.com (Justin Barber) Date: Wed, 27 Jun 2012 07:09:52 -0700 (PDT) Subject: [newbie] problem with data (different behaviour between batch and interactive use) In-Reply-To: References: Message-ID: When you are reading it in measurement is a string. The indicies of the string are going to be returned in your print statements. Similar to having done this in the interpreter: In [17]: measurement = '+3.874693E01,+9.999889E03,+9.910000E+37,+1.876595E+04,+3.994000E+04' In [18]: measurement[1] Out[18]: '3' In [19]: measurement[0] Out[19]: '+' You need to split up your string and convert to floats. measurement = map(float, serkeith.readline().replace('\x11','').replace('\x13','').replace('\x0d','\n').split(',')) Something like that should work... to test in interpreter do the following : measurement = map(float, '+3.874693E01,+9.999889E03,+9.910000E+37,+1.876595E+04,+3.994000E+04'.split(',')) In [24]: measurement[0] Out[24]: 38.74693 From brackey.chris26 at gmail.com Wed Jun 27 10:23:53 2012 From: brackey.chris26 at gmail.com (kim phillips) Date: Wed, 27 Jun 2012 09:23:53 -0500 Subject: Draft Message-ID: -------------- next part -------------- An HTML attachment was scrubbed... URL: From tismer at stackless.com Wed Jun 27 10:34:31 2012 From: tismer at stackless.com (Christian Tismer) Date: Wed, 27 Jun 2012 16:34:31 +0200 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> <4FEB077E.1010607@stackless.com> Message-ID: <4FEB19F7.6080103@stackless.com> On 27.06.12 15:44, Stefan Behnel wrote: > Christian Tismer, 27.06.2012 15:15: >> print, function or not, is not important enough to enforce a rewrite >> everywhere because of syntax error. That hides the real semantic >> changes which _are_ important. >> >> So what I would have done is to let it work in an imperfect way. People >> then have the chance to rewrite with the print function, where it makes >> sense. But old packages which need to be changed, only because they >> have lots of >> >> if DEBUG: >> print xxx, yyy, ... >> >> could just stay unchanged or migrated later after the real meat has >> been properly tested etc. > Well, at least a SyntaxError makes it easy to find. And even if you don't > intend to use 2to3, you can still run it once to generate a patch for you > that only fixes up "print". In many cases, that will also make it work in > Py2 in such an "imperfect" way, either by doing the right thing already or > by printing out a tuple instead of a space separated string. If it's only > for debug output (which, as I said, would better be served by the logging > module), I can't see why that would be all that unacceptable. > Ok, here comes the real story: I extracted a few files from the old PIL package and made the stuff that was needed for my own little utility with a couple of monkey-patches, import hooks etc. After quite some trouble, this worked unter python 2.6 and 2.7, with the unchanged original PIL files. And I was after that: abuse PIL without maintaining it! Then I got real problems when trying to make it run under python 3.2, and from then on I needed two sets of source files, mostly because of the print mess. Most other things were adjustable by monkey-patches, moving to the io module etc. etc. In the end, the only thing that required a real change of source code that I could not circumvent was the indexing of bytes, which is giving chars under python 2.x, but integers under 3.x. At this point my hope to keep the unmodified PIL files died, although without print, this would have been an isolated single 20 lines block in the TiffImagePlugin only, instead of much more changes criss-cross over several sources. Anyway, I ended up with a port of the relevant PIL files to python 3 with some backward-compatible additions (for heaven's sake, at least python 3 accepts the __future__ imports), so now I'm down to single source files, but unfortunately changed files, and I have to track changes in the future. That battle was lost: I wanted the PIL files simply to be drop-ins, without going to work on PIL, because then I would do a complete rewrite after some discussion with the author. That's why I was unhappy with py3's missing flexibility. ciao -- Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From theller at ctypes.org Wed Jun 27 10:36:07 2012 From: theller at ctypes.org (Thomas Heller) Date: Wed, 27 Jun 2012 16:36:07 +0200 Subject: 2to6 ? Message-ID: Is there a tool, similar to 2to3, which converts python2 code to code using six.py, so that it runs unchanged with python2 *and* python 3? Thomas From invalid at invalid.invalid Wed Jun 27 10:53:37 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 27 Jun 2012 14:53:37 +0000 (UTC) Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: On 2012-06-27, David H. Lipman wrote: > From: "Adam" >> "John Nagle" wrote in message >> news:jse604$1cq$1 at dont-email.me... >>> On 6/26/2012 9:12 PM, Adam wrote: >>>> Host OS: Ubuntu 10.04 LTS >>>> Guest OS: Windows XP Pro SP3 >>>> >>>> I am able to open port COM4 with Terminal emulator. >>>> >>>> So, what can cause PySerial to generate the following error ... >>>> >>>> C:\Wattcher>python wattcher.py >>>> Traceback (most recent call last): >>>> File "wattcher.py", line 56, in >>>> ser.open() >>>> File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, in open >>>> raise SerialException("could not open port %s: %s" % (self.portstr, >>>> ctypes.WinError())) >>>> serial.serialutil.SerialException: could not open port COM4: [Error 5] >>>> Access is denied. >>> >>> Are you trying to access serial ports from a virtual machine? Which >>> virtual machine environment? Xen? VMware? QEmu? VirtualBox? I >>> wouldn't expect that to work in most of those. Except he says it _does_ work with his terminal emulator. >>> What is "COM4", anyway? Few machines today actually have four >>> serial ports. Is some device emulating a serial port? It shouldn't matter. If other apps can open COM4, then pyserial should be able to open COM4. >> Thanks, and yes, I am using VirtualBox. My laptop does not have a >> serial port so I use a USB-to-serial converter, which is assigned >> COM4. > > Then it is a Virtual COM port. Often software will want to > communicate directly to the COM4 port which is usually at: IRQ3 and > I/O 2E8h. Pyserial doesn't do that. It uses the standard win32 serial API, and it should work just fine with any Win32 serial device (what you call a "virtual" COM port). -- Grant Edwards grant.b.edwards Yow! World War III? at No thanks! gmail.com From adam at no_thanks.com Wed Jun 27 11:26:29 2012 From: adam at no_thanks.com (Adam) Date: Wed, 27 Jun 2012 08:26:29 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: "Paul" wrote in message news:jseu9c$sp3$1 at dont-email.me... > Adam wrote: >> "John Nagle" wrote in message >> news:jse604$1cq$1 at dont-email.me... >>> On 6/26/2012 9:12 PM, Adam wrote: >>>> Host OS: Ubuntu 10.04 LTS >>>> Guest OS: Windows XP Pro SP3 >>>> >>>> >>>> I am able to open port COM4 with Terminal emulator. >>>> >>>> So, what can cause PySerial to generate the following error ... >>>> >>>> C:\Wattcher>python wattcher.py >>>> Traceback (most recent call last): >>>> File "wattcher.py", line 56, in >>>> ser.open() >>>> File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, >>>> in >>>> open >>>> raise SerialException("could not open port %s: %s" % >>>> (self.portstr, >>>> ctypes.WinError())) >>>> serial.serialutil.SerialException: could not open port COM4: [Error 5] >>>> Access is denied. >>> Are you trying to access serial ports from a virtual machine? >>> Which virtual machine environment? Xen? VMware? QEmu? VirtualBox? >>> I wouldn't expect that to work in most of those. >>> >>> What is "COM4", anyway? Few machines today actually have four >>> serial ports. Is some device emulating a serial port? >>> >>> John Nagle >>> >> >> Thanks, and yes, I am using VirtualBox. My laptop does not have a serial >> port so >> I use a USB-to-serial converter, which is assigned COM4. >> > > Doesn't VirtualBox allow "remapping" serial ports ? I thought you > could have COM 4 in the host OS, and make it COM 1 or COM 2 in > the guest. Something like that. > > http://virtuatopia.com/images/6/60/Virtualbox_serial_port_settings.jpg > > Also, Windows (as a host), is notorious for stealing control of > COM ports. Even Windows software, when you run it, would report > "COM 4 is busy". Then, you have to track down *why* it's busy. > Is it that FAX software you installed ? The GPS software > that talks to your GPS serial interface ? > > In theory, the "Handle" program is supposed to identify what > is keeping a COM port busy, but I don't get the desired > results from it very often. You need to know the naming > convention for virtual COM ports (COM4 via USB to serial, is > more virtual than physical). That's what makes it harder > to track down. > > These are some names for COM ports, in Windows. The last two entries, > are my USB to serial adapters. VCP1 functions as COM3. > VCP0 functions as COM4. The VCP part is what would be > listed in "Handle" from Sysinternals. The \device\serial > format, is more likely to be used with true "native" > motherboard serial ports. > > \device\serial > > ups.exe pid: 1072 NT AUTHORITY\SYSTEM > 98: File (---) \Device\VCP0 > hypertrm.exe pid: 3404 ComputerName\UserID (claims to use COM3) > E0: File (---) \Device\VCP1 > > You can download "Handle" and play with it here. > > http://technet.microsoft.com/en-us/sysinternals/bb896655 > > Note that, in my Handle results, at the time I was running > the Windows provided ups.exe to talk to my external UPS > (uninterruptible power supply). So that's what that > reference is. The "hypertrm" one, is me using the > built-in Windows terminal software, to talk to COM3, > to keep the port artificially busy for the purposes > of testing. > > If things were working well in your case, you *might* > see something of this form. If not, you'd instead > see the name of the process that has "stolen" the > com port. > > virtualbox.exe pid: 1234 ComputerName\UserID > E0: File (---) \Device\VCP0 > > HTH, > Paul Thanks (Guru Paul), I've been using the USB-to-serial converter successfully without enabling/remapping via VBox Settings=>Serial Ports (which are both "not" enabled). I can see the serial port COM4 under Device Manager though. So, maybe enabling is necessary when the host has "native" serial ports, which my laptop does not have. >From the output generated by Handle.exe, here's the section for TeraTerm ... ------------------------------------------------------------------------------ ttermpro.exe pid: 596 VBOX_WINXPPRO\adam (claims to use COM4) C: File (RW-) D:\downloads\Tera Term Pro\ttpro313 2C: Section \BaseNamedObjects\ttset_memfilemap 44: File (RW-) C:\WINDOWS.0\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202 54: File (RW-) C:\WINDOWS.0\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.6195_x-ww_44262b86 70: Section \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_K32_0_1c9aa25ea688500_7c80_S-1-5-21-1801674531-1078145449-1957994488-1004 78: File (RWD) C:\DOCUME~1\adam\LOCALS~1\Temp\IswTmp\Logs\ISWSHEX.swl AC: Section \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_A32_0_1c98aa70f70ec00_77dd_S-1-5-21-1801674531-1078145449-1957994488-1004 100: Section \BaseNamedObjects\CiceroSharedMemDefaultS-1-5-21-1801674531-1078145449-1957994488-1004 108: File (RW-) D:\downloads\Tera Term Pro\ttpro313\httplog.log 120: Section \BaseNamedObjects\CTF.TimListCache.FMPDefaultS-1-5-21-1801674531-1078145449-1957994488-1004SFM.DefaultS-1-5-21-1801674531-1078145449-1957994488-1004 128: Section \BaseNamedObjects\ShimSharedMemory 138: Section \BaseNamedObjects\MSCTF.Shared.SFM.IAB ------------------------------------------------------------------------------ From nospam at needed.com Wed Jun 27 12:04:14 2012 From: nospam at needed.com (Paul) Date: Wed, 27 Jun 2012 12:04:14 -0400 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help In-Reply-To: References: Message-ID: Adam wrote: > "Paul" wrote in message > news:jseu9c$sp3$1 at dont-email.me... >> Adam wrote: >>> "John Nagle" wrote in message >>> news:jse604$1cq$1 at dont-email.me... >>>> On 6/26/2012 9:12 PM, Adam wrote: >>>>> Host OS: Ubuntu 10.04 LTS >>>>> Guest OS: Windows XP Pro SP3 >>>>> >>>>> >>>>> I am able to open port COM4 with Terminal emulator. >>>>> >>>>> So, what can cause PySerial to generate the following error ... >>>>> >>>>> C:\Wattcher>python wattcher.py >>>>> Traceback (most recent call last): >>>>> File "wattcher.py", line 56, in >>>>> ser.open() >>>>> File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, >>>>> in >>>>> open >>>>> raise SerialException("could not open port %s: %s" % >>>>> (self.portstr, >>>>> ctypes.WinError())) >>>>> serial.serialutil.SerialException: could not open port COM4: [Error 5] >>>>> Access is denied. >>>> Are you trying to access serial ports from a virtual machine? >>>> Which virtual machine environment? Xen? VMware? QEmu? VirtualBox? >>>> I wouldn't expect that to work in most of those. >>>> >>>> What is "COM4", anyway? Few machines today actually have four >>>> serial ports. Is some device emulating a serial port? >>>> >>>> John Nagle >>>> >>> Thanks, and yes, I am using VirtualBox. My laptop does not have a serial >>> port so >>> I use a USB-to-serial converter, which is assigned COM4. >>> >> Doesn't VirtualBox allow "remapping" serial ports ? I thought you >> could have COM 4 in the host OS, and make it COM 1 or COM 2 in >> the guest. Something like that. >> >> http://virtuatopia.com/images/6/60/Virtualbox_serial_port_settings.jpg >> >> Also, Windows (as a host), is notorious for stealing control of >> COM ports. Even Windows software, when you run it, would report >> "COM 4 is busy". Then, you have to track down *why* it's busy. >> Is it that FAX software you installed ? The GPS software >> that talks to your GPS serial interface ? >> >> In theory, the "Handle" program is supposed to identify what >> is keeping a COM port busy, but I don't get the desired >> results from it very often. You need to know the naming >> convention for virtual COM ports (COM4 via USB to serial, is >> more virtual than physical). That's what makes it harder >> to track down. >> >> These are some names for COM ports, in Windows. The last two entries, >> are my USB to serial adapters. VCP1 functions as COM3. >> VCP0 functions as COM4. The VCP part is what would be >> listed in "Handle" from Sysinternals. The \device\serial >> format, is more likely to be used with true "native" >> motherboard serial ports. >> >> \device\serial >> >> ups.exe pid: 1072 NT AUTHORITY\SYSTEM >> 98: File (---) \Device\VCP0 >> hypertrm.exe pid: 3404 ComputerName\UserID (claims to use COM3) >> E0: File (---) \Device\VCP1 >> >> You can download "Handle" and play with it here. >> >> http://technet.microsoft.com/en-us/sysinternals/bb896655 >> >> Note that, in my Handle results, at the time I was running >> the Windows provided ups.exe to talk to my external UPS >> (uninterruptible power supply). So that's what that >> reference is. The "hypertrm" one, is me using the >> built-in Windows terminal software, to talk to COM3, >> to keep the port artificially busy for the purposes >> of testing. >> >> If things were working well in your case, you *might* >> see something of this form. If not, you'd instead >> see the name of the process that has "stolen" the >> com port. >> >> virtualbox.exe pid: 1234 ComputerName\UserID >> E0: File (---) \Device\VCP0 >> >> HTH, >> Paul > > > Thanks (Guru Paul), I've been using the USB-to-serial converter successfully > without > enabling/remapping via VBox Settings=>Serial Ports (which are both "not" > enabled). > I can see the serial port COM4 under Device Manager though. So, maybe > enabling is > necessary when the host has "native" serial ports, which my laptop does not > have. > > From the output generated by Handle.exe, here's the section for TeraTerm ... > ------------------------------------------------------------------------------ > ttermpro.exe pid: 596 VBOX_WINXPPRO\adam (claims to use COM4) > C: File (RW-) D:\downloads\Tera Term Pro\ttpro313 > 2C: Section \BaseNamedObjects\ttset_memfilemap > 44: File (RW-) > C:\WINDOWS.0\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202 > 54: File (RW-) > C:\WINDOWS.0\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.6195_x-ww_44262b86 > 70: Section > \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_K32_0_1c9aa25ea688500_7c80_S-1-5-21-1801674531-1078145449-1957994488-1004 > 78: File (RWD) C:\DOCUME~1\adam\LOCALS~1\Temp\IswTmp\Logs\ISWSHEX.swl > AC: Section > \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_A32_0_1c98aa70f70ec00_77dd_S-1-5-21-1801674531-1078145449-1957994488-1004 > 100: Section > \BaseNamedObjects\CiceroSharedMemDefaultS-1-5-21-1801674531-1078145449-1957994488-1004 > 108: File (RW-) D:\downloads\Tera Term Pro\ttpro313\httplog.log > 120: Section > \BaseNamedObjects\CTF.TimListCache.FMPDefaultS-1-5-21-1801674531-1078145449-1957994488-1004SFM.DefaultS-1-5-21-1801674531-1078145449-1957994488-1004 > 128: Section \BaseNamedObjects\ShimSharedMemory > 138: Section \BaseNamedObjects\MSCTF.Shared.SFM.IAB > ------------------------------------------------------------------------------ For Handle to give a positive result, the TeraTerm program would need to currently have the serial port open. If you haven't started a terminal session, it might not be listed. Handle has some kind of filter function, and you can try searching for the name of the port that way. I don't see anything in that snipping, which looks like a serial port. Paul From ironfroggy at gmail.com Wed Jun 27 12:51:31 2012 From: ironfroggy at gmail.com (Calvin Spealman) Date: Wed, 27 Jun 2012 12:51:31 -0400 Subject: PyCarolinas Is a Go! Message-ID: PyCarolinas 2012 Is a Go! We?ve now finalized the location and dates, and can officially announce that PyCarolinas 2012, the first Python conference held in the Carolinas, will be October 20th and 21st at the Kerr building of the UNC School of Pharmacy. PyCarolinas is aFREEconference. We are extremely lucky to have an excellent space donated, and will raise our additional funds outside of registration costs. There will be a registration opening up closer to the conference date, with a cut-off around 150 participants. We?ll have two well-equipped rooms to fill, hopefully splitting our talks into novice and advanced tracks. Day one will be all talk, and day two will rolling and afternoon and evening of sprints. We have a great space to fill our first year with, so please read the Call for Proposals re-post below and help make this a great conference! We want anything you?d like to talk about. What have you built? What problems have you solved? What experiences can you talk about? If you aren?t sure, propose anyway! We?ll try our best to give feedback, so if you aren?t sure you have a fully fleshed idea: propose it for the feedback and see what happens. REPOST OF CALL FOR PROPOSALS (originally http://blog.pycarolinas.org/post/23480731404/call-for-proposals) PyCarolinas 2012 Call For Proposals PyCarolinas 2012, the first Python conference held in the carolinas, is now accepting proposals! We?re looking for proposals for talks you can present to this great and growing Python community. PyCarolinas will be held in October in Chapel Hill, NC. The exact location and dates of the two-day conference will be announced shortly. The proposal deadline is July 20, 2012. Please submit your proposals to talks at pycarolinas.org. About PyCarolinas 2012 PyCarolinas 2012 is the first Python Conference held in the carolinas and will be located in Chapel Hill, NC this October. The specific date and location will be announced shortly. It is a two day conference, with one day of talks and one day or sprinting. Who should submit a proposal? Anyone! We?re looking for as broad a cross-section of the Python community as possible. We?re looking for both experienced conference speakers and people new to technical conferences; industry professionals and hobbyists; entrepreneurs, researchers, and system administrators. You?ve probably learned something that other Python users could benefit from, so come toPyCarolinas and share your story. Maybe you?ve written the next great data mining package, or you have a case study to share, or you?ve learned something about how to start a Python users? group, or you just want to help novices learn how to choose a Python web framework. If you have something to tell your fellow Python programmers, this is your chance. You don?t have to be a professional speaker to give a talk at PyCarolinas. Presenters can be volunteers from all walks of life and all levels of experience. From hardcore hackers to educators to hobbyists, anyone with something to say and the desire to say it is welcome. If you have a topic idea but you?re not sure exactly how to turn it into a killer session, let us know! The program committee is happy to work with you to help your session shine. What kind of sessions can I give? PyCarolinas 2012, as a small event, is acceptingonly traditional sessions during the main conference. We are looking for sessions at 30 and 45 minutes. All levels of talks from from novice-level overviews to advanced topics are welcome. Conference registration and travel PyCarolinas is entirely volunteer-organized and run, and must keep costs as low as possible. We are unable to provide assistance or compensation for speakers traveling to and staying near the conference for the duration of the event. Timeline and deadlines Please don?t delay! The proposal window is long, but the sooner you submit a proposal, the more time we?ll have to help you put forward the best proposal. The program committee will officially begin reviewing proposals and giving feedback as soon as the CFP closes, but the team will attempt to begin reviewing and discussing proposals prior to the close of the Call for Proposals to assist authors. Proposals for talks will be accepted until July 20th. The list of selected talks and tutorials will be finalized by the end of August. Thank you! Submit your proposal to talks at pycarolinas.org and thanks for helping us make the first ever PyCarolinas great! Visit our website to sign up for updates by e-mail Website: http://pycarolinas.org/ Original Post: http://blog.pycarolinas.org/post/25999258917/pycarolinas-2012-is-a-go From dthomas86 at me.com Wed Jun 27 13:05:44 2012 From: dthomas86 at me.com (David Thomas) Date: Wed, 27 Jun 2012 10:05:44 -0700 (PDT) Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: <4fea2e26$0$6883$e4fe514c@news2.news.xs4all.nl> References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <4fea0a7b$0$6942$e4fe514c@news2.news.xs4all.nl> <4fea2e26$0$6883$e4fe514c@news2.news.xs4all.nl> Message-ID: <2401bda7-46a0-4dcb-93e5-4bd739e729d2@googlegroups.com> On Tuesday, June 26, 2012 10:48:22 PM UTC+1, Hans Mulder wrote: > On 26/06/12 22:41:59, Dave Angel wrote: > > On 06/26/2012 03:16 PM, Hans Mulder wrote: > >> > >> > >> Python is an executable, and is > >> typically located in a "bin" directory. To find out where > >> it is, type > >> > >> type python > >> > >> at the shell prompt (that's the first prompt you get if you > >> open a Terminal window). > >> > >> > > > > That's a typo. You presumably meant: > > > > which python > > > > No, I meant: > > $ type python > python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python > > 'type' is a bash builtin that tells you how bash would interpret > a command. 'which' is a separate program, which tells you how > csh would interpret a command. For a 'bash' user, 'type' is more > accurate than 'which'. For example, 'type' recognizes 'bash' > builtins. > > -- HansM I have the following: Is this why I keep getting an error using launcher? Also to open the script in terminal do I need to put the following at the beginning of my script: #!/bin/python On python.org it states to To run your script from the Terminal window you must make sure that /usr/local/bin is in your shell search path. How can I make sure that the Python I have installed on my Mac is in my shell search path. http://www.freeimagehosting.net/saskk Thanks again and I am sorry for all the questions, I am just getting started on Python From subhabangalore at gmail.com Wed Jun 27 13:33:44 2012 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Wed, 27 Jun 2012 10:33:44 -0700 (PDT) Subject: Slow output Message-ID: <53d49cb1-a68a-49c4-b925-b8a910ac415a@googlegroups.com> Dear Group, I am Sri Subhabrata Banerjee writing from India. I am running a small program which exploits around 12 1 to 2 KB .txt files. I am using MS Windows XP Service Pack 3 and Python 2.6 where IDLE is GUI. The text is plain ASCII text. The RAM of the machine is around 2 GB. To run the program the machine is becoming dead slow and it is executing only after several minutes. I am shocked as I have run hugely loaded Statistical Learning stuff only on 516MB RAM on Python using Windows XP only. And that too on a laptop. I am not getting. I discussed the issue with my system administrator and he increased the RAM to 8GB result improved by 30% but not satisfactory speed. May any one suggest me what may be the likely issue? Thanking You in Advance, Subhabrata Banerjee. From adam at no_thanks.com Wed Jun 27 13:41:46 2012 From: adam at no_thanks.com (Adam) Date: Wed, 27 Jun 2012 10:41:46 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: "Paul" wrote in message news:jsfatv$djt$1 at dont-email.me... > Adam wrote: >> "Paul" wrote in message >> news:jseu9c$sp3$1 at dont-email.me... >>> Adam wrote: >>>> "John Nagle" wrote in message >>>> news:jse604$1cq$1 at dont-email.me... >>>>> On 6/26/2012 9:12 PM, Adam wrote: >>>>>> Host OS: Ubuntu 10.04 LTS >>>>>> Guest OS: Windows XP Pro SP3 >>>>>> >>>>>> >>>>>> I am able to open port COM4 with Terminal emulator. >>>>>> >>>>>> So, what can cause PySerial to generate the following error ... >>>>>> >>>>>> C:\Wattcher>python wattcher.py >>>>>> Traceback (most recent call last): >>>>>> File "wattcher.py", line 56, in >>>>>> ser.open() >>>>>> File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line >>>>>> 56, in >>>>>> open >>>>>> raise SerialException("could not open port %s: %s" % >>>>>> (self.portstr, >>>>>> ctypes.WinError())) >>>>>> serial.serialutil.SerialException: could not open port COM4: [Error >>>>>> 5] >>>>>> Access is denied. >>>>> Are you trying to access serial ports from a virtual machine? >>>>> Which virtual machine environment? Xen? VMware? QEmu? VirtualBox? >>>>> I wouldn't expect that to work in most of those. >>>>> >>>>> What is "COM4", anyway? Few machines today actually have four >>>>> serial ports. Is some device emulating a serial port? >>>>> >>>>> John Nagle >>>>> >>>> Thanks, and yes, I am using VirtualBox. My laptop does not have a >>>> serial port so >>>> I use a USB-to-serial converter, which is assigned COM4. >>>> >>> Doesn't VirtualBox allow "remapping" serial ports ? I thought you >>> could have COM 4 in the host OS, and make it COM 1 or COM 2 in >>> the guest. Something like that. >>> >>> http://virtuatopia.com/images/6/60/Virtualbox_serial_port_settings.jpg >>> >>> Also, Windows (as a host), is notorious for stealing control of >>> COM ports. Even Windows software, when you run it, would report >>> "COM 4 is busy". Then, you have to track down *why* it's busy. >>> Is it that FAX software you installed ? The GPS software >>> that talks to your GPS serial interface ? >>> >>> In theory, the "Handle" program is supposed to identify what >>> is keeping a COM port busy, but I don't get the desired >>> results from it very often. You need to know the naming >>> convention for virtual COM ports (COM4 via USB to serial, is >>> more virtual than physical). That's what makes it harder >>> to track down. >>> >>> These are some names for COM ports, in Windows. The last two entries, >>> are my USB to serial adapters. VCP1 functions as COM3. >>> VCP0 functions as COM4. The VCP part is what would be >>> listed in "Handle" from Sysinternals. The \device\serial >>> format, is more likely to be used with true "native" >>> motherboard serial ports. >>> >>> \device\serial >>> >>> ups.exe pid: 1072 NT AUTHORITY\SYSTEM >>> 98: File (---) \Device\VCP0 >>> hypertrm.exe pid: 3404 ComputerName\UserID (claims to use COM3) >>> E0: File (---) \Device\VCP1 >>> >>> You can download "Handle" and play with it here. >>> >>> http://technet.microsoft.com/en-us/sysinternals/bb896655 >>> >>> Note that, in my Handle results, at the time I was running >>> the Windows provided ups.exe to talk to my external UPS >>> (uninterruptible power supply). So that's what that >>> reference is. The "hypertrm" one, is me using the >>> built-in Windows terminal software, to talk to COM3, >>> to keep the port artificially busy for the purposes >>> of testing. >>> >>> If things were working well in your case, you *might* >>> see something of this form. If not, you'd instead >>> see the name of the process that has "stolen" the >>> com port. >>> >>> virtualbox.exe pid: 1234 ComputerName\UserID >>> E0: File (---) \Device\VCP0 >>> >>> HTH, >>> Paul >> >> >> Thanks (Guru Paul), I've been using the USB-to-serial converter >> successfully without >> enabling/remapping via VBox Settings=>Serial Ports (which are both "not" >> enabled). >> I can see the serial port COM4 under Device Manager though. So, maybe >> enabling is >> necessary when the host has "native" serial ports, which my laptop does >> not have. >> >> From the output generated by Handle.exe, here's the section for TeraTerm >> ... >> ------------------------------------------------------------------------------ >> ttermpro.exe pid: 596 VBOX_WINXPPRO\adam (claims to use COM4) >> C: File (RW-) D:\downloads\Tera Term Pro\ttpro313 >> 2C: Section \BaseNamedObjects\ttset_memfilemap >> 44: File (RW-) >> C:\WINDOWS.0\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202 >> 54: File (RW-) >> C:\WINDOWS.0\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.6195_x-ww_44262b86 >> 70: Section >> \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_K32_0_1c9aa25ea688500_7c80_S-1-5-21-1801674531-1078145449-1957994488-1004 >> 78: File (RWD) >> C:\DOCUME~1\adam\LOCALS~1\Temp\IswTmp\Logs\ISWSHEX.swl >> AC: Section >> \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_A32_0_1c98aa70f70ec00_77dd_S-1-5-21-1801674531-1078145449-1957994488-1004 >> 100: Section >> \BaseNamedObjects\CiceroSharedMemDefaultS-1-5-21-1801674531-1078145449-1957994488-1004 >> 108: File (RW-) D:\downloads\Tera Term Pro\ttpro313\httplog.log >> 120: Section >> \BaseNamedObjects\CTF.TimListCache.FMPDefaultS-1-5-21-1801674531-1078145449-1957994488-1004SFM.DefaultS-1-5-21-1801674531-1078145449-1957994488-1004 >> 128: Section \BaseNamedObjects\ShimSharedMemory >> 138: Section \BaseNamedObjects\MSCTF.Shared.SFM.IAB >> ------------------------------------------------------------------------------ > > For Handle to give a positive result, the TeraTerm program would need to > currently have the serial port open. If you haven't started a terminal > session, > it might not be listed. > > Handle has some kind of filter function, and you can try searching for the > name > of the port that way. > > I don't see anything in that snipping, which looks like a serial port. > > Paul Okay, this time I am sure that serial port COM4 is open and receiving data via telnet.exe (also listed below). >From the output generated by Handle.exe, here's the sections for TeraTerm & Telnet .. ------------------------------------------------------------------------------ ttermpro.exe pid: 3808 VBOX_WINXPPRO\adam (claims to use COM4) C: File (RW-) D:\downloads\Tera Term Pro\ttpro313 2C: Section \BaseNamedObjects\ttset_memfilemap 44: File (RW-) C:\WINDOWS.0\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202 54: File (RW-) C:\WINDOWS.0\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.6195_x-ww_44262b86 70: Section \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_K32_0_1c9aa25ea688500_7c80_S-1-5-21-1801674531-1078145449-1957994488-1004 78: File (RWD) C:\DOCUME~1\adam\LOCALS~1\Temp\IswTmp\Logs\ISWSHEX.swl AC: Section \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_A32_0_1c98aa70f70ec00_77dd_S-1-5-21-1801674531-1078145449-1957994488-1004 100: Section \BaseNamedObjects\CiceroSharedMemDefaultS-1-5-21-1801674531-1078145449-1957994488-1004 108: File (RW-) D:\downloads\Tera Term Pro\ttpro313\httplog.log 120: Section \BaseNamedObjects\CTF.TimListCache.FMPDefaultS-1-5-21-1801674531-1078145449-1957994488-1004SFM.DefaultS-1-5-21-1801674531-1078145449-1957994488-1004 128: Section \BaseNamedObjects\ShimSharedMemory 138: Section \BaseNamedObjects\MSCTF.Shared.SFM.IN 150: Section \BaseNamedObjects\MSCTF.Shared.SFM.IIM ------------------------------------------------------------------------------ telnet.exe pid: 2408 VBOX_WINXPPRO\adam D8: File (RW-) D:\Handle 6EC: Section \BaseNamedObjects\ShimSharedMemory 6F4: Section \BaseNamedObjects\CTF.TimListCache.FMPDefaultS-1-5-21-1801674531-1078145449-1957994488-1004SFM.DefaultS-1-5-21-1801674531-1078145449-1957994488-1004 710: Section \BaseNamedObjects\CiceroSharedMemDefaultS-1-5-21-1801674531-1078145449-1957994488-1004 740: Section \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_A32_0_1c98aa70f70ec00_77dd_S-1-5-21-1801674531-1078145449-1957994488-1004 774: File (RWD) C:\DOCUME~1\adam\LOCALS~1\Temp\IswTmp\Logs\ISWSHEX.swl 77C: Section \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_K32_0_1c9aa25ea688500_7c80_S-1-5-21-1801674531-1078145449-1957994488-1004 798: File (RW-) C:\WINDOWS.0\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.6195_x-ww_44262b86 79C: File (RW-) C:\WINDOWS.0\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202 ------------------------------------------------------------------------------ usage: handle [[-a [-l]] [-u] | [-c [-y]] | [-s]] [-p |] [name] -a Dump all handle information. -l Just show pagefile-backed section handles. -c Closes the specified handle (interpreted as a hexadecimal number). You must specify the process by its PID. WARNING: Closing handles can cause application or system instability. -y Don't prompt for close handle confirmation. -s Print count of each type of handle open. -u Show the owning user name when searching for handles. -p Dump handles belonging to process (partial name accepted). name Search for handles to objects with (fragment accepted). No arguments will dump all file references. Handle type summary: Desktop : 56 Directory : 165 Event : 3470 File : 1463 IoCompletion : 142 Job : 1 Key : 1540 KeyedEvent : 49 Mutant : 632 Port : 566 Process : 221 Section : 373 Semaphore : 1327 SymbolicLink : 2 Thread : 1009 Timer : 46 Token : 93 WaitablePort : 3 WindowStation : 99 WmiGuid : 98 Total handles: 11355 This is a tough one. From tjreedy at udel.edu Wed Jun 27 13:57:43 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Jun 2012 13:57:43 -0400 Subject: json.loads() should return a more specific error In-Reply-To: References: Message-ID: On 6/27/2012 8:45 AM, Roy Smith wrote: > Before I go open an enhancement request, what do people think of the > idea that json.load() should return something more specific than > ValueError? I do not know of any written policy about when to create custom error classes in the stdlib. I know there are some that are just empty catchall renamings. "class ModException(Exception): pass" This does not seem to have much use except your use us scanning logs, and does have some cost. > I've got some code that looks like > > try: > response = requests.get(url) > except RequestException as ex: > logger.exception(ex) > return [] > data = response.text > try: > events = json.loads(data) > except ValueError as ex: > logger.error("%s: %r", ex, data) > return [] You could solve your immediate problem by starting the string with something like 'JSON: '. One might want the url included in the log, which would never be part of an exception from json. Given that data can be arbitrarily long, logging data does not seem like that good an idea. To me, the important question is not the exception name, which you can replace, but whether the message part of the exception gives information about the actual problem. If it just says something redundant and useless like 'bad input', then improving that would be a good enhancement. > This would be so much neater if json would return something I could > identify as a json error. It would all just collapse into: > > try: > events = requests.get(url).json Would not this be events = json.loads(requests.get(url).text) ? Either way, 'events' is the only new binding that persists. > except (RequestException, JSONDecodeError) as ex: Just using ValueError would work if you condition the logging on the value of ex. > logger.exception(ex) This would only be the equivalent of your first code if the arbitrarily large input data were attached to the JSONDecodeError -- and thereby kept alive when it could otherwise be deleted/collected (and the custom class had its own __str__ method). I do not think this a good idea. The exception should only contain extracted bits that show the problem. > return [] > > We could make JSONDecodeError a subclass of ValueError so existing code > would continue to work. Bottom line: I do not think you should expect exception instances to necessarily have all the info you would want logged for reading out of context (as opposed to reading interactively). On the other hand, exceptions should contain specific information about the problem that the raising code knows and that is hard to get otherwise. -- Terry Jan Reedy From nospam at needed.com Wed Jun 27 14:04:17 2012 From: nospam at needed.com (Paul) Date: Wed, 27 Jun 2012 14:04:17 -0400 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help In-Reply-To: References: Message-ID: Adam wrote: > > > This is a tough one. Try handle -a > allhand.txt Then open the allhand.txt with Notepad and look for interesting entries. ******* I tested right now, and first opened a session in HyperTerminal with one of my USB to serial adapters. The second serial adapter, is connect to a UPS, looking for a shutdown message. So the second entry should be present at all times. hypertrm.exe pid: 3452 ... 120: File (---) \Device\VCP1 ups.exe pid: 1568 NT AUTHORITY\SYSTEM ... 98: File (---) \Device\VCP0 I don't have any "serial" entries on this machine. But one of my other machines, has a real COM port on the SuperI/O chip, so the entries for that would involve the word "serial" in some way. The USB ones, at least the ones I've got, say VCP. Possibly because one of the driver files sets up virtual COM ports. There is a control panel for the driver, that maps a virtual COM port, to a COM port number, like COM3 and COM4 in this case. Paul From python at mrabarnett.plus.com Wed Jun 27 14:06:08 2012 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 27 Jun 2012 19:06:08 +0100 Subject: Slow output In-Reply-To: <53d49cb1-a68a-49c4-b925-b8a910ac415a@googlegroups.com> References: <53d49cb1-a68a-49c4-b925-b8a910ac415a@googlegroups.com> Message-ID: <4FEB4B90.6050002@mrabarnett.plus.com> On 27/06/2012 18:33, subhabangalore at gmail.com wrote: > Dear Group, > I am Sri Subhabrata Banerjee writing from India. I am running a small > program which exploits around 12 1 to 2 KB .txt files. I am using MS > Windows XP Service Pack 3 and Python 2.6 where IDLE is GUI. The text > is plain ASCII text. The RAM of the machine is around 2 GB. To run > the program the machine is becoming dead slow and it is executing > only after several minutes. I am shocked as I have run hugely loaded > Statistical Learning stuff only on 516MB RAM on Python using Windows > XP only. And that too on a laptop. I am not getting. I discussed the > issue with my system administrator and he increased the RAM to 8GB > result improved by 30% but not satisfactory speed. May any one > suggest me what may be the likely issue? > Could you post the program here (you say that it's small) so that we can see what you're trying to do. From tjreedy at udel.edu Wed Jun 27 14:06:45 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Jun 2012 14:06:45 -0400 Subject: 2to6 ? In-Reply-To: References: Message-ID: On 6/27/2012 10:36 AM, Thomas Heller wrote: > Is there a tool, similar to 2to3, which converts python2 code > to code using six.py, so that it runs unchanged with python2 > *and* python 3? Others have expressed a similar wish, but I do not know that anyone has actually revised 2to3 to make a 2to6, or how feasible that would be. -- Terry Jan Reedy From lamialily at cleverpun.com Wed Jun 27 14:17:04 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Wed, 27 Jun 2012 11:17:04 -0700 Subject: cmd i/o stream module In-Reply-To: References: Message-ID: [Default] On Wed, 27 Jun 2012 18:37:52 +0530, prakash jp wrote: >Hi All, > >I am interested to interact with the command prompt, is there a module to >control the input/output stream. Thanks in advance for the pointers > >Thanks >Prakash Well, from the start, the sys module gives access to the stdin, stdout, and stderr as file-like objects. I also know that Unix Python users can make use of the curses module. Beyond that, I'm not sure. I'm sure someone more experienced can chip in with specific functionality in Windows, though. ~Temia -- The amazing programming device: fuelled entirely by coffee, it codes while awake and tests while asleep! From hansmu at xs4all.nl Wed Jun 27 14:29:38 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 27 Jun 2012 20:29:38 +0200 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: <2401bda7-46a0-4dcb-93e5-4bd739e729d2@googlegroups.com> References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <4fea0a7b$0$6942$e4fe514c@news2.news.xs4all.nl> <4fea2e26$0$6883$e4fe514c@news2.news.xs4all.nl> <2401bda7-46a0-4dcb-93e5-4bd739e729d2@googlegroups.com> Message-ID: <4feb5112$0$6863$e4fe514c@news2.news.xs4all.nl> On 27/06/12 19:05:44, David Thomas wrote: > Is this why I keep getting an error using launcher? No. Yesterday your problem was that you tried this: input("\n\nPress the enter key to exit") That works fine in Pyhton3, but you are using python2 and in python2, the you must do this instead: raw_input("\n\nPress the enter key to exit") If you still get that error, you can either use "raw_input()" or switch to Python3, where "input" would be correct. If you're learning Python from a tutorial, you should carefully read the first section of the tutorial, where they mention whether the explains pyhton2 or python3, and use a matching Python (or a matching tutorial). If the tutorial doesn't say for which version it is, then it's for pyhton2 (and several years old). > Also to open the script in terminal do I need to put > the following at the beginning of my script: > > #!/bin/python No, that doesn't help. There are at least three pythons on your system, but there isn't one in /bin. There are basically two ways to run a python script in terminal: Method 1: type the word "python", followed by a space and the full path to your script, enclosed in quotes, e.g. python '/Users/dthomaw86/Documents/Python Documents/game_over_enter_key.py' The quotes are necessary, because you have a space character in the path. Method 2: Step 1: put valid a '#!' line at the top of the script, for example: #!/ust/local/bin/python Step 2: in Terminal, go to the folder where the script is: cd '/Users/dthomaw86/Documents/Python Documents' Step 3: make the script "executable" chmod +x game_over_enter_key.py Step 4: you can now run the script with: ./game_over_enter_key.py If you want to run the script again, you only need to repeat step 4. Or use the "up arrow" key in Terminal. I think you should pick one method and stick with it, until you get the hang of Terminal. > On python.org it states to To run your script from the Terminal > window you must make sure that /usr/local/bin is in your shell > search path. The installer for Mac from python.org has installed python2.7 in /Libary/Frameworks/Python.frameworks/Versions/2.7/bin and added that directory to you shell search path. > How can I make sure that the Python I have installed on my Mac > is in my shell search path. > > http://www.freeimagehosting.net/saskk If you look at the screen shot, you'll see that the shell has found python in /Libary/Frameworks/Python.frameworks/Versions/2.7/bin Incidentally, you don't have to upload screenshots from Termimal. You can you just select text in Terminal and use cmd-C to copy it to the clipboard, and then cmd-V to paste it to this forum. This is a text-only forum, but text from Terminal _is_ text, so that's allowed. For example: HansM 4$ cat game_over_enter_key.py raw_input("\n\nPress the enter key to exit") HansM 5$ python game_over_enter_key.py Press the enter key to exit HansM 6$ > Thanks again and I am sorry for all the questions, > I am just getting started on Python That's all right: most people run into this sort of issues when they try their first script. There are usually several ways to do things, and that leads to you getting conflicting advice. Hope this helps, -- HansM From storchaka at gmail.com Wed Jun 27 14:58:53 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 27 Jun 2012 21:58:53 +0300 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <4FEB19F7.6080103@stackless.com> References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> <4FEB077E.1010607@stackless.com> <4FEB19F7.6080103@stackless.com> Message-ID: On 27.06.12 17:34, Christian Tismer wrote: > That's why I was unhappy with py3's missing flexibility. Excessive flexibility is amorphism. From jeanmichel at sequans.com Wed Jun 27 14:59:49 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 27 Jun 2012 20:59:49 +0200 Subject: Slow output In-Reply-To: <4FEB4B90.6050002@mrabarnett.plus.com> References: <53d49cb1-a68a-49c4-b925-b8a910ac415a@googlegroups.com> <4FEB4B90.6050002@mrabarnett.plus.com> Message-ID: <4FEB5825.6060708@sequans.com> MRAB wrote: > On 27/06/2012 18:33, subhabangalore at gmail.com wrote: >> Dear Group, >> I am Sri Subhabrata Banerjee writing from India. I am running a small >> program which exploits around 12 1 to 2 KB .txt files. I am using MS >> Windows XP Service Pack 3 and Python 2.6 where IDLE is GUI. The text >> is plain ASCII text. The RAM of the machine is around 2 GB. To run >> the program the machine is becoming dead slow and it is executing >> only after several minutes. I am shocked as I have run hugely loaded >> Statistical Learning stuff only on 516MB RAM on Python using Windows >> XP only. And that too on a laptop. I am not getting. I discussed the >> issue with my system administrator and he increased the RAM to 8GB >> result improved by 30% but not satisfactory speed. May any one >> suggest me what may be the likely issue? >> > Could you post the program here (you say that it's small) so that we > can see what you're trying to do. Additionaly, you may want to look at http://docs.python.org/library/profile.html You may spot quite quickly where your program is dying. It's worth the try, it's doesn't take long to setup the profile. JM From storchaka at gmail.com Wed Jun 27 15:08:07 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 27 Jun 2012 22:08:07 +0300 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: On 27.06.12 14:22, Stefan Behnel wrote: > For comparison, the revival of the "u" string prefix in Py3.3 is a simple > change in the parser grammar that's easy to maintain but that has a huge > impact on the Py3 compatibility of code that accepts to drop support for > Py2.5 and earlier (as well as Py3.[012]) but wants to keep working in > Py2.[67] (which supports the opposite "b" prefix). And even this simple change has caused unexpected issues (see issues #15054 and #15096), which were not predicted by the preceding stormy discussion. IMHO, the negative consequences of this change are undervalued. From phpyjs at gmail.com Wed Jun 27 15:12:00 2012 From: phpyjs at gmail.com (phpyjs at gmail.com) Date: Wed, 27 Jun 2012 12:12:00 -0700 (PDT) Subject: XPlatform ToolKit Message-ID: EnTK (batteries included) http://stk.phpyjs.com/ntk.zip EsTK (pilas incluidas) http://stk.phpyjs.com/stk.zip Reverse Engineer This From g.rodola at gmail.com Wed Jun 27 15:36:01 2012 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Wed, 27 Jun 2012 21:36:01 +0200 Subject: ANN: psutil 0.5.0 released Message-ID: Hi folks, I'm pleased to announce the 0.5.0 release of psutil: http://code.google.com/p/psutil/ === Major new features === - system users - (Linux, Windows) process CPU affinity (get and set) - (POSIX) process number of opened file descriptors. - (Windows) process number of opened handles. - psutil.disk_partitions() now provides also mount options - new Process.as_dict() method. - Process.get_children(recursive=True): return all process descendants. - 2to3 is not longer required to run at installation time in order to support Python 3 - ppid, name, exe, cmdline and create_time properties of Process class are now cached after being accessed. - psutil.process_iter() now caches Process instances between calls. For a complete list of features and bug fixes see: http://psutil.googlecode.com/svn/trunk/HISTORY === New features by example === >>> import psutil, os >>> >>> psutil.get_users() [user(name='giampaolo', terminal='pts/2', host='localhost', started=1340737536.0), user(name='giampaolo', terminal='pts/3', host='localhost', started=1340737792.0)] >>> >>> psutil.disk_partitions() [partition(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'), partition(device='/dev/sda2', mountpoint='/home', fstype='ext, opts='rw')] >>> >>> p = psutil.Process(os.getpid()) >>> p.get_num_fds() 4 >>> >>> p.get_num_handles() # windows only 254 >>> >>> p.get_memory_maps() [mmap(path='/lib/x86_64-linux-gnu/libutil-2.15.so', rss=16384, anonymous=8192, swap=0), mmap(path='/lib/x86_64-linux-gnu/libc-2.15.so', rss=6384, anonymous=15, swap=0), mmap(path='/lib/x86_64-linux-gnu/libcrypto.so.1.0.0', rss=34124, anonymous=1245, swap=0), mmap(path='[heap]', rss=54653, anonymous=8192, swap=0), mmap(path='[stack]', rss=1542, anonymous=166, swap=0), ...] >>> >>> p.as_dict() {'status': 0, 'pid': 29510, 'connections': [], 'cmdline': ['python'], ...} >>> >>> p.get_cpu_affinity() [0, 1, 2, 3] >>> p.set_cpu_affinity([0]) >>> >>> p.get_children(recursive=True) [, , ...] >>> === Links === * Home page: http://code.google.com/p/psutil * Source tarball: http://psutil.googlecode.com/files/psutil-0.5.0.tar.gz * Api Reference: http://code.google.com/p/psutil/wiki/Documentation Please try out this new release and let me know if you experience any problem by filing issues on the bug tracker. Thanks in advance. --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ From wxjmfauth at gmail.com Wed Jun 27 15:49:16 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 27 Jun 2012 12:49:16 -0700 (PDT) Subject: =?ISO-8859-1?Q?Py330b1=2C_un_caf=E9_cr=E8me_sucr=E9?= Message-ID: <2ab28feb-71ed-44ec-a0e2-7258ef545e27@googlegroups.com> # -*- coding: cp1252 -*- # caf?.py import sys print(sys.version) sys.path.append('d:\\cr?me') import cr?me import sucr? s = ' '.join(['un', 'caf?', cr?me.tag, sucr?.tag]) print(s) input(':') #------ # .\sucr?.py: # -*- coding: cp1252 -*- #tag = 'sucr?' #------ # d:\cr?me\cr?me.py # -*- coding: cp1252 -*- #tag = 'cr?me' # output # 3.3.0b1 (v3.3.0b1:e15c554cd43e+, Jun 26 2012, 20:30:00) [MSC v.1600 32 bit (Intel)] # un caf? cr?me sucr? # : # :-) From steve+comp.lang.python at pearwood.info Wed Jun 27 16:27:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Jun 2012 20:27:47 GMT Subject: Slow output References: <53d49cb1-a68a-49c4-b925-b8a910ac415a@googlegroups.com> Message-ID: <4feb6cc2$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Jun 2012 19:06:08 +0100, MRAB wrote: > On 27/06/2012 18:33, subhabangalore at gmail.com wrote: >> Dear Group, >> I am Sri Subhabrata Banerjee writing from India. I am running a small >> program which exploits around 12 1 to 2 KB .txt files. I am using MS >> Windows XP Service Pack 3 and Python 2.6 where IDLE is GUI. The text is >> plain ASCII text. The RAM of the machine is around 2 GB. To run the >> program the machine is becoming dead slow and it is executing only >> after several minutes. [...] > Could you post the program here (you say that it's small) so that we can > see what you're trying to do. I bet that he is building up long strings using repeated string concatenation: s = '' for item in many_items: s += item instead of accumulating them into a list, then joining them all at once. Repeated string concatenation can be *painfully* slow, especially under Windows. (For some reason, the details of Windows memory management sometimes prevents the string concat optimization from working.) -- Steven From adam at no_thanks.com Wed Jun 27 16:40:19 2012 From: adam at no_thanks.com (Adam) Date: Wed, 27 Jun 2012 13:40:19 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: "Paul" wrote in message news:jsfhv2$ta9$1 at dont-email.me... > Adam wrote: > >> >> This is a tough one. > > Try > > handle -a > allhand.txt > > Then open the allhand.txt with Notepad and look for interesting entries. > > ******* > > I tested right now, and first opened a session in HyperTerminal with one > of my USB to serial adapters. The second serial adapter, is connect to a > UPS, looking for a shutdown message. So the second entry should be present > at all times. > > hypertrm.exe pid: 3452 > ... > 120: File (---) \Device\VCP1 > > > ups.exe pid: 1568 NT AUTHORITY\SYSTEM > ... > 98: File (---) \Device\VCP0 > > I don't have any "serial" entries on this machine. But one of > my other machines, has a real COM port on the SuperI/O chip, > so the entries for that would involve the word "serial" in some > way. The USB ones, at least the ones I've got, say VCP. Possibly > because one of the driver files sets up virtual COM ports. There > is a control panel for the driver, that maps a virtual COM port, > to a COM port number, like COM3 and COM4 in this case. > > Paul Thanks (Guru Paul), you're the best. I think we may have something this time ... 144: File (---) \Device\ProlificSerial3 And, TeraTerm (using COM4) is open and receiving data wirelessly. >From the output generated by "handle -a", here's the section for TeraTerm ... ------------------------------------------------------------------------------ ttermpro.exe pid: 3648 VBOX_WINXPPRO\adam (claims to use COM4) 4: KeyedEvent \KernelObjects\CritSecOutOfMemoryEvent 8: Directory \KnownDlls C: File (RW-) D:\downloads\Tera Term Pro\ttpro313 10: Event 14: Directory \Windows 18: Port 1C: WindowStation \Windows\WindowStations\WinSta0 20: Desktop \Default 24: WindowStation \Windows\WindowStations\WinSta0 28: Directory \BaseNamedObjects 2C: Section \BaseNamedObjects\ttset_memfilemap 30: Semaphore 34: Semaphore 38: Key HKLM 3C: Event 40: Semaphore \BaseNamedObjects\shell.{A48F1A32-A340-11D1-BC6B-00A0C90312E1} 44: File (RW-) C:\WINDOWS.0\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202 48: File (---) \Device\KsecDD 4C: Key HKCU 50: Key HKCU\CLSID 54: File (RW-) C:\WINDOWS.0\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.6195_x-ww_44262b86 58: Mutant 5C: Event \BaseNamedObjects\crypt32LogoffEvent 60: Event 64: Mutant 68: Event 6C: Event 70: Section \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_K32_0_1c9aa25ea688500_7c80_S-1-5-21-1801674531-1078145449-1957994488-1004 74: Event 78: File (RWD) C:\DOCUME~1\adam\LOCALS~1\Temp\IswTmp\Logs\ISWSHEX.swl 7C: Semaphore 80: Semaphore 84: Semaphore 88: Semaphore 8C: Semaphore 90: Semaphore 94: Semaphore 98: Semaphore 9C: Semaphore A0: Semaphore A4: Semaphore A8: Semaphore AC: Section \BaseNamedObjects\_ISWINTERNAL_EPT32_SHEX_A32_0_1c98aa70f70ec00_77dd_S-1-5-21-1801674531-1078145449-1957994488-1004 B0: Port B4: Section B8: Key HKCU BC: Mutant \BaseNamedObjects\CTF.LBES.MutexDefaultS-1-5-21-1801674531-1078145449-1957994488-1004 C0: File (---) \Device\Tcp C4: File (---) \Device\Tcp C8: File (---) \Device\Ip CC: File (---) \Device\Ip D0: File (---) \Device\Ip D4: Semaphore D8: Semaphore DC: Key HKLM\SYSTEM\ControlSet001\Services\Tcpip\Linkage E0: Key HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters E4: Key HKLM\SYSTEM\ControlSet001\Services\NetBT\Parameters\Interfaces E8: Key HKLM\SYSTEM\ControlSet001\Services\NetBT\Parameters EC: Thread ttermpro.exe(3648): 3684 F0: Event F4: Key HKLM\SYSTEM\ControlSet001\Services\WinSock2\Parameters\Protocol_Catalog9 F8: Event FC: Key HKLM\SYSTEM\ControlSet001\Services\WinSock2\Parameters\NameSpace_Catalog5 100: Section \BaseNamedObjects\CiceroSharedMemDefaultS-1-5-21-1801674531-1078145449-1957994488-1004 104: Key HKLM\SOFTWARE\Microsoft\SystemCertificates\My 108: File (RW-) D:\downloads\Tera Term Pro\ttpro313\httplog.log 10C: Mutant \BaseNamedObjects\CTF.Compart.MutexDefaultS-1-5-21-1801674531-1078145449-1957994488-1004 110: Mutant \BaseNamedObjects\CTF.Asm.MutexDefaultS-1-5-21-1801674531-1078145449-1957994488-1004 114: Mutant \BaseNamedObjects\CTF.Layouts.MutexDefaultS-1-5-21-1801674531-1078145449-1957994488-1004 118: Mutant \BaseNamedObjects\CTF.TMD.MutexDefaultS-1-5-21-1801674531-1078145449-1957994488-1004 11C: Mutant \BaseNamedObjects\CTF.TimListCache.FMPDefaultS-1-5-21-1801674531-1078145449-1957994488-1004MUTEX.DefaultS-1-5-21-1801674531-1078145449-1957994488-1004 120: Section \BaseNamedObjects\CTF.TimListCache.FMPDefaultS-1-5-21-1801674531-1078145449-1957994488-1004SFM.DefaultS-1-5-21-1801674531-1078145449-1957994488-1004 124: Mutant \BaseNamedObjects\ShimCacheMutex 128: Section \BaseNamedObjects\ShimSharedMemory 12C: Mutant \BaseNamedObjects\MSCTF.Shared.MUTEX.IN 130: Event \BaseNamedObjects\ReadEnd4 134: Event 138: Section \BaseNamedObjects\MSCTF.Shared.SFM.IN 13C: Event \BaseNamedObjects\Write4 140: Event \BaseNamedObjects\ReadEnd4 144: File (---) \Device\ProlificSerial3 148: Event \BaseNamedObjects\Read4 14C: Thread ttermpro.exe(3648): 272 150: Section \BaseNamedObjects\MSCTF.Shared.SFM.EGO 154: Event 158: Mutant \BaseNamedObjects\MSCTF.Shared.MUTEX.EGO ------------------------------------------------------------------------------ The Python script needed a call to ser.close() before ser.open() in order to work. Yes, that's right ... things are working fine now. :-) From dthomas86 at me.com Wed Jun 27 16:45:47 2012 From: dthomas86 at me.com (David Thomas) Date: Wed, 27 Jun 2012 13:45:47 -0700 (PDT) Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: <4feb5112$0$6863$e4fe514c@news2.news.xs4all.nl> References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <4fea0a7b$0$6942$e4fe514c@news2.news.xs4all.nl> <4fea2e26$0$6883$e4fe514c@news2.news.xs4all.nl> <2401bda7-46a0-4dcb-93e5-4bd739e729d2@googlegroups.com> <4feb5112$0$6863$e4fe514c@news2.news.xs4all.nl> Message-ID: Thank you ever so much raw_input works fine. Do you think I should stick with Python 2 before I go to 3? I have a text book which is using 3 but I've been using an online tutorial which has been helping me lots, which uses version 2. I found by just typing python then having a space and dragging the file from finder into terminal works. From kliateni at gmail.com Wed Jun 27 16:48:37 2012 From: kliateni at gmail.com (Karim) Date: Wed, 27 Jun 2012 22:48:37 +0200 Subject: Py330b1, un =?ISO-8859-1?Q?caf=E9_cr=E8me_sucr=E9?= In-Reply-To: <2ab28feb-71ed-44ec-a0e2-7258ef545e27@googlegroups.com> References: <2ab28feb-71ed-44ec-a0e2-7258ef545e27@googlegroups.com> Message-ID: <4FEB71A5.4060105@gmail.com> Euhhh, j'ai pas tout suivi. C'est quoi la feinte? Cheers Karim Le 27/06/2012 21:49, wxjmfauth at gmail.com a ?crit : > # -*- coding: cp1252 -*- > # caf?.py > > import sys > print(sys.version) > > sys.path.append('d:\\cr?me') > import cr?me > import sucr? > > s = ' '.join(['un', 'caf?', cr?me.tag, sucr?.tag]) > print(s) > > input(':') > > #------ > # .\sucr?.py: > # -*- coding: cp1252 -*- > #tag = 'sucr?' > > #------ > # d:\cr?me\cr?me.py > # -*- coding: cp1252 -*- > #tag = 'cr?me' > > > > # output > # 3.3.0b1 (v3.3.0b1:e15c554cd43e+, Jun 26 2012, 20:30:00) [MSC v.1600 32 bit (Intel)] > # un caf? cr?me sucr? > # : > > # :-) From dthomas86 at me.com Wed Jun 27 17:00:03 2012 From: dthomas86 at me.com (David Thomas) Date: Wed, 27 Jun 2012 14:00:03 -0700 (PDT) Subject: Recommend decent Computer Science books Message-ID: <30276019-dadf-4857-96b0-c3b9aaf6da1d@googlegroups.com> Hi I know that this is a group about Python. But I am just wondering if anybody can recommend any introductory/good books on Conputer Science. Kind regards From jason.swails at gmail.com Wed Jun 27 17:02:31 2012 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 27 Jun 2012 17:02:31 -0400 Subject: question about numpy, subclassing, and a DeprecationWarning Message-ID: Hello, I'm running into an unexpected issue in a program I'm writing, and I was hoping someone could provide some clarification for me. I'm trying to subclass numpy.ndarray (basically create a class to handle a 3D grid). When I instantiate a numpy.ndarray, everything works as expected. When I call numpy.ndarray's constructor directly within my subclass, I get a deprecation warning about object.__init__ not taking arguments. Presumably this means that ndarray's __init__ is somehow (for some reason?) calling object's __init__... This is some sample code: >>> import numpy as np >>> class derived(np.ndarray): ... def __init__(self, stuff): ... np.ndarray.__init__(self, stuff) ... >>> l = derived((2,3)) __main__:3: DeprecationWarning: object.__init__() takes no parameters >>> l derived([[ 8.87744455e+159, 6.42896975e-109, 5.56218818e+180], [ 1.79996515e+219, 2.41625066e+198, 5.15855295e+307]]) >>> Am I doing something blatantly stupid? Is there a better way of going about this? I suppose I could create a normal class and just put the grid points in a ndarray as an attribute to the class, but I would rather subclass ndarray directly (not sure I have a good reason for it, though). Suggestions on what I should do? Thanks! Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jun 27 17:14:42 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Jun 2012 17:14:42 -0400 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: On 6/27/2012 3:08 PM, Serhiy Storchaka wrote: > On 27.06.12 14:22, Stefan Behnel wrote: >> For comparison, the revival of the "u" string prefix in Py3.3 is a simple >> change in the parser grammar that's easy to maintain > And even this simple change has caused unexpected issues (see issues > #15054 and #15096), which were not predicted by the preceding stormy > discussion. #15054 was mostly not about 'u'. http://bugs.python.org/issue15096 is about 'u', or rather about the post discussion extension of 'u' to 'ur'. During the discussion of 'u', I predicted that adding 'innocuous' 'u' would lead to efforts to add other things. Adding 'ur' was the first example of that. We are fortunate that someone decided to test the new feature at the alpha stage. At least the near fiasco is a lesson. > IMHO, the negative consequences of this change are undervalued. Another prediction: people who code Python without reading the manual, at least not for new features, will learn about 'u' somehow (such as by reading this list) and may do either of the following, both of which are bad. 1. They will confuse themselves by thinking that 'u' actually means somethings. They may then confuse others by writing about its supposed meaning. This might get amusing. 2. They will use 'u' in Python 3 only code, thereby making it incompatible with 3.2-, even if it otherwise would not be. These two actions will reinforce each other. -- Terry Jan Reedy From invalid at invalid.invalid Wed Jun 27 17:18:09 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 27 Jun 2012 21:18:09 +0000 (UTC) Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: On 2012-06-27, Adam wrote: > The Python script needed a call to ser.close() before ser.open() in > order to work. IOW, the port opened OK, but when you tried to open it a second time without closing it first, _that's_ when the .open() call failed. That's a restriction built in to Win32. You can't open a serial port that's already open. [Linux doesn't have that restriction.] Why do you need to open it a second time? -- Grant Edwards grant.b.edwards Yow! Send your questions to at ``ASK ZIPPY'', Box 40474, gmail.com San Francisco, CA 94140, USA From hansmu at xs4all.nl Wed Jun 27 17:33:39 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 27 Jun 2012 23:33:39 +0200 Subject: Executing Python Scripts on Mac using Python Launcher In-Reply-To: References: <8b352333-23b5-4cfb-843d-29ffe1ef0905@googlegroups.com> <4fea0a7b$0$6942$e4fe514c@news2.news.xs4all.nl> <4fea2e26$0$6883$e4fe514c@news2.news.xs4all.nl> <2401bda7-46a0-4dcb-93e5-4bd739e729d2@googlegroups.com> <4feb5112$0$6863$e4fe514c@news2.news.xs4all.nl> Message-ID: <4feb7c33$0$6894$e4fe514c@news2.news.xs4all.nl> On 27/06/12 22:45:47, David Thomas wrote: > Thank you ever so much raw_input works fine. > Do you think I should stick with Python 2 before I go to 3? I think so. The differences are not that big, but big enough to confuse a beginner. Once you know pyhton2, read http://docs.python.org/py3k/whatsnew/3.0.html That's the official overview of what has changed between python2 and python3. > I have a text book which is using 3 but I've been using an > online tutorial which has been helping me lots, which uses > version 2. If you decide to use the book, you'll want to install Python3 on your Mac. If you do that, you'll find that typing "python" in Terminal still gets you python2.7; you have to type "pyhton3" to get python3. > I found by just typing python then having a space and > dragging the file from finder into terminal works. I just tried it, and it works. Terminal uses backslashes to protect characters that need quoting in the shell. I'd use single quotes myself, but this also works. -- HansM From adam at no_thanks.com Wed Jun 27 17:48:44 2012 From: adam at no_thanks.com (Adam) Date: Wed, 27 Jun 2012 14:48:44 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: "Grant Edwards" wrote in message news:jsftah$bb5$1 at reader1.panix.com... > On 2012-06-27, Adam wrote: > >> The Python script needed a call to ser.close() before ser.open() in >> order to work. > > IOW, the port opened OK, but when you tried to open it a second time > without closing it first, _that's_ when the .open() call failed. > > That's a restriction built in to Win32. You can't open a serial port > that's already open. [Linux doesn't have that restriction.] > > Why do you need to open it a second time? > > -- > Grant Edwards grant.b.edwards Yow! Send your > questions to > at ``ASK ZIPPY'', Box > 40474, > gmail.com San Francisco, CA 94140, > USA As far as I can tell, the wireless hardware connected to the USB-to-serial converter is receiving data (which may have the serial port open?). I can see the data being received in TeraTerm (using COM4). After closing TeraTerm, I start up the Python script and get the following error message ... C:\Wattcher>python wattcher.py Traceback (most recent call last): File "wattcher.py", line 56, in ser.open() File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, in open raise SerialException("could not open port %s: %s" % (self.portstr, ctypes.WinError())) serial.serialutil.SerialException: could not open port COM4: [Error 5] Access is denied. Searching for similar encounters of this error message, some people said that calling ser.close() before ser.open() solved the problem. And, it worked for me as well. Is this considered a chicken & egg situation? From robert.kern at gmail.com Wed Jun 27 17:57:39 2012 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 27 Jun 2012 22:57:39 +0100 Subject: question about numpy, subclassing, and a DeprecationWarning In-Reply-To: References: Message-ID: On 6/27/12 10:02 PM, Jason Swails wrote: > Hello, > > I'm running into an unexpected issue in a program I'm writing, and I was hoping > someone could provide some clarification for me. I'm trying to subclass > numpy.ndarray (basically create a class to handle a 3D grid). When I > instantiate a numpy.ndarray, everything works as expected. When I call > numpy.ndarray's constructor directly within my subclass, I get a deprecation > warning about object.__init__ not taking arguments. Presumably this means that > ndarray's __init__ is somehow (for some reason?) calling object's __init__... > > This is some sample code: > > >>> import numpy as np > >>> class derived(np.ndarray): > ... def __init__(self, stuff): > ... np.ndarray.__init__(self, stuff) > ... > >>> l = derived((2,3)) > __main__:3: DeprecationWarning: object.__init__() takes no parameters > >>> l > derived([[ 8.87744455e+159, 6.42896975e-109, 5.56218818e+180], > [ 1.79996515e+219, 2.41625066e+198, 5.15855295e+307]]) > >>> > > Am I doing something blatantly stupid? Is there a better way of going about > this? I suppose I could create a normal class and just put the grid points in a > ndarray as an attribute to the class, but I would rather subclass ndarray > directly (not sure I have a good reason for it, though). Suggestions on what I > should do? numpy.ndarray does not have its own __init__(), just a __new__(). It's __init__() is the same as object.__init__(), which takes no arguments. [~] |3> np.ndarray.__init__ is object.__init__ True There is no need to call np.ndarray.__init__() explicitly. http://docs.scipy.org/doc/numpy/user/basics.subclassing.html#a-brief-python-primer-on-new-and-init You will also want to ask numpy questions on the numpy mailing list. http://www.scipy.org/Mailing_Lists Personally, I recommend not subclassing ndarray at all. It rarely works out well. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From invalid at invalid.invalid Wed Jun 27 18:06:54 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 27 Jun 2012 22:06:54 +0000 (UTC) Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: On 2012-06-27, Adam wrote: > "Grant Edwards" wrote: >> On 2012-06-27, Adam wrote: >> >>> The Python script needed a call to ser.close() before ser.open() in >>> order to work. >> >> IOW, the port opened OK, but when you tried to open it a second time >> without closing it first, _that's_ when the .open() call failed. >> >> That's a restriction built in to Win32. You can't open a serial port >> that's already open. [Linux doesn't have that restriction.] >> >> Why do you need to open it a second time? > > As far as I can tell, the wireless hardware connected to the > USB-to-serial converter is receiving data (which may have the serial > port open?). I can see the data being received in TeraTerm (using > COM4). After closing TeraTerm, I start up the Python script and get > the following error message ... > > C:\Wattcher>python wattcher.py > Traceback (most recent call last): > File "wattcher.py", line 56, in > ser.open() > File "C:\Python25\Lib\site-packages\serial\serialwin32.py", line 56, in > open > raise SerialException("could not open port %s: %s" % (self.portstr, > ctypes.WinError())) > serial.serialutil.SerialException: could not open port COM4: [Error 5] > Access is denied. > > > Searching for similar encounters of this error message, some people > said that calling ser.close() before ser.open() solved the problem. > And, it worked for me as well. > > Is this considered a chicken & egg situation? Can you post a small example showing what you're doing? If you're getting that error (and calling ser.close() makes that error go away), then it's because you're trying to re-open a port that you already have open. What happens if you just get rid of both the ser.close() and ser.open() calls? IOW, the port is apparently already open -- why do you want to close() and then re-open() it? -- Grant Edwards grant.b.edwards Yow! I wonder if I should at put myself in ESCROW!! gmail.com From tismer at stackless.com Wed Jun 27 18:11:05 2012 From: tismer at stackless.com (Christian Tismer) Date: Thu, 28 Jun 2012 00:11:05 +0200 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> <4FEB077E.1010607@stackless.com> <4FEB19F7.6080103@stackless.com> Message-ID: <4FEB84F9.9080501@stackless.com> On 6/27/12 8:58 PM, Serhiy Storchaka wrote: > On 27.06.12 17:34, Christian Tismer wrote: >> That's why I was unhappy with py3's missing flexibility. > > Excessive flexibility is amorphism. > Random notes without context and reasoning are no better than spam. My answer as well, of course, so let's stop here. -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From breamoreboy at yahoo.co.uk Wed Jun 27 18:14:13 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 27 Jun 2012 23:14:13 +0100 Subject: XPlatform ToolKit In-Reply-To: References: Message-ID: On 27/06/2012 20:12, phpyjs at gmail.com wrote: > EnTK (batteries included) http://stk.phpyjs.com/ntk.zip > EsTK (pilas incluidas) http://stk.phpyjs.com/stk.zip > > Reverse Engineer This > sihT -- Cheers. Mark Lawrence. From invalid at invalid.invalid Wed Jun 27 18:18:59 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 27 Jun 2012 22:18:59 +0000 (UTC) Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: On 2012-06-27, Grant Edwards wrote: > On 2012-06-27, Adam wrote: >> "Grant Edwards" wrote: >>> Why do you need to open it a second time? >> >> As far as I can tell, the wireless hardware connected to the >> USB-to-serial converter is receiving data (which may have the serial >> port open?). I can see the data being received in TeraTerm (using >> COM4). After closing TeraTerm, I start up the Python script and get >> the following error message ... [...] >> Searching for similar encounters of this error message, some people >> said that calling ser.close() before ser.open() solved the problem. >> And, it worked for me as well. >> >> Is this considered a chicken & egg situation? > > Can you post a small example showing what you're doing? The best way to get help is to write as small a program as possible that demonstrates the problem, and post it. I'll help you get started... Does this program work? import serial ser = serial.Serial("COM4") ser.close() At the moment, I don't have access to a Windows machine, but I think the above should run without any errors. If it works, then you've successfully opened and closed the COM4 port. Start adding "features", in increments as small as possible, until the program fails. Then try to remove stuff that's not needed while still keeping the failure. IOW, try to find the smallest possible program that fails. Usually, in the process of doing that, you'll figure out what you were doing wrong. If not, post the smallest failing program you can come up with, and somebody will be able to help. If you won't show us what you're doing, we can't tell you what you're doing wrong. -- Grant Edwards grant.b.edwards Yow! Gee, I feel kind of at LIGHT in the head now, gmail.com knowing I can't make my satellite dish PAYMENTS! From iconoclast011 at gmail.com Wed Jun 27 18:21:13 2012 From: iconoclast011 at gmail.com (iconoclast011) Date: Wed, 27 Jun 2012 17:21:13 -0500 Subject: Question:Programming a game grid ... Message-ID: Fairly new to Python ... Is there a way to efficiently (different from my brute force code shown below) to set up a game grid of buttons (ie with pygame) responding to mouse clicks ? I would want to vary the size of the grid ... Thanks Brute force code: from Tkinter import * root = Tk() f = Frame(root, bg = "blue", width = 500, height = 500) f.pack(side=LEFT, expand = 1) f3 = Frame(f, bg = "white", width = 500) f3.pack(side=LEFT, expand = 1, pady = 50, padx = 50) #f2 = Frame(root, bg = "black", height=100, width = 100) #f2.pack(side=LEFT, fill = Y) #b = Button(f2, text = "test") #b.pack() var = 'b00' vars()[var] = Button(f3, text = "00", bg = "white") b00.grid(row=0, column=0) b00.bind('', leftclick) # bind left mouse click b00.bind('', rightclick) # bind left mouse click var = 'b01' vars()[var] = Button(f3, text = "01", bg = "white") b01.grid(row=0, column=1) b01.bind('', leftclick) # bind left mouse click b01.bind('', rightclick) # bind left mouse click b02 = Button(f3, text = "02", bg = "white") b02.grid(row=0, column=2) b02.bind('', leftclick) # bind left mouse click b02.bind('', rightclick) # bind left mouse click b03 = Button(f3, text = "03", bg = "white") b03.grid(row=0, column=3) b03.bind('', leftclick) # bind left mouse click b03.bind('', rightclick) # bind left mouse click b04 = Button(f3, text = "04", bg = "white") b04.grid(row=0, column=4) b04.bind('', leftclick) # bind left mouse click b04.bind('', rightclick) # bind left mouse click b05 = Button(f3, text = "05", bg = "white") b05.grid(row=0, column=5) b05.bind('', leftclick) # bind left mouse click b05.bind('', rightclick) # bind left mouse click b06 = Button(f3, text = "06", bg = "white") b06.grid(row=0, column=6) b07 = Button(f3, text = "07", bg = "white") b07.grid(row=0, column=7) b08 = Button(f3, text = "08", bg = "white") b08.grid(row=0, column=8) b10 = Button(f3, text = "10", bg = "white") b10.grid(row=1, column=0) b11 = Button(f3, text = "11", bg = "white") b11.grid(row=1, column=1) b12 = Button(f3, text = "12", bg = "white") b12.grid(row=1, column=2) b13 = Button(f3, text = "13", bg = "white") b13.grid(row=1, column=3) b14 = Button(f3, text = "14", bg = "white") b14.grid(row=1, column=4) b15 = Button(f3, text = "15", bg = "white") b15.grid(row=1, column=5) b16 = Button(f3, text = "16", bg = "white") b16.grid(row=1, column=6) b17 = Button(f3, text = "17", bg = "white") b17.grid(row=1, column=7) b18 = Button(f3, text = "18", bg = "white") b18.grid(row=1, column=8) b20 = Button(f3, text = "20", bg = "white") b20.grid(row=2, column=0) b21 = Button(f3, text = "21", bg = "white") b21.grid(row=2, column=1) b22 = Button(f3, text = "22", bg = "white") b22.grid(row=2, column=2) b23 = Button(f3, text = "23", bg = "white") b23.grid(row=2, column=3) b24 = Button(f3, text = "24", bg = "white") b24.grid(row=2, column=4) b25 = Button(f3, text = "25", bg = "white") b25.grid(row=2, column=5) b26 = Button(f3, text = "26", bg = "white") b26.grid(row=2, column=6) b27 = Button(f3, text = "27", bg = "white") b27.grid(row=2, column=7) b28 = Button(f3, text = "28", bg = "white") b28.grid(row=2, column=8) b30 = Button(f3, text = "30", bg = "white") b30.grid(row=3, column=0) b31 = Button(f3, text = "31", bg = "white") b31.grid(row=3, column=1) b32 = Button(f3, text = "32", bg = "white") b32.grid(row=3, column=2) b36 = Button(f3, text = "36", bg = "white") b36.grid(row=3, column=6) b37 = Button(f3, text = "37", bg = "white") b37.grid(row=3, column=7) b38 = Button(f3, text = "38", bg = "white") b38.grid(row=3, column=8) b33 = Button(f3, text = "33", bg = "white") b33.grid(row=3, column=3) b34 = Button(f3, text = "34", bg = "white") b34.grid(row=3, column=4) b35 = Button(f3, text = "35", bg = "white") b35.grid(row=3, column=5) b40 = Button(f3, text = "40", bg = "white") b40.grid(row=4, column=0) b41 = Button(f3, text = "41", bg = "white") b41.grid(row=4, column=1) b42 = Button(f3, text = "42", bg = "white") b42.grid(row=4, column=2) b43 = Button(f3, text = "43", bg = "white") b43.grid(row=4, column=3) b44 = Button(f3, text = "44", bg = "white") b44.grid(row=4, column=4) b45 = Button(f3, text = "45", bg = "white") b45.grid(row=4, column=5) b46 = Button(f3, text = "46", bg = "white") b46.grid(row=4, column=6) b47 = Button(f3, text = "47", bg = "white") b47.grid(row=4, column=7) b48 = Button(f3, text = "48", bg = "white") b48.grid(row=4, column=8) b50 = Button(f3, text = "50", bg = "white") b50.grid(row=5, column=0) b51 = Button(f3, text = "51", bg = "white") b51.grid(row=5, column=1) b52 = Button(f3, text = "52", bg = "white") b52.grid(row=5, column=2) b53 = Button(f3, text = "53", bg = "white") b53.grid(row=5, column=3) b54 = Button(f3, text = "54", bg = "white") b54.grid(row=5, column=4) b55 = Button(f3, text = "55", bg = "white") b55.grid(row=5, column=5) b56 = Button(f3, text = "56", bg = "white") b56.grid(row=5, column=6) b57 = Button(f3, text = "57", bg = "white") b57.grid(row=5, column=7) b58 = Button(f3, text = "58", bg = "white") b58.grid(row=5, column=8) b60 = Button(f3, text = "60", bg = "white") b60.grid(row=6, column=0) b61 = Button(f3, text = "61", bg = "white") b61.grid(row=6, column=1) b62 = Button(f3, text = "62", bg = "white") b62.grid(row=6, column=2) b63 = Button(f3, text = "63", bg = "white") b63.grid(row=6, column=3) b64 = Button(f3, text = "64", bg = "white") b64.grid(row=6, column=4) b65 = Button(f3, text = "65", bg = "white") b65.grid(row=6, column=5) b66 = Button(f3, text = "66", bg = "white") b66.grid(row=6, column=6) b67 = Button(f3, text = "67", bg = "white") b67.grid(row=6, column=7) b68 = Button(f3, text = "68", bg = "white") b68.grid(row=6, column=8) b70 = Button(f3, text = "70", bg = "white") b70.grid(row=7, column=0) b71 = Button(f3, text = "71", bg = "white") b71.grid(row=7, column=1) b72 = Button(f3, text = "72", bg = "white") b72.grid(row=7, column=2) b73 = Button(f3, text = "73", bg = "white") b73.grid(row=7, column=3) b74 = Button(f3, text = "74", bg = "white") b74.grid(row=7, column=4) b75 = Button(f3, text = "75", bg = "white") b75.grid(row=7, column=5) b76 = Button(f3, text = "76", bg = "white") b76.grid(row=7, column=6) b77 = Button(f3, text = "77", bg = "white") b77.grid(row=7, column=7) b78 = Button(f3, text = "78", bg = "white") b78.grid(row=7, column=8) b80 = Button(f3, text = "80", bg = "white") b80.grid(row=8, column=0) b81 = Button(f3, text = "81", bg = "white") b81.grid(row=8, column=1) b82 = Button(f3, text = "82", bg = "white") b82.grid(row=8, column=2) b83 = Button(f3, text = "83", bg = "white") b83.grid(row=8, column=3) b84 = Button(f3, text = "84", bg = "white") b84.grid(row=8, column=4) b85 = Button(f3, text = "85", bg = "white") b85.grid(row=8, column=5) b86 = Button(f3, text = "86", bg = "white") b86.grid(row=8, column=6) b87 = Button(f3, text = "87", bg = "white") b87.grid(row=8, column=7) b88 = Button(f3, text = "88", bg = "white") b88.grid(row=8, column=8) b88.bind('', leftclick) # bind left mouse click b88.bind('', rightclick) # bind left mouse click #b86.configure(text = "X") b86.configure(bg = "black") b86.configure(fg = "white") root.title('Puzzle Grid') root.mainloop() -- --------------------------------- --- -- - Posted with NewsLeecher v5.0 Beta 15 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From lamialily at cleverpun.com Wed Jun 27 18:26:46 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Wed, 27 Jun 2012 15:26:46 -0700 Subject: XPlatform ToolKit References: Message-ID: <842nu7ppq2nqfsi29jbfif4pfi49q3p3is@4ax.com> On Wed, 27 Jun 2012 23:14:13 +0100, Mark Lawrence wrote: >On 27/06/2012 20:12, phpyjs at gmail.com wrote: >> EnTK (batteries included) http://stk.phpyjs.com/ntk.zip >> EsTK (pilas incluidas) http://stk.phpyjs.com/stk.zip >> >> Reverse Engineer This >> > >sihT No no no, clearly it's sihT reenignE. ~Temia -- The amazing programming device: fuelled entirely by coffee, it codes while awake and tests while asleep! From g.starck at gmail.com Wed Jun 27 18:29:43 2012 From: g.starck at gmail.com (gst) Date: Wed, 27 Jun 2012 15:29:43 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Py330b1=2C_un_caf=E9_cr=E8me_sucr=E9?= References: <2ab28feb-71ed-44ec-a0e2-7258ef545e27@googlegroups.com> Message-ID: On 27 juin, 22:48, Karim wrote: > > Euhhh, j'ai pas tout suivi. C'est quoi la feinte? > Perso je suis pas s?r qu'il y en ait une. Je dirais que l'OP a peut-?tre eu un grand besoin de caf? cr?me sucr? et a voulu partager son plaisir avec d'autres, why not ;) regards, gst. > > Le 27/06/2012 21:49, wxjmfa... at gmail.com a ?crit : > > > > > > > > > # -*- coding: cp1252 -*- > > # caf?.py > > > import sys > > print(sys.version) > > > sys.path.append('d:\\cr?me') > > import cr?me > > import sucr? > > > s = ' '.join(['un', 'caf?', cr?me.tag, sucr?.tag]) > > print(s) > > > input(':') > > > #------ > > # .\sucr?.py: > > # -*- coding: cp1252 -*- > > #tag = 'sucr?' > > > #------ > > # d:\cr?me\cr?me.py > > # -*- coding: cp1252 -*- > > #tag = 'cr?me' > > > # output > > # 3.3.0b1 (v3.3.0b1:e15c554cd43e+, Jun 26 2012, 20:30:00) [MSC v.1600 32 bit (Intel)] > > # un caf? cr?me sucr? > > # : > > > # :-) From lamialily at cleverpun.com Wed Jun 27 18:31:06 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Wed, 27 Jun 2012 15:31:06 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: On Wed, 27 Jun 2012 22:18:59 +0000 (UTC), Grant Edwards wrote: >> Can you post a small example showing what you're doing? > >The best way to get help is to write as small a program as possible >that demonstrates the problem, and post it. I'll help you get >started... > >Does this program work? > > import serial > ser = serial.Serial("COM4") > ser.close() > >At the moment, I don't have access to a Windows machine, but I think >the above should run without any errors. If it works, then you've >successfully opened and closed the COM4 port. Start adding >"features", in increments as small as possible, until the program >fails. > >Then try to remove stuff that's not needed while still keeping the >failure. > >IOW, try to find the smallest possible program that fails. > >Usually, in the process of doing that, you'll figure out what you were >doing wrong. If not, post the smallest failing program you can come >up with, and somebody will be able to help. > >If you won't show us what you're doing, we can't tell you what you're >doing wrong. Actually, I believe someone in an earlier thread in the newsgroup or elsewhere pointed out that serial ports automatically open under Windows. I'd have to look it back up when I have the time, which I don't have at the moment, unfortunately. ~Temia -- The amazing programming device: fuelled entirely by coffee, it codes while awake and tests while asleep! From rosuav at gmail.com Wed Jun 27 18:46:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Jun 2012 08:46:13 +1000 Subject: Recommend decent Computer Science books In-Reply-To: <30276019-dadf-4857-96b0-c3b9aaf6da1d@googlegroups.com> References: <30276019-dadf-4857-96b0-c3b9aaf6da1d@googlegroups.com> Message-ID: On Thu, Jun 28, 2012 at 7:00 AM, David Thomas wrote: > Hi I know that this is a group about Python. ?But I am just wondering if anybody can recommend any introductory/good books on Conputer Science. Well, there are books about Python specifically. They get discussed periodically on this list, too; here's a recent thread: http://www.gossamer-threads.com/lists/python/python/988206 I cannot personally endorse any of the books mentioned, but only because I've not read them. :) ChrisA From adam at no_thanks.com Wed Jun 27 18:51:38 2012 From: adam at no_thanks.com (Adam) Date: Wed, 27 Jun 2012 15:51:38 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: "Temia Eszteri" wrote in message news:ra2nu7h75720i75ijhabg12dngrab756e8 at 4ax.com... > On Wed, 27 Jun 2012 22:18:59 +0000 (UTC), Grant Edwards > wrote: > >>> Can you post a small example showing what you're doing? >> >>The best way to get help is to write as small a program as possible >>that demonstrates the problem, and post it. I'll help you get >>started... >> >>Does this program work? >> >> import serial >> ser = serial.Serial("COM4") >> ser.close() >> >>At the moment, I don't have access to a Windows machine, but I think >>the above should run without any errors. If it works, then you've >>successfully opened and closed the COM4 port. Start adding >>"features", in increments as small as possible, until the program >>fails. >> >>Then try to remove stuff that's not needed while still keeping the >>failure. >> >>IOW, try to find the smallest possible program that fails. >> >>Usually, in the process of doing that, you'll figure out what you were >>doing wrong. If not, post the smallest failing program you can come >>up with, and somebody will be able to help. >> >>If you won't show us what you're doing, we can't tell you what you're >>doing wrong. > > Actually, I believe someone in an earlier thread in the newsgroup or > elsewhere pointed out that serial ports automatically open under > Windows. I'd have to look it back up when I have the time, which I > don't have at the moment, unfortunately. > > ~Temia > -- > The amazing programming device: fuelled entirely by coffee, it codes while > awake and tests while asleep! Thanks, I think I read that as well but can't recall where. I am just running Python scripts (downloaded), which is not opening the serial port more than once (as Grant keeps assuming). From Joshua.R.English at gmail.com Wed Jun 27 19:09:51 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Wed, 27 Jun 2012 16:09:51 -0700 (PDT) Subject: Getting lazy with decorators In-Reply-To: References: <9d0c01f4-4430-4a45-8776-20d8dede9e14@googlegroups.com> <513d25ea-e977-4b84-b388-bfb23c171aae@googlegroups.com> Message-ID: <3e726c11-f3ee-4cd7-983c-cd4ab923a0b1@googlegroups.com> On Monday, June 25, 2012 11:57:39 PM UTC-7, Peter Otten wrote: > > > > There is nothing in the documentation (that I have found) that points to > > this solution. > > That's because I "invented" it. > Oh bother. The lines I completely overlooked were in your __getattr__ override. Boy is my face red. On further experimentation, adding a do_xxx command without the decorator still works...ish. The undecorated do_xxx is still considered to have a help function, and it prints the raw docstring (instead of using the show_help method to clean it up). Josh From Joshua.R.English at gmail.com Wed Jun 27 19:09:51 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Wed, 27 Jun 2012 16:09:51 -0700 (PDT) Subject: Getting lazy with decorators In-Reply-To: References: <9d0c01f4-4430-4a45-8776-20d8dede9e14@googlegroups.com> <513d25ea-e977-4b84-b388-bfb23c171aae@googlegroups.com> Message-ID: <3e726c11-f3ee-4cd7-983c-cd4ab923a0b1@googlegroups.com> On Monday, June 25, 2012 11:57:39 PM UTC-7, Peter Otten wrote: > > > > There is nothing in the documentation (that I have found) that points to > > this solution. > > That's because I "invented" it. > Oh bother. The lines I completely overlooked were in your __getattr__ override. Boy is my face red. On further experimentation, adding a do_xxx command without the decorator still works...ish. The undecorated do_xxx is still considered to have a help function, and it prints the raw docstring (instead of using the show_help method to clean it up). Josh From dwblas at gmail.com Wed Jun 27 19:24:30 2012 From: dwblas at gmail.com (David) Date: Wed, 27 Jun 2012 16:24:30 -0700 (PDT) Subject: Question:Programming a game grid ... In-Reply-To: References: Message-ID: First, you should be getting an error on vars()[var] = Button(f3, text = "00", bg = "white") as vars() has not been declared and it does not appear to be valid Python syntax. I don't see a reason to store a reference to the button since you won't be modifying them. Also, you can not mix pack() and grid(). It produces unpredictable results. try: import Tkinter as tk ## Python 2.x except ImportError: import tkinter as tk ## Python 3.x def leftclick(*args): print "leftclick called" def rightclick(*args): print "rightclick called" root = tk.Tk() f3 = tk.Frame(root, bg = "white", width = 500) f3.grid() this_row=0 this_column=0 for ctr in range(0, 89): b = tk.Button(f3, text = "%0d" % (ctr), bg = "white") b.grid(row=this_row, column=this_column) b.bind('', leftclick) # bind left mouse click b.bind('', rightclick) # bind left mouse click this_column += 1 if this_column > 6: this_column=0 this_row += 1 root.title('Puzzle Grid') root.mainloop() From invalid at invalid.invalid Wed Jun 27 19:24:57 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 27 Jun 2012 23:24:57 +0000 (UTC) Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: On 2012-06-27, Adam wrote: > >> Actually, I believe someone in an earlier thread in the newsgroup or >> elsewhere pointed out that serial ports automatically open under >> Windows. I'd have to look it back up when I have the time, which I >> don't have at the moment, unfortunately. What they're referring to is that on startup, Windows used to open serial ports and query them to see if there was a serial mouse connected. If it _thought_ it found a mouse, it would then hold the port. I don't think that behavior has been enabled by default for a long time. If that were the case, then your terminal program wouldn't be able to open the port either. However, IIRC, some versions of windows do open and then close the ports during the bus/device enumeration step of startup. However, they don't keep the port open, so it doesn't affect the ability of user applications to later open the port. > Thanks, I think I read that as well but can't recall where. > > I am just running Python scripts (downloaded), which is not opening > the serial port more than once (as Grant keeps assuming). Well, I'm assuming your description of what you're doing is accurate. If you're telling the truth, then the program is opening the port more than once. If the port wasn't already open, then calling ser.close() wouldn't do _anything_. Here's the close() implmentation from pyserial: def close(self): """Close port""" if self._isOpen: if self.hComPort: # Restore original timeout values: win32.SetCommTimeouts(self.hComPort, self._orgTimeouts) # Close COM-Port: win32.CloseHandle(self.hComPort) win32.CloseHandle(self._overlappedRead.hEvent) win32.CloseHandle(self._overlappedWrite.hEvent) self.hComPort = None self._isOpen = False There's only _one_ place where self._isOpen is set to True, and that's at the end of the open() call: def open(self): """Open port with current settings. This may throw a SerialException if the port cannot be opened.""" [...] self._overlappedWrite.hEvent = win32.CreateEvent(None, 0, 0, None) self._isOpen = True If you have to add the call "ser.close()" before you can open the port with "ser.open()", then that means that the port _was_already_open_. -- Grant Edwards grant.b.edwards Yow! World War III? at No thanks! gmail.com From rosuav at gmail.com Wed Jun 27 19:35:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Jun 2012 09:35:59 +1000 Subject: Question:Programming a game grid ... In-Reply-To: References: Message-ID: On Thu, Jun 28, 2012 at 9:24 AM, David wrote: > First, you should be getting an error on > vars()[var] = Button(f3, text = "00", bg = "white") > as vars() has not been declared and it does not appear to be valid Python syntax. It's valid syntax, but highly inadvisable. What it does is call the vars() function, then dereference its argument for assignment - perfectly legal when the function returns a dictionary, which vars does. But check the docs: http://docs.python.org/library/functions.html#vars It's intended to be read, NOT written. It's entirely possible that this works at module level, but should not be relied on. Also, other Python implementations or even other versions of the same Python could behave differently. ChrisA From rosuav at gmail.com Wed Jun 27 19:37:10 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Jun 2012 09:37:10 +1000 Subject: Question:Programming a game grid ... In-Reply-To: References: Message-ID: On Thu, Jun 28, 2012 at 9:35 AM, Chris Angelico wrote: > On Thu, Jun 28, 2012 at 9:24 AM, David wrote: >> First, you should be getting an error on >> vars()[var] = Button(f3, text = "00", bg = "white") >> as vars() has not been declared and it does not appear to be valid Python syntax. > > It's valid syntax, but highly inadvisable. Clarification: There's nothing inadvisable about the syntax, just about writing to vars(). Dereferencing a function's return value is perfectly alright. ChrisA From python at mrabarnett.plus.com Wed Jun 27 19:43:14 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 Jun 2012 00:43:14 +0100 Subject: Question:Programming a game grid ... In-Reply-To: References: Message-ID: <4FEB9A92.9040707@mrabarnett.plus.com> On 27/06/2012 23:21, iconoclast011 wrote: > Fairly new to Python ... Is there a way to efficiently (different from my brute > force code shown below) to set up a game grid of buttons (ie with pygame) > responding to mouse clicks ? I would want to vary the size of the grid ... > [code snipped] Something based around this, perhaps: buttons = {} for row in range(10): for column in range(9): b = Button(f3, text = "{0}{1}".format(row, column), bg = "white") b.grid(row=0, column=0) b.bind('', leftclick) # bind left mouse click b.bind('', rightclick) # bind left mouse click buttons['{0}{1}'.format(row, column)] = b From charleshixsn at earthlink.net Wed Jun 27 20:13:00 2012 From: charleshixsn at earthlink.net (Charles Hixson) Date: Wed, 27 Jun 2012 17:13:00 -0700 Subject: exception problem In-Reply-To: <4fe817d3$0$29866$c3e8da3$5496439d@news.astraweb.com> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4fe817d3$0$29866$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FEBA18C.5090204@earthlink.net> On 06/25/2012 12:48 AM, Steven D'Aprano wrote: > On Sun, 24 Jun 2012 16:16:25 -0700, Charles Hixson wrote: > > >> But what I wanted was to catch any exception. >> > Be careful of what you ask for, since you might get it. > > "Catch any exception" is almost certainly the wrong thing to do, almost > always. The one good reason I've seen for a bare except is to wrap the > top level of an application in order to redirect uncaught exceptions to > something other than the console (such as a GUI error dialog box). And > even then, you probably don't want to catch *all* exceptions, but only > those that inherit from Exception: > > try: > main() # run my application > except Exception as err: > display_error_dialog(err) > # or log to a file, or something... > > > > This time it was the right thing, as I suspected that *SOME* exception was being thrown, but had no idea what one. The problem was I didn't know how to print the result when I caught the exception. This has since been cleared up, but first I found it on Google, and then I was told about it on the list. The documentation left me totally ... well, not uninformed, but confused. As I said it turned out to be a method call on an uninitialized variable, as I found out once I figured out how to list the result of catching the exception. Which is what I expected the documentation to show me how to do. The comments on the list have been vastly helpful, even if they still tend to assume that I know more than I do. (And even if some of them seem to be a bit ... off. E.g., suggesting that I generate the exception on purpose so I can find out what it is, when I started off with no idea as to WHAT the problem was.) What really annoys me is the way the documentation has worsened since python 2.5, but if you know what it is trying to tell you, then I guess you aren't bothered by undefined terms and lack of examples. I went away from programming in Python for a couple of years though, and I guess I missed the transition, or something. -- Charles Hixson From adam at no_thanks.com Wed Jun 27 20:14:51 2012 From: adam at no_thanks.com (Adam) Date: Wed, 27 Jun 2012 17:14:51 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: "Grant Edwards" wrote in message news:jsg4o8$o4p$1 at reader1.panix.com... > On 2012-06-27, Adam wrote: >> >>> Actually, I believe someone in an earlier thread in the newsgroup or >>> elsewhere pointed out that serial ports automatically open under >>> Windows. I'd have to look it back up when I have the time, which I >>> don't have at the moment, unfortunately. > > What they're referring to is that on startup, Windows used to open > serial ports and query them to see if there was a serial mouse > connected. If it _thought_ it found a mouse, it would then hold the > port. I don't think that behavior has been enabled by default for a > long time. > > If that were the case, then your terminal program wouldn't be able to > open the port either. > > However, IIRC, some versions of windows do open and then close the > ports during the bus/device enumeration step of startup. However, they > don't keep the port open, so it doesn't affect the ability of user > applications to later open the port. > >> Thanks, I think I read that as well but can't recall where. >> >> I am just running Python scripts (downloaded), which is not opening >> the serial port more than once (as Grant keeps assuming). > > Well, I'm assuming your description of what you're doing is accurate. > > If you're telling the truth, then the program is opening the port more > than once. > > If the port wasn't already open, then calling ser.close() wouldn't do > _anything_. Here's the close() implmentation from pyserial: > > def close(self): > """Close port""" > if self._isOpen: > if self.hComPort: > # Restore original timeout values: > win32.SetCommTimeouts(self.hComPort, self._orgTimeouts) > # Close COM-Port: > win32.CloseHandle(self.hComPort) > win32.CloseHandle(self._overlappedRead.hEvent) > win32.CloseHandle(self._overlappedWrite.hEvent) > self.hComPort = None > self._isOpen = False > > There's only _one_ place where self._isOpen is set to True, and that's > at the end of the open() call: > > def open(self): > """Open port with current settings. This may throw a > SerialException > if the port cannot be opened.""" > [...] > self._overlappedWrite.hEvent = win32.CreateEvent(None, 0, 0, None) > self._isOpen = True > > If you have to add the call "ser.close()" before you can open the port > with "ser.open()", then that means that the port _was_already_open_. > > -- > Grant Edwards grant.b.edwards Yow! World War III? > at No thanks! > gmail.com Obviously pySerial considers the serial port open and will not open an already open serial port. However, why is it that TeraTerm can open the serial port? Here's the link where I read about calling ser.close() before ser.open() ... Trying to open a serial port with pyserial on WinXP -> "Access denied" http://stackoverflow.com/questions/2063257/trying-to-open-a-serial-port-with-pyserial-on-winxp-access-denied Here's the Python scripts ... https://github.com/adafruit/Tweet-a-Watt/downloads Click on the "Download as ..." button for the Python scripts From steve+comp.lang.python at pearwood.info Wed Jun 27 20:15:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Jun 2012 00:15:09 GMT Subject: Question:Programming a game grid ... References: Message-ID: <4feba20d$0$29866$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Jun 2012 16:24:30 -0700, David wrote: > First, you should be getting an error on > vars()[var] = Button(f3, text = "00", bg = "white") > as vars() has not been declared The Fine Manual says differently: Python 2: http://docs.python.org/library/functions.html#vars Python 3: http://docs.python.org/py3k/library/functions.html#vars > and it does not appear to be valid Python syntax. It's perfectly fine syntax, no different from: my_dict['spam'] = 'a yummy ham-like substance' or similar. -- Steven From wuwei23 at gmail.com Wed Jun 27 20:31:34 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 27 Jun 2012 17:31:34 -0700 (PDT) Subject: Question:Programming a game grid ... References: Message-ID: <3dfaba22-9fe6-4f79-b74a-11d37e81cfc5@m2g2000pbv.googlegroups.com> On Jun 28, 8:21?am, iconoclast011 wrote: > Fairly new to Python ... Is there a way to efficiently (different from my brute > force code shown below) to set up a game grid of buttons (ie with pygame) > responding to mouse clicks ? ? I would want to vary the size of the grid ... It hasn't been updated for a few years, but I was always impressed by Richard Jones' use of context managers in his withgui, especially his minesweeper example: import random class Cell(object): def __init__(self, i, j, has_bomb): self.i, self.j = i, j self.has_bomb = has_bomb class Board(list): def __init__(self, size, chance=.2): self.size = size self[:] = [[Cell(i, j, random.random() < chance) for i in range(size)] for j in range(size)] def count(self, cell): '''Count the number of bombs near the cell.''' return sum(self[j][i].has_bomb for i in range(max(0, cell.i-1), min(self.size, cell.i +2)) for j in range(max(0, cell.j-1), min(self.size, cell.j+2))) board = Board(20) with gui.canvas(width=320, height=320) as canvas: for column in board: for cell in column: @canvas.image('cover.png', x=cell.i*16, y=cell.j*16) def on_mouse(image, mouse, cell=cell): count = board.count(cell) if cell.has_bomb: image.value = 'bomb.png' print 'GAME OVER!' elif count: image.destroy() canvas.label(str(count), x=cell.i*16+8, y=cell.j*16+8, anchor=center) else: image.destroy() http://www.mechanicalcat.net/richard/log/Python/Something_I_m_working_on.7 https://code.launchpad.net/withgui From wuwei23 at gmail.com Wed Jun 27 20:36:21 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 27 Jun 2012 17:36:21 -0700 (PDT) Subject: exception problem References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4fe817d3$0$29866$c3e8da3$5496439d@news.astraweb.com> Message-ID: <962dcbfa-4746-4764-937f-2f101aa74141@wt8g2000pbb.googlegroups.com> On Jun 28, 10:13?am, Charles Hixson wrote: > On 06/25/2012 12:48 AM, Steven D'Aprano wrote: > > "Catch any exception" is almost certainly the wrong thing to do, almost > > always. > This time it was the right thing, as I suspected that *SOME* exception > was being thrown, but had no idea what one. ?The problem was I didn't > know how to print the result when I caught the exception. I think you're still missing the point. If you _didn't_ have a bare try/except, the exception _would have been raised_ and the exception displayed. You _don't_ need an exception handler for exceptions to occur, they just occur. You _only_ need a handler when you want to, y'know, handle them. > This has > since been cleared up, but first I found it on Google, and then I was > told about it on the list. ?The documentation left me totally ... well, > not uninformed, but confused. ?As I said it turned out to be a method > call on an uninitialized variable, as I found out once I figured out how > to list the result of catching the exception. ?Which is what I expected > the documentation to show me how to do. The documentation doesn't expect you to write code to block error reporting. If you had just removed the try/except, you would have seen the problem right away. > What really annoys me is the way the documentation has worsened since > python 2.5, but if you know what it is trying to tell you, then I guess > you aren't bothered by undefined terms and lack of examples. ?I went > away from programming in Python for a couple of years though, and I > guess I missed the transition, or something. Can I suggest re-looking at the tutorial for errors & exceptions? I really think you're making this a lot more difficult for yourself than it needs to be. http://docs.python.org/tutorial/errors.html From wuwei23 at gmail.com Wed Jun 27 20:44:23 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 27 Jun 2012 17:44:23 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> <4FEB077E.1010607@stackless.com> <4FEB19F7.6080103@stackless.com> Message-ID: <78358b8a-2131-46b8-b41b-042c06ef1ee6@n9g2000pbi.googlegroups.com> On Jun 28, 8:11?am, Christian Tismer wrote: > Random notes without context and reasoning are no better than spam. > My answer as well, of course, so let's stop here. It's more that all of this has been discussed at length. Repeatedly. It's very easy to criticise the current state of affairs when you didn't actively participate in the lead up to it and, by your own admission, really just want tools to "abuse" existing libraries without putting effort into migration. It's fine that you want this, but don't expect anyone else to put in effort where you're not prepared. If you believe providing a complementary __past__ namespace will work - even though I believe Guido has explicitly stated it will never happen - then the onus is on you to come up with an implementation. From howmuchistoday at gmail.com Wed Jun 27 21:14:56 2012 From: howmuchistoday at gmail.com (howmuchistoday at gmail.com) Date: Wed, 27 Jun 2012 18:14:56 -0700 (PDT) Subject: Is there any way to decode String using unknown codec? Message-ID: Hi I'm a Korean and when I use modules like sys, os, &c, sometimes the interpreter show me broken strings like '\x13\xb3\x12\xc8'. It mustbe the Korean "alphabet" but I can't decode it to the rightway. I tried to decode it using codecs like cp949,mbcs,utf-8 but It failed. The only way I found is eval('\x13\xb3\x12\xc8'). It raises an Error with showing right Korean. Is there any way to deal it being not broken? From wuwei23 at gmail.com Wed Jun 27 22:05:47 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 27 Jun 2012 19:05:47 -0700 (PDT) Subject: Slow output References: <53d49cb1-a68a-49c4-b925-b8a910ac415a@googlegroups.com> Message-ID: On Jun 28, 3:33?am, subhabangal... at gmail.com wrote: > May any one suggest me what may be the likely issue? In situations like this, it always helps to see your code, especially if you can reduce it down to only the part doing the loading. One thing that can help reduce memory usage is to replace lists/list comprehensions with generators. For example, this loads the entire file into memory: for line in open('big.txt').readlines(): # do something to line While this only loads one line at a time: for line in open('big.txt'): # do something to line You can also do the same with multiple files by creating a generator to return their content a line at a time: filenames = ['a.txt', 'b.txt', 'c.txt'] files = (open(name) for name in filenames) lines = (line for file in files for line in file) for line in lines: # do something to line I highly recommend David Beazley's "Generator Tricks for Systems Programmers" for more techniques like this. From woooee at gmail.com Wed Jun 27 22:15:54 2012 From: woooee at gmail.com (woooee at gmail.com) Date: Wed, 27 Jun 2012 19:15:54 -0700 (PDT) Subject: Question:Programming a game grid ... In-Reply-To: <4feba20d$0$29866$c3e8da3$5496439d@news.astraweb.com> References: <4feba20d$0$29866$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5f203d38-5595-46af-85aa-ba8aeeb46c25@googlegroups.com> On Wednesday, June 27, 2012 5:15:09 PM UTC-7, Steven D'Aprano wrote: > On Wed, 27 Jun 2012 16:24:30 -0700, David wrote: > > > First, you should be getting an error on > > vars()[var] = Button(f3, text = "00", bg = "white") > > as vars() has not been declared > > The Fine Manual says differently: > > Python 2: > http://docs.python.org/library/functions.html#vars > > Python 3: > http://docs.python.org/py3k/library/functions.html#vars > > > > and it does not appear to be valid Python syntax. > > It's perfectly fine syntax, no different from: > > my_dict['spam'] = 'a yummy ham-like substance' > > or similar. > > > -- > Steven "as vars() has not been declared and it does not appear to be valid Python syntax" You assume too much IMHO. Vars() was not declared in the code provided and I do not think that we should be assuming that it is a function returning a dictionary instead of an error. Just my opinion. From benjamin.kaplan at case.edu Wed Jun 27 22:20:28 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 27 Jun 2012 19:20:28 -0700 Subject: Is there any way to decode String using unknown codec? In-Reply-To: References: Message-ID: On Wed, Jun 27, 2012 at 6:14 PM, wrote: > Hi > I'm a Korean and when I use modules like sys, os, &c, > sometimes the interpreter show me broken strings like > '\x13\xb3\x12\xc8'. > It mustbe the Korean "alphabet" but I can't decode it to the rightway. > I tried to decode it using codecs like cp949,mbcs,utf-8 > but It failed. > The only way I found is eval('\x13\xb3\x12\xc8'). > It raises an Error with showing right Korean. > Is there any way to deal it being not broken? > -- It's not broken. You're just using the wrong encodings. Try utf-16le. From wuwei23 at gmail.com Wed Jun 27 22:43:07 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 27 Jun 2012 19:43:07 -0700 (PDT) Subject: Question:Programming a game grid ... References: <4feba20d$0$29866$c3e8da3$5496439d@news.astraweb.com> <5f203d38-5595-46af-85aa-ba8aeeb46c25@googlegroups.com> Message-ID: <8ecd09f5-6b94-45aa-a354-adeb11aab000@d6g2000pbt.googlegroups.com> On Jun 28, 12:15?pm, woo... at gmail.com wrote: > You assume too much IMHO. ?Vars() was not declared in > the code provided and I do not think that we should be > assuming that it is a function returning a dictionary instead > of an error. http://docs.python.org/library/functions.html#vars Do you have the same objection to every built-in? > Just my opinion. There are two ways to help people: by trying to understand what they're doing, or by submitting them to endless pedantry. Only one of those is actually helpful. From iconoclast011 at gmail.com Wed Jun 27 22:59:41 2012 From: iconoclast011 at gmail.com (iconoclast011) Date: Wed, 27 Jun 2012 21:59:41 -0500 Subject: Question:Programming a game grid ... References: <8ecd09f5-6b94-45aa-a354-adeb11aab000@d6g2000pbt.googlegroups.com> Message-ID: <8uSdna9xetkAVXbSnZ2dnUVZ_qSdnZ2d@giganews.com> In reply to "alex23" who wrote the following: > On Jun 28, 12:15=A0pm, woo... at gmail.com wrote: > > You assume too much IMHO. =A0Vars() was not declared in > > the code provided and I do not think that we should be > > assuming that it is a function returning a dictionary instead > > of an error. > > http://docs.python.org/library/functions.html#vars > > Do you have the same objection to every built-in? > > > Just my opinion. > > There are two ways to help people: by trying to understand what > they're doing, or by submitting them to endless pedantry. Only one of > those is actually helpful. Thanks to all ... I think I'll plunge into a book on Tkinter ... KDA -- --------------------------------- --- -- - Posted with NewsLeecher v5.0 Beta 15 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - From lamialily at cleverpun.com Wed Jun 27 23:03:12 2012 From: lamialily at cleverpun.com (Temia Eszteri) Date: Wed, 27 Jun 2012 20:03:12 -0700 Subject: Question:Programming a game grid ... References: <4feba20d$0$29866$c3e8da3$5496439d@news.astraweb.com> <5f203d38-5595-46af-85aa-ba8aeeb46c25@googlegroups.com> <8ecd09f5-6b94-45aa-a354-adeb11aab000@d6g2000pbt.googlegroups.com> Message-ID: On Wed, 27 Jun 2012 19:43:07 -0700 (PDT), alex23 wrote: >There are two ways to help people: by trying to understand what >they're doing, or by submitting them to endless pedantry. Only one of >those is actually helpful. Is it alright if I use that as a quote? Properly attributed, of course. -- The amazing programming device: fuelled entirely by coffee, it codes while awake and tests while asleep! From rantingrickjohnson at gmail.com Wed Jun 27 23:25:29 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Wed, 27 Jun 2012 20:25:29 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0e9ffee0-32be-409d-b7e5-bce7bba45211@googlegroups.com> On Monday, June 25, 2012 10:35:14 PM UTC-5, Steven D'Aprano wrote: > (Rick, don't make me regret communicating with you again.) Well unfortunately Steven i am not sure what causes you to stop communicating with me for these seeming random periods of time -- although i can deduce from past experiences that you have difficulty accepting diverse opinions, then, your emotions take control causing you to wield the only weapon of recourse you have available to you: the kill file -- so in that sense, i cannot provide a solution for a problem that exists beyond my control. HTH. > On Mon, 25 Jun 2012 19:28:01 -0700, rantingrickjohnson wrote: > There's no real difference between typing print(...) and all the other > functions in Python. Do you lament having to type len(obj) instead of > "len obj" or list(zip(a, b, c)) instead of "list zip a b c"? No. I actually like the forced parenthesis -- even when on a function declaration with no arguments. I think this is a consistent approach. And boy do i love consistency! > Making print a statement in the first place was a mistake, but > fortunately it was a simple enough mistake to rectify once the need for > backward compatibility was relaxed. Agreed. However, my comment was not a rant against the new print function, more that, it is a warning against pushing people to learn Python 2.x FIRST, and therby "training" them with the bad habit of using a "naked print syntax" that they will surely lament in the future. For me the print statement is like a big old delicious chocolate chip cookie and the print function is like a plate of leafy vegetables. I know i should eat my vegetables; but that damn cookie is just too tempting! From gsulser at gmail.com Wed Jun 27 23:26:03 2012 From: gsulser at gmail.com (Greg) Date: Wed, 27 Jun 2012 20:26:03 -0700 (PDT) Subject: Recommend decent Computer Science books In-Reply-To: <30276019-dadf-4857-96b0-c3b9aaf6da1d@googlegroups.com> References: <30276019-dadf-4857-96b0-c3b9aaf6da1d@googlegroups.com> Message-ID: <7a32eb48-9737-4825-827f-bcd316be9f2b@googlegroups.com> On Wednesday, June 27, 2012 2:00:03 PM UTC-7, David Thomas wrote: > Hi I know that this is a group about Python. But I am just wondering if anybody can recommend any introductory/good books on Conputer Science. > > Kind regards I recommend "Python Programming: An Introduction to Computer Science" - 2nd Edition by John Zelle. Regards, From rantingrickjohnson at gmail.com Wed Jun 27 23:32:03 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Wed, 27 Jun 2012 20:32:03 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <2b6eb040-711e-4af7-a7a9-dd91a10dd3f6@googlegroups.com> <87ehp2fyth.fsf@friendface.gateway.2wire.net> Message-ID: On Tuesday, June 26, 2012 1:24:43 AM UTC-5, Stefan Behnel wrote: > Maybe we should add a remote error reporting mode to Python that sends all > syntax error messages not only to the local screen but also directly to the > PSF so that they can fund developers who are able to delete that error > message from the interpreter based on real world statistical evidence. That > would eventually make the language match the powerset of what all users > have in their fingers. A very worthy goal, if you ask me. I'm sure you meant this a joke, however, some feedback like this would be greatly beneficial to the developers and community. It's not something you'd want to send each time an exception is thrown, but a log could be requested for delivery from time to time. I think it would be a great addition to any python editor; especially those geared toward neophytes: like IDLE and such. From rantingrickjohnson at gmail.com Wed Jun 27 23:32:03 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Wed, 27 Jun 2012 20:32:03 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <2b6eb040-711e-4af7-a7a9-dd91a10dd3f6@googlegroups.com> <87ehp2fyth.fsf@friendface.gateway.2wire.net> Message-ID: On Tuesday, June 26, 2012 1:24:43 AM UTC-5, Stefan Behnel wrote: > Maybe we should add a remote error reporting mode to Python that sends all > syntax error messages not only to the local screen but also directly to the > PSF so that they can fund developers who are able to delete that error > message from the interpreter based on real world statistical evidence. That > would eventually make the language match the powerset of what all users > have in their fingers. A very worthy goal, if you ask me. I'm sure you meant this a joke, however, some feedback like this would be greatly beneficial to the developers and community. It's not something you'd want to send each time an exception is thrown, but a log could be requested for delivery from time to time. I think it would be a great addition to any python editor; especially those geared toward neophytes: like IDLE and such. From steve+comp.lang.python at pearwood.info Wed Jun 27 23:44:43 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Jun 2012 03:44:43 GMT Subject: exception problem References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4fe817d3$0$29866$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4febd32b$0$29866$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Jun 2012 17:13:00 -0700, Charles Hixson wrote: > On 06/25/2012 12:48 AM, Steven D'Aprano wrote: >> On Sun, 24 Jun 2012 16:16:25 -0700, Charles Hixson wrote: >> >> >>> But what I wanted was to catch any exception. >>> >> Be careful of what you ask for, since you might get it. >> >> "Catch any exception" is almost certainly the wrong thing to do, almost >> always. The one good reason I've seen for a bare except is to wrap the >> top level of an application in order to redirect uncaught exceptions to >> something other than the console (such as a GUI error dialog box). And >> even then, you probably don't want to catch *all* exceptions, but only >> those that inherit from Exception: >> >> try: >> main() # run my application >> except Exception as err: >> display_error_dialog(err) >> # or log to a file, or something... >> >> >> >> > This time it was the right thing, as I suspected that *SOME* exception > was being thrown, but had no idea what one. The problem was I didn't > know how to print the result when I caught the exception. > [...] once I figured out how > to list the result of catching the exception. If you had simply NOT caught it, the full traceback would have been printed automatically and you could have easily seen what exception was being raised, the error message, and where it was being raised from. This is exactly why you should not have used a bare except, or any except at all, but just let the uncaught exception print on its own. When trying to diagnose bugs, try...except is not your friend. Tracebacks are your friend. [...] > What really annoys me is the way the documentation has worsened since > python 2.5, but if you know what it is trying to tell you, then I guess > you aren't bothered by undefined terms and lack of examples. I went > away from programming in Python for a couple of years though, and I > guess I missed the transition, or something. If you have concrete examples of where you think the documentation could be improved, please either raise an enhancement request or bug report: http://bugs.python.org/ or at least raise them here (and hope somebody else raised the bug report). Otherwise, there's nothing we can do about vague complaints. -- Steven From rantingrickjohnson at gmail.com Wed Jun 27 23:53:59 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Wed, 27 Jun 2012 20:53:59 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, June 26, 2012 1:34:03 AM UTC-5, Stefan Behnel wrote: > First of all, the statement has a rather special syntax that is not obvious > and practically non-extensible. It also has hidden semantics that are hard > to explain and mixes formatting with output - soft-space, anyone? > > The function is straight forward, configurable, does one thing, works with > help() and doesn't get in the way. And something as rarely[1] used as a > print simply doesn't deserve special syntax. Oh, and, yes, you can even > pass it into some code as callback, although I rarely had a need for that. > > Stefan > > > [1] Seriously, it's not very helpful in interactive mode and too simplistic > to be used in application code. Even scripts often work better with logging > than with prints. Unfortunately, even though "print" is supposedly only used by the neophytes, the python<3.0 stdlib is full of print statements. For instance, out of 3173 files, 986 contained the word "print"[1]. Heck just in the Lib folder alone (without recusing down sub directories) there are 1352 instances of "print" in a "py" file! Naive Nancy Mused: "If only neophtes use print, and the Python Lib is full of prints statements, then the python developers must be...OH DEAR GAWD!" [1] of course that is when using `filestr.count("print")` -- I assume that the word "print" is not used excessively in comments or docstrings. Someone else can do a less naive search if they like. From rantingrickjohnson at gmail.com Wed Jun 27 23:53:59 2012 From: rantingrickjohnson at gmail.com (rantingrickjohnson at gmail.com) Date: Wed, 27 Jun 2012 20:53:59 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, June 26, 2012 1:34:03 AM UTC-5, Stefan Behnel wrote: > First of all, the statement has a rather special syntax that is not obvious > and practically non-extensible. It also has hidden semantics that are hard > to explain and mixes formatting with output - soft-space, anyone? > > The function is straight forward, configurable, does one thing, works with > help() and doesn't get in the way. And something as rarely[1] used as a > print simply doesn't deserve special syntax. Oh, and, yes, you can even > pass it into some code as callback, although I rarely had a need for that. > > Stefan > > > [1] Seriously, it's not very helpful in interactive mode and too simplistic > to be used in application code. Even scripts often work better with logging > than with prints. Unfortunately, even though "print" is supposedly only used by the neophytes, the python<3.0 stdlib is full of print statements. For instance, out of 3173 files, 986 contained the word "print"[1]. Heck just in the Lib folder alone (without recusing down sub directories) there are 1352 instances of "print" in a "py" file! Naive Nancy Mused: "If only neophtes use print, and the Python Lib is full of prints statements, then the python developers must be...OH DEAR GAWD!" [1] of course that is when using `filestr.count("print")` -- I assume that the word "print" is not used excessively in comments or docstrings. Someone else can do a less naive search if they like. From rantingrickjohnson at gmail.com Thu Jun 28 00:04:01 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 27 Jun 2012 21:04:01 -0700 (PDT) Subject: Question:Programming a game grid ... References: Message-ID: On Jun 27, 5:21?pm, iconoclast011 wrote: > Fairly new to Python ... Is there a way to efficiently (different from my brute > force code shown below) to set up a game grid of buttons (ie with pygame) > responding to mouse clicks ? ? I would want to vary the size of the grid ... > > Thanks > > Brute force code: > from Tkinter import * > > root = Tk() > > f = Frame(root, bg = "blue", width = 500, height = 500) > f.pack(side=LEFT, expand = 1) > > f3 = Frame(f, bg = "white", width = 500) > f3.pack(side=LEFT, expand = 1, pady = 50, padx = 50) > > #f2 = Frame(root, bg = "black", height=100, width = 100) > #f2.pack(side=LEFT, fill = Y) > > #b = Button(f2, text = "test") > #b.pack() > > var = 'b00' > vars()[var] = Button(f3, text = "00", bg = "white") > b00.grid(row=0, column=0) > b00.bind('', leftclick) ? # bind left mouse click > b00.bind('', rightclick) ? # bind left mouse click > > var = 'b01' > vars()[var] = Button(f3, text = "01", bg = "white") > b01.grid(row=0, column=1) > b01.bind('', leftclick) ? # bind left mouse click > b01.bind('', rightclick) ? # bind left mouse click > > b02 = Button(f3, text = "02", bg = "white") > b02.grid(row=0, column=2) > b02.bind('', leftclick) ? # bind left mouse click > b02.bind('', rightclick) ? # bind left mouse click > > b03 = Button(f3, text = "03", bg = "white") > b03.grid(row=0, column=3) > b03.bind('', leftclick) ? # bind left mouse click > b03.bind('', rightclick) ? # bind left mouse click > > b04 = Button(f3, text = "04", bg = "white") > b04.grid(row=0, column=4) > b04.bind('', leftclick) ? # bind left mouse click > b04.bind('', rightclick) ? # bind left mouse click > > b05 = Button(f3, text = "05", bg = "white") > b05.grid(row=0, column=5) > b05.bind('', leftclick) ? # bind left mouse click > b05.bind('', rightclick) ? # bind left mouse click > > b06 = Button(f3, text = "06", bg = "white") > b06.grid(row=0, column=6) > b07 = Button(f3, text = "07", bg = "white") > b07.grid(row=0, column=7) > b08 = Button(f3, text = "08", bg = "white") > b08.grid(row=0, column=8) > > b10 = Button(f3, text = "10", bg = "white") > b10.grid(row=1, column=0) > b11 = Button(f3, text = "11", bg = "white") > b11.grid(row=1, column=1) > b12 = Button(f3, text = "12", bg = "white") > b12.grid(row=1, column=2) > > b13 = Button(f3, text = "13", bg = "white") > b13.grid(row=1, column=3) > b14 = Button(f3, text = "14", bg = "white") > b14.grid(row=1, column=4) > b15 = Button(f3, text = "15", bg = "white") > b15.grid(row=1, column=5) > > b16 = Button(f3, text = "16", bg = "white") > b16.grid(row=1, column=6) > b17 = Button(f3, text = "17", bg = "white") > b17.grid(row=1, column=7) > b18 = Button(f3, text = "18", bg = "white") > b18.grid(row=1, column=8) > > b20 = Button(f3, text = "20", bg = "white") > b20.grid(row=2, column=0) > b21 = Button(f3, text = "21", bg = "white") > b21.grid(row=2, column=1) > b22 = Button(f3, text = "22", bg = "white") > b22.grid(row=2, column=2) > > b23 = Button(f3, text = "23", bg = "white") > b23.grid(row=2, column=3) > b24 = Button(f3, text = "24", bg = "white") > b24.grid(row=2, column=4) > b25 = Button(f3, text = "25", bg = "white") > b25.grid(row=2, column=5) > > b26 = Button(f3, text = "26", bg = "white") > b26.grid(row=2, column=6) > b27 = Button(f3, text = "27", bg = "white") > b27.grid(row=2, column=7) > b28 = Button(f3, text = "28", bg = "white") > b28.grid(row=2, column=8) > > b30 = Button(f3, text = "30", bg = "white") > b30.grid(row=3, column=0) > b31 = Button(f3, text = "31", bg = "white") > b31.grid(row=3, column=1) > b32 = Button(f3, text = "32", bg = "white") > b32.grid(row=3, column=2) > > b36 = Button(f3, text = "36", bg = "white") > b36.grid(row=3, column=6) > b37 = Button(f3, text = "37", bg = "white") > b37.grid(row=3, column=7) > b38 = Button(f3, text = "38", bg = "white") > b38.grid(row=3, column=8) > > b33 = Button(f3, text = "33", bg = "white") > b33.grid(row=3, column=3) > b34 = Button(f3, text = "34", bg = "white") > b34.grid(row=3, column=4) > b35 = Button(f3, text = "35", bg = "white") > b35.grid(row=3, column=5) > > b40 = Button(f3, text = "40", bg = "white") > b40.grid(row=4, column=0) > b41 = Button(f3, text = "41", bg = "white") > b41.grid(row=4, column=1) > b42 = Button(f3, text = "42", bg = "white") > b42.grid(row=4, column=2) > > b43 = Button(f3, text = "43", bg = "white") > b43.grid(row=4, column=3) > b44 = Button(f3, text = "44", bg = "white") > b44.grid(row=4, column=4) > b45 = Button(f3, text = "45", bg = "white") > b45.grid(row=4, column=5) > > b46 = Button(f3, text = "46", bg = "white") > b46.grid(row=4, column=6) > b47 = Button(f3, text = "47", bg = "white") > b47.grid(row=4, column=7) > b48 = Button(f3, text = "48", bg = "white") > b48.grid(row=4, column=8) > > b50 = Button(f3, text = "50", bg = "white") > b50.grid(row=5, column=0) > b51 = Button(f3, text = "51", bg = "white") > b51.grid(row=5, column=1) > b52 = Button(f3, text = "52", bg = "white") > b52.grid(row=5, column=2) > > b53 = Button(f3, text = "53", bg = "white") > b53.grid(row=5, column=3) > b54 = Button(f3, text = "54", bg = "white") > b54.grid(row=5, column=4) > b55 = Button(f3, text = "55", bg = "white") > b55.grid(row=5, column=5) > > b56 = Button(f3, text = "56", bg = "white") > b56.grid(row=5, column=6) > b57 = Button(f3, text = "57", bg = "white") > b57.grid(row=5, column=7) > b58 = Button(f3, text = "58", bg = "white") > b58.grid(row=5, column=8) > > b60 = Button(f3, text = "60", bg = "white") > b60.grid(row=6, column=0) > b61 = Button(f3, text = "61", bg = "white") > b61.grid(row=6, column=1) > b62 = Button(f3, text = "62", bg = "white") > b62.grid(row=6, column=2) > > b63 = Button(f3, text = "63", bg = "white") > b63.grid(row=6, column=3) > b64 = Button(f3, text = "64", bg = "white") > b64.grid(row=6, column=4) > b65 = Button(f3, text = "65", bg = "white") > b65.grid(row=6, column=5) > > b66 = Button(f3, text = "66", bg = "white") > b66.grid(row=6, column=6) > b67 = Button(f3, text = "67", bg = "white") > b67.grid(row=6, column=7) > b68 = Button(f3, text = "68", bg = "white") > b68.grid(row=6, column=8) > > b70 = Button(f3, text = "70", bg = "white") > b70.grid(row=7, column=0) > b71 = Button(f3, text = "71", bg = "white") > b71.grid(row=7, column=1) > b72 = Button(f3, text = "72", bg = "white") > b72.grid(row=7, column=2) > > b73 = Button(f3, text = "73", bg = "white") > b73.grid(row=7, column=3) > b74 = Button(f3, text = "74", bg = "white") > b74.grid(row=7, column=4) > b75 = Button(f3, text = "75", bg = "white") > b75.grid(row=7, column=5) > > b76 = Button(f3, text = "76", bg = "white") > b76.grid(row=7, column=6) > b77 = Button(f3, text = "77", bg = "white") > b77.grid(row=7, column=7) > b78 = Button(f3, text = "78", bg = "white") > b78.grid(row=7, column=8) > > b80 = Button(f3, text = "80", bg = "white") > b80.grid(row=8, column=0) > b81 = Button(f3, text = "81", bg = "white") > b81.grid(row=8, column=1) > b82 = Button(f3, text = "82", bg = "white") > b82.grid(row=8, column=2) > > b83 = Button(f3, text = "83", bg = "white") > b83.grid(row=8, column=3) > b84 = Button(f3, text = "84", bg = "white") > b84.grid(row=8, column=4) > b85 = Button(f3, text = "85", bg = "white") > b85.grid(row=8, column=5) > > b86 = Button(f3, text = "86", bg = "white") > b86.grid(row=8, column=6) > b87 = Button(f3, text = "87", bg = "white") > b87.grid(row=8, column=7) > b88 = Button(f3, text = "88", bg = "white") > b88.grid(row=8, column=8) > b88.bind('', leftclick) ? # bind left mouse click > b88.bind('', rightclick) ? # bind left mouse click > > #b86.configure(text = "X") > b86.configure(bg = "black") > b86.configure(fg = "white") > > root.title('Puzzle Grid') > root.mainloop() And on the sixth day the code god created loops and iterators; and his fingers thanked him; and he suddenly found he had developed an excess of free time... and so he rested. From wuwei23 at gmail.com Thu Jun 28 00:05:56 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 27 Jun 2012 21:05:56 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Rick, fix your mail reader/sender, your lines aren't wrapping properly. On Jun 28, 1:53?pm, rantingrickjohn... at gmail.com wrote: > Unfortunately, even though "print" is supposedly only used by the neophytes, the python<3.0 stdlib is full of print statements. For instance, out of 3173 files, 986 contained the word "print"[1]. Heck just in the Lib folder alone (without recusing down sub directories) there are 1352 instances of "print" in a "py" file! Stefan said "rarely used". Until you count all keywords & built-ins in those files and provide a relative basis of comparison, you're not saying anything here. > Naive Nancy Mused: "If only neophtes use print, and the Python Lib is full of prints statements, then the python developers must be...OH DEAR GAWD!" It's a good thing there's no open flame around given the sheer number of strawmen you stuff into your posts. No one made any such claim about "neophytes", just that logging can be better than print() as a general debugging tool. > [1] of course that is when using `filestr.count("print")` -- I assume that the word "print" is not used excessively in comments or docstrings. Someone else can do a less naive search if they like. So you couldn't even be bothered to do it right, but you're happy to form a noisy opinion on this crap, and now the onus is on someone else to correct the ignorance you've pushed onto this list. Again. From rustompmody at gmail.com Thu Jun 28 00:15:25 2012 From: rustompmody at gmail.com (rusi) Date: Wed, 27 Jun 2012 21:15:25 -0700 (PDT) Subject: Recommend decent Computer Science books References: <30276019-dadf-4857-96b0-c3b9aaf6da1d@googlegroups.com> Message-ID: On Jun 28, 2:00?am, David Thomas wrote: > Hi I know that this is a group about Python. ?But I am just wondering if anybody can recommend any introductory/good books on Conputer Science. > > Kind regards This is like asking: How do I live my life? or make money (or love)? etc Not that there are no answers, rather too many to be useful. So if you want this to be a little more useful you should say - who you are (eg student, or what kind of professional) etc - what you are looking for - why ask this on a python list Since we dont yet have any such data, some general comments: - There are many good books on computer science (and many more not good) - Of those many have very little to do with programming languages - Of course there are good CS books dealing with programming both specifically (as in python) and generically (as in implementation, semantics etc) - The usual spelling is 'computer.' If your spelling was deliberate then, yes, Ive been 'conned' into answering :-) From ian.g.kelly at gmail.com Thu Jun 28 00:29:23 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 27 Jun 2012 22:29:23 -0600 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jun 27, 2012 9:57 PM, wrote: > [1] of course that is when using `filestr.count("print")` -- I assume that the word "print" is not used excessively in comments or docstrings. Someone else can do a less naive search if they like. Or as part of a longer name, e.g. the traceback.print_* family of functions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu Jun 28 00:32:23 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Jun 2012 04:32:23 GMT Subject: Why has python3 been created as a seperate language where there is still python2.7 ? References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> <4FEB077E.1010607@stackless.com> <4FEB19F7.6080103@stackless.com> <78358b8a-2131-46b8-b41b-042c06ef1ee6@n9g2000pbi.googlegroups.com> Message-ID: <4febde56$0$29866$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Jun 2012 17:44:23 -0700, alex23 wrote: > If you believe providing a complementary __past__ namespace will work - > even though I believe Guido has explicitly stated it will never happen - > then the onus is on you to come up with an implementation. Guido speaks only for CPython. Other implementations can always do differently. The Python 3 naysayers are welcome to fork Python 2.7 and support it forever, with or without a __past__ namespace. That's the power of open source software. And who knows, if it becomes popular enough, perhaps it will be ported to CPython too. -- Steven From steve+comp.lang.python at pearwood.info Thu Jun 28 00:39:38 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Jun 2012 04:39:38 GMT Subject: Question:Programming a game grid ... References: <4feba20d$0$29866$c3e8da3$5496439d@news.astraweb.com> <5f203d38-5595-46af-85aa-ba8aeeb46c25@googlegroups.com> Message-ID: <4febe00a$0$29866$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Jun 2012 19:15:54 -0700, woooee wrote: > "as vars() has not been declared and it does not appear to be valid > Python syntax" > > You assume too much IMHO. Vars() was not declared in the code provided > and I do not think that we should be assuming that it is a function > returning a dictionary instead of an error. Just my opinion. Thanks for sharing. It's an ignorant opinion. vars is a built-in function, just like len, chr, map, and many others. Ignorance is not a sin, but willful ignorance is. I already gave the links showing that vars is a built-in function, and you chose to ignore them. Here they are again. Please take a few seconds to read at least one of them, so that you will be a better programmer in the future and your opinion will be less ignorant: Python 2: http://docs.python.org/library/functions.html#vars Python 3: http://docs.python.org/py3k/library/functions.html#vars -- Steven From storchaka at gmail.com Thu Jun 28 01:36:15 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 28 Jun 2012 08:36:15 +0300 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: On 28.06.12 00:14, Terry Reedy wrote: > Another prediction: people who code Python without reading the manual, > at least not for new features, will learn about 'u' somehow (such as by > reading this list) and may do either of the following, both of which are > bad. > > 1. They will confuse themselves by thinking that 'u' actually means > somethings. They may then confuse others by writing about its supposed > meaning. This might get amusing. > > 2. They will use 'u' in Python 3 only code, thereby making it > incompatible with 3.2-, even if it otherwise would not be. > > These two actions will reinforce each other. Yes, this is what I mean. I can even make a prediction: in just 5 years, as this feature would be banned in a decent society. The authors of the books will be strongly advise not to use it, and in software companies 'u' will be prohibited in coding style. But get rid of this will be difficult. From stefan_ml at behnel.de Thu Jun 28 01:47:24 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 28 Jun 2012 07:47:24 +0200 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: Serhiy Storchaka, 28.06.2012 07:36: > On 28.06.12 00:14, Terry Reedy wrote: >> Another prediction: people who code Python without reading the manual, >> at least not for new features, will learn about 'u' somehow (such as by >> reading this list) and may do either of the following, both of which are >> bad. >> >> 1. They will confuse themselves by thinking that 'u' actually means >> somethings. They may then confuse others by writing about its supposed >> meaning. This might get amusing. >> >> 2. They will use 'u' in Python 3 only code, thereby making it >> incompatible with 3.2-, even if it otherwise would not be. >> >> These two actions will reinforce each other. > > Yes, this is what I mean. I can even make a prediction: in just 5 years, as > this feature would be banned in a decent society. The authors of the books > will be strongly advise not to use it, and in software companies 'u' will > be prohibited in coding style. But get rid of this will be difficult. Once Py2.7 is out of maintenance, we can deprecate that feature in one release and start warning about it in the next one. You're then free to use the corresponding 2to3 fixer to get it back out of your code with a single patch. Stefan From breamoreboy at yahoo.co.uk Thu Jun 28 02:02:33 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 28 Jun 2012 07:02:33 +0100 Subject: XPlatform ToolKit In-Reply-To: <842nu7ppq2nqfsi29jbfif4pfi49q3p3is@4ax.com> References: <842nu7ppq2nqfsi29jbfif4pfi49q3p3is@4ax.com> Message-ID: On 27/06/2012 23:26, Temia Eszteri wrote: > On Wed, 27 Jun 2012 23:14:13 +0100, Mark Lawrence > wrote: > >> On 27/06/2012 20:12, phpyjs at gmail.com wrote: >>> EnTK (batteries included) http://stk.phpyjs.com/ntk.zip >>> EsTK (pilas incluidas) http://stk.phpyjs.com/stk.zip >>> >>> Reverse Engineer This >>> >> >> sihT > > No no no, clearly it's sihT reenignE. > > ~Temia So much for the "excellent communication skills" bit on my CV :) -- Cheers. Mark Lawrence. From lars at rational-it.com Thu Jun 28 02:59:22 2012 From: lars at rational-it.com (lars van gemerden) Date: Wed, 27 Jun 2012 23:59:22 -0700 (PDT) Subject: moving methods from class to instance of other class Message-ID: Hi all, I have some trouble with the following question: Let say i have the following classes: class A(object): def __init__(self): self.name = 'a' def do(self): print 'A.do: self.name =', self.name class B(object): def __init__(self): self.name = 'b' The question is: How do i move the 'do' method from A to b (resulting in printing "A.do: self.name = b")? I have tried (with a = A() and b B()): B.do = types.MethodType(A.do, b) #Error and stuff like: b.do = a.do b.do() But either i get an error or b.do() prints "A.do: self.name = a", so the self parameter of a.do is stored somehow in the method. In other words, how do i unbind 'do' from a/A and bind it to b (the instance)? Cheers, Lars From benjamin.kaplan at case.edu Thu Jun 28 03:22:25 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 28 Jun 2012 00:22:25 -0700 Subject: moving methods from class to instance of other class In-Reply-To: References: Message-ID: On Wed, Jun 27, 2012 at 11:59 PM, lars van gemerden wrote: > Hi all, > > I have some trouble with the following question: Let say i have the > following classes: > > class A(object): > ? ?def __init__(self): > ? ? ? ?self.name = 'a' > ? ?def do(self): > ? ? ? ?print 'A.do: self.name =', self.name > > class B(object): > ? ?def __init__(self): > ? ? ? ?self.name = 'b' > > > > The question is: How do i move the 'do' method from A to b (resulting > in ?printing "A.do: self.name = b")? > > I have tried (with a = A() and b ?B()): > > B.do = types.MethodType(A.do, b) #Error > > and stuff like: > > b.do = a.do > b.do() > > But either i get an error or b.do() prints ?"A.do: self.name = a", so > the self parameter of a.do is stored somehow in the method. > > In other words, how do i unbind 'do' from a/A and bind it to b (the > instance)? > > Cheers, Lars > Is there any particular reason you can't just have B be a subclass of A? You could do b.do = types.MethodType(A.do.im_func, b, B) but there's no point in re-inventing the wheel. From s.pasoev at gmail.com Thu Jun 28 03:38:49 2012 From: s.pasoev at gmail.com (Sergi Pasoev) Date: Thu, 28 Jun 2012 11:38:49 +0400 Subject: Learning python by reading Message-ID: <87pq8jnawm.fsf@gmail.com> Hello Do you know some python programs that make good reading to learn the language by studying and modifying the source code ? I often try to understand things in the standard library, and apart from doing this kind of search myself, I would be glad to hear some ideas from more experienced programmers. Obviously, a good place to search is pypi and Python standard library, but which packages/modules ? From lars at rational-it.com Thu Jun 28 04:14:23 2012 From: lars at rational-it.com (lars van gemerden) Date: Thu, 28 Jun 2012 01:14:23 -0700 (PDT) Subject: moving methods from class to instance of other class References: Message-ID: <4dbb6034-cad2-4605-adf6-ad6a03ad82f2@o4g2000yqk.googlegroups.com> On Jun 28, 9:22?am, Benjamin Kaplan wrote: > On Wed, Jun 27, 2012 at 11:59 PM, lars van gemerden > > > > > > > > > > wrote: > > Hi all, > > > I have some trouble with the following question: Let say i have the > > following classes: > > > class A(object): > > ? ?def __init__(self): > > ? ? ? ?self.name = 'a' > > ? ?def do(self): > > ? ? ? ?print 'A.do: self.name =', self.name > > > class B(object): > > ? ?def __init__(self): > > ? ? ? ?self.name = 'b' > > > The question is: How do i move the 'do' method from A to b (resulting > > in ?printing "A.do: self.name = b")? > > > I have tried (with a = A() and b ?B()): > > > B.do = types.MethodType(A.do, b) #Error > > > and stuff like: > > > b.do = a.do > > b.do() > > > But either i get an error or b.do() prints ?"A.do: self.name = a", so > > the self parameter of a.do is stored somehow in the method. > > > In other words, how do i unbind 'do' from a/A and bind it to b (the > > instance)? > > > Cheers, Lars > > Is there any particular reason you can't just have B be a subclass of > A? You could do > > b.do = types.MethodType(A.do.im_func, b, B) > > but there's no point in re-inventing the wheel. Perfect, Thank you, As to the why, to make a long story short, actually instantiation would fit better conceptually than inheritance in this case, but that would mean the 'A' instances would be types, which introduces metaclasses, which i tried but i ran into problems with e.g. pickle and with complexity. Cheers, Lars From wustcsvstudio at vip.qq.com Thu Jun 28 05:30:37 2012 From: wustcsvstudio at vip.qq.com (=?gb18030?B?w867w7Ld?=) Date: Thu, 28 Jun 2012 17:30:37 +0800 Subject: how can I implement "cd" like shell in Python? Message-ID: how can I implement "cd" like shell in Python? -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Thu Jun 28 05:34:41 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 28 Jun 2012 02:34:41 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: On Thursday, June 28, 2012 7:47:24 AM UTC+2, Stefan Behnel wrote: > Serhiy Storchaka, 28.06.2012 07:36: > > On 28.06.12 00:14, Terry Reedy wrote: > >> Another prediction: people who code Python without reading the manual, > >> at least not for new features, will learn about 'u' somehow (such as by > >> reading this list) and may do either of the following, both of which are > >> bad. > >> > >> 1. They will confuse themselves by thinking that 'u' actually means > >> somethings. They may then confuse others by writing about its supposed > >> meaning. This might get amusing. > >> > >> 2. They will use 'u' in Python 3 only code, thereby making it > >> incompatible with 3.2-, even if it otherwise would not be. > >> > >> These two actions will reinforce each other. > > > > Yes, this is what I mean. I can even make a prediction: in just 5 years, as > > this feature would be banned in a decent society. The authors of the books > > will be strongly advise not to use it, and in software companies 'u' will > > be prohibited in coding style. But get rid of this will be difficult. > > Once Py2.7 is out of maintenance, we can deprecate that feature in one > release and start warning about it in the next one. You're then free to use > the corresponding 2to3 fixer to get it back out of your code with a single > patch. > > Stefan On the other side, one can argue this (elegancy): b'a serie of bytes' u'a unicode, a serie of code points' 'python2? str? python3? encoded _unicode?' jmf From wxjmfauth at gmail.com Thu Jun 28 05:34:41 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 28 Jun 2012 02:34:41 -0700 (PDT) Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: On Thursday, June 28, 2012 7:47:24 AM UTC+2, Stefan Behnel wrote: > Serhiy Storchaka, 28.06.2012 07:36: > > On 28.06.12 00:14, Terry Reedy wrote: > >> Another prediction: people who code Python without reading the manual, > >> at least not for new features, will learn about 'u' somehow (such as by > >> reading this list) and may do either of the following, both of which are > >> bad. > >> > >> 1. They will confuse themselves by thinking that 'u' actually means > >> somethings. They may then confuse others by writing about its supposed > >> meaning. This might get amusing. > >> > >> 2. They will use 'u' in Python 3 only code, thereby making it > >> incompatible with 3.2-, even if it otherwise would not be. > >> > >> These two actions will reinforce each other. > > > > Yes, this is what I mean. I can even make a prediction: in just 5 years, as > > this feature would be banned in a decent society. The authors of the books > > will be strongly advise not to use it, and in software companies 'u' will > > be prohibited in coding style. But get rid of this will be difficult. > > Once Py2.7 is out of maintenance, we can deprecate that feature in one > release and start warning about it in the next one. You're then free to use > the corresponding 2to3 fixer to get it back out of your code with a single > patch. > > Stefan On the other side, one can argue this (elegancy): b'a serie of bytes' u'a unicode, a serie of code points' 'python2? str? python3? encoded _unicode?' jmf From rosuav at gmail.com Thu Jun 28 06:14:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Jun 2012 20:14:35 +1000 Subject: Why has python3 been created as a seperate language where there is still python2.7 ? In-Reply-To: References: <1340509604.38915.YahooMailClassic@web164605.mail.gq1.yahoo.com> <4fe92df1$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEADFB4.5090301@stackless.com> Message-ID: On Thu, Jun 28, 2012 at 7:34 PM, wrote: > On the other side, one can argue this (elegancy): > > b'a series of bytes' > u'a unicode, a series of code points' Alas, not perfectly so. A 'bytes' object and a 'unicode' object can be described that way (with 'str' an alias for one or t'other), but literal strings are never that simple. (Backslash escapes, delimiters, newlines, etc, etc, etc.) However, it is a nice idea, to the extent that it's possible. ChrisA From s.pasoev at gmail.com Thu Jun 28 07:09:14 2012 From: s.pasoev at gmail.com (Sergi Pasoev) Date: Thu, 28 Jun 2012 15:09:14 +0400 Subject: how can I implement "cd" like shell in Python? Message-ID: <87pq8jsnfp.fsf@gmail.com> Do you mean to implement the cd command ? To what extent do you want to implement it ? if what you want is just to have a script to change the current working directory, it is as easy as this: import sys import os os.chdir(sys.argv[1]) plus you could add some error-handling code. From python at mrabarnett.plus.com Thu Jun 28 07:28:06 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 Jun 2012 12:28:06 +0100 Subject: Is there any way to decode String using unknown codec? In-Reply-To: References: Message-ID: <4FEC3FC6.1040800@mrabarnett.plus.com> On 28/06/2012 02:14, howmuchistoday at gmail.com wrote: > Hi > I'm a Korean and when I use modules like sys, os, &c, > sometimes the interpreter show me broken strings like > '\x13\xb3\x12\xc8'. > It mustbe the Korean "alphabet" but I can't decode it to the rightway. > I tried to decode it using codecs like cp949,mbcs,utf-8 > but It failed. > The only way I found is eval('\x13\xb3\x12\xc8'). > It raises an Error with showing right Korean. > Is there any way to deal it being not broken? > It might be UTF-16: >>> b'\x13\xb3\x12\xc8'.decode("utf16") '??' I don't know Korean, but that looks reasonable! From hansmu at xs4all.nl Thu Jun 28 07:33:10 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Thu, 28 Jun 2012 13:33:10 +0200 Subject: how can I implement "cd" like shell in Python? In-Reply-To: <87pq8jsnfp.fsf@gmail.com> References: <87pq8jsnfp.fsf@gmail.com> Message-ID: <4fec40f6$0$6961$e4fe514c@news2.news.xs4all.nl> On 28/06/12 13:09:14, Sergi Pasoev wrote: > Do you mean to implement the cd command ? To what extent do you want to > implement it ? if what you want is just to have a script to change the > current working directory, it is as easy as this: > > > import sys > import os > os.chdir(sys.argv[1]) > > plus you could add some error-handling code. 'cd' is a shell built-in, because otherwise it would have no effect. You can write a Python script that invokes os.chdir(), but that won't have any effect on the shell that starts the script. What are you trying to achieve? -- HansM From wustcsvstudio at vip.qq.com Thu Jun 28 07:34:30 2012 From: wustcsvstudio at vip.qq.com (=?gb18030?B?w867w7Ld?=) Date: Thu, 28 Jun 2012 19:34:30 +0800 Subject: I can't send images to this mail-list Message-ID: hi,all: why can't I send images to python-list at python.org?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Thu Jun 28 07:35:38 2012 From: lists at cheimes.de (Christian Heimes) Date: Thu, 28 Jun 2012 13:35:38 +0200 Subject: how can I implement "cd" like shell in Python? In-Reply-To: <87pq8jsnfp.fsf@gmail.com> References: <87pq8jsnfp.fsf@gmail.com> Message-ID: Am 28.06.2012 13:09, schrieb Sergi Pasoev: > Do you mean to implement the cd command ? To what extent do you want to > implement it ? if what you want is just to have a script to change the > current working directory, it is as easy as this: Please note that you can't change the working directory of another process. Your snipplet won't alter the current working directory of the shell. "cd" is a builtin shell command, not a binary. Christian From wustcsvstudio at vip.qq.com Thu Jun 28 07:39:30 2012 From: wustcsvstudio at vip.qq.com (=?gb18030?B?w867w7Ld?=) Date: Thu, 28 Jun 2012 19:39:30 +0800 Subject: =?gb18030?B?16q3oqO6UmU6aG93IGNhbiBJIGltcGxlbWVudCAi?= =?gb18030?B?Y2QiIGxpa2Ugc2hlbGwgaW4gUHl0aG9uPw==?= Message-ID: thanks !But this method can not change the directory of the main process.For example: the current directory is "/home/work/local/scripts",this directory have a python script file "cd.py" after executing the script cd.py by "python cd.py ..",the current work directory has no changes,the path is still "/home/work/local/scripts" ------------------ Original ------------------ From: "Sergi Pasoev"; Date: 2012?6?28?(???) ??7:09 To: "python-list"; Subject: how can I implement "cd" like shell in Python? Do you mean to implement the cd command ? To what extent do you want to implement it ? if what you want is just to have a script to change the current working directory, it is as easy as this: import sys import os os.chdir(sys.argv[1]) plus you could add some error-handling code. -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Thu Jun 28 08:12:02 2012 From: d at davea.name (Dave Angel) Date: Thu, 28 Jun 2012 08:12:02 -0400 Subject: how can I implement "cd" like shell in Python? In-Reply-To: References: Message-ID: <4FEC4A12.8010906@davea.name> On 06/28/2012 05:30 AM, ??? wrote: > how can I implement "cd" like shell in Python? > import os os.chdir("newdirectory") But the more important question is why you want to. Inside a Python program, many people find that changing directory causes unexpected difficulties, and they simply keep track of a full path instead, using various os.path functions to manage it. And once the python program ends, the shell should have no knowledge of what you changed it to. Now, a particular shell program might have some convention that allows a program to inform it what directory to continue in. But that's a question about that shell, not about Python. And you never said what your environment is. So give some more specifics to your needs, and somebody is likely to know an approach. -- DaveA From wustcsvstudio at vip.qq.com Thu Jun 28 08:28:40 2012 From: wustcsvstudio at vip.qq.com (=?gb18030?B?QWxleCBjaGVu?=) Date: Thu, 28 Jun 2012 20:28:40 +0800 Subject: =?gb18030?B?u9i4tKO6IGhvdyBjYW4gSSBpbXBsZW1lbnQgImNk?= =?gb18030?B?IiBsaWtlIHNoZWxsIGluIFB5dGhvbj8=?= Message-ID: I just want to write a python program,it can be called in the linux terminal like the command "cd" to change the directory of the shell terminal ------------------ ???? ------------------ ???: "Dave Angel"; ????: 2012?6?28?(???) ??8:12 ???: "Alex Chen"; ??: "python-list"; ??: Re: how can I implement "cd" like shell in Python? On 06/28/2012 05:30 AM, ??? wrote: > how can I implement "cd" like shell in Python? > import os os.chdir("newdirectory") But the more important question is why you want to. Inside a Python program, many people find that changing directory causes unexpected difficulties, and they simply keep track of a full path instead, using various os.path functions to manage it. And once the python program ends, the shell should have no knowledge of what you changed it to. Now, a particular shell program might have some convention that allows a program to inform it what directory to continue in. But that's a question about that shell, not about Python. And you never said what your environment is. So give some more specifics to your needs, and somebody is likely to know an approach. -- DaveA -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Thu Jun 28 08:52:57 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 28 Jun 2012 05:52:57 -0700 Subject: exception problem In-Reply-To: <4FEBA18C.5090204@earthlink.net> References: <4FE79433.8020704@earthlink.net> <4FE7982C.5020708@mrabarnett.plus.com> <4fe817d3$0$29866$c3e8da3$5496439d@news.astraweb.com> <4FEBA18C.5090204@earthlink.net> Message-ID: <4FEC53A9.2060108@stoneleaf.us> Charles Hixson wrote: > On 06/25/2012 12:48 AM, Steven D'Aprano wrote: >> "Catch any exception" is almost certainly the wrong thing to do, almost >> always. >> > This time it was the right thing No, it wasn't. If you hadn't caught it, Python would have printed it out for you, along with the full trace-back, giving you most if not all the information you needed to track down the bug. ~Ethan~ From hkaratoy at gmail.com Thu Jun 28 09:07:45 2012 From: hkaratoy at gmail.com (hkaratoy at gmail.com) Date: Thu, 28 Jun 2012 06:07:45 -0700 (PDT) Subject: TKinter Frame Size automatic Message-ID: <04c56243-cce8-476c-a228-49fd703834a1@googlegroups.com> I have a question about the frame size. I want to create Tabbed window. There will be one Window and tabs in this window. The page will be displayed whenever the user press the corresponding tab. This is simple NoteBook behaviour from Tkinter. I do not want to set the master window size but I want to make it dynamic regarding to the largest tabbed window. Lets say I have 4 pages which are tabbed, and if the 3 rd tabbed page has the largest size I want to set my main window to that size. Then I do nto have to set the master page size. I can read the frame size with frame.winfo_width(), frame.winfo_height(), but I can only learn this when the tabbed frame is created, and I think it is too late for the initialization of the main widnow size. I am quite confused. Because I do now know that I can learn the frame size before I packed all the widgets to it. Regards From kushal.kumaran at gmail.com Thu Jun 28 09:46:23 2012 From: kushal.kumaran at gmail.com (Kushal Kumaran) Date: Thu, 28 Jun 2012 19:16:23 +0530 Subject: =?UTF-8?Q?Re=3A_=E5=9B=9E=E5=A4=8D=EF=BC=9A_how_can_I_implement?= =?UTF-8?Q?_=22cd=22_like_shell_in_Python=3F?= In-Reply-To: References: Message-ID: Alex chen wrote: >I just want to write a python program,it can be called in the linux >terminal like the command "cd" to change the directory of the shell >terminal > This cannot be done. Shells implement cd as a builtin, rather than a command such as /usr/bin/cd because there is no way to change the current working directory of your parent process. Also, policy on this mailing list is to put your reply below the text you are quoting, as I'm doing here. It's called bottom posting. -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. From subhabangalore at gmail.com Thu Jun 28 10:11:45 2012 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Thu, 28 Jun 2012 07:11:45 -0700 (PDT) Subject: Slow output In-Reply-To: <53d49cb1-a68a-49c4-b925-b8a910ac415a@googlegroups.com> References: <53d49cb1-a68a-49c4-b925-b8a910ac415a@googlegroups.com> Message-ID: <1abe014f-df23-4a82-bb49-c15ad4ae0396@googlegroups.com> On Wednesday, June 27, 2012 11:03:44 PM UTC+5:30, (unknown) wrote: > Dear Group, > I am Sri Subhabrata Banerjee writing from India. I am running a small program which exploits around 12 1 to 2 KB .txt files. I am using MS Windows XP Service Pack 3 and Python 2.6 where IDLE is GUI. The text is plain ASCII text. The RAM of the machine is around 2 GB. To run the program the machine is becoming dead slow and it is executing only after several minutes. I am shocked as I have run hugely loaded Statistical Learning stuff only on 516MB RAM on Python using Windows XP only. And that too on a laptop. > I am not getting. I discussed the issue with my system administrator and he increased the RAM to 8GB result improved by 30% but not satisfactory speed. May any one suggest me what may be the likely issue? > > Thanking You in Advance, > Subhabrata Banerjee. Dear Group, Thank you for your kind reply and teaching me some nice coding options. I would port your suggestions and see if it improves. Unfortuantely I can not share the code as it has slight propietary issue, but I was debugging the code on myself, I was seeing that if I write the outputs in the file then it is giving fast results, but if I print it to the console -which is a list of big size, but well even I print all the files of 1KB each I have 12 files only, why a print command would make it so slow? I have searched processed made big n-grams big calculations across even UTF-8 encoding data sets Python gave result in fragment of seconds. Regards, Subhabrata Banerjee. From invalid at invalid.invalid Thu Jun 28 10:15:15 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 28 Jun 2012 14:15:15 +0000 (UTC) Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: On 2012-06-28, Adam wrote: > Obviously pySerial considers the serial port open Because it's already been opened by the Python program. > and will not open an already open serial port. Pyserial will happily try if you call the open() of a port that's already open, but Windows will return an error. > However, why is it that TeraTerm can open the serial port? Because TeraTerm only opens it once. > Here's the link where I read about calling ser.close() before > ser.open() ... > > Trying to open a serial port with pyserial on WinXP -> "Access denied" > > http://stackoverflow.com/questions/2063257/trying-to-open-a-serial-port-with-pyserial-on-winxp-access-denied That code is broken. The port is opened by this line: self.ser=serial.Serial(port='\\.\COM1', baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1) And then the author tries to _open_it_a_second_time_ here: self.ser.open() > Here's the Python scripts ... > https://github.com/adafruit/Tweet-a-Watt/downloads > Click on the "Download as ..." button for the Python scripts Like I kept telling you, those programs are trying to re-open a port that they've already open. Here's the erroneous code: wattcher.py: 53 54 # open up the FTDI serial port to get data transmitted to xbee 55 ser = serial.Serial(SERIALPORT, BAUDRATE) 56 ser.open() 57 Line 55 opens the serial port. Line 56 tries to _open_it_again_. _The_port_is_already_open_. Windows doesn't allow a serial port to be opened twice, therefore the ser.open() call raises an exception. Just delete line 56. The same thing happens here: gmeter-wattcher.py 83 84 # open up the FTDI serial port to get data transmitted to xbee 85 ser = serial.Serial(SERIALPORT, BAUDRATE) 86 ser.open() 87 Just delete line 86. See how simple it was to get the problem solved once you posted the actual code? -- Grant Edwards grant.b.edwards Yow! HUMAN REPLICAS are at inserted into VATS of gmail.com NUTRITIONAL YEAST ... From driscoll at cs.wisc.edu Thu Jun 28 10:27:05 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 28 Jun 2012 09:27:05 -0500 Subject: =?ISO-8859-1?Q?=DE=1A_how_can_I_implement_=22cd=22?= =?ISO-8859-1?Q?_like_shell_in_Python=3F?= In-Reply-To: References: Message-ID: <4FEC69B9.9060400@cs.wisc.edu> On 6/28/2012 7:28, Alex chen wrote: > I just want to write a python program,it can be called in the linux > terminal like the command "cd" to change the directory of the shell terminal You "can't" do this; a program the shell runs cannot affect the shell's execution. What you have to do is have some help from the shell. Have your Python program output the path to the directory you want to change to. Then you can run it as follows cd $(new-directory.py) or, if has arguments, cd $(new-directory.py foo blah) (The $(...) is usually spelled as `...` around the internet. If you're unfamiliar, what it does is run the command then substitute the *output* of that command at the command line.) Eventually you probably want to wrap this up so you don't have to do that every time. You can use a shell function for this. Assuming you're using an 'sh' derivative, it will look something like function my-cd() { cd $(new-directory.py "$@") } I'm not a shell programmer and I always forget the names of the variables holding the arguments, so check that at first and make sure it's passing the right thing to the new-directory script, e.g. that it works with whitespace in the arguments and that it isn't including the equivalent to argv[0] in the script. Evan From wustcsvstudio at vip.qq.com Thu Jun 28 10:33:34 2012 From: wustcsvstudio at vip.qq.com (=?ISO-8859-1?B?QWxleCBjaGVu?=) Date: Thu, 28 Jun 2012 22:33:34 +0800 Subject: how can I implement "cd" like shell in Python? Message-ID: OK,I see! Thank you everyone. ------------------ Original ------------------ From: "Evan Driscoll"; Date: Thu, Jun 28, 2012 10:27 PM To: "Alex chen"; Cc: "d"; "python-list"; Subject: Re: how can I implement "cd" like shell in Python? On 6/28/2012 7:28, Alex chen wrote: > I just want to write a python program,it can be called in the linux > terminal like the command "cd" to change the directory of the shell terminal You "can't" do this; a program the shell runs cannot affect the shell's execution. What you have to do is have some help from the shell. Have your Python program output the path to the directory you want to change to. Then you can run it as follows cd $(new-directory.py) or, if has arguments, cd $(new-directory.py foo blah) (The $(...) is usually spelled as `...` around the internet. If you're unfamiliar, what it does is run the command then substitute the *output* of that command at the command line.) Eventually you probably want to wrap this up so you don't have to do that every time. You can use a shell function for this. Assuming you're using an 'sh' derivative, it will look something like function my-cd() { cd $(new-directory.py "$@") } I'm not a shell programmer and I always forget the names of the variables holding the arguments, so check that at first and make sure it's passing the right thing to the new-directory script, e.g. that it works with whitespace in the arguments and that it isn't including the equivalent to argv[0] in the script. Evan -------------- next part -------------- An HTML attachment was scrubbed... URL: From dthomas86 at me.com Thu Jun 28 10:35:58 2012 From: dthomas86 at me.com (David Thomas) Date: Thu, 28 Jun 2012 07:35:58 -0700 (PDT) Subject: Recommend decent Computer Science books In-Reply-To: References: <30276019-dadf-4857-96b0-c3b9aaf6da1d@googlegroups.com> Message-ID: <980b656d-1cc0-40b9-a50a-d5cacf45b850@googlegroups.com> Thanks everyone for the feedback really appreciate it especially the above post cheers From andrea.crotti.0 at gmail.com Thu Jun 28 11:28:56 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 28 Jun 2012 16:28:56 +0100 Subject: retry many times decorator Message-ID: Hi everyone, I'm replacing a perl system that has to work a lot with databases and perforce (and a few other things). This script have to run completely unsupervisioned, so it's important that it doesn't just quit at the first attempt waiting for human intervent.. They say that the network sometimes has problems so all over the code there are things like: until ($dbh = DBI->connect('...')) { sleep( 5 * 60 ); ) Since I really don't want to do that I tried to do a decorator: class retry_n_times: def __init__(self, ntimes=3, timeout=3, fatal=True): self.ntimes = ntimes self.timeout = timeout self.fatal = fatal def __call__(self, func): def _retry_n_times(*args, **kwargs): attempts = 0 while True: logger.debug("Attempt number %s of %s" % (attempts, func.__name__)) ret = func(*args, **kwargs) if ret: return ret else: sleep(self.timeout) attempts += 1 if attempts == self.ntimes: logger.error("Giving up the attempts while running %s" % func.__name__) if self.fatal: exit(100) return _retry_n_times which can be used as @retry_n_times(ntimes=10) def connect(): try: conn = mysql_connection() except Exception: return False else: return True So the function to be decorated has to return a boolean.. The problem is that I would like to keep the exception message to report a bit better what could be the problem, in case the retry fails. Any idea about how to improve it? From alister.ware at ntlworld.com Thu Jun 28 11:54:04 2012 From: alister.ware at ntlworld.com (Alister) Date: Thu, 28 Jun 2012 15:54:04 GMT Subject: =?UTF-8?b?5Zue5aSN77ya?= how can I implement "cd" like shell in Python? References: Message-ID: On Thu, 28 Jun 2012 20:28:40 +0800, Alex chen wrote: > I just want to write a python program,it can be called in the linux > terminal like the command "cd" to change the directory of the shell > terminal > > > That would not only be needlesly re-inventing the wheel but making it square in the process. what is wrong with just calling cd if you are in the terminal. From gundlach at gmail.com Thu Jun 28 11:58:49 2012 From: gundlach at gmail.com (Michael Gundlach) Date: Thu, 28 Jun 2012 11:58:49 -0400 Subject: SSL handshake hanging, despite bugfix in stdlib In-Reply-To: References: Message-ID: On Mon, Jun 25, 2012 at 4:19 PM, Terry Reedy wrote: > Issue x ended with the message that the patch to issue y presumably fixed > issue x as well. I see two choices. (WHere I forget x and y, but they were > defined in previous posts.) > > 1. Post to issue x something like > Thanks for your advice, Terry. http://bugs.python.org/issue1251 updated as you suggested. - Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Jun 28 12:12:40 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 Jun 2012 17:12:40 +0100 Subject: retry many times decorator In-Reply-To: References: Message-ID: <4FEC8278.7020806@mrabarnett.plus.com> On 28/06/2012 16:28, andrea crotti wrote: > Hi everyone, I'm replacing a perl system that has to work a lot with > databases and perforce (and a few other things). > > This script have to run completely unsupervisioned, so it's important > that it doesn't just quit at the first attempt waiting for human > intervent.. > > They say that the network sometimes has problems so all over the code > there are things like: > until ($dbh = DBI->connect('...')) > { > sleep( 5 * 60 ); > ) > > > Since I really don't want to do that I tried to do a decorator: > > class retry_n_times: > def __init__(self, ntimes=3, timeout=3, fatal=True): > self.ntimes = ntimes > self.timeout = timeout > self.fatal = fatal > > def __call__(self, func): > def _retry_n_times(*args, **kwargs): > attempts = 0 > while True: > logger.debug("Attempt number %s of %s" % (attempts, > func.__name__)) > ret = func(*args, **kwargs) > if ret: > return ret > else: > sleep(self.timeout) > > attempts += 1 > if attempts == self.ntimes: > logger.error("Giving up the attempts while running > %s" % func.__name__) > if self.fatal: > exit(100) > > return _retry_n_times > > which can be used as > > @retry_n_times(ntimes=10) > def connect(): > try: > conn = mysql_connection() > except Exception: > return False > else: > return True > > > So the function to be decorated has to return a boolean.. The problem > is that I would like to keep the exception message to report a bit > better what could be the problem, in case the retry fails. > > Any idea about how to improve it? > Returning a boolean isn't very Pythonic. It would be better, IMHO, if it could swallow a specified exception (or specified exceptions?) raised when an attempt failed, up to the maximum permitted number of attempts. If the final attempt fails, propagate the exception. From andrea.crotti.0 at gmail.com Thu Jun 28 12:26:36 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Thu, 28 Jun 2012 17:26:36 +0100 Subject: retry many times decorator In-Reply-To: <4FEC8278.7020806@mrabarnett.plus.com> References: <4FEC8278.7020806@mrabarnett.plus.com> Message-ID: > Returning a boolean isn't very Pythonic. It would be better, IMHO, if > it could swallow a specified exception (or specified exceptions?) > raised when an attempt failed, up to the maximum permitted number of > attempts. If the final attempt fails, propagate the exception. > -- > http://mail.python.org/mailman/listinfo/python-list Yes right I also didn't like it.. Now it become something as below, so I capture every possible exception (since it must be generic) and log what exception was raised. I'm not re-raising because if it fails and it's fatal I should just exit, and if it's not fatal it should just continue.. class retry_n_times: def __init__(self, ntimes=3, timeout=3, fatal=True): self.ntimes = ntimes self.timeout = timeout self.fatal = fatal def __call__(self, func): def _retry_n_times(*args, **kwargs): attempts = 0 while True: logger.debug("Attempt number %s of %s" % (attempts, func.__name__)) try: ret = func(*args, **kwargs) except Exception as e: logger.error("Got exception %s with error %s" % (type(e), str(e))) sleep(self.timeout) else: return ret attempts += 1 if attempts == self.ntimes: logger.error("Giving up the attempts while running %s" % func.__name__) if self.fatal: exit(100) return _retry_n_times From dthomas86 at me.com Thu Jun 28 13:11:52 2012 From: dthomas86 at me.com (David Thomas) Date: Thu, 28 Jun 2012 10:11:52 -0700 (PDT) Subject: Following syntax error in Mac OX10.7 Terminal Message-ID: <5eacd83f-03c9-43b5-b799-733aa576b1df@googlegroups.com> Hi, I have the following error regarding a loop tutorial found on http://www.sthurlow.com/python/lesson04/ >>> a=0 >>> while a<10: ... a=a+1 File "", line 2 a=a+1 ^ IndentationError: expected an indented block When I run Python IDE it seems to work fine. The following code is: a=0 while a<10: a=a+1 print a Kind regards From laurent.pointal at free.fr Thu Jun 28 13:13:21 2012 From: laurent.pointal at free.fr (Laurent Pointal) Date: Thu, 28 Jun 2012 19:13:21 +0200 Subject: how can I implement "cd" like shell in Python? References: <87pq8jsnfp.fsf@gmail.com> Message-ID: <4fec90b1$0$6573$426a34cc@news.free.fr> Sergi Pasoev wrote: > Do you mean to implement the cd command ? To what extent do you want to > implement it ? if what you want is just to have a script to change the > current working directory, it is as easy as this: > > > import sys > import os > os.chdir(sys.argv[1]) > > plus you could add some error-handling code. To have a shell / python script interaction for cwd management, you can take a look at autojump https://github.com/joelthelion/autojump/wiki Its a Python script + different shells glue. A+ Laurent. -- Laurent POINTAL - laurent.pointal at laposte.net From dieter at handshake.de Thu Jun 28 13:18:12 2012 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 28 Jun 2012 19:18:12 +0200 Subject: Is there any way to decode String using unknown codec? References: Message-ID: <87wr2rpd7v.fsf@handshake.de> howmuchistoday at gmail.com writes: > I'm a Korean and when I use modules like sys, os, &c, > sometimes the interpreter show me broken strings like > '\x13\xb3\x12\xc8'. > It mustbe the Korean "alphabet" but I can't decode it to the rightway. > I tried to decode it using codecs like cp949,mbcs,utf-8 > but It failed. > The only way I found is eval('\x13\xb3\x12\xc8'). This looks as if "sys.stdout/sys.stderr" knew the correct encoding. Check it like this: import sys sys.stdout.encoding From s.pasoev at gmail.com Thu Jun 28 13:30:42 2012 From: s.pasoev at gmail.com (Sergi Pasoev) Date: Thu, 28 Jun 2012 21:30:42 +0400 Subject: Re Following syntax error in Mac OX10.7 Terminal Message-ID: <871ukzs5rx.fsf@gmail.com> You just have to consider that indentation matters in Python, so you have to type the code in Python interpreter as you have written it below, that is, press Tab before each line when you are inside the 'while (or any other like for, if, with, etc.) block. a=0 while a<10: a=a+1 print a I can guess from your message that you aren't aware of one very important Python feature, and maybe you also didn't willingly choose to learn Python2 instead of Python3 ? In this case I would advise you to consider both versions before choosing. From bahamutzero8825 at gmail.com Thu Jun 28 13:31:47 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 28 Jun 2012 12:31:47 -0500 Subject: Following syntax error in Mac OX10.7 Terminal In-Reply-To: <5eacd83f-03c9-43b5-b799-733aa576b1df@googlegroups.com> References: <5eacd83f-03c9-43b5-b799-733aa576b1df@googlegroups.com> Message-ID: <4FEC9503.4040201@gmail.com> On 6/28/2012 12:11 PM, David Thomas wrote: > Hi, > I have the following error regarding a loop tutorial found on http://www.sthurlow.com/python/lesson04/ > >>>> a=0 >>>> while a<10: > ... a=a+1 > File "", line 2 > a=a+1 > ^ > IndentationError: expected an indented block You indented in the IDE, but not in the interpreter. Indent with a space or a tab. In Python, indentation is syntactically important. Everything indented will be part of that while loop; the next line that isn't indented will be considered not part of the loop. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From tjreedy at udel.edu Thu Jun 28 13:33:49 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Jun 2012 13:33:49 -0400 Subject: TKinter Frame Size automatic In-Reply-To: <04c56243-cce8-476c-a228-49fd703834a1@googlegroups.com> References: <04c56243-cce8-476c-a228-49fd703834a1@googlegroups.com> Message-ID: On 6/28/2012 9:07 AM, hkaratoy at gmail.com wrote: > I have a question about the frame size. > > I want to create Tabbed window. There will be one Window and tabs in > this window. The page will be displayed whenever the user press the > corresponding tab. This is simple NoteBook behaviour from Tkinter. I > do not want to set the master window size but I want to make it > dynamic regarding to the largest tabbed window. Normally, like in a browser, tabs display text of unknown, variable size and take their size from the master window. If the tabs display fixed-sized forms, for instance, I would expect that you could resize the main window after inserting tab widgets but before displaying. If not, you should be to create the widgets first, find the largest height and width, create the master, and then put the widgets into the master, changing their 'master' attribute. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Thu Jun 28 13:43:53 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Jun 2012 17:43:53 GMT Subject: retry many times decorator References: <4FEC8278.7020806@mrabarnett.plus.com> Message-ID: <4fec97d9$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 28 Jun 2012 17:26:36 +0100, andrea crotti wrote: >> Returning a boolean isn't very Pythonic. It would be better, IMHO, if >> it could swallow a specified exception (or specified exceptions?) >> raised when an attempt failed, up to the maximum permitted number of >> attempts. If the final attempt fails, propagate the exception. -- >> http://mail.python.org/mailman/listinfo/python-list > > > Yes right I also didn't like it.. Now it become something as below, so > I capture every possible exception (since it must be generic) I disagree. If you make a coding error in your function, why do you think it is useful to retry that buggy code over and over again? It's never going to get less buggy unless you see the exception and fix the bug. For any operation that you want to retry, identify the *temporary* errors, catch them, and retry the request. *Permanent* errors should immediately fail, without retrying. *Unexpected* errors should not be caught, since they probably represent a bug in your code. E.g. when trying to read a HTTP resource, there is no point retrying a 400 Bad Request repeatedly, and it is rather anti-social to keep hammering a website when it's already told you that your syntax is wrong. Likewise, if you get 401, there is no point in retrying with the exact same request -- you need a *different* request, this time using authentication. A 403 is a permanent error and there's no point in retrying. A 404 might be temporary (although it probably isn't). A 503 or 504 is likely to be temporary. And so forth. http://en.wikipedia.org/wiki/List_of_HTTP_status_codes And if you get an unexpected AttributeError: 'NoneType' object has no attribute 'read' (as I just did today, in one of my scripts), that's a bug that should be fixed. Almost any other resource you might try is likely to have similar responses: some errors will indicate temporary failures, others will be permanent, and some will indicate a bug in your code. I think it is rude and pointless to repeatedly retry the same failed request if it cannot possibly succeed. I also find that exponential backoff for the delay is best. E.g. wait 1 second after the first failed attempt, 2 seconds after the second, 4 seconds after the third, 8 seconds after the fourth, etc. -- Steven From tjreedy at udel.edu Thu Jun 28 13:57:25 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Jun 2012 13:57:25 -0400 Subject: moving methods from class to instance of other class In-Reply-To: References: Message-ID: On 6/28/2012 2:59 AM, lars van gemerden wrote: > class A(object): > def __init__(self): > self.name = 'a' > def do(self): > print 'A.do: self.name =', self.name > > class B(object): > def __init__(self): > self.name = 'b' > > The question is: How do i move the 'do' method from A to b > (resulting in printing "A.do: self.name = b")? If you want to move the method from class A to class B (which is normally more sensible than to instance b of B) B.do = A.do.im_func # Python 2 B.do = A.do # Python 3 b = B() b.do() # print (with print adjusted for PY3) A.do: self.name = b If you want a B instance to act like an A instance, you can change its class (subject to some limitations). The following works. b = B() b.__class__ = A b.do() If make the change temporary and the reversion automatic, write a context manager. -- Terry Jan Reedy From dthomas86 at me.com Thu Jun 28 14:22:32 2012 From: dthomas86 at me.com (David Thomas) Date: Thu, 28 Jun 2012 11:22:32 -0700 (PDT) Subject: Following syntax error in Mac OX10.7 Terminal In-Reply-To: References: <5eacd83f-03c9-43b5-b799-733aa576b1df@googlegroups.com> Message-ID: Thank you very much I didn't realise that the indentation was important. The IDE indents automatically whilst terminal doesn't. Thanks for pointing it out. From roel at roelschroeven.net Thu Jun 28 15:08:29 2012 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 28 Jun 2012 21:08:29 +0200 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help In-Reply-To: References: Message-ID: Temia Eszteri schreef: > Actually, I believe someone in an earlier thread in the newsgroup or > elsewhere pointed out that serial ports automatically open under > Windows. I'd have to look it back up when I have the time, which I > don't have at the moment, unfortunately. That doesn't have anything to do with Windows, but with how pySerial works. See the documentation for __init__(): "The port is immediately opened on object creation, when a port is given. It is not opened when port is None and a successive call to open() will be needed." So if your script does something like prt = serial.Serial('COM4') then pySerial automatically opens the port, and you shouldn't call prt.open() anymore. If, on the contrary, you do something like prt = serial.Serial() prt.port = 'COM4' then pySerial doesn't open the port, and you have to call prt.open() to do it. PySerial has this same behavior on both Windows and Linux. The difference might be that on Linux it is possible to open serial ports more than once, while that doesn't work on Windows. Best regards, Roel From roel at roelschroeven.net Thu Jun 28 15:14:37 2012 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 28 Jun 2012 21:14:37 +0200 Subject: Slow output In-Reply-To: <53d49cb1-a68a-49c4-b925-b8a910ac415a@googlegroups.com> References: <53d49cb1-a68a-49c4-b925-b8a910ac415a@googlegroups.com> Message-ID: subhabangalore at gmail.com schreef: > Dear Group, > I am Sri Subhabrata Banerjee writing from India. I am running a small > program which exploits around 12 1 to 2 KB .txt files. I am using MS > Windows XP Service Pack 3 and Python 2.6 where IDLE is GUI. The text > is plain ASCII text. The RAM of the machine is around 2 GB. To run > the program the machine is becoming dead slow and it is executing > only after several minutes. I am shocked as I have run hugely loaded > Statistical Learning stuff only on 516MB RAM on Python using Windows > XP only. And that too on a laptop. I am not getting. I discussed the > issue with my system administrator and he increased the RAM to 8GB > result improved by 30% but not satisfactory speed. May any one > suggest me what may be the likely issue? Does the program generate a lot of text? Do you run the program in IDLE? IDLE gets very slow when it has to show a lot of text. Try running the program from the command line to see if that offers any improvement. Best regards, Roel From fabiofz at gmail.com Thu Jun 28 16:26:37 2012 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 28 Jun 2012 17:26:37 -0300 Subject: PyDev 2.6.0 Released Message-ID: Hi All, PyDev 2.6.0 has been released Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- Interactive console: * It's now possible to use the interactive console attached to a debug session. (patch from Hussain Bohra) To use this feature either right-click a frame in the debug view and choosing PyDev > Debug console or create a new Interactive console as usual (Ctrl+Alt+Enter and choose 'PyDev Debug Console' -- but note that this option will only be enabled when in a debug session with a selected frame in the Debug view. * Fixed issue where completions from the console did not work properly with '%' because quoting was not being properly done. * Fixed issue where the execfile() redefinition in the PyDev console did not use the proper globals * When launching interactive console, PYTHONPATH order is properly kept (patch from James Blackburn). * Fix pasting into the middle of the console (patch from James Blackburn). * For paste, only go to the end of the line if the cursor isn't in range (patch from James Blackburn). PyUnit: * Improved preferences page configuration (links shown to add options). * Improved test discovery in PyDev PyUnit runner (exclude/include files/tests options added). Jython: * print may be used in dotted names as Jython requires for grammars 2.4 and 2.5. Others: * In a build, PyDev could end up reading the contents of files unrelated to Python. * Django project startup compatible with django 1.4. * Assignments to builtins when in the class-level no longer generate a warning. * Fixed issue starting new thread in the debugger (fix for paste/waitress). * Fixed error configuring interpreter if os.path was not present. * Fixed issue when configuring interpreter which has unicode characters in the PYTHONPATH. * When searching for external files, also take a look at the configured projects, as it may be that the file should actually be found in an external source folder. * Fixed issues getting marker on files with a dirty editor and where we could end up getting markers from other files. * The scripting output console is not shown unless there's actually some output to show. * A bunch of other minor fixes. What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Appcelerator http://appcelerator.com/ Aptana http://aptana.com/ PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From adam at no_thanks.com Thu Jun 28 16:31:48 2012 From: adam at no_thanks.com (Adam) Date: Thu, 28 Jun 2012 13:31:48 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied - please help References: Message-ID: "Grant Edwards" wrote in message news:jshotj$s55$1 at reader1.panix.com... > On 2012-06-28, Adam wrote: > >> Obviously pySerial considers the serial port open > > Because it's already been opened by the Python program. > >> and will not open an already open serial port. > > Pyserial will happily try if you call the open() of a port that's > already open, but Windows will return an error. > >> However, why is it that TeraTerm can open the serial port? > > Because TeraTerm only opens it once. > >> Here's the link where I read about calling ser.close() before >> ser.open() ... >> >> Trying to open a serial port with pyserial on WinXP -> "Access denied" >> >> http://stackoverflow.com/questions/2063257/trying-to-open-a-serial-port-with-pyserial-on-winxp-access-denied > > That code is broken. > > The port is opened by this line: > > self.ser=serial.Serial(port='\\.\COM1', baudrate=9600, > bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, > stopbits=serial.STOPBITS_ONE, timeout=1) > > And then the author tries to _open_it_a_second_time_ here: > > self.ser.open() > >> Here's the Python scripts ... >> https://github.com/adafruit/Tweet-a-Watt/downloads >> Click on the "Download as ..." button for the Python scripts > > Like I kept telling you, those programs are trying to re-open a port > that they've already open. Here's the erroneous code: > > wattcher.py: > > 53 > 54 # open up the FTDI serial port to get data transmitted to xbee > 55 ser = serial.Serial(SERIALPORT, BAUDRATE) > 56 ser.open() > 57 > > Line 55 opens the serial port. > > Line 56 tries to _open_it_again_. _The_port_is_already_open_. > Windows doesn't allow a serial port to be opened twice, therefore the > ser.open() call raises an exception. > > Just delete line 56. > > > The same thing happens here: > > gmeter-wattcher.py > > 83 > 84 # open up the FTDI serial port to get data transmitted to xbee > 85 ser = serial.Serial(SERIALPORT, BAUDRATE) > 86 ser.open() > 87 > > Just delete line 86. > > See how simple it was to get the problem solved once you posted the > actual code? > > -- > Grant Edwards grant.b.edwards Yow! HUMAN REPLICAS are > at inserted into VATS of > gmail.com NUTRITIONAL YEAST ... Thanks, Grant ! From andrea.crotti.0 at gmail.com Thu Jun 28 17:11:44 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 28 Jun 2012 22:11:44 +0100 Subject: retry many times decorator In-Reply-To: <4fec97d9$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <4FEC8278.7020806@mrabarnett.plus.com> <4fec97d9$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FECC890.1030202@gmail.com> On 06/28/2012 06:43 PM, Steven D'Aprano wrote: > On Thu, 28 Jun 2012 17:26:36 +0100, andrea crotti wrote: > > > I disagree. If you make a coding error in your function, why do you think > it is useful to retry that buggy code over and over again? It's never > going to get less buggy unless you see the exception and fix the bug. > > For any operation that you want to retry, identify the *temporary* > errors, catch them, and retry the request. *Permanent* errors should > immediately fail, without retrying. *Unexpected* errors should not be > caught, since they probably represent a bug in your code. Ah well maybe I wasn't clear, but I'm not going to retry random things, I will only decorate the functions that I know for sure that could go wrong for temporary network problems. For example they told me that sometimes mysql just doesn't respond in time for some reasons, but there's nothing permanently wrong, so retrying is the best option.. It would be good of course, however, to catch the exceptions that are known to be permanent problems in the function at least, and leave the retry as last resource.. Thanks for the idea of the exponential backoff, which is also a better name than timeout for the variable.. From howmuchistoday at gmail.com Thu Jun 28 17:27:32 2012 From: howmuchistoday at gmail.com (howmuchistoday at gmail.com) Date: Thu, 28 Jun 2012 14:27:32 -0700 (PDT) Subject: Is there any way to decode String using unknown codec? In-Reply-To: References: Message-ID: <615e7c90-b240-43e3-a106-ed07c1ffc500@googlegroups.com> T 2012? 6? 28? ??? ?? 11? 20? 28? UTC+9, Benjamin Kaplan ?? ?: > On Wed, Jun 27, 2012 at 6:14 PM, wrote: > > Hi > > I'm a Korean and when I use modules like sys, os, &c, > > sometimes the interpreter show me broken strings like > > '\x13\xb3\x12\xc8'. > > It mustbe the Korean "alphabet" but I can't decode it to the rightway. > > I tried to decode it using codecs like cp949,mbcs,utf-8 > > but It failed. > > The only way I found is eval('\x13\xb3\x12\xc8'). > > It raises an Error with showing right Korean. > > Is there any way to deal it being not broken? > > -- > > It's not broken. You're just using the wrong encodings. Try utf-16le. Thank you guys. The problem is solved! From howmuchistoday at gmail.com Thu Jun 28 17:27:32 2012 From: howmuchistoday at gmail.com (howmuchistoday at gmail.com) Date: Thu, 28 Jun 2012 14:27:32 -0700 (PDT) Subject: Is there any way to decode String using unknown codec? In-Reply-To: References: Message-ID: <615e7c90-b240-43e3-a106-ed07c1ffc500@googlegroups.com> T 2012? 6? 28? ??? ?? 11? 20? 28? UTC+9, Benjamin Kaplan ?? ?: > On Wed, Jun 27, 2012 at 6:14 PM, wrote: > > Hi > > I'm a Korean and when I use modules like sys, os, &c, > > sometimes the interpreter show me broken strings like > > '\x13\xb3\x12\xc8'. > > It mustbe the Korean "alphabet" but I can't decode it to the rightway. > > I tried to decode it using codecs like cp949,mbcs,utf-8 > > but It failed. > > The only way I found is eval('\x13\xb3\x12\xc8'). > > It raises an Error with showing right Korean. > > Is there any way to deal it being not broken? > > -- > > It's not broken. You're just using the wrong encodings. Try utf-16le. Thank you guys. The problem is solved! From adam at no_thanks.com Thu Jun 28 17:48:08 2012 From: adam at no_thanks.com (Adam) Date: Thu, 28 Jun 2012 14:48:08 -0700 Subject: PySerial could not open port COM4: [Error 5] Access is denied- please help References: Message-ID: "Roel Schroeven" wrote in message news:mailman.1618.1340910525.4697.python-list at python.org... > Temia Eszteri schreef: >> Actually, I believe someone in an earlier thread in the newsgroup or >> elsewhere pointed out that serial ports automatically open under >> Windows. I'd have to look it back up when I have the time, which I >> don't have at the moment, unfortunately. > > That doesn't have anything to do with Windows, but with how pySerial > works. See the documentation for __init__(): > > "The port is immediately opened on object creation, when a port is given. > It is not opened when port is None and a successive call to open() will be > needed." > > So if your script does something like > > prt = serial.Serial('COM4') > > then pySerial automatically opens the port, and you shouldn't call > prt.open() anymore. > > If, on the contrary, you do something like > > prt = serial.Serial() > prt.port = 'COM4' > > then pySerial doesn't open the port, and you have to call prt.open() to do > it. > > PySerial has this same behavior on both Windows and Linux. The difference > might be that on Linux it is possible to open serial ports more than once, > while that doesn't work on Windows. > > Best regards, > Roel > Thanks for the info. Your explanation helps a lot. From vradhug at gmail.com Thu Jun 28 19:55:35 2012 From: vradhug at gmail.com (Flexton Inc) Date: Thu, 28 Jun 2012 16:55:35 -0700 (PDT) Subject: Seeking Python Programmer - San Jose, CA Message-ID: Hi, Do you love coding and Interested in exploring Python? OR Expert in Python, we have a requirement on Contract to Hire position with a well known client in Bay Area, CA Location: San Jose, CA Duration: 6-12 months Someone who loves coding with Python coding experience, UNIX background (solving complex Unix solutions), done Application work with Python, Web Services, Testing services, worked on large scale web sites. Please email me for more details: radha at flextoninc.com Looking forward to hear back from you!! Best Regards, Radha Gopal Krishna Technical Resource Manager Flexton Inc Tel: 408-845-9400 Ext :105 Email: radha at flextoninc.com URL: www.flextoninc.com From vradhug at gmail.com Thu Jun 28 19:55:58 2012 From: vradhug at gmail.com (Flexton Inc) Date: Thu, 28 Jun 2012 16:55:58 -0700 (PDT) Subject: Seeking Python Programmer - San Jose, CA Message-ID: Hi, Do you love coding and Interested in exploring Python? OR Expert in Python, we have a requirement on Contract to Hire position with a well known client in Bay Area, CA Location: San Jose, CA Duration: 6-12 months Someone who loves coding with Python coding experience, UNIX background (solving complex Unix solutions), done Application work with Python, Web Services, Testing services, worked on large scale web sites. Please email me for more details: radha at flextoninc.com Looking forward to hear back from you!! Best Regards, Radha Gopal Krishna Technical Resource Manager Flexton Inc Tel: 408-845-9400 Ext :105 Email: radha at flextoninc.com URL: www.flextoninc.com From ben+python at benfinney.id.au Thu Jun 28 20:56:31 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 29 Jun 2012 10:56:31 +1000 Subject: Seeking Python Programmer - San Jose, CA References: Message-ID: <871ukzrl4w.fsf@benfinney.id.au> Flexton Inc writes: > Do you love coding and Interested in exploring Python? OR Expert in > Python, we have a requirement on Contract to Hire position [?] Please do not use this forum for recruiting. Instead, use the Python Job Board for that purpose. -- \ ?There is something wonderful in seeing a wrong-headed majority | `\ assailed by truth.? ?John Kenneth Galbraith, 1989-07-28 | _o__) | Ben Finney From tyler at tysdomain.com Thu Jun 28 22:57:44 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Thu, 28 Jun 2012 20:57:44 -0600 Subject: code review Message-ID: <4FED19A8.8060201@tysdomain.com> Hello all: I was curious if someone wouldn't mind poking at some code. I have an idea for a game I want to write (and if this works I want to use this as a framework for another project), but I'd like to make sure I'm doing things correctly/there's not a better way to do things. My concern is I'm going to get way far into this, then realize I totally broke something. So, if someone wouldn't mind taking a peek I'd appreciate it. My concerns are: 1) style/cleanlyness: does everything look ok? 2) Workability: is there a better way to do what is there? 3) Speed: am I doing something that could be improved? I don't want to spend a ton of time looking for non-existent bottlenecks and trying to improve on them, but if I'm doing something that's bad, I'd like to fix it. The project page is at: http://code.google.com/p/pymud Any information is greatly appreciated. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From wuwei23 at gmail.com Thu Jun 28 23:58:15 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 28 Jun 2012 20:58:15 -0700 (PDT) Subject: code review References: Message-ID: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> On Jun 29, 12:57?pm, "Littlefield, Tyler" wrote: > I was curious if someone wouldn't mind poking at some code. > The project page is at:http://code.google.com/p/pymud > Any information is greatly appreciated. I couldn't find any actual code at that site, the git repository is currently empty. From steve+comp.lang.python at pearwood.info Fri Jun 29 03:31:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Jun 2012 07:31:04 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> Message-ID: <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 28 Jun 2012 20:58:15 -0700, alex23 wrote: > On Jun 29, 12:57?pm, "Littlefield, Tyler" wrote: >> I was curious if someone wouldn't mind poking at some code. The project >> page is at:http://code.google.com/p/pymud Any information is greatly >> appreciated. > > I couldn't find any actual code at that site, the git repository is > currently empty. Given that all code contains bugs, that's the best sort of repository! -- Steven From rosuav at gmail.com Fri Jun 29 03:42:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Jun 2012 17:42:17 +1000 Subject: code review In-Reply-To: <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jun 29, 2012 at 5:31 PM, Steven D'Aprano wrote: > Given that all code contains bugs, that's the best sort of repository! Only in the sense that a cheese shop can be lauded for its cleanliness... But I am somewhat curious to see the OP's actual code. MUDs are my personal specialty. ChrisA From rosuav at gmail.com Fri Jun 29 03:43:28 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Jun 2012 17:43:28 +1000 Subject: I can't send images to this mail-list In-Reply-To: References: Message-ID: On Thu, Jun 28, 2012 at 9:34 PM, ??? wrote: > hi,all: > ??? why can't I send images to python-list at python.org?? > It's a text-only list. Post your image to some free hosting somewhere and then include a link to it in your message, or - if possible - explain your issue/question in text. Chris Angelico From storchaka at gmail.com Fri Jun 29 04:14:09 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 29 Jun 2012 11:14:09 +0300 Subject: code review In-Reply-To: <4FED19A8.8060201@tysdomain.com> References: <4FED19A8.8060201@tysdomain.com> Message-ID: > The project page is at: > http://code.google.com/p/pymud > Any information is greatly appreciated. Do you mean https://github.com/benthomasson/pymud, http://pymud.blogspot.com/ or http://sourceforge.net/projects/pymud/ ? From andrea.crotti.0 at gmail.com Fri Jun 29 04:53:43 2012 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Fri, 29 Jun 2012 09:53:43 +0100 Subject: retry many times decorator In-Reply-To: <4FECC890.1030202@gmail.com> References: <4FEC8278.7020806@mrabarnett.plus.com> <4fec97d9$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FECC890.1030202@gmail.com> Message-ID: On the other hand now that I think again even supposing there is a permanent error like MySql completely down, retrying continuosly won't do any harm anyway because the machine will not be able to do anything else anyway, when someone will fix MySql it would restart again without human intervention. So I think I could even just let it retry and use maybe a SMTPHanlder for the logging errors, to make the notification of problems very quick.. From ramapraba2653 at gmail.com Fri Jun 29 05:39:56 2012 From: ramapraba2653 at gmail.com (SUPREME) Date: Fri, 29 Jun 2012 02:39:56 -0700 (PDT) Subject: SOUTH INDIAN HOT ACTRESS PHOTOS AND VIDEOS Message-ID: ALL INTERVIEW QUESTIONS& STUDY MATERIAL http://newdotnetinterviewquestions.blogspot.in/ TOP DATING TIPS TO ENCOURAGE WOMEN FOR DATING http://datingsitesdatingtips.blogspot.in/ FOR LATEST MOVIE UPDATED LINKS SULAGNA PANIGRAHI HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/06/sulagna-panigrahi-actress.html RUBY PARIHAR HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.com/2012/06/actress-ruby-parihar.html ACTRESS YAMI GOUTHAM LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/06/yami-gautam-actress.html ACTRESS HOT STILLS IN SIIMA AWARDS 2012 http://actressgallery-kalyani.blogspot.in/2012/06/actress-siima-awards-2012-stills.html EM BABU LADDU KAVALA MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/06/em-babu-laddu-kavala-movie-stills.html SRMANARAYANA MOVIE HOT STILLS http://actressgallery-kalyani.blogspot.in/2012/06/srimannarayana-movie-stills.html KAJAL AGARWAL LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/06/kajal-agarwal-latest-stills.html SANA KHAN LATEST HOT PHOTO GALLERY http://actressgallery-kalyani.blogspot.in/2012/06/sana-khan-latest-stills.html COOL BOYS HOT GIRLS MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/06/cool-boys-hot-girls-movie-stills.html MITAAYI MOVIE LATEST GALLERY http://actressgallery-kalyani.blogspot.in/2012/06/mitaayi-movie-stills.html NAGARJUNA DAMARUKAM MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/damarukam-movie-stills.html ALLU ARJUN JULAYI MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/julayi-movie-stills.html SUDIGADU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/05/sudigadu-movie-stills.html MR 7 MOVIE FILM GALLERY http://actressgallery-kalyani.blogspot.in/2012/05/mr7-movie-stills.html ALL THE BEST MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/all-best-movie-stills.html Midatha Telugu movie Hot Namitha Stills http://actressgallery-kalyani.blogspot.com/2012/05/midatha-movie-stills.html OKA COLLEGE LOVE STORY MOVIE STILLS http://actressgallery-kalyani.blogspot.in/2012/05/oka-college-love-story-movie-stills.html KATRINA KAIF LATEST UNSEENED PHOTOS http://actressgallery-kalyani.blogspot.com/2012/05/katrina-kaif-latest-pics.html TAMIL ACTRESS ARUNDHATI HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/05/arundhati-tamil-actress.html THANDHAVAM MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2012/05/thandavam-movie-stills.html KHO KHO LATEST MOVIE SPICY STILLS http://actressgallery-kalyani.blogspot.com/2012/05/kho-kho-movie-stills.html Oh My Love Movie Latest Photo Gallery http://actressgallery-kalyani.blogspot.com/2012/04/oh-my-love-movie-stills.html Oka Romantic Crime katha Movie stills http://actressgallery-kalyani.blogspot.in/2012/04/oka-romantic-crime-katha-movie-stills.html DARUVU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/03/daruvu-movie-stills.html Pavan Kalyan,Shruthi Hasan Gabbar Singh Movie Photos http://actressgallery-kalyani.blogspot.in/2012/04/gabbar-singh-movie-stills.html Good Morning Latest Movie Stills http://actressgallery-kalyani.blogspot.com/2012/04/good-morning-movie-stills.html EEGA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/04/eega-movie-stills.html Mem Vayasuku Vacham Latest Hot Stills http://actressgallery-kalyani.blogspot.com/2012/04/mem-vayasuku-vacham-stills.html DAMMU MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/04/dammu-movie-stills.html ILEANA LATEST HOT PHOTOSHOOT http://actressgallery-kalyani.blogspot.in/2012/01/ileana-latest-stills.html ACTREESS SUPRIYA SHAILJA LATEST STILLS http://actressgallery-kalyani.blogspot.in/2012/02/supriya-shailja-stills.html SHEELA LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2012/01/sheela-latest-stills.html KATRINA KAIF ITEM SONG STILLS http://actressgallery-kalyani.blogspot.com/2012/01/katrina-kaif-item-song-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html HOT KATRINA KAIF PHOTOS http://actressgallery-kalyani.blogspot.com/2011/09/katrina-kaif.html HOT LINKS FOR YOUTH ONLY PRANEETHA HOT SPICY IMAGES http://actressimages-9.blogspot.in/2012/06/praneetha-latest-stills.html SHRUTHI HASSAN HALF SAREE STILLS http://actressimages-9.blogspot.in/2012/05/shruti-hassan-half-saree-stills.html TAMANNA HOT NAVEL PHOTOS http://actressimages-9.blogspot.in/2012/05/tamanna-navel-photos.html TRISHA LATEST HOT STILLS http://actressgallery9.blogspot.in/2012/05/trisha.html MONIKA LATEST HOT HD STLLS http://actressgallery9.blogspot.in/2012/05/monika-stills.html MALLIKA KAPOOR HOT SIZZLING STILLS http://actressimages-9.blogspot.in/2012/05/mallika-kapoor.html Richa Panai Stills http://actressimages-9.blogspot.com/2012/04/richa-panai-stills.html MADHAVI LATHA LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/04/madhavi-latha-stills.html KRITI KHARBANDA HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/kriti-kharbanda.html NEELAM UPADHYAY HOT PHOTOSHOOT http://actressimages-9.blogspot.in/2012/03/neelam-upadhyay.html SAMANTHA LATEST HOT ROMANTIC STILLS http://actressimages-9.blogspot.in/2012/03/samantha-latest-stills.html NAYANTHARA HOT WALLPAPERS http://actressimages-9.blogspot.in/2012/01/nayanthara.html ANU SMRUTHI LATEST HOT STILLS http://actressimages-9.blogspot.in/2012/02/anu-smirthi-stills.html AISHWARYA RAI LATEST HOT PICS http://actressimages-9.blogspot.in/2012/01/aishwarya-rai.html From barber.justin at gmail.com Fri Jun 29 08:45:02 2012 From: barber.justin at gmail.com (Justin Barber) Date: Fri, 29 Jun 2012 05:45:02 -0700 (PDT) Subject: retry many times decorator In-Reply-To: References: <4FEC8278.7020806@mrabarnett.plus.com> <4fec97d9$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FECC890.1030202@gmail.com> Message-ID: <01e8fd76-3cdb-4ffc-9553-cd2d95d3c260@googlegroups.com> On Friday, June 29, 2012 4:53:43 AM UTC-4, andrea crotti wrote: > On the other hand now that I think again even supposing there is a > permanent error like MySql completely down, retrying continuosly > won't do any harm anyway because the machine will not be able to do > anything else anyway, when someone will fix MySql it would > restart again without human intervention. > > So I think I could even just let it retry and use maybe a SMTPHanlder > for the logging errors, to make the notification of problems very > quick.. Rather then write a decorator, sounds like you should write your own class or method connecting to the database that has the ability to retry. Are you finding you are decorating only db calls or are you decorating all sorts of stuff? From barber.justin at gmail.com Fri Jun 29 08:45:02 2012 From: barber.justin at gmail.com (Justin Barber) Date: Fri, 29 Jun 2012 05:45:02 -0700 (PDT) Subject: retry many times decorator In-Reply-To: References: <4FEC8278.7020806@mrabarnett.plus.com> <4fec97d9$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FECC890.1030202@gmail.com> Message-ID: <01e8fd76-3cdb-4ffc-9553-cd2d95d3c260@googlegroups.com> On Friday, June 29, 2012 4:53:43 AM UTC-4, andrea crotti wrote: > On the other hand now that I think again even supposing there is a > permanent error like MySql completely down, retrying continuosly > won't do any harm anyway because the machine will not be able to do > anything else anyway, when someone will fix MySql it would > restart again without human intervention. > > So I think I could even just let it retry and use maybe a SMTPHanlder > for the logging errors, to make the notification of problems very > quick.. Rather then write a decorator, sounds like you should write your own class or method connecting to the database that has the ability to retry. Are you finding you are decorating only db calls or are you decorating all sorts of stuff? From ben+python at benfinney.id.au Fri Jun 29 09:08:03 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 29 Jun 2012 23:08:03 +1000 Subject: I can't send images to this mail-list References: Message-ID: <87k3yqqn9o.fsf@benfinney.id.au> Chris Angelico writes: > On Thu, Jun 28, 2012 at 9:34 PM, ??? wrote: > > ??? why can't I send images to python-list at python.org?? > > It's a text-only list. I'll take this opportunity to give heartfelt thanks to the administrators for that policy; please keep this a text-only forum. -- \ ?Come on Milhouse, there?s no such thing as a soul! It?s just | `\ something they made up to scare kids, like the Boogie Man or | _o__) Michael Jackson.? ?Bart, _The Simpsons_ | Ben Finney From tyler at tysdomain.com Fri Jun 29 10:44:55 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Fri, 29 Jun 2012 08:44:55 -0600 Subject: code review In-Reply-To: References: <4FED19A8.8060201@tysdomain.com> Message-ID: <4FEDBF67.5060702@tysdomain.com> On 6/29/2012 2:14 AM, Serhiy Storchaka wrote: >> The project page is at: >> http://code.google.com/p/pymud >> Any information is greatly appreciated. > > Do you mean > No, I mean http://code.google.com/p/pymud -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From tyler at tysdomain.com Fri Jun 29 11:03:22 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Fri, 29 Jun 2012 09:03:22 -0600 Subject: code review In-Reply-To: <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FEDC3BA.6060502@tysdomain.com> On 6/29/2012 1:31 AM, Steven D'Aprano wrote: > On Thu, 28 Jun 2012 20:58:15 -0700, alex23 wrote: > >> On Jun 29, 12:57 pm, "Littlefield, Tyler" wrote: >>> I was curious if someone wouldn't mind poking at some code. The project >>> page is at:http://code.google.com/p/pymud Any information is greatly >>> appreciated. >> I couldn't find any actual code at that site, the git repository is >> currently empty. OOPS, sorry. Apparently I'm not as good with git as I thought. Everything's in the repo now. From dthomas86 at me.com Fri Jun 29 11:13:44 2012 From: dthomas86 at me.com (David Thomas) Date: Fri, 29 Jun 2012 08:13:44 -0700 (PDT) Subject: Re Following syntax error in Mac OX10.7 Terminal In-Reply-To: <871ukzs5rx.fsf@gmail.com> References: <871ukzs5rx.fsf@gmail.com> Message-ID: <7e3890e4-3225-47f1-99e8-e5574c6413ef@googlegroups.com> On Thursday, June 28, 2012 6:30:42 PM UTC+1, Sergi Pasoev wrote: > You just have to consider that indentation matters in Python, so you > have to type the code in Python interpreter as you have written it > below, that is, press Tab before each line when you are inside the > 'while (or any other like for, if, with, etc.) block. > > a=0 > while a<10: > a=a+1 > print a > > I can guess from your message that you aren't aware of one very > important Python feature, and maybe you also didn't willingly choose to > learn Python2 instead of Python3 ? In this case I would advise you to > consider both versions before choosing. Hi yeah I'm currently learning python 2 at the moment and the tutorial that I am studying doesn't explain about indentation. From python at mrabarnett.plus.com Fri Jun 29 11:21:56 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 29 Jun 2012 16:21:56 +0100 Subject: Re Following syntax error in Mac OX10.7 Terminal In-Reply-To: <7e3890e4-3225-47f1-99e8-e5574c6413ef@googlegroups.com> References: <871ukzs5rx.fsf@gmail.com> <7e3890e4-3225-47f1-99e8-e5574c6413ef@googlegroups.com> Message-ID: <4FEDC814.7050903@mrabarnett.plus.com> On 29/06/2012 16:13, David Thomas wrote: > On Thursday, June 28, 2012 6:30:42 PM UTC+1, Sergi Pasoev wrote: >> You just have to consider that indentation matters in Python, so you >> have to type the code in Python interpreter as you have written it >> below, that is, press Tab before each line when you are inside the >> 'while (or any other like for, if, with, etc.) block. >> >> a=0 >> while a<10: >> a=a+1 >> print a >> >> I can guess from your message that you aren't aware of one very >> important Python feature, and maybe you also didn't willingly choose to >> learn Python2 instead of Python3 ? In this case I would advise you to >> consider both versions before choosing. > > Hi yeah I'm currently learning python 2 at the moment and the tutorial that > I am studying doesn't explain about indentation. > Really? Indentation is a basic feature of Python! From ethan at stoneleaf.us Fri Jun 29 11:26:58 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 29 Jun 2012 08:26:58 -0700 Subject: I can't send images to this mail-list In-Reply-To: <87k3yqqn9o.fsf@benfinney.id.au> References: <87k3yqqn9o.fsf@benfinney.id.au> Message-ID: <4FEDC942.8010509@stoneleaf.us> Ben Finney wrote: > Chris Angelico writes: >> ??? wrote: >>> why can't I send images to python-list at python.org?? >> >> It's a text-only list. > > I'll take this opportunity to give heartfelt thanks to the > administrators for that policy; please keep this a text-only forum. +1000 From dthomas86 at me.com Fri Jun 29 11:58:57 2012 From: dthomas86 at me.com (David Thomas) Date: Fri, 29 Jun 2012 08:58:57 -0700 (PDT) Subject: Re Following syntax error in Mac OX10.7 Terminal In-Reply-To: References: <871ukzs5rx.fsf@gmail.com> <7e3890e4-3225-47f1-99e8-e5574c6413ef@googlegroups.com> Message-ID: <4c2a80da-70bd-48c0-92c9-c7182d3578b3@googlegroups.com> On Friday, June 29, 2012 4:21:56 PM UTC+1, MRAB wrote: > On 29/06/2012 16:13, David Thomas wrote: > > On Thursday, June 28, 2012 6:30:42 PM UTC+1, Sergi Pasoev wrote: > >> You just have to consider that indentation matters in Python, so you > >> have to type the code in Python interpreter as you have written it > >> below, that is, press Tab before each line when you are inside the > >> 'while (or any other like for, if, with, etc.) block. > >> > >> a=0 > >> while a<10: > >> a=a+1 > >> print a > >> > >> I can guess from your message that you aren't aware of one very > >> important Python feature, and maybe you also didn't willingly choose to > >> learn Python2 instead of Python3 ? In this case I would advise you to > >> consider both versions before choosing. > > > > Hi yeah I'm currently learning python 2 at the moment and the tutorial that > > I am studying doesn't explain about indentation. > > > Really? Indentation is a basic feature of Python! while {condition that the loop continues}: {what to do in the loop} {have it indented, usually four spaces} {the code here is not looped} {because it isn't indented} Just discovered this in the tutorial further down. I'm currently learning Python 2 because there seems to be a lot of tutorials out there covering Python 2 rather than 3. Thanks for the help this community is great for help. From dthomas86 at me.com Fri Jun 29 11:58:57 2012 From: dthomas86 at me.com (David Thomas) Date: Fri, 29 Jun 2012 08:58:57 -0700 (PDT) Subject: Re Following syntax error in Mac OX10.7 Terminal In-Reply-To: References: <871ukzs5rx.fsf@gmail.com> <7e3890e4-3225-47f1-99e8-e5574c6413ef@googlegroups.com> Message-ID: <4c2a80da-70bd-48c0-92c9-c7182d3578b3@googlegroups.com> On Friday, June 29, 2012 4:21:56 PM UTC+1, MRAB wrote: > On 29/06/2012 16:13, David Thomas wrote: > > On Thursday, June 28, 2012 6:30:42 PM UTC+1, Sergi Pasoev wrote: > >> You just have to consider that indentation matters in Python, so you > >> have to type the code in Python interpreter as you have written it > >> below, that is, press Tab before each line when you are inside the > >> 'while (or any other like for, if, with, etc.) block. > >> > >> a=0 > >> while a<10: > >> a=a+1 > >> print a > >> > >> I can guess from your message that you aren't aware of one very > >> important Python feature, and maybe you also didn't willingly choose to > >> learn Python2 instead of Python3 ? In this case I would advise you to > >> consider both versions before choosing. > > > > Hi yeah I'm currently learning python 2 at the moment and the tutorial that > > I am studying doesn't explain about indentation. > > > Really? Indentation is a basic feature of Python! while {condition that the loop continues}: {what to do in the loop} {have it indented, usually four spaces} {the code here is not looped} {because it isn't indented} Just discovered this in the tutorial further down. I'm currently learning Python 2 because there seems to be a lot of tutorials out there covering Python 2 rather than 3. Thanks for the help this community is great for help. From ben+python at benfinney.id.au Fri Jun 29 12:02:26 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 30 Jun 2012 02:02:26 +1000 Subject: Re Following syntax error in Mac OX10.7 Terminal References: <871ukzs5rx.fsf@gmail.com> <7e3890e4-3225-47f1-99e8-e5574c6413ef@googlegroups.com> Message-ID: <87fw9eqf71.fsf@benfinney.id.au> David Thomas writes: > Hi yeah I'm currently learning python 2 at the moment and the tutorial > that I am studying doesn't explain about indentation. You might be better served by the official Python tutorial . If you work through it from beginning to end, doing each exercise and experimenting to be sure you understand before moving through, you will get a good grounding in the fundamentals of the language. -- \ ?Don't worry about what anybody else is going to do. The best | `\ way to predict the future is to invent it.? ?Alan Kay | _o__) | Ben Finney From s.pasoev at gmail.com Fri Jun 29 12:12:08 2012 From: s.pasoev at gmail.com (Sergi Pasoev) Date: Fri, 29 Jun 2012 20:12:08 +0400 Subject: Re Re Following syntax error in Mac OX10.7 Terminal Message-ID: <87d34i9jxj.fsf@gmail.com> > Just discovered this in the tutorial further down. I'm currently > learning Python 2 because there seems to be a lot of tutorials out there > covering Python 2 rather than 3. While deciding which version of Python to learn, a better counsel could be found here: http://wiki.python.org/moin/Python2orPython3 From Joshua.R.English at gmail.com Fri Jun 29 12:31:53 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Fri, 29 Jun 2012 09:31:53 -0700 (PDT) Subject: format() not behaving as expected Message-ID: <7d1714cb-7aea-4048-bdc5-1b65d0f6c109@googlegroups.com> I have a list of tuples, and usually print them using: print c, " ".join(map(str, list_of_tuples)) This is beginning to feel clunky (but gives me essentially what I want), and I thought there was a better, more concise, way to achieve this, so I explored the new string format and format() function: >>> c = (1,3) >>> s = "{0[0]}" >>> print s.format(c) '1' >>> print format(c,s) Traceback (most recent call last): File "", line 1, in ValueError: Invalid conversion specification I'm running *** Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32. *** (This is actually a PortablePython run on a Windows 7 machine) Any idea why one form works and the other doesn't? From g.rodola at gmail.com Fri Jun 29 12:59:50 2012 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Fri, 29 Jun 2012 18:59:50 +0200 Subject: ANN: psutil 0.5.0 released In-Reply-To: References: Message-ID: 2012/6/27 Giampaolo Rodol? : > Hi folks, > I'm pleased to announce the 0.5.0 release of psutil: > http://code.google.com/p/psutil/ > > === Major new features === > > - system users > - (Linux, Windows) process CPU affinity (get and set) > - (POSIX) process number of opened file descriptors. > - (Windows) process number of opened handles. > - psutil.disk_partitions() now provides also mount options > - new Process.as_dict() method. > - Process.get_children(recursive=True): return all process descendants. > - 2to3 is not longer required to run at installation time in order to > support Python 3 > - ppid, name, exe, cmdline and create_time properties of Process class > are now cached after being accessed. > - psutil.process_iter() now caches Process instances between calls. > > For a complete list of features and bug fixes see: > http://psutil.googlecode.com/svn/trunk/HISTORY > > > === New features by example === > >>>> import psutil, os >>>> >>>> psutil.get_users() > [user(name='giampaolo', terminal='pts/2', host='localhost', > started=1340737536.0), > ?user(name='giampaolo', terminal='pts/3', host='localhost', > started=1340737792.0)] >>>> >>>> psutil.disk_partitions() > [partition(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'), > ?partition(device='/dev/sda2', mountpoint='/home', fstype='ext, opts='rw')] >>>> >>>> p = psutil.Process(os.getpid()) >>>> p.get_num_fds() > 4 >>>> >>>> p.get_num_handles() ?# windows only > 254 >>>> >>>> p.get_memory_maps() > [mmap(path='/lib/x86_64-linux-gnu/libutil-2.15.so', rss=16384, > anonymous=8192, swap=0), > ?mmap(path='/lib/x86_64-linux-gnu/libc-2.15.so', rss=6384, > anonymous=15, swap=0), > ?mmap(path='/lib/x86_64-linux-gnu/libcrypto.so.1.0.0', rss=34124, > anonymous=1245, swap=0), > ?mmap(path='[heap]', rss=54653, anonymous=8192, swap=0), > ?mmap(path='[stack]', rss=1542, anonymous=166, swap=0), > ?...] >>>> >>>> p.as_dict() > {'status': 0, 'pid': 29510, 'connections': [], 'cmdline': ['python'], ...} >>>> >>>> p.get_cpu_affinity() > [0, 1, 2, 3] >>>> p.set_cpu_affinity([0]) >>>> >>>> p.get_children(recursive=True) > [, , ...] >>>> > > > === Links === > > * Home page: http://code.google.com/p/psutil > * Source tarball: http://psutil.googlecode.com/files/psutil-0.5.0.tar.gz > * Api Reference: http://code.google.com/p/psutil/wiki/Documentation > > > Please try out this new release and let me know if you experience any > problem by filing issues on the bug tracker. > Thanks in advance. > > > --- Giampaolo Rodola' > > http://code.google.com/p/pyftpdlib/ > http://code.google.com/p/psutil/ > http://code.google.com/p/pysendfile/ A last-moment bug on Windows appeared. Please ignore 0.5.0 version and download 0.5.1: http://psutil.googlecode.com/files/psutil-0.5.1.tar.gz --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ From python at mrabarnett.plus.com Fri Jun 29 13:02:45 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 29 Jun 2012 18:02:45 +0100 Subject: format() not behaving as expected In-Reply-To: <7d1714cb-7aea-4048-bdc5-1b65d0f6c109@googlegroups.com> References: <7d1714cb-7aea-4048-bdc5-1b65d0f6c109@googlegroups.com> Message-ID: <4FEDDFB5.40608@mrabarnett.plus.com> On 29/06/2012 17:31, Josh English wrote: > I have a list of tuples, and usually print them using: > > print c, " ".join(map(str, list_of_tuples)) > > This is beginning to feel clunky (but gives me essentially what I want), and I thought there was a better, more concise, way to achieve this, so I explored the new string format and format() function: > >>>> c = (1,3) >>>> s = "{0[0]}" >>>> print s.format(c) > '1' >>>> print format(c,s) > Traceback (most recent call last): > File "", line 1, in > ValueError: Invalid conversion specification > > I'm running *** Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32. *** > (This is actually a PortablePython run on a Windows 7 machine) > > Any idea why one form works and the other doesn't? > The ".format" method accepts multiple arguments, so the placeholders in the format string need to specify which argument to format as well as how to format it (the format specification after the ":"). The "format" function, on the other hand, accepts only a single argument to format, so it needs only the format specification, and therefore can't accept subscripting or attributes. >>> c = "foo" >>> print "{0:s}".format(c) foo >>> format(c, "s") 'foo' From steve+comp.lang.python at pearwood.info Fri Jun 29 13:08:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Jun 2012 17:08:20 GMT Subject: format() not behaving as expected References: <7d1714cb-7aea-4048-bdc5-1b65d0f6c109@googlegroups.com> Message-ID: <4fede104$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 29 Jun 2012 09:31:53 -0700, Josh English wrote: > I have a list of tuples, and usually print them using: > > print c, " ".join(map(str, list_of_tuples)) > > This is beginning to feel clunky (but gives me essentially what I want), > and I thought there was a better, more concise, way to achieve this, so > I explored the new string format and format() function: > >>>> c = (1,3) >>>> s = "{0[0]}" >>>> print s.format(c) > '1' That's not actually the output copied and pasted. You have quotes around the string, which you don't get if you pass it to the print command. >>>> print format(c,s) > Traceback (most recent call last): > File "", line 1, in > ValueError: Invalid conversion specification [...] > Any idea why one form works and the other doesn't? Because the format built-in function is not the same as the format string method. The string method takes brace substitutions, like "{0[0]}" which returns the first item of the first argument. The format function takes a format spec, not a brace substitution. For example: >>> format(c, '<10s') '(1, 3) ' >>> format(c, '>10s') ' (1, 3)' >>> format(c, '*>10s') '****(1, 3)' The details of the format spec are in the Fine Manual: http://docs.python.org/library/string.html#formatspec although sadly all the examples are about using brace substitutions, not format specs. (Personally, I find the documentation about format to be less than helpful.) You can also read the PEP that introduced the new formatting, but keep in mind that there have been some changes since the PEP was written, so it may not quite match the current status quo. http://www.python.org/dev/peps/pep-3101/ -- Steven From Joshua.R.English at gmail.com Fri Jun 29 13:19:30 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Fri, 29 Jun 2012 10:19:30 -0700 (PDT) Subject: format() not behaving as expected In-Reply-To: References: <7d1714cb-7aea-4048-bdc5-1b65d0f6c109@googlegroups.com> Message-ID: On Friday, June 29, 2012 10:02:45 AM UTC-7, MRAB wrote: > > The ".format" method accepts multiple arguments, so the placeholders in > the format string need to specify which argument to format as well as > how to format it (the format specification after the ":"). > > The "format" function, on the other hand, accepts only a single > argument to format, so it needs only the format specification, and > therefore can't accept subscripting or attributes. > > >>> c = "foo" > >>> print "{0:s}".format(c) > foo > >>> format(c, "s") > 'foo' Thank you. That's beginning to make sense to me. If I understand this, everything between the braces is the format specification, and the format specification doesn't include the braces, right? Josh From Joshua.R.English at gmail.com Fri Jun 29 13:19:30 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Fri, 29 Jun 2012 10:19:30 -0700 (PDT) Subject: format() not behaving as expected In-Reply-To: References: <7d1714cb-7aea-4048-bdc5-1b65d0f6c109@googlegroups.com> Message-ID: On Friday, June 29, 2012 10:02:45 AM UTC-7, MRAB wrote: > > The ".format" method accepts multiple arguments, so the placeholders in > the format string need to specify which argument to format as well as > how to format it (the format specification after the ":"). > > The "format" function, on the other hand, accepts only a single > argument to format, so it needs only the format specification, and > therefore can't accept subscripting or attributes. > > >>> c = "foo" > >>> print "{0:s}".format(c) > foo > >>> format(c, "s") > 'foo' Thank you. That's beginning to make sense to me. If I understand this, everything between the braces is the format specification, and the format specification doesn't include the braces, right? Josh From Joshua.R.English at gmail.com Fri Jun 29 13:24:58 2012 From: Joshua.R.English at gmail.com (Josh English) Date: Fri, 29 Jun 2012 10:24:58 -0700 (PDT) Subject: format() not behaving as expected In-Reply-To: <4fede104$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <7d1714cb-7aea-4048-bdc5-1b65d0f6c109@googlegroups.com> <4fede104$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <61b63296-d7d5-4c1f-9055-d4e0c3113cb5@googlegroups.com> On Friday, June 29, 2012 10:08:20 AM UTC-7, Steven D'Aprano wrote: > >>>> c = (1,3) > >>>> s = "{0[0]}" > >>>> print s.format(c) > > '1' > > That's not actually the output copied and pasted. You have quotes around > the string, which you don't get if you pass it to the print command. > Mea culpa. I typed it in manually because the direct copy and paste was rather ugly full of errors because of many haplographies. > >>>> print format(c,s) > > Traceback (most recent call last): > > File "", line 1, in > > ValueError: Invalid conversion specification > [...] > > Any idea why one form works and the other doesn't? > > Because the format built-in function is not the same as the format string > method. ... > > (Personally, I find the documentation about format to be less than > helpful.) > Thanks. I think it's coming together. Either way, this format seems uglier than what I had before, and it's longer to type out. I suppose that's just programmers preference. Josh From python at mrabarnett.plus.com Fri Jun 29 13:41:29 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 29 Jun 2012 18:41:29 +0100 Subject: format() not behaving as expected In-Reply-To: References: <7d1714cb-7aea-4048-bdc5-1b65d0f6c109@googlegroups.com> Message-ID: <4FEDE8C9.8050401@mrabarnett.plus.com> On 29/06/2012 18:19, Josh English wrote: > On Friday, June 29, 2012 10:02:45 AM UTC-7, MRAB wrote: >> >> The ".format" method accepts multiple arguments, so the placeholders in >> the format string need to specify which argument to format as well as >> how to format it (the format specification after the ":"). >> >> The "format" function, on the other hand, accepts only a single >> argument to format, so it needs only the format specification, and >> therefore can't accept subscripting or attributes. >> >> >>> c = "foo" >> >>> print "{0:s}".format(c) >> foo >> >>> format(c, "s") >> 'foo' > > Thank you. That's beginning to make sense to me. If I understand this, > everything between the braces is the format specification, > and the format specification doesn't include the braces, right? > No, the format specification is the part after the ":" (if present), as in the example. Here are more examples: >>> c = "foo" >>> print "{0}".format(c) foo >>> format(c, "") 'foo' >>> print "To 2 decimal places: {0:0.2f}".format(1.2345) To 2 decimal places: 1.23 >>> print format(1.2345, "0.02f") 1.23 From chris at python.org Fri Jun 29 13:48:43 2012 From: chris at python.org (Chris Withers) Date: Fri, 29 Jun 2012 18:48:43 +0100 Subject: =?UTF-8?B?6L2s5Y+R77yaUmU6aG93IGNhbiBJIGltcGxlbWVudCAiY2QiIGw=?= =?UTF-8?B?aWtlIHNoZWxsIGluIFB5dGhvbj8=?= In-Reply-To: References: Message-ID: <4FEDEA7B.6040600@python.org> On 28/06/2012 12:39, ??? wrote: > > thanks !But this method can not change the directory of the main > process.For example: > the current directory is "/home/work/local/scripts",this directory have > a python script file "cd.py" > after executing the script cd.py by "python cd.py ..",the current work > directory has no changes,the path is still "/home/work/local/scripts" Sounds like you might want to give the ipython shell a go, since it has a lot of this already implemented. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From alister.ware at ntlworld.com Fri Jun 29 15:41:11 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 29 Jun 2012 19:41:11 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 29 Jun 2012 09:03:22 -0600, Littlefield, Tyler wrote: > On 6/29/2012 1:31 AM, Steven D'Aprano wrote: >> On Thu, 28 Jun 2012 20:58:15 -0700, alex23 wrote: >> >>> On Jun 29, 12:57 pm, "Littlefield, Tyler" wrote: >>>> I was curious if someone wouldn't mind poking at some code. The >>>> project page is at:http://code.google.com/p/pymud Any information is >>>> greatly appreciated. >>> I couldn't find any actual code at that site, the git repository is >>> currently empty. > > OOPS, sorry. Apparently I'm not as good with git as I thought. > Everything's in the repo now. I am no expert but from what have picked up so far from x import is frowned upon in most cases also this section in main strikes me as a bit odd and convoluted w = world() serv = server(client) w.server = serv serv.world = w I think you are cross referencing classes & would be better to investigate inheritance. -- The bogosity meter just pegged. From python at mrabarnett.plus.com Fri Jun 29 16:09:06 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 29 Jun 2012 21:09:06 +0100 Subject: code review In-Reply-To: References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FEE0B62.5020205@mrabarnett.plus.com> On 29/06/2012 20:41, Alister wrote: > On Fri, 29 Jun 2012 09:03:22 -0600, Littlefield, Tyler wrote: > >> On 6/29/2012 1:31 AM, Steven D'Aprano wrote: >>> On Thu, 28 Jun 2012 20:58:15 -0700, alex23 wrote: >>> >>>> On Jun 29, 12:57 pm, "Littlefield, Tyler" wrote: >>>>> I was curious if someone wouldn't mind poking at some code. The >>>>> project page is at:http://code.google.com/p/pymud Any information is >>>>> greatly appreciated. >>>> I couldn't find any actual code at that site, the git repository is >>>> currently empty. >> >> OOPS, sorry. Apparently I'm not as good with git as I thought. >> Everything's in the repo now. > > I am no expert but from what have picked up so far > > from x import > > is frowned upon in most cases > I think you mean: from x import * > also this section in main strikes me as a bit odd and convoluted > > w = world() > serv = server(client) > w.server = serv > serv.world = w > > I think you are cross referencing classes & would be better to > investigate inheritance. > > From breamoreboy at yahoo.co.uk Fri Jun 29 16:13:09 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 29 Jun 2012 21:13:09 +0100 Subject: I can't send images to this mail-list In-Reply-To: <4FEDC942.8010509@stoneleaf.us> References: <87k3yqqn9o.fsf@benfinney.id.au> <4FEDC942.8010509@stoneleaf.us> Message-ID: On 29/06/2012 16:26, Ethan Furman wrote: > Ben Finney wrote: >> Chris Angelico writes: >>> ??? wrote: >>>> why can't I send images to python-list at python.org?? > >> >>> It's a text-only list. >> >> I'll take this opportunity to give heartfelt thanks to the >> administrators for that policy; please keep this a text-only forum. > > +1000 > I also entirely agree with this policy, but I've told you a trillion times not to exaggerate :) -- Cheers. Mark Lawrence. From martin.hellwig at gmail.com Fri Jun 29 16:27:54 2012 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Fri, 29 Jun 2012 13:27:54 -0700 (PDT) Subject: code review In-Reply-To: References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1b4644e1-f406-4ced-b753-7038babad778@googlegroups.com> On Friday, 29 June 2012 20:41:11 UTC+1, Alister wrote: > On Fri, 29 Jun 2012 09:03:22 -0600, Littlefield, Tyler wrote: > > > On 6/29/2012 1:31 AM, Steven D'Aprano wrote: > >> On Thu, 28 Jun 2012 20:58:15 -0700, alex23 wrote: > >> > >>> On Jun 29, 12:57 pm, "Littlefield, Tyler" wrote: > >>>> I was curious if someone wouldn't mind poking at some code. The > >>>> project page is at:http://code.google.com/p/pymud Any information is > >>>> greatly appreciated. > >>> I couldn't find any actual code at that site, the git repository is > >>> currently empty. > > > > OOPS, sorry. Apparently I'm not as good with git as I thought. > > Everything's in the repo now. > > I am no expert but from what have picked up so far > > from x import > > is frowned upon in most cases from x import * is frowned upon, however, from x import y is fine IMHO. > > also this section in main strikes me as a bit odd and convoluted > > w = world() > serv = server(client) > w.server = serv > serv.world = w > > I think you are cross referencing classes & would be better to > investigate inheritance. > Generally speaking, read PEP8 and apply it please, there are tools like pylint that can help you with that. It also seems you are doing things quite java like, but I guess that is just a thing of getting used to python. If you are planning to let your code being used like a framework that is extended by others, try to avoid more advanced functions just because they seem handy, always ask yourself is it clearer? Try to unit-test your code and try to gain some decent code coverage, that will increase maturity of your code rather quickly. But for the rest it looks like you are good in organizing it all in sub-modules, which is a very nice thing to see. Good luck! -- mph From alister.ware at ntlworld.com Fri Jun 29 16:43:02 2012 From: alister.ware at ntlworld.com (Alister) Date: Fri, 29 Jun 2012 20:43:02 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <1b4644e1-f406-4ced-b753-7038babad778@googlegroups.com> Message-ID: On Fri, 29 Jun 2012 13:27:54 -0700, Martin P. Hellwig wrote: > On Friday, 29 June 2012 20:41:11 UTC+1, Alister wrote: >> On Fri, 29 Jun 2012 09:03:22 -0600, Littlefield, Tyler wrote: >> >> > On 6/29/2012 1:31 AM, Steven D'Aprano wrote: >> >> On Thu, 28 Jun 2012 20:58:15 -0700, alex23 wrote: >> >> >> >>> On Jun 29, 12:57 pm, "Littlefield, Tyler" >> >>> wrote: >> >>>> I was curious if someone wouldn't mind poking at some code. The >> >>>> project page is at:http://code.google.com/p/pymud Any information >> >>>> is greatly appreciated. >> >>> I couldn't find any actual code at that site, the git repository is >> >>> currently empty. >> > >> > OOPS, sorry. Apparently I'm not as good with git as I thought. >> > Everything's in the repo now. >> >> I am no expert but from what have picked up so far >> >> from x import >> >> is frowned upon in most cases > > from x import * is frowned upon, however, from x import y is fine IMHO. >> well I said I was no expert & picking things up. re investigation I see your reasoning and yes it was the from X import * I was thinking of. Although a simple import X retaining the name-space ref does make it easy to identify the origins of a function (at the expense of more typing) -- Flying is the second greatest feeling you can have. The greatest feeling? Landing... Landing is the greatest feeling you can have. From tyler at tysdomain.com Fri Jun 29 16:49:11 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Fri, 29 Jun 2012 14:49:11 -0600 Subject: code review In-Reply-To: References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4FEE14C7.3030700@tysdomain.com> I am no expert but from what have picked up so far from x import is frowned upon in most cases also this section in main strikes me as a bit odd and convoluted w = world() serv = server(client) w.server = serv serv.world = w I think you are cross referencing classes & would be better to investigate inheritance. From what I understand and how I've always employed it, inheritance is ment when you wish to give a class characteristics of another class. All I'm doing here is setting the world and server classes on each other, so they can call one another. This probably isn't needed in case of serv.server = w, but for sure the other way around. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From d at davea.name Fri Jun 29 21:59:41 2012 From: d at davea.name (Dave Angel) Date: Fri, 29 Jun 2012 21:59:41 -0400 Subject: I can't send images to this mail-list In-Reply-To: <9qcsu7hadmv6v9jj8jamk9sd9ustfsviga@invalid.netcom.com> References: <87k3yqqn9o.fsf@benfinney.id.au> <4FEDC942.8010509@stoneleaf.us> <9qcsu7hadmv6v9jj8jamk9sd9ustfsviga@invalid.netcom.com> Message-ID: <4FEE5D8D.6020601@davea.name> On 06/29/2012 06:59 PM, Dennis Lee Bieber wrote: > On Fri, 29 Jun 2012 21:13:09 +0100, Mark Lawrence > declaimed the following in > gmane.comp.python.general: > >> On 29/06/2012 16:26, Ethan Furman wrote: >>> Ben Finney wrote: >>>> Chris Angelico writes: >>>>> ??? wrote: >>>>>> why can't I send images to python-list at python.org?? >>> >> >>>>> It's a text-only list. >>>> I'll take this opportunity to give heartfelt thanks to the >>>> administrators for that policy; please keep this a text-only forum. >>> +1000 >>> >> I also entirely agree with this policy, but I've told you a trillion >> times not to exaggerate :) >> > +Googol +Googolplex or even +Googolplexian -- DaveA From bahamutzero8825 at gmail.com Fri Jun 29 22:05:20 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 29 Jun 2012 21:05:20 -0500 Subject: Re Following syntax error in Mac OX10.7 Terminal In-Reply-To: <4c2a80da-70bd-48c0-92c9-c7182d3578b3@googlegroups.com> References: <871ukzs5rx.fsf@gmail.com> <7e3890e4-3225-47f1-99e8-e5574c6413ef@googlegroups.com> <4c2a80da-70bd-48c0-92c9-c7182d3578b3@googlegroups.com> Message-ID: <4FEE5EE0.7060600@gmail.com> On 6/29/2012 10:58 AM, David Thomas wrote: > Just discovered this in the tutorial further down. I'm currently learning Python 2 because there seems to be a lot of tutorials out there covering Python 2 rather than 3. The latest edition (3rd?) of Programming Python by Mark Lutz covers py3k (it targets 3.0/3.1 IIRC, but the official Python docs cover the differences between versions). The tutorial in the official docs is short compared to a book, but it covers the basics well. The official docs do cover each module in the standard library in great detail. It is mainly reference, though there are a few tutorials (e.g. the logging module has at least 2 tutorials). If you are not restricted to 2.x, learn 3.2/3.3. 2.x is used mainly because some major libraries (e.g., Twisted, Django) and/or other dependencies do not support 3.x yet. There will be no 2.8, and 2.7 isn't getting any new features AFAIK. -- CPython 3.3.0a4 | Windows NT 6.1.7601.17803 From steve+comp.lang.python at pearwood.info Fri Jun 29 22:28:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Jun 2012 02:28:52 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4fee6464$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 29 Jun 2012 19:41:11 +0000, Alister wrote: > also this section in main strikes me as a bit odd and convoluted > > w = world() > serv = server(client) > w.server = serv > serv.world = w > > I think you are cross referencing classes & would be better to > investigate inheritance. What you show above is composition, and is a perfectly valid technique, and in fact should often be *preferred* to inheritance. The only slightly dubious part, and I stress *slightly*, is that there is a circular reference: w refers to serv, and serv refers back to w. While legitimate, it is a very slight "code smell" that should be investigated. If there is a way to get the same result without the circular reference, that would be preferred. For example, perhaps server methods that need to know the world could take it as an explicit argument, rather than fetching it implicitly from server.world. Or, a moderately advanced technique, use a weak-ref instead. Inheritance should only be used to model "is-a" relationships. For example, Herbie the Love Bug is a Volkswagen Beetle, so inheritance is appropriate. http://en.wikipedia.org/wiki/Herbie class Vehicle(object): pass class Car(Vehicle): pass class Beetle(Car): pass herbie = Beetle() Composition should be used to model "has-a" relationships. For example, a car has an engine, it is not a kind of engine, and so inheritance is inappropriate and composition should be used. I would re-write the Car class as follows: class Engine(object): pass class Car(Vehicle): def __init__(self): self.engine = Engine() So now we can talk about Herbie's engine: herbie.engine # Herbie, being a car, has an engine, he is not an engine -- Steven From tjreedy at udel.edu Fri Jun 29 23:00:30 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Jun 2012 23:00:30 -0400 Subject: code review In-Reply-To: <4FEE14C7.3030700@tysdomain.com> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <4FEE14C7.3030700@tysdomain.com> Message-ID: On 6/29/2012 4:49 PM, Littlefield, Tyler wrote: > I am no expert but from what have picked up so far from x import is > frowned upon in most cases from x import * # frowned on by many as reader will not necessarily know what that imports, conflicts are possible, and if you import * twice, reader may really not know what came from where from x import y,x # fine, common, used in stdlib import x as y # ditto from x import y as z # ditto -- Terry Jan Reedy From tjreedy at udel.edu Fri Jun 29 23:02:07 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Jun 2012 23:02:07 -0400 Subject: code review In-Reply-To: References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <1b4644e1-f406-4ced-b753-7038babad778@googlegroups.com> Message-ID: On 6/29/2012 4:43 PM, Alister wrote: >> from x import * is frowned upon, however, from x import y is fine IMHO. >>> > well I said I was no expert & picking things up. re investigation I see > your reasoning and yes it was the from X import * I was thinking of. > > Although a simple import X retaining the name-space ref does make it easy > to identify the origins of a function (at the expense of more typing) import tkinter as tk for example, to minimize extra typing while identifying source. ___ Terry Jan Reedy From dan at tombstonezero.net Fri Jun 29 23:14:29 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Fri, 29 Jun 2012 20:14:29 -0700 Subject: I can't send images to this mail-list In-Reply-To: <4FEE5D8D.6020601@davea.name> References: <87k3yqqn9o.fsf@benfinney.id.au> <4FEDC942.8010509@stoneleaf.us> <9qcsu7hadmv6v9jj8jamk9sd9ustfsviga@invalid.netcom.com> <4FEE5D8D.6020601@davea.name> Message-ID: <20120629201429.2eb0cb37@particle> On Fri, 29 Jun 2012 21:59:41 -0400 Dave Angel wrote: > On 06/29/2012 06:59 PM, Dennis Lee Bieber wrote: > > On Fri, 29 Jun 2012 21:13:09 +0100, Mark Lawrence > > declaimed the following in > > gmane.comp.python.general: > > > >> On 29/06/2012 16:26, Ethan Furman wrote: > >>> Ben Finney wrote: > >>>> Chris Angelico writes: > >>>>> ??? wrote: > >>>>>> why can't I send images to python-list at python.org?? > >>> >> > >>>>> It's a text-only list. > >>>> I'll take this opportunity to give heartfelt thanks to the > >>>> administrators for that policy; please keep this a text-only > >>>> forum. > >>> +1000 > >>> > >> I also entirely agree with this policy, but I've told you a > >> trillion times not to exaggerate :) > >> > > +Googol > +Googolplex > or even > > +Googolplexian At the risk of skipping G1: +Graham's Number? From rustompmody at gmail.com Fri Jun 29 23:26:41 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 29 Jun 2012 20:26:41 -0700 (PDT) Subject: =?ISO-8859-1?Q?Re=3A_Pythonic_cross=2Dplatform_GUI_desingers_=E0_la_Inte?= =?ISO-8859-1?Q?rface_Builder_=28Re=3A_what_gui_designer_is_everyone_using=29?= References: <20120608142721.3ab95cb7.feliphil@gmx.net> <2ad99bdf-e33e-4a8e-90c9-1fc8bf1f9f97@m10g2000vbn.googlegroups.com> <1cf1da6c-e6b1-40d6-ac59-95ae988974c1@z2g2000yqf.googlegroups.com> <0efa2cbd-c0a3-4dcb-beae-2cdf9063999a@l10g2000pbi.googlegroups.com> Message-ID: <5da93d1b-f161-454f-8a1d-7993312ecdb0@f8g2000pbf.googlegroups.com> On Jun 10, 3:36?pm, Arnaud Delobelle wrote: > On 10 June 2012 07:16, rusi wrote: > > > This is worth a read in this context:http://osteele.com/archives/2004/11/ides > > Interesting! I definitely fall nicely at one extreme of this > dichotomy. ?Every time I've tried to use an IDE, it's made me feel > inadequate and I've quickly retreated to my comfort zone (emacs + > xterm). Here is a more recent discussion in the same vein: http://henrikwarne.com/2012/06/17/programmer-productivity-emacs-versus-intellij-idea/ Reddited here: http://www.reddit.com/r/programming/comments/vqb9l/programmer_productivity_emacs_versus_intellij_idea/ > I felt inadequate because I felt like the IDE was hindering > me rather than helping me. ?All I ask from the program that I use to > write code is: > > * syntax highlighting > * sensible auto-indenting > * as little reliance on the mouse as possible > * emacs key bindings :) To some extent the new article just confirms the old Osteele one: viz. Programmers stuck with java had better spend their time using the most powerful tools to compensate for their inadequate language. However it also indicates the opposite: Benefits of sophisticated refactoring support are almost certainly underestimated by users of vi/emacs. > > This article makes me feel more positive about my inability to feel > comfortable in an IDE. ?Thanks for the link! > > -- > Arnaud T From storchaka at gmail.com Sat Jun 30 03:32:05 2012 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 30 Jun 2012 10:32:05 +0300 Subject: code review In-Reply-To: <4FEDBF67.5060702@tysdomain.com> References: <4FED19A8.8060201@tysdomain.com> <4FEDBF67.5060702@tysdomain.com> Message-ID: On 29.06.12 17:44, Littlefield, Tyler wrote: > On 6/29/2012 2:14 AM, Serhiy Storchaka wrote: >>> The project page is at: >>> http://code.google.com/p/pymud >>> Any information is greatly appreciated. >> >> Do you mean >> No, I mean http://code.google.com/p/pymud Then you probably should choose another name. From alister.ware at ntlworld.com Sat Jun 30 05:22:23 2012 From: alister.ware at ntlworld.com (Alister) Date: Sat, 30 Jun 2012 09:22:23 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <4fee6464$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 30 Jun 2012 02:28:52 +0000, Steven D'Aprano wrote: > On Fri, 29 Jun 2012 19:41:11 +0000, Alister wrote: > >> also this section in main strikes me as a bit odd and convoluted >> >> w = world() >> serv = server(client) >> w.server = serv serv.world = w >> >> I think you are cross referencing classes & would be better to >> investigate inheritance. > > What you show above is composition, and is a perfectly valid technique, > and in fact should often be *preferred* to inheritance. > > The only slightly dubious part, and I stress *slightly*, is that there > is a circular reference: w refers to serv, and serv refers back to w. > While legitimate, it is a very slight "code smell" that should be > investigated. > If there is a way to get the same result without the circular reference, > that would be preferred. > > For example, perhaps server methods that need to know the world could > take it as an explicit argument, rather than fetching it implicitly from > server.world. > > Or, a moderately advanced technique, use a weak-ref instead. > > Inheritance should only be used to model "is-a" relationships. For > example, Herbie the Love Bug is a Volkswagen Beetle, so inheritance is > appropriate. > > http://en.wikipedia.org/wiki/Herbie > > > class Vehicle(object): > pass > > class Car(Vehicle): > pass > > class Beetle(Car): > pass > > herbie = Beetle() > > Composition should be used to model "has-a" relationships. For example, > a car has an engine, it is not a kind of engine, and so inheritance is > inappropriate and composition should be used. I would re-write the Car > class as follows: > > class Engine(object): > pass > > class Car(Vehicle): > def __init__(self): > self.engine = Engine() > > So now we can talk about Herbie's engine: > > herbie.engine # Herbie, being a car, has an engine, he is not an engine I probably was not to clear (due to my own inexperience) it was the circular references that grabbed my attention, it may be OK but suggests to me there may be a better approach. -- ((lambda (foo) (bar foo)) (baz)) From alister.ware at ntlworld.com Sat Jun 30 05:31:53 2012 From: alister.ware at ntlworld.com (Alister) Date: Sat, 30 Jun 2012 09:31:53 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 29 Jun 2012 14:49:11 -0600, Littlefield, Tyler wrote: > I am no expert but from what have picked up so far from x import is > frowned upon in most cases also this section in main strikes me as a bit > odd and convoluted w = world() serv = server(client) w.server = serv > serv.world = w I think you are cross referencing classes & would be > better to investigate inheritance. > > From what I understand and how I've always employed it, inheritance is > ment when you wish to give a class characteristics of another class. All > I'm doing here is setting the world and server classes on each other, so > they can call one another. This probably isn't needed in case of > serv.server = w, but for sure the other way around. I was not too sure of exactly why the code looked odd. as mentioned in another post I should really have referred to the circular references. I am new to python (about 6 months of home hacking), I looked at the code to see if it could improve my knowledge & my responses have been intended to spark a 2 way discussion of the pro's & cons of the approach. So far that seems to be working, I expect by the end of this I will have learnt much about real world python apps. -- Nobody ever died from oven crude poisoning. From alister.ware at ntlworld.com Sat Jun 30 05:36:49 2012 From: alister.ware at ntlworld.com (Alister) Date: Sat, 30 Jun 2012 09:36:49 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 30 Jun 2012 09:31:53 +0000, Alister wrote: > On Fri, 29 Jun 2012 14:49:11 -0600, Littlefield, Tyler wrote: > >> I am no expert but from what have picked up so far from x import is >> frowned upon in most cases also this section in main strikes me as a >> bit odd and convoluted w = world() serv = server(client) w.server = >> serv serv.world = w I think you are cross referencing classes & would >> be better to investigate inheritance. >> >> From what I understand and how I've always employed it, inheritance is >> ment when you wish to give a class characteristics of another class. >> All I'm doing here is setting the world and server classes on each >> other, so they can call one another. This probably isn't needed in case >> of serv.server = w, but for sure the other way around. > > I was not too sure of exactly why the code looked odd. > as mentioned in another post I should really have referred to the > circular references. > > I am new to python (about 6 months of home hacking), I looked at the > code to see if it could improve my knowledge & my responses have been > intended to spark a 2 way discussion of the pro's & cons of the > approach. > So far that seems to be working, I expect by the end of this I will have > learnt much about real world python apps. perhaps now is a good time for me to look at the rest of the modules to see if i can work out exactly what these circular references do. btw where or what is pants.py? -- If the path be beautiful, let us not ask where it leads. -- Anatole France From alister.ware at ntlworld.com Sat Jun 30 06:04:20 2012 From: alister.ware at ntlworld.com (Alister) Date: Sat, 30 Jun 2012 10:04:20 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 29 Jun 2012 09:03:22 -0600, Littlefield, Tyler wrote: > On 6/29/2012 1:31 AM, Steven D'Aprano wrote: >> On Thu, 28 Jun 2012 20:58:15 -0700, alex23 wrote: >> >>> On Jun 29, 12:57 pm, "Littlefield, Tyler" wrote: >>>> I was curious if someone wouldn't mind poking at some code. The >>>> project page is at:http://code.google.com/p/pymud Any information is >>>> greatly appreciated. >>> I couldn't find any actual code at that site, the git repository is >>> currently empty. > > OOPS, sorry. Apparently I'm not as good with git as I thought. > Everything's in the repo now. I think I may be on firmer grounds with the next few: isValidPassword can be simplified to def isValidPassword(password: count=len(password) return count>= mud.minpass and count<= mud.maxpass ( I used count to save finding the length of password twice although it probably makes no difference in this scenario) similar construct can be used for isValidUser def isValidUser(name): if name.isalpha(): count=len(name) return count>=mud.minname and count >mud.maxname return False -- No one wants war. -- Kirk, "Errand of Mercy", stardate 3201.7 From __peter__ at web.de Sat Jun 30 06:29:31 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 30 Jun 2012 12:29:31 +0200 Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Alister wrote: > I think I may be on firmer grounds with the next few: > > isValidPassword can be simplified to > > def isValidPassword(password: > count=len(password) > return count>= mud.minpass and count<= mud.maxpass > > ( I used count to save finding the length of password twice although it > probably makes no difference in this scenario) If you spell it def is_valid_password(password): return mud.minpass <= len(password) <= mud.maxpass it is even easier to see that you are performing an interval check. From tismer at stackless.com Sat Jun 30 06:41:46 2012 From: tismer at stackless.com (Christian Tismer) Date: Sat, 30 Jun 2012 12:41:46 +0200 Subject: tiffany 0.6.1 released Message-ID: <4FEED7EA.9010100@stackless.com> Tiffany - Read/Write Multipage-Tiff with PIL without PIL ======================================================== Tiffany stands for any tiff. The tiny module solves a large set of problems, has no dependencies and just works wherever Python works. Tiffany was developed in the course of the *DiDoCa* project and will always appear on PyPi. Version 0.6.1 ------------- This version uses the new int.from_bytes/to_bytes methods from python3.2 and emulates them on python2.6/2.7 . This migration was tested using pytest. Tiffany is quite unlikely to change anymore until user requests come, or I get better test data: Testing with larger tiff files ------------------------------ The implementation right now copies data in one big chunk. I would like to make that better/not limited by memory. For that, I need a tiff file that is a few megabytes big. Can somebody please send me one? Extending Tiffany? ------------------ I'm also thinking of - an interface to Qt (without adding a dependency) - a command line interface, to make tiffany into a new tiff tool, - support for other toolkits that need to handle tiff files. Ideas about this are most welcome. Please let me know if this stuff works for you, and send requests to or use the links in the bitbucket website: https://bitbucket.org/didoca/tiffany cheers -- Chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/ 14482 Potsdam : PGP key -> http://pgp.uni-mainz.de work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a. PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list From fabiofz at gmail.com Sat Jun 30 07:56:43 2012 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Sat, 30 Jun 2012 08:56:43 -0300 Subject: PyDev IPython Confusion In-Reply-To: References: Message-ID: On Wed, May 23, 2012 at 5:06 PM, Wanderer wrote: > I have two versions of Python and Ipython; Python 2.6.6 with Ipython > 0.11 and Python 2.7.3 with Ipython 0.12. When I run the Eclipse PyDev > console for the Python 2.7.3 it says it is using Ipython 0.11 as the > interpreter. Ipython 0.11 should not be in the Path for Python 2.7.3. > Is this a bug in Ipython 0.12? Is there a command to check the Ipython > version to verify it is Ipython 0.11 and not Ipython 0.12? Could this > be something in the Windows registry that Ipython 0.11 is the > 'registered' version of Ipython? > Please check on the latest PyDev 2.6.0 release (there was an issue related PYTHONPATH ordering inside PyDev which could potentially lead to that). If it doesn't solve it for you, check if your PYTHONPATH is what you expected inside the shell: import sys; print('\n'.join(sorted(sys.path))) and compare that with your configuration... ( note that the recommended place to ask PyDev questions is at stackoverflow with a PyDev tag... see: http://pydev.org/about.html ) Cheers, Fabio From anthon at mnt.org Sat Jun 30 10:32:06 2012 From: anthon at mnt.org (Anthon van der Neut) Date: Sat, 30 Jun 2012 16:32:06 +0200 Subject: tiffany 0.6.1 released In-Reply-To: <4FEED7EA.9010100@stackless.com> References: <4FEED7EA.9010100@stackless.com> Message-ID: <4FEF0DE6.2020004@mnt.org> Christian, I should have several larger Tiff files, but I would have to search a bi. I used tilded tiffs ack in the early 90-s as a solution to mapping large images onto raytraced surfaces on machines with only 20Mb of memory. I will have to search though and I am now travelling. If I fail to come back to you after I return home (in a week time), drop me an email. Are you going to be at Europython again (we once shared a taxi in Birmingham). I will drive down there tomoorw. Regards Anthon On 2012-06-30 12:41, Christian Tismer wrote: > Tiffany - Read/Write Multipage-Tiff with PIL without PIL > ======================================================== > > Tiffany stands for any tiff. The tiny module solves a large set of > problems, has no dependencies and just works wherever Python works. > Tiffany was developed in the course of the *DiDoCa* project and will > always appear on PyPi. > > > Version 0.6.1 > ------------- > > This version uses the new int.from_bytes/to_bytes methods from > python3.2 and emulates them on python2.6/2.7 . This migration > was tested using pytest. > > Tiffany is quite unlikely to change anymore until user requests come, > or I get better test data: > > > Testing with larger tiff files > ------------------------------ > > The implementation right now copies data in one big chunk. I would > like to make that better/not limited by memory. For that, I need > a tiff file that is a few megabytes big. > Can somebody please send me one? > > > Extending Tiffany? > ------------------ > > I'm also thinking of > > - an interface to Qt (without adding a dependency) > > - a command line interface, to make tiffany into a new tiff tool, > > - support for other toolkits that need to handle tiff files. > > Ideas about this are most welcome. > > Please let me know if this stuff works for you, and send requests to > or use the links in the bitbucket website: > > https://bitbucket.org/didoca/tiffany > > cheers -- Chris > -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Sat Jun 30 12:25:47 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 30 Jun 2012 09:25:47 -0700 Subject: tiffany 0.6.1 released References: Message-ID: <7x4nps3gxg.fsf@ruckus.brouhaha.com> Christian Tismer writes: > Tiffany stands for any tiff. The tiny module solves a large set of > problems, has no dependencies and just works wherever Python works. > Tiffany was developed in the course of the *DiDoCa* project and will > always appear on PyPi. This sounds pretty neat. I didn't comment on it earlier because I haven't tried it out, since I haven't had occasion to deal with tiff files anytime recently. But I've had to process them for some projects in the past, and tiffany would have been useful then. It's good to know that it's out there. From fperez.net at gmail.com Sat Jun 30 13:55:35 2012 From: fperez.net at gmail.com (Fernando Perez) Date: Sat, 30 Jun 2012 17:55:35 +0000 (UTC) Subject: [ANN] IPython 0.13 is officially out! Message-ID: Hi all, on behalf of the IPython development team, and just in time for the imminent Debian freeze and SciPy 2012, I'm thrilled to announce, after an intense 6 months of work, the official release of IPython 0.13. This version contains several major new features, as well as a large amount of bug and regression fixes. The previous version (0.12) was released on December 19 2011, so in this development cycle we had: - ~6 months of work. - 373 pull requests merged. - 742 issues closed (non-pull requests). - contributions from 62 authors. - 1760 commits. - a diff of 114226 lines. This means that we closed a total of 1115 issues over 6 months, for a rate of almost 200 issues closed and 300 commits per month. We are very grateful to all of you who have contributed so enthusiastically to the project and have had the patience of pushing your contributions through our often lengthy review process. We've also welcomed several new members to the core IPython development group: J?rgen Stenarson (@jstenar - this really was an omission as J?rgen has been our Windows expert for a long time) and Matthias Bussonier (@Carreau), who has been very active on all fronts of the project. *Highlights* There is too much new work to write up here, so we refer you to our" What's New" document (http://ipython.org/ipython-doc/rel-0.13/whatsnew/version0.13.html) for the full details. But the main highlights of this release are: * Brand new UI for the notebook, with major usability improvements (real menus, toolbar, and much more) * Manage all your parallel cluster configurations from the notebook with push-button simplicity (cluster start/stop with one button). * Cell magics: commands prefixed with %% apply to an entire cell. We ship with many cell magics by default, including timing, profiling, running cells under bash, Perl and Ruby as well as magics to interface seamlessly with Cython, R and Octave. * The IPython.parallel tools have received many fixes, optimizations, and a number of API improvements to make writing, profiling and debugging parallel codes with IPython much easier. * We have unified our interactive kernels (the basic ipython object you know and love) with the engines running in parallel, so that you can now use all IPython special tricks in parallel too. And you can connect a console or qtconsole to any parallel engine for direct, interactive execution, plotting and debugging in a cluster. *Downloads* Downloads can be found on: - Github: http://github.com/ipython/ipython/downloads - PyPI: http://pypi.python.org/pypi/ipython More download/install details: http://ipython.org/download.html. Please see our release notes for the full details on everything about this release: http://ipython.org/ipython-doc/rel-0.13/whatsnew/version0.13.html As usual, if you find any other problem, please file a ticket --or even better, a pull request fixing it-- on our github issues site (https://github.com/ipython/ipython/issues). Many thanks to all who contributed! Fernando, on behalf of the IPython development team. http://ipython.org From PointedEars at web.de Sat Jun 30 14:39:22 2012 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sat, 30 Jun 2012 20:39:22 +0200 Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2662370.TGmo96CKe1@PointedEars.de> Peter Otten wrote: > If you spell it > > def is_valid_password(password): > return mud.minpass <= len(password) <= mud.maxpass > > it is even easier to see that you are performing an interval check. This is probably a tautology around here, but *what* *a* *great* *programming* *language*. -- PointedEars Please do not Cc: me. / Bitte keine Kopien per E-Mail. From t at jollybox.de Sat Jun 30 15:38:58 2012 From: t at jollybox.de (Thomas Jollans) Date: Sat, 30 Jun 2012 21:38:58 +0200 Subject: code review In-Reply-To: <2662370.TGmo96CKe1@PointedEars.de> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> Message-ID: <4FEF55D2.3040704@jollybox.de> On 06/30/2012 08:39 PM, Thomas 'PointedEars' Lahn wrote: > Peter Otten wrote: > >> If you spell it >> >> def is_valid_password(password): >> return mud.minpass <= len(password) <= mud.maxpass >> >> it is even easier to see that you are performing an interval check. > > This is probably a tautology around here, but *what* *a* *great* > *programming* *language*. > Personally, I don't like this feature of the language. I find a ternary operator that uses symbols that can also be binary operators confusing and inconsistent with the way operators usually work/the way terms are usually associated. It has the charm of being something you'd "naturally" write in the context of non-programming mathematics, at the cost of being very odd indeed in the context of programming in general and Python in particular. From alister.ware at ntlworld.com Sat Jun 30 16:25:39 2012 From: alister.ware at ntlworld.com (Alister) Date: Sat, 30 Jun 2012 20:25:39 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7hJHr.500116$jl.425893@fx19.am4> On Sat, 30 Jun 2012 12:29:31 +0200, Peter Otten wrote: > Alister wrote: > >> I think I may be on firmer grounds with the next few: >> >> isValidPassword can be simplified to >> >> def isValidPassword(password: >> count=len(password) >> return count>= mud.minpass and count<= mud.maxpass >> >> ( I used count to save finding the length of password twice although it >> probably makes no difference in this scenario) > > If you spell it > > def is_valid_password(password): > return mud.minpass <= len(password) <= mud.maxpass > > it is even easier to see that you are performing an interval check. I realise that was possible, that is brilliant! it is exactly how you would write it ass a mathematical definition. -- "The only real way to look younger is not to be born so soon." -- Charles Schulz, "Things I've Had to Learn Over and Over and Over" From alister.ware at ntlworld.com Sat Jun 30 16:30:45 2012 From: alister.ware at ntlworld.com (Alister) Date: Sat, 30 Jun 2012 20:30:45 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> Message-ID: On Sat, 30 Jun 2012 21:38:58 +0200, Thomas Jollans wrote: > On 06/30/2012 08:39 PM, Thomas 'PointedEars' Lahn wrote: >> Peter Otten wrote: >> >>> If you spell it >>> >>> def is_valid_password(password): >>> return mud.minpass <= len(password) <= mud.maxpass >>> >>> it is even easier to see that you are performing an interval check. >> >> This is probably a tautology around here, but *what* *a* *great* >> *programming* *language*. >> >> > Personally, I don't like this feature of the language. I find a ternary > operator that uses symbols that can also be binary operators confusing > and inconsistent with the way operators usually work/the way terms are > usually associated. > > It has the charm of being something you'd "naturally" write in the > context of non-programming mathematics, at the cost of being very odd > indeed in the context of programming in general and Python in > particular. Surely this fits perfectly with the lines 1 & 7 in the zen of python (import this) "Beautifull is better than ugly" and "Readability counts" I find that construct both beautiful and readable, if it cannot be used in the languages then that is their loss. -- Removing the straw that broke the camel's back does not necessarily allow the camel to walk again. From t at jollybox.de Sat Jun 30 16:50:43 2012 From: t at jollybox.de (Thomas Jollans) Date: Sat, 30 Jun 2012 22:50:43 +0200 Subject: code review In-Reply-To: References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> Message-ID: <4FEF66A3.9040805@jollybox.de> On 06/30/2012 10:30 PM, Alister wrote: > On Sat, 30 Jun 2012 21:38:58 +0200, Thomas Jollans wrote: > >> On 06/30/2012 08:39 PM, Thomas 'PointedEars' Lahn wrote: >>> Peter Otten wrote: >>> >>>> If you spell it >>>> >>>> def is_valid_password(password): >>>> return mud.minpass <= len(password) <= mud.maxpass >>>> >>>> it is even easier to see that you are performing an interval check. >>> >>> This is probably a tautology around here, but *what* *a* *great* >>> *programming* *language*. >>> >>> >> Personally, I don't like this feature of the language. I find a ternary >> operator that uses symbols that can also be binary operators confusing >> and inconsistent with the way operators usually work/the way terms are >> usually associated. >> >> It has the charm of being something you'd "naturally" write in the >> context of non-programming mathematics, at the cost of being very odd >> indeed in the context of programming in general and Python in >> particular. > > Surely this fits perfectly with the lines 1 & 7 in the zen of python > (import this) > "Beautifull is better than ugly" and "Readability counts" > > I find that construct both beautiful and readable, if it cannot be used > in the languages then that is their loss. Are we quoting the Zen now? Contra: In re usual operator rules: "Special cases aren't special enough to break the rules." Which of the two comparisons is done first anyway? "In the face of ambiguity, refuse the temptation to guess." Speaking of two comparisons, no "and"! "Explicit is better than implicit." Then again, pro: "Beautiful is better than ugly." "Readability counts." "[Although] practicality beats purity." I can see the appeal. It's quite elegant in and of itself. However, I find that in the context of the whole Python language, it's a bit of a glitch and reduces elegance. (I'm probably in the minority on this one) From alain at dpt-info.u-strasbg.fr Sat Jun 30 17:07:41 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sat, 30 Jun 2012 23:07:41 +0200 Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> Message-ID: <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> Thomas Jollans writes: >>>>> def is_valid_password(password): >>>>> return mud.minpass <= len(password) <= mud.maxpass > Which of the two comparisons is done first anyway? > "In the face of ambiguity, refuse the temptation to guess." There is no ambiguity. See the language reference: "Formally, if a, b, c, ..., y, z are expressions and op1, op2, ..., opN are comparison operators, then a op1 b op2 c ... y opN z is equivalent to a op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once." The last restriction (single evaluation of involved expressions) makes this a bit more than raw syntactic sugar. -- Alain. From t at jollybox.de Sat Jun 30 17:35:19 2012 From: t at jollybox.de (Thomas Jollans) Date: Sat, 30 Jun 2012 23:35:19 +0200 Subject: code review In-Reply-To: <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> Message-ID: <4FEF7117.7000109@jollybox.de> On 06/30/2012 11:07 PM, Alain Ketterlin wrote: > Thomas Jollans writes: > >>>>>> def is_valid_password(password): >>>>>> return mud.minpass <= len(password) <= mud.maxpass > >> Which of the two comparisons is done first anyway? >> "In the face of ambiguity, refuse the temptation to guess." > > There is no ambiguity. See the language reference: Of course it's technically clearly defined, but the syntax isn't explicit. To know what the order is (or whether there is an order!) one has to consult the language reference (which shouldn't be necessary), or make an educated guess, which would almost certainly be correct, but we're supposed to refuse the temptation to guess, right? > "Formally, if a, b, c, ..., y, z are expressions and op1, op2, ..., opN > are comparison operators, then a op1 b op2 c ... y opN z is equivalent > to a op1 b and b op2 c and ... y opN z, except that each expression is > evaluated at most once." > > The last restriction (single evaluation of involved expressions) makes > this a bit more than raw syntactic sugar. From lists at cheimes.de Sat Jun 30 17:35:31 2012 From: lists at cheimes.de (Christian Heimes) Date: Sat, 30 Jun 2012 23:35:31 +0200 Subject: tiffany 0.6.1 released In-Reply-To: <7x4nps3gxg.fsf@ruckus.brouhaha.com> References: <7x4nps3gxg.fsf@ruckus.brouhaha.com> Message-ID: Am 30.06.2012 18:25, schrieb Paul Rubin: > Christian Tismer writes: >> Tiffany stands for any tiff. The tiny module solves a large set of >> problems, has no dependencies and just works wherever Python works. >> Tiffany was developed in the course of the *DiDoCa* project and will >> always appear on PyPi. > > This sounds pretty neat. I didn't comment on it earlier because I > haven't tried it out, since I haven't had occasion to deal with tiff > files anytime recently. But I've had to process them for some projects > in the past, and tiffany would have been useful then. It's good to know > that it's out there. I've developed smc.freeimage exclusively to process large amounts of TIFF images. I estimate that we have processed more than twelve million unique TIFF images with about half a petabyte of data. The packages uses Cython to wrap FreeImage (containing libtiff, libpng, libjpeg, libraw and more) and LittleCMS2. The package is mostly fitted to our needs, a bit limited (e.g. no conversion of CMYK to RGB with color management) and doesn't follow recent best practices for Cython code, but it does it job well. I need to clean up the code base some day when more people get interested in the lib. Christian From tjreedy at udel.edu Sat Jun 30 17:47:55 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 Jun 2012 17:47:55 -0400 Subject: code review In-Reply-To: <4FEF7117.7000109@jollybox.de> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> Message-ID: On 6/30/2012 5:35 PM, Thomas Jollans wrote: > On 06/30/2012 11:07 PM, Alain Ketterlin wrote: >> Thomas Jollans writes: >> >>>>>>> def is_valid_password(password): >>>>>>> return mud.minpass <= len(password) <= mud.maxpass >> >>> Which of the two comparisons is done first anyway? >>> "In the face of ambiguity, refuse the temptation to guess." >> >> There is no ambiguity. See the language reference: > > Of course it's technically clearly defined, but the syntax isn't > explicit. To know what the order is (or whether there is an order!) one > has to consult the language reference (which shouldn't be necessary), or > make an educated guess, which would almost certainly be correct, but > we're supposed to refuse the temptation to guess, right? Python pretty consistently evaluates expressions and equal precedence operators left to right. One really should learn that. No 'implementation defined' ambiguity. -- Terry Jan Reedy From martin.hellwig at gmail.com Sat Jun 30 17:48:16 2012 From: martin.hellwig at gmail.com (Martin P. Hellwig) Date: Sat, 30 Jun 2012 14:48:16 -0700 (PDT) Subject: code review In-Reply-To: References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> Message-ID: <2e7167a8-ab55-422d-808c-9ddb7c44639d@googlegroups.com> On Saturday, 30 June 2012 21:30:45 UTC+1, Alister wrote: > On Sat, 30 Jun 2012 21:38:58 +0200, Thomas Jollans wrote: > > > On 06/30/2012 08:39 PM, Thomas 'PointedEars' Lahn wrote: > >> Peter Otten wrote: > >> > >>> If you spell it > >>> > >>> def is_valid_password(password): > >>> return mud.minpass <= len(password) <= mud.maxpass > >>> > Surely this fits perfectly with the lines 1 & 7 in the zen of python > (import this) > "Beautifull is better than ugly" and "Readability counts" > Agree, however I like to stress the "don't make me unnecessary read with care" rule. Meaning if I read that line, I have to read it carefully to make sure I understand what is happening, the following would not do that although syntax wise equal: def length_between_min_max(password): return(mud.minpass <= len(password) <= mud.maxpass) def is_valid_password(password): valid = True if not length_between_max_min(password): valid = False if some_other_test(password): valid = False return(valid) This I can read, typically I would not even read what the function length_beteen_max_min does as long as there is no bug in it because, it is perfectly english clear what the intention is. -- mph From t at jollybox.de Sat Jun 30 18:05:26 2012 From: t at jollybox.de (Thomas Jollans) Date: Sun, 01 Jul 2012 00:05:26 +0200 Subject: code review In-Reply-To: References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> Message-ID: <4FEF7826.40900@jollybox.de> On 06/30/2012 11:47 PM, Terry Reedy wrote: > On 6/30/2012 5:35 PM, Thomas Jollans wrote: >> On 06/30/2012 11:07 PM, Alain Ketterlin wrote: >>> Thomas Jollans writes: >>> >>>>>>>> def is_valid_password(password): >>>>>>>> return mud.minpass <= len(password) <= mud.maxpass >>> >>>> Which of the two comparisons is done first anyway? >>>> "In the face of ambiguity, refuse the temptation to guess." >>> >>> There is no ambiguity. See the language reference: >> >> Of course it's technically clearly defined, but the syntax isn't >> explicit. To know what the order is (or whether there is an order!) one >> has to consult the language reference (which shouldn't be necessary), or >> make an educated guess, which would almost certainly be correct, but >> we're supposed to refuse the temptation to guess, right? > > Python pretty consistently evaluates expressions and equal precedence > operators left to right. Yes. My sole point, really, is that "normally", one would expect these two expressions to be equivalent: a < b < c (a < b) < c This is clearly not true. That's the inconsistency here with the rest of the language. As soon as you read it as a ternary operator, the two comparisons are logically simultaneous. Doing the left hand comparison first is clearly the intuitive thing to do, but it's still, strictly speaking, arbitrary. Intuitive, clearly defined, but arbitrary. The ternary conditional operator is a different beast because its sub-operators "if" and "else" aren't also binary operators, so it's obvious that it's parsed differently. > One really should learn that. No > 'implementation defined' ambiguity. From alain at dpt-info.u-strasbg.fr Sat Jun 30 19:03:14 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sun, 01 Jul 2012 01:03:14 +0200 Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> Message-ID: <87obo0e72l.fsf@dpt-info.u-strasbg.fr> Thomas Jollans writes: > On 06/30/2012 11:47 PM, Terry Reedy wrote: >>>>>>>>> def is_valid_password(password): >>>>>>>>> return mud.minpass <= len(password) <= mud.maxpass >>>> >>>>> Which of the two comparisons is done first anyway? >>>>> "In the face of ambiguity, refuse the temptation to guess." >>>> >>>> There is no ambiguity. See the language reference: >>> Of course it's technically clearly defined, but the syntax isn't >>> explicit. >> Python pretty consistently evaluates expressions and equal precedence >> operators left to right. > > Yes. My sole point, really, is that "normally", one would expect these > two expressions to be equivalent: > > a < b < c > (a < b) < c > > This is clearly not true. That's the inconsistency here with the rest of > the language. No, comparison operators are different from arithmetic operators in that they always evaluate to a boolean. There are only rare cases where it makes sense to compare comparisons. > As soon as you read it as a ternary operator, the two comparisons are > logically simultaneous. There is no ternary operator, you can chain as many as you want, using whatever operators: if a <= b < c > d >= e: ... Once you view this as a conjonction of conditions, you find back the semantics of "and": short-circuit, left to right evaluation. I find this consistent. -- Alain. From rosuav at gmail.com Sat Jun 30 19:25:30 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jul 2012 09:25:30 +1000 Subject: code review In-Reply-To: <4FEF7826.40900@jollybox.de> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> <4FEF7826.40900@jollybox.de> Message-ID: On Sun, Jul 1, 2012 at 8:05 AM, Thomas Jollans wrote: > Yes. My sole point, really, is that "normally", one would expect these > two expressions to be equivalent: > > a < b < c > (a < b) < c > > This is clearly not true. Python has quite a few things like that, actually. The most noticeable for C programmers is: a = b = c = d = e = 0 which in C is identical to a = (b = (c = (d = (e = 0)))) because assignment is an expression, but in Python is equivalent to nothing because assignment is simply allowed to do multiple. Downside: *Only* simple assignment can be chained. Augmented assignment cannot: >>> a+=10 # That's fine. >>> a+=b+=10 File "", line 1 a+=b+=10 ^ SyntaxError: invalid syntax >>> a=b+=10 File "", line 1 a=b+=10 ^ SyntaxError: invalid syntax >>> a+=b=10 File "", line 1 a+=b=10 ^ SyntaxError: invalid syntax In C, these are all well-defined and valid, and are evaluated right-to-left, and do what you would expect. (And yes, it's handy at times to do this sort of thing.) So it's not a special case for the comparison operators; it's a more general case that Python handles certain chains of operators as single entities, rather than breaking everything down into "OPERAND OPERATOR OPERAND" and evaluating one at a time. Is it better than/worse than C? Not really. It's a design choice and we code within it. (My personal preference is for the C style, as it makes for a more expressive language with less mental glitching, but as I say, that's personal preference.) ChrisA From t at jollybox.de Sat Jun 30 19:50:08 2012 From: t at jollybox.de (Thomas Jollans) Date: Sun, 01 Jul 2012 01:50:08 +0200 Subject: code review In-Reply-To: References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> <4FEF7826.40900@jollybox.de> Message-ID: <4FEF90B0.4080000@jollybox.de> On 07/01/2012 01:25 AM, Chris Angelico wrote: > On Sun, Jul 1, 2012 at 8:05 AM, Thomas Jollans wrote: >> Yes. My sole point, really, is that "normally", one would expect these >> two expressions to be equivalent: >> >> a < b < c >> (a < b) < c >> >> This is clearly not true. > > Python has quite a few things like that, actually. The most noticeable > for C programmers is: > > a = b = c = d = e = 0 > > which in C is identical to > > a = (b = (c = (d = (e = 0)))) > > because assignment is an expression, but in Python is equivalent to > nothing because assignment is simply allowed to do multiple. Downside: > *Only* simple assignment can be chained. Augmented assignment cannot: > >>>> a+=10 # That's fine. >>>> a+=b+=10 > File "", line 1 > a+=b+=10 > ^ > SyntaxError: invalid syntax >>>> a=b+=10 > File "", line 1 > a=b+=10 > ^ > SyntaxError: invalid syntax >>>> a+=b=10 > File "", line 1 > a+=b=10 > ^ > SyntaxError: invalid syntax > > > In C, these are all well-defined and valid, and are evaluated > right-to-left, and do what you would expect. (And yes, it's handy at > times to do this sort of thing.) > > So it's not a special case for the comparison operators; it's a more > general case that Python handles certain chains of operators as single > entities, rather than breaking everything down into "OPERAND OPERATOR > OPERAND" and evaluating one at a time. Is it better than/worse than C? > Not really. It's a design choice and we code within it. (My personal > preference is for the C style, as it makes for a more expressive > language with less mental glitching, but as I say, that's personal > preference.) Nicely put. Of course it's not catastrophic, it's just a feature of Python that I'm not particularly fond of. Another operator with special chaining behaviour that occurred to me is the tuple-building "," operator. This is a particularly interesting one since the "," symbol is also used in other contexts where it is not an operator, and the symbol can be considered an operator in the way it can be in Python only in very few (if any) other programming languages. From ben+python at benfinney.id.au Sat Jun 30 20:08:21 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 01 Jul 2012 10:08:21 +1000 Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> Message-ID: <87bok0qr62.fsf@benfinney.id.au> Thomas Jollans writes: > My sole point, really, is that "normally", one would expect these two > expressions to be equivalent: > > a < b < c > (a < b) < c What norm gives you that expectation? That's not how those operators work in mathematical notation. I know of no programming language that would give a newcomer to Python that expectation. So where is the norm you're referring to? The operator symbols are not chosen arbitrarily for Python; they are, in the case of ??, chosen because of semantic meaning those symbols already have. That's the norm informing this meaning, and I think it negates the point you're making. > This is clearly not true. That's the inconsistency here with the rest > of the language. There is inconsistency already in the symbols people see and the semantics already associated with those symbols. Expecting that any symbol, before Python defines it, will be devoid of any normal meaning is a delusion. -- \ ?The Vatican is not a state.? a state must have territory. This | `\ is a palace with gardens, about as big as an average golf | _o__) course.? ?Geoffrey Robertson, 2010-09-18 | Ben Finney From rosuav at gmail.com Sat Jun 30 20:37:05 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jul 2012 10:37:05 +1000 Subject: code review In-Reply-To: <87bok0qr62.fsf@benfinney.id.au> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> <87bok0qr62.fsf@benfinney.id.au> Message-ID: On Sun, Jul 1, 2012 at 10:08 AM, Ben Finney wrote: > Thomas Jollans writes: > >> My sole point, really, is that "normally", one would expect these two >> expressions to be equivalent: >> >> a < b < c >> (a < b) < c > > What norm gives you that expectation? That's not how those operators > work in mathematical notation. I know of no programming language that > would give a newcomer to Python that expectation. So where is the norm > you're referring to? C, SQL, REXX, and many other languages. ChrisA From steve+comp.lang.python at pearwood.info Sat Jun 30 22:06:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Jul 2012 02:06:37 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> Message-ID: <4fefb0ad$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sun, 01 Jul 2012 00:05:26 +0200, Thomas Jollans wrote: > Yes. My sole point, really, is that "normally", one would expect these > two expressions to be equivalent: > > a < b < c > (a < b) < c Good grief. Why would you expect that? You can't just arbitrarily stick parentheses around parts of expressions and expect the result to remain unchanged. Order of evaluation matters: 2**3**4 != (2**3)**4 Comparisons are no different. You can't just toss in some arbitrary brackets and expect the result to be the same. In the second case, the parentheses explicitly turn the comparison into the equivalent of this: temporary_flag = a < b temporary_flag < c which is not the same as a < b < c. This has nothing to do with chained comparisons. You can write the same thing without chaining: a < b and b < c (a < b) < c Is it not obvious that the second case is completely different from the first? Chaining is irrelevant here. > This is clearly not true. That's the inconsistency here with the rest of > the language. Nonsense. Your expectation that parentheses should not affect the order of evaluation is at odds with the entire Python language, to say nothing of almost every programming language in existence. > As soon as you read it as a ternary operator, Well that's your problem. Why are you reading it as a ternary operator? It isn't one. It is a pair of chained binary operator. How can you tell that it is a pair of binary operators, rather than a single ternary operator? 1) There are TWO operators, hence a pair, not a single ternary operator; 2) each operator takes TWO arguments, not three. Chained comparisons is a standard mathematical notation with an obvious meaning that is familiar to anyone with even a passing familiarity to mathematics. They have straight-forward and simple semantics. If other languages don't allow them, so much the worse for other languages. You seem to be inventing arguments to support an irrational dislike to the feature, but the arguments don't stand up. By all means say that you don't like chained comparisons, that is your right, but your attempts to rationalise that dislike simply do not work. -- Steven From rosuav at gmail.com Sat Jun 30 22:20:52 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jul 2012 12:20:52 +1000 Subject: code review In-Reply-To: <4fefb0ad$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> <4fefb0ad$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 1, 2012 at 12:06 PM, Steven D'Aprano wrote: > You can't just arbitrarily stick parentheses around parts of expressions > and expect the result to remain unchanged. Order of evaluation matters: > > 2**3**4 != (2**3)**4 But that's because ** binds right to left. It _is_ valid to say: 2**3**4 = 2**(3**4) That's the usual way of depicting order of evaluation: putting in the implicit parentheses. 1+2*3 = 1+(2*3) Everyone who knows algebra knows that the parens are optional, but nobody would expect them to change the evaluation of the expression. It's like adding whitespace: 1+2*3 = 1 + 2 * 3 = 1 + 2*3 where the latter is another way of showing order of evaluation (the asterisk "binds more tightly" than the plus). With comparisons, it's not the same. (a <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> Message-ID: On Jul 1, 3:05?am, Thomas Jollans wrote: > Yes. My sole point, really, is that "normally", one would expect these > two expressions to be equivalent: > > a < b < c > (a < b) < c > > This is clearly not true. That's the inconsistency here.... I dont see the inconsistency with the specific example as you've given. However if we consider the argument in general, there is something to be said for being (more) careful to distinguish associative and conjunctive interpretation of operators. IOW for an arbitrary operator * (not standard multiply): If * : t x t -> t, the only meaningful semantics of a*b*c is (a*b)*c or a*(b*c) If * : t x t -> Bool the only meaningful semantics of a*b*c is a*b + b*c where the most reasonable instance of '+' is 'and' What happens when t = Bool? Both cases match. And there is something to be said for notationally allowing for both cases Dijkstra/Scholten and David Gries books on logic in computer science expand on this. A short net-reachable paper is http://wwwhome.ewi.utwente.nl/~fokkinga/mmf2001a.pdf From steve+comp.lang.python at pearwood.info Sat Jun 30 23:23:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Jul 2012 03:23:20 GMT Subject: code review References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> <87bok0qr62.fsf@benfinney.id.au> Message-ID: <4fefc2a8$0$29988$c3e8da3$5496439d@news.astraweb.com> On Sun, 01 Jul 2012 10:37:05 +1000, Chris Angelico wrote: > On Sun, Jul 1, 2012 at 10:08 AM, Ben Finney > wrote: >> Thomas Jollans writes: >> >>> My sole point, really, is that "normally", one would expect these two >>> expressions to be equivalent: >>> >>> a < b < c >>> (a < b) < c >> >> What norm gives you that expectation? That's not how those operators >> work in mathematical notation. I know of no programming language that >> would give a newcomer to Python that expectation. So where is the norm >> you're referring to? > > C, SQL, REXX, and many other languages. All the worse for those languages, since they violate the semantics of mathematical notation. The more I learn about C, the less I want to know about C. What sort of crazy language designer thought that having 2 == 2 == 2 return 0 (false) was a good idea? At least Pascal gives an error, since you can't compare bools with longints, and forces you to write: (2 = 2) and (2 = 2) Sheer craziness for C to abuse mathematical notation like that. But what is one to expect from a language where (unsigned)-1 == -1 apparently is true. http://nitoprograms.blogspot.com.au/2011/05/signed-and-unsigned- comparisons-in-c-c.html -- Steven From rosuav at gmail.com Sat Jun 30 23:48:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jul 2012 13:48:04 +1000 Subject: code review In-Reply-To: <4fefc2a8$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> <87bok0qr62.fsf@benfinney.id.au> <4fefc2a8$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 1, 2012 at 1:23 PM, Steven D'Aprano wrote: > All the worse for those languages, since they violate the semantics of > mathematical notation. Not so. It simply means that booleans are nothing special. In REXX, there are no data types at all, and "1" and "0" are your booleans. In C, boolean and comparison operations return integers, either 1 or 0. Same was true of Python early on, if I understand correctly. It's not shameful. > The more I learn about C, the less I want to know about C. What sort of > crazy language designer thought that having > > 2 == 2 == 2 > > return 0 (false) was a good idea? It makes perfect sense though; your comparisons simply return integers, so you can legally index using them. A simple binary tree can work thus: node child[2]; next_node = child[search_value>current_value]; > Sheer craziness for C to abuse mathematical notation like that. But what > is one to expect from a language where > > (unsigned)-1 == -1 > > apparently is true. Of course it's true. When you compare an unsigned value to a signed one, the signed value is automatically up-cast to unsigned, in the same way that comparing 32-bit and 64-bit integers will do. So whatever rule the compiler uses to cast your first -1 to unsigned will be used to cast the second to unsigned, and they'll be equal. As to "2 == 2 == 2": I don't see it as a problem that: x = (2 == 2) y = (x == 2) z = (2 == 2 == 2) leave y and z as the same. There are different ways of interpreting the z statement, but having it identical to y is certainly a plausible one. ChrisA