From rosuav at gmail.com Mon Oct 1 00:20:55 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Oct 2012 14:20:55 +1000 Subject: parse an environment file In-Reply-To: References: Message-ID: On Mon, Oct 1, 2012 at 10:11 AM, Jason Friedman wrote: > $ env > > produces about 100 entries, most of which are provided by my .bashrc; > cron provides only a limited number of environment variables. > > I want my python 3.2.2 script, called via cron, to know what those > additional variables are. How? Looking into my crystal ball, I'm wondering if perhaps what you're asking is for your cron job to have environment variables that aren't set by cron, ones that you can see in your bash environment. This is a common issue (usually with $PATH), and by no means Python-specific. A quick web search will bring up some results, for instance: http://www.google.com/search?q=cron+environment+variables http://duckduckgo.com/?q=cron+environment+variables http://www.bing.com/search?q=cron+environment+variables If this isn't what you're asking about, please consider clarifying your question :) Chris Angelico From peterfarrell66 at gmail.com Mon Oct 1 00:44:30 2012 From: peterfarrell66 at gmail.com (Peter Farrell) Date: Sun, 30 Sep 2012 21:44:30 -0700 (PDT) Subject: Can't import modules In-Reply-To: References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6edd4676-e4e8-4f1a-b82b-4699ed470792@googlegroups.com> On Sunday, September 30, 2012 8:19:28 PM UTC-7, Dave Angel wrote: > On 09/30/2012 09:35 PM, Peter Farrell wrote: > > > On Sunday, September 30, 2012 6:25:29 PM UTC-7, Steven D'Aprano wrote: > > >> On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote: > > >> > > >> > > >> > > >>> Thanks for trying to help, everybody. Sorry I didn't post the whole > > >>> error message. Now my problem is I just installed VPython and I'm trying > > >>> to run the very first example, bounce.py which I located. I opened it > > >>> and ran it in Idle. I got this message: > > >> > > >> > > >> In general, any time you get unexpected or unusual errors in IDLE, you > > >> should try running the same code without IDLE, just at the regular Python > > >> prompt. > > >> > > > Thanks again for the help. I entered the import statements you suggested into the Python Shell and they gave me the same error message. (Neither did visual_all, but of course the print statement worked.) > > > > Don't run it in the Python Shell, and don't use IDLE at all. Run your > > test either at the cmd window, or from plain Python's interactive > > interpreter, or maybe from VIDLE. > > > > >From the official download page: > > http://www.vpython.org/contents/download_windows.html > > > > > > """How to run VPython > > > > * > > > > Start the program editor with the "VIDLE for Python" shortcut on the > > desktop > > or on the Start menu. > > > > * > > > > Open an example program -- for example, bounce2.py. > > > > * > > > > Press F5 to run (or use the Run menu). > > > > """ > > > > > > > Since I use Python 3.2.3 I've had trouble with programs and modules designed for Python 2 and many programs don't work on my 64-bit system. > > > > > > I was hoping it was a common error that newbies encounter. > > > > > > Thanks again, Python fans. I'll keep you posted on my progress! > > VPython has separate versions for Python 2.7 and 3.2 Hopefully you > > downloaded the 3.2 version, since you're running it in c:\python32 > > > > Also, these are for the 32bit version of CPython. So double-check which > > one you've got installed. > > > > > > > > -- > > > > DaveA Yes, I downloaded the 3.2 version but on 64-bit. None of the 32-bit Python programs I've installed have worked. VPython didn't install a VIDLE icon on my desktop. An earlier version did, but then it said it couldn't find the .exe file to work! I've sent a message to the VPython groups. I'm looking forward to using this program, when it finally works! Thanks again, Peter From peterfarrell66 at gmail.com Mon Oct 1 00:44:30 2012 From: peterfarrell66 at gmail.com (Peter Farrell) Date: Sun, 30 Sep 2012 21:44:30 -0700 (PDT) Subject: Can't import modules In-Reply-To: References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6edd4676-e4e8-4f1a-b82b-4699ed470792@googlegroups.com> On Sunday, September 30, 2012 8:19:28 PM UTC-7, Dave Angel wrote: > On 09/30/2012 09:35 PM, Peter Farrell wrote: > > > On Sunday, September 30, 2012 6:25:29 PM UTC-7, Steven D'Aprano wrote: > > >> On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote: > > >> > > >> > > >> > > >>> Thanks for trying to help, everybody. Sorry I didn't post the whole > > >>> error message. Now my problem is I just installed VPython and I'm trying > > >>> to run the very first example, bounce.py which I located. I opened it > > >>> and ran it in Idle. I got this message: > > >> > > >> > > >> In general, any time you get unexpected or unusual errors in IDLE, you > > >> should try running the same code without IDLE, just at the regular Python > > >> prompt. > > >> > > > Thanks again for the help. I entered the import statements you suggested into the Python Shell and they gave me the same error message. (Neither did visual_all, but of course the print statement worked.) > > > > Don't run it in the Python Shell, and don't use IDLE at all. Run your > > test either at the cmd window, or from plain Python's interactive > > interpreter, or maybe from VIDLE. > > > > >From the official download page: > > http://www.vpython.org/contents/download_windows.html > > > > > > """How to run VPython > > > > * > > > > Start the program editor with the "VIDLE for Python" shortcut on the > > desktop > > or on the Start menu. > > > > * > > > > Open an example program -- for example, bounce2.py. > > > > * > > > > Press F5 to run (or use the Run menu). > > > > """ > > > > > > > Since I use Python 3.2.3 I've had trouble with programs and modules designed for Python 2 and many programs don't work on my 64-bit system. > > > > > > I was hoping it was a common error that newbies encounter. > > > > > > Thanks again, Python fans. I'll keep you posted on my progress! > > VPython has separate versions for Python 2.7 and 3.2 Hopefully you > > downloaded the 3.2 version, since you're running it in c:\python32 > > > > Also, these are for the 32bit version of CPython. So double-check which > > one you've got installed. > > > > > > > > -- > > > > DaveA Yes, I downloaded the 3.2 version but on 64-bit. None of the 32-bit Python programs I've installed have worked. VPython didn't install a VIDLE icon on my desktop. An earlier version did, but then it said it couldn't find the .exe file to work! I've sent a message to the VPython groups. I'm looking forward to using this program, when it finally works! Thanks again, Peter From cjgohlke at gmail.com Mon Oct 1 02:10:47 2012 From: cjgohlke at gmail.com (cjgohlke at gmail.com) Date: Sun, 30 Sep 2012 23:10:47 -0700 (PDT) Subject: Can't import modules In-Reply-To: <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> Message-ID: <550089ae-edde-447d-a977-712bc4125acb@googlegroups.com> On Sunday, September 30, 2012 5:35:02 PM UTC-7, Peter Farrell wrote: > Thanks for trying to help, everybody. Sorry I didn't post the whole error message. Now my problem is I just installed VPython and I'm trying to run the very first example, bounce.py which I located. I opened it and ran it in Idle. I got this message: > > > > Traceback (most recent call last): > > File "C:\Python32\Lib\site-packages\visual\examples\bounce.py", line 1, in > > from visual import * > > File "C:\Python32\lib\site-packages\visual\__init__.py", line 1, in > > from .visual_all import * > > File "C:\Python32\lib\site-packages\visual\visual_all.py", line 1, in > > from vis import version > > File "C:\Python32\lib\site-packages\vis\__init__.py", line 3, in > > from .cvisual import (vector, dot, mag, mag2, norm, cross, rotate, > > SystemError: initialization of cvisual raised unreported exception > > Works for me on win-amd64-3.2. Do you have the numpy package installed? The cvisual extension module uses the numpy C API. The SystemError is expected if numpy is not installed. Install numpy-MKL-1.6.2.win-amd64-py3.2.?exe from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy if you are using VPython-5.74.win-amd64-py3.2.?exe. Christoph > I'm not a programmer, just a math teacher/tutor who's trying to teach my students to understand math through using something real like Python. I'll keep you posted on my progress. > > > > Thank you in advance for your help! > > > > Peter > > > > On Sunday, September 30, 2012 1:22:31 PM UTC-7, Hans Mulder wrote: > > > On 30/09/12 21:42:37, Peter Farrell wrote: > > > > > > > I'm still new to Python, so here's another easy one. After I save something > > > > > > > I've done as a .py file, how do I import it into something else I work on? > > > > > > > Every time I try to import something other than turtle or math, I get this error message: > > > > > > > > > > > > > > 'module' object is not callable > > > > > > > > > > > > > > What am I doing wrong? > > > > > > > > > > > > For starters, you're not showing us any code. > > > > > > > > > > > > The error message suggests that you have successfully imported > > > > > > a module, and you then try to use the module as if it were a > > > > > > callable. That won't work: modules are not callable. > > > > > > > > > > > > My crystal ball says that you may have been a Java programmer > > > > > > in an earlier life. In Java, a file must define exactly one > > > > > > class, and the class must have the same name as the file. > > > > > > > > > > > > Python is not Java. In Python, a file may define one class, > > > > > > or twenty, or none at all. To avoid confusion, do not give > > > > > > any of your classes the same name as any of your files. > > > > > > > > > > > > > > > > > > Hope this helps, > > > > > > > > > > > > -- HansM From pulsarpietro at gmail.com Mon Oct 1 04:14:31 2012 From: pulsarpietro at gmail.com (pedr0) Date: Mon, 1 Oct 2012 01:14:31 -0700 (PDT) Subject: How write a IGMP V3 request Message-ID: Hello, I wrote this piece of code but I am not able to modify it in order to use IGMPV3 and use the source feature of IGMPV3, how can I add a membership for a group on an interface for specified source ? Something like this piece of code (C under Linux): setsockopt(fd,SOL_IP,MCAST_JOIN_SOURCE_GROUP, &group_source_req, sizeof(group_source_req)); import socket import fcntl import struct import sys def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) if len(sys.argv) < 3: print 'Usage : [MCAST_ADDR] [PORT] [IFNAME]' sys.exit(1) MCAST_GRP = sys.argv[1] MCAST_PORT = int(sys.argv[2]) IF = sys.argv[3] ip_if = get_ip_address(IF) packet = 0 print("Capturing from "+IF+"("+ip_if+") group "+MCAST_GRP+":"+str(MCAST_PORT)) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(('', MCAST_PORT)) sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, socket.inet_aton(MCAST_GRP)+socket.inet_aton(ip_if)) while True: try: sock.recv(1024) print '1K received' packet = packet +1 except: print 'Received '+str(packet*1024)+' bytes' sock.setsockopt(socket.IPPROTO_IP, socket.IP_DROP_MEMBERSHIP, socket.inet_aton(MCAST_GRP)+socket.inet_aton(ip_if)) sys.exit(0) From breamoreboy at yahoo.co.uk Mon Oct 1 04:19:37 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Oct 2012 09:19:37 +0100 Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: On 01/10/2012 01:58, 88888 Dihedral wrote: > > Your question seems vague to me. If you know you are storing > only immutable tuples in a list, then the way to iterate is simple. > Does Python have a magic method that let's me use mutable tuples? I'd also like immutable lists. Is it worth raising a feature request on the bug tracker? -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Mon Oct 1 04:28:54 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Oct 2012 09:28:54 +0100 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: Message-ID: On 01/10/2012 04:06, Edward Diener wrote: > On 9/30/2012 3:38 PM, Andrew Berg wrote: >> Unix-based OSes should already obey the shebang line, and on Windows, >> there's py.exe in 3.3 that will launch the intended version based on >> that shebang line. > > The problem with that is that one has to already being using 3.3 to use > this facility. I was hoping for a solution which was backwards > compatible with Python 2.x. > You don't need 3.3 to get py.exe. I've been running it for months, it's available here https://bitbucket.org/vinay.sajip/pylauncher/downloads -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Mon Oct 1 04:36:19 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Oct 2012 09:36:19 +0100 Subject: Can't import modules In-Reply-To: <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> References: <36813ff7-68b9-44eb-9b25-7c13ae739566@googlegroups.com> <5068a9e0$0$6915$e4fe514c@news2.news.xs4all.nl> <2e36e097-a43f-43b4-98a6-8da999c39c21@googlegroups.com> <5068f109$0$29997$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/10/2012 02:25, Steven D'Aprano wrote: > On Sun, 30 Sep 2012 17:35:02 -0700, Peter Farrell wrote: > >> Thanks for trying to help, everybody. Sorry I didn't post the whole >> error message. Now my problem is I just installed VPython and I'm trying >> to run the very first example, bounce.py which I located. I opened it >> and ran it in Idle. I got this message: > > In general, any time you get unexpected or unusual errors in IDLE, you > > In Windows, I *think* that if you run "python" (or perhaps "python32") > from the Start Menu, it will open an interactive prompt similar to IDLE. Just python. With the arrival of pylauncher http://www.python.org/dev/peps/pep-0397/ you can also type py [options]. -- Cheers. Mark Lawrence. From ulrich.eckhardt at dominolaser.com Mon Oct 1 06:00:04 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 01 Oct 2012 12:00:04 +0200 Subject: parse an environment file In-Reply-To: References: Message-ID: <466oj9-id6.ln1@satorlaser.homedns.org> Am 01.10.2012 02:11, schrieb Jason Friedman: > $ crontab -l > * * * * * env > > This produces mail with the following contents: > [...] > SHELL=/bin/sh ^^^^^^^ [...] > > On the other hand > > $ env > > produces about 100 entries, most of which are provided by my .bashrc; bash != sh Instead of running a script in default POSIX shell, you might be able to run it in bash, which will then read your ~/.bashrc (verify that from the docs, I'm not 100% sure). Maybe it is as easy as changing the first line to '#!/bin/bash'. > I want my python 3.2.2 script, called via cron, to know what those > additional variables are. To be honest, I would reconsider the approach. You could patch the cron invokation, but that still won't fix any other invokations like starting it from a non-bash shell, filemanager, atd etc. You could instead set these variables in a different place that is considered by more applications. I wonder if maybe ~/.profile would be such a place. Alternatively, assuming these environment variables are just for your Python program, you could store these settings in a separate configuration file instead. Environment variables are always a bit like using globals instead of function parameters. Good luck! Uli From alain at dpt-info.u-strasbg.fr Mon Oct 1 06:16:00 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 01 Oct 2012 12:16:00 +0200 Subject: parse an environment file References: Message-ID: <87ehlih50f.fsf@dpt-info.u-strasbg.fr> Jason Friedman writes: [...] > I want my python 3.2.2 script, called via cron, to know what those > additional variables are. How? This is not a python question. Have a look at the crontab(5) man page, it's all explained there. -- Alain. From jason at powerpull.net Mon Oct 1 10:12:50 2012 From: jason at powerpull.net (Jason Friedman) Date: Mon, 1 Oct 2012 08:12:50 -0600 Subject: parse an environment file In-Reply-To: References: Message-ID: > I want my python 3.2.2 script, called via cron, to know what those > additional variables are. How? Thank you for the feedback. A crontab line of * * * * * . /path/to/export_file && /path/to/script.py does indeed work, but for various reasons this approach will not always be available to me. Let me restate my question. I have a file that looks like this: export VAR1=foo export VAR2=bar # Comment export VAR3=${VAR1}${VAR2} I want this: my_dict = {'VAR1': 'foo', 'VAR2': 'bar', 'VAR3': 'foobar'} I can roll my own, but I'm thinking there is a module or existing code that does this. I looked at the os and sys and configparse modules but did not see it. From overhaalsgang_24_bob at me.com Mon Oct 1 10:19:27 2012 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Mon, 1 Oct 2012 07:19:27 -0700 (PDT) Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> <3de0aac0-d7f2-4990-9428-54c89b143b9a@googlegroups.com> Message-ID: <4be2f2ac-c061-48d7-baf1-212e28f2f5ec@googlegroups.com> Op vrijdag 21 september 2012 16:15:30 UTC+2 schreef Joel Goldstick het volgende: > On Fri, Sep 21, 2012 at 9:58 AM, BobAalsma wrote: > > > Op vrijdag 21 september 2012 15:36:11 UTC+2 schreef Jerry Hill het volgende: > > >> On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma wrote: > > >> > > >> > Thanks, Joel, yes, but as far as I'm aware these would all require the Python programme to have the user's username and password (or "credentials"), which I wanted to avoid. > > >> > > >> > > >> > > >> No matter what you do, your web service is going to have to > > >> > > >> authenticate with the remote web site. The details of that > > >> > > >> authentication are going to vary with each remote web site you want to > > >> > > >> connect to. > > >> > > >> > > >> > > >> -- > > >> > > >> Jerry > > > > > > Hmm, from the previous posts I get the impression that I could best solve this by asking the user for the specific combination of username, password and URL + promising not to keep any of that... > > > > > > OK, that does sound doable - thank you all > > > > > > I recommend that you write your program to read pages that are not > > protected. Once you get that working, you can go back and figure out > > how you want to get the username/password from your 'friends' and add > > that in. Also look up Beautiful Soup (version 4) for a great library > > to parse the pages that you retrieve > > > > > > Bob > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > Joel Goldstick Joel, I've spent some time with this but don't really understand my results - some help would be appreciated. I've built a tester that will read my LinkedIn home page, which is password protected. When I use that method for reading other people's pages, the program is redirected to the LinkedIn login page. When I paste the URLs for the other people's pages in any browser, the requested pages are shown. Bob From rosuav at gmail.com Mon Oct 1 10:21:45 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Oct 2012 00:21:45 +1000 Subject: parse an environment file In-Reply-To: References: Message-ID: On Tue, Oct 2, 2012 at 12:12 AM, Jason Friedman wrote: > Let me restate my question. I have a file that looks like this: > export VAR1=foo > export VAR2=bar > # Comment > export VAR3=${VAR1}${VAR2} > > I want this: > my_dict = {'VAR1': 'foo', 'VAR2': 'bar', 'VAR3': 'foobar'} > > I can roll my own, but I'm thinking there is a module or existing code > that does this. I looked at the os and sys and configparse modules > but did not see it. Is there a reason to use that format, rather than using Python notation? I've at times made config files that simply get imported. Instead of a dictionary, you'd have a module object: # config.py VAR1='foo' VAR2='bar' VAR3=VAR1+VAR2 # main file import config as my_dict ChrisA From rosuav at gmail.com Mon Oct 1 10:41:58 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Oct 2012 00:41:58 +1000 Subject: parse an environment file In-Reply-To: References: Message-ID: On Tue, Oct 2, 2012 at 12:37 AM, Jason Friedman wrote: >> Is there a reason to use that format, rather than using Python >> notation? I've at times made config files that simply get imported. >> Instead of a dictionary, you'd have a module object: >> >> >> # config.py >> VAR1='foo' >> VAR2='bar' >> VAR3=VAR1+VAR2 >> > There is a reason: /path/to/export_file exists for Bash scripts, too, > and I do not think I could get Bash to read config.py in the format > stated above. I want to maintain only one file. (Responding on-list and hoping it was merely oversight that had that email come to me personally) Ah, fair enough. Well, since you're using the full range of bash functionality, the only viable way to parse it is with bash itself. I'd recommend going with the version you have above: > * * * * * . /path/to/export_file && /path/to/script.py Under what circumstances is this not an option? That'd be the next thing to consider. Alternatively, you may want to consider making your own config file format. If you consciously restrict yourself to a severe subset of bash functionality, you could easily parse it in Python - for instance, always look for "export %s=%s" with simple strings for the variable name and value. ChrisA From andriy.kornatskyy at live.com Mon Oct 1 11:24:57 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Mon, 1 Oct 2012 18:24:57 +0300 Subject: Fastest template engine In-Reply-To: References: Message-ID: 1. Added benchmarks for python 3.3 2. Captured total numbers of calls made by corresponding template engine and number of unique functions used. http://mindref.blogspot.com/2012/07/python-fastest-template.html Comments or suggestions are welcome. Andriy ---------------------------------------- > From: andriy.kornatskyy at live.com > To: python-list at python.org > Subject: Fastest template engine > Date: Sun, 23 Sep 2012 12:24:36 +0300 > > > I have run recently a benchmark of a trivial 'big table' example for various python template engines (jinja2, mako, tenjin, tornado and wheezy.template) run on cpython2.7 and pypy1.9...... you might find it interesting: > > http://mindref.blogspot.com/2012/07/python-fastest-template.html > > Comments or suggestions are welcome. > > Thanks. > > Andriy Kornatskyy > -- > http://mail.python.org/mailman/listinfo/python-list From redstone-cold at 163.com Mon Oct 1 11:28:32 2012 From: redstone-cold at 163.com (iMath) Date: Mon, 1 Oct 2012 08:28:32 -0700 (PDT) Subject: =?UTF-8?Q?where_to_view_range=28=5Bstart=5D=2C_stop=5B=2C_step=5D=29=27s_C_imple?= =?UTF-8?Q?mentation_source_code_=EF=BC=9F?= Message-ID: where to view range([start], stop[, step])'s C implementation source code ? From dihedral88888 at googlemail.com Mon Oct 1 11:29:22 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 1 Oct 2012 08:29:22 -0700 (PDT) Subject: parse an environment file In-Reply-To: References: Message-ID: On Monday, October 1, 2012 10:42:02 PM UTC+8, Chris Angelico wrote: > On Tue, Oct 2, 2012 at 12:37 AM, Jason Friedman wrote: > > >> Is there a reason to use that format, rather than using Python > > >> notation? I've at times made config files that simply get imported. > > >> Instead of a dictionary, you'd have a module object: > > >> > > >> > > >> # config.py > > >> VAR1='foo' > > >> VAR2='bar' > > >> VAR3=VAR1+VAR2 > > >> > > > There is a reason: /path/to/export_file exists for Bash scripts, too, > > > and I do not think I could get Bash to read config.py in the format > > > stated above. I want to maintain only one file. > > > > (Responding on-list and hoping it was merely oversight that had that > > email come to me personally) > > > > Ah, fair enough. Well, since you're using the full range of bash > > functionality, the only viable way to parse it is with bash itself. > > I'd recommend going with the version you have above: > > > > > * * * * * . /path/to/export_file && /path/to/script.py > > > > Under what circumstances is this not an option? That'd be the next > > thing to consider. > > > > Alternatively, you may want to consider making your own config file > > format. If you consciously restrict yourself to a severe subset of > > bash functionality, you could easily parse it in Python - for > > instance, always look for "export %s=%s" with simple strings for the > > variable name and value. > > > > ChrisA I think one can ues some decorators to wrap OS or platform dependent functions. I am sure someone did that long time ago as the iron python wrapped dot-net. From dihedral88888 at googlemail.com Mon Oct 1 11:29:22 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 1 Oct 2012 08:29:22 -0700 (PDT) Subject: parse an environment file In-Reply-To: References: Message-ID: On Monday, October 1, 2012 10:42:02 PM UTC+8, Chris Angelico wrote: > On Tue, Oct 2, 2012 at 12:37 AM, Jason Friedman wrote: > > >> Is there a reason to use that format, rather than using Python > > >> notation? I've at times made config files that simply get imported. > > >> Instead of a dictionary, you'd have a module object: > > >> > > >> > > >> # config.py > > >> VAR1='foo' > > >> VAR2='bar' > > >> VAR3=VAR1+VAR2 > > >> > > > There is a reason: /path/to/export_file exists for Bash scripts, too, > > > and I do not think I could get Bash to read config.py in the format > > > stated above. I want to maintain only one file. > > > > (Responding on-list and hoping it was merely oversight that had that > > email come to me personally) > > > > Ah, fair enough. Well, since you're using the full range of bash > > functionality, the only viable way to parse it is with bash itself. > > I'd recommend going with the version you have above: > > > > > * * * * * . /path/to/export_file && /path/to/script.py > > > > Under what circumstances is this not an option? That'd be the next > > thing to consider. > > > > Alternatively, you may want to consider making your own config file > > format. If you consciously restrict yourself to a severe subset of > > bash functionality, you could easily parse it in Python - for > > instance, always look for "export %s=%s" with simple strings for the > > variable name and value. > > > > ChrisA I think one can ues some decorators to wrap OS or platform dependent functions. I am sure someone did that long time ago as the iron python wrapped dot-net. From hansmu at xs4all.nl Mon Oct 1 11:35:04 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Mon, 01 Oct 2012 17:35:04 +0200 Subject: parse an environment file In-Reply-To: References: Message-ID: <5069b829$0$6949$e4fe514c@news2.news.xs4all.nl> On 1/10/12 16:12:50, Jason Friedman wrote: >> I want my python 3.2.2 script, called via cron, to know what those >> additional variables are. How? > > Thank you for the feedback. A crontab line of > > * * * * * . /path/to/export_file && /path/to/script.py > > does indeed work, but for various reasons this approach will not > always be available to me. > > Let me restate my question. I have a file that looks like this: > export VAR1=foo > export VAR2=bar > # Comment > export VAR3=${VAR1}${VAR2} > > I want this: > my_dict = {'VAR1': 'foo', 'VAR2': 'bar', 'VAR3': 'foobar'} > > I can roll my own, but I'm thinking there is a module or existing code > that does this. I looked at the os and sys and configparse modules > but did not see it. One tactic is to write a wrapper script in shellese that sets the variables and then runs your script. Something like: #/bin/bash export VAR1=foo export VAR2=bar # Comment export VAR3=${VAR1}${VAR2} # Read some more settings from a file . /path/to/file/with/more/exports # Drum roll ..... /path/to/your/script.py This allows you to copy-and-paste all sorts of weird and wonderful shell syntax into your wrapper script. AFAIK, there is no Python module that can read shell syntax. You could translate all that shell syntax manually to Python, but that may not be worth the effort. Hope this helps, -- HansM From ian.g.kelly at gmail.com Mon Oct 1 11:41:52 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 1 Oct 2012 09:41:52 -0600 Subject: =?UTF-8?Q?Re=3A_where_to_view_range=28=5Bstart=5D=2C_stop=5B=2C_step=5D=29=27s_C_i?= =?UTF-8?Q?mplementation_source_code_=EF=BC=9F?= In-Reply-To: References: Message-ID: On Mon, Oct 1, 2012 at 9:28 AM, iMath wrote: > where to view range([start], stop[, step])'s C implementation source code ? http://hg.python.org/cpython/file/3f739f42be51/Objects/rangeobject.c From alister.ware at ntlworld.com Mon Oct 1 12:02:18 2012 From: alister.ware at ntlworld.com (Alister) Date: Mon, 01 Oct 2012 16:02:18 GMT Subject: Coexistence of Python 2.x and 3.x on same OS References: Message-ID: On Sun, 30 Sep 2012 15:14:17 -0400, Edward Diener wrote: > Has there been any official software that allows both the Python 2.x and > 3.x releases to coexist on the same OS so that the end-user can easily > switch between them when invoking Python scripts after each has been > installed to their own directories/folders ? > > I know of some unoffical solutions, but they require lots of tweaks. > Given the vagaries of the different OSs on which Python can run I am > hoping for some offical solution which will work on any of the most > popular OSs ( Windows, Linux, Mac ). > > The situation is so confusing on Windows, where the file associations, > registry entries, and other internal software which allows a given > Python release to work properly when invoking Python is so complicated, > that I have given up on trying to install more than one Python release > and finding a relaible, foolproof way of switching between them. So > although I would like to use the latest 3.x series on Windows I have > decide to stick with the latest 2.x series instead because much software > using Python does not support 3.x yet. on my fedora system it was a simple matter of:- #> yum install python3 to use python 3 i specify it in my shebang line #!/usr/bun/env python3 Simple Not sure about Windoze though (Although from memory the install asks where to install so should not be a major issue) -- Immortality consists largely of boredom. -- Zefrem Cochrane, "Metamorphosis", stardate 3219.8 From bnrj.rudra at gmail.com Mon Oct 1 12:44:19 2012 From: bnrj.rudra at gmail.com (=?UTF-8?Q?=E0=A6=B0=E0=A7=81=E0=A6=A6=E0=A7=8D=E0=A6=B0_?= =?UTF-8?Q?=E0=A6=AC=E0=A7=8D=E0=A6=AF=E0=A6=BE=E0=A6=A3=E0=A6=BE?= =?UTF-8?Q?=E0=A6=B0=E0=A7=8D=E0=A6=9C=E0=A7=80?=) Date: Mon, 01 Oct 2012 17:44:19 +0100 Subject: get google scholar using python Message-ID: <1349109859.27817.7.camel@roddur> If I am trying to access a google scholar search result using python, I get the following error(403): $ python Python 2.7.3 (default, Jul 24 2012, 10:05:38) [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from HTMLParser import HTMLParser >>> import urllib2 response = urllib2.urlopen('http://scholar.google.co.uk/scholar?q=albert +einstein%2B1905&btnG=&hl=en&as_sdt=0%2C5&as_sdtp=') Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.7/urllib2.py", line 126, in urlopen return _opener.open(url, data, timeout) File "/usr/lib64/python2.7/urllib2.py", line 406, in open response = meth(req, response) File "/usr/lib64/python2.7/urllib2.py", line 519, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib64/python2.7/urllib2.py", line 444, in error return self._call_chain(*args) File "/usr/lib64/python2.7/urllib2.py", line 378, in _call_chain result = func(*args) File "/usr/lib64/python2.7/urllib2.py", line 527, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 403: Forbidden >>> Will you kindly explain me the way to get rid of this? From nick.cash at npcinternational.com Mon Oct 1 12:51:24 2012 From: nick.cash at npcinternational.com (Nick Cash) Date: Mon, 1 Oct 2012 16:51:24 +0000 Subject: get google scholar using python In-Reply-To: <1349109859.27817.7.camel@roddur> References: <1349109859.27817.7.camel@roddur> Message-ID: <846C3A8E860C4344B567D813B63AA51D48C792E7@BL2PRD0610MB349.namprd06.prod.outlook.com> > urllib2.urlopen('http://scholar.google.co.uk/scholar?q=albert >... > urllib2.HTTPError: HTTP Error 403: Forbidden > >>> > > Will you kindly explain me the way to get rid of this? Looks like Google blocks non-browser user agents from retrieving this query. You *could* work around it by setting the User-Agent header to something fake that looks browser-ish, but you're almost certainly breaking Google's TOS if you do so. Should you really really want to, urllib2 makes it easy: urllib2.urlopen(urllib2.Request("http://scholar.google.co.uk/scholar?q=albert+einstein%2B1905&btnG=&hl=en&as_sdt=0%2C5&as_sdtp=", headers={"User-Agent":"Mozilla/5.0 Cheater/1.0"})) -Nick Cash From invalid at invalid.invalid Mon Oct 1 13:19:39 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 1 Oct 2012 17:19:39 +0000 (UTC) Subject: get google scholar using python References: <1349109859.27817.7.camel@roddur> Message-ID: On 2012-10-01, Nick Cash wrote: >> urllib2.urlopen('http://scholar.google.co.uk/scholar?q=albert >>... >> urllib2.HTTPError: HTTP Error 403: Forbidden >> >> Will you kindly explain me the way to get rid of this? > > Looks like Google blocks non-browser user agents from retrieving this > query. You *could* work around it by setting the User-Agent header to > something fake that looks browser-ish, but you're almost certainly > breaking Google's TOS if you do so. I don't know about that particular Google service, but Google often provides an API that's intended for use by non-browser programs. Those interfaces are usually both easier to use for the programmer and impose less load on the servers. -- Grant Edwards grant.b.edwards Yow! I am deeply CONCERNED at and I want something GOOD gmail.com for BREAKFAST! From pruebauno at latinmail.com Mon Oct 1 13:22:14 2012 From: pruebauno at latinmail.com (nn) Date: Mon, 1 Oct 2012 10:22:14 -0700 (PDT) Subject: print or write on a text file ? References: Message-ID: On Sep 28, 2:42?pm, Franck Ditter wrote: > Hi ! > Here is Python 3.3 > Is it better in any way to use print(x,x,x,file='out') > or out.write(x) ? Any reason to prefer any of them ? > There should be a printlines, like readlines ? > Thanks, > > ? ? franck There is out.writelines(lst) From bnrj.rudra at gmail.com Mon Oct 1 13:28:42 2012 From: bnrj.rudra at gmail.com (=?UTF-8?Q?=E0=A6=B0=E0=A7=81=E0=A6=A6=E0=A7=8D=E0=A6=B0_?= =?UTF-8?Q?=E0=A6=AC=E0=A7=8D=E0=A6=AF=E0=A6=BE=E0=A6=A3=E0=A6=BE?= =?UTF-8?Q?=E0=A6=B0=E0=A7=8D=E0=A6=9C=E0=A7=80?=) Date: Mon, 01 Oct 2012 18:28:42 +0100 Subject: get google scholar using python In-Reply-To: References: <1349109859.27817.7.camel@roddur> Message-ID: <1349112522.1787.5.camel@roddur> I know one more python app that do the same thing http://www.icir.org/christian/downloads/scholar.py and few other app(Mendeley desktop) for which I found an explanation: (from http://academia.stackexchange.com/questions/2567/api-eula-and-scraping-for-google-scholar ) that: "I know how Mendley uses it: they require you to click a button for each individual search of Google Scholar. If they automatically did the Google Scholar meta-data search for each paper when you import a folder-full then they would violate the old Scholar EULA. That is why they make you click for each query: if each query is accompanied by a click and not part of some script or loop then it is in compliance with the old EULA." So, If I manage to use the User-Agent as shown by you, will I still violating the google EULA? This is my first try of scrapping HTML. So please help On Mon, 2012-10-01 at 16:51 +0000, Nick Cash wrote: > > urllib2.urlopen('http://scholar.google.co.uk/scholar?q=albert > >... > > urllib2.HTTPError: HTTP Error 403: Forbidden > > >>> > > > > Will you kindly explain me the way to get rid of this? > > Looks like Google blocks non-browser user agents from retrieving this query. You *could* work around it by setting the User-Agent header to something fake that looks browser-ish, but you're almost certainly breaking Google's TOS if you do so. > > Should you really really want to, urllib2 makes it easy: > urllib2.urlopen(urllib2.Request("http://scholar.google.co.uk/scholar?q=albert+einstein%2B1905&btnG=&hl=en&as_sdt=0%2C5&as_sdtp=", headers={"User-Agent":"Mozilla/5.0 Cheater/1.0"})) > > -Nick Cash From malaclypse2 at gmail.com Mon Oct 1 14:09:34 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Mon, 1 Oct 2012 14:09:34 -0400 Subject: get google scholar using python In-Reply-To: <1349112522.1787.5.camel@roddur> References: <1349109859.27817.7.camel@roddur> <1349112522.1787.5.camel@roddur> Message-ID: On Mon, Oct 1, 2012 at 1:28 PM, ????? ?????????? wrote: > So, If I manage to use the User-Agent as shown by you, will I still > violating the google EULA? Very likely, yes. The overall Google Terms of Services (http://www.google.com/intl/en/policies/terms/) say "Don?t misuse our Services. For example, don?t interfere with our Services or try to access them using a method other than the interface and the instructions that we provide." The only method that Google appears to allow for accessing Scholar is via the web interface, and they explicitly block web scraping through that interface, as you discovered. It's true that you can get around their block, but I believe that doing so violates the terms of service. Google does not appear to offer an API to access Scholar programatically, nor do I see a more specific EULA or TOS for the Scholar service beyond that general TOS document. That said, I am not a lawyer. If you want legal advice, you'll need to pay a lawyer for that advice. -- Jerry From drobinow at gmail.com Mon Oct 1 15:36:14 2012 From: drobinow at gmail.com (David Robinow) Date: Mon, 1 Oct 2012 15:36:14 -0400 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: <50691419.7000408@davea.name> References: <50691419.7000408@davea.name> Message-ID: On Sun, Sep 30, 2012 at 11:55 PM, Dave Angel wrote: >> The problem with that is that one has to already being using 3.3 to >> use this facility. I was hoping for a solution which was backwards >> compatible with Python 2.x. >>... >> That does not solve the problem for Python 2.x distributions. > If you read the Pep, it says the launcher will work for both 2.x and 3.x > http://www.python.org/dev/peps/pep-0397/ > > > I've read that elsewhere, but I can't see just where you would get the > necessary modules to run it with 2.x Possibly you'd have to build it > from sources, as there are Windows binaries that get installed to the > C:\Windows directory. I'm not sure what you're getting at here. The solution is to install Python 3.3, which provides the launcher. It works with Python 2.x. Is there some reason not to install 3.3? From breamoreboy at yahoo.co.uk Mon Oct 1 15:46:06 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Oct 2012 20:46:06 +0100 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: <50691419.7000408@davea.name> Message-ID: On 01/10/2012 20:36, David Robinow wrote: > On Sun, Sep 30, 2012 at 11:55 PM, Dave Angel wrote: >>> The problem with that is that one has to already being using 3.3 to >>> use this facility. I was hoping for a solution which was backwards >>> compatible with Python 2.x. >>> ... >>> That does not solve the problem for Python 2.x distributions. >> If you read the Pep, it says the launcher will work for both 2.x and 3.x >> http://www.python.org/dev/peps/pep-0397/ >> >> >> I've read that elsewhere, but I can't see just where you would get the >> necessary modules to run it with 2.x Possibly you'd have to build it >> from sources, as there are Windows binaries that get installed to the >> C:\Windows directory. > I'm not sure what you're getting at here. The solution is to install > Python 3.3, which provides the launcher. It works with Python 2.x. Is > there some reason not to install 3.3? > Fo those who missed it earlier you can download the launcher here https://bitbucket.org/vinay.sajip/pylauncher/downloads , you don't need Python 3.3. -- Cheers. Mark Lawrence. From joshua.landau.ws at gmail.com Mon Oct 1 15:53:59 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Mon, 1 Oct 2012 20:53:59 +0100 Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: On 1 October 2012 09:19, Mark Lawrence wrote: > On 01/10/2012 01:58, 88888 Dihedral wrote: > >> >> Your question seems vague to me. If you know you are storing >> only immutable tuples in a list, then the way to iterate is simple. >> >> > Does Python have a magic method that let's me use mutable tuples? I'd > also like immutable lists. Is it worth raising a feature request on the > bug tracker? Whilst your question is valid, 88888 Dihedral is a bot. [Lazy] Answers to your questions: no and no. Python's tuples are immutable, except from C. They are made this way so program with that in mind, I guess. That said, an immutable list *is* a tuple and vice-versa, effectively. -------------- next part -------------- An HTML attachment was scrubbed... URL: From subhabangalore at gmail.com Tue Oct 2 04:43:41 2012 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Tue, 2 Oct 2012 01:43:41 -0700 (PDT) Subject: Download issue. Message-ID: <3ad9babb-3c25-4f6f-a410-96827910bf7e@googlegroups.com> Dear Group, I am using Python on Windows 7 SP-1 (64 bit). I have two versions of Python installed 2.7 and 3.2. I want to install networkx in both. How may I do that? If any one may kindly let me know. Regards, Subhabrata. From nathaire at gmail.com Tue Oct 2 05:26:56 2012 From: nathaire at gmail.com (WhisperingWally) Date: Tue, 2 Oct 2012 09:26:56 +0000 (UTC) Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? References: Message-ID: Gelonida N gmail.com> writes: > I wondered whether some of you have a little more insight into what's > going on with PIL. AFAIK the latest PIL stuff lives here: hg.effbot.org From fetchinson at googlemail.com Tue Oct 2 05:45:54 2012 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 2 Oct 2012 11:45:54 +0200 Subject: terminate called after throwing an instance of 'CABRTException' Message-ID: I've noticed a strange thing with python lately: Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57) [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def f(): print x ... >>> f() terminate called after throwing an instance of 'CABRTException' Traceback (most recent call last): File "", line 1, in File "", line 1, in f NameError: global name 'x' is not defined >>> Clearly there is a NameError because x is not defined, but what the hell is the "terminate ..... 'CABRTException'" business? I guess it has to do with abrt but abrt is not running on my system at all. Also, if I run python2.7 with the above code I don't get the CABRTException stuff. What is really strange is that I have all sorts of recent files in /var/cache/abrt/pyhook-* indicating that somehow abrt is doing things even though it is not running, for instance chkconfig --list | grep abrt shows it off in all run levels. What's going on? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From xenplex at gmail.com Tue Oct 2 06:38:44 2012 From: xenplex at gmail.com (Ritchie Flick) Date: Tue, 2 Oct 2012 12:38:44 +0200 Subject: Download issue. In-Reply-To: <3ad9babb-3c25-4f6f-a410-96827910bf7e@googlegroups.com> References: <3ad9babb-3c25-4f6f-a410-96827910bf7e@googlegroups.com> Message-ID: http://www.pip-installer.org/en/latest/index.html -- Ritchie Flick -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Oct 2 06:54:40 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Oct 2012 12:54:40 +0200 Subject: terminate called after throwing an instance of 'CABRTException' References: Message-ID: Daniel Fetchinson wrote: > I've noticed a strange thing with python lately: > > > > Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57) > [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> def f(): print x > ... >>>> f() > terminate called after throwing an instance of 'CABRTException' > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in f > NameError: global name 'x' is not defined >>>> > > > > Clearly there is a NameError because x is not defined, but what the > hell is the "terminate ..... 'CABRTException'" business? > > I guess it has to do with abrt but abrt is not running on my system at > all. Also, if I run python2.7 with the above code I don't get the > CABRTException stuff. What is really strange is that I have all sorts > of recent files in /var/cache/abrt/pyhook-* indicating that somehow > abrt is doing things even though it is not running, for instance > chkconfig --list | grep abrt shows it off in all run levels. > > What's going on? No idea, but I'd have a look at sys.modules, and if >>> import sys >>> [name for name in sys.modules if "abrt" in name.lower()] [] gives a non-empty result I'd investigate where the culprit is imported -- /usr/lib/python2.6/sitecustomize.py would be the obvious candidate. From d at davea.name Tue Oct 2 07:05:06 2012 From: d at davea.name (Dave Angel) Date: Tue, 02 Oct 2012 07:05:06 -0400 Subject: Download issue. In-Reply-To: <3ad9babb-3c25-4f6f-a410-96827910bf7e@googlegroups.com> References: <3ad9babb-3c25-4f6f-a410-96827910bf7e@googlegroups.com> Message-ID: <506ACA62.3020704@davea.name> On 10/02/2012 04:43 AM, subhabangalore at gmail.com wrote: > Dear Group, > > I am using Python on Windows 7 SP-1 (64 bit). > > I have two versions of Python installed 2.7 and 3.2. > > I want to install networkx in both. > > How may I do that? > > If any one may kindly let me know. > Doing a search for networkx, there are several. But the most likely candidate for what you might mean is: http://pypi.python.org/pypi/networkx/ from that I see that both 2.7 and 3.2 are supported, and follow a link to: http://networkx.lanl.gov/ then I look for the documentation, which is here: http://networkx.lanl.gov/contents.html After that, I don't know what to tell you, as I don't use the package. They do have a discussion group, however. I don't know its real name, as all they list on the pages I saw was a google-groups link. If you don't understand python egg files, and how to install them, you might start with: http://peak.telecommunity.com/DevCenter/EasyInstall or http://www.pip-installer.org/en/latest/index.html -- DaveA From fetchinson at googlemail.com Tue Oct 2 08:06:01 2012 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 2 Oct 2012 14:06:01 +0200 Subject: terminate called after throwing an instance of 'CABRTException' In-Reply-To: References: Message-ID: >> I've noticed a strange thing with python lately: >> >> >> >> Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57) >> [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> def f(): print x >> ... >>>>> f() >> terminate called after throwing an instance of 'CABRTException' >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 1, in f >> NameError: global name 'x' is not defined >>>>> >> >> >> >> Clearly there is a NameError because x is not defined, but what the >> hell is the "terminate ..... 'CABRTException'" business? >> >> I guess it has to do with abrt but abrt is not running on my system at >> all. Also, if I run python2.7 with the above code I don't get the >> CABRTException stuff. What is really strange is that I have all sorts >> of recent files in /var/cache/abrt/pyhook-* indicating that somehow >> abrt is doing things even though it is not running, for instance >> chkconfig --list | grep abrt shows it off in all run levels. >> >> What's going on? > > No idea, but I'd have a look at sys.modules, and if > >>>> import sys >>>> [name for name in sys.modules if "abrt" in name.lower()] > [] > > gives a non-empty result I'd investigate where the culprit is imported -- > /usr/lib/python2.6/sitecustomize.py would be the obvious candidate. Indeed! Thanks a lot, /usr/lib/python2.6/site-packages/sitecustomize.py was created by the package abrt-addon-python (at least this is the fedora name) and so it was activated by python itself completely independently from abrt (which was not running). Now I removed all packages called abrt-* and the problem is gone. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From ulrich.eckhardt at dominolaser.com Tue Oct 2 08:27:11 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 02 Oct 2012 14:27:11 +0200 Subject: unit testing class hierarchies Message-ID: Greetings! I'm trying to unittest a class hierachy using Python 2.7. I have a common baseclass Base and derived classes D1 and D2 that I want to test. The baseclass in not instantiatable on its own. Now, the first approach is to have test cases TestD1 and TestD2, both derived from class TestCase: class TestD1(unittest.TestCase): def test_base(self): ... def test_r(self): ... def test_s(self): ... class TestD2(unittest.TestCase): def test_base(self): # same as above ... def test_x(self): ... def test_y(self): ... As you see, the code for test_base() is redundant, so the idea is to move it to a baseclass: class TestBase(unittest.TestCase): def test_base(self): ... class TestD1(TestBase): def test_r(self): ... def test_s(self): ... class TestD2(TestBase): def test_x(self): ... def test_y(self): ... The problem here is that TestBase is not a complete test case (just as class Base is not complete), but the unittest framework will still try to run it on its own. One way around this is to not derive class TestBase from unittest.TestCase but instead use multiple inheritance in the derived classes [1]. Maybe it's just my personal gut feeling, but I don't like that solution, because it is not obvious that this class actually needs to be combined with a TestCase class in order to function. I would rather tell the unittest framework directly that it's not supposed to consider this intermediate class as a test case, but couldn't find a way to express that clearly. How would you do this? Uli [1] in C++ I would call that a "mixin" From aclark at aclark.net Tue Oct 2 09:12:54 2012 From: aclark at aclark.net (Alex Clark) Date: Tue, 2 Oct 2012 09:12:54 -0400 Subject: PIL questions: still supported? Problems on 2.7 for win? alternatives? References: Message-ID: On 2012-10-02 09:26:56 +0000, WhisperingWally said: > Gelonida N gmail.com> writes: > >> I wondered whether some of you have a little more insight into what's >> going on with PIL. > > AFAIK the latest PIL stuff lives here: > > hg.effbot.org Certainly true, though somewhat meaningless in the current context of "what's going on with PIL?"[1]. The latest Pillow (PIL fork) lives here: - https://github.com/python-imaging/Pillow And if folks commit meaningful changes there, we'll get releases out as needed. In other words, you are welcome and encouraged to explore all your options. And if it helps, you can affect the future of PIL in a meaningful way via Pillow. Alex [1] The last commit to: http://hg.effbot.org/pil-2009-raclette was in 2011. Based on that information, the answer would appear to be "nothing", which is why Pillow exists. -- Alex Clark ? http://aclark.net From andriy.kornatskyy at live.com Tue Oct 2 09:17:40 2012 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Tue, 2 Oct 2012 16:17:40 +0300 Subject: Fastest web framework In-Reply-To: References: , , <50604907.6060405@ziade.org>, , , <5062C603.90905@ziade.org>, , , <5062CDC6.40703@ziade.org>, Message-ID: In order to provide more reliable benchmark, I get rid of application server and network boundary. As a result I simulated a valid WSGI request and isolated calls just to the web framework alone. Also I found interesting to take a look at total number of calls and unique functions used by corresponding web framework. The post has been updated: http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html Isolated benchmark source code is here: https://bitbucket.org/akorn/helloworld/src/tip/benchmark.py I should mention several web frameworks experience huge memory leaks in this?benchmark. BONUS: added benchmark for python 3.3 (for the web frameworks that support it) and plain simple WSGI application (for contrast). Comments or suggestions are welcome. Thanks. Andriy Kornatskyy ---------------------------------------- > From: andriy.kornatskyy at live.com > To: tarek at ziade.org > Subject: RE: Fastest web framework > Date: Sat, 29 Sep 2012 12:18:32 +0300 > CC: python-list at python.org > > > Tarek, > > My response inline to your: > > > You are not getting my point. What happens to weezhy or XXX framework > > when you are running it in a given stack, under heavy load ? > > let me correct you, it is wheezy.web (not `weezhy`). > > Tell me your definition of web framework heavy load. If you have one, we > can try benchmark it. > > > There are many interactions that may impact the behavior of the stack - > > most of them are in the web server itself, but they can be things in the > > framework too, depending on the architectural choice. > > The reason I choose uWSGI is due to minimal possible impact that application > server may cause. Since this component `equally influence` productivity > of each framework it can be to some degree ignored. > > > And you will not know it with an hello world app. To put it more > > bluntly, your benchmark is going to join the big pile of hello worlds > > benchmarks that are completely meaningless. > > Can not agree. This is just simple thing. Simple things should run > fast, no doubt. If you can provide a better idea as to which framework > calls to put into benchmark, I will be happy extend the benchmark case. > > > If you want to prove that weezhy is faster than another py framework, > > because, I dunno, the number of function calls are smaller ? then you > > need to isolate this and > > do a different kind of bench. > > > > Have a look at http://plope.com/pyroptimization , it's a good example > > The numbers provided in that article are incorrect. They didn't match results > from the file they provide (result.txt in each framework dir) at the time > of writing. > > I have used that idea to re-run things (isolated benchmark; report with > total time, total number of calls and number of distinct functions used). > See here: > > https://bitbucket.org/akorn/helloworld/src/tip/benchmark.py > > I will update original post a bit later (to let you comment on this). > > > Same thing for the raw speed of your templating engine - isolation is > > required. > > Improved bigtable benchmark report by adding total number of calls and > number distinct functions used: > https://bitbucket.org/akorn/wheezy.template/src/tip/demos/bigtable/bigtable.py > > Original post not updated yet. > > > One good read: > > http://blog.ianbicking.org/2010/03/16/web-server-benchmarking-we-need/ > > Sounds not so bad. It points to some specific workloads. Any attempt to prioritize > and/or practically implement them? > > Thanks. > > Andriy From demianbrecht at gmail.com Tue Oct 2 10:05:49 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Tue, 02 Oct 2012 07:05:49 -0700 Subject: unit testing class hierarchies In-Reply-To: References: Message-ID: <506AF4BD.6080402@gmail.com> > [1] in C++ I would call that a "mixin" Mixins are perfectly valid Python constructs as well and are perfectly valid (imho) for this use case. On a side note, I usually append a "Mixin" suffix to my mixin classes in order to make it obvious to the reader. -- Demian Brecht @demianbrecht http://demianbrecht.github.com From thbach at students.uni-mainz.de Tue Oct 2 10:06:38 2012 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Tue, 2 Oct 2012 16:06:38 +0200 Subject: unit testing class hierarchies In-Reply-To: References: Message-ID: <20121002140638.GA5282@taris.box> On Tue, Oct 02, 2012 at 02:27:11PM +0200, Ulrich Eckhardt wrote: > As you see, the code for test_base() is redundant, so the idea is to > move it to a baseclass: > > class TestBase(unittest.TestCase): > def test_base(self): > ... > > class TestD1(TestBase): > def test_r(self): > ... > def test_s(self): > ... > > class TestD2(TestBase): > def test_x(self): > ... > def test_y(self): > ... Could you provide more background? How do you avoid that test_base() runs in TestD1 or TestD2? To me it sounds like test_base() is actually no test. Hence, I would rather give it a catchy name like _build_base_cls(). If a method name does not start with 'test' it is not considered a test to run automatically. Does this help? Regards, Thomas Bach. From demianbrecht at gmail.com Tue Oct 2 10:23:05 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Tue, 02 Oct 2012 07:23:05 -0700 Subject: Are ABCs an anti-pattern? Message-ID: <506AF8C9.8060406@gmail.com> I don't use them anymore, but I'm curious about others opinions on this list... The more time I spend in Python, discovering what "Pythonic" code is and such, it seems that I throw away much in terms of academic learnings as far as "OOP correctness" goes. In doing so, I find that, in general, overall LOC (yes, I'm aware that this is a poor metric to judge anything on), readability and overall quality of code seems to go up. Yes, you give the user much more rope to hang themselves with making the general assumption that the user knows what they're doing, but we're all consenting adults here after all, right? ;) As an example, I initially had an OAuth 2.0 client library that was roughly 450 LOC (using ABCs, adapter patterns for the various flows, etc). Dropping this for a more "Pythonic" (at least, what my interpretation of Pythonic code is) brought the entire library down to 55 LOC. Having said that, the decline in LOC and overall grok-ability wasn't entirely due to moving away from ABCs and dropping the use of adapters, but it did have quite a bit to do with it). As such, I see ABCs as somewhat of an anti-pattern in the Python world. The concept is obviously essential in non-duck-typed language using strict OOP, but does it *really* belong in Python? -- Demian Brecht @demianbrecht http://demianbrecht.github.com From __peter__ at web.de Tue Oct 2 10:32:48 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Oct 2012 16:32:48 +0200 Subject: unit testing class hierarchies References: Message-ID: Ulrich Eckhardt wrote: > As you see, the code for test_base() is redundant, so the idea is to > move it to a baseclass: > > class TestBase(unittest.TestCase): > def test_base(self): > ... > > class TestD1(TestBase): > def test_r(self): > ... > def test_s(self): > ... > > class TestD2(TestBase): > def test_x(self): > ... > def test_y(self): > ... > > The problem here is that TestBase is not a complete test case (just as > class Base is not complete), but the unittest framework will still try > to run it on its own. One way around this is to not derive class > TestBase from unittest. Another is to remove it from the global namespace with del TestBase From fayaz at dexetra.com Tue Oct 2 11:05:33 2012 From: fayaz at dexetra.com (Fayaz Yusuf Khan) Date: Tue, 02 Oct 2012 20:35:33 +0530 Subject: unit testing class hierarchies References: Message-ID: Peter Otten wrote: > Ulrich Eckhardt wrote: >> The problem here is that TestBase is not a complete test case (just as >> class Base is not complete), but the unittest framework will still try >> to run it on its own. How exactly are you invoking the test runner? unittest? nose? You can tell the test discoverer which classes you want it to run and which ones you don't. For the unittest library, I use my own custom load_tests methods: def load_tests(loader, tests, pattern): testcases = [TestD1, TestD2] return TestSuite([loader.loadTestsFromTestCase(testcase) for testcase in testcases]) http://docs.python.org/library/unittest.html#load-tests-protocol >> One way around this is to not derive class >> TestBase from unittest. > > Another is to remove it from the global namespace with > > del TestBase Removing the class from namespace may or may not help. Consider a scenario where someone decided to be creative with the cls.__bases__ attribute. -- Fayaz Yusuf Khan Cloud architect, Dexetra SS, India fayaz.yusuf.khan_AT_gmail_DOT_com, fayaz_AT_dexetra_DOT_com +91-9746-830-823 From ulrich.eckhardt at dominolaser.com Tue Oct 2 11:24:35 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 02 Oct 2012 17:24:35 +0200 Subject: unit testing class hierarchies In-Reply-To: References: Message-ID: Am 02.10.2012 16:06, schrieb Thomas Bach: > On Tue, Oct 02, 2012 at 02:27:11PM +0200, Ulrich Eckhardt wrote: >> As you see, the code for test_base() is redundant, so the idea is to >> move it to a baseclass: >> >> class TestBase(unittest.TestCase): >> def test_base(self): >> ... >> >> class TestD1(TestBase): >> def test_r(self): >> ... >> def test_s(self): >> ... >> >> class TestD2(TestBase): >> def test_x(self): >> ... >> def test_y(self): >> ... > > Could you provide more background? How do you avoid that test_base() > runs in TestD1 or TestD2? Sorry, there's a misunderstanding: I want test_base() to be run as part of both TestD1 and TestD2, because it tests basic functions provided by both class D1 and D2. Uli From thudfoo at gmail.com Tue Oct 2 12:03:47 2012 From: thudfoo at gmail.com (xDog Walker) Date: Tue, 2 Oct 2012 09:03:47 -0700 Subject: parse an environment file In-Reply-To: <5069b829$0$6949$e4fe514c@news2.news.xs4all.nl> References: <5069b829$0$6949$e4fe514c@news2.news.xs4all.nl> Message-ID: <201210020903.47187.thudfoo@gmail.com> On Monday 2012 October 01 08:35, Hans Mulder wrote: > AFAIK, there is no Python module that can read shell syntax. The stdlib's shlex might be that module. -- Yonder nor sorghum stenches shut ladle gulls stopper torque wet strainers. From maniandram01 at gmail.com Tue Oct 2 12:12:04 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 2 Oct 2012 09:12:04 -0700 (PDT) Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: On Monday, 1 October 2012 13:47:50 UTC+5:30, Mark Lawrence wrote: > On 01/10/2012 01:58, 88888 Dihedral wrote: > > > > > > Your question seems vague to me. If you know you are storing > > > only immutable tuples in a list, then the way to iterate is simple. > > > > > > > Does Python have a magic method that let's me use mutable tuples? I'd > > also like immutable lists. Is it worth raising a feature request on the > > bug tracker? > > > > -- > > Cheers. > > > > Mark Lawrence. Mark, you are talking to a bot. From maniandram01 at gmail.com Tue Oct 2 12:12:04 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 2 Oct 2012 09:12:04 -0700 (PDT) Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: On Monday, 1 October 2012 13:47:50 UTC+5:30, Mark Lawrence wrote: > On 01/10/2012 01:58, 88888 Dihedral wrote: > > > > > > Your question seems vague to me. If you know you are storing > > > only immutable tuples in a list, then the way to iterate is simple. > > > > > > > Does Python have a magic method that let's me use mutable tuples? I'd > > also like immutable lists. Is it worth raising a feature request on the > > bug tracker? > > > > -- > > Cheers. > > > > Mark Lawrence. Mark, you are talking to a bot. From maniandram01 at gmail.com Tue Oct 2 12:16:09 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 2 Oct 2012 09:16:09 -0700 (PDT) Subject: parse an environment file In-Reply-To: References: <5069b829$0$6949$e4fe514c@news2.news.xs4all.nl> Message-ID: On Tuesday, 2 October 2012 21:34:04 UTC+5:30, xDog Walker wrote: > On Monday 2012 October 01 08:35, Hans Mulder wrote: > > > AFAIK, there is no Python module that can read shell syntax. > > > > The stdlib's shlex might be that module. > > > > -- > > Yonder nor sorghum stenches shut ladle gulls stopper torque wet > > strainers. shlex can only split shell code into tokens. From maniandram01 at gmail.com Tue Oct 2 12:16:09 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 2 Oct 2012 09:16:09 -0700 (PDT) Subject: parse an environment file In-Reply-To: References: <5069b829$0$6949$e4fe514c@news2.news.xs4all.nl> Message-ID: On Tuesday, 2 October 2012 21:34:04 UTC+5:30, xDog Walker wrote: > On Monday 2012 October 01 08:35, Hans Mulder wrote: > > > AFAIK, there is no Python module that can read shell syntax. > > > > The stdlib's shlex might be that module. > > > > -- > > Yonder nor sorghum stenches shut ladle gulls stopper torque wet > > strainers. shlex can only split shell code into tokens. From maniandram01 at gmail.com Tue Oct 2 12:17:20 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 2 Oct 2012 09:17:20 -0700 (PDT) Subject: How to apply the user's HTML environment in a Python programme? In-Reply-To: <4be2f2ac-c061-48d7-baf1-212e28f2f5ec@googlegroups.com> References: <4382e132-4eb5-4733-9fed-535e704f2175@googlegroups.com> <3de0aac0-d7f2-4990-9428-54c89b143b9a@googlegroups.com> <4be2f2ac-c061-48d7-baf1-212e28f2f5ec@googlegroups.com> Message-ID: <33028bcf-9e6e-4460-81d8-4a86de763cf5@googlegroups.com> On Monday, 1 October 2012 19:49:27 UTC+5:30, BobAalsma wrote: > Op vrijdag 21 september 2012 16:15:30 UTC+2 schreef Joel Goldstick het volgende: > > > On Fri, Sep 21, 2012 at 9:58 AM, BobAalsma wrote: > > > > > > > Op vrijdag 21 september 2012 15:36:11 UTC+2 schreef Jerry Hill het volgende: > > > > > > >> On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma wrote: > > > > > > >> > > > > > > >> > Thanks, Joel, yes, but as far as I'm aware these would all require the Python programme to have the user's username and password (or "credentials"), which I wanted to avoid. > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> No matter what you do, your web service is going to have to > > > > > > >> > > > > > > >> authenticate with the remote web site. The details of that > > > > > > >> > > > > > > >> authentication are going to vary with each remote web site you want to > > > > > > >> > > > > > > >> connect to. > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> -- > > > > > > >> > > > > > > >> Jerry > > > > > > > > > > > > > > Hmm, from the previous posts I get the impression that I could best solve this by asking the user for the specific combination of username, password and URL + promising not to keep any of that... > > > > > > > > > > > > > > OK, that does sound doable - thank you all > > > > > > > > > > > > > > > > > > I recommend that you write your program to read pages that are not > > > > > > protected. Once you get that working, you can go back and figure out > > > > > > how you want to get the username/password from your 'friends' and add > > > > > > that in. Also look up Beautiful Soup (version 4) for a great library > > > > > > to parse the pages that you retrieve > > > > > > > > > > > > > > Bob > > > > > > > -- > > > > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > Joel Goldstick > > > > Joel, > > > > I've spent some time with this but don't really understand my results - some help would be appreciated. > > I've built a tester that will read my LinkedIn home page, which is password protected. > > When I use that method for reading other people's pages, the program is redirected to the LinkedIn login page. > > When I paste the URLs for the other people's pages in any browser, the requested pages are shown. > > > > Bob Not all the authentication information is in the URL. Some of it is in cookies in the browser. From breamoreboy at yahoo.co.uk Tue Oct 2 12:44:45 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 02 Oct 2012 17:44:45 +0100 Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: On 02/10/2012 17:12, Ramchandra Apte wrote: > On Monday, 1 October 2012 13:47:50 UTC+5:30, Mark Lawrence wrote: >> On 01/10/2012 01:58, 88888 Dihedral wrote: >> >>> >> >>> Your question seems vague to me. If you know you are storing >> >>> only immutable tuples in a list, then the way to iterate is simple. >> >>> >> >> >> >> Does Python have a magic method that let's me use mutable tuples? I'd >> >> also like immutable lists. Is it worth raising a feature request on the >> >> bug tracker? >> >> >> >> -- >> >> Cheers. >> >> >> >> Mark Lawrence. > > Mark, you are talking to a bot. > What happened to freedom of speech? If I want to talk to a bot, I'll talk to a bot. Besides I'm not convinced it/he/she is a bot. Plus if you read my post carefully, add in several years experience of Python the language and Python the comedy, you might come to the conclusion that a certain amount of urine extraction was going on :) -- Cheers. Mark Lawrence. From ulrich.eckhardt at dominolaser.com Tue Oct 2 12:54:41 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 02 Oct 2012 18:54:41 +0200 Subject: unit testing class hierarchies In-Reply-To: References: Message-ID: Am 02.10.2012 16:06, schrieb Thomas Bach: > On Tue, Oct 02, 2012 at 02:27:11PM +0200, Ulrich Eckhardt wrote: >> As you see, the code for test_base() is redundant, so the idea is to >> move it to a baseclass: >> >> class TestBase(unittest.TestCase): >> def test_base(self): >> ... >> >> class TestD1(TestBase): >> def test_r(self): >> ... >> def test_s(self): >> ... >> >> class TestD2(TestBase): >> def test_x(self): >> ... >> def test_y(self): >> ... > > Could you provide more background? How do you avoid that test_base() > runs in TestD1 or TestD2? Sorry, there's a misunderstanding: I want test_base() to be run as part of both TestD1 and TestD2, because it tests basic functions provided by both classes D1 and D2. The instances of D1 and D2 are created in TestD1.setUp and TestD2.setUp and then used by all tests. There is no possible implementation creating such an instance for TestBase, since the baseclass is abstract. Last edit for today, I hope that makes my intentions clear... ;) Uli From __peter__ at web.de Tue Oct 2 13:38:23 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Oct 2012 19:38:23 +0200 Subject: unit testing class hierarchies References: Message-ID: Ulrich Eckhardt wrote: > Am 02.10.2012 16:06, schrieb Thomas Bach: >> On Tue, Oct 02, 2012 at 02:27:11PM +0200, Ulrich Eckhardt wrote: >>> As you see, the code for test_base() is redundant, so the idea is to >>> move it to a baseclass: >>> >>> class TestBase(unittest.TestCase): >>> def test_base(self): >>> ... >>> >>> class TestD1(TestBase): >>> def test_r(self): >>> ... >>> def test_s(self): >>> ... >>> >>> class TestD2(TestBase): >>> def test_x(self): >>> ... >>> def test_y(self): >>> ... >> >> Could you provide more background? How do you avoid that test_base() >> runs in TestD1 or TestD2? > > Sorry, there's a misunderstanding: I want test_base() to be run as part > of both TestD1 and TestD2, because it tests basic functions provided by > both classes D1 and D2. The instances of D1 and D2 are created in > TestD1.setUp and TestD2.setUp and then used by all tests. There is no > possible implementation creating such an instance for TestBase, since > the baseclass is abstract. > > Last edit for today, I hope that makes my intentions clear... > > ;) Ceterum censeo baseclassinem esse delendam ;) $ cat test_shared.py import unittest class Shared(unittest.TestCase): def test_shared(self): pass class D1(Shared): def test_d1_only(self): pass class D2(Shared): def test_d2_only(self): pass del Shared unittest.main() $ python test_shared.py -v test_d1_only (__main__.D1) ... ok test_shared (__main__.D1) ... ok test_d2_only (__main__.D2) ... ok test_shared (__main__.D2) ... ok ---------------------------------------------------------------------- Ran 4 tests in 0.000s OK $ From __peter__ at web.de Tue Oct 2 13:40:38 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Oct 2012 19:40:38 +0200 Subject: unit testing class hierarchies References: Message-ID: Fayaz Yusuf Khan wrote: > Peter Otten wrote: > >> Ulrich Eckhardt wrote: >>> The problem here is that TestBase is not a complete test case (just > as >>> class Base is not complete), but the unittest framework will still > try >>> to run it on its own. > How exactly are you invoking the test runner? unittest? nose? You can > tell the test discoverer which classes you want it to run and which > ones you don't. For the unittest library, I use my own custom > load_tests methods: > def load_tests(loader, tests, pattern): > testcases = [TestD1, TestD2] > return TestSuite([loader.loadTestsFromTestCase(testcase) > for testcase in testcases]) > http://docs.python.org/library/unittest.html#load-tests-protocol > >>> One way around this is to not derive class >>> TestBase from unittest. >> >> Another is to remove it from the global namespace with >> >> del TestBase > Removing the class from namespace may or may not help. Consider a > scenario where someone decided to be creative with the cls.__bases__ > attribute. Isn't that a bit far-fetched? I'd rather start simple and fix problems as they arise... From dreamingforward at gmail.com Tue Oct 2 13:51:04 2012 From: dreamingforward at gmail.com (Mark Adam) Date: Tue, 2 Oct 2012 12:51:04 -0500 Subject: Are ABCs an anti-pattern? In-Reply-To: <506AF8C9.8060406@gmail.com> References: <506AF8C9.8060406@gmail.com> Message-ID: On Tue, Oct 2, 2012 at 9:23 AM, Demian Brecht wrote: > I don't use them anymore, but I'm curious about others opinions on this > list... > Interesting question. I think they haven't been useful for representing the real world as everyone hoped, but are pretty good for organizing structures within the Python universe (like "object "collections" --> {'list','set','dict'...}, for example). mark -------------- next part -------------- An HTML attachment was scrubbed... URL: From demianbrecht at gmail.com Tue Oct 2 13:51:31 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Tue, 2 Oct 2012 10:51:31 -0700 Subject: unit testing class hierarchies In-Reply-To: References: Message-ID: Am I missing something? Is there something that wasn't answered by my reply about using mixins? from unittest import TestCase class SharedTestMixin(object): def test_shared(self): self.assertNotEquals('foo', 'bar') class TestA(TestCase, SharedTestMixin): def test_a(self): self.assertEquals('a', 'a') class TestB(TestCase, SharedTestMixin): def test_b(self): self.assertEquals('b', 'b') $ nosetests test.py -v test_a (test.TestA) ... ok test_shared (test.TestA) ... ok test_b (test.TestB) ... ok test_shared (test.TestB) ... ok ---------------------------------------------------------------------- Ran 4 tests in 0.001s OK This seems to be a clear answer to the problem that solves the original requirements without introducing error-prone, non-obvious solutions. > Sorry, there's a misunderstanding: I want test_base() to be run as part of > both TestD1 and TestD2, because it tests basic functions provided by both > classes D1 and D2. The instances of D1 and D2 are created in TestD1.setUp > and TestD2.setUp and then used by all tests. There is no possible > implementation creating such an instance for TestBase, since the baseclass > is abstract. > > Last edit for today, I hope that makes my intentions clear... > > ;) > > Uli > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Oct 2 13:58:02 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Oct 2012 03:58:02 +1000 Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: On Wed, Oct 3, 2012 at 2:44 AM, Mark Lawrence wrote: > What happened to freedom of speech? If I want to talk to a bot, I'll talk > to a bot. Besides I'm not convinced it/he/she is a bot. Plus if you read > my post carefully, add in several years experience of Python the language > and Python the comedy, you might come to the conclusion that a certain > amount of urine extraction was going on :) Coupled with a bit of bot-seeding, which is always fun. One of these days I'm going to mail Dihedral a whole pile of Gilbert and Sullivan operetta and see if any of it comes back in his posts... Dihedral might be a bot and might not. I've come to the conclusion that it's not worth trying to find out, given that a good bot can outdo a lot of humans in useful conversation. ChrisA From demianbrecht at gmail.com Tue Oct 2 14:06:42 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Tue, 2 Oct 2012 11:06:42 -0700 Subject: unit testing class hierarchies In-Reply-To: References: Message-ID: Am I missing something? Is there something that wasn't answered by my reply about using mixins? from unittest import TestCase class SharedTestMixin(object): def test_shared(self): self.assertNotEquals('foo', 'bar') class TestA(TestCase, SharedTestMixin): def test_a(self): self.assertEquals('a', 'a') class TestB(TestCase, SharedTestMixin): def test_b(self): self.assertEquals('b', 'b') $ nosetests test.py -v test_a (test.TestA) ... ok test_shared (test.TestA) ... ok test_b (test.TestB) ... ok test_shared (test.TestB) ... ok ---------------------------------------------------------------------- Ran 4 tests in 0.001s OK This seems to be a clear answer to the problem that solves the original requirements without introducing error-prone, non-obvious solutions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Tue Oct 2 14:35:55 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 02 Oct 2012 19:35:55 +0100 Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: On 02/10/2012 18:58, Chris Angelico wrote: > > Dihedral might be a bot and might not. I've come to the conclusion > that it's not worth trying to find out, given that a good bot can > outdo a lot of humans in useful conversation. > > ChrisA > Try telling that to the newbies on the Python tutor mailing list and they simply won't believe ya :) -- Cheers. Mark Lawrence. From breamoreboy at yahoo.co.uk Tue Oct 2 14:41:11 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 02 Oct 2012 19:41:11 +0100 Subject: unit testing class hierarchies In-Reply-To: References: Message-ID: On 02/10/2012 19:06, Demian Brecht wrote: > Am I missing something? Is there something that wasn't answered by my reply > about using mixins? > > from unittest import TestCase > > class SharedTestMixin(object): > def test_shared(self): > self.assertNotEquals('foo', 'bar') > > class TestA(TestCase, SharedTestMixin): > def test_a(self): > self.assertEquals('a', 'a') > > class TestB(TestCase, SharedTestMixin): > def test_b(self): > self.assertEquals('b', 'b') > > $ nosetests test.py -v > test_a (test.TestA) ... ok > test_shared (test.TestA) ... ok > test_b (test.TestB) ... ok > test_shared (test.TestB) ... ok > > ---------------------------------------------------------------------- > Ran 4 tests in 0.001s > > OK > > This seems to be a clear answer to the problem that solves the original > requirements without introducing error-prone, non-obvious solutions. > > > Peter Otten's response is obviously vastly superior to yours, 4 tests in 0.000s compared to your highly inefficient 4 tests in 0.001s :) -- Cheers. Mark Lawrence. From tjreedy at udel.edu Tue Oct 2 14:55:54 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Oct 2012 14:55:54 -0400 Subject: Are ABCs an anti-pattern? In-Reply-To: <506AF8C9.8060406@gmail.com> References: <506AF8C9.8060406@gmail.com> Message-ID: On 10/2/2012 10:23 AM, Demian Brecht wrote: > I don't use them anymore, but I'm curious about others opinions on this > list... > > The more time I spend in Python, discovering what "Pythonic" code is and > such, it seems that I throw away much in terms of academic learnings as > far as "OOP correctness" goes. In doing so, I find that, in general, > overall LOC (yes, I'm aware that this is a poor metric to judge anything > on), readability and overall quality of code seems to go up. Yes, you > give the user much more rope to hang themselves with making the general > assumption that the user knows what they're doing, but we're all > consenting adults here after all, right? ;) > > As an example, I initially had an OAuth 2.0 client library that was > roughly 450 LOC (using ABCs, adapter patterns for the various flows, > etc). Dropping this for a more "Pythonic" (at least, what my > interpretation of Pythonic code is) brought the entire library down to > 55 LOC. Having said that, the decline in LOC and overall grok-ability > wasn't entirely due to moving away from ABCs and dropping the use of > adapters, but it did have quite a bit to do with it). > > As such, I see ABCs as somewhat of an anti-pattern in the Python world. > The concept is obviously essential in non-duck-typed language using > strict OOP, but does it *really* belong in Python? ABCs were added (fairly recently) in 3.0 for the reasons given in http://python.org/dev/peps/pep-3119/ It was expected that it would take awhile for them to see good, pythonic uses. We obviously did okay without them up to 2.7. They are partly informational, partly meant to help duck typing. I don't think they are used much in the stdlib (except to register classes) and I have not used them myself. -- Terry Jan Reedy From tjreedy at udel.edu Tue Oct 2 14:59:04 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Oct 2012 14:59:04 -0400 Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: On 10/2/2012 1:58 PM, Chris Angelico wrote: > On Wed, Oct 3, 2012 at 2:44 AM, Mark Lawrence wrote: >> What happened to freedom of speech? If I want to talk to a bot, I'll talk >> to a bot. Besides I'm not convinced it/he/she is a bot. Plus if you read >> my post carefully, add in several years experience of Python the language >> and Python the comedy, you might come to the conclusion that a certain >> amount of urine extraction was going on :) > > Coupled with a bit of bot-seeding, which is always fun. > > One of these days I'm going to mail Dihedral a whole pile of Gilbert > and Sullivan operetta and see if any of it comes back in his posts... > > Dihedral might be a bot and might not. I've come to the conclusion > that it's not worth trying to find out, given that a good bot can > outdo a lot of humans in useful conversation. I just read that bots playing Unreal Tournament with an 'act human' module seem more human to at least some humans than humans. Perhaps that is because humans have to become bot-like to play UT well. -- Terry Jan Reedy From timothyh2ster at gmail.com Tue Oct 2 15:01:05 2012 From: timothyh2ster at gmail.com (timothy holmes) Date: Tue, 2 Oct 2012 12:01:05 -0700 Subject: trying to unsubscribe Message-ID: My efforts at trying to unsubscribe are not working. Could you help me with this, or take this email as a request to unsubscribe. Thanks, Timothy Holmes -------------- next part -------------- An HTML attachment was scrubbed... URL: From tyler at tysdomain.com Tue Oct 2 16:00:27 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Tue, 02 Oct 2012 14:00:27 -0600 Subject: design question:game skill system Message-ID: <506B47DB.9030401@tysdomain.com> Hello all: I'm looking at a skill/perk system, where the player builds up his char by using perk points to add abilities. Each perk is under a category, and generally costs go up as you increase the perk. So I'm trying to figure something out; first, I'd really like the cost calculation and all of that to be dynamic, so that I don't have to write a calculateCost per object. I'd also like to be able to specify dependencies and say a level, as well as other factors before a player can obtain a perk and have them self documenting. The idea is that a player could do something like: data perk extended health and it would tell them they require health at 50 before they can purchase extended health, as well as the cost, the increase per level and the total overall cost. Any ideas on how to set this up would be really appreciated. Finally, I'm curious how to store and calculate these. I thought about using a uid per perk, then storing something like: {uid:level} on the player, but means that I have to lookup the name somehow still in the main perk database, then use that uid to check if the player has it. Are there better ways of storing skills? I'm also thinking about calculation; currently the CalculateMaxHp method would have to add up all the possible perks for health, then add stats and all that. That could get really rough on performance if it's called often; would something like a cache work, where you have something like: {attribute:dirty}? So if I call CalculateHealth, it checks for the dirty flag, and if it doesn't exist just returns the previous max HP, but if the dirty flag is set, it recalculates? Then anything modifying health (level gains, perks, stat increases/etc) would just set the dirty flag and call calculate? Thoughts/ideas would be welcome. Thanks, -- 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 joel.goldstick at gmail.com Tue Oct 2 16:08:17 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 2 Oct 2012 16:08:17 -0400 Subject: trying to unsubscribe In-Reply-To: References: Message-ID: On Tue, Oct 2, 2012 at 3:01 PM, timothy holmes wrote: > My efforts at trying to unsubscribe are not working. Could you help me with > this, or take this email as a request to unsubscribe. > Thanks, > Timothy Holmes > > -- > http://mail.python.org/mailman/listinfo/python-list > Go here http://mail.python.org/mailman/listinfo/python-list and look for unsubscribe near the bottom -- Joel Goldstick From ian.g.kelly at gmail.com Tue Oct 2 16:34:12 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 2 Oct 2012 14:34:12 -0600 Subject: design question:game skill system In-Reply-To: <506B47DB.9030401@tysdomain.com> References: <506B47DB.9030401@tysdomain.com> Message-ID: On Tue, Oct 2, 2012 at 2:00 PM, Littlefield, Tyler wrote: > Hello all: > I'm looking at a skill/perk system, where the player builds up his char by > using perk points to add abilities. > Each perk is under a category, and generally costs go up as you increase the > perk. > So I'm trying to figure something out; first, I'd really like the cost > calculation and all of that to be dynamic, so that I don't have to write a > calculateCost per object. I'd also like to be able to specify dependencies > and say a level, as well as other factors before a player can obtain a perk > and have them self documenting. The idea is that a player could do something > like: > data perk extended health > and it would tell them they require health at 50 before they can purchase > extended health, as well as the cost, the increase per level and the total > overall cost. What are the cost calculations based on? If there are specific formulas then you would need to store them somehow, possibly just as a function to be called or string to be evaled, but if the security of the perk database is of concern then you could engineer a more sandboxed representation. For dependencies, you can keep them in a container. An extended health perk might look something like: cost_formula = "5 * level ** 2" dependencies = {HEALTH: 50, PLAYER_LEVEL: 15} benefits = {HEALTH: "7 * level"} where HEALTH and PLAYER_LEVEL are just some arbitrary known constants. Your core perks library would then be responsible for looking this information up, running the formulas, and performing whatever calculations on it are needed. > Finally, I'm curious how to store and calculate these. I thought about using > a uid per perk, then storing something like: {uid:level} on the player, but > means that I have to lookup the name somehow still in the main perk > database, then use that uid to check if the player has it. Are there better > ways of storing skills? When you say uids, you mean UUIDs, right? I'm not sure what advantage there is in using abstracted unique identifiers for these. Assuming you have full control over what perks are added, you can ensure there will be no name clashes, so why not just use the name or a name-based tag to uniquely identify each perk? Regardless of how you identify them, though, your code is at some point going to have to go to the database to look them up, so I would suggest you just go ahead and write that code, and then you can add some caching later if it turns out to be needed. > I'm also thinking about calculation; currently the > CalculateMaxHp method would have to add up all the possible perks for > health, then add stats and all that. That could get really rough on > performance if it's called often; would something like a cache work, where > you have something like: {attribute:dirty}? So if I call CalculateHealth, it > checks for the dirty flag, and if it doesn't exist just returns the previous > max HP, but if the dirty flag is set, it recalculates? Then anything > modifying health (level gains, perks, stat increases/etc) would just set the > dirty flag and call calculate? Sounds reasonable. I wouldn't use a separate flag attribute, though. When max HP becomes dirty, clear the cached value, and use the absence of a cached value to inform your code that it needs to recalculate. From dihedral88888 at googlemail.com Tue Oct 2 16:54:20 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 2 Oct 2012 13:54:20 -0700 (PDT) Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: <853f0efb-875c-47f3-be4a-f9a667857c4d@googlegroups.com> On Monday, October 1, 2012 4:17:50 PM UTC+8, Mark Lawrence wrote: > On 01/10/2012 01:58, 88888 Dihedral wrote: > > > > > > Your question seems vague to me. If you know you are storing > > > only immutable tuples in a list, then the way to iterate is simple. > > > > > > > Does Python have a magic method that let's me use mutable tuples? I'd > > also like immutable lists. Is it worth raising a feature request on the > > bug tracker? > > > > -- > > Cheers. > > > > Mark Lawrence. Python resolves objects by names and dynamical types. This will force the programmer to write structured programs. From dihedral88888 at googlemail.com Tue Oct 2 16:54:20 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 2 Oct 2012 13:54:20 -0700 (PDT) Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: <853f0efb-875c-47f3-be4a-f9a667857c4d@googlegroups.com> On Monday, October 1, 2012 4:17:50 PM UTC+8, Mark Lawrence wrote: > On 01/10/2012 01:58, 88888 Dihedral wrote: > > > > > > Your question seems vague to me. If you know you are storing > > > only immutable tuples in a list, then the way to iterate is simple. > > > > > > > Does Python have a magic method that let's me use mutable tuples? I'd > > also like immutable lists. Is it worth raising a feature request on the > > bug tracker? > > > > -- > > Cheers. > > > > Mark Lawrence. Python resolves objects by names and dynamical types. This will force the programmer to write structured programs. From u4.sunny at gmail.com Tue Oct 2 17:26:05 2012 From: u4.sunny at gmail.com (sunny narang) Date: Tue, 2 Oct 2012 14:26:05 -0700 (PDT) Subject: Python Developers needed in Austin TX with a top notch IT company Message-ID: <0016597f-ad5c-4e6e-adca-8303372a402b@googlegroups.com> Job Title: Python developers Duration: 6 months; Location: Austin TX Responsibilities / Skills: 1) distributed complex application experience 2) prefer experience with enterprise class identity management systems, particularly around auth/credentials 3) experience with openstack 4) experience with large scale systems 5) Proficiency with Linux, ability to write Bash / Perl / Python scripts to run CRON jobs 6) Experience working in an agile environment and with a distributed team If interested, please reply with your updated Resume at sunny_narang at persistent.co.in Regards, Sunny Narang Talent Acquisition sunny_narang at persistent.co.in Persistent Systems Ltd. | 20 Glorious Years | www.persistentsys.com From ben+python at benfinney.id.au Tue Oct 2 18:30:19 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Oct 2012 08:30:19 +1000 Subject: unit testing class hierarchies References: Message-ID: <7wwqz8cxs4.fsf@benfinney.id.au> Ulrich Eckhardt writes: > I want test_base() to be run as part of both TestD1 and TestD2, > because it tests basic functions provided by both classes D1 and D2. It sounds, from your description so far, that you have identified a design flaw in D1 and D2. The common functionality should be moved to a common code point (maybe a base class of D1 and D2; maybe a function without need of a class). Then you'll have only one occurrence of that functionality to test, which is good design as well as easier test code :-) -- \ ?When I was a little kid we had a sand box. It was a quicksand | `\ box. I was an only child... eventually.? ?Steven Wright | _o__) | Ben Finney From hotmail.com at gmail.com Tue Oct 2 19:11:34 2012 From: hotmail.com at gmail.com (hotmail.com at gmail.com) Date: Tue, 2 Oct 2012 16:11:34 -0700 (PDT) Subject: Issue installing pyopencv in mac In-Reply-To: References: Message-ID: <0990112d-13d4-401e-804e-4926389ddee0@googlegroups.com> On Wednesday, August 29, 2012 6:21:50 AM UTC-4, Rakesh Rocker RuLZzz wrote: > I tried installing pyopencv in mac but i gives me an error > > I have installed all the dependent softwares like opencv,boost, etc....still unable to fix it. > > also i have updated xcode and using python 2.7 > > I also tried using mac port but still no use > > > > can anybody help me....Thanks in advance. Are you having these issues? http://stackoverflow.com/questions/12354628/errors-met-while-installing-pyopencv-2-1-0-with-opencv-2-4-2 Because I am getting this exact error too. I installed Boost 1.50.0 and OpenCV 2.4.2 using Homebrew, and am trying to install pyopencv 2.1.0 with pip+virtualenv, to no avail. Python 2.7.2, Mac OSX Mountain Lion. I hope someone out there has figured this out. From christos.jonathan.hayward at gmail.com Tue Oct 2 19:12:59 2012 From: christos.jonathan.hayward at gmail.com (Jonathan Hayward) Date: Tue, 2 Oct 2012 16:12:59 -0700 (PDT) Subject: Experimental Python-based shell Message-ID: <8646284b-df85-45fe-a793-56b081c6262c@googlegroups.com> I've made an experimental Python-based Unix/Linux shell at: http://JonathansCorner.com/cjsh/ An experimental Unix/Linux command line shell, implemented in Python 3, that takes advantage of some more recent concepts in terms of usability and searching above pinpointing files in heirarchies. I invite you to try it. Jonathan Hayward, Jonathan.Hayward at pobox.com, JonathansCorner.com From roy at panix.com Tue Oct 2 19:46:00 2012 From: roy at panix.com (Roy Smith) Date: Tue, 02 Oct 2012 19:46:00 -0400 Subject: unit testing class hierarchies References: Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > >> Another is to remove it from the global namespace with > >> > >> del TestBase When I had this problem, that's the solution I used. From steve+comp.lang.python at pearwood.info Tue Oct 2 20:57:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Oct 2012 00:57:20 GMT Subject: Slicing iterables in sub-generators without loosing elements References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: <506b8d70$0$29982$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Oct 2012 03:58:02 +1000, Chris Angelico wrote: > Dihedral might be a bot and might not. I've come to the conclusion that > it's not worth trying to find out, given that a good bot can outdo a lot > of humans in useful conversation. Oh, I'm convinced that it's a bot. The fact that Dihedral never responds to conversations about him/it is a give away: nearly all people are far to egotistical to let accusations of bot-hood go unchallenged. And even though its responses are grammatically correct, they often are semantically meaningless. Even the best AIs (Evie, CleverBot, Alice) don't come close to passing the Turing test. It helps that Dihedral only talks about computer programming, but even so, it has well and truly failed my personal Turing test. Mind you, some human beings fail the Turing test too: http://northernplanets.blogspot.com.au/2006/06/failing-turing-test.html Of course, Dihedral's creator wanted to really confound us, the occasional human response would probably muddy the waters sufficiently. -- Steven From dihedral88888 at googlemail.com Tue Oct 2 21:11:20 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 2 Oct 2012 18:11:20 -0700 (PDT) Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: <506b8d70$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> <506b8d70$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7b411618-ab6b-4d07-b272-caf0c4acc3cd@googlegroups.com> Steven D'Aprano? 2012?10?3????UTC+8??8?57?20???? > On Wed, 03 Oct 2012 03:58:02 +1000, Chris Angelico wrote: > > > > > Dihedral might be a bot and might not. I've come to the conclusion that > > > it's not worth trying to find out, given that a good bot can outdo a lot > > > of humans in useful conversation. > > > > Oh, I'm convinced that it's a bot. > > > > The fact that Dihedral never responds to conversations about him/it is a > > give away: nearly all people are far to egotistical to let accusations of > > bot-hood go unchallenged. And even though its responses are grammatically > > correct, they often are semantically meaningless. Even the best AIs > > (Evie, CleverBot, Alice) don't come close to passing the Turing test. It > > helps that Dihedral only talks about computer programming, but even so, > > it has well and truly failed my personal Turing test. > > > > Mind you, some human beings fail the Turing test too: > > > > http://northernplanets.blogspot.com.au/2006/06/failing-turing-test.html > > > > > > Of course, Dihedral's creator wanted to really confound us, the > > occasional human response would probably muddy the waters sufficiently. > > > > > > > > -- > > Steven Are you still not getting the generator part in Python? Do you really test any generator before? From steve+comp.lang.python at pearwood.info Tue Oct 2 21:20:52 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Oct 2012 01:20:52 GMT Subject: unit testing class hierarchies References: Message-ID: <506b92f3$0$29982$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Oct 2012 08:30:19 +1000, Ben Finney wrote: > Ulrich Eckhardt writes: > >> I want test_base() to be run as part of both TestD1 and TestD2, because >> it tests basic functions provided by both classes D1 and D2. > > It sounds, from your description so far, that you have identified a > design flaw in D1 and D2. > > The common functionality should be moved to a common code point (maybe a > base class of D1 and D2; maybe a function without need of a class). Then > you'll have only one occurrence of that functionality to test, which is > good design as well as easier test code :-) But surely, regardless of where that functionality is defined, you still need to test that both D1 and D2 exhibit the correct behaviour? Otherwise D2 (say) may break that functionality and your tests won't notice. Given a class hierarchy like this: class AbstractBaseClass: spam = "spam" class D1(AbstractBaseClass): pass class D2(D1): pass I write tests like this: class TestD1CommonBehaviour(unittest.TestCase): cls = D1 def testSpam(self): self.assertTrue(self.cls.spam == "spam") def testHam(self): self.assertFalse(hasattr(self.cls, 'ham')) class TestD2CommonBehaviour(TestD1CommonBehaviour): cls = D2 class TestD1SpecialBehaviour(unittest.TestCase): # D1 specific tests here class TestD2SpecialBehaviour(unittest.TestCase): # D2 specific tests here If D2 doesn't inherit from D1, but both from AbstractBaseClass, I need to do a little more work. First, in the test suite I create a subclass specifically for testing the common behaviour, write tests for that, then subclass from that: class MyD(AbstractBaseClass): # Defeat the prohibition on instantiating the base class pass class TestCommonBehaviour(unittest.TestCase): cls = MyD def testSpam(self): self.assertTrue(self.cls.spam == "spam") def testHam(self): self.assertFalse(hasattr(self.cls, 'ham')) class TestD1CommonBehaviour(unittest.TestCase): cls = D1 class TestD2CommonBehaviour(unittest.TestCase): cls = D2 D1 and D2 specific tests remain the same. Either way, each class gets tested for the full set of expected functionality. -- Steven From steve+comp.lang.python at pearwood.info Tue Oct 2 21:24:13 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Oct 2012 01:24:13 GMT Subject: Slicing iterables in sub-generators without loosing elements References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> <506b8d70$0$29982$c3e8da3$5496439d@news.astraweb.com> <7b411618-ab6b-4d07-b272-caf0c4acc3cd@googlegroups.com> Message-ID: <506b93bc$0$29982$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Oct 2012 18:11:20 -0700, 88888 Dihedral wrote: > Steven D'Aprano? 2012?10?3????UTC+8??8?57?20???? >> Oh, I'm convinced that it's a bot. >> The fact that Dihedral never responds to conversations about him/it is >> a give away: nearly all people are far to egotistical to let >> accusations of bot-hood go unchallenged. [...] >> Of course, Dihedral's creator wanted to really confound us, the >> occasional human response would probably muddy the waters sufficiently. > Are you still not getting the generator part in Python? Do you really > test any generator before? I rest my case :) I have many problems with generators. Can you tell me more about them? I really need your help. Sometimes, when it is very cold, the diesel freezes and the generator raises StopIteration at the wrong place. -- Steven From dihedral88888 at googlemail.com Tue Oct 2 21:42:19 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 2 Oct 2012 18:42:19 -0700 (PDT) Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: <506b93bc$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> <506b8d70$0$29982$c3e8da3$5496439d@news.astraweb.com> <7b411618-ab6b-4d07-b272-caf0c4acc3cd@googlegroups.com> <506b93bc$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6034f90d-da05-4cfb-83c3-016832703f74@googlegroups.com> Steven D'Aprano? 2012?10?3????UTC+8??9?24?13???? > On Tue, 02 Oct 2012 18:11:20 -0700, 88888 Dihedral wrote: > > > > > Steven D'Aprano? 2012?10?3????UTC+8??8?57?20???? > > > > >> Oh, I'm convinced that it's a bot. > > >> The fact that Dihedral never responds to conversations about him/it is > > >> a give away: nearly all people are far to egotistical to let > > >> accusations of bot-hood go unchallenged. > > [...] > > >> Of course, Dihedral's creator wanted to really confound us, the > > >> occasional human response would probably muddy the waters sufficiently. > > > > > Are you still not getting the generator part in Python? Do you really > > > test any generator before? > > > > I rest my case :) > > > > I have many problems with generators. Can you tell me more about them? I > > really need your help. Sometimes, when it is very cold, the diesel > > freezes and the generator raises StopIteration at the wrong place. > > > > > > > > -- > > Steven Please work out your own templates as I showed in the decorator part. From contropinion at gmail.com Tue Oct 2 22:03:20 2012 From: contropinion at gmail.com (contro opinion) Date: Tue, 2 Oct 2012 22:03:20 -0400 Subject: local variable 'a' referenced b Message-ID: code1 >>> def foo(): ... a = 1 ... def bar(): ... b=2 ... print a + b ... bar() ... ... >>> foo() 3 code2 >>> def foo(): ... a = 1 ... def bar(): ... b=2 ... a = a + b ... print a ... bar() ... >>> foo() Traceback (most recent call last): File "", line 1, in File "", line 7, in foo File "", line 5, in bar UnboundLocalError: local variable 'a' referenced b why code2 can not get output of 3? -------------- next part -------------- An HTML attachment was scrubbed... URL: From d at davea.name Tue Oct 2 22:26:23 2012 From: d at davea.name (Dave Angel) Date: Tue, 02 Oct 2012 22:26:23 -0400 Subject: local variable 'a' referenced b In-Reply-To: References: Message-ID: <506BA24F.8060409@davea.name> On 10/02/2012 10:03 PM, contro opinion wrote: > code1 >>>> def foo(): > ... a = 1 > ... def bar(): > ... b=2 > ... print a + b > ... bar() > ... > ... >>>> foo() > 3 > > code2 >>>> def foo(): > ... a = 1 > ... def bar(): > ... b=2 > ... a = a + b Because your function bar() has an assignment to a, it becomes a local, and masks access to the one in the containing function. Then because when you start executing that assignment statement, a hasn't yet gotten a value, you get the error below. > ... print a > ... bar() > ... >>>> foo() > Traceback (most recent call last): > File "", line 1, in > File "", line 7, in foo > File "", line 5, in bar > UnboundLocalError: local variable 'a' referenced b > > why code2 can not get output of 3? > In Python3, you can avoid the "problem" by declaring a as nonlocal. def foo(): a = 1 def bar(): nonlocal a b=2 a = a + b print (a) bar() foo() if you're stuck with Python2.x, you can use a mutable object for a, and mutate it, rather than replace it. For example, def foo(): a = [3] def bar(): b=2 a.append(b) #this mutates a, but doesn't assign it print (a) a[0] += b #likewise, for a number within the list print (a) bar() That should work in either 2.x or 3.2 -- DaveA From maniandram01 at gmail.com Tue Oct 2 23:21:17 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 2 Oct 2012 20:21:17 -0700 (PDT) Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: <8ddd9288-b822-4cb9-9f7f-99d0d34e1419@googlegroups.com> On Tuesday, 2 October 2012 22:13:20 UTC+5:30, Mark Lawrence wrote: > On 02/10/2012 17:12, Ramchandra Apte wrote: > > > On Monday, 1 October 2012 13:47:50 UTC+5:30, Mark Lawrence wrote: > > >> On 01/10/2012 01:58, 88888 Dihedral wrote: > > >> > > >>> > > >> > > >>> Your question seems vague to me. If you know you are storing > > >> > > >>> only immutable tuples in a list, then the way to iterate is simple. > > >> > > >>> > > >> > > >> > > >> > > >> Does Python have a magic method that let's me use mutable tuples? I'd > > >> > > >> also like immutable lists. Is it worth raising a feature request on the > > >> > > >> bug tracker? > > >> > > >> > > >> > > >> -- > > >> > > >> Cheers. > > >> > > >> > > >> > > >> Mark Lawrence. > > > > > > Mark, you are talking to a bot. > > > > > > > What happened to freedom of speech? If I want to talk to a bot, I'll > > talk to a bot. Besides I'm not convinced it/he/she is a bot. Plus if > > you read my post carefully, add in several years experience of Python > > the language and Python the comedy, you might come to the conclusion > > that a certain amount of urine extraction was going on :) > > > > -- > > Cheers. > > > > Mark Lawrence. Never said you can't. From maniandram01 at gmail.com Tue Oct 2 23:21:17 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Tue, 2 Oct 2012 20:21:17 -0700 (PDT) Subject: Slicing iterables in sub-generators without loosing elements In-Reply-To: References: <040cf4f0-e6de-45b1-add4-462c02fc2c7f@googlegroups.com> Message-ID: <8ddd9288-b822-4cb9-9f7f-99d0d34e1419@googlegroups.com> On Tuesday, 2 October 2012 22:13:20 UTC+5:30, Mark Lawrence wrote: > On 02/10/2012 17:12, Ramchandra Apte wrote: > > > On Monday, 1 October 2012 13:47:50 UTC+5:30, Mark Lawrence wrote: > > >> On 01/10/2012 01:58, 88888 Dihedral wrote: > > >> > > >>> > > >> > > >>> Your question seems vague to me. If you know you are storing > > >> > > >>> only immutable tuples in a list, then the way to iterate is simple. > > >> > > >>> > > >> > > >> > > >> > > >> Does Python have a magic method that let's me use mutable tuples? I'd > > >> > > >> also like immutable lists. Is it worth raising a feature request on the > > >> > > >> bug tracker? > > >> > > >> > > >> > > >> -- > > >> > > >> Cheers. > > >> > > >> > > >> > > >> Mark Lawrence. > > > > > > Mark, you are talking to a bot. > > > > > > > What happened to freedom of speech? If I want to talk to a bot, I'll > > talk to a bot. Besides I'm not convinced it/he/she is a bot. Plus if > > you read my post carefully, add in several years experience of Python > > the language and Python the comedy, you might come to the conclusion > > that a certain amount of urine extraction was going on :) > > > > -- > > Cheers. > > > > Mark Lawrence. Never said you can't. From jason at powerpull.net Tue Oct 2 23:49:21 2012 From: jason at powerpull.net (Jason Friedman) Date: Tue, 2 Oct 2012 21:49:21 -0600 Subject: parse an environment file In-Reply-To: References: Message-ID: > Ah, fair enough. Well, since you're using the full range of bash > functionality, the only viable way to parse it is with bash itself. > I'd recommend going with the version you have above: > >> * * * * * . /path/to/export_file && /path/to/script.py > > Under what circumstances is this not an option? That'd be the next > thing to consider. > > Alternatively, you may want to consider making your own config file > format. If you consciously restrict yourself to a severe subset of > bash functionality, you could easily parse it in Python - for > instance, always look for "export %s=%s" with simple strings for the > variable name and value. > Thank you, Chris, off-list post unintentional. It may be the case that I do not maintain /path/to/export_file; I might just be allowed to read it. Based on your responses and everyone's responses I'm guessing that what I am doing is sufficiently novel that there is no canned solution. I looked at shlex but did not see how that would be helpful. Thank you all for your thoughts. From rosuav at gmail.com Wed Oct 3 00:03:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Oct 2012 14:03:59 +1000 Subject: parse an environment file In-Reply-To: References: Message-ID: On Wed, Oct 3, 2012 at 1:49 PM, Jason Friedman wrote: > Based on your responses and everyone's responses I'm guessing that > what I am doing is sufficiently novel that there is no canned > solution. I looked at shlex but did not see how that would be > helpful. The only canned solution for parsing a bash script is bash. Think about it the other way around: If you wanted to have a Python variable made available to a bash script, the obvious thing to do is to invoke Python. It's the same thing. I recommend going with Hans Mulder's suggestion of a wrapper script; that seems to be the cleanest option available. ChrisA From timr at probo.com Wed Oct 3 01:08:24 2012 From: timr at probo.com (Tim Roberts) Date: Tue, 02 Oct 2012 22:08:24 -0700 Subject: Experimental Python-based shell References: <8646284b-df85-45fe-a793-56b081c6262c@googlegroups.com> Message-ID: Jonathan Hayward wrote: > >I've made an experimental Python-based Unix/Linux shell at: > >http://JonathansCorner.com/cjsh/ > >An experimental Unix/Linux command line shell, implemented in Python 3, >that takes advantage of some more recent concepts in terms of usability >and searching above pinpointing files in heirarchies. > >I invite you to try it. Without intending to detract from your work in any way, are you familiar with the IPython project? http://ipython.org/ You may find some interesting synergy with them. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From demianbrecht at gmail.com Wed Oct 3 01:54:12 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Tue, 02 Oct 2012 22:54:12 -0700 Subject: local variable 'a' referenced b In-Reply-To: <506BA24F.8060409@davea.name> References: <506BA24F.8060409@davea.name> Message-ID: <506BD304.6090905@gmail.com> On 12-10-02 07:26 PM, Dave Angel wrote: > > if you're stuck with Python2.x, you can use a mutable object for a, and > mutate it, rather than replace it. For example, > > > def foo(): > a = [3] > def bar(): > b=2 > a.append(b) #this mutates a, but doesn't assign it > print (a) > a[0] += b #likewise, for a number within the list > print (a) > bar() > > That should work in either 2.x or 3.2 > Alternatively, you can restructure your code by simply adding a parameter to bar(). Nice thing about this is that if you ever move bar() out into another module, then you don't have to worry about documenting the side effects on 'a' so users (including yourself) aren't confused later: >>> def foo(): ... a = 1 ... def bar(n): ... b = 2 ... return n + b ... a = bar(a) ... print a ... >>> foo() 3 -- Demian Brecht @demianbrecht http://demianbrecht.github.com From d at davea.name Wed Oct 3 02:08:41 2012 From: d at davea.name (Dave Angel) Date: Wed, 03 Oct 2012 02:08:41 -0400 Subject: local variable 'a' referenced b In-Reply-To: <506BD304.6090905@gmail.com> References: <506BA24F.8060409@davea.name> <506BD304.6090905@gmail.com> Message-ID: <506BD669.1050907@davea.name> On 10/03/2012 01:54 AM, Demian Brecht wrote: > On 12-10-02 07:26 PM, Dave Angel wrote: >> >> if you're stuck with Python2.x, you can use a mutable object for a, and >> mutate it, rather than replace it. For example, >> >> >> def foo(): >> a = [3] >> def bar(): >> b=2 >> a.append(b) #this mutates a, but doesn't assign it >> print (a) >> a[0] += b #likewise, for a number within the list >> print (a) >> bar() >> >> That should work in either 2.x or 3.2 >> > > Alternatively, you can restructure your code by simply adding a > parameter to bar(). Nice thing about this is that if you ever move > bar() out into another module, then you don't have to worry about > documenting the side effects on 'a' so users (including yourself) > aren't confused later: > > >>> def foo(): > ... a = 1 > ... def bar(n): > ... b = 2 > ... return n + b > ... a = bar(a) > ... print a > ... > >>> foo() > 3 > > One problem with short examples is they mask the reason for the code to be structured that way. I assumed that the OP was really talking about a closure, and that sharing that variable was deliberate. I seldom write nested functions otherwise. -- DaveA From demianbrecht at gmail.com Wed Oct 3 04:05:53 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Wed, 3 Oct 2012 01:05:53 -0700 Subject: local variable 'a' referenced b In-Reply-To: <506BD669.1050907@davea.name> References: <506BA24F.8060409@davea.name> <506BD304.6090905@gmail.com> <506BD669.1050907@davea.name> Message-ID: > > One problem with short examples is they mask the reason for the code to > be structured that way. > > Couldn't agree more (I don't think I've ever written a nested function outside a closure). I made the assumption that the OP wasn't asking about closures based on his code samples. In hindsight, should have likely asked for clarification first. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Wed Oct 3 04:50:09 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 3 Oct 2012 10:50:09 +0200 (CEST) Subject: design question:game skill system In-Reply-To: <506B47DB.9030401@tysdomain.com> Message-ID: <268012065.515960.1349254209142.JavaMail.root@sequans.com> ----- Original Message ----- > Hello all: > I'm looking at a skill/perk system, where the player builds up his > char > by using perk points to add abilities. > Each perk is under a category, and generally costs go up as you > increase > the perk. > So I'm trying to figure something out; first, I'd really like the > cost > calculation and all of that to be dynamic, so that I don't have to > write > a calculateCost per object. I'd also like to be able to specify > dependencies and say a level, as well as other factors before a > player > can obtain a perk and have them self documenting. The idea is that a > player could do something like: > data perk extended health > and it would tell them they require health at 50 before they can > purchase extended health, as well as the cost, the increase per level > and the total overall cost. > Any ideas on how to set this up would be really appreciated. > Finally, I'm curious how to store and calculate these. I thought > about > using a uid per perk, then storing something like: {uid:level} on the > player, but means that I have to lookup the name somehow still in the > main perk database, then use that uid to check if the player has it. > Are > there better ways of storing skills? I'm also thinking about > calculation; currently the CalculateMaxHp method would have to add up > all the possible perks for health, then add stats and all that. That > could get really rough on performance if it's called often; would > something like a cache work, where you have something like: > {attribute:dirty}? So if I call CalculateHealth, it checks for the > dirty > flag, and if it doesn't exist just returns the previous max HP, but > if > the dirty flag is set, it recalculates? Then anything modifying > health > (level gains, perks, stat increases/etc) would just set the dirty > flag > and call calculate? > Thoughts/ideas would be welcome. > Thanks, Hi, Again, do not think about performances before actually having an issue with them. What's the point to optimize something that doesn't need it ? For your cache problem, google "python memoize decorator" for a bunch of decorators that will allow you to cache your data without any effort. JM From oscar.j.benjamin at gmail.com Wed Oct 3 05:33:55 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 3 Oct 2012 10:33:55 +0100 Subject: unit testing class hierarchies In-Reply-To: <506b92f3$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <506b92f3$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3 October 2012 02:20, Steven D'Aprano wrote: > > But surely, regardless of where that functionality is defined, you still > need to test that both D1 and D2 exhibit the correct behaviour? Otherwise > D2 (say) may break that functionality and your tests won't notice. > > Given a class hierarchy like this: > > class AbstractBaseClass: > spam = "spam" > > class D1(AbstractBaseClass): pass > class D2(D1): pass > > > I write tests like this: > > class TestD1CommonBehaviour(unittest.TestCase): > cls = D1 > def testSpam(self): > self.assertTrue(self.cls.spam == "spam") > def testHam(self): > self.assertFalse(hasattr(self.cls, 'ham')) > > class TestD2CommonBehaviour(TestD1CommonBehaviour): > cls = D2 That's an excellent idea. I wanted a convenient way to run the same tests on two classes in order to test both a pure python and a cython-accelerator module implementation of the same class. I find it difficult to work out how to do such simple things with unittest because of its Java-like insistence on organising all tests into classes. I can't immediately remember what solution I came up with but yours is definitely better. Oscar From grahn+nntp at snipabacken.se Wed Oct 3 09:48:11 2012 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 3 Oct 2012 13:48:11 GMT Subject: Experimental Python-based shell References: <8646284b-df85-45fe-a793-56b081c6262c@googlegroups.com> Message-ID: On Tue, 2012-10-02, Jonathan Hayward wrote: > I've made an experimental Python-based Unix/Linux shell at: > > http://JonathansCorner.com/cjsh/ > > An experimental Unix/Linux command line shell, implemented in Python > 3, that takes advantage of some more recent concepts in terms of > usability and searching above pinpointing files in heirarchies. > > I invite you to try it. Hard to do without a manual page, or any documentation at all except for a tiny "hello world"-style example ... /Jorgen -- // Jorgen Grahn O o . From amirouche.boubekki at gmail.com Wed Oct 3 09:52:57 2012 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Wed, 3 Oct 2012 15:52:57 +0200 Subject: Experimental Python-based shell In-Reply-To: <8646284b-df85-45fe-a793-56b081c6262c@googlegroups.com> References: <8646284b-df85-45fe-a793-56b081c6262c@googlegroups.com> Message-ID: H?llo, 2012/10/3 Jonathan Hayward > I've made an experimental Python-based Unix/Linux shell at: > > http://JonathansCorner.com/cjsh/ > > An experimental Unix/Linux command line shell, implemented in Python 3, > that takes advantage of some more recent concepts in terms of usability and > searching above pinpointing files in heirarchies. > This sound like a great idea! What are the other benefits of it except the file lookup thing ? Does it do fuzzy match yet ? Is there any repository on bitbucket or github ? Thanks, Amirouche -------------- next part -------------- An HTML attachment was scrubbed... URL: From boxeakasteen at gmail.com Wed Oct 3 10:26:43 2012 From: boxeakasteen at gmail.com (Steen Lysgaard) Date: Wed, 03 Oct 2012 16:26:43 +0200 Subject: Combinations of lists Message-ID: <506C4B23.6020809@gmail.com> Hi, I am looking for a clever way to compute all combinations of two lists. Look at this example: h = ['A','A','B','B'] m = ['a','b'] the resulting combinations should be of the same length as h and each element in m can be used twice. The sought after result using h and m from above is: [['aA', 'aA', 'bB', 'bB'], ['aA', 'aB', 'bA', 'bB'], ['aB', 'aB', 'bA', 'bA']] (the order of the results does not matter i.e. ['aA', 'aA', 'bB', 'bB'] and ['aA', 'bB', 'aA', 'bB'] are considered the same) This is achieved by the code below, this however needs to go through all possible combinations (faculty of len(h)) and rule out duplicates as they occur and this is too much if for example len(h) is 16. Can anyone guide me to a better solution? Thanks, Steen h = ['A','A','B','B'] m = ['a','b'] c = [] for i in h: c.append([]) for j in m: c[-1].append(j+i) c[-1].append(j+i) combs = [] for a in permutations(range(len(h)),len(h)): comb = [] for i in range(len(h)): comb.append(c[i][a[i]]) comb.sort() if comb not in combs: combs.append(comb) print combs print len(combs) From sahnov.m at gmail.com Wed Oct 3 10:37:17 2012 From: sahnov.m at gmail.com (=?KOI8-R?B?88HIzs/XIO3JyMHJzA==?=) Date: Wed, 3 Oct 2012 18:37:17 +0400 Subject: Combinations of lists In-Reply-To: <506C4B23.6020809@gmail.com> References: <506C4B23.6020809@gmail.com> Message-ID: >>> t1 = [1,2,3] >>> t2 = [4,5,6] >>> [(x,y) for x in t1 for y in t2] [(1, 4), (1, 5), (1, 6), (2, 4), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6)] 2012/10/3 Steen Lysgaard > Hi, > > I am looking for a clever way to compute all combinations of two lists. > Look at this example: > > h = ['A','A','B','B'] > m = ['a','b'] > > the resulting combinations should be of the same length as h and each > element in m can be used twice. The sought after result using h and m from > above is: > > [['aA', 'aA', 'bB', 'bB'], > ['aA', 'aB', 'bA', 'bB'], > ['aB', 'aB', 'bA', 'bA']] > > (the order of the results does not matter i.e. ['aA', 'aA', 'bB', 'bB'] > and ['aA', 'bB', 'aA', 'bB'] are considered the same) > > This is achieved by the code below, this however needs to go through all > possible combinations (faculty of len(h)) and rule out duplicates as they > occur and this is too much if for example len(h) is 16. > > Can anyone guide me to a better solution? > > Thanks, > Steen > > h = ['A','A','B','B'] > m = ['a','b'] > > c = [] > for i in h: > c.append([]) > for j in m: > c[-1].append(j+i) > c[-1].append(j+i) > > combs = [] > > for a in permutations(range(len(h)),**len(h)): > comb = [] > for i in range(len(h)): > comb.append(c[i][a[i]]) > comb.sort() > > if comb not in combs: > combs.append(comb) > > print combs > > print len(combs) > -- > http://mail.python.org/**mailman/listinfo/python-list > -- -- ICQ:#7499099 JID:soider at jabber.ru -------------- next part -------------- An HTML attachment was scrubbed... URL: From alain at dpt-info.u-strasbg.fr Wed Oct 3 11:11:42 2012 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Wed, 03 Oct 2012 17:11:42 +0200 Subject: Combinations of lists References: Message-ID: <87zk43fv4h.fsf@dpt-info.u-strasbg.fr> Steen Lysgaard writes: > I am looking for a clever way to compute all combinations of two > lists. Look at this example: > > h = ['A','A','B','B'] > m = ['a','b'] > > the resulting combinations should be of the same length as h and each > element in m can be used twice. The sought after result using h and m > from above is: > > [['aA', 'aA', 'bB', 'bB'], > ['aA', 'aB', 'bA', 'bB'], > ['aB', 'aB', 'bA', 'bA']] I can't make sense of your explanation, which doesn't seem to match your example (the result is not of the same size as h). Here is a way to compute { xh | x in m }, where xh is a list where x is prepended to each element of h. result = [ [ x+l for l in h ] for x in m ] If there is no duplicate in the original lists, then there will be no duplicate in the result. Is that what you are looking for? -- Alain. From jonathan.hayward at pobox.com Wed Oct 3 11:40:05 2012 From: jonathan.hayward at pobox.com (Jonathan Hayward) Date: Wed, 3 Oct 2012 10:40:05 -0500 Subject: Experimental Python-based shell In-Reply-To: References: <8646284b-df85-45fe-a793-56b081c6262c@googlegroups.com> Message-ID: The chief benefit besides the searching, so far, is that you can use Py3k mixed with shell commands as the scripting language--so script in Python instead of bash. When using Python for scripting, Python lines are indented by an extra tab (or four spaces) while shell-like commands are not indented. So: cjsh> for index in range(10): ----> echo %(index)d ----> 0 1 2 3 4 5 6 7 8 9 Echo could (and maybe should) be a built-in, but it isn't. The output is os.system()'ed to bash, which echoes based on a command that includes the value of a Python variable. The implementation is a bit crude, but it is reasonably powerful. I have other things on the agenda, like making it able to run scripts and doing fuzzy matching, but for now those are the main two attractions. On Wed, Oct 3, 2012 at 8:52 AM, Amirouche Boubekki < amirouche.boubekki at gmail.com> wrote: > H?llo, > > 2012/10/3 Jonathan Hayward > >> I've made an experimental Python-based Unix/Linux shell at: >> >> http://JonathansCorner.com/cjsh/ >> >> An experimental Unix/Linux command line shell, implemented in Python 3, >> that takes advantage of some more recent concepts in terms of usability and >> searching above pinpointing files in heirarchies. >> > > This sound like a great idea! What are the other benefits of it except > the file lookup thing ? Does it do fuzzy match yet ? > > Is there any repository on bitbucket or github ? > > Thanks, > > Amirouche > -- [image: Christos Jonathan Hayward] Christos Jonathan Hayward, an Orthodox Christian author. *Amazon * ? Author Bio ? *Email * ? Facebook ? Google Plus ? *Kindle * ? LinkedIn ? *Professional * ? Twitter ? *Web * ? What's New? I invite you to visit my "theology, literature, and other creative works" site. *See one page of my website! * -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Oct 3 11:42:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Oct 2012 15:42:47 GMT Subject: Combinations of lists References: Message-ID: <506c5cf7$0$29982$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Oct 2012 16:26:43 +0200, Steen Lysgaard wrote: > Hi, > > I am looking for a clever way to compute all combinations of two lists. > Look at this example: > > h = ['A','A','B','B'] > m = ['a','b'] > > the resulting combinations should be of the same length as h and each > element in m can be used twice. Why twice? What if you had these? h = ['A', 'A', 'B', 'B', 'C', 'D', 'E', 'E'] m = ['a', 'b', 'c'] Would you still use each element in m twice? Or some other number? > The sought after result using h and m from above is: > > [['aA', 'aA', 'bB', 'bB'], > ['aA', 'aB', 'bA', 'bB'], > ['aB', 'aB', 'bA', 'bA']] > > (the order of the results does not matter i.e. ['aA', 'aA', 'bB', 'bB'] > and ['aA', 'bB', 'aA', 'bB'] are considered the same) > > This is achieved by the code below, this however needs to go through all > possible combinations (faculty of len(h)) and rule out duplicates as > they occur and this is too much if for example len(h) is 16. I don't understand this requirement. In the example above, you don't rule out duplicates. Both 'aA' and 'bB' are duplicated. What duplicates are you ruling out? -- Steven From mpg at elzevir.fr Wed Oct 3 12:20:00 2012 From: mpg at elzevir.fr (Manuel =?iso-8859-1?q?P=E9gouri=E9-Gonnard?=) Date: Wed, 3 Oct 2012 18:20:00 +0200 (CEST) Subject: Combinations of lists References: <506c5cf7$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano scripsit : > On Wed, 03 Oct 2012 16:26:43 +0200, Steen Lysgaard wrote: > >> This is achieved by the code below, this however needs to go through all >> possible combinations (faculty of len(h)) and rule out duplicates as >> they occur and this is too much if for example len(h) is 16. > > I don't understand this requirement. In the example above, you don't rule > out duplicates. Both 'aA' and 'bB' are duplicated. What duplicates are > you ruling out? > I think the requirement is that r[i] != r[j] as soon as i != j, if r is the resulting list of lists. (As opposed to having r[i][j] != r[i][k] for all i and j != k.) -- Manuel P?gouri?-Gonnard - http://people.math.jussieu.fr/~mpg/ From bringa at gmail.com Wed Oct 3 12:23:03 2012 From: bringa at gmail.com (Daniel Klein) Date: Wed, 3 Oct 2012 09:23:03 -0700 (PDT) Subject: Help me abstract this (and stop me from using eval) Message-ID: <2d902087-7a52-46b8-83a5-f163a87ee88e@googlegroups.com> Hi! I've got import scripts for a bunch of csv files into an sqlite database. I have one csv file per language. I don't write directly to the sqlite db; this is a django app and I'm creating items in my django models. My script (scripts, unfortunately) work just fine, but it feels beyond stupid to have one script per language--importgerman, importfrench etc. The problem is that I don't know how to abstract which language I'm currently writing to. Here's the central loop: http://pastebin.com/NBT6feNB This is for the Polish version of the script, of course, the one that gets fed pl.csv. For those unfamiliar with django, I need to first retrieve the message instance for issue name / long text / short text / category name. Hence the ugly tempmes stuff. So ideally I would tell the script which language I'm currently importing and based on that it would write to the appropriate text fields. But I don't know how to abstract this: tempmes.polish = row[1] Well, I do. Like this: eval("tempmes." + language + " = row[1]") But... eval is evil, no? There's got to be a better way? From amirouche.boubekki at gmail.com Wed Oct 3 12:25:32 2012 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Wed, 3 Oct 2012 18:25:32 +0200 Subject: Experimental Python-based shell In-Reply-To: References: <8646284b-df85-45fe-a793-56b081c6262c@googlegroups.com> Message-ID: 2012/10/3 Jonathan Hayward > The chief benefit besides the searching, so far, is that you can use Py3k > mixed with shell commands as the scripting language--so script in Python > instead of bash. > > When using Python for scripting, Python lines are indented by an extra tab > (or four spaces) while shell-like commands are not indented. So: > > cjsh> for index in range(10): > ----> echo %(index)d > ----> > 0 > 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > > Echo could (and maybe should) be a built-in, but it isn't. The output is > os.system()'ed to bash, which echoes based on a command that includes the > value of a Python variable. The implementation is a bit crude, but it is > reasonably powerful. > > I have other things on the agenda, like making it able to run scripts and > doing fuzzy matching, but for now those are the main two attractions. > Is it possible to drop completly the bash syntax and use some python library (I saw it on github) that wraps bash commands with python functions or the other around making it possible to call python functions with a bash-like syntax. The syntax you are talking about seems strange. Regards, Amirouche -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwpolska at gmail.com Wed Oct 3 12:33:05 2012 From: kwpolska at gmail.com (Kwpolska) Date: Wed, 3 Oct 2012 18:33:05 +0200 Subject: Help me abstract this (and stop me from using eval) In-Reply-To: <2d902087-7a52-46b8-83a5-f163a87ee88e@googlegroups.com> References: <2d902087-7a52-46b8-83a5-f163a87ee88e@googlegroups.com> Message-ID: On Wed, Oct 3, 2012 at 6:23 PM, Daniel Klein wrote: > tempmes.polish = row[1] > > Well, I do. Like this: > > eval("tempmes." + language + " = row[1]") > > But... eval is evil, no? There's got to be a better way? > -- > http://mail.python.org/mailman/listinfo/python-list Easy. tempmes = myissue.name language = 'polish' setattr(tempmes, language, row[1]) tempmes.save() -- Kwpolska stop html mail | always bottom-post www.asciiribbon.org | www.netmeister.org/news/learn2quote.html GPG KEY: 5EAAEA16 From ian.g.kelly at gmail.com Wed Oct 3 12:34:28 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 3 Oct 2012 10:34:28 -0600 Subject: Combinations of lists In-Reply-To: <506c5cf7$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <506c5cf7$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Oct 3, 2012 at 9:42 AM, Steven D'Aprano wrote: > I don't understand this requirement. In the example above, you don't rule > out duplicates. Both 'aA' and 'bB' are duplicated. What duplicates are > you ruling out? Duplicate multisets, not duplicate strings. I'll take a crack at this problem sometime later, but right now I don't have the time. From demianbrecht at gmail.com Wed Oct 3 12:35:26 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Wed, 3 Oct 2012 09:35:26 -0700 Subject: Are ABCs an anti-pattern? In-Reply-To: References: <506AF8C9.8060406@gmail.com> Message-ID: > > > ABCs were added (fairly recently) in 3.0 for the reasons given in > http://python.org/dev/peps/**pep-3119/ > It was expected that it would take awhile for them to see good, pythonic > uses. We obviously did okay without them up to 2.7. > I read the PEP before posting just to make sure that I wasn't missing anything. The gut feeling that I got after reading PEP 3119 was that it was written by an academic relatively recently out of school (or in school even), or coming from a strictly typed language who saw this as a hole in the language. Don't get me wrong. In theory (and coming from a C/C++ background), I fully appreciate the need for such language features. However, in practice, it seems to somewhat be contrary to the Zen of Python. One thing that irks me a bit about abc's is that those coming from other (strictly typed) language backgrounds (or school for that matter) will think "hey, my prof/books told me that I should use an abstract base class to define the contract for [x]". Next step, Google abstract base classes and Python, they're presented with abcs, rather than how to look and think about the problem differently using Pythonic idioms. This kind of thing (imho) is a catalyst for many over-engineered Python packages and misunderstanding of the core language. In short, it seems like somewhat of an academic crutch to me. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Oct 3 12:36:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Oct 2012 16:36:09 GMT Subject: Help me abstract this (and stop me from using eval) References: <2d902087-7a52-46b8-83a5-f163a87ee88e@googlegroups.com> Message-ID: <506c6979$0$29982$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Oct 2012 09:23:03 -0700, Daniel Klein wrote: > So ideally I would tell the script which language I'm currently > importing and based on that it would write to the appropriate text > fields. But I don't know how to abstract this: > > tempmes.polish = row[1] > > Well, I do. Like this: > > eval("tempmes." + language + " = row[1]") setattr(tempmes, language, row[1]) -- Steven From bringa at gmail.com Wed Oct 3 12:40:12 2012 From: bringa at gmail.com (Daniel Klein) Date: Wed, 3 Oct 2012 09:40:12 -0700 (PDT) Subject: Help me abstract this (and stop me from using eval) In-Reply-To: <506c6979$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <2d902087-7a52-46b8-83a5-f163a87ee88e@googlegroups.com> <506c6979$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thank you Steven! That was PRECISELY what I was looking for. From bringa at gmail.com Wed Oct 3 12:41:32 2012 From: bringa at gmail.com (Daniel Klein) Date: Wed, 3 Oct 2012 09:41:32 -0700 (PDT) Subject: Help me abstract this (and stop me from using eval) In-Reply-To: References: <2d902087-7a52-46b8-83a5-f163a87ee88e@googlegroups.com> <506c6979$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, October 3, 2012 5:40:12 PM UTC+1, Daniel Klein wrote: > Thank you Steven! That was PRECISELY what I was looking for. (And kwpolska!) From jonathan.hayward at pobox.com Wed Oct 3 13:24:51 2012 From: jonathan.hayward at pobox.com (Jonathan Hayward) Date: Wed, 3 Oct 2012 12:24:51 -0500 Subject: Experimental Python-based shell In-Reply-To: References: <8646284b-df85-45fe-a793-56b081c6262c@googlegroups.com> Message-ID: I am open to suggestions and patches. I don't think the syntax strange, though: it offers a clear and distinct way to differentiate Python and shell commands, and shell commands can access Python variables when specified. And it is a simple rule, without footnotes needed. On Wed, Oct 3, 2012 at 11:25 AM, Amirouche Boubekki < amirouche.boubekki at gmail.com> wrote: > > > 2012/10/3 Jonathan Hayward > >> The chief benefit besides the searching, so far, is that you can use Py3k >> mixed with shell commands as the scripting language--so script in Python >> instead of bash. >> >> When using Python for scripting, Python lines are indented by an extra >> tab (or four spaces) while shell-like commands are not indented. So: >> >> cjsh> for index in range(10): >> ----> echo %(index)d >> ----> >> 0 >> 1 >> 2 >> 3 >> 4 >> 5 >> 6 >> 7 >> 8 >> 9 >> >> Echo could (and maybe should) be a built-in, but it isn't. The output is >> os.system()'ed to bash, which echoes based on a command that includes the >> value of a Python variable. The implementation is a bit crude, but it is >> reasonably powerful. >> >> I have other things on the agenda, like making it able to run scripts and >> doing fuzzy matching, but for now those are the main two attractions. >> > > Is it possible to drop completly the bash syntax and use some python > library (I saw it on github) that wraps bash commands with python functions > or the other around making it possible to call python functions with a > bash-like syntax. The syntax you are talking about seems strange. > > Regards, > > Amirouche > -- [image: Christos Jonathan Hayward] Christos Jonathan Hayward, an Orthodox Christian author. *Amazon * ? Author Bio ? *Email * ? Facebook ? Google Plus ? *Kindle * ? LinkedIn ? *Professional * ? Twitter ? *Web * ? What's New? I invite you to visit my "theology, literature, and other creative works" site. *See one page of my website! * -------------- next part -------------- An HTML attachment was scrubbed... URL: From hansmu at xs4all.nl Wed Oct 3 13:55:44 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Wed, 03 Oct 2012 19:55:44 +0200 Subject: Can somebody give me an advice about what to learn? In-Reply-To: References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: <506c7c20$0$6908$e4fe514c@news2.news.xs4all.nl> On 1/10/12 00:14:29, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> you can't, for instance, retain a "socket connection object" across >> that sort of reload. > > Yeah, that's a problem. There's nothing fundamental about a TCP > connection endpoint which precludes it being serialized and passed > around. The amount of state involved is pretty small. Unless I've > forgotten something, 2 IP addresses, 2 port numbers, a few bits worth of > TCP protocol state, and, for open connections, 2 sequence numbers. > Maybe a couple of timers, but I don't think they're strictly necessary. > The problem is, most of that state is private to the kernel. You're looking at the wrong abstraction level. A socket connection object is a thin wrapper around a file descriptor. Most posix platforms allow you to pass file descriptors to other processes running on the same box. Thus, most posix platforms *do* allow you to pass socket connection objects around, though you won't win prizes for portability. > On the other hand, you could do what "screen" does, and spawn a process > per connection to hold the connection open :-) That won't work for the sort of application we're discussing, because it creates too many processes. A pool of processes, each handling many connections, might work though. -- HansM From ramdevtech.netinc at gmail.com Wed Oct 3 14:26:32 2012 From: ramdevtech.netinc at gmail.com (ram dev) Date: Wed, 3 Oct 2012 11:26:32 -0700 (PDT) Subject: Need Data Architect/Technical Business Analyst For 6months at San Rafael, CA Message-ID: Good Day, urgent Requirement : San Rafael, CA 6 months As a member of the Market Intelligence team, the Data Architect/Technical Business Analyst will be tasked with assessing current state business process and corresponding data flows, understanding Marketing business objectives, and identifying gaps in process, systems, and data that prevent execution against those objectives. This will require understanding the broader internal data integration landscape to adequately determine synergies/ overlap and call out integration areas pertinent to Marketing that are insufficiently addressed by current systems and in-flight projects. Principal Duties and Responsibilities: ? Develop clear understanding of company?s integrated Marketing objectives/KPIs ? Leverage IT and Marketing resources to understand related process/data flows ? Develop and execute ETL procedures to integrate required sources (where currently feasible) ? Perform data/system/project gap analysis, documenting issues within the context of Marketing objectives ? Work closely with/inform business owners and project teams to ensure that documented gaps are addressed Requirements: ? 5+ years SQL experience (SQL Server, Oracle) experience ? 5+ years ETL (SSIS, DTS, Informatica) experience ? High proficiency in data/systems analysis and integration ? Understanding of data models, data quality ? Proven ability to work within a highly-matrixed, global organization ? Excellent documentation and organizational skills ? Excellent communication skills, both written and verbal, and interpersonal skills Desired Knowledge/Skills: ? Siebel CRM data model experience strongly preferred ? Business systems analysis./process engineering experience strongly preferred ? SFDC data model experience a plus ? Understanding of Clients Customer, Product, Contract, and Entitlement data/structures a plus Thanks, ============================ Ram Dev Recruiter Tech-Net Inc. Tel: 916-458-4390 Ext 102 Email: ram at tech-netinc.com From steve+comp.lang.python at pearwood.info Wed Oct 3 14:26:50 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Oct 2012 18:26:50 GMT Subject: Emulating C++ namespaces with ChainMap and metaclass trickery Message-ID: <506c836a$0$29982$c3e8da3$5496439d@news.astraweb.com> C++ namespaces are useful for encapsulating related objects within a single file, subdividing the global namespace without using classes. Python has modules, but they come in separate files. Using Python 3.3's ChainMap type, and some metaclass trickery, I abuse the class keyword to (almost) emulate C++ namespaces: http://code.activestate.com/recipes/578279/ -- Steven From feliphil at gmx.net Wed Oct 3 14:31:08 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Wed, 3 Oct 2012 20:31:08 +0200 Subject: Can somebody give me an advice about what to learn? References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> Message-ID: <20121003203108.50406660f9e7843c7e2e99a7@gmx.net> > I'm really new to Usenet/Newsgroups, but... I'd like to learn some > new programming language, because I learnt a bit of Perl though its > OOP is ugly. So, after searching a bit, I found Python and Ruby, and > both of they are cute. So, assuming you'll say me "learn python", why > should I learn it over Ruby? The point why Ruby was started (perceived deficit of object-orientation) has been remedied since Python 2.2. However, Ruby has reproduced quite a few of those well-known problems of other languages that Python deliberately avoids (such as e.g. deficit of orthogonality) and that make reading and understanding code difficult, besides introducing sources for potential bugs. Sincerely, Wolfgang From joshua.landau.ws at gmail.com Wed Oct 3 15:08:03 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Wed, 3 Oct 2012 20:08:03 +0100 Subject: Combinations of lists In-Reply-To: <506C4B23.6020809@gmail.com> References: <506C4B23.6020809@gmail.com> Message-ID: On 3 October 2012 15:26, Steen Lysgaard wrote: > Hi, > > I am looking for a clever way to compute all combinations of two lists. > Look at this example: > > h = ['A','A','B','B'] > m = ['a','b'] > > the resulting combinations should be of the same length as h and each > element in m can be used twice. The sought after result using h and m from > above is: > > [['aA', 'aA', 'bB', 'bB'], > ['aA', 'aB', 'bA', 'bB'], > ['aB', 'aB', 'bA', 'bA']] > > (the order of the results does not matter i.e. ['aA', 'aA', 'bB', 'bB'] > and ['aA', 'bB', 'aA', 'bB'] are considered the same) > > This is achieved by the code below, this however needs to go through all > possible combinations (faculty of len(h)) and rule out duplicates as they > occur and this is too much if for example len(h) is 16. > > Can anyone guide me to a better solution? What lengths can the two lists be? Is len(h) === 2*len(m), or it it just this time? Depending on your answer this could be easy or hard ;) -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Wed Oct 3 15:20:40 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 3 Oct 2012 20:20:40 +0100 Subject: Combinations of lists In-Reply-To: <506C4B23.6020809@gmail.com> References: <506C4B23.6020809@gmail.com> Message-ID: On 3 October 2012 15:26, Steen Lysgaard wrote: > Hi, > > I am looking for a clever way to compute all combinations of two lists. Look > at this example: > > h = ['A','A','B','B'] > m = ['a','b'] > > the resulting combinations should be of the same length as h and each > element in m can be used twice. The sought after result using h and m from > above is: > > [['aA', 'aA', 'bB', 'bB'], > ['aA', 'aB', 'bA', 'bB'], > ['aB', 'aB', 'bA', 'bA']] > > (the order of the results does not matter i.e. ['aA', 'aA', 'bB', 'bB'] and > ['aA', 'bB', 'aA', 'bB'] are considered the same) > > This is achieved by the code below, this however needs to go through all > possible combinations (faculty of len(h)) and rule out duplicates as they > occur and this is too much if for example len(h) is 16. I'm assuming that len(m) is always 2. Then if len(m) is 16 each element of h can be used 8 times. If this is not as you intended you will need to clarify how this problem generalises to other cases. The elements that go with the 'b's are implicitly determined once you have chosen the elements that go with the 'a's. The problem then is solved if you choose the elements that go with the 'a's. If we need to choose say k elements to go with the 'a's the basic problem becomes: "enumerate over all multisets of size k that are subsets of the multiset h." ''' def submultisets(multiset, subsetsize, stack=None): # Enter recursion if stack is None: multiset = dict((c, multiset.count(c)) for c in set(multiset)) stack = [] c = next(iter(multiset)) # End recursion if len(multiset) == 1: missing = subsetsize - len(stack) if multiset[c] >= missing: yield stack + missing * [c] return # Continue recursion count = multiset.pop(c) for n in range(count + 1): stack.extend(n * c) for result in submultisets(multiset, subsetsize, stack): yield result del stack[-n:] multiset[c] = count def uniquecombinations(h, m): for ha in submultisets(h, len(h)//2): hb = list(h) for c in ha: hb.remove(c) yield [m[0] + a for a in ha] + [m[1] + b for b in hb] h = ['A', 'A', 'B', 'B'] m = ['a', 'b'] for x in uniquecombinations(h, m): print(x) ''' Output: ['aB', 'aB', 'bA', 'bA'] ['aA', 'aB', 'bA', 'bB'] ['aA', 'aA', 'bB', 'bB'] Oscar From joshua.landau.ws at gmail.com Wed Oct 3 15:54:45 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Wed, 3 Oct 2012 20:54:45 +0100 Subject: Combinations of lists In-Reply-To: References: <506C4B23.6020809@gmail.com> Message-ID: On 3 October 2012 20:20, Oscar Benjamin wrote: > On 3 October 2012 15:26, Steen Lysgaard wrote: > > Hi, > > > > I am looking for a clever way to compute all combinations of two lists. > Look > > at this example: > > > > h = ['A','A','B','B'] > > m = ['a','b'] > > > > the resulting combinations should be of the same length as h and each > > element in m can be used twice. The sought after result using h and m > from > > above is: > > > > [['aA', 'aA', 'bB', 'bB'], > > ['aA', 'aB', 'bA', 'bB'], > > ['aB', 'aB', 'bA', 'bA']] > > > > (the order of the results does not matter i.e. ['aA', 'aA', 'bB', 'bB'] > and > > ['aA', 'bB', 'aA', 'bB'] are considered the same) > > > > This is achieved by the code below, this however needs to go through all > > possible combinations (faculty of len(h)) and rule out duplicates as they > > occur and this is too much if for example len(h) is 16. > > I'm assuming that len(m) is always 2. Then if len(m) is 16 each > element of h can be used 8 times. If this is not as you intended you > will need to clarify how this problem generalises to other cases. > His code only works when len(m) is half of len(h), so this may not be the right assumption. > The elements that go with the 'b's are implicitly determined once you > have chosen the elements that go with the 'a's. The problem then is > solved if you choose the elements that go with the 'a's. If we need to > choose say k elements to go with the 'a's the basic problem becomes: > "enumerate over all multisets of size k that are subsets of the > multiset h." > > ''' > def submultisets(multiset, subsetsize, stack=None): > # Enter recursion > if stack is None: > multiset = dict((c, multiset.count(c)) for c in set(multiset)) > stack = [] > > c = next(iter(multiset)) > > # End recursion > if len(multiset) == 1: > missing = subsetsize - len(stack) > if multiset[c] >= missing: > yield stack + missing * [c] > return > > # Continue recursion > count = multiset.pop(c) > for n in range(count + 1): > stack.extend(n * c) > for result in submultisets(multiset, subsetsize, stack): > yield result > del stack[-n:] > multiset[c] = count > > def uniquecombinations(h, m): > for ha in submultisets(h, len(h)//2): > hb = list(h) > for c in ha: > hb.remove(c) > yield [m[0] + a for a in ha] + [m[1] + b for b in hb] > > h = ['A', 'A', 'B', 'B'] > m = ['a', 'b'] > > for x in uniquecombinations(h, m): > print(x) > ''' > > Output: > ['aB', 'aB', 'bA', 'bA'] > ['aA', 'aB', 'bA', 'bB'] > ['aA', 'aA', 'bB', 'bB'] > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Oct 3 16:14:39 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Oct 2012 16:14:39 -0400 Subject: unit testing class hierarchies In-Reply-To: References: <506b92f3$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/3/2012 5:33 AM, Oscar Benjamin wrote: > On 3 October 2012 02:20, Steven D'Aprano > wrote: >> >> But surely, regardless of where that functionality is defined, you still >> need to test that both D1 and D2 exhibit the correct behaviour? Otherwise >> D2 (say) may break that functionality and your tests won't notice. >> >> Given a class hierarchy like this: >> >> class AbstractBaseClass: >> spam = "spam" >> >> class D1(AbstractBaseClass): pass >> class D2(D1): pass >> >> >> I write tests like this: >> >> class TestD1CommonBehaviour(unittest.TestCase): >> cls = D1 >> def testSpam(self): >> self.assertTrue(self.cls.spam == "spam") >> def testHam(self): >> self.assertFalse(hasattr(self.cls, 'ham')) >> >> class TestD2CommonBehaviour(TestD1CommonBehaviour): >> cls = D2 > > That's an excellent idea. I wanted a convenient way to run the same > tests on two classes in order to test both a pure python and a > cython-accelerator module implementation of the same class. Python itself has same issue with testing Python and C coded modules. It has the additional issue that the Python class by default import the C version, so additional work is needed to avoid that and actually test the python code. For instance, heapq.test_heapq.py has ... py_heapq = support.import_fresh_module('heapq', blocked=['_heapq']) c_heapq = support.import_fresh_module('heapq', fresh=['_heapq']) ... class TestHeap(TestCase): module = None ... class TestHeapPython(TestHeap): module = py_heapq @skipUnless(c_heapq, 'requires _heapq') class TestHeapC(TestHeap): module = c_heapq ... def test_main(verbose=None): test_classes = [TestModules, TestHeapPython, TestHeapC, # TestHeap is omitted from the list and not run directly -- Terry Jan Reedy From boxeakasteen at gmail.com Wed Oct 3 16:15:05 2012 From: boxeakasteen at gmail.com (Steen Lysgaard) Date: Wed, 3 Oct 2012 22:15:05 +0200 Subject: Combinations of lists In-Reply-To: References: <506C4B23.6020809@gmail.com> Message-ID: Hi, thanks for your interest. Sorry for not being completely clear, yes the length of m will always be half of the length of h. /Steen 2012/10/3 Joshua Landau : > On 3 October 2012 20:20, Oscar Benjamin wrote: >> >> On 3 October 2012 15:26, Steen Lysgaard wrote: >> > Hi, >> > >> > I am looking for a clever way to compute all combinations of two lists. >> > Look >> > at this example: >> > >> > h = ['A','A','B','B'] >> > m = ['a','b'] >> > >> > the resulting combinations should be of the same length as h and each >> > element in m can be used twice. The sought after result using h and m >> > from >> > above is: >> > >> > [['aA', 'aA', 'bB', 'bB'], >> > ['aA', 'aB', 'bA', 'bB'], >> > ['aB', 'aB', 'bA', 'bA']] >> > >> > (the order of the results does not matter i.e. ['aA', 'aA', 'bB', 'bB'] >> > and >> > ['aA', 'bB', 'aA', 'bB'] are considered the same) >> > >> > This is achieved by the code below, this however needs to go through all >> > possible combinations (faculty of len(h)) and rule out duplicates as >> > they >> > occur and this is too much if for example len(h) is 16. >> >> I'm assuming that len(m) is always 2. Then if len(m) is 16 each >> element of h can be used 8 times. If this is not as you intended you >> will need to clarify how this problem generalises to other cases. > > > His code only works when len(m) is half of len(h), so this may not be the > right assumption. > >> >> The elements that go with the 'b's are implicitly determined once you >> have chosen the elements that go with the 'a's. The problem then is >> solved if you choose the elements that go with the 'a's. If we need to >> choose say k elements to go with the 'a's the basic problem becomes: >> "enumerate over all multisets of size k that are subsets of the >> multiset h." >> >> ''' >> def submultisets(multiset, subsetsize, stack=None): >> # Enter recursion >> if stack is None: >> multiset = dict((c, multiset.count(c)) for c in set(multiset)) >> stack = [] >> >> c = next(iter(multiset)) >> >> # End recursion >> if len(multiset) == 1: >> missing = subsetsize - len(stack) >> if multiset[c] >= missing: >> yield stack + missing * [c] >> return >> >> # Continue recursion >> count = multiset.pop(c) >> for n in range(count + 1): >> stack.extend(n * c) >> for result in submultisets(multiset, subsetsize, stack): >> yield result >> del stack[-n:] >> multiset[c] = count >> >> def uniquecombinations(h, m): >> for ha in submultisets(h, len(h)//2): >> hb = list(h) >> for c in ha: >> hb.remove(c) >> yield [m[0] + a for a in ha] + [m[1] + b for b in hb] >> >> h = ['A', 'A', 'B', 'B'] >> m = ['a', 'b'] >> >> for x in uniquecombinations(h, m): >> print(x) >> ''' >> >> Output: >> ['aB', 'aB', 'bA', 'bA'] >> ['aA', 'aB', 'bA', 'bB'] >> ['aA', 'aA', 'bB', 'bB'] From tjreedy at udel.edu Wed Oct 3 16:22:39 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Oct 2012 16:22:39 -0400 Subject: Experimental Python-based shell In-Reply-To: References: <8646284b-df85-45fe-a793-56b081c6262c@googlegroups.com> Message-ID: Indexing Python code is ugly. I suggest prefixing non-Python with $. On 10/3/2012 1:24 PM, Jonathan Hayward wrote: > I am open to suggestions and patches. I don't think the syntax strange, > though: it offers a clear and distinct way to differentiate Python and > shell commands, and shell commands can access Python variables when > specified. And it is a simple rule, without footnotes needed. -- Terry Jan Reedy From oscar.j.benjamin at gmail.com Wed Oct 3 16:29:11 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 3 Oct 2012 21:29:11 +0100 Subject: Combinations of lists In-Reply-To: References: <506C4B23.6020809@gmail.com> Message-ID: Oscar wrote: >>> def uniquecombinations(h, m): >>> for ha in submultisets(h, len(h)//2): >>> hb = list(h) >>> for c in ha: >>> hb.remove(c) >>> yield [m[0] + a for a in ha] + [m[1] + b for b in hb] >>> >>> h = ['A', 'A', 'B', 'B'] >>> m = ['a', 'b'] >>> >>> for x in uniquecombinations(h, m): >>> print(x) >>> ''' >>> >>> Output: >>> ['aB', 'aB', 'bA', 'bA'] >>> ['aA', 'aB', 'bA', 'bB'] >>> ['aA', 'aA', 'bB', 'bB'] On 3 October 2012 21:15, Steen Lysgaard wrote: > Hi, > > thanks for your interest. Sorry for not being completely clear, yes > the length of m will always be half of the length of h. > > /Steen Then you can make the uniquecombinations function recursive. First find the elements that go with 'a' then from the remaining elements find those that go with 'b', then 'c' and so on. Oscar From dihedral88888 at googlemail.com Wed Oct 3 16:41:35 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 3 Oct 2012 13:41:35 -0700 (PDT) Subject: Combinations of lists In-Reply-To: References: <506C4B23.6020809@gmail.com> Message-ID: <580dd38a-1fff-4c6d-b874-8f9cbcc195b4@googlegroups.com> Oscar Benjamin? 2012?10?4????UTC+8??4?29?51???? > Oscar wrote: > > >>> def uniquecombinations(h, m): > > >>> for ha in submultisets(h, len(h)//2): > > >>> hb = list(h) > > >>> for c in ha: > > >>> hb.remove(c) > > >>> yield [m[0] + a for a in ha] + [m[1] + b for b in hb] > > >>> > > >>> h = ['A', 'A', 'B', 'B'] > > >>> m = ['a', 'b'] > > >>> > > >>> for x in uniquecombinations(h, m): > > >>> print(x) > > >>> ''' > > >>> > > >>> Output: > > >>> ['aB', 'aB', 'bA', 'bA'] > > >>> ['aA', 'aB', 'bA', 'bB'] > > >>> ['aA', 'aA', 'bB', 'bB'] > > > > On 3 October 2012 21:15, Steen Lysgaard wrote: > > > Hi, > > > > > > thanks for your interest. Sorry for not being completely clear, yes > > > the length of m will always be half of the length of h. > > > > > > /Steen > > > > Then you can make the uniquecombinations function recursive. First > > find the elements that go with 'a' then from the remaining elements > > find those that go with 'b', then 'c' and so on. > > > > Oscar Lets simplify the problem as follows: A set of m symbols [0, 1,2,3...m-1] and each symbol can occur a pecified number of times [(0, k(0)), (1, k(1)), ....(m-1, k(m-1)].rom a list to form a list of (i, k(i)) where k(i) are all positive integers. For example [ (0,3), (1,2), (2, 1), (3, 2)], this is easy to generate valid numbers in base m numbers of sum(k(i)) digits. in the final string. From dihedral88888 at googlemail.com Wed Oct 3 16:41:35 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 3 Oct 2012 13:41:35 -0700 (PDT) Subject: Combinations of lists In-Reply-To: References: <506C4B23.6020809@gmail.com> Message-ID: <580dd38a-1fff-4c6d-b874-8f9cbcc195b4@googlegroups.com> Oscar Benjamin? 2012?10?4????UTC+8??4?29?51???? > Oscar wrote: > > >>> def uniquecombinations(h, m): > > >>> for ha in submultisets(h, len(h)//2): > > >>> hb = list(h) > > >>> for c in ha: > > >>> hb.remove(c) > > >>> yield [m[0] + a for a in ha] + [m[1] + b for b in hb] > > >>> > > >>> h = ['A', 'A', 'B', 'B'] > > >>> m = ['a', 'b'] > > >>> > > >>> for x in uniquecombinations(h, m): > > >>> print(x) > > >>> ''' > > >>> > > >>> Output: > > >>> ['aB', 'aB', 'bA', 'bA'] > > >>> ['aA', 'aB', 'bA', 'bB'] > > >>> ['aA', 'aA', 'bB', 'bB'] > > > > On 3 October 2012 21:15, Steen Lysgaard wrote: > > > Hi, > > > > > > thanks for your interest. Sorry for not being completely clear, yes > > > the length of m will always be half of the length of h. > > > > > > /Steen > > > > Then you can make the uniquecombinations function recursive. First > > find the elements that go with 'a' then from the remaining elements > > find those that go with 'b', then 'c' and so on. > > > > Oscar Lets simplify the problem as follows: A set of m symbols [0, 1,2,3...m-1] and each symbol can occur a pecified number of times [(0, k(0)), (1, k(1)), ....(m-1, k(m-1)].rom a list to form a list of (i, k(i)) where k(i) are all positive integers. For example [ (0,3), (1,2), (2, 1), (3, 2)], this is easy to generate valid numbers in base m numbers of sum(k(i)) digits. in the final string. From dreamingforward at gmail.com Wed Oct 3 16:50:08 2012 From: dreamingforward at gmail.com (Mark Adam) Date: Wed, 3 Oct 2012 15:50:08 -0500 Subject: Emulating C++ namespaces with ChainMap and metaclass trickery In-Reply-To: <506c836a$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <506c836a$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Oct 3, 2012 at 1:26 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > C++ namespaces are useful for encapsulating related objects within a > single file, subdividing the global namespace without using classes. > Python has modules, but they come in separate files. > > Using Python 3.3's ChainMap type, and some metaclass trickery, I abuse > the class keyword to (almost) emulate C++ namespaces: > Very interesting. I like the idea of continuing the namespace meme. My idea of using the builtins (in the prior list thread of "namespaces and modules"), is that if we overhaul the builtins, a unified data model could emerge to incorporate whatever ideas one may have for namespaces (i.e. "enclosures with a name"). My idea was to introduce the compound data type (using a ":" colon to separate two sides), whereby one associates a (*hashable*) "name" with an object ("meals":{"breakfast","lunch","dinner"}) . This has the extra advantage of killing two warts in Python with one stone: {} now is the empty set literal like people are taught, and a set of compounds makes a dictionary (dict now has set operations available), something which, in theory, should simply CPython implementation AND the python environment/API. "expose name" put the dictionary (or whatever type is decided for the rhs) into the builtin/global namespace. I have further thoughts, but that's all I have at the moment.... markj gothenburg, nebraska -------------- next part -------------- An HTML attachment was scrubbed... URL: From pd at google-groups-2012.dobrogost.net Wed Oct 3 17:13:10 2012 From: pd at google-groups-2012.dobrogost.net (Piotr Dobrogost) Date: Wed, 3 Oct 2012 14:13:10 -0700 (PDT) Subject: Why is pylaucher in Python 3.3 being installed in Windows folder? Message-ID: <6aa17d70-b4a4-44e4-aef3-46596768979f@c20g2000vbz.googlegroups.com> Why is pylauncher in Python 3.3 being installed in Windows folder and not in Program Files folder? Installing into Windows folder was maybe acceptable 10 years ago but not now... From tyler at tysdomain.com Wed Oct 3 17:20:43 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Wed, 03 Oct 2012 15:20:43 -0600 Subject: design question:game skill system In-Reply-To: References: <506B47DB.9030401@tysdomain.com> Message-ID: <506CAC2B.9070801@tysdomain.com> I just wanted to say thanks to all the people that provided input, both aonand off list. It gave me a good direction to head in. Thanks again. On 10/2/2012 2:34 PM, Ian Kelly wrote: > On Tue, Oct 2, 2012 at 2:00 PM, Littlefield, Tyler wrote: >> Hello all: >> I'm looking at a skill/perk system, where the player builds up his char by >> using perk points to add abilities. >> Each perk is under a category, and generally costs go up as you increase the >> perk. >> So I'm trying to figure something out; first, I'd really like the cost >> calculation and all of that to be dynamic, so that I don't have to write a >> calculateCost per object. I'd also like to be able to specify dependencies >> and say a level, as well as other factors before a player can obtain a perk >> and have them self documenting. The idea is that a player could do something >> like: >> data perk extended health >> and it would tell them they require health at 50 before they can purchase >> extended health, as well as the cost, the increase per level and the total >> overall cost. > What are the cost calculations based on? If there are specific > formulas then you would need to store them somehow, possibly just as a > function to be called or string to be evaled, but if the security of > the perk database is of concern then you could engineer a more > sandboxed representation. For dependencies, you can keep them in a > container. An extended health perk might look something like: > > cost_formula = "5 * level ** 2" > dependencies = {HEALTH: 50, PLAYER_LEVEL: 15} > benefits = {HEALTH: "7 * level"} > > where HEALTH and PLAYER_LEVEL are just some arbitrary known constants. > Your core perks library would then be responsible for looking this > information up, running the formulas, and performing whatever > calculations on it are needed. > >> Finally, I'm curious how to store and calculate these. I thought about using >> a uid per perk, then storing something like: {uid:level} on the player, but >> means that I have to lookup the name somehow still in the main perk >> database, then use that uid to check if the player has it. Are there better >> ways of storing skills? > When you say uids, you mean UUIDs, right? I'm not sure what advantage > there is in using abstracted unique identifiers for these. Assuming > you have full control over what perks are added, you can ensure there > will be no name clashes, so why not just use the name or a name-based > tag to uniquely identify each perk? Regardless of how you identify > them, though, your code is at some point going to have to go to the > database to look them up, so I would suggest you just go ahead and > write that code, and then you can add some caching later if it turns > out to be needed. > >> I'm also thinking about calculation; currently the >> CalculateMaxHp method would have to add up all the possible perks for >> health, then add stats and all that. That could get really rough on >> performance if it's called often; would something like a cache work, where >> you have something like: {attribute:dirty}? So if I call CalculateHealth, it >> checks for the dirty flag, and if it doesn't exist just returns the previous >> max HP, but if the dirty flag is set, it recalculates? Then anything >> modifying health (level gains, perks, stat increases/etc) would just set the >> dirty flag and call calculate? > Sounds reasonable. I wouldn't use a separate flag attribute, though. > When max HP becomes dirty, clear the cached value, and use the absence > of a cached value to inform your code that it needs to recalculate. -- 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 bsj at abzinc.com Wed Oct 3 18:30:24 2012 From: bsj at abzinc.com (Benjamin Jessup) Date: Wed, 03 Oct 2012 18:30:24 -0400 Subject: fastest data structure for retrieving objects identified by (x,y) tuple? Message-ID: <506CBC80.2090505@abzinc.com> I have a group of objects identified by unique (x,y) pairs and I want to find out an object's "neighbors" in a matrix of size 2400 x 2400. ############# #obj# # # ############# # # #obj# 3 x 3 Example ############# # # # # ############# There is either a neighbor, or a null value. I always know the (x,y) pair to check the neighbors of, so is doing, >> obj = grid[x][y] #lists, doesn't scale with num of objects or, >> obj = grid.get((x,y),None) #dictionary, scales with num of objects the fastest? I can't seem to find a conclusion by testing each alone, then in the full environment. Is it that, depending on the number of objects, each has an advantage? I know the fastest way to retrieve them would be to have them store pointers to their neighbors, then use those for retrieval. When large numbers of objects are changing their (x,y) pairs, rebuilding the pointers is too slow. From joshua.landau.ws at gmail.com Wed Oct 3 18:35:02 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Wed, 3 Oct 2012 23:35:02 +0100 Subject: Combinations of lists In-Reply-To: References: <506C4B23.6020809@gmail.com> Message-ID: On 3 October 2012 21:15, Steen Lysgaard wrote: > Hi, > > thanks for your interest. Sorry for not being completely clear, yes > the length of m will always be half of the length of h. > (Please don't top post ) I have a solution to this, then. It's not short *or* fast, but it's a lot faster than yours. But first let me explain the most obvious optimization to your version of the code: combs = set() > > for a in permutations(range(len(h)),len(h)): > comb = [] > for i in range(len(h)): > comb.append(c[i][a[i]]) > comb.sort() > > frzn = tuple(comb) > if frzn not in combs: > combs.add(frzn) What I have done here is make your "combs" a set. This helps because you are searching inside it and that is an O(N) operation... for lists. A set can do the same in O(1). Simplez. first = list("AABBCCDDEE") second = list("abcde") import itertools # # Generator, so ignoring case convention class force_unique_combinations: def __init__(self, lst, n): self.cache = set() self.internal_iter = itertools.combinations(lst, n) def __iter__(self): return self def __next__(self): while True: nxt = next(self.internal_iter) if not nxt in self.cache: self.cache.add(nxt) return nxt def combine(first, second): sletter = second[0] first_combinations = force_unique_combinations(first, 2) if len(second) == 1: for combination in first_combinations: yield [sletter+combination[0], sletter+combination[1]] else: for combination in first_combinations: first_ = first[:] first_.remove(combination[0]) first_.remove(combination[1]) prefix = [sletter+combination[0], sletter+combination[1]] for inner in combine(first_, second[1:]): yield prefix + inner This is quite naive, because I don't know how to properly implement force_unique_combinations, but it runs. I hope this is right. If you need significantly more speed your best chance is probably Cython or C, although I don't doubt 10x more speed may well be possible from within Python. *Also, 88888 Dihedral is a bot, or at least pretending like crazy to be one. * -------------- next part -------------- An HTML attachment was scrubbed... URL: From joshua.landau.ws at gmail.com Wed Oct 3 18:47:39 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Wed, 3 Oct 2012 23:47:39 +0100 Subject: fastest data structure for retrieving objects identified by (x, y) tuple? In-Reply-To: <506CBC80.2090505@abzinc.com> References: <506CBC80.2090505@abzinc.com> Message-ID: On 3 October 2012 23:30, Benjamin Jessup wrote: > I have a group of objects identified by unique (x,y) pairs and I want to > find out an object's "neighbors" in a matrix of size 2400 x 2400. > ############# > #obj# # # > ############# > # # #obj# 3 x 3 Example > ############# > # # # # > ############# > There is either a neighbor, or a null value. I always know the (x,y) pair > to check the neighbors of, so is doing, > >> obj = grid[x][y] #lists, doesn't scale with num of objects > or, > >> obj = grid.get((x,y),None) #dictionary, scales with num of objects > the fastest? I can't seem to find a conclusion by testing each alone, then > in the full environment. Is it that, depending on the number of objects, > each has an advantage? > > I know the fastest way to retrieve them would be to have them store > pointers to their neighbors, then use those for retrieval. When large > numbers of objects are changing their (x,y) pairs, rebuilding the pointers > is too slow You really are asking the wrong question. If most of the data is None, then a sparse matrix is best. Otherwise, lists make the most sense. *However, *what you really want is... a matrix. Look for a sparse matrix type ( http://stackoverflow.com/questions/1053928/python-numpy-very-large-matrices) if you need sparse, and otherwise Numpy's matrix should do fine. The thing is this: "I can't seem to find a conclusion by testing each alone, then in the full environment. Is it that, depending on the number of objects, each has an advantage?" If you can't tell, don't bother. Dictionaries will have a memory advantage with sparse matrices, lists in the other cases. That's the important part, as look-up is fast for both*. If you need faster than these builtins, use Numpy or SciPy. If you really need optimization help, profile and ask the *right* question to this list. * To actually answer the question: They both have O(1) look-up time, although dictionaries have a theoretical * worst* case of O(N). Being simpler, it's faster to index a list. However, you're doing that twice, so it's probably around even. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Oct 3 21:58:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Oct 2012 01:58:16 GMT Subject: fastest data structure for retrieving objects identified by (x,y) tuple? References: Message-ID: <506ced38$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Oct 2012 18:30:24 -0400, Benjamin Jessup wrote: > I have a group of objects identified by unique (x,y) pairs and I want to > find out an object's "neighbors" in a matrix of size 2400 x 2400. [...] > There is either a neighbor, or a null value. I always know the (x,y) > pair to check the neighbors of, so is doing, > >> obj = grid[x][y] #lists, doesn't scale with num of objects > or, > >> obj = grid.get((x,y),None) #dictionary, scales with num of objects > the fastest? I can't seem to find a conclusion by testing each alone, > then in the full environment. Is it that, depending on the number of > objects, each has an advantage? Almost certainly not. Since you don't show how you test each, I have no idea why you can't find a conclusion. Let's start off with the question you don't ask: which uses less memory? The answer is, the dict solution by far. Here is a test: # populate a random matrix using both dict and list adict = {} alist = [[None]*2400 for i in range(2400)] from random import randrange for i in range(1000): x = randrange(2400) y = randrange(2400) adict[(x, y)] = "something" alist[x][y] = "something" import sys print(sys.getsizeof(adict)) print(sys.getsizeof(alist) + sum(sys.getsizeof(L) for L in alist)) The actual sizes printed will depend on how sparse the matrices are, but for the same above (approximately half full), using Python 2.7, the figures I get are: adict: 24712 alist: 23127324 Now let's test the speed: # randomly select matrix coordinates to look-up test_coords = [] for i in range(1000): x = randrange(2400) y = randrange(2400) test_coords.append((x, y)) # build some test code from timeit import Timer setup = "from __main__ import adict, alist, test_coords" t1 = Timer("for p in test_coords: obj = adict.get(p)", setup) t2 = Timer("for p in test_coords: obj = alist[p[0]][p[1]]", setup) # run the test code print(min(t1.repeat(number=10000, repeat=7))) print(min(t2.repeat(number=10000, repeat=7))) Again, on my system using Python 2.7, I get: 3.13823986053 2.97539305687 which shows that the two are very close, but the list solution is about 6% faster. So in this situation, a list of lists uses about 100 times more memory than a dict, but look-ups are about 6% faster. I would be very surprised if the timing results depended on the number of objects in the matrices. In case you are not familiar with timeit, let me explain what I have done: * I pre-select 1000 random coordinates. * I write some test code inside a Timer object that look up each of those coordinates, plus some setup code. * timeit runs the setup code once. * Then it runs my test code 10000 times as a single trial, timing it as accurately as possible. * It does seven trials, and I report the best of the seven. The time printed is measured in seconds. In this case, I get 3 seconds per trial, or 3e-7 seconds = 0.3 microseconds per lookup. > I know the fastest way to retrieve them would be to have them store > pointers to their neighbors, then use those for retrieval. How do you know that? No offence, but if you can't even work out whether lookups in a dict or a list are faster, I can't imagine why you think you can intuit what the fastest way to retrieve the nearest neighbours would be. -- Steven From steve+comp.lang.python at pearwood.info Wed Oct 3 22:04:17 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Oct 2012 02:04:17 GMT Subject: Why is pylaucher in Python 3.3 being installed in Windows folder? References: <6aa17d70-b4a4-44e4-aef3-46596768979f@c20g2000vbz.googlegroups.com> Message-ID: <506ceea1$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Oct 2012 14:13:10 -0700, Piotr Dobrogost wrote: > Why is pylauncher in Python 3.3 being installed in Windows folder and > not in Program Files folder? Installing into Windows folder was maybe > acceptable 10 years ago but not now... Read the PEP: http://www.python.org/dev/peps/pep-0397/ -- Steven From steve+comp.lang.python at pearwood.info Wed Oct 3 22:25:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Oct 2012 02:25:01 GMT Subject: fastest data structure for retrieving objects identified by (x,y) tuple? References: <506ced38$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <506cf37c$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Oct 2012 01:58:16 +0000, Steven D'Aprano wrote: > adict: 24712 > alist: 23127324 [...] > So in this situation, a list of lists uses about 100 times > more memory than a dict, but look-ups are about 6% faster. Correction: about 1000 times more memory. Sorry for the typo. -- Steven From contropinion at gmail.com Wed Oct 3 23:01:17 2012 From: contropinion at gmail.com (contro opinion) Date: Wed, 3 Oct 2012 23:01:17 -0400 Subject: + in regular expression Message-ID: >>> str=" gg" >>> x1=re.match("\s+",str) >>> x1 <_sre.SRE_Match object at 0xb7354db0> >>> x2=re.match("\s{6}",str) >>> x2 <_sre.SRE_Match object at 0xb7337f38> >>> x3=re.match("\s{6}+",str) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 137, in match return _compile(pattern, flags).match(string) File "/usr/lib/python2.6/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: multiple repeat >>> why the "\s{6}+" is not a regular pattern? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tyler at tysdomain.com Wed Oct 3 23:11:29 2012 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Wed, 03 Oct 2012 21:11:29 -0600 Subject: final question: logging to stdout and updating files Message-ID: <506CFE61.2020302@tysdomain.com> pHello all: I've seen frameworks like django reload files when it detects that they've been changed; how hard would it be to make my engine reload files that it detects were changed? I'm also curious how hard it would be to build in some error recovery. For example right now when an exception occurs, the player is sometimes just left hanging. It's a lot harder with Python for me, because I don't get the compile-time errors that I would with c++ for example to know that I did something wrong; while that's not always useful/and by far it doesn't catch everything, it does help. I'm familiar with things like pychecker, but it seems to be reporting a lot of issues that aren't issues. For example, I have a world module which is the core of the engine; it handles players, as well as keeps tracks of all rooms that are loaded in the game and that. Because player and world would have circular imports, I just pass the world object into player functions like logon/create. Pychecker tells me that the world parameter (which is a local var at that point) shadows the world variable in world; world is a singleton, so when you import world it just has a world = World() at the bottom of the module. also: I have the following code: logging.basicConfig(filename=path.join("logs", "mud.log"), level=logging.DEBUG) logger = logging.getLogger(__name__) logger.addHandler(logging.StreamHandler()) I like it displaying to stderr since usually when I'm doing this I'm in screen bouncing back and forth between the output and the tt++ session, but right now I can't get a couple of things; I'm not sure how to set it to log and all other messages to stderr as I did for the file, and I'd like to use a rotating log handler so that it'll rotate when the files are say above 16 KB or something. Is it possible to do something like this; perhaps make it compress the file before it writes to disk, or call a command to do so, so that it wouldn't hang the entire mud while it compresses? Thanks, and sorry again for all the questions. -- 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 ian.g.kelly at gmail.com Wed Oct 3 23:17:19 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 3 Oct 2012 21:17:19 -0600 Subject: + in regular expression In-Reply-To: References: Message-ID: On Wed, Oct 3, 2012 at 9:01 PM, contro opinion wrote: > why the "\s{6}+" is not a regular pattern? Use a group: "(?:\s{6})+" From ian.g.kelly at gmail.com Wed Oct 3 23:21:52 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 3 Oct 2012 21:21:52 -0600 Subject: Why is pylaucher in Python 3.3 being installed in Windows folder? In-Reply-To: <506ceea1$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <6aa17d70-b4a4-44e4-aef3-46596768979f@c20g2000vbz.googlegroups.com> <506ceea1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Oct 3, 2012 at 8:04 PM, Steven D'Aprano wrote: > On Wed, 03 Oct 2012 14:13:10 -0700, Piotr Dobrogost wrote: > >> Why is pylauncher in Python 3.3 being installed in Windows folder and >> not in Program Files folder? Installing into Windows folder was maybe >> acceptable 10 years ago but not now... > > Read the PEP: > > http://www.python.org/dev/peps/pep-0397/ The PEP explains why it's in the Windows folder as opposed to the System32 folder, but not why either of those locations should be preferable to Program Files. From k.sahithi2862 at gmail.com Thu Oct 4 00:18:32 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Wed, 3 Oct 2012 21:18:32 -0700 (PDT) Subject: HOT TEMPTING PHOTOS & VIDEOS Message-ID: <05e0955e-25e0-4d2f-8166-76a9c1f542e6@b9g2000pbc.googlegroups.com> REGINA NEW ACTRESS HOT PHOTOS http://actressgallery-images.blogspot.in/2012/10/regina-actress.html Krishnam Vande Jagadgurum Telugu Movie Photos Stills http://actressgallery-images.blogspot.in/2012/10/krishnam-vande-jagadgurum-stills.html KAJL AGARWAL SPICY STILLS IN BROTHERS MOVIE http://actressgallery-images.blogspot.in/2012/10/brothers-movie-photos.html Cameraman Gangatho Rambabu Movie Stills http://actressgallery-images.blogspot.in/2012/10/cameraman-gangatho-rambabu-movie-stills.html DAMARUKAM MOVIE HOT SPCY GALLERY http://actressgallery-images.blogspot.in/2012/10/damarukam-movie-stills.html ACTRESS POORNA LATEST HOT PHOTOS http://actressgallery-images.blogspot.in/2012/09/poorna.html LOVERS ENJOYMENT VIDEOS IN PARKS http://youtu.be/835RKstl5WY Crazy Cheer GirlsSuper Dance Videos http://youtu.be/f91izd0BdyU Yuvraj Singh Smashes Pakistan Bowler http://youtu.be/9y-kPCP0Ku4 Crazy Girl Super Dance http://youtu.be/f91izd0BdyU COMPLICATED TRUE LOVE STORY http://youtu.be/MUE_rZ0onsc Amrutha First night videos http://youtu.be/vk2foRUABao ENGENEERING COLLEGE GIRLS ENJOYMENT VIDOES http://youtu.be/8itq-a9Mp_c PRABHAS REBEL MOVIE STILLS http://actressgallery-images.blogspot.in/2012/09/rebel-movie-stills.html AGNATHAM MOVIE WALLPAPERS http://actressgallery-images.blogspot.in/2012/09/agnatham-movie-stills.html SADA HOT STILLS IN MYTHILI MOVIE http://actressgallery-images.blogspot.in/2012/09/mythili-movie-stills.html RIYA CHAKRAVARTHI LATEST GALLERY http://actressgallery-images.blogspot.in/2012/09/ria-chakravarthi.html TELISI TELIYAKA MOVIE STILLS http://actressgallery-images.blogspot.in/2012/09/telisi-teliyaka-movie-stills.html LIVE MOVIE LATEST PHOTOS http://actressgallery-images.blogspot.in/2012/09/live-movie-stills.html ANAGARIGAM 2 MOVIE HOT STILLS http://actressgallery-images.blogspot.in/2012/08/anagarigam-2-movie-stills.html CHARULATHA MOVIE SPICY STILLS http://actressgallery-images.blogspot.in/2012/08/charulatha-telugu-movie-images.html LOVE CYCLE LATEST MOVIE GALLERY http://actressgallery-images.blogspot.in/2012/08/love-cycle-telugu-movie-photos.html NIRANTHARAM NEE OOHALE GALLERY http://actressgallery-images.blogspot.in/2012/08/nirantharam-nee-oohale-movie-stills.html SAIBABA MOVIE IMAGES http://actressgallery-images.blogspot.in/2012/08/nagarjuna-shridi-sai-movie-stills.html SRIDEVI ENGLISH VINGLISH MOVIE IMAGES http://actressgallery-images.blogspot.in/2012/08/sri-devi-english-vinglish-movie-stills.html SUDIGADU FILM GALLERY http://actressgallery-images.blogspot.in/2012/08/sudigadu-movie-stills.html HOT GIRLS VIDEOS University Girls Party Enjoyment http://youtu.be/xvKiwWcDDM0 Hostel girls Secret Enjoyments http://youtu.be/LiX__IFTBoo Girls Dance ForBollywood Latest hits http://youtu.be/-5PDndnMPro Engineering college girls Enjoyment http://youtu.be/8itq-a9Mp_c GIRAFFE VIDEO IN ZOOPARK http://youtu.be/JTd9BWU9_4o From clp2 at rebertia.com Thu Oct 4 00:30:14 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Oct 2012 21:30:14 -0700 Subject: Why is pylaucher in Python 3.3 being installed in Windows folder? In-Reply-To: References: <6aa17d70-b4a4-44e4-aef3-46596768979f@c20g2000vbz.googlegroups.com> <506ceea1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Oct 3, 2012 at 8:21 PM, Ian Kelly wrote: > On Wed, Oct 3, 2012 at 8:04 PM, Steven D'Aprano > wrote: >> On Wed, 03 Oct 2012 14:13:10 -0700, Piotr Dobrogost wrote: >> >>> Why is pylauncher in Python 3.3 being installed in Windows folder and >>> not in Program Files folder? Installing into Windows folder was maybe >>> acceptable 10 years ago but not now... >> >> Read the PEP: >> >> http://www.python.org/dev/peps/pep-0397/ > > The PEP explains why it's in the Windows folder as opposed to the > System32 folder, but not why either of those locations should be > preferable to Program Files. Presumably because Program Files isn't part of the $PATH. http://superuser.com/questions/124239/what-is-the-default-path-environment-variable-setting-on-fresh-install-of-window Contrast (from the PEP): "However, the Windows directory is always on the path." Now, as for why the launcher must be on the $PATH?*shrugs* Cheers, Chris From clp2 at rebertia.com Thu Oct 4 00:47:33 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Oct 2012 21:47:33 -0700 Subject: Can somebody give me an advice about what to learn? In-Reply-To: <20121003203108.50406660f9e7843c7e2e99a7@gmx.net> References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> <20121003203108.50406660f9e7843c7e2e99a7@gmx.net> Message-ID: On Wed, Oct 3, 2012 at 11:31 AM, Wolfgang Keller wrote: >> I'm really new to Usenet/Newsgroups, but... I'd like to learn some >> new programming language, because I learnt a bit of Perl though its >> OOP is ugly. So, after searching a bit, I found Python and Ruby, and >> both of they are cute. So, assuming you'll say me "learn python", why >> should I learn it over Ruby? > > The point why Ruby was started (perceived deficit of object-orientation) > has been remedied since Python 2.2. Not completely. At the least, there's arguably still the issue of len() and friends (vs. `.length` etc.), and also of `self` being explicit. Cheers, Chris From shambhu.rajak at calsoftinc.com Thu Oct 4 01:13:57 2012 From: shambhu.rajak at calsoftinc.com (Shambhu Rajak) Date: Thu, 4 Oct 2012 10:43:57 +0530 Subject: How to execute commands on a windows machine from a Linux machine Message-ID: <008501cda1ef$0ec17eb0$2c447c10$@calsoftinc.com> Here i have two questions, 1. I want to write a framework for Linux machine that can execute commands on windows machine: How to create a persistent shell between Linux and Windows machine. 2. I require to extract windows disk management features, for eg: Number of drives on that windows machine , volume size of the machine, to create a partition, all these storage stuffs. I want to achieve all these features of windows machine, from linux. -Shambhu -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Thu Oct 4 02:15:05 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 04 Oct 2012 01:15:05 -0500 Subject: How to execute commands on a windows machine from a Linux machine In-Reply-To: <008501cda1ef$0ec17eb0$2c447c10$@calsoftinc.com> References: <008501cda1ef$0ec17eb0$2c447c10$@calsoftinc.com> Message-ID: <506D2969.5080305@gmail.com> On 2012.10.04 00:13, Shambhu Rajak wrote: > Here i have two questions, > > 1. I want to write a framework for Linux machine that can execute > commands on windows machine: > > How to create a persistent shell between Linux and Windows machine. > > 2. I require to extract windows disk management features, for eg: > Number of drives on that windows machine , > > volume size of the machine, to create a partition, all these storage > stuffs. I want to achieve all these features of windows machine, from linux. If you must use Python, there are execnet and RPyC, which will allow you to execute Python code remotely. Otherwise, there is Copssh, which has an SSH server that runs on Windows. http://codespeak.net/execnet/ http://rpyc.sourceforge.net/ https://www.itefix.no/i2/copssh -- CPython 3.3.0 | Windows NT 6.1.7601.17835 From steve+comp.lang.python at pearwood.info Thu Oct 4 02:34:42 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Oct 2012 06:34:42 GMT Subject: Can somebody give me an advice about what to learn? References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> <20121003203108.50406660f9e7843c7e2e99a7@gmx.net> Message-ID: <506d2e02$0$29972$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Oct 2012 21:47:33 -0700, Chris Rebert wrote: > On Wed, Oct 3, 2012 at 11:31 AM, Wolfgang Keller > wrote: >>> I'm really new to Usenet/Newsgroups, but... I'd like to learn some new >>> programming language, because I learnt a bit of Perl though its OOP is >>> ugly. So, after searching a bit, I found Python and Ruby, and both of >>> they are cute. So, assuming you'll say me "learn python", why should I >>> learn it over Ruby? >> >> The point why Ruby was started (perceived deficit of >> object-orientation) has been remedied since Python 2.2. > > Not completely. At the least, there's arguably still the issue of len() > and friends (vs. `.length` etc.), and also of `self` being explicit. I'm not entirely sure which "perceived deficit of object-orientation" is being talked about, or why anyone but OOP purists would consider that a problem. Python is *more* object-oriented than Java, and I don't hear anyone complaining that Java isn't object-oriented. Everything[1] in Python is an object. *Everything*. Ints are objects. Strings are objects. Arrays are objects. There's no distinction between "boxed" and "unboxed" ints, like in Java or Haskell -- Python just has ints, and they're always objects. As for len() and friends, that's a red-herring. Just because the syntax is written len(x) instead of x.len() doesn't make Python less object- oriented. It's just syntax: "a + b" is no less OO than "a.plus(b)". Somebody might not *like* the syntax "a + b", or "len(x)", but they should just say so, and not pretend that it isn't OO. Likewise self. Explicit or implicit, how does that make a language less or more object-oriented? That's as foolish as saying that Python isn't object-oriented because you don't have to declare the type of variables: x = (float)1.234 Again, there are arguments for and against explicit self, but "explicit self is not OO" is not a valid argument. Being object-oriented has both costs and benefits. Java compromises on the idea of OOP for performance: native, non-object ints are faster than object ints. All these people complaining that Python isn't OO enough because you have to write "self" in method declarations, why aren't they complaining that Java isn't OO enough because ints are unboxed primitive types? [1] Emphasis on the *thing* part. Control structures aren't things in that sense, they aren't values at all, they are actions that takes place during execution. -- Steven From oscar.j.benjamin at gmail.com Thu Oct 4 02:58:24 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 4 Oct 2012 07:58:24 +0100 Subject: fastest data structure for retrieving objects identified by (x, y) tuple? In-Reply-To: <506ced38$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <506ced38$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Oct 4, 2012 3:02 AM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > # populate a random matrix using both dict and list > adict = {} > alist = [[None]*2400 for i in range(2400)] > from random import randrange > for i in range(1000): > x = randrange(2400) > y = randrange(2400) > adict[(x, y)] = "something" > alist[x][y] = "something" > > import sys > print(sys.getsizeof(adict)) > print(sys.getsizeof(alist) + sum(sys.getsizeof(L) for L in alist)) > > > The actual sizes printed will depend on how sparse the matrices are, but > for the same above (approximately half full), using Python 2.7, the > figures I get are: > > adict: 24712 > alist: 23127324 I make it 0.02% full. If it was half full the dict might not have a memory advantage. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From maniandram01 at gmail.com Thu Oct 4 03:53:49 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 4 Oct 2012 00:53:49 -0700 (PDT) Subject: final question: logging to stdout and updating files In-Reply-To: References: Message-ID: On Thursday, 4 October 2012 08:41:35 UTC+5:30, Littlefield, Tyler wrote: > pHello all: > > I've seen frameworks like django reload files when it detects that > > they've been changed; how hard would it be to make my engine reload > > files that it detects were changed? I'm also curious how hard it would > > be to build in some error recovery. For example right now when an > > exception occurs, the player is sometimes just left hanging. It's a lot > > harder with Python for me, because I don't get the compile-time errors > > that I would with c++ for example to know that I did something wrong; > > while that's not always useful/and by far it doesn't catch everything, > > it does help. I'm familiar with things like pychecker, but it seems to > > be reporting a lot of issues that aren't issues. For example, I have a > > world module which is the core of the engine; it handles players, as > > well as keeps tracks of all rooms that are loaded in the game and that. > > Because player and world would have circular imports, I just pass the > > world object into player functions like logon/create. Pychecker tells me > > that the world parameter (which is a local var at that point) shadows > > the world variable in world; world is a singleton, so when you import > > world it just has a world = World() at the bottom of the module. > > > > also: I have the following code: > > logging.basicConfig(filename=path.join("logs", "mud.log"), > > level=logging.DEBUG) > > logger = logging.getLogger(__name__) > > logger.addHandler(logging.StreamHandler()) > > I like it displaying to stderr since usually when I'm doing this I'm in > > screen bouncing back and forth between the output and the tt++ session, > > but right now I can't get a couple of things; I'm not sure how to set it > > to log and all other messages to stderr as I did for the file, and I'd > > like to use a rotating log handler so that it'll rotate when the files > > are say above 16 KB or something. Is it possible to do something like > > this; perhaps make it compress the file before it writes to disk, or > > call a command to do so, so that it wouldn't hang the entire mud while > > it compresses? > > Thanks, and sorry again for all the questions. > > > > -- > > 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. I use pylint with NINJA IDE. NINJA IDE automatically shows common problems. From maniandram01 at gmail.com Thu Oct 4 03:53:49 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 4 Oct 2012 00:53:49 -0700 (PDT) Subject: final question: logging to stdout and updating files In-Reply-To: References: Message-ID: On Thursday, 4 October 2012 08:41:35 UTC+5:30, Littlefield, Tyler wrote: > pHello all: > > I've seen frameworks like django reload files when it detects that > > they've been changed; how hard would it be to make my engine reload > > files that it detects were changed? I'm also curious how hard it would > > be to build in some error recovery. For example right now when an > > exception occurs, the player is sometimes just left hanging. It's a lot > > harder with Python for me, because I don't get the compile-time errors > > that I would with c++ for example to know that I did something wrong; > > while that's not always useful/and by far it doesn't catch everything, > > it does help. I'm familiar with things like pychecker, but it seems to > > be reporting a lot of issues that aren't issues. For example, I have a > > world module which is the core of the engine; it handles players, as > > well as keeps tracks of all rooms that are loaded in the game and that. > > Because player and world would have circular imports, I just pass the > > world object into player functions like logon/create. Pychecker tells me > > that the world parameter (which is a local var at that point) shadows > > the world variable in world; world is a singleton, so when you import > > world it just has a world = World() at the bottom of the module. > > > > also: I have the following code: > > logging.basicConfig(filename=path.join("logs", "mud.log"), > > level=logging.DEBUG) > > logger = logging.getLogger(__name__) > > logger.addHandler(logging.StreamHandler()) > > I like it displaying to stderr since usually when I'm doing this I'm in > > screen bouncing back and forth between the output and the tt++ session, > > but right now I can't get a couple of things; I'm not sure how to set it > > to log and all other messages to stderr as I did for the file, and I'd > > like to use a rotating log handler so that it'll rotate when the files > > are say above 16 KB or something. Is it possible to do something like > > this; perhaps make it compress the file before it writes to disk, or > > call a command to do so, so that it wouldn't hang the entire mud while > > it compresses? > > Thanks, and sorry again for all the questions. > > > > -- > > 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. I use pylint with NINJA IDE. NINJA IDE automatically shows common problems. From oscar.j.benjamin at gmail.com Thu Oct 4 05:27:19 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 4 Oct 2012 10:27:19 +0100 Subject: final question: logging to stdout and updating files In-Reply-To: <506CFE61.2020302@tysdomain.com> References: <506CFE61.2020302@tysdomain.com> Message-ID: On 4 October 2012 04:11, Littlefield, Tyler wrote: > pHello all: > I've seen frameworks like django reload files when it detects that they've > been changed; how hard would it be to make my engine reload files that it > detects were changed? I tend to think that it's better to reload things explicitly. But if you do want to monitor your files for changes you can use something like this: http://packages.python.org/watchdog/ > I'm also curious how hard it would be to build in some > error recovery. For example right now when an exception occurs, the player > is sometimes just left hanging. The general idea is to try and make state changes atomic. In other words if an error occurs during an operation the previous state should be kept or restored. A simple way to do this is to ensure that anything that might generate an error is run before anything that changes state e.g.: def change_my_values(self, intvalue_string, floatvalue_string): # Do all processing first (might generate errors) iv = int(intvalue_string) fv = float(floatvalue_string) # Then change state self.intvalue = iv self.floatvalue = fv In this simple case, you can get the same effect with: def change_my_values(self, invalue_string, floatvalue_string): self.intvalue, self.floatvalue = in(intvalue_string), float(floatvalue_string) A more sophisticated way might use something like: oldstate = current_state() try: set_state(compute_new_state()) except: restore_state(oldstate) raise Naturally this is quite tedious if you have to put try/except everywhere, but this kind of exception handling can easily be factored out into a context manager. > It's a lot harder with Python for me, > because I don't get the compile-time errors that I would with c++ for > example to know that I did something wrong; while that's not always > useful/and by far it doesn't catch everything, it does help. Use unit tests. > I'm familiar > with things like pychecker, but it seems to be reporting a lot of issues > that aren't issues. You may find those useful but they are not a substitute for unit tests. > For example, I have a world module which is the core of > the engine; it handles players, as well as keeps tracks of all rooms that > are loaded in the game and that. Because player and world would have > circular imports, I just pass the world object into player functions like > logon/create. Pychecker tells me that the world parameter (which is a local > var at that point) shadows the world variable in world; world is a > singleton, so when you import world it just has a world = World() at the > bottom of the module. I would let the main script import World and create the world instance rather than placing a global variable in the world module. > > also: I have the following code: > logging.basicConfig(filename=path.join("logs", "mud.log"), > level=logging.DEBUG) > logger = logging.getLogger(__name__) > logger.addHandler(logging.StreamHandler()) > I like it displaying to stderr since usually when I'm doing this I'm in > screen bouncing back and forth between the output and the tt++ session, but > right now I can't get a couple of things; I'm not sure how to set it to log > and all other messages to stderr as I did for the file, and I'd like to use > a rotating log handler so that it'll rotate when the files are say above 16 > KB or something. Is it possible to do something like this; perhaps make it > compress the file before it writes to disk, or call a command to do so, so > that it wouldn't hang the entire mud while it compresses? Use a standard system tool to manage your server logs. For example logrotate(8) >From the manpage: ''' logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large. ''' Oscar From ashishjain.ash at gmail.com Thu Oct 4 07:24:13 2012 From: ashishjain.ash at gmail.com (ashishjain.ash at gmail.com) Date: Thu, 4 Oct 2012 04:24:13 -0700 (PDT) Subject: How to print html in python the normal way Message-ID: <4d096ff3-e25f-400e-89c6-47483aaacc0d@googlegroups.com> Hi, I wrote a simple filter as: @register.filter() def html(value): return '

Check

' when I use this filter in my template, it displays html as:

Check

I want to display as: Check am I missing something. - Thanks for your help Ashish From rosuav at gmail.com Thu Oct 4 07:30:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Oct 2012 21:30:53 +1000 Subject: How to print html in python the normal way In-Reply-To: <4d096ff3-e25f-400e-89c6-47483aaacc0d@googlegroups.com> References: <4d096ff3-e25f-400e-89c6-47483aaacc0d@googlegroups.com> Message-ID: On Thu, Oct 4, 2012 at 9:24 PM, wrote: > am I missing something. The first thing you're missing is more detail in your question. My crystal ball tells me you're using some kind of web framework and viewing this in your browser. And my second crystal ball suggests that it's probably Django. But is this correct? Lots more detail, please! ChrisA From bsj at abzinc.com Thu Oct 4 08:20:00 2012 From: bsj at abzinc.com (Benjamin Jessup) Date: Thu, 04 Oct 2012 08:20:00 -0400 Subject: Python-list Digest, Vol 109, Issue 20 In-Reply-To: References: Message-ID: <506D7EF0.8010001@abzinc.com> On 10/4/2012 12:20 AM, python-list-request at python.org wrote: > How do you know that? > > No offence, but if you can't even work out whether lookups in a dict or a > list are faster, I can't imagine why you think you can intuit what the > fastest way to retrieve the nearest neighbours would be. Whats wrong with the test below? # randomly select matrix coordinates to look-up from random import randrange test_coords = [] for i in range(1000): x = randrange(2400); y = randrange(2400); test_coords.append((x, y)) # build objects class Object():pass obj1 = Object(); obj2 = Object(); obj1.up = obj2 # build some test code from timeit import Timer setup = "from __main__ import test_coords, obj1, obj2" t = Timer("for p in test_coords: obj = obj1.up", setup) # run the test code print(min(t.repeat(number=10000, repeat=7))) import platform print(platform.python_version()) On my system, I get: 0.719622326348 2.7.1 From bsj at abzinc.com Thu Oct 4 08:21:13 2012 From: bsj at abzinc.com (Benjamin Jessup) Date: Thu, 04 Oct 2012 08:21:13 -0400 Subject: fastest data structure for retrieving objects identified by (x, y) tuple? In-Reply-To: References: Message-ID: <506D7F39.8060703@abzinc.com> On 10/4/2012 12:20 AM, python-list-request at python.org wrote: > How do you know that? > > No offence, but if you can't even work out whether lookups in a dict or a > list are faster, I can't imagine why you think you can intuit what the > fastest way to retrieve the nearest neighbours would be. Whats wrong with the test below? # randomly select matrix coordinates to look-up from random import randrange test_coords = [] for i in range(1000): x = randrange(2400); y = randrange(2400); test_coords.append((x, y)) # build objects class Object():pass obj1 = Object(); obj2 = Object(); obj1.up = obj2 # build some test code from timeit import Timer setup = "from __main__ import test_coords, obj1, obj2" t = Timer("for p in test_coords: obj = obj1.up", setup) # run the test code print(min(t.repeat(number=10000, repeat=7))) import platform print(platform.python_version()) On my system, I get: 0.719622326348 2.7.1 From maniandram01 at gmail.com Thu Oct 4 09:11:56 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 4 Oct 2012 06:11:56 -0700 (PDT) Subject: How to print html in python the normal way In-Reply-To: References: <4d096ff3-e25f-400e-89c6-47483aaacc0d@googlegroups.com> Message-ID: On Thursday, 4 October 2012 17:00:57 UTC+5:30, Chris Angelico wrote: > On Thu, Oct 4, 2012 at 9:24 PM, wrote: > > > am I missing something. > > > > The first thing you're missing is more detail in your question. My > > crystal ball tells me you're using some kind of web framework and > > viewing this in your browser. And my second crystal ball suggests that > > it's probably Django. But is this correct? Lots more detail, please! > > > > ChrisA +1 From maniandram01 at gmail.com Thu Oct 4 09:11:56 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 4 Oct 2012 06:11:56 -0700 (PDT) Subject: How to print html in python the normal way In-Reply-To: References: <4d096ff3-e25f-400e-89c6-47483aaacc0d@googlegroups.com> Message-ID: On Thursday, 4 October 2012 17:00:57 UTC+5:30, Chris Angelico wrote: > On Thu, Oct 4, 2012 at 9:24 PM, wrote: > > > am I missing something. > > > > The first thing you're missing is more detail in your question. My > > crystal ball tells me you're using some kind of web framework and > > viewing this in your browser. And my second crystal ball suggests that > > it's probably Django. But is this correct? Lots more detail, please! > > > > ChrisA +1 From maniandram01 at gmail.com Thu Oct 4 09:19:33 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 4 Oct 2012 06:19:33 -0700 (PDT) Subject: design question:game skill system In-Reply-To: References: <506B47DB.9030401@tysdomain.com> Message-ID: On Wednesday, 3 October 2012 14:19:57 UTC+5:30, Jean-Michel Pichavant wrote: > ----- Original Message ----- > > > Hello all: > > > I'm looking at a skill/perk system, where the player builds up his > > > char > > > by using perk points to add abilities. > > > Each perk is under a category, and generally costs go up as you > > > increase > > > the perk. > > > So I'm trying to figure something out; first, I'd really like the > > > cost > > > calculation and all of that to be dynamic, so that I don't have to > > > write > > > a calculateCost per object. I'd also like to be able to specify > > > dependencies and say a level, as well as other factors before a > > > player > > > can obtain a perk and have them self documenting. The idea is that a > > > player could do something like: > > > data perk extended health > > > and it would tell them they require health at 50 before they can > > > purchase extended health, as well as the cost, the increase per level > > > and the total overall cost. > > > Any ideas on how to set this up would be really appreciated. > > > Finally, I'm curious how to store and calculate these. I thought > > > about > > > using a uid per perk, then storing something like: {uid:level} on the > > > player, but means that I have to lookup the name somehow still in the > > > main perk database, then use that uid to check if the player has it. > > > Are > > > there better ways of storing skills? I'm also thinking about > > > calculation; currently the CalculateMaxHp method would have to add up > > > all the possible perks for health, then add stats and all that. That > > > could get really rough on performance if it's called often; would > > > something like a cache work, where you have something like: > > > {attribute:dirty}? So if I call CalculateHealth, it checks for the > > > dirty > > > flag, and if it doesn't exist just returns the previous max HP, but > > > if > > > the dirty flag is set, it recalculates? Then anything modifying > > > health > > > (level gains, perks, stat increases/etc) would just set the dirty > > > flag > > > and call calculate? > > > Thoughts/ideas would be welcome. > > > Thanks, > > > > Hi, > > > > Again, do not think about performances before actually having an issue with them. What's the point to optimize something that doesn't need it ? > > > > For your cache problem, google "python memoize decorator" for a bunch of decorators that will allow you to cache your data without any effort. > > > > JM True, but I always have an irresistible urge to optimize to every yoctosecond even if its absolutely useless to optimize. From maniandram01 at gmail.com Thu Oct 4 09:19:33 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 4 Oct 2012 06:19:33 -0700 (PDT) Subject: design question:game skill system In-Reply-To: References: <506B47DB.9030401@tysdomain.com> Message-ID: On Wednesday, 3 October 2012 14:19:57 UTC+5:30, Jean-Michel Pichavant wrote: > ----- Original Message ----- > > > Hello all: > > > I'm looking at a skill/perk system, where the player builds up his > > > char > > > by using perk points to add abilities. > > > Each perk is under a category, and generally costs go up as you > > > increase > > > the perk. > > > So I'm trying to figure something out; first, I'd really like the > > > cost > > > calculation and all of that to be dynamic, so that I don't have to > > > write > > > a calculateCost per object. I'd also like to be able to specify > > > dependencies and say a level, as well as other factors before a > > > player > > > can obtain a perk and have them self documenting. The idea is that a > > > player could do something like: > > > data perk extended health > > > and it would tell them they require health at 50 before they can > > > purchase extended health, as well as the cost, the increase per level > > > and the total overall cost. > > > Any ideas on how to set this up would be really appreciated. > > > Finally, I'm curious how to store and calculate these. I thought > > > about > > > using a uid per perk, then storing something like: {uid:level} on the > > > player, but means that I have to lookup the name somehow still in the > > > main perk database, then use that uid to check if the player has it. > > > Are > > > there better ways of storing skills? I'm also thinking about > > > calculation; currently the CalculateMaxHp method would have to add up > > > all the possible perks for health, then add stats and all that. That > > > could get really rough on performance if it's called often; would > > > something like a cache work, where you have something like: > > > {attribute:dirty}? So if I call CalculateHealth, it checks for the > > > dirty > > > flag, and if it doesn't exist just returns the previous max HP, but > > > if > > > the dirty flag is set, it recalculates? Then anything modifying > > > health > > > (level gains, perks, stat increases/etc) would just set the dirty > > > flag > > > and call calculate? > > > Thoughts/ideas would be welcome. > > > Thanks, > > > > Hi, > > > > Again, do not think about performances before actually having an issue with them. What's the point to optimize something that doesn't need it ? > > > > For your cache problem, google "python memoize decorator" for a bunch of decorators that will allow you to cache your data without any effort. > > > > JM True, but I always have an irresistible urge to optimize to every yoctosecond even if its absolutely useless to optimize. From joel.goldstick at gmail.com Thu Oct 4 09:19:35 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 4 Oct 2012 09:19:35 -0400 Subject: How to print html in python the normal way In-Reply-To: References: <4d096ff3-e25f-400e-89c6-47483aaacc0d@googlegroups.com> Message-ID: On Thu, Oct 4, 2012 at 9:11 AM, Ramchandra Apte wrote: > On Thursday, 4 October 2012 17:00:57 UTC+5:30, Chris Angelico wrote: >> On Thu, Oct 4, 2012 at 9:24 PM, wrote: >> >> > am I missing something. >> >> You should look at the built in django tags, and learn about them before writing your own In this case, look here: https://docs.djangoproject.com/en/dev/topics/templates/#filters striptags Strips all [X]HTML tags. For example: {{ value|striptags }} If value is "Joel a slug", the output will be "Joel is a slug". Again, these are just a few examples; see the built-in filter reference for the complete list. -- Joel Goldstick From maniandram01 at gmail.com Thu Oct 4 09:34:28 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 4 Oct 2012 06:34:28 -0700 (PDT) Subject: final question: logging to stdout and updating files In-Reply-To: References: Message-ID: On Thursday, 4 October 2012 08:41:35 UTC+5:30, Littlefield, Tyler wrote: > pHello all: > > I've seen frameworks like django reload files when it detects that > > they've been changed; how hard would it be to make my engine reload > > files that it detects were changed? I'm also curious how hard it would > > be to build in some error recovery. For example right now when an > > exception occurs, the player is sometimes just left hanging. It's a lot > > harder with Python for me, because I don't get the compile-time errors > > that I would with c++ for example to know that I did something wrong; > > while that's not always useful/and by far it doesn't catch everything, > > it does help. I'm familiar with things like pychecker, but it seems to > > be reporting a lot of issues that aren't issues. For example, I have a > > world module which is the core of the engine; it handles players, as > > well as keeps tracks of all rooms that are loaded in the game and that. > > Because player and world would have circular imports, I just pass the > > world object into player functions like logon/create. Pychecker tells me > > that the world parameter (which is a local var at that point) shadows > > the world variable in world; world is a singleton, so when you import > > world it just has a world = World() at the bottom of the module. > > > > also: I have the following code: > > logging.basicConfig(filename=path.join("logs", "mud.log"), > > level=logging.DEBUG) > > logger = logging.getLogger(__name__) > > logger.addHandler(logging.StreamHandler()) > > I like it displaying to stderr since usually when I'm doing this I'm in > > screen bouncing back and forth between the output and the tt++ session, > > but right now I can't get a couple of things; I'm not sure how to set it > > to log and all other messages to stderr as I did for the file, and I'd > > like to use a rotating log handler so that it'll rotate when the files > > are say above 16 KB or something. Is it possible to do something like > > this; perhaps make it compress the file before it writes to disk, or > > call a command to do so, so that it wouldn't hang the entire mud while > > it compresses? > > Thanks, and sorry again for all the questions. > > > > -- > > 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. Solution for the logging problem is to use to use logging.handlers.BaseRotatingHandler [0] ^0 http://docs.python.org/dev/library/logging.handlers.html#baserotatinghandler "Optimize code always even if it causes bugs" - Ramchandra Apte, 2001- From maniandram01 at gmail.com Thu Oct 4 09:34:28 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Thu, 4 Oct 2012 06:34:28 -0700 (PDT) Subject: final question: logging to stdout and updating files In-Reply-To: References: Message-ID: On Thursday, 4 October 2012 08:41:35 UTC+5:30, Littlefield, Tyler wrote: > pHello all: > > I've seen frameworks like django reload files when it detects that > > they've been changed; how hard would it be to make my engine reload > > files that it detects were changed? I'm also curious how hard it would > > be to build in some error recovery. For example right now when an > > exception occurs, the player is sometimes just left hanging. It's a lot > > harder with Python for me, because I don't get the compile-time errors > > that I would with c++ for example to know that I did something wrong; > > while that's not always useful/and by far it doesn't catch everything, > > it does help. I'm familiar with things like pychecker, but it seems to > > be reporting a lot of issues that aren't issues. For example, I have a > > world module which is the core of the engine; it handles players, as > > well as keeps tracks of all rooms that are loaded in the game and that. > > Because player and world would have circular imports, I just pass the > > world object into player functions like logon/create. Pychecker tells me > > that the world parameter (which is a local var at that point) shadows > > the world variable in world; world is a singleton, so when you import > > world it just has a world = World() at the bottom of the module. > > > > also: I have the following code: > > logging.basicConfig(filename=path.join("logs", "mud.log"), > > level=logging.DEBUG) > > logger = logging.getLogger(__name__) > > logger.addHandler(logging.StreamHandler()) > > I like it displaying to stderr since usually when I'm doing this I'm in > > screen bouncing back and forth between the output and the tt++ session, > > but right now I can't get a couple of things; I'm not sure how to set it > > to log and all other messages to stderr as I did for the file, and I'd > > like to use a rotating log handler so that it'll rotate when the files > > are say above 16 KB or something. Is it possible to do something like > > this; perhaps make it compress the file before it writes to disk, or > > call a command to do so, so that it wouldn't hang the entire mud while > > it compresses? > > Thanks, and sorry again for all the questions. > > > > -- > > 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. Solution for the logging problem is to use to use logging.handlers.BaseRotatingHandler [0] ^0 http://docs.python.org/dev/library/logging.handlers.html#baserotatinghandler "Optimize code always even if it causes bugs" - Ramchandra Apte, 2001- From info at egenix.com Thu Oct 4 09:41:20 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Thu, 04 Oct 2012 15:41:20 +0200 Subject: ANN: Python Meeting =?ISO-8859-1?Q?D=FCsseldorf_-_23=2E10=2E?= =?ISO-8859-1?Q?2012?= Message-ID: <506D9200.9090902@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, 23.10.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-10-23 ________________________________________________________________________ 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, Oct 04 2012) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2012-09-27: Released eGenix PyRun 1.1.0 ... http://egenix.com/go35 2012-09-26: Released mxODBC.Connect 2.0.1 ... http://egenix.com/go34 2012-09-25: Released mxODBC 3.2.1 ... http://egenix.com/go33 2012-10-23: Python Meeting Duesseldorf ... 19 days to go 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 steve+comp.lang.python at pearwood.info Thu Oct 4 10:00:26 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Oct 2012 14:00:26 GMT Subject: final question: logging to stdout and updating files References: Message-ID: <506d967a$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Oct 2012 06:34:28 -0700, Ramchandra Apte wrote: > "Optimize code always even if it causes bugs" - Ramchandra Apte, 2001- Well, you've just added yourself into my list of people whose advice should always be ignored. That is *terrible* advice. But if you insist on following it, you can optimize *any* Python program to this: # === start code === pass # this line is optional # === end code === There you go. The most heavily optimized, fastest Python program in existence. Sure, it has a few bugs, but boy is it fast!!! -- Steven From steve+comp.lang.python at pearwood.info Thu Oct 4 10:04:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Oct 2012 14:04:21 GMT Subject: fastest data structure for retrieving objects identified by (x, y) tuple? References: Message-ID: <506d9765$0$29978$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Oct 2012 08:21:13 -0400, Benjamin Jessup wrote: > On 10/4/2012 12:20 AM, python-list-request at python.org wrote: >> How do you know that? >> >> No offence, but if you can't even work out whether lookups in a dict or >> a list are faster, I can't imagine why you think you can intuit what >> the fastest way to retrieve the nearest neighbours would be. > > Whats wrong with the test below? [snip code] I don't know. Is this a trick question? Is the answer, "nothing is wrong"? It doesn't seem to be very useful code, but since I don't know what you think you are testing, I can't tell you whether you are doing it wrong or not. -- Steven From rosuav at gmail.com Thu Oct 4 10:27:34 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Oct 2012 00:27:34 +1000 Subject: final question: logging to stdout and updating files In-Reply-To: <506d967a$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <506d967a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Oct 5, 2012 at 12:00 AM, Steven D'Aprano wrote: > That is *terrible* advice. But if you insist on following it, you can > optimize *any* Python program to this: > > # === start code === > pass # this line is optional > # === end code === > > > There you go. The most heavily optimized, fastest Python program in > existence. Sure, it has a few bugs, but boy is it fast!!! Not many bugs though! I ran it in my Python 5.2.7 for GNU/Windows 256-bit (err, yeah, I borrowed Guido's time machine but had the silly thing in reverse... oops) and it worked perfectly, except that indentation has moved from "significant" to "mandatory". When I added the necessary 5 space indent at the beginning, it correctly created world peace, ensured that Australia won the next Test Match, and then printed "Hello, world!\n" to stdout. Unfortunately, a bug in your "end code" comment meant that the peace it created was by wiping out all life, but that's pretty minor in the scheme of things. Optimization really is that important, folks! ChrisA may need to schedule surgical detongueing of his cheek From pd at google-groups-2012.dobrogost.net Thu Oct 4 10:41:08 2012 From: pd at google-groups-2012.dobrogost.net (Piotr Dobrogost) Date: Thu, 4 Oct 2012 07:41:08 -0700 (PDT) Subject: Why is pylaucher in Python 3.3 being installed in Windows folder? References: <6aa17d70-b4a4-44e4-aef3-46596768979f@c20g2000vbz.googlegroups.com> <506ceea1$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <61a80e13-ddeb-4d7e-9da3-1e7377f65a67@h16g2000vby.googlegroups.com> On Oct 4, 6:30?am, Chris Rebert wrote: > Presumably because Program Files isn't part of the $PATH.http://superuser.com/questions/124239/what-is-the-default-path-enviro... > Contrast (from the PEP): "However, the Windows directory is always on the path." I guess that's the reason indeed. > Now, as for why the launcher must be on the $PATH?*shrugs* Now, the question is why not put pylauncher together with python.exe now, when 3.3 has an option to add Python's folder to the PATH? In case there are more than one Python installed this would mean changing pylauncher when changing active Python (via PATH modification). Maybe that's undesired? If so then installing to Program Files and adding its folder to PATH the same way Python's folder is added would be much better than installing into Windows folder. From steve+comp.lang.python at pearwood.info Thu Oct 4 10:52:43 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Oct 2012 14:52:43 GMT Subject: final question: logging to stdout and updating files References: Message-ID: <506da2bb$0$29978$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Oct 2012 21:11:29 -0600, Littlefield, Tyler wrote: > I've seen frameworks like django reload files when it detects that > they've been changed; how hard would it be to make my engine reload > files that it detects were changed? Oh, about as hard as writing a program. What sort of files? What does your engine do? How does it do it? Without knowing the answers to these questions, how can we possibly tell you how hard it will be to reload them? Detecting changed files is easy. If you google for "python monitor directory" and similar terms, you will find a metric tonne of solutions. Having your engine reload files is entirely up to you: it's your engine, it will be as trivial or as difficult as you make it be. > I'm also curious how hard it would be to build in some error recovery. How long is a piece of string? Again, that depends on you. If you design your application with error recovery in mind, it could be trivial. If you don't, it could be impossible. > For example right now when an > exception occurs, the player is sometimes just left hanging. It's a lot > harder with Python for me, because I don't get the compile-time errors > that I would with c++ for example to know that I did something wrong; > while that's not always useful/and by far it doesn't catch everything, > it does help. Sure, compiler-time checks can sometimes be useful. But in general, they tend to only detect the most trivial errors, syntax errors (Python does that too) and type errors. In Python, the usual answer is to concentrate on writing good unit tests. Good unit tests will test far more than the compiler ever could, and will pay for themselves a hundred times over. > I'm familiar with things like pychecker, but it seems to > be reporting a lot of issues that aren't issues. Pychecker, like other linters, don't just report fatal errors. They may also report *suspicious code* which may indicate an error, poor techniques, unused code, bad naming conventions, or other examples of poor style. You should be able to turn off such warnings. > For example, I have a > world module which is the core of the engine; it handles players, as > well as keeps tracks of all rooms that are loaded in the game and that. > Because player and world would have circular imports Right there is a terrible *code smell*. http://www.joelonsoftware.com/articles/Wrong.html Maybe you have a good reason for a circular import, but alarm bells are ringing. Rather than having: # world.py import player # player.py import world which leads to all sorts of complications, it is usually better to have a single module import both world and player and then combine them as needed. -- Steven From boxeakasteen at gmail.com Thu Oct 4 11:12:38 2012 From: boxeakasteen at gmail.com (Steen Lysgaard) Date: Thu, 4 Oct 2012 17:12:38 +0200 Subject: Combinations of lists In-Reply-To: References: <506C4B23.6020809@gmail.com> Message-ID: 2012/10/4 Joshua Landau : > On 3 October 2012 21:15, Steen Lysgaard wrote: >> >> Hi, >> >> thanks for your interest. Sorry for not being completely clear, yes >> the length of m will always be half of the length of h. > > > (Please don't top post) > > I have a solution to this, then. > It's not short or fast, but it's a lot faster than yours. > > But first let me explain the most obvious optimization to your version of > the code: > >> combs = set() >> >> >> for a in permutations(range(len(h)),len(h)): >> comb = [] >> for i in range(len(h)): >> comb.append(c[i][a[i]]) >> comb.sort() >> >> frzn = tuple(comb) >> if frzn not in combs: >> combs.add(frzn) > > > What I have done here is make your "combs" a set. This helps because you > are searching inside it and that is an O(N) operation... for lists. > A set can do the same in O(1). Simplez. > > first = list("AABBCCDDEE") > second = list("abcde") > import itertools > # > # Generator, so ignoring case convention > class force_unique_combinations: > def __init__(self, lst, n): > self.cache = set() > self.internal_iter = itertools.combinations(lst, n) > def __iter__(self): > return self > def __next__(self): > while True: > nxt = next(self.internal_iter) > if not nxt in self.cache: > self.cache.add(nxt) > return nxt > def combine(first, second): > sletter = second[0] > first_combinations = force_unique_combinations(first, 2) > if len(second) == 1: > for combination in first_combinations: > yield [sletter+combination[0], sletter+combination[1]] > else: > for combination in first_combinations: > first_ = first[:] > first_.remove(combination[0]) > first_.remove(combination[1]) > prefix = [sletter+combination[0], sletter+combination[1]] > for inner in combine(first_, second[1:]): > yield prefix + inner > > > This is quite naive, because I don't know how to properly implement > force_unique_combinations, but it runs. I hope this is right. If you need > significantly more speed your best chance is probably Cython or C, although > I don't doubt 10x more speed may well be possible from within Python. > > > Also, 88888 Dihedral is a bot, or at least pretending like crazy to be one. Great, I've now got a solution much faster than what I could come up with. Thanks to the both of you. And a good spot on 88... I could not for my life understand what he (it) had written. /Steen From pd at google-groups-2012.dobrogost.net Thu Oct 4 11:32:01 2012 From: pd at google-groups-2012.dobrogost.net (Piotr Dobrogost) Date: Thu, 4 Oct 2012 08:32:01 -0700 (PDT) Subject: Why is pylaucher in Python 3.3 being installed in Windows folder? References: <6aa17d70-b4a4-44e4-aef3-46596768979f@c20g2000vbz.googlegroups.com> Message-ID: I raised this issue at http://bugs.python.org/issue16131 From ian.g.kelly at gmail.com Thu Oct 4 11:51:10 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 4 Oct 2012 09:51:10 -0600 Subject: Why is pylaucher in Python 3.3 being installed in Windows folder? In-Reply-To: <61a80e13-ddeb-4d7e-9da3-1e7377f65a67@h16g2000vby.googlegroups.com> References: <6aa17d70-b4a4-44e4-aef3-46596768979f@c20g2000vbz.googlegroups.com> <506ceea1$0$29978$c3e8da3$5496439d@news.astraweb.com> <61a80e13-ddeb-4d7e-9da3-1e7377f65a67@h16g2000vby.googlegroups.com> Message-ID: On Thu, Oct 4, 2012 at 8:41 AM, Piotr Dobrogost wrote: > Now, the question is why not put pylauncher together with python.exe > now, when 3.3 has an option to add Python's folder to the PATH? In > case there are more than one Python installed this would mean changing > pylauncher when changing active Python (via PATH modification). Maybe > that's undesired? If so then installing to Program Files and adding > its folder to PATH the same way Python's folder is added would be much > better than installing into Windows folder. It shouldn't go in the Python folder. There can be more than one active Python installation, but there should really be only one active pylauncher installation. They should also be kept separate for uninstallation. So the launcher should have its own separate Program Files folder. I don't see why it's so important that the location be on the path in the first place, though. As I understand it this tool is primarily intended to support the .py and .pyw file associations, and those are best looked up in the registry, not on the path. The only reason I can see for having it on the path is for when you want to explicitly invoke it on the command line, and for that we can either add the Program Files location to the path or just let the user deal with setting the path, as many Windows programs do. > I raised this issue at http://bugs.python.org/issue16131 Unfortunately, with Python 3.3 already released, I suspect that it's probably too late to change this. From amoebae at gmail.com Thu Oct 4 11:53:20 2012 From: amoebae at gmail.com (David Banks) Date: Thu, 4 Oct 2012 08:53:20 -0700 (PDT) Subject: How can I hide my stack frames in a TestCase subclass? Message-ID: <52b17563-966c-46bc-bd77-da29e944c909@googlegroups.com> I want to add a custom assert method to a TestCase subclass. I tried to copy my implementation from the unittest module so that it would match the behaviour of the regular TestCase as closely as possible. (I would prefer to just delegate to self.assertEqual() but this causes even more backtrace noise, see below.) The unittest module seems to automatically hide some internal details of its implementation when reporting failed assertions. import unittest class MyTestCase(unittest.TestCase): def assertLengthIsOne(self, sequence, msg=None): if len(sequence) != 1: msg = self._formatMessage(msg, "length is not one") raise self.failureException(msg) class TestFoo(MyTestCase): seq = (1, 2, 3, 4, 5) def test_stock_unittest_assertion(self): self.assertEqual(len(self.seq), 1) def test_custom_assertion(self): self.assertLengthIsOne(self.seq) unittest.main() The output of this is as such: amoe at vuurvlieg $ python unittest-demo.py FF ====================================================================== FAIL: test_custom_assertion (__main__.TestFoo) ---------------------------------------------------------------------- Traceback (most recent call last): File "unittest-demo.py", line 16, in test_custom_assertion self.assertLengthIsOne(self.seq) File "unittest-demo.py", line 7, in assertLengthIsOne raise self.failureException(msg) AssertionError: length is not one ====================================================================== FAIL: test_stock_unittest_assertion (__main__.TestFoo) ---------------------------------------------------------------------- Traceback (most recent call last): File "unittest-demo.py", line 13, in test_stock_unittest_assertion self.assertEqual(len(self.seq), 1) AssertionError: 5 != 1 ---------------------------------------------------------------------- Ran 2 tests in 0.000s FAILED (failures=2) Note that the custom assert method causes a stack trace with two frames, one inside the method itself, whereas the stock unittest method only has one frame, the relevant line in the user's code. How can I apply this frame-hiding behaviour to my own method? From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Oct 4 12:11:28 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 04 Oct 2012 18:11:28 +0200 Subject: fastest data structure for retrieving objects identified by (x, y) tuple? In-Reply-To: <506ced38$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <506ced38$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 04.10.2012 03:58 schrieb Steven D'Aprano: > alist = [[None]*2400 for i in range(2400)] > from random import randrange > for i in range(1000): > x = randrange(2400) > y = randrange(2400) > adict[(x, y)] = "something" > alist[x][y] = "something" > The actual sizes printed will depend on how sparse the matrices are, but > for the same above (approximately half full), I wouldn't consider 1000 of 5760000 "half full"... Thomas From oscar.j.benjamin at gmail.com Thu Oct 4 12:40:16 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 4 Oct 2012 17:40:16 +0100 Subject: Why is pylaucher in Python 3.3 being installed in Windows folder? In-Reply-To: References: <6aa17d70-b4a4-44e4-aef3-46596768979f@c20g2000vbz.googlegroups.com> <506ceea1$0$29978$c3e8da3$5496439d@news.astraweb.com> <61a80e13-ddeb-4d7e-9da3-1e7377f65a67@h16g2000vby.googlegroups.com> Message-ID: On 4 October 2012 16:51, Ian Kelly wrote: > On Thu, Oct 4, 2012 at 8:41 AM, Piotr Dobrogost > wrote: >> Now, the question is why not put pylauncher together with python.exe >> now, when 3.3 has an option to add Python's folder to the PATH? In >> case there are more than one Python installed this would mean changing >> pylauncher when changing active Python (via PATH modification). Maybe >> that's undesired? If so then installing to Program Files and adding >> its folder to PATH the same way Python's folder is added would be much >> better than installing into Windows folder. > > It shouldn't go in the Python folder. There can be more than one > active Python installation, but there should really be only one active > pylauncher installation. They should also be kept separate for > uninstallation. So the launcher should have its own separate Program > Files folder. > > I don't see why it's so important that the location be on the path in > the first place, though. As I understand it this tool is primarily > intended to support the .py and .pyw file associations, and those are > best looked up in the registry, not on the path. The only reason I > can see for having it on the path is for when you want to explicitly > invoke it on the command line, and for that we can either add the > Program Files location to the path or just let the user deal with > setting the path, as many Windows programs do. Having them on PATH means that you can do: > py script.py and the effect will be analogous to (in a unix shell): $ ./script.py Of course the idea with the launcher is that you just do > script.py The difference - on my machine - between explicitly using invoking py and allowing the file association to do it is that the latter breaks when redirecting stdin (this is an old bug in Windows): Q:\>script.py < foo Traceback (most recent call last): File "Q:\script.py", line 5, in for line in sys.stdin: IOError: [Errno 9] Bad file descriptor Q:\>py script.py < foo LOTS OF STUFF It would be good to be able to choose where to put the launchers. Unless I missed something that wasn't an option in the installer. It lets you choose the location of all the other files by choosing where to put the Python folder. Also it's not as simple as just moving them to where you want after install since they are associated with the registry keys for running .py and .pyw files. As it happens, since I don't have access to the WINDOWS folder on my work machine, the installer did just put them into the Python33 folder (which is fine with me). Oscar From feliphil at gmx.net Thu Oct 4 13:45:56 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Thu, 4 Oct 2012 19:45:56 +0200 Subject: Can somebody give me an advice about what to learn? References: <15f76508-437a-4d18-ac9b-16174ef172e8@googlegroups.com> <20121003203108.50406660f9e7843c7e2e99a7@gmx.net> <506d2e02$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20121004194556.2d80e3f0c95a6fbdd52628ba@gmx.net> > >> The point why Ruby was started (perceived deficit of > >> object-orientation) has been remedied since Python 2.2. > > > > Not completely. At the least, there's arguably still the issue of > > len() and friends (vs. `.length` etc.), and also of `self` being > > explicit. > > I'm not entirely sure which "perceived deficit of object-orientation" > is being talked about, or why anyone but OOP purists would consider > that a problem. Yukihiro Matsumoto did. I myself never perceived any lack of object-orientation with Python, since I've learned programming with Pascal anyway. >;-> I just wanted to point out that given the state of Python today, no one would probably consider starting Ruby any more. Sincerely, Wolfgang From animelovin at gmail.com Thu Oct 4 14:10:46 2012 From: animelovin at gmail.com (Etienne Robillard) Date: Thu, 4 Oct 2012 14:10:46 -0400 Subject: notmm is dead! Message-ID: <20121004141046.677dac1e8bf6dada0b6af6b3@gmail.com> Dear list, Due to lack of energy and resources i'm really sad to announce the removal of notmm from pypi and bitbucket. I deleted also my account from bitbucket as it was not really useful for me. notmm will continue to be accessible from my master site at http://gthc.org/dist/notmm until the server get down, as I cannot find money to pay for the hosting of notmm.org, neither anyone to encourage the project so it can grow further. I have tried to develop a coherent extension for Django using the open source model but I'm afraid to have been bitten by its failure to encourage a free market over one dictated by profit and the use of cheap tricks to compete unfairly with perhaps too much openness. I always will also continue to love and use free softwares but sadly it seems asking for a little fairness is too much asked to competitors dedicated in stealing and subverting my work for their own advantages... I therefore refuse to continue any longer being mocked by competitors asking excessive prices for having a broken Internet dictated by a few companies and decide the content I should be visiting. Shall you have anything you wish saying I'll be open to discuss further on this list. I wish also to thanks the supporters of the project who have invested time and energy into my business and dedication to the notmm project. Best wishes, Etienne -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ erob at gthcfoundation.org "If a free society cannot help the many who are poor, it cannot save the few who are rich." -John F. Kennedy From breamoreboy at yahoo.co.uk Thu Oct 4 15:03:03 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 4 Oct 2012 12:03:03 -0700 (PDT) Subject: Anybody know what's up with Gmane? Message-ID: <4509cf54-a71d-44cc-90a5-0abd7c6a80cd@googlegroups.com> Good evening all, I read some 20 Python mailing lists through Gmane using Thunderbird on Windows but nothing new has arrived for almost 24 hours, hence why I've reluctantly resorted to Google groups to try and find out what is going on. Looking directly at http://news.gmane.org/gmane.comp.python.general shows the last post was the Steven D'Aprano thread titled "Emulating C++ namespaces with ChainMap and metaclass trickery" on 3 Oct at 20:26. I've tried flagging this up but obviously with no success. Anyone any ideas on how to sort this out? Kindest regards. Mark Lawrence. From dihedral88888 at googlemail.com Thu Oct 4 15:20:00 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 4 Oct 2012 12:20:00 -0700 (PDT) Subject: Combinations of lists In-Reply-To: References: <506C4B23.6020809@gmail.com> Message-ID: <3c6e2683-6328-4225-9ef2-20bf21c3a846@googlegroups.com> On Thursday, October 4, 2012 11:12:41 PM UTC+8, Steen Lysgaard wrote: > 2012/10/4 Joshua Landau : > > > On 3 October 2012 21:15, Steen Lysgaard wrote: > > >> > > >> Hi, > > >> > > >> thanks for your interest. Sorry for not being completely clear, yes > > >> the length of m will always be half of the length of h. > > > > > > > > > (Please don't top post) > > > > > > I have a solution to this, then. > > > It's not short or fast, but it's a lot faster than yours. > > > > > > But first let me explain the most obvious optimization to your version of > > > the code: > > > > > >> combs = set() > > >> > > >> > > >> for a in permutations(range(len(h)),len(h)): > > >> comb = [] > > >> for i in range(len(h)): > > >> comb.append(c[i][a[i]]) > > >> comb.sort() > > >> > > >> frzn = tuple(comb) > > >> if frzn not in combs: > > >> combs.add(frzn) > > > > > > > > > What I have done here is make your "combs" a set. This helps because you > > > are searching inside it and that is an O(N) operation... for lists. > > > A set can do the same in O(1). Simplez. > > > > > > first = list("AABBCCDDEE") > > > second = list("abcde") > > > import itertools > > > # > > > # Generator, so ignoring case convention > > > class force_unique_combinations: > > > def __init__(self, lst, n): > > > self.cache = set() > > > self.internal_iter = itertools.combinations(lst, n) > > > def __iter__(self): > > > return self > > > def __next__(self): > > > while True: > > > nxt = next(self.internal_iter) > > > if not nxt in self.cache: > > > self.cache.add(nxt) > > > return nxt > > > def combine(first, second): > > > sletter = second[0] > > > first_combinations = force_unique_combinations(first, 2) > > > if len(second) == 1: > > > for combination in first_combinations: > > > yield [sletter+combination[0], sletter+combination[1]] > > > else: > > > for combination in first_combinations: > > > first_ = first[:] > > > first_.remove(combination[0]) > > > first_.remove(combination[1]) > > > prefix = [sletter+combination[0], sletter+combination[1]] > > > for inner in combine(first_, second[1:]): > > > yield prefix + inner > > > > > > > > > This is quite naive, because I don't know how to properly implement > > > force_unique_combinations, but it runs. I hope this is right. If you need > > > significantly more speed your best chance is probably Cython or C, although > > > I don't doubt 10x more speed may well be possible from within Python. > > > > > > > > > Also, 88888 Dihedral is a bot, or at least pretending like crazy to be one. > > > > Great, I've now got a solution much faster than what I could come up with. > > Thanks to the both of you. > > And a good spot on 88... I could not for my life understand what he > > (it) had written. > > > > /Steen If an unique order is defined, then it is trivial to solve this problem without any recursions. From dihedral88888 at googlemail.com Thu Oct 4 15:20:00 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 4 Oct 2012 12:20:00 -0700 (PDT) Subject: Combinations of lists In-Reply-To: References: <506C4B23.6020809@gmail.com> Message-ID: <3c6e2683-6328-4225-9ef2-20bf21c3a846@googlegroups.com> On Thursday, October 4, 2012 11:12:41 PM UTC+8, Steen Lysgaard wrote: > 2012/10/4 Joshua Landau : > > > On 3 October 2012 21:15, Steen Lysgaard wrote: > > >> > > >> Hi, > > >> > > >> thanks for your interest. Sorry for not being completely clear, yes > > >> the length of m will always be half of the length of h. > > > > > > > > > (Please don't top post) > > > > > > I have a solution to this, then. > > > It's not short or fast, but it's a lot faster than yours. > > > > > > But first let me explain the most obvious optimization to your version of > > > the code: > > > > > >> combs = set() > > >> > > >> > > >> for a in permutations(range(len(h)),len(h)): > > >> comb = [] > > >> for i in range(len(h)): > > >> comb.append(c[i][a[i]]) > > >> comb.sort() > > >> > > >> frzn = tuple(comb) > > >> if frzn not in combs: > > >> combs.add(frzn) > > > > > > > > > What I have done here is make your "combs" a set. This helps because you > > > are searching inside it and that is an O(N) operation... for lists. > > > A set can do the same in O(1). Simplez. > > > > > > first = list("AABBCCDDEE") > > > second = list("abcde") > > > import itertools > > > # > > > # Generator, so ignoring case convention > > > class force_unique_combinations: > > > def __init__(self, lst, n): > > > self.cache = set() > > > self.internal_iter = itertools.combinations(lst, n) > > > def __iter__(self): > > > return self > > > def __next__(self): > > > while True: > > > nxt = next(self.internal_iter) > > > if not nxt in self.cache: > > > self.cache.add(nxt) > > > return nxt > > > def combine(first, second): > > > sletter = second[0] > > > first_combinations = force_unique_combinations(first, 2) > > > if len(second) == 1: > > > for combination in first_combinations: > > > yield [sletter+combination[0], sletter+combination[1]] > > > else: > > > for combination in first_combinations: > > > first_ = first[:] > > > first_.remove(combination[0]) > > > first_.remove(combination[1]) > > > prefix = [sletter+combination[0], sletter+combination[1]] > > > for inner in combine(first_, second[1:]): > > > yield prefix + inner > > > > > > > > > This is quite naive, because I don't know how to properly implement > > > force_unique_combinations, but it runs. I hope this is right. If you need > > > significantly more speed your best chance is probably Cython or C, although > > > I don't doubt 10x more speed may well be possible from within Python. > > > > > > > > > Also, 88888 Dihedral is a bot, or at least pretending like crazy to be one. > > > > Great, I've now got a solution much faster than what I could come up with. > > Thanks to the both of you. > > And a good spot on 88... I could not for my life understand what he > > (it) had written. > > > > /Steen If an unique order is defined, then it is trivial to solve this problem without any recursions. From mike20007 at gmail.com Thu Oct 4 16:52:50 2012 From: mike20007 at gmail.com (mike20007 at gmail.com) Date: Thu, 4 Oct 2012 13:52:50 -0700 (PDT) Subject: sum function Message-ID: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> Hi All, I am new to python and am getting the data from hbase. I am trying to do sum on the column as below scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) total = 0.0 r = client.scannerGet(scanner) while r: for k in (r[0].columns): total += float(r[0].columns[k].value) r = client.scannerGet(scanner) print total Do you know of better (faster) way to do sum? Any thoughts please? Thanks From ian.g.kelly at gmail.com Thu Oct 4 17:04:53 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 4 Oct 2012 15:04:53 -0600 Subject: sum function In-Reply-To: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> Message-ID: On Thu, Oct 4, 2012 at 2:52 PM, wrote: > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) > total = 0.0 > r = client.scannerGet(scanner) > while r: > for k in (r[0].columns): > total += float(r[0].columns[k].value) > r = client.scannerGet(scanner) > > print total > > Do you know of better (faster) way to do sum? scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) next_r = itertools.partial(client.scannerGet, scanner) total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) From ian.g.kelly at gmail.com Thu Oct 4 17:05:48 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 4 Oct 2012 15:05:48 -0600 Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> Message-ID: On Thu, Oct 4, 2012 at 3:04 PM, Ian Kelly wrote: > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) > next_r = itertools.partial(client.scannerGet, scanner) > total = sum(float(col.value) for r in iter(next_r, None) for col in > r.itervalues()) That should be "functools" above, not "itertools". :-P From mike20007 at gmail.com Thu Oct 4 17:29:54 2012 From: mike20007 at gmail.com (Mike) Date: Thu, 4 Oct 2012 14:29:54 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> Message-ID: <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> I get below error NameError: name 'functools' is not defined Thanks From mike20007 at gmail.com Thu Oct 4 17:29:54 2012 From: mike20007 at gmail.com (Mike) Date: Thu, 4 Oct 2012 14:29:54 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> Message-ID: <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> I get below error NameError: name 'functools' is not defined Thanks From mike20007 at gmail.com Thu Oct 4 17:31:19 2012 From: mike20007 at gmail.com (Mike) Date: Thu, 4 Oct 2012 14:31:19 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> Message-ID: Thanks Ian for the quick reply. I get the below error. NameError: name 'itertools' is not defined Thanks From mike20007 at gmail.com Thu Oct 4 17:31:19 2012 From: mike20007 at gmail.com (Mike) Date: Thu, 4 Oct 2012 14:31:19 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> Message-ID: Thanks Ian for the quick reply. I get the below error. NameError: name 'itertools' is not defined Thanks From rosuav at gmail.com Thu Oct 4 17:34:41 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Oct 2012 07:34:41 +1000 Subject: sum function In-Reply-To: <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> Message-ID: On Fri, Oct 5, 2012 at 7:29 AM, Mike wrote: > I get below error > > NameError: name 'functools' is not defined > > Thanks functools is a module: import functools ChrisA From d at davea.name Thu Oct 4 17:39:50 2012 From: d at davea.name (Dave Angel) Date: Thu, 04 Oct 2012 17:39:50 -0400 Subject: sum function In-Reply-To: <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> Message-ID: <506E0226.7010202@davea.name> On 10/04/2012 05:29 PM, Mike wrote: > I get below error > > NameError: name 'functools' is not defined > functools is a module in the standard library. You need to import it. import functools -- DaveA From breamoreboy at yahoo.co.uk Thu Oct 4 17:59:27 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 04 Oct 2012 22:59:27 +0100 Subject: + in regular expression In-Reply-To: References: Message-ID: On 04/10/2012 04:01, contro opinion wrote: >>>> str=" gg" >>>> x1=re.match("\s+",str) >>>> x1 > <_sre.SRE_Match object at 0xb7354db0> >>>> x2=re.match("\s{6}",str) >>>> x2 > <_sre.SRE_Match object at 0xb7337f38> >>>> x3=re.match("\s{6}+",str) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/re.py", line 137, in match > return _compile(pattern, flags).match(string) > File "/usr/lib/python2.6/re.py", line 245, in _compile > raise error, v # invalid expression > sre_constants.error: multiple repeat >>>> > > why the "\s{6}+" is not a regular pattern? > > > Why are you too lazy to do any research before posting a question? -- Cheers. Mark Lawrence. From ramit.prasad at jpmorgan.com Thu Oct 4 18:24:17 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 4 Oct 2012 22:24:17 +0000 Subject: Experimental Python-based shell In-Reply-To: References: <8646284b-df85-45fe-a793-56b081c6262c@googlegroups.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166D7158@SCACMX008.exchad.jpmchase.net> (A little quoting manipulation to make it easier to read with appropriate context.) > > On Wed, Oct 3, 2012 at 11:25 AM, Amirouche Boubekki wrote: > > > 2012/10/3 Jonathan Hayward > > > The chief benefit besides the searching, so far, is that you can use Py3k mixed with shell commands as the > > > scripting language--so script in Python instead of bash. > > > > > > When using Python for scripting, Python lines are indented by an extra tab (or four spaces) while shell-like > > > commands are not indented. So: > > > > cjsh> ? ? for index in range(10): > > > ----> echo %(index)d > > > ----> > > > 0 > > > 1 > > > 2 [snip] > > > > > Echo could (and maybe should) be a built-in, but it isn't. The output is os.system()'ed to bash, which echoes > > > based on a command that includes the value of a Python variable. The implementation is a bit crude, but it is > > reasonably powerful. > > > > > > I have other things on the agenda, like making it able to run scripts and doing fuzzy matching, but for now > > > those are the main two attractions. > > > > Is it possible to drop completly the bash syntax and use some python library (I saw it on github) that wraps > > bash commands with python functions or the other around making it possible to call python functions with a bash- > > like syntax. The syntax you are talking about seems strange. > > > > Regards, > > > > Amirouche Jonathan Hayward wrote: > I am open to suggestions and patches. I don't think the syntax strange, though: it offers a clear and distinct > way to differentiate Python and shell commands, and shell commands can access Python variables when specified. > And it is a simple rule, without footnotes needed. I need more footnotes. :) Does every shell command not have indentation? How can you tell if the shell command is supposed to be in the loop or after the loop? for index in range(10): # do something echo %(index)d Is the above equivalent to Python pseudo-code solution A or B? Solution A, for index in range(10): #do something Popen('echo', file_path) Solution B, for index in range(10): #do something Popen('echo', file_path) How do I make achieve the other solution? 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 Thu Oct 4 18:36:02 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Thu, 4 Oct 2012 22:36:02 +0000 Subject: final question: logging to stdout and updating files In-Reply-To: References: <506d967a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166D71B1@SCACMX008.exchad.jpmchase.net> Chris Angelico wrote: > Sent: Thursday, October 04, 2012 9:28 AM > To: python-list at python.org > Subject: Re: final question: logging to stdout and updating files > > On Fri, Oct 5, 2012 at 12:00 AM, Steven D'Aprano > wrote: > > That is *terrible* advice. But if you insist on following it, you can > > optimize *any* Python program to this: > > > > # === start code === > > pass # this line is optional > > # === end code === > > > > > > There you go. The most heavily optimized, fastest Python program in > > existence. Sure, it has a few bugs, but boy is it fast!!! > > Not many bugs though! I ran it in my Python 5.2.7 for GNU/Windows > 256-bit (err, yeah, I borrowed Guido's time machine but had the silly > thing in reverse... oops) and it worked perfectly, except that > indentation has moved from "significant" to "mandatory". When I added > the necessary 5 space indent at the beginning, it correctly created > world peace, ensured that Australia won the next Test Match, and then > printed "Hello, world!\n" to stdout. Unfortunately, a bug in your "end > code" comment meant that the peace it created was by wiping out all > life, but that's pretty minor in the scheme of things. Python is a product for Americans! ;) It should ensure America wins the Test Match....wait, do we even have a cricket team? > > Optimization really is that important, folks! > > ChrisA > may need to schedule surgical detongueing of his cheek Think we could get a group rate for c.l.p? Ramit 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 __peter__ at web.de Thu Oct 4 18:41:24 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Oct 2012 00:41:24 +0200 Subject: How can I hide my stack frames in a TestCase subclass? References: <52b17563-966c-46bc-bd77-da29e944c909@googlegroups.com> Message-ID: David Banks wrote: > I want to add a custom assert method to a TestCase subclass. I tried to > copy my implementation from the unittest module so that it would match > the behaviour of the regular TestCase as closely as possible. (I would > prefer to just delegate to self.assertEqual() but this causes even more > backtrace noise, see below.) The unittest module seems to automatically > hide some internal details of its implementation when reporting failed > assertions. > > import unittest > > class MyTestCase(unittest.TestCase): > def assertLengthIsOne(self, sequence, msg=None): > if len(sequence) != 1: > msg = self._formatMessage(msg, "length is not one") > raise self.failureException(msg) > > class TestFoo(MyTestCase): > seq = (1, 2, 3, 4, 5) > > def test_stock_unittest_assertion(self): > self.assertEqual(len(self.seq), 1) > > def test_custom_assertion(self): > self.assertLengthIsOne(self.seq) > > > unittest.main() > > The output of this is as such: > > amoe at vuurvlieg $ python unittest-demo.py > FF > ====================================================================== > FAIL: test_custom_assertion (__main__.TestFoo) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "unittest-demo.py", line 16, in test_custom_assertion > self.assertLengthIsOne(self.seq) > File "unittest-demo.py", line 7, in assertLengthIsOne > raise self.failureException(msg) > AssertionError: length is not one > > ====================================================================== > FAIL: test_stock_unittest_assertion (__main__.TestFoo) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "unittest-demo.py", line 13, in test_stock_unittest_assertion > self.assertEqual(len(self.seq), 1) > AssertionError: 5 != 1 > > ---------------------------------------------------------------------- > Ran 2 tests in 0.000s > > FAILED (failures=2) > > Note that the custom assert method causes a stack trace with two frames, > one inside the method itself, whereas the stock unittest method only has > one frame, the relevant line in the user's code. How can I apply this > frame-hiding behaviour to my own method? Move MyTestCase in a separate module and define a global variable __unittest = True $ cat mytestcase.py import unittest __unittest = True class MyTestCase(unittest.TestCase): def assertLengthIsOne(self, sequence, msg=None): if len(sequence) != 1: msg = self._formatMessage(msg, "length is not one") raise self.failureException(msg) $ cat mytestcase_demo.py import unittest from mytestcase import MyTestCase class TestFoo(MyTestCase): seq = (1, 2, 3, 4, 5) def test_stock_unittest_assertion(self): self.assertEqual(len(self.seq), 1) def test_custom_assertion(self): self.assertLengthIsOne(self.seq) if __name__ == "__main__": unittest.main() $ python mytestcase_demo.py FF ====================================================================== FAIL: test_custom_assertion (__main__.TestFoo) ---------------------------------------------------------------------- Traceback (most recent call last): File "mytestcase_demo.py", line 11, in test_custom_assertion self.assertLengthIsOne(self.seq) AssertionError: length is not one ====================================================================== FAIL: test_stock_unittest_assertion (__main__.TestFoo) ---------------------------------------------------------------------- Traceback (most recent call last): File "mytestcase_demo.py", line 8, in test_stock_unittest_assertion self.assertEqual(len(self.seq), 1) AssertionError: 5 != 1 ---------------------------------------------------------------------- Ran 2 tests in 0.000s FAILED (failures=2) $ From animelovin at gmail.com Thu Oct 4 19:13:51 2012 From: animelovin at gmail.com (Etienne Robillard) Date: Thu, 4 Oct 2012 19:13:51 -0400 Subject: notmm is dead! In-Reply-To: References: <20121004141046.677dac1e8bf6dada0b6af6b3@gmail.com> <20121004181157.31c1083520ff8230242962e1@gmail.com> Message-ID: <20121004191351.8c6fcfd8ddad7b6e6bfc02f2@gmail.com> Thanks, but I tried all that and don't have much energy for continuing. If you're serious about open source then maybe you can forward the thread to django-developers and get some fundings to pay for a minimalistic fee to get the project maintained by someone else, otherwise I'd prefer sticking with more profitable activities. E On Fri, 5 Oct 2012 08:23:05 +1000 Chris Angelico wrote: > On Fri, Oct 5, 2012 at 8:11 AM, Etienne Robillard wrote: > > For $399 i give you the current source code and you can do whatever you like with it, including > > putting in github or sf. i think to have lost too many time already with further > > maintaining the open source version without getting a penny out of it. > > Like I said, I'm not personally interested; but perhaps say that to > the django list and someone'll bite. But if you're really tired of it, > then just post the source code and someone may end up taking your > project to places you never had the energy to. > > > There was - and, incidentally, still kinda is - a project called Gmud, > a 32-bit (but Win32s compatible) Windows MUD client. Its author asked > people to send him money if they liked and used the program - $US20 I > think - but almost nobody ever did. For years, Gmud was the > recommended Windows client for Threshold RPG, and yet still something > like *four* people ever sent the author money. So the author threw the > source out to the world and said "I'm done, have fun". > > Enter the Threshold RPG community. Gmud has been extremely popular (in > fact, some people still use it today), in spite of some limitations > that may have been reasonable a few years ago, but are ridiculous now, > like a fixed 500-line scrollback buffer. So some of the people there > ask me to grab the source, tweak a few things, and recompile. I'm a > geek, I do these sorts of things. > > Well, it turned out to be not that simple, for a few reasons. But > eventually, after a near-complete rewrite, I produced a new MUD client > that uses the same look and feel as Gmud, as an acknowledged > derivative. RosMud++ is now the officially recommended Windows client > for Threshold, and it would never have happened if Gmud's source > hadn't been given away. > > > It's really hard to make money off software, these days. Which is a > pity, because there's lots of good software that'd be worth money. I > do see your pain. :( This is part of why my newest MUD client, Gypsum, > is open-sourced from the very beginning. > > ChrisA -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ erob at gthcfoundation.org From rosuav at gmail.com Thu Oct 4 19:25:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Oct 2012 09:25:18 +1000 Subject: notmm is dead! In-Reply-To: <20121004191351.8c6fcfd8ddad7b6e6bfc02f2@gmail.com> References: <20121004141046.677dac1e8bf6dada0b6af6b3@gmail.com> <20121004181157.31c1083520ff8230242962e1@gmail.com> <20121004191351.8c6fcfd8ddad7b6e6bfc02f2@gmail.com> Message-ID: On Fri, Oct 5, 2012 at 9:13 AM, Etienne Robillard wrote: > Thanks, but I tried all that and don't have much energy for continuing. If you're > serious about open source then maybe you can forward the thread to django-developers > and get some fundings to pay for a minimalistic fee to get the project maintained > by someone else, otherwise I'd prefer sticking with more profitable activities. Apologies to all for the non sequitur, Etienne and I were indulging in an off-list conversation. I don't mind it being public (there's nothing secret in it), but it may be a tad confusing to those who just got the tail end of that! ChrisA From steve+comp.lang.python at pearwood.info Thu Oct 4 19:37:47 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Oct 2012 23:37:47 GMT Subject: fastest data structure for retrieving objects identified by (x,y) tuple? References: <506ced38$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <506e1dcb$0$29972$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Oct 2012 18:11:28 +0200, Thomas Rachel wrote: > Am 04.10.2012 03:58 schrieb Steven D'Aprano: >> alist = [[None]*2400 for i in range(2400)] from random import randrange >> for i in range(1000): >> x = randrange(2400) >> y = randrange(2400) >> adict[(x, y)] = "something" >> alist[x][y] = "something" > >> The actual sizes printed will depend on how sparse the matrices are, >> but for the same above (approximately half full), > > I wouldn't consider 1000 of 5760000 "half full"... Doh! I obviously can't multiply... I mean, well done, that was a deliberate test to see who was paying attention, and you passed! :) -- Steven From tjreedy at udel.edu Thu Oct 4 19:47:01 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Oct 2012 19:47:01 -0400 Subject: Anybody know what's up with Gmane? In-Reply-To: <4509cf54-a71d-44cc-90a5-0abd7c6a80cd@googlegroups.com> References: <4509cf54-a71d-44cc-90a5-0abd7c6a80cd@googlegroups.com> Message-ID: <506E1FF5.7040200@udel.edu> On 10/4/2012 3:03 PM, Mark Lawrence wrote: > I read some 20 Python mailing lists through Gmane using Thunderbird > on Windows but nothing new has arrived for almost 24 hours, hence why > I've reluctantly resorted to Google groups to try and find out what > is going on. Looking directly at > http://news.gmane.org/gmane.comp.python.general shows the last post > was the Steven D'Aprano thread titled "Emulating C++ namespaces with > ChainMap and metaclass trickery" on 3 Oct at 20:26. > > I've tried flagging this up but obviously with no success. Anyone > any ideas on how to sort this out? This is the longest outage I remember, but it is back up now. I am reading and replying via gmane. -- Terry Jan Reedy From fabiofz at gmail.com Thu Oct 4 20:02:55 2012 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 4 Oct 2012 21:02:55 -0300 Subject: PyDev 2.7.0 Released Message-ID: Hi All, PyDev 2.7.0 has been released Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- * **Code formatter**: * Number of spaces before a comment can be configured (default: 2 spaces as pep-8 recommends) * Minimum number of spaces before start of comment may be configured (default: 1 space as pep-8 recommends) * Right trim lines now also properly trims comments. * When the auto-formatter is enabled, if syntax errors are present the code-formatting is not applied (it could end up getting things wrong in this situation). * Python 3.3 'yield from' syntax now properly supported. * Fixed issue when unable to get filesystem encoding when configuring interpreter. * Debugger: 'Enable Condition' checkbox in break properties dialog no longer ignored. * Fixed ClassCastException during parse in Python file with yield in global scope. * Fixed StackOverflowError in fast parser (i.e.: parser used to get only the outline of the code). * PyDev Mylyn integration can now be installed on Eclipse 4.2. * Fixed NPE when trying to add interpreter and it detected directory which we could not list() in Java. * Fixed cache issue in code-completion (nature.startRequests() could end up not having nature.endRequests() called). * Save a bit faster on big files (i.e.: No longer doing invalidateTextPresentation on each save). 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 steve+comp.lang.python at pearwood.info Thu Oct 4 20:22:06 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Oct 2012 00:22:06 GMT Subject: notmm is dead! References: Message-ID: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> On Thu, 04 Oct 2012 14:10:46 -0400, Etienne Robillard wrote: > Dear list, > > Due to lack of energy and resources i'm really sad to announce the > removal of notmm from pypi and bitbucket. Well that's just rude. Even if you don't intend to maintain the software any more, why are you removing it from pypi? Since you say you are a fan of Open Source software, just flag it as unmaintained and leave it for somebody else to pick up. If you are going to abandon the project, release it on PyPI with a dual MIT and GPL licence, and let it be taken over by somebody else. If you were looking for sympathy here, starting off by removing your project from free hosting, then complaining that you can't pay for the non-free hosting, was NOT the right way to do so. By the way, the latest version of notmm (0.4.4) has an empty licence file. No licence means that everyone using it is unlicenced and therefore infringing your copyright. -- Steven From nad at acm.org Thu Oct 4 20:32:47 2012 From: nad at acm.org (Ned Deily) Date: Thu, 04 Oct 2012 17:32:47 -0700 Subject: Anybody know what's up with Gmane? References: <4509cf54-a71d-44cc-90a5-0abd7c6a80cd@googlegroups.com> Message-ID: In article <4509cf54-a71d-44cc-90a5-0abd7c6a80cd at googlegroups.com>, Mark Lawrence wrote: > I read some 20 Python mailing lists through Gmane using Thunderbird on > Windows but nothing new has arrived for almost 24 hours, hence why I've > reluctantly resorted to Google groups to try and find out what is going on. > Looking directly at http://news.gmane.org/gmane.comp.python.general shows the > last post was the Steven D'Aprano thread titled "Emulating C++ namespaces > with ChainMap and metaclass trickery" on 3 Oct at 20:26. > > I've tried flagging this up but obviously with no success. Anyone any ideas > on how to sort this out? There were problems on one of the gmane servers. The problem was fixed as of about three hours ago and things should be returning to normal. -- Ned Deily, nad at acm.org From animelovin at gmail.com Thu Oct 4 20:38:23 2012 From: animelovin at gmail.com (Etienne Robillard) Date: Thu, 4 Oct 2012 20:38:23 -0400 Subject: notmm is dead! In-Reply-To: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: <20121004203823.5fb52a370de74f027328b07f@gmail.com> Err not exactly.. :) Firstly notmm is still ISC licensed and available from here http://gthc.org/notmm/dist/. Secondly i don't want to leave it to the hands of people without I can get a single dime for the work did, however some peoples don't seem to get this point yet.. My apologies if you feel this removal was rude anyways. Feel free to contact me again if you need further clarification or would like to take over maintainership of a branch for a minimal fee. Kind regards, Etienne On 05 Oct 2012 00:22:06 GMT Steven D'Aprano wrote: > On Thu, 04 Oct 2012 14:10:46 -0400, Etienne Robillard wrote: > > > Dear list, > > > > Due to lack of energy and resources i'm really sad to announce the > > removal of notmm from pypi and bitbucket. > > Well that's just rude. Even if you don't intend to maintain the software > any more, why are you removing it from pypi? Since you say you are a fan > of Open Source software, just flag it as unmaintained and leave it for > somebody else to pick up. > > If you are going to abandon the project, release it on PyPI with a dual > MIT and GPL licence, and let it be taken over by somebody else. > > If you were looking for sympathy here, starting off by removing your > project from free hosting, then complaining that you can't pay for the > non-free hosting, was NOT the right way to do so. > > By the way, the latest version of notmm (0.4.4) has an empty licence > file. No licence means that everyone using it is unlicenced and therefore > infringing your copyright. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ erob at gthcfoundation.org From mike20007 at gmail.com Thu Oct 4 20:40:49 2012 From: mike20007 at gmail.com (Mike) Date: Thu, 4 Oct 2012 17:40:49 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> Message-ID: <3e6de8b6-5ad5-4b29-92b4-9e957158ca5a@googlegroups.com> On Thursday, October 4, 2012 5:40:26 PM UTC-4, Dave Angel wrote: > On 10/04/2012 05:29 PM, Mike wrote: > > > I get below error > > > > > > NameError: name 'functools' is not defined > > > > > > > functools is a module in the standard library. You need to import it. > > > > import functools > > > > > > > > -- > > > > DaveA I imported functools. Now I get the below error please. Traceback (most recent call last): File "test.py", line 16, in total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) File "test.py", line 16, in total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) AttributeError: 'list' object has no attribute 'itervalues' Thanks From mike20007 at gmail.com Thu Oct 4 20:40:49 2012 From: mike20007 at gmail.com (Mike) Date: Thu, 4 Oct 2012 17:40:49 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> Message-ID: <3e6de8b6-5ad5-4b29-92b4-9e957158ca5a@googlegroups.com> On Thursday, October 4, 2012 5:40:26 PM UTC-4, Dave Angel wrote: > On 10/04/2012 05:29 PM, Mike wrote: > > > I get below error > > > > > > NameError: name 'functools' is not defined > > > > > > > functools is a module in the standard library. You need to import it. > > > > import functools > > > > > > > > -- > > > > DaveA I imported functools. Now I get the below error please. Traceback (most recent call last): File "test.py", line 16, in total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) File "test.py", line 16, in total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) AttributeError: 'list' object has no attribute 'itervalues' Thanks From ian.g.kelly at gmail.com Thu Oct 4 20:46:18 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 4 Oct 2012 18:46:18 -0600 Subject: notmm is dead! In-Reply-To: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Oct 4, 2012 at 6:22 PM, Steven D'Aprano wrote: > By the way, the latest version of notmm (0.4.4) has an empty licence > file. No licence means that everyone using it is unlicenced and therefore > infringing your copyright. It's an ISC license. The notmm-0.4.4/LICENSE file is a link to the notmm-0.4.4/notmm-0.4.4-rc7/LICENSE file, unless your archiver fails to reconstruct the link when untarring, in which case the former ends up as an empty file (but the latter is still present). From animelovin at gmail.com Thu Oct 4 20:56:43 2012 From: animelovin at gmail.com (Etienne Robillard) Date: Thu, 4 Oct 2012 20:56:43 -0400 Subject: notmm is dead! In-Reply-To: References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: <20121004205643.b92cbe656521996843cf01fe@gmail.com> You probably have a old tarball or something... $ wget http://gthc.org/dist/notmm/notmm-0.4.4.tar.gz $ md5sum notmm-0.4.4.tar.gz dff1b2ec5373b5157cf79d57169a336e notmm-0.4.4.tar.gz Cheers, Etienne On Thu, 4 Oct 2012 18:46:18 -0600 Ian Kelly wrote: > On Thu, Oct 4, 2012 at 6:22 PM, Steven D'Aprano > wrote: > > By the way, the latest version of notmm (0.4.4) has an empty licence > > file. No licence means that everyone using it is unlicenced and therefore > > infringing your copyright. > > It's an ISC license. The notmm-0.4.4/LICENSE file is a link to the > notmm-0.4.4/notmm-0.4.4-rc7/LICENSE file, unless your archiver fails > to reconstruct the link when untarring, in which case the former ends > up as an empty file (but the latter is still present). > -- > http://mail.python.org/mailman/listinfo/python-list -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ erob at gthcfoundation.org From ian.g.kelly at gmail.com Thu Oct 4 20:59:03 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 4 Oct 2012 18:59:03 -0600 Subject: sum function In-Reply-To: <3e6de8b6-5ad5-4b29-92b4-9e957158ca5a@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> <3e6de8b6-5ad5-4b29-92b4-9e957158ca5a@googlegroups.com> Message-ID: On Thu, Oct 4, 2012 at 6:40 PM, Mike wrote: > Traceback (most recent call last): > File "test.py", line 16, in > total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) > File "test.py", line 16, in > total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) > AttributeError: 'list' object has no attribute 'itervalues' "r.itervalues()" should have been "r[0].columns.itervalues()", I think. It's hard to test code against an API that you don't have. :-) From mike20007 at gmail.com Thu Oct 4 22:01:24 2012 From: mike20007 at gmail.com (Mike) Date: Thu, 4 Oct 2012 19:01:24 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> <3e6de8b6-5ad5-4b29-92b4-9e957158ca5a@googlegroups.com> Message-ID: I agree with you, Ian. Thanks for all the help. Now I get the below error. File "test.py", line 17, in total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) File "test.py", line 17, in total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) Thanks From mike20007 at gmail.com Thu Oct 4 22:01:24 2012 From: mike20007 at gmail.com (Mike) Date: Thu, 4 Oct 2012 19:01:24 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> <3e6de8b6-5ad5-4b29-92b4-9e957158ca5a@googlegroups.com> Message-ID: I agree with you, Ian. Thanks for all the help. Now I get the below error. File "test.py", line 17, in total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) File "test.py", line 17, in total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) Thanks From driscoll at cs.wisc.edu Thu Oct 4 22:25:40 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Thu, 04 Oct 2012 21:25:40 -0500 Subject: + in regular expression In-Reply-To: References: Message-ID: <506E4524.3010504@cs.wisc.edu> On 10/04/2012 04:59 PM, Mark Lawrence wrote: >> why the "\s{6}+" is not a regular pattern? >> >> >> > > > Why are you too lazy to do any research before posting a question? > Errr... what? I'm only somewhat familiar with the extra stuff that languages provide in their regexs beyond true regular expressions and simple extensions, but I was surprised to see the question because I too would have expected that to work. (And match any sequence of whitespace characters whose length is a multiple of six.) I reskimmed the documentation of the re module and didn't see anything that would prohibit it. I looked at several of the results of a Google search for the multiple repeat error, and didn't really find any explanation beyond "because you can't do it" or "here's a regex that works." (Well, OK, I did see a mention of + being a possessive quantifier which Python doesn't support. But that still doesn't explain why my expectation isn't what happened.) In what way is that an unreasonable question? Evan From torriem at gmail.com Thu Oct 4 22:39:55 2012 From: torriem at gmail.com (Michael Torrie) Date: Thu, 04 Oct 2012 20:39:55 -0600 Subject: notmm is dead! In-Reply-To: <20121004191351.8c6fcfd8ddad7b6e6bfc02f2@gmail.com> References: <20121004141046.677dac1e8bf6dada0b6af6b3@gmail.com> <20121004181157.31c1083520ff8230242962e1@gmail.com> <20121004191351.8c6fcfd8ddad7b6e6bfc02f2@gmail.com> Message-ID: <506E487B.3010704@gmail.com> On 10/04/2012 05:13 PM, Etienne Robillard wrote: > Thanks, but I tried all that and don't have much energy for continuing. If you're > serious about open source then maybe you can forward the thread to django-developers > and get some fundings to pay for a minimalistic fee to get the project maintained > by someone else, otherwise I'd prefer sticking with more profitable activities. Nothing in the existing license prevents someone from taking the latest source and posting it back on Pypi as an unmaintained package. Isn't that correct? What are you referring to when you say "minimalistic fee." Would this be a fee you require for transferring copyright assignment? I know of no fee necessary for a new maintainer to take over should one wish to. Copyright assignment is not strictly necessary. From Saroo_Jain at infosys.com Thu Oct 4 23:44:25 2012 From: Saroo_Jain at infosys.com (Saroo Jain) Date: Fri, 5 Oct 2012 03:44:25 +0000 Subject: + in regular expression In-Reply-To: References: Message-ID: <9824145E4C0B6C4A94BEF7CE7692E808199E4064@BLRKECMBX22.ad.infosys.com> x3=re.match("\s{6}+",str) instead use x3=re.match("\s{6,}",str) This serves the purpose. And also give some food for thought for why the first one throws an error. Cheers, Saroo -----Original Message----- From: Python-list [mailto:python-list-bounces+saroo_jain=infosys.com at python.org] On Behalf Of Mark Lawrence Sent: Friday, October 05, 2012 3:29 AM To: python-list at python.org Subject: Re: + in regular expression On 04/10/2012 04:01, contro opinion wrote: >>>> str=" gg" >>>> x1=re.match("\s+",str) >>>> x1 > <_sre.SRE_Match object at 0xb7354db0> >>>> x2=re.match("\s{6}",str) >>>> x2 > <_sre.SRE_Match object at 0xb7337f38> >>>> x3=re.match("\s{6}+",str) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/re.py", line 137, in match > return _compile(pattern, flags).match(string) > File "/usr/lib/python2.6/re.py", line 245, in _compile > raise error, v # invalid expression > sre_constants.error: multiple repeat >>>> > > why the "\s{6}+" is not a regular pattern? > > > Why are you too lazy to do any research before posting a question? -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list **************** CAUTION - Disclaimer ***************** This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system. ***INFOSYS******** End of Disclaimer ********INFOSYS*** From tjreedy at udel.edu Fri Oct 5 00:12:02 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Oct 2012 00:12:02 -0400 Subject: Experimental Python-based shell In-Reply-To: References: <8646284b-df85-45fe-a793-56b081c6262c@googlegroups.com> Message-ID: On 10/3/2012 4:22 PM, Terry Reedy wrote: > Indexing Python code is ugly. I suggest prefixing non-Python with $. Indenting, meaning indenting the Python header lines but not non-Python lines. > On 10/3/2012 1:24 PM, Jonathan Hayward wrote: >> I am open to suggestions and patches. I don't think the syntax strange, >> though: it offers a clear and distinct way to differentiate Python and >> shell commands, and shell commands can access Python variables when >> specified. And it is a simple rule, without footnotes needed. > -- Terry Jan Reedy From deron.meranda at gmail.com Fri Oct 5 00:13:17 2012 From: deron.meranda at gmail.com (Deron Meranda) Date: Thu, 4 Oct 2012 21:13:17 -0700 (PDT) Subject: Embedded Python 3 porting issues when passing FILE* to PyRun_SimpleFile() in Windows mixed-compiler environment Message-ID: Hi. I'm trying to convert a large C application that embeds Python so it works with Python 3, and am running into an new API limitation I can't solve. I have a report from Windows users that there is a crashing problem occurring with calls to PyRun_SimpleFile (and similar functions). This appears to happen when people are using a Python DLL compiled with one compiler (e.g., MicroSoft's) and the application with another compiler (e.g., MinGW/gcc). The basic problem is that C type (FILE*) is not defined by the Windows OS, but instead is specific to the compiler and its associated runtime-environment. So therefore it is not safe to pass a FILE* across DLL boundaries. However many of the Python C API functions only accept a FILE*. Under Python 2 a work-around was used by calling the PyFile_FromString() then PyFile_AsFile(), to effectively get the underlying fopen() to occur inside the Python DLL so that an incompatible FILE* is not passed across the DLL boundary. However many of those PyFile functions, including PyFile_FromFile(), were removed from the Python 3 API. So how can one safely call PyRun_SimpleFile() in Python 3 in Windows where different compilers could be used? Thanks -- Deron Meranda http://deron.meranda.us/ From ian.g.kelly at gmail.com Fri Oct 5 01:14:13 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 4 Oct 2012 23:14:13 -0600 Subject: + in regular expression In-Reply-To: <9824145E4C0B6C4A94BEF7CE7692E808199E4064@BLRKECMBX22.ad.infosys.com> References: <9824145E4C0B6C4A94BEF7CE7692E808199E4064@BLRKECMBX22.ad.infosys.com> Message-ID: On Thu, Oct 4, 2012 at 9:44 PM, Saroo Jain wrote: > x3=re.match("\s{6}+",str) > > instead use > x3=re.match("\s{6,}",str) > > This serves the purpose. And also give some food for thought for why the first one throws an error. That matches six or more spaces, not multiples of six spaces. From cs at zip.com.au Fri Oct 5 01:22:28 2012 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 5 Oct 2012 15:22:28 +1000 Subject: + in regular expression In-Reply-To: References: Message-ID: <20121005052228.GA19273@cskk.homeip.net> On 03Oct2012 21:17, Ian Kelly wrote: | On Wed, Oct 3, 2012 at 9:01 PM, contro opinion wrote: | > why the "\s{6}+" is not a regular pattern? | | Use a group: "(?:\s{6})+" Yeah, it is probably a precedence issue in the grammar. "(\s{6})+" is also accepted. -- Cameron Simpson Disclaimer: ERIM wanted to share my opinions, but I wouldn't let them. - David Wiseman From mpg at elzevir.fr Fri Oct 5 02:28:22 2012 From: mpg at elzevir.fr (Manuel =?iso-8859-1?q?P=E9gouri=E9-Gonnard?=) Date: Fri, 5 Oct 2012 08:28:22 +0200 (CEST) Subject: How can I hide my stack frames in a TestCase subclass? References: <52b17563-966c-46bc-bd77-da29e944c909@googlegroups.com> Message-ID: Peter Otten scripsit : > David Banks wrote: > >> Note that the custom assert method causes a stack trace with two frames, >> one inside the method itself, whereas the stock unittest method only has >> one frame, the relevant line in the user's code. How can I apply this >> frame-hiding behaviour to my own method? > > Move MyTestCase in a separate module and define a global variable > > __unittest = True > Hum, is it documented somewhere? I can't find it in the doc. Also, I'm curious to know what kind of magic it's using. -- Manuel P?gouri?-Gonnard - http://people.math.jussieu.fr/~mpg/ From justmailharsh at gmail.com Fri Oct 5 03:20:35 2012 From: justmailharsh at gmail.com (justmailharsh at gmail.com) Date: Fri, 5 Oct 2012 00:20:35 -0700 (PDT) Subject: Reading properties file in Python, except using ConfigParser() Message-ID: Hi All, How to read properties file in Python? I found ConfigParser() but it has a 'section' limitation, so looking for other alternatives. Thanks, Harsh From shivakrshn49 at gmail.com Fri Oct 5 04:03:56 2012 From: shivakrshn49 at gmail.com (shivakrshn49 at gmail.com) Date: Fri, 5 Oct 2012 01:03:56 -0700 (PDT) Subject: How to create a login screen using core python language without using any framework Message-ID: <97fa2804-adda-428f-a78a-d9ab3e22e965@googlegroups.com> I need to develop a simple login page using Python language with two fields and a button, like: Username, Password, Login I know there are some beautiful Python frameworks like Django, Grok, WebPy, TurboGears which support web development using Python, but mine is a basic requirement consisting of only 3 screens (pages): * 1st page - Login page (Redirects to 2nd page when login button is clicked) * 2nd page - Page with records in the form of a list, with an option for adding new records (Redirects to 3rd page when "Add Records" button is clicked) * 3rd page - Page with fields, which are saved as records for the list on 2nd page (After entering details and clicking Submit) So, I have decided to develop the above functionality using Python **without** using any framework, so that I can have flexibility as well as write my own code. 1. Is it possible to create a login page using Python without using a framework? 2. I haven't worked on web services and don't know the basics of web development in Python. 3. If possible, can you provide me an example on how to create a login page using Python and achieve the functionality described above? From gandalf at shopzeus.com Fri Oct 5 04:06:58 2012 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 05 Oct 2012 10:06:58 +0200 Subject: Reading properties file in Python, except using ConfigParser() In-Reply-To: References: Message-ID: <506E9522.10304@shopzeus.com> On 2012-10-05 09:20, justmailharsh at gmail.com wrote: > Hi All, > > How to read properties file in Python? I found ConfigParser() but it has a 'section' limitation, so looking for other alternatives. http://wiki.python.org/moin/ConfigParserShootout From breamoreboy at yahoo.co.uk Fri Oct 5 04:11:22 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 05 Oct 2012 09:11:22 +0100 Subject: final question: logging to stdout and updating files In-Reply-To: References: <506d967a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/10/2012 15:27, Chris Angelico wrote: > ensured that Australia won the next Test Match > > ChrisA > may need to schedule surgical detongueing of his cheek > I'll arrange the cheek detonguing very cheaply after a comment like that :) -- Cheers. Mark Lawrence. From __peter__ at web.de Fri Oct 5 04:12:54 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Oct 2012 10:12:54 +0200 Subject: How can I hide my stack frames in a TestCase subclass? References: <52b17563-966c-46bc-bd77-da29e944c909@googlegroups.com> Message-ID: Manuel P?gouri?-Gonnard wrote: > Peter Otten scripsit : > >> David Banks wrote: >> >>> Note that the custom assert method causes a stack trace with two frames, >>> one inside the method itself, whereas the stock unittest method only has >>> one frame, the relevant line in the user's code. How can I apply this >>> frame-hiding behaviour to my own method? >> >> Move MyTestCase in a separate module and define a global variable >> >> __unittest = True >> > Hum, is it documented somewhere? I can't find it in the doc. Also, I'm > curious to know what kind of magic it's using. I took advantage of the fact that Python is open source and had a look into the source code ;) $ cd /usr/lib/python2.7/unittest $ grep frame *.py -C2 ... result.py- result.py- def _is_relevant_tb_level(self, tb): result.py: return '__unittest' in tb.tb_frame.f_globals result.py- ... $ grep _is_relevant_tb_level *.py -C5 result.py- result.py- def _exc_info_to_string(self, err, test): result.py- """Converts a sys.exc_info()-style tuple of values into a string.""" result.py- exctype, value, tb = err result.py- # Skip test runner traceback levels result.py: while tb and self._is_relevant_tb_level(tb): result.py- tb = tb.tb_next result.py- ... And so on. I actually used an editor, not grep -- but you get the idea. From sahnov.m at gmail.com Fri Oct 5 04:13:30 2012 From: sahnov.m at gmail.com (=?KOI8-R?B?88HIzs/XIO3JyMHJzA==?=) Date: Fri, 5 Oct 2012 12:13:30 +0400 Subject: How to create a login screen using core python language without using any framework In-Reply-To: <97fa2804-adda-428f-a78a-d9ab3e22e965@googlegroups.com> References: <97fa2804-adda-428f-a78a-d9ab3e22e965@googlegroups.com> Message-ID: Hi, you can write a simple wsgi app for that, and run it through simple server, for example. http://docs.python.org/library/wsgiref.html 05.10.2012 12:06 ???????????? ???????: > I need to develop a simple login page using Python language with two > fields and a button, like: > > Username, Password, Login > > I know there are some beautiful Python frameworks like > > Django, Grok, WebPy, TurboGears > > which support web development using Python, but mine is a basic > requirement consisting of only 3 screens (pages): > > * 1st page - Login page (Redirects to 2nd page when login button is > clicked) > * 2nd page - Page with records in the form of a list, with an option for > adding new records (Redirects to 3rd page when "Add Records" button is > clicked) > * 3rd page - Page with fields, which are saved as records for the list > on 2nd page (After entering details and clicking Submit) > > So, I have decided to develop the above functionality using Python > **without** using any framework, so that I can have flexibility as well as > write my own code. > > 1. Is it possible to create a login page using Python without using a > framework? > > 2. I haven't worked on web services and don't know the basics of web > development in Python. > > 3. If possible, can you provide me an example on how to create a login > page using Python and achieve the functionality described above? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Fri Oct 5 04:19:31 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 05 Oct 2012 09:19:31 +0100 Subject: final question: logging to stdout and updating files In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474166D71B1@SCACMX008.exchad.jpmchase.net> References: <506d967a$0$29978$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF474166D71B1@SCACMX008.exchad.jpmchase.net> Message-ID: On 04/10/2012 23:36, Prasad, Ramit wrote: > > Python is a product for Americans! ;) It should ensure America > wins the Test Match....wait, do we even have a cricket team? ChrisA could have been talking rugby, your rugby union team isn't't too bad for a bunch of amateurs, some of whom had to take unpaid leave to play in the world cup. I don't think there's any rugby league sides in the USA. Then there's speedway and...? > >> >> Optimization really is that important, folks! >> >> ChrisA >> may need to schedule surgical detongueing of his cheek > > Think we could get a group rate for c.l.p? I'm sure that with some appropriate grovelling the PSF could arrange this. Perhaps fly everybody to the UK for PyCon and get the surgery done on the NHS at the same time. > > Ramit > -- Cheers. Mark Lawrence. From ashishjain.ash at gmail.com Fri Oct 5 04:20:28 2012 From: ashishjain.ash at gmail.com (ashishjain.ash at gmail.com) Date: Fri, 5 Oct 2012 01:20:28 -0700 (PDT) Subject: How to print html in python the normal way In-Reply-To: References: <4d096ff3-e25f-400e-89c6-47483aaacc0d@googlegroups.com> Message-ID: <744677a5-8f47-4b03-b15f-2b3db6f0642d@googlegroups.com> Hi, Thanks for the reply. Apologies for my question not clear. Yes I am using django framework for it. - Regards Ashish From ashishjain.ash at gmail.com Fri Oct 5 04:20:28 2012 From: ashishjain.ash at gmail.com (ashishjain.ash at gmail.com) Date: Fri, 5 Oct 2012 01:20:28 -0700 (PDT) Subject: How to print html in python the normal way In-Reply-To: References: <4d096ff3-e25f-400e-89c6-47483aaacc0d@googlegroups.com> Message-ID: <744677a5-8f47-4b03-b15f-2b3db6f0642d@googlegroups.com> Hi, Thanks for the reply. Apologies for my question not clear. Yes I am using django framework for it. - Regards Ashish From maniandram01 at gmail.com Fri Oct 5 04:29:02 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 5 Oct 2012 01:29:02 -0700 (PDT) Subject: notmm is dead! In-Reply-To: References: Message-ID: <383e8919-d40d-4913-9474-f65a3a63ba8c@googlegroups.com> On Thursday, 4 October 2012 23:40:47 UTC+5:30, Etienne Robillard wrote: > Dear list, > > > > Due to lack of energy and resources i'm really sad to announce the removal of notmm from pypi and bitbucket. I deleted > > also my account from bitbucket as it was not really useful for me. notmm will continue to be accessible from my master > > site at http://gthc.org/dist/notmm until the server get down, as I cannot find money to pay for the hosting of notmm.org, Can't you use Google Code? > > neither anyone to encourage the project so it can grow further. > > > > I have tried to develop a coherent extension for Django using the open source model but I'm afraid to have been > > bitten by its failure to encourage a free market over one dictated by profit and the use of cheap tricks to compete unfairly > > with perhaps too much openness. I always will also continue to love and use free softwares but sadly it seems asking for a little > > fairness is too much asked to competitors dedicated in stealing and subverting my work for their own advantages... > > > > I therefore refuse to continue any longer being mocked by competitors asking excessive prices for having a broken Internet dictated by > > a few companies and decide the content I should be visiting. > > > > Shall you have anything you wish saying I'll be open to discuss further on this list. I wish also to thanks the supporters > > of the project who have invested time and energy into my business and dedication to the notmm project. > > > > Best wishes, > > > > Etienne > > > > -- > > Etienne Robillard > > Green Tea Hackers Club > > Fine Software Carpentry For The Rest Of Us! > > http://gthc.org/ > > erob at gthcfoundation.org > > > > "If a free society cannot help the many who are poor, it cannot save the few who are rich." -John F. Kennedy From maniandram01 at gmail.com Fri Oct 5 04:31:29 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 5 Oct 2012 01:31:29 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> <3e6de8b6-5ad5-4b29-92b4-9e957158ca5a@googlegroups.com> Message-ID: On Friday, 5 October 2012 07:31:24 UTC+5:30, Mike wrote: > I agree with you, Ian. Thanks for all the help. Now I get the below error. > > > > File "test.py", line 17, in > > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) > > File "test.py", line 17, in > > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) > > > > Thanks You have missed the last line of the traceback (error) From maniandram01 at gmail.com Fri Oct 5 04:31:29 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 5 Oct 2012 01:31:29 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com> <3e6de8b6-5ad5-4b29-92b4-9e957158ca5a@googlegroups.com> Message-ID: On Friday, 5 October 2012 07:31:24 UTC+5:30, Mike wrote: > I agree with you, Ian. Thanks for all the help. Now I get the below error. > > > > File "test.py", line 17, in > > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) > > File "test.py", line 17, in > > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) > > > > Thanks You have missed the last line of the traceback (error) From mpg at elzevir.fr Fri Oct 5 04:50:45 2012 From: mpg at elzevir.fr (Manuel =?iso-8859-1?q?P=E9gouri=E9-Gonnard?=) Date: Fri, 5 Oct 2012 10:50:45 +0200 (CEST) Subject: How can I hide my stack frames in a TestCase subclass? References: <52b17563-966c-46bc-bd77-da29e944c909@googlegroups.com> Message-ID: Peter Otten scripsit : > Manuel P?gouri?-Gonnard wrote: > >> Peter Otten scripsit : >> >>> __unittest = True >>> >> Hum, is it documented somewhere? I can't find it in the doc. Also, I'm >> curious to know what kind of magic it's using. > > I took advantage of the fact that Python is open source and had a look into > the source code ;) > Fair enough. However, there was an implied question in the "documented" part: can we rely on it? Isn't it considered an implementation detail (names starting with underscores)? > $ cd /usr/lib/python2.7/unittest > $ grep frame *.py -C2 > ... > result.py- > result.py- def _is_relevant_tb_level(self, tb): > result.py: return '__unittest' in tb.tb_frame.f_globals > result.py- > ... > > $ grep _is_relevant_tb_level *.py -C5 > result.py- > result.py- def _exc_info_to_string(self, err, test): > result.py- """Converts a sys.exc_info()-style tuple of values into a > string.""" > result.py- exctype, value, tb = err > result.py- # Skip test runner traceback levels > result.py: while tb and self._is_relevant_tb_level(tb): > result.py- tb = tb.tb_next > result.py- > ... > > And so on. I actually used an editor, not grep -- but you get the idea. Sure, thanks. -- Manuel P?gouri?-Gonnard - http://people.math.jussieu.fr/~mpg/ From sanluca78 at gmail.com Fri Oct 5 04:51:42 2012 From: sanluca78 at gmail.com (Luca Sanna) Date: Fri, 5 Oct 2012 01:51:42 -0700 (PDT) Subject: error bluetooth Message-ID: <05fbbc10-241d-4976-a571-afbf5ac2c872@googlegroups.com> the code is output the error of the ubuntu from bluetooth import * target_name = "My Phone" target_address = None nearby_devices = discover_devices() for address in nearby_devices: if target_name == lookup_name( address ): target_address = address break if target_address is not None: print "found target bluetooth device with address", target_address else: print "could not find target bluetooth device nearby" the error luca at luca-XPS-M1330:~/py-temperature/py-temperature$ python bluetooth.py Traceback (most recent call last): File "bluetooth.py", line 14, in from bluetooth import * File "/home/luca/py-temperature/py-temperature/bluetooth.py", line 19, in nearby_devices = discover_devices() NameError: name 'discover_devices' is not defined luca at luca-XPS-M1330:~/py-temperature/py-temperature$ it's a bug of the module? thanks From duncan.booth at invalid.invalid Fri Oct 5 05:23:26 2012 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Oct 2012 09:23:26 GMT Subject: + in regular expression References: Message-ID: Cameron Simpson wrote: > On 03Oct2012 21:17, Ian Kelly wrote: >| On Wed, Oct 3, 2012 at 9:01 PM, contro opinion >| wrote: >| > why the "\s{6}+" is not a regular pattern? >| >| Use a group: "(?:\s{6})+" > > Yeah, it is probably a precedence issue in the grammar. > "(\s{6})+" is also accepted. It's about syntax, not precedence, but the documentation doesn't really spell it out in full. Like most regex documentation it talks in woolly terms about special characters rather than giving a formal syntax. A regular expression element may be followed by a quantifier. Quantifiers are '*', '+', '?', '{n}', '{n,m}' (and lazy quantifiers '*?', '+?', '{n,m}?'). There's nothing in the regex language which says you can follow an element with two quantifiers. Parentheses (grouping or non-grouping) around a regex turn that regex into a single element which is why you can then use another quantifier. In bnf, I think Python's regexes would be somthing like: re ::= union | simple-re union ::= re | simple-re simple-re ::= concatenation | basic-re concatenation ::= simple-re basic-re basic-re ::= element | element quantifier element ::= group | nc-group | "." | "^" | "$" | char | charset quantifier = "*" | "+" | "?" | "{" NUMBER "}" | "{" NUMBER "," NUMBER "}" |"*?" | "+?" | "{" NUMBER "," NUMBER "}?" group ::= "(" re ")" nc-group ::= "(?:" re ")" char = | "\" ... and so on. I didn't include charsets or all the (?...) extensions or special sequences. -- Duncan Booth http://kupuguy.blogspot.com From __peter__ at web.de Fri Oct 5 05:26:47 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Oct 2012 11:26:47 +0200 Subject: How can I hide my stack frames in a TestCase subclass? References: <52b17563-966c-46bc-bd77-da29e944c909@googlegroups.com> Message-ID: Manuel P?gouri?-Gonnard wrote: > However, there was an implied question in the "documented" part: can > we rely on it? Isn't it considered an implementation detail (names > starting with underscores)? "Not documented" was my implied answer. I think you have a valid use case, though, so you could make a feature request for an official way to hide stack frames on the bugtracker http://bugs.python.org or the python-ideas mailing list. From hansmu at xs4all.nl Fri Oct 5 05:29:09 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 05 Oct 2012 11:29:09 +0200 Subject: How to create a login screen using core python language without using any framework In-Reply-To: <97fa2804-adda-428f-a78a-d9ab3e22e965@googlegroups.com> References: <97fa2804-adda-428f-a78a-d9ab3e22e965@googlegroups.com> Message-ID: <506ea86d$0$6969$e4fe514c@news2.news.xs4all.nl> On 5/10/12 10:03:56, shivakrshn49 at gmail.com wrote: > I need to develop a simple login page using Python language with > two fields and a button, like: > > Username, Password, Login > > I know there are some beautiful Python frameworks like > > Django, Grok, WebPy, TurboGears > > which support web development using Python, but mine is a basic > requirement consisting of only 3 screens (pages): > > * 1st page - Login page (Redirects to 2nd page when login button > is clicked) > * 2nd page - Page with records in the form of a list, with an > option for adding new records (Redirects to 3rd page when "Add > Records" button is clicked) > * 3rd page - Page with fields, which are saved as records for > the list on 2nd page (After entering details and clicking Submit) Implementing your application using any of those frameworks you mentioned, would be easy. > So, I have decided to develop the above functionality using Python > **without** using any framework, so that I can have flexibility as > well as write my own code. This is a bad idea. You'll get much more flexibility using an existing framework then you'd ever achieve by reinventing the wheel on your own. Especially if you have no experience in this field. > 1. Is it possible to create a login page using Python without > using a framework? Yes. But it's a lot of work. You'd effectively be rewriting all the functionality you'd get for free with a framework. And it wouldn't be as flexible, because frameworks can flex in directions that you didn't think of. > 2. I haven't worked on web services and don't know the basics of > web development in Python. In that case, your chances of success are fairly slim. > 3. If possible, can you provide me an example on how to create a > login page using Python and achieve the functionality described > above? The frameworks you mentioned earlier come with tutorials. These tutorials contain such examples. You should really use an existing framework. Once you're aware of how much functionality you get out of a framework (any of them), you wouldn't dream of rewriting all that functionality on your own. Hope this helps, -- HansM From ulrich.eckhardt at dominolaser.com Fri Oct 5 06:03:38 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 05 Oct 2012 12:03:38 +0200 Subject: error bluetooth In-Reply-To: <05fbbc10-241d-4976-a571-afbf5ac2c872@googlegroups.com> References: <05fbbc10-241d-4976-a571-afbf5ac2c872@googlegroups.com> Message-ID: Am 05.10.2012 10:51, schrieb Luca Sanna: > the code is output the error of the ubuntu > > from bluetooth import * > [...] > > nearby_devices = discover_devices() > [...] > > the error > > luca at luca-XPS-M1330:~/py-temperature/py-temperature$ python bluetooth.py > Traceback (most recent call last): > File "bluetooth.py", line 14, in > from bluetooth import * > File "/home/luca/py-temperature/py-temperature/bluetooth.py", line 19, in > nearby_devices = discover_devices() > NameError: name 'discover_devices' is not defined The module "bluetooth" doesn't export any function called discover_devices(). You could try "dir(bluetooth)" or "help(bluetooth)" (do that from an interactive prompt) to find out what is in there. I don't know why you expect such a function there, if it is mentioned in the documentation or example code that would be a bug. Uli From d at davea.name Fri Oct 5 06:33:18 2012 From: d at davea.name (Dave Angel) Date: Fri, 05 Oct 2012 06:33:18 -0400 Subject: error bluetooth In-Reply-To: <05fbbc10-241d-4976-a571-afbf5ac2c872@googlegroups.com> References: <05fbbc10-241d-4976-a571-afbf5ac2c872@googlegroups.com> Message-ID: <506EB76E.1090308@davea.name> On 10/05/2012 04:51 AM, Luca Sanna wrote: > the code is output the error of the ubuntu > > from bluetooth import * > > target_name = "My Phone" > target_address = None > > nearby_devices = discover_devices() > > for address in nearby_devices: > if target_name == lookup_name( address ): > target_address = address > break > > if target_address is not None: > print "found target bluetooth device with address", target_address > else: > print "could not find target bluetooth device nearby" > > the error > > luca at luca-XPS-M1330:~/py-temperature/py-temperature$ python bluetooth.py > Traceback (most recent call last): > File "bluetooth.py", line 14, in > from bluetooth import * > File "/home/luca/py-temperature/py-temperature/bluetooth.py", line 19, in > nearby_devices = discover_devices() > NameError: name 'discover_devices' is not defined > luca at luca-XPS-M1330:~/py-temperature/py-temperature$ > > it's a bug of the module? thanks Perhaps you named your script bluetooth.py, and thus masked the module bluetooth.py. Pick a different name for your own sources. -- DaveA From animelovin at gmail.com Fri Oct 5 06:43:47 2012 From: animelovin at gmail.com (Etienne Robillard) Date: Fri, 5 Oct 2012 06:43:47 -0400 Subject: notmm is dead! In-Reply-To: <506E487B.3010704@gmail.com> References: <20121004141046.677dac1e8bf6dada0b6af6b3@gmail.com> <20121004181157.31c1083520ff8230242962e1@gmail.com> <20121004191351.8c6fcfd8ddad7b6e6bfc02f2@gmail.com> <506E487B.3010704@gmail.com> Message-ID: <20121005064347.10aa9146cc3c053b14dbeaca@gmail.com> No. All past notmm licenses were and still ARE ISC licensed. The license fee is simply because I'm shifting into commercial license for new releases, including the newer 0.4.5 version... Pypi was not the authority source for notmm and neither anyone can claim the license was left blank, thats once again a form of plagiarism. Shall anyone is really serious about supporting the work i did then he'll want to pay a minimal fee to get the proper license rights and can contact me off-list if he want to fork a branch to github of google code. Thanks, Etienne On Thu, 04 Oct 2012 20:39:55 -0600 Michael Torrie wrote: > On 10/04/2012 05:13 PM, Etienne Robillard wrote: > > Thanks, but I tried all that and don't have much energy for continuing. If you're > > serious about open source then maybe you can forward the thread to django-developers > > and get some fundings to pay for a minimalistic fee to get the project maintained > > by someone else, otherwise I'd prefer sticking with more profitable activities. > > Nothing in the existing license prevents someone from taking the latest > source and posting it back on Pypi as an unmaintained package. Isn't > that correct? > > What are you referring to when you say "minimalistic fee." Would this > be a fee you require for transferring copyright assignment? I know of > no fee necessary for a new maintainer to take over should one wish to. > Copyright assignment is not strictly necessary. > > -- > http://mail.python.org/mailman/listinfo/python-list -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ erob at gthcfoundation.org From i.hudooku at gmail.com Fri Oct 5 07:03:52 2012 From: i.hudooku at gmail.com (The Matchmaker) Date: Fri, 5 Oct 2012 04:03:52 -0700 (PDT) Subject: When was the last time you did something for the first time? Message-ID: What do you want to talk about today? From animelovin at gmail.com Fri Oct 5 07:08:59 2012 From: animelovin at gmail.com (Etienne Robillard) Date: Fri, 5 Oct 2012 07:08:59 -0400 Subject: When was the last time you did something for the first time? In-Reply-To: References: Message-ID: <20121005070859.77f9c3b9840edaf58aea3a15@gmail.com> Micro$oft :) On Fri, 5 Oct 2012 04:03:52 -0700 (PDT) The Matchmaker wrote: > What do you want to talk about today? > -- > http://mail.python.org/mailman/listinfo/python-list -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ erob at gthcfoundation.org From gd.usenet at spamfence.net Fri Oct 5 07:32:10 2012 From: gd.usenet at spamfence.net (=?ISO-8859-1?Q?G=FCnther?= Dietrich) Date: Fri, 05 Oct 2012 13:32:10 +0200 Subject: Reading properties file in Python, except using ConfigParser() References: Message-ID: justmailharsh at gmail.com wrote: >How to read properties file in Python? I found ConfigParser() but it has a >'section' limitation, so looking for other alternatives. Have a look at PyYAML. Best regards, G?nther From hansmu at xs4all.nl Fri Oct 5 07:32:49 2012 From: hansmu at xs4all.nl (Hans Mulder) Date: Fri, 05 Oct 2012 13:32:49 +0200 Subject: error bluetooth In-Reply-To: <05fbbc10-241d-4976-a571-afbf5ac2c872@googlegroups.com> References: <05fbbc10-241d-4976-a571-afbf5ac2c872@googlegroups.com> Message-ID: <506ec562$0$6942$e4fe514c@news2.news.xs4all.nl> On 5/10/12 10:51:42, Luca Sanna wrote: > from bluetooth import * [......] > luca at luca-XPS-M1330:~/py-temperature/py-temperature$ python bluetooth.py When you say "from bluetooth import *", Python will find a file name "bluetooth.py" and import stuff from that file. Since your script happens to be named "bluetooth.py", Python will import your script, thinking it is a module. > it's a bug of the module? You've chosen the wrong file name. Rename your script. Hope this helps, -- HansM From sanluca78 at gmail.com Fri Oct 5 08:03:00 2012 From: sanluca78 at gmail.com (Luca Sanna) Date: Fri, 5 Oct 2012 05:03:00 -0700 (PDT) Subject: error bluetooth In-Reply-To: <506ec562$0$6942$e4fe514c@news2.news.xs4all.nl> References: <05fbbc10-241d-4976-a571-afbf5ac2c872@googlegroups.com> <506ec562$0$6942$e4fe514c@news2.news.xs4all.nl> Message-ID: <289b78fd-6015-4c66-9967-37727120a440@googlegroups.com> Il giorno venerd? 5 ottobre 2012 13:33:14 UTC+2, Hans Mulder ha scritto: > On 5/10/12 10:51:42, Luca Sanna wrote: > > > > > from bluetooth import * > > > > [......] > > > > > luca at luca-XPS-M1330:~/py-temperature/py-temperature$ python bluetooth.py > > > > When you say "from bluetooth import *", Python will find a file > > name "bluetooth.py" and import stuff from that file. Since your > > script happens to be named "bluetooth.py", Python will import > > your script, thinking it is a module. > > > > > it's a bug of the module? > > > > You've chosen the wrong file name. Rename your script. > > > > > > Hope this helps, > > > > -- HansM i'm sorry, it's ok the rename file in bt.py how do I send a ping in bluetooth? because android phones are not always visible. I can not find the ping command thanks From eldiener at tropicsoft.invalid Fri Oct 5 08:06:41 2012 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Fri, 05 Oct 2012 08:06:41 -0400 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: Message-ID: On 10/1/2012 1:32 PM, Dennis Lee Bieber wrote: > On Sun, 30 Sep 2012 23:06:04 -0400, Edward Diener > declaimed the following in > gmane.comp.python.general: > > >> My thought is a program distributed by Python which finds the versions >> of Python on an OS, lets the end-user choose which version should be >> invoked when Python is invoked, and does whatever is necessary to make >> that version the default version. >> > Which wouldn't be usable on any system that has to boot/process > unattended, and run's Python scripts for configuration set-up. I can understand that but my use of Python on Windows is not that case. I simply want to be able to choose which version of Python runs when it is invoked, when I have multiple versions installed. Surely that is a very common case for end-users running 'python' or invoking some script which is associated with python. > > Making a version "default" pretty much means being able to rewrite > the PATH environment variable... And I've seen too many messes made by > some software already (including once having two generations of Python > showing up in one PATH!) The PATH environment is constantly changing whether in Linux or Windows. Claiming that this is too dangerous" is silly. From eldiener at tropicsoft.invalid Fri Oct 5 08:15:30 2012 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Fri, 05 Oct 2012 08:15:30 -0400 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: Message-ID: On 10/1/2012 12:02 PM, Alister wrote: > On Sun, 30 Sep 2012 15:14:17 -0400, Edward Diener wrote: > >> Has there been any official software that allows both the Python 2.x and >> 3.x releases to coexist on the same OS so that the end-user can easily >> switch between them when invoking Python scripts after each has been >> installed to their own directories/folders ? >> >> I know of some unoffical solutions, but they require lots of tweaks. >> Given the vagaries of the different OSs on which Python can run I am >> hoping for some offical solution which will work on any of the most >> popular OSs ( Windows, Linux, Mac ). >> >> The situation is so confusing on Windows, where the file associations, >> registry entries, and other internal software which allows a given >> Python release to work properly when invoking Python is so complicated, >> that I have given up on trying to install more than one Python release >> and finding a relaible, foolproof way of switching between them. So >> although I would like to use the latest 3.x series on Windows I have >> decide to stick with the latest 2.x series instead because much software >> using Python does not support 3.x yet. > > on my fedora system it was a simple matter of:- > #> yum install python3 > > to use python 3 i specify it in my shebang line > > #!/usr/bun/env python3 > > Simple > > Not sure about Windoze though (Although from memory the install asks > where to install so should not be a major issue) Windows installs of Python do not distinguish releases by Pythonx(.x) but just install different versions of Python in different directories. However one can make links to the different versions based on their release numbers, and that would allow a shebang line work if it was supported. From eldiener at tropicsoft.invalid Fri Oct 5 08:16:36 2012 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Fri, 05 Oct 2012 08:16:36 -0400 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: Message-ID: On 9/30/2012 3:38 PM, Andrew Berg wrote: > On 2012.09.30 14:14, Edward Diener wrote: >> The situation is so confusing on Windows, where the file associations, >> registry entries, and other internal software which allows a given >> Python release to work properly when invoking Python is so complicated, >> that I have given up on trying to install more than one Python release >> and finding a relaible, foolproof way of switching between them. So >> although I would like to use the latest 3.x series on Windows I have >> decide to stick with the latest 2.x series instead because much software >> using Python does not support 3.x yet. > > http://www.python.org/dev/peps/pep-0397/ > > Unix-based OSes should already obey the shebang line, and on Windows, > there's py.exe in 3.3 that will launch the intended version based on > that shebang line. While I was using the alpha/beta versions of 3.3, I > had no problems invoking either 3.2 or 3.3 with the shebang line on Windows. > Thanks ! I will get this and hopefully it will do what I want. From breamoreboy at yahoo.co.uk Fri Oct 5 08:29:13 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 05 Oct 2012 13:29:13 +0100 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: Message-ID: On 05/10/2012 13:15, Edward Diener wrote: > On 10/1/2012 12:02 PM, Alister wrote: >> On Sun, 30 Sep 2012 15:14:17 -0400, Edward Diener wrote: >> >>> Has there been any official software that allows both the Python 2.x and >>> 3.x releases to coexist on the same OS so that the end-user can easily >>> switch between them when invoking Python scripts after each has been >>> installed to their own directories/folders ? >>> >>> I know of some unoffical solutions, but they require lots of tweaks. >>> Given the vagaries of the different OSs on which Python can run I am >>> hoping for some offical solution which will work on any of the most >>> popular OSs ( Windows, Linux, Mac ). >>> >>> The situation is so confusing on Windows, where the file associations, >>> registry entries, and other internal software which allows a given >>> Python release to work properly when invoking Python is so complicated, >>> that I have given up on trying to install more than one Python release >>> and finding a relaible, foolproof way of switching between them. So >>> although I would like to use the latest 3.x series on Windows I have >>> decide to stick with the latest 2.x series instead because much software >>> using Python does not support 3.x yet. >> >> on my fedora system it was a simple matter of:- >> #> yum install python3 >> >> to use python 3 i specify it in my shebang line >> >> #!/usr/bun/env python3 >> >> Simple >> >> Not sure about Windoze though (Although from memory the install asks >> where to install so should not be a major issue) > > Windows installs of Python do not distinguish releases by Pythonx(.x) > but just install different versions of Python in different directories. > However one can make links to the different versions based on their > release numbers, and that would allow a shebang line work if it was > supported. > > Please read this http://www.python.org/dev/peps/pep-0397/ and let us know whether or not it fits your needs on Windows. -- Cheers. Mark Lawrence. From maniandram01 at gmail.com Fri Oct 5 09:03:20 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 5 Oct 2012 06:03:20 -0700 (PDT) Subject: When was the last time you did something for the first time? In-Reply-To: References: Message-ID: <174ae38f-f841-437d-9f69-e0e00ce3b6ba@googlegroups.com> On Friday, 5 October 2012 16:33:52 UTC+5:30, The Matchmaker wrote: > What do you want to talk about today? Nothing. From joel.goldstick at gmail.com Fri Oct 5 09:11:31 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 5 Oct 2012 09:11:31 -0400 Subject: How to create a login screen using core python language without using any framework In-Reply-To: <506ea86d$0$6969$e4fe514c@news2.news.xs4all.nl> References: <97fa2804-adda-428f-a78a-d9ab3e22e965@googlegroups.com> <506ea86d$0$6969$e4fe514c@news2.news.xs4all.nl> Message-ID: On Fri, Oct 5, 2012 at 5:29 AM, Hans Mulder wrote: > On 5/10/12 10:03:56, shivakrshn49 at gmail.com wrote: >> I need to develop a simple login page using Python language with >> two fields and a button, like: >> >> Username, Password, Login >> >> I know there are some beautiful Python frameworks like >> >> Django, Grok, WebPy, TurboGears >> >> which support web development using Python, but mine is a basic >> requirement consisting of only 3 screens (pages): >> >> * 1st page - Login page (Redirects to 2nd page when login button >> is clicked) >> * 2nd page - Page with records in the form of a list, with an >> option for adding new records (Redirects to 3rd page when "Add >> Records" button is clicked) >> * 3rd page - Page with fields, which are saved as records for >> the list on 2nd page (After entering details and clicking Submit) > > Implementing your application using any of those frameworks you > mentioned, would be easy. > >> So, I have decided to develop the above functionality using Python >> **without** using any framework, so that I can have flexibility as >> well as write my own code. > > This is a bad idea. You'll get much more flexibility using > an existing framework then you'd ever achieve by reinventing > the wheel on your own. Especially if you have no experience > in this field. > >> 1. Is it possible to create a login page using Python without >> using a framework? > > Yes. > > But it's a lot of work. You'd effectively be rewriting all > the functionality you'd get for free with a framework. And > it wouldn't be as flexible, because frameworks can flex in > directions that you didn't think of. > >> 2. I haven't worked on web services and don't know the basics of >> web development in Python. > > In that case, your chances of success are fairly slim. > >> 3. If possible, can you provide me an example on how to create a >> login page using Python and achieve the functionality described >> above? > > The frameworks you mentioned earlier come with tutorials. > These tutorials contain such examples. > > You should really use an existing framework. Once you're > aware of how much functionality you get out of a framework > (any of them), you wouldn't dream of rewriting all that > functionality on your own. I totally agree about using a framework. You say you want a 'simple' 3 page website. Why do you think it is simple? You say you don't have any skills at creating websites with python. From your description, you will need to build a directory of entries, a form, and attach it to a database, so that means you also need to understand sql (or something!). You need to display individual records I imagine. Do you need to edit them after they are created? How are you going to manage the accounts? Will you create them? Will you let the visitor create an account? Where will you store the account information? Do different accounts have different permissions? If you install django (for instance), go through the online tutorials in about 2 hours, you could probably build your specification in a day. Even if you have problems there is an active django mailing list to ask specific questions. I haven't tried the other frameworks, but there might be similar help available for them. -- Joel Goldstick From maniandram01 at gmail.com Fri Oct 5 09:32:28 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 5 Oct 2012 06:32:28 -0700 (PDT) Subject: final question: logging to stdout and updating files In-Reply-To: <506d967a$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <506d967a$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <943555c6-2d99-4f20-9177-653f60bbfb1a@googlegroups.com> On Thursday, 4 October 2012 19:30:26 UTC+5:30, Steven D'Aprano wrote: > On Thu, 04 Oct 2012 06:34:28 -0700, Ramchandra Apte wrote: > > > > > "Optimize code always even if it causes bugs" - Ramchandra Apte, 2001- > > > > Well, you've just added yourself into my list of people whose advice > > should always be ignored. > > > > That is *terrible* advice. But if you insist on following it, you can > > optimize *any* Python program to this: > > > > # === start code === > > pass # this line is optional > > # === end code === > > > > > > There you go. The most heavily optimized, fastest Python program in > > existence. Sure, it has a few bugs, but boy is it fast!!! > > > > > > -- > > Steven Please disclose the list of people. This email is subject to important disclosures available at loobafoobajo.ke/legal.html LOOBA FOOBA JOKE COMPANY MAKES NO WARRANTIES ABOUT THIS EMAIL Read at your risk - you may die from reading this email. ;-P From mike20007 at gmail.com Fri Oct 5 09:39:15 2012 From: mike20007 at gmail.com (Mike) Date: Fri, 5 Oct 2012 06:39:15 -0700 (PDT) Subject: sum function In-Reply-To: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> Message-ID: <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com> On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote: > Hi All, > > > > I am new to python and am getting the data from hbase. > > I am trying to do sum on the column as below > > > > > > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) > > total = 0.0 > > r = client.scannerGet(scanner) > > while r: > > for k in (r[0].columns): > > total += float(r[0].columns[k].value) > > r = client.scannerGet(scanner) > > > > print total > > > > Do you know of better (faster) way to do sum? > > > > Any thoughts please? > > > > Thanks Sorry about that. Here you go Traceback (most recent call last): File "test.py", line 17, in total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) File "test.py", line 17, in total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) IndexError: list index out of range From maniandram01 at gmail.com Fri Oct 5 09:41:43 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 5 Oct 2012 06:41:43 -0700 (PDT) Subject: sum function In-Reply-To: <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com> Message-ID: <04412893-e6ba-43cc-8d9c-7867f82af4d1@googlegroups.com> On Friday, 5 October 2012 19:09:15 UTC+5:30, Mike wrote: > On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote: > > > Hi All, > > > > > > > > > > > > I am new to python and am getting the data from hbase. > > > > > > I am trying to do sum on the column as below > > > > > > > > > > > > > > > > > > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) > > > > > > total = 0.0 > > > > > > r = client.scannerGet(scanner) > > > > > > while r: > > > > > > for k in (r[0].columns): > > > > > > total += float(r[0].columns[k].value) > > > > > > r = client.scannerGet(scanner) > > > > > > > > > > > > print total > > > > > > > > > > > > Do you know of better (faster) way to do sum? > > > > > > > > > > > > Any thoughts please? > > > > > > > > > > > > Thanks > > > > Sorry about that. Here you go > > > > Traceback (most recent call last): > > File "test.py", line 17, in > > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) > > File "test.py", line 17, in > > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) > > IndexError: list index out of range the variable "r" is an empty list From mike20007 at gmail.com Fri Oct 5 09:47:12 2012 From: mike20007 at gmail.com (Mike) Date: Fri, 5 Oct 2012 06:47:12 -0700 (PDT) Subject: sum function In-Reply-To: <04412893-e6ba-43cc-8d9c-7867f82af4d1@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com> <04412893-e6ba-43cc-8d9c-7867f82af4d1@googlegroups.com> Message-ID: On Friday, October 5, 2012 9:41:44 AM UTC-4, Ramchandra Apte wrote: > On Friday, 5 October 2012 19:09:15 UTC+5:30, Mike wrote: > > > On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote: > > > > > > > Hi All, > > > > > > > > > > > > > > > > > > > > > > > > > > > > I am new to python and am getting the data from hbase. > > > > > > > > > > > > > > I am trying to do sum on the column as below > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) > > > > > > > > > > > > > > total = 0.0 > > > > > > > > > > > > > > r = client.scannerGet(scanner) > > > > > > > > > > > > > > while r: > > > > > > > > > > > > > > for k in (r[0].columns): > > > > > > > > > > > > > > total += float(r[0].columns[k].value) > > > > > > > > > > > > > > r = client.scannerGet(scanner) > > > > > > > > > > > > > > > > > > > > > > > > > > > > print total > > > > > > > > > > > > > > > > > > > > > > > > > > > > Do you know of better (faster) way to do sum? > > > > > > > > > > > > > > > > > > > > > > > > > > > > Any thoughts please? > > > > > > > > > > > > > > > > > > > > > > > > > > > > Thanks > > > > > > > > > > > > Sorry about that. Here you go > > > > > > > > > > > > Traceback (most recent call last): > > > > > > File "test.py", line 17, in > > > > > > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) > > > > > > File "test.py", line 17, in > > > > > > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) > > > > > > IndexError: list index out of range > > > > the variable "r" is an empty list Here is the actual code. scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) next_r = functools.partial(client.scannerGet, scanner) total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) Scanner does have rows. Are we missing something please? Thanks From mike20007 at gmail.com Fri Oct 5 09:59:07 2012 From: mike20007 at gmail.com (Mike) Date: Fri, 5 Oct 2012 06:59:07 -0700 (PDT) Subject: How to call python script from web. Message-ID: <4bf240e0-26a2-4470-9e8e-badc8d8ae464@googlegroups.com> Hi, I can call the php script from browser assuming apache web server exists. How can I call the python script like php script? Any thought? Thanks From joel.goldstick at gmail.com Fri Oct 5 10:23:32 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 5 Oct 2012 10:23:32 -0400 Subject: How to call python script from web. In-Reply-To: <4bf240e0-26a2-4470-9e8e-badc8d8ae464@googlegroups.com> References: <4bf240e0-26a2-4470-9e8e-badc8d8ae464@googlegroups.com> Message-ID: On Fri, Oct 5, 2012 at 9:59 AM, Mike wrote: > Hi, > > I can call the php script from browser assuming apache web server exists. > > How can I call the python script like php script? > > Any thought? > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list A popular way for apache is to use mod_wsgi. http://code.google.com/p/modwsgi/ -- Joel Goldstick From demianbrecht at gmail.com Fri Oct 5 10:41:33 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Fri, 05 Oct 2012 07:41:33 -0700 Subject: How to create a login screen using core python language without using any framework In-Reply-To: References: <97fa2804-adda-428f-a78a-d9ab3e22e965@googlegroups.com> <506ea86d$0$6969$e4fe514c@news2.news.xs4all.nl> Message-ID: <506EF19D.8070600@gmail.com> On 12-10-05 06:11 AM, Joel Goldstick wrote: > I totally agree about using a framework. You say you want a 'simple' > 3 page website. Why do you think it is simple? You say you don't > have any skills at creating websites with python. From your > description, you will need to build a directory of entries, a form, > and attach it to a database, so that means you also need to understand > sql (or something!). You need to display individual records I imagine. > Do you need to edit them after they are created? How are you going > to manage the accounts? Will you create them? Will you let the > visitor create an account? Where will you store the account > information? Do different accounts have different permissions? > Not to mention security. Frameworks like Django provide protection against things like: * CSRF (Cross Site Request Forgery) * XSS ((X)Cross Site Scripting) * SQL injection As well as others. For a comprehensive list of protection that Django offers, check out https://docs.djangoproject.com/en/dev/topics/security/. -- Demian Brecht @demianbrecht http://demianbrecht.github.com From torriem at gmail.com Fri Oct 5 11:10:48 2012 From: torriem at gmail.com (Michael Torrie) Date: Fri, 05 Oct 2012 09:10:48 -0600 Subject: notmm is dead! In-Reply-To: <20121005064347.10aa9146cc3c053b14dbeaca@gmail.com> References: <20121004141046.677dac1e8bf6dada0b6af6b3@gmail.com> <20121004181157.31c1083520ff8230242962e1@gmail.com> <20121004191351.8c6fcfd8ddad7b6e6bfc02f2@gmail.com> <506E487B.3010704@gmail.com> <20121005064347.10aa9146cc3c053b14dbeaca@gmail.com> Message-ID: <506EF878.5030303@gmail.com> On 10/05/2012 04:43 AM, Etienne Robillard wrote: > No. All past notmm licenses were and still ARE ISC licensed. The license fee > is simply because I'm shifting into commercial license for new releases, including > the newer 0.4.5 version... Pypi was not the authority source for notmm and > neither anyone can claim the license was left blank, thats once again a form of plagiarism. > > Shall anyone is really serious about supporting the work i did then he'll want to pay a minimal fee to get > the proper license rights and can contact me off-list if he want to fork a branch > to github of google code. Someone certainly could fork any past ISC version and proceed from there. That is simply my point. Without any license fees and without any accusation of "plagiarism." Indeed it wouldn't be plagiarism because your name would still be on it, and copyright assigned to you. I don't know what you are talking about with the plagiarism thing. If there indeed was a tarball out there with an empty license file all that would do would be to prevent the downloader from legally doing *anything* with the file. That's all the original poster was saying. We're just trying to be clear on the terms here, not accusing you of anything, nor trying to denigrate all your hard work. From hchapa at lrgvdc911.org Fri Oct 5 11:17:25 2012 From: hchapa at lrgvdc911.org (Hector Chapa) Date: Fri, 5 Oct 2012 10:17:25 -0500 Subject: When was the last time you did something for the first time? In-Reply-To: <174ae38f-f841-437d-9f69-e0e00ce3b6ba@googlegroups.com> References: <174ae38f-f841-437d-9f69-e0e00ce3b6ba@googlegroups.com> Message-ID: I learn trigonometry -----Original Message----- From: Ramchandra Apte [mailto:maniandram01 at gmail.com] Sent: Friday, October 05, 2012 8:03 AM To: python-list at python.org Subject: Re: When was the last time you did something for the first time? On Friday, 5 October 2012 16:33:52 UTC+5:30, The Matchmaker wrote: > What do you want to talk about today? Nothing. From driscoll at cs.wisc.edu Fri Oct 5 11:27:00 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Fri, 05 Oct 2012 10:27:00 -0500 Subject: + in regular expression In-Reply-To: References: Message-ID: <506EFC44.40508@cs.wisc.edu> On 10/05/2012 04:23 AM, Duncan Booth wrote: > A regular expression element may be followed by a quantifier. > Quantifiers are '*', '+', '?', '{n}', '{n,m}' (and lazy quantifiers > '*?', '+?', '{n,m}?'). There's nothing in the regex language which says > you can follow an element with two quantifiers. In fact, *you* did -- the first sentence of that paragraph! :-) \s is a regex, so you can follow it with a quantifier and get \s{6}. That's also a regex, so you should be able to follow it with a quantifier. I can understand that you can create a grammar that excludes it. I'm actually really interested to know if anyone knows whether this was a deliberate decision and, if so, what the reason is. (And if not -- should it be considered a (low priority) bug?) Was it because such patterns often reveal a mistake? Because "\s{6}+" has other meanings in different regex syntaxes and the designers didn't want confusion? Because it was simpler to parse that way? Because the "hey you recognize regular expressions by converting it to a finite automaton" story is a lie in most real-world regex implementations (in part because they're not actually regular expressions) and repeated quantifiers cause problems with the parsing techniques that actually get used? Evan From ian.g.kelly at gmail.com Fri Oct 5 11:29:39 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Oct 2012 09:29:39 -0600 Subject: notmm is dead! In-Reply-To: <20121004205643.b92cbe656521996843cf01fe@gmail.com> References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> <20121004205643.b92cbe656521996843cf01fe@gmail.com> Message-ID: On Oct 4, 2012 6:56 PM, "Etienne Robillard" wrote: > > You probably have a old tarball or something... Not unless you've replaced it since I made my post, as I had just downloaded it to check the license. -------------- next part -------------- An HTML attachment was scrubbed... URL: From driscoll at cs.wisc.edu Fri Oct 5 11:31:26 2012 From: driscoll at cs.wisc.edu (Evan Driscoll) Date: Fri, 05 Oct 2012 10:31:26 -0500 Subject: + in regular expression In-Reply-To: <506EFC44.40508@cs.wisc.edu> References: <506EFC44.40508@cs.wisc.edu> Message-ID: <506EFD4E.9030100@cs.wisc.edu> On 10/05/2012 10:27 AM, Evan Driscoll wrote: > On 10/05/2012 04:23 AM, Duncan Booth wrote: >> A regular expression element may be followed by a quantifier. >> Quantifiers are '*', '+', '?', '{n}', '{n,m}' (and lazy quantifiers >> '*?', '+?', '{n,m}?'). There's nothing in the regex language which says >> you can follow an element with two quantifiers. > In fact, *you* did -- the first sentence of that paragraph! :-) > > \s is a regex, so you can follow it with a quantifier and get \s{6}. > That's also a regex, so you should be able to follow it with a > quantifier. OK, I guess this isn't true... you said a "regular expression *element*" can be followed by a quantifier. I just took what I usually see as part of a regular expression and read into your post something it didn't quite say. Still, the rest of mine applies. Evan From animelovin at gmail.com Fri Oct 5 11:51:26 2012 From: animelovin at gmail.com (Etienne Robillard) Date: Fri, 5 Oct 2012 11:51:26 -0400 Subject: notmm is dead! In-Reply-To: References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> <20121004205643.b92cbe656521996843cf01fe@gmail.com> Message-ID: <20121005115126.615ccff8999a8bccea387136@gmail.com> On Fri, 5 Oct 2012 09:29:39 -0600 Ian Kelly wrote: > On Oct 4, 2012 6:56 PM, "Etienne Robillard" wrote: > > > > You probably have a old tarball or something... > > Not unless you've replaced it since I made my post, as I had just > downloaded it to check the license. The 0.4.4 release is old, however, so you might really got a wrong tarball. :-) Cheers, Etienne -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ erob at gthcfoundation.org From python at mrabarnett.plus.com Fri Oct 5 12:07:47 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Oct 2012 17:07:47 +0100 Subject: + in regular expression In-Reply-To: <506EFC44.40508@cs.wisc.edu> References: <506EFC44.40508@cs.wisc.edu> Message-ID: <506F05D3.2020306@mrabarnett.plus.com> On 2012-10-05 16:27, Evan Driscoll wrote: > On 10/05/2012 04:23 AM, Duncan Booth wrote: >> A regular expression element may be followed by a quantifier. >> Quantifiers are '*', '+', '?', '{n}', '{n,m}' (and lazy quantifiers >> '*?', '+?', '{n,m}?'). There's nothing in the regex language which says >> you can follow an element with two quantifiers. > In fact, *you* did -- the first sentence of that paragraph! :-) > > \s is a regex, so you can follow it with a quantifier and get \s{6}. > That's also a regex, so you should be able to follow it with a quantifier. > > I can understand that you can create a grammar that excludes it. I'm > actually really interested to know if anyone knows whether this was a > deliberate decision and, if so, what the reason is. (And if not -- > should it be considered a (low priority) bug?) > > Was it because such patterns often reveal a mistake? Because "\s{6}+" > has other meanings in different regex syntaxes and the designers didn't > want confusion? Because it was simpler to parse that way? Because the > "hey you recognize regular expressions by converting it to a finite > automaton" story is a lie in most real-world regex implementations (in > part because they're not actually regular expressions) and repeated > quantifiers cause problems with the parsing techniques that actually get > used? > You rarely want to repeat a repeated element. It can also result in catastrophic backtracking unless you're _very_ careful. In many other regex implementations (including mine), "*+", "*+" and "?+" are possessive quantifiers, much as "??", "*?" and "??" are lazy quantifiers. You could, of course, ask why adding "?" after a quantifier doesn't make it optional, e.g. why r"\s{6}?" doesn't mean the same as r"(?:\s{6})?", or why r"\s{0,6}?" doesn't mean the same as r"(?:\s{0,6})?". From michael at stroeder.com Fri Oct 5 12:24:13 2012 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Fri, 05 Oct 2012 18:24:13 +0200 Subject: [fcgi.py] Force cache upgrade? In-Reply-To: <1nfc68di85mfuaqm2gggura2bsio7gg4ke@4ax.com> References: <1nfc68di85mfuaqm2gggura2bsio7gg4ke@4ax.com> Message-ID: Gilles wrote: > On Fri, 28 Sep 2012 23:57:14 +0200, Gilles wrote: >> I guess the FastCGI server (Flup) only updates its cache every so >> often. Do I need to type a command to force Flup to recompile the >> Python script? > > Turns out that, yes, mod_fcgid is configured to reload a script only > after some time or some number of hits, Well, that's the whole point of using FastCGI: Have a long-running process for better performance. Ciao, Michael. From ethan at stoneleaf.us Fri Oct 5 13:39:53 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Oct 2012 10:39:53 -0700 Subject: instance.attribute lookup Message-ID: <506F1B69.8030800@stoneleaf.us> There is a StackOverflow question [1] that points to this on-line book [2] which has a five-step sequence for looking up attributes: > When retrieving an attribute from an object (print > objectname.attrname) Python follows these steps: > > 1. If attrname is a special (i.e. Python-provided) attribute for > objectname, return it. > > 2. Check objectname.__class__.__dict__ for attrname. If it exists and > is a data-descriptor, return the descriptor result. Search all bases > of objectname.__class__ for the same case. > > 3. Check objectname.__dict__ for attrname, and return if found. If > objectname is a class, search its bases too. If it is a class and a > descriptor exists in it or its bases, return the descriptor result. > > 4. Check objectname.__class__.__dict__ for attrname. If it exists and > is a non-data descriptor, return the descriptor result. If it exists, > and is not a descriptor, just return it. If it exists and is a data > descriptor, we shouldn't be here because we would have returned at > point 2. Search all bases of objectname.__class__ for same case. > > 5. Raise AttributeError I'm thinking step 1 is flat-out wrong and doesn't exist. Does anybody know otherwise? ~Ethan~ [1] http://stackoverflow.com/q/10536539/208880 [2] http://www.cafepy.com/article/python_attributes_and_methods/ch01s05.html From tjreedy at udel.edu Fri Oct 5 14:52:13 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Oct 2012 14:52:13 -0400 Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com> <04412893-e6ba-43cc-8d9c-7867f82af4d1@googlegroups.com> Message-ID: <506F2C5D.3030000@udel.edu> On 10/5/2012 9:47 AM, Mike wrote: > On Friday, October 5, 2012 9:41:44 AM UTC-4, Ramchandra Apte wrote: >> On Friday, 5 October 2012 19:09:15 UTC+5:30, Mike wrote: >> >>> On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote: >> >>> >> >>>> Hi All, >> >>> >> >>>> >> >>> >> >>>> >> >>> >> >>>> >> >>> >> >>>> I am new to python and am getting the data from hbase. If you want as many people as possible to read your posts, stop using a mail-agent and site that spits in the face of readers by doubling blank lines each iteration. Alternatives have been discussed previously. -- Terry Jan Reedy From sanluca78 at gmail.com Fri Oct 5 14:55:41 2012 From: sanluca78 at gmail.com (Luca Sanna) Date: Fri, 5 Oct 2012 11:55:41 -0700 (PDT) Subject: calendar from python to html Message-ID: hi, I enter a calendar in an html page in each calendar day, I enter a time that is used by the program to perform actions with python What can I use to do this? thanks From ian.g.kelly at gmail.com Fri Oct 5 15:29:04 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Oct 2012 13:29:04 -0600 Subject: sum function In-Reply-To: <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com> Message-ID: On Fri, Oct 5, 2012 at 7:39 AM, Mike wrote: > Sorry about that. Here you go > > Traceback (most recent call last): > File "test.py", line 17, in > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) > File "test.py", line 17, in > total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) > IndexError: list index out of range Maybe the sentinel value is not None as I assumed, and it's overrunning the end of the data? What does client.scannerGet return when there is no more data? From ramit.prasad at jpmorgan.com Fri Oct 5 15:37:59 2012 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 5 Oct 2012 19:37:59 +0000 Subject: notmm is dead! In-Reply-To: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474166DB3A7@SCACMX008.exchad.jpmchase.net> Steven D'Aprano wrote: > Sent: Thursday, October 04, 2012 7:22 PM > To: python-list at python.org > Subject: Re: notmm is dead! > > On Thu, 04 Oct 2012 14:10:46 -0400, Etienne Robillard wrote: > > > Dear list, > > > > Due to lack of energy and resources i'm really sad to announce the > > removal of notmm from pypi and bitbucket. > > Well that's just rude. Even if you don't intend to maintain the software > any more, why are you removing it from pypi? Since you say you are a fan > of Open Source software, just flag it as unmaintained and leave it for > somebody else to pick up. > > If you are going to abandon the project, release it on PyPI with a dual > MIT and GPL licence, and let it be taken over by somebody else. > > If you were looking for sympathy here, starting off by removing your > project from free hosting, then complaining that you can't pay for the > non-free hosting, was NOT the right way to do so. I might be misunderstanding, but I think Etienne wants money in exchange for letting someone else take over. > > By the way, the latest version of notmm (0.4.4) has an empty licence > file. No licence means that everyone using it is unlicenced and therefore > infringing your copyright. > > 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 trent at snakebite.org Fri Oct 5 15:58:37 2012 From: trent at snakebite.org (Trent Nelson) Date: Fri, 5 Oct 2012 15:58:37 -0400 Subject: Are ABCs an anti-pattern? In-Reply-To: <506AF8C9.8060406@gmail.com> References: <506AF8C9.8060406@gmail.com> Message-ID: <20121005195836.GA94783@snakebite.org> On Tue, Oct 02, 2012 at 07:23:05AM -0700, Demian Brecht wrote: > I don't use them anymore, but I'm curious about others opinions on this > list... I like them. In particular, I like that I can enumerate all the subclasses that happen to implement the ABC via the metaclass's __subclasses__() method. I also like that I can trust Python not to instantiate a subclass of an ABC unless it meets all the interface criteria I've stipulated. Both of these aspects make ABCs a great fit when your base classes will be subclassed by other users/libraries (i.e. that you have no control over). For example, I use them in a project of mine called Enversion in order to automatically generate command-line scaffolding with as little effort (programming/typing-wise as possible). The ABC stuff lives in 'evn.cli' and provides a set of generic classes for command-line tools. One of the command line tools that ships with Enversion is the 'evnadmin' command. Thanks to all the ABC scaffolding in the 'evn.cli/command' module, all I need to write is the following to get an 'evnadmin' command-line interface: from evn.cli import ( CLI, CommandLine, ) class AdminCommandLine(CommandLine): @property def commands_module(self): return evn.admin.commands class AdminCLI(CLI): @property def program_name(self): return 'evnadmin' @property def commandline_subclasses(self): return AdminCommandLine.__subclasses__() class DoctestCommandLine(AdminCommandLine): _quiet_ = True class DumpDefaultConfigCommandLine(AdminCommandLine): pass class DumpConfigCommandLine(AdminCommandLine): _conf_ = True class ShowConfigFileLoadOrderCommandLine(AdminCommandLine): _conf_ = True class DumpHookCodeCommandLine(AdminCommandLine): _conf_ = True _repo_ = True [snip] Running 'evnadmin' with no arguments yields this: % evnadmin Type 'evnadmin help' for help on a specific subcommand. Available subcommands: analyze create disable-remote-debug (drd) doctest dump-config (dc) dump-default-config (ddc) dump-hook-code (dhc) enable enable-remote-debug (erd) find-merges (fm) fix-hooks (fh) root-info (ri) run-hook (rh) show-config-file-load-order (scflo) show-repo-hook-status (srhs) show-repo-remote-debug-sessions (srrds) show-roots (sr) toggle-remote-debug (trd) version The scaffolding can generate all of that automatically thanks to the ability to enumerate __subclasses__() of a metaclass. The fact that Python will bomb out if a derived class doesn't implement all the required methods/properties is icing on the cake. When you are expecting other developers to leverage your ABCs, getting instant feedback when you forget to implement a required method/property is incredibly useful. It's definitely not a case of battling the design decisions made by the ABC author... Relevant Python files: https://github.com/tpn/enversion/blob/master/evn/cli.py https://github.com/tpn/enversion/blob/master/evn/admin/cli.py Regards, Trent. > Demian Brecht > @demianbrecht > http://demianbrecht.github.com > -- > http://mail.python.org/mailman/listinfo/python-list From mike20007 at gmail.com Fri Oct 5 16:03:49 2012 From: mike20007 at gmail.com (Mike) Date: Fri, 5 Oct 2012 13:03:49 -0700 (PDT) Subject: sum function In-Reply-To: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> Message-ID: <9cfb599a-31c2-486f-95c9-d60e1d29f730@googlegroups.com> I added the print command. It prints [] when there is no data. Thanks From mike20007 at gmail.com Fri Oct 5 16:09:11 2012 From: mike20007 at gmail.com (Mike) Date: Fri, 5 Oct 2012 13:09:11 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com> <04412893-e6ba-43cc-8d9c-7867f82af4d1@googlegroups.com> Message-ID: <397c5421-e28b-482e-82ce-6bf693056d51@googlegroups.com> Terry, I am not using the mail client. I am just posting on the site. Something wrong with this site. When you do individual reply, it does the double posting which it shouldn't. See "Ramachandra Apte's" reply. It is posted twice too. Thanks From mike20007 at gmail.com Fri Oct 5 16:09:11 2012 From: mike20007 at gmail.com (Mike) Date: Fri, 5 Oct 2012 13:09:11 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com> <04412893-e6ba-43cc-8d9c-7867f82af4d1@googlegroups.com> Message-ID: <397c5421-e28b-482e-82ce-6bf693056d51@googlegroups.com> Terry, I am not using the mail client. I am just posting on the site. Something wrong with this site. When you do individual reply, it does the double posting which it shouldn't. See "Ramachandra Apte's" reply. It is posted twice too. Thanks From ian.g.kelly at gmail.com Fri Oct 5 16:10:36 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Oct 2012 14:10:36 -0600 Subject: sum function In-Reply-To: <9cfb599a-31c2-486f-95c9-d60e1d29f730@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <9cfb599a-31c2-486f-95c9-d60e1d29f730@googlegroups.com> Message-ID: On Fri, Oct 5, 2012 at 2:03 PM, Mike wrote: > I added the print command. > > It prints [] when there is no data. Change "iter(next_r, None)" to "iter(next_r, [])" From vasudevram at gmail.com Fri Oct 5 16:19:17 2012 From: vasudevram at gmail.com (vasudevram) Date: Fri, 5 Oct 2012 13:19:17 -0700 (PDT) Subject: fmap(), "inverse" of Python map() function Message-ID: <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function.html - Vasudev Ram www.dancingbison.com jugad2.blogspot.com twitter.com/vasudevram From d at davea.name Fri Oct 5 16:26:26 2012 From: d at davea.name (Dave Angel) Date: Fri, 05 Oct 2012 16:26:26 -0400 Subject: sum function In-Reply-To: <397c5421-e28b-482e-82ce-6bf693056d51@googlegroups.com> References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com> <04412893-e6ba-43cc-8d9c-7867f82af4d1@googlegroups.com> <397c5421-e28b-482e-82ce-6bf693056d51@googlegroups.com> Message-ID: <506F4272.5010003@davea.name> On 10/05/2012 04:09 PM, Mike wrote: > Terry, > > I am not using the mail client. I am just posting on the site. And which site would that be (that you're using)? There are a few. I'm guessing you use google-groups. And all of them get gatewayed to the actual list, with differing numbers of bugs. I use email to access it directly. I solve one of the duplicate-message problems with google groups by automatically deleting any message addressed to google-groups. There are about 100 such messages each month. Another problem is that lots of these gateways post to both the newsgroup and to the python-list. > > Something wrong with this site. When you do individual reply, it does the double posting which it shouldn't. See "Ramachandra Apte's" reply. It is posted twice too. > > Thanks > > > -- DaveA From mike20007 at gmail.com Fri Oct 5 17:19:56 2012 From: mike20007 at gmail.com (Mike) Date: Fri, 5 Oct 2012 14:19:56 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <9cfb599a-31c2-486f-95c9-d60e1d29f730@googlegroups.com> Message-ID: <48ef35fb-89c4-4d4a-8eb6-b8ae5286db47@googlegroups.com> That worked, Ian. Thanks From ian.g.kelly at gmail.com Fri Oct 5 17:31:35 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Oct 2012 15:31:35 -0600 Subject: fmap(), "inverse" of Python map() function In-Reply-To: <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> References: <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> Message-ID: On Fri, Oct 5, 2012 at 2:19 PM, vasudevram wrote: > > http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function.html Your fmap is a special case of reduce. def fmap(functions, argument): return reduce(lambda result, func: func(result), functions, argument) From davejay2662 at gmail.com Fri Oct 5 17:43:16 2012 From: davejay2662 at gmail.com (dave) Date: Fri, 5 Oct 2012 14:43:16 -0700 (PDT) Subject: Job Message-ID: Looking for entry to mid level Python Developer for Contract job in New England. Let me know if you want to hear more. From ian.g.kelly at gmail.com Fri Oct 5 17:43:31 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Oct 2012 15:43:31 -0600 Subject: fmap(), "inverse" of Python map() function In-Reply-To: References: <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> Message-ID: On Fri, Oct 5, 2012 at 3:31 PM, Ian Kelly wrote: > On Fri, Oct 5, 2012 at 2:19 PM, vasudevram wrote: >> >> http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function.html > > Your fmap is a special case of reduce. > > def fmap(functions, argument): > return reduce(lambda result, func: func(result), functions, argument) In a more functional style, you could also use reduce to compose the functions before applying them: def compose(f, g): return lambda x: f(g(x)) def fmap(functions): return reduce(compose, reversed(functions)) # Allowing you to then do: result = fmap(functions)(argument) Cheers, Ian From iandouglas736 at gmail.com Fri Oct 5 17:53:55 2012 From: iandouglas736 at gmail.com (ian douglas) Date: Fri, 05 Oct 2012 21:53:55 -0000 Subject: notmm is dead! In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474166DB3A7@SCACMX008.exchad.jpmchase.net> References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF474166DB3A7@SCACMX008.exchad.jpmchase.net> Message-ID: <506F489C.6010805@gmail.com> On 10/05/2012 12:37 PM, Prasad, Ramit wrote: > I might be misunderstanding, but I think Etienne wants money in > exchange for letting someone else take over. Not to stir up the hornet's nest any more, but it also sounds like now he wants money for people to license things as well: "The license fee is simply because I'm shifting into commercial license for new releases" Wait, new releases? I thought the project was "dead" ? So, Etienne, are you continuing to maintain the project, or aren't you? In your original "this project is dead" message, you said you had "been bitten by its failure to encourage a free market over one dictated by profit" ... yet now your desire is to be making money (presumably profit?) by selling us a license, so how does that differentiate from those you claim use "cheap tricks to compete" if you hijack a mailing list for several days by claiming you're shutting down the project then say you're charing for licenses which may lead people to believe you're going to KEEP maintaining it? Why on earth would I pay for a license to use code that is not being maintained? Seems like very strange logic to me. Or by having someone pay you some quantity of money to take over as maintainer? I can think of no better way to just kill off a project than expect someone to pay money to take over as a maintainer. I don't recall ever hearing of such a thing in my experience with open-source projects... I'm all about supporting open source projects when I gain value from them (I've donated thousands of dollars and countless hours), but Etienne's back-and-forth on this has me turned off from even wanting to try his project, much less support him. There are so many free places to host code/documentation these days, asking people to donate extra funds to maintain a custom domain name and hosting when free alternatives exist seems as unnecessary as having to pay money to become the next maintainer. -id From me at robin-krahl.de Fri Oct 5 18:22:38 2012 From: me at robin-krahl.de (Robin Krahl) Date: Sat, 06 Oct 2012 00:22:38 +0200 Subject: Executing untrusted scripts in a sandboxed environment Message-ID: <4hrls608xbax633ej6s1n54j.1349475464556@email.android.com> Hi all, I need to execute untrusted scripts in my Python application. To avoid security issues, I want to use a sandboxed environment. This means that the script authors have no access to the file system. They may only access objects, modules and classes that are "flagged" or "approved" for scripting. I read that I will not be able to do this with Python scripts. (See SandboxedPython page in the Python wiki [0] and several SE.com questions, e. g. [1].) So my question is: What is the best way to "embed" a script engine in a sandboxed environment that has access to the Python modules and classes that I provide? Thanks for your help. Best regards, Robin [0] http://wiki.python.org/moin/SandboxedPython [1] http://stackoverflow.com/questions/3068139/how-can-i-sandbox-python-in-pure-python From jeanpierreda at gmail.com Fri Oct 5 18:52:41 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 5 Oct 2012 18:52:41 -0400 Subject: fmap(), "inverse" of Python map() function In-Reply-To: References: <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> Message-ID: On Fri, Oct 5, 2012 at 5:31 PM, Ian Kelly wrote: > On Fri, Oct 5, 2012 at 2:19 PM, vasudevram wrote: >> >> http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function.html > > Your fmap is a special case of reduce. So is map. def map(f, seq): return reduce( lambda rseq, newpre: rseq.append(f(newpre)) or rseq, seq, []) "X is a special case of reduce" is basically the same as saying "X can be implemented using a for loop". If it's meant as a complaint, it's a poor one. -- Devin From steve+comp.lang.python at pearwood.info Fri Oct 5 19:00:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Oct 2012 23:00:30 GMT Subject: instance.attribute lookup References: Message-ID: <506f668d$0$29978$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Oct 2012 10:39:53 -0700, Ethan Furman wrote: > There is a StackOverflow question [1] that points to this on-line book > [2] which has a five-step sequence for looking up attributes: > > > When retrieving an attribute from an object (print > > objectname.attrname) Python follows these steps: > > > > 1. If attrname is a special (i.e. Python-provided) attribute for > > objectname, return it. [...] > I'm thinking step 1 is flat-out wrong and doesn't exist. Does anybody > know otherwise? I'm thinking I don't even understand what step 1 means. What's a Python-provided attribute, and how is it different from other attributes? -- Steven From ethan at stoneleaf.us Fri Oct 5 19:12:22 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Oct 2012 16:12:22 -0700 Subject: instance.attribute lookup In-Reply-To: <506f668d$0$29978$c3e8da3$5496439d@news.astraweb.com> References: <506f668d$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: <506F6956.2070502@stoneleaf.us> Steven D'Aprano wrote: > On Fri, 05 Oct 2012 10:39:53 -0700, Ethan Furman wrote: > >> There is a StackOverflow question [1] that points to this on-line book >> [2] which has a five-step sequence for looking up attributes: >> >> > When retrieving an attribute from an object (print >> > objectname.attrname) Python follows these steps: >> > >> > 1. If attrname is a special (i.e. Python-provided) attribute for >> > objectname, return it. > [...] >> I'm thinking step 1 is flat-out wrong and doesn't exist. Does anybody >> know otherwise? > > I'm thinking I don't even understand what step 1 means. > > What's a Python-provided attribute, and how is it different from other > attributes? Well, if /you/ don't understand it I feel a lot better about not understanding it either! :) Glad to know I'm not missing something (besides ESP, a crystal ball, and a mind-reader!) ~Ethan~ From ian.g.kelly at gmail.com Fri Oct 5 19:24:14 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Oct 2012 17:24:14 -0600 Subject: fmap(), "inverse" of Python map() function In-Reply-To: References: <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> Message-ID: On Fri, Oct 5, 2012 at 4:52 PM, Devin Jeanpierre wrote: > On Fri, Oct 5, 2012 at 5:31 PM, Ian Kelly wrote: >> On Fri, Oct 5, 2012 at 2:19 PM, vasudevram wrote: >>> >>> http://jugad2.blogspot.in/2012/10/fmap-inverse-of-python-map-function.html >> >> Your fmap is a special case of reduce. > > So is map. I realize that. My point is that the function *feels* more like a variant of reduce than of map. > If it's meant as a complaint, it's a poor one. It's not. From christian at python.org Fri Oct 5 19:26:32 2012 From: christian at python.org (Christian Heimes) Date: Sat, 06 Oct 2012 01:26:32 +0200 Subject: instance.attribute lookup In-Reply-To: <506F1B69.8030800@stoneleaf.us> References: <506F1B69.8030800@stoneleaf.us> Message-ID: Am 05.10.2012 19:39, schrieb Ethan Furman: > I'm thinking step 1 is flat-out wrong and doesn't exist. Does anybody > know otherwise? The answer is confusing and also wrong. For instance it ignores the existence of __slots__, metaclasses and the different lookup strategy of __special__ methods in old style and new style classes. From ian.g.kelly at gmail.com Fri Oct 5 19:29:51 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Oct 2012 17:29:51 -0600 Subject: instance.attribute lookup In-Reply-To: <506F1B69.8030800@stoneleaf.us> References: <506F1B69.8030800@stoneleaf.us> Message-ID: On Fri, Oct 5, 2012 at 11:39 AM, Ethan Furman wrote: > There is a StackOverflow question [1] that points to this on-line book [2] > which has a five-step sequence for looking up attributes: > >> When retrieving an attribute from an object (print >> objectname.attrname) Python follows these steps: >> >> 1. If attrname is a special (i.e. Python-provided) attribute for >> objectname, return it. >> >> 2. Check objectname.__class__.__dict__ for attrname. If it exists and >> is a data-descriptor, return the descriptor result. Search all bases >> of objectname.__class__ for the same case. >> >> 3. Check objectname.__dict__ for attrname, and return if found. If >> objectname is a class, search its bases too. If it is a class and a >> descriptor exists in it or its bases, return the descriptor result. >> >> 4. Check objectname.__class__.__dict__ for attrname. If it exists and >> is a non-data descriptor, return the descriptor result. If it exists, >> and is not a descriptor, just return it. If it exists and is a data >> descriptor, we shouldn't be here because we would have returned at >> point 2. Search all bases of objectname.__class__ for same case. >> >> 5. Raise AttributeError > > I'm thinking step 1 is flat-out wrong and doesn't exist. Does anybody know > otherwise? I think step 1 refers to looking up attributes like "foo.__class__" or "foo.__dict__" themselves. From jeanpierreda at gmail.com Fri Oct 5 19:30:57 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 5 Oct 2012 19:30:57 -0400 Subject: fmap(), "inverse" of Python map() function In-Reply-To: References: <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> Message-ID: On Fri, Oct 5, 2012 at 7:24 PM, Ian Kelly wrote: > I realize that. My point is that the function *feels* more like a > variant of reduce than of map. > >> If it's meant as a complaint, it's a poor one. > > It's not. Fair enough all around. Sorry for misunderstanding. -- Devin From breamoreboy at yahoo.co.uk Fri Oct 5 19:32:44 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 06 Oct 2012 00:32:44 +0100 Subject: instance.attribute lookup In-Reply-To: <506F6956.2070502@stoneleaf.us> References: <506f668d$0$29978$c3e8da3$5496439d@news.astraweb.com> <506F6956.2070502@stoneleaf.us> Message-ID: On 06/10/2012 00:12, Ethan Furman wrote: > Steven D'Aprano wrote: >> On Fri, 05 Oct 2012 10:39:53 -0700, Ethan Furman wrote: >> >>> There is a StackOverflow question [1] that points to this on-line book >>> [2] which has a five-step sequence for looking up attributes: >>> >>> > When retrieving an attribute from an object (print >>> > objectname.attrname) Python follows these steps: >>> > >>> > 1. If attrname is a special (i.e. Python-provided) attribute for >>> > objectname, return it. >> [...] >>> I'm thinking step 1 is flat-out wrong and doesn't exist. Does anybody >>> know otherwise? >> >> I'm thinking I don't even understand what step 1 means. >> >> What's a Python-provided attribute, and how is it different from other >> attributes? > > Well, if /you/ don't understand it I feel a lot better about not > understanding it either! :) > > Glad to know I'm not missing something (besides ESP, a crystal ball, and > a mind-reader!) > > ~Ethan~ My probably highly uneducated guess is that "Python-provided attribute" refers to double underscore names. YMMV by several trillion light years :) -- Cheers. Mark Lawrence. From cs at zip.com.au Fri Oct 5 19:37:42 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 6 Oct 2012 09:37:42 +1000 Subject: + in regular expression In-Reply-To: <506EFC44.40508@cs.wisc.edu> References: <506EFC44.40508@cs.wisc.edu> Message-ID: <20121005233741.GA21277@cskk.homeip.net> On 05Oct2012 10:27, Evan Driscoll wrote: | I can understand that you can create a grammar that excludes it. [...] | Was it because such patterns often reveal a mistake? For myself, I would consider that sufficient reason. I've seen plenty of languages (C and shell, for example, though they are not alone or egrarious) where a compiler can emit a syntax complaint many lines from the actual coding mistake (in shell, an unclosed quote or control construct is a common examplei; Python has the same issue but mitigated by the indentation requirements which cut the occurence down a lot). Forbidding a common error by requiring a wordier workaround isn't unreasonable. | Because "\s{6}+" | has other meanings in different regex syntaxes and the designers didn't | want confusion? I think Python REs are supposed to be Perl compatible; ISTR an opening sentence to that effect... | Because it was simpler to parse that way? Because the | "hey you recognize regular expressions by converting it to a finite | automaton" story is a lie in most real-world regex implementations (in | part because they're not actually regular expressions) and repeated | quantifiers cause problems with the parsing techniques that actually get | used? There are certainly constructs that can cause an exponential amount of backtracking is misused. One could make a case for discouragement (though not a case for forbidding them). Just my 2c, -- Cameron Simpson The most annoying thing about being without my files after our disc crash was discovering once again how widespread BLINK was on the web. From skip at pobox.com Fri Oct 5 20:24:58 2012 From: skip at pobox.com (Skip Montanaro) Date: Fri, 5 Oct 2012 19:24:58 -0500 Subject: Problems building Python from hg trunk on Open SUSE Message-ID: I haven't messed around with Python 3 recently, so decided to give it a whirl again. I cloned the trunk (cpython) and set about it. This is on an OpenSUSE 12.1 system. I configured like so: ./configure --prefix=/home/skipm/.linux-local and ran the usual "make ; make install". I'm a bit perplexed about how it is installed. Instead of installing shared objects in /home/skipm/.linux-local/lib/python3.4/lib-dynload they were installed in /home/skipm/.linux-local/lib64/python3.4/lib-dynload (note the "lib64" vs. "lib"). This would be fine, except sys.path doesn't include the "lib64" version of this path: % PYTHONPATH= PYTHONSTARTUP= ~/.linux-local/bin/python3.4 -S Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] Python 3.4.0a0 (default:26200f535296, Oct 3 2012, 12:48:07) [GCC 4.4.6 [TWW]] on linux >>> import sys >>> sys.path ['', '', '/home/skipm/.linux-local/lib/python34.zip', '/home/skipm/.linux-local/lib/python3.4/', '/home/skipm/.linux-local/lib/python3.4/plat-linux', '/home/skipm/.linux-local/lib/lib-dynload'] I see the message about setting PYTHONHOME. (That happens to be bad advice as sys.prefix and sys.exec_prefix are identical in this case.) What I don't understand is why directories containing "lib64" are not in sys.path by default, given that that's where "make install" put things. GCC is as delivered by The Written Word. (This is a work computer. The powers that be settled on TWW awhile ago for packaging all open source software we use on Linux and Solaris, thus removing a headache from our support staff.) It is: % gcc --version gcc (GCC) 4.4.6 [TWW] Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. The architecture looks like this: % uname -a Linux udesktop264 3.1.0-1.2-desktop #1 SMP PREEMPT Thu Nov 3 14:45:45 UTC 2011 (187dde0) x86_64 x86_64 x86_64 GNU/Linux I don't see anything in the output of "./configure --help" which relates to 64-bit install directories, though I do see some lines in config.log about guessing the architecture. Some cursory googling didn't turn up any promising web pages, and I didn't find anything in the various documentation files in the repo related to building Python. Any suggestions about how to resolve this would be appreciated. Thx, Skip From eldiener at tropicsoft.invalid Fri Oct 5 20:51:36 2012 From: eldiener at tropicsoft.invalid (Edward Diener) Date: Fri, 05 Oct 2012 20:51:36 -0400 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: Message-ID: On 10/5/2012 5:32 PM, Dennis Lee Bieber wrote: > On Fri, 05 Oct 2012 08:15:30 -0400, Edward Diener > declaimed the following in > gmane.comp.python.general: > >> >> Windows installs of Python do not distinguish releases by Pythonx(.x) >> but just install different versions of Python in different directories. > > Really? > > E:\Python27>dir > Volume in drive E is Data > Volume Serial Number is 2626-D991 > > Directory of E:\Python27 > > 08/28/2012 05:32 PM . > 08/28/2012 05:32 PM .. > 08/28/2012 02:11 PM DLLs > 08/28/2012 05:43 PM Doc > 08/28/2012 02:11 PM include > 08/31/2012 04:58 PM Lib > 08/28/2012 02:11 PM libs > 08/28/2012 02:15 PM 108,255 matplotlib-wininst.log > 08/28/2012 02:18 PM 4,169 MySQL-python-wininst.log > 08/28/2012 02:15 PM 98,498 numpy-wininst.log > 08/28/2012 02:20 PM 17,816 PIL-wininst.log > 08/28/2012 03:29 PM 1,572 PyOpenGL-accelerate-wininst.log > 08/28/2012 03:38 PM 3,009 pyserial-wininst.log > > 06/24/2011 12:38 PM 27,136 python.exe **** > 06/24/2011 12:38 PM 27,136 python2.7.exe **** > 06/24/2011 12:38 PM 27,136 python2.exe **** > > 08/28/2012 05:32 PM 90,943 PythonCard-wininst.log > > 06/24/2011 12:38 PM 27,136 pythonw.exe **** > 06/24/2011 12:38 PM 27,136 pythonw2.7.exe **** > 06/24/2011 12:38 PM 27,136 pythonw2.exe **** That's, as you say, ActievState. The normal Python installer does not create a python2.7.exe etc. But of course I can create any links I want, so that's not really the problem. The major difficulty is that prior to invoking either "python" directly or a script with a normal Python file association, I want to be able to specify which version of Python should be invoked as the default without having to specifically invoke a partiocular version by typing 'python2.7 ...' or 'python3.3 ...' etc. > > 08/28/2012 02:15 PM 196,096 Removematplotlib.exe > 08/28/2012 02:18 PM 196,096 RemoveMySQL-python.exe > 08/28/2012 02:15 PM 196,096 Removenumpy.exe > 08/28/2012 02:20 PM 196,096 RemovePIL.exe > 08/28/2012 03:29 PM 196,096 RemovePyOpenGL-accelerate.exe > 08/28/2012 03:38 PM 196,096 Removepyserial.exe > 08/28/2012 05:32 PM 61,440 RemovePythonCard.exe > 08/28/2012 02:20 PM 196,096 Removereportlab.exe > 08/28/2012 02:19 PM 196,096 Removescipy.exe > 08/28/2012 05:29 PM 196,096 RemoveWConio.exe > 08/28/2012 02:20 PM 40,362 reportlab-wininst.log > 08/28/2012 02:19 PM 159,420 scipy-wininst.log > 08/28/2012 05:32 PM Scripts > 08/28/2012 02:11 PM tcl > 08/28/2012 02:11 PM Tools > 11/28/2007 04:32 PM 258,352 unicows.dll > 06/24/2011 12:38 PM 49,664 w9xpopen.exe > 08/28/2012 05:29 PM 891 WConio-wininst.log > 28 File(s) 2,822,071 bytes > 10 Dir(s) 148,557,684,736 bytes free > > E:\Python27> > > That's what was set up by a recent ActiveState installer (well, > recent for me -- I'd still been using 2.5 three months ago) > > Yes, it IS in a version numbered directory, but there are copies of > the executable named as plain python, pythonX, and pythonX.Y > > E:\Python27>cd %homepath% > > E:\UserData\Wulfraed\My Documents>python > ActivePython 2.7.2.5 (ActiveState Software Inc.) based on > Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> ^Z > > > E:\UserData\Wulfraed\My Documents>python2.7 > ActivePython 2.7.2.5 (ActiveState Software Inc.) based on > Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> > > Granted, one would need to have each installation directory in the > PATH, ordered such that the preferred version would be found first when > using just "python". There is much more than just the PATH needed to change to have a different Python be the default. File associations also. I thnk there are more things too, but I know it has always been difficult on Windows to easily change which distribution is called when "python" is executed or some Python file association is executed. I welcome the new Python launcher for Windows mentioned but have not had a chance to use it and see how it works yet. I will try it this weekend and hopefully it will work well to solve the problem of having multiple Python installations installed on Windows at the same time, and being able to easily specify the one I want invoked. From nad at acm.org Fri Oct 5 21:37:13 2012 From: nad at acm.org (Ned Deily) Date: Fri, 05 Oct 2012 18:37:13 -0700 Subject: Problems building Python from hg trunk on Open SUSE References: Message-ID: In article , Skip Montanaro wrote: > I haven't messed around with Python 3 recently, so decided to give it > a whirl again. I cloned the trunk (cpython) and set about it. This > is on an OpenSUSE 12.1 system. I configured like so: [...] > Any suggestions about how to resolve this would be appreciated. It looks like you're running into the problems described in: http://bugs.python.org/issue15631 -- Ned Deily, nad at acm.org From dihedral88888 at googlemail.com Fri Oct 5 21:43:49 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 5 Oct 2012 18:43:49 -0700 (PDT) Subject: notmm is dead! In-Reply-To: References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: Prasad, Ramit? 2012?10?6????UTC+8??4?06?31???? > Steven D'Aprano wrote: > > > Sent: Thursday, October 04, 2012 7:22 PM > > > To: python-list at python.org > > > Subject: Re: notmm is dead! > > > > > > On Thu, 04 Oct 2012 14:10:46 -0400, Etienne Robillard wrote: > > > > > > > Dear list, > > > > > > > > Due to lack of energy and resources i'm really sad to announce the > > > > removal of notmm from pypi and bitbucket. > > > > > > Well that's just rude. Even if you don't intend to maintain the software > > > any more, why are you removing it from pypi? Since you say you are a fan > > > of Open Source software, just flag it as unmaintained and leave it for > > > somebody else to pick up. > > > > > > If you are going to abandon the project, release it on PyPI with a dual > > > MIT and GPL licence, and let it be taken over by somebody else. > > > > > > If you were looking for sympathy here, starting off by removing your > > > project from free hosting, then complaining that you can't pay for the > > > non-free hosting, was NOT the right way to do so. > > > > I might be misunderstanding, but I think Etienne wants money in > > exchange for letting someone else take over. > > > > > > > > By the way, the latest version of notmm (0.4.4) has an empty licence > > > file. No licence means that everyone using it is unlicenced and therefore > > > infringing your copyright. > > > > > > > > > > > > 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. I think it is OK to have some string attatched in those open source projects. Nowadays the software industry is just like the perfume and prtinting and the audio-video entaertainment industry. The replication cost is so low. Don't forget the lawsuites in Facebook about the participants charged the founder in the courts. From dihedral88888 at googlemail.com Fri Oct 5 21:43:49 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 5 Oct 2012 18:43:49 -0700 (PDT) Subject: notmm is dead! In-Reply-To: References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: Prasad, Ramit? 2012?10?6????UTC+8??4?06?31???? > Steven D'Aprano wrote: > > > Sent: Thursday, October 04, 2012 7:22 PM > > > To: python-list at python.org > > > Subject: Re: notmm is dead! > > > > > > On Thu, 04 Oct 2012 14:10:46 -0400, Etienne Robillard wrote: > > > > > > > Dear list, > > > > > > > > Due to lack of energy and resources i'm really sad to announce the > > > > removal of notmm from pypi and bitbucket. > > > > > > Well that's just rude. Even if you don't intend to maintain the software > > > any more, why are you removing it from pypi? Since you say you are a fan > > > of Open Source software, just flag it as unmaintained and leave it for > > > somebody else to pick up. > > > > > > If you are going to abandon the project, release it on PyPI with a dual > > > MIT and GPL licence, and let it be taken over by somebody else. > > > > > > If you were looking for sympathy here, starting off by removing your > > > project from free hosting, then complaining that you can't pay for the > > > non-free hosting, was NOT the right way to do so. > > > > I might be misunderstanding, but I think Etienne wants money in > > exchange for letting someone else take over. > > > > > > > > By the way, the latest version of notmm (0.4.4) has an empty licence > > > file. No licence means that everyone using it is unlicenced and therefore > > > infringing your copyright. > > > > > > > > > > > > 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. I think it is OK to have some string attatched in those open source projects. Nowadays the software industry is just like the perfume and prtinting and the audio-video entaertainment industry. The replication cost is so low. Don't forget the lawsuites in Facebook about the participants charged the founder in the courts. From hexusnexus at gmail.com Fri Oct 5 22:20:03 2012 From: hexusnexus at gmail.com (Jason Benjamin) Date: Fri, 05 Oct 2012 19:20:03 -0700 Subject: calendar from python to html In-Reply-To: References: Message-ID: Well, you need a web server, a webpage, a database (could just be a file), a cgi script, and the datetime module. Optionally, you can use a web framework like CherryPy or Django, which covers a lot of these by itself. I only know Python 2, but here are some examples: A basic web server: webdir = '.' port = 80 import os, sys from BaseHTTPServer import HTTPServer from CGIHTTPServer import CGIHTTPRequestHandler if len(sys.argv) > 1: webdir = sys.argv[1] if len(sys.argv) > 2: port = int(sys.argv[2]) print 'webdir "%s", port %s' % (webdir, port) #Windows only hack if sys.platform[:3] == 'win': CGIHTTPRequestHandler.have_popen2 = False CGIHTTPRequestHandler.have_popen3 = False sys.path.append('cgi-bin') os.chdir(webdir) srvraddr = ("", port) srvrobj = HTTPServer(srvraddr, CGIHTTPRequestHandler) srvrobj.serve_forever() Start the script in the same directory as the cgi script and HTML. Assuming you have a file that holds '1' time per date, you could write a program to pickle and unpickle dictionaries that are derived from form data: import pickle import cgi file = open('dates.pkl', 'rb') mydates = pickle.load(file) file.close() html = """

Schedule

""" dates = ['april01', 'april02', 'april03', 'april04'] if form.has_key('submitted'): newdates = {} for d in dates: if form.has_key(d): newdates[d] = form[d].value else: newdates[d] = '' mydates = newdates output = open('dates.pkl', 'wb') pickle.dump(mydates, output) output.close() else: for d in dates: if not mydates.has_key(d): mydates[d] = '' print html % mydates Then you could write an additional program that runs in the background or something: import pickle from datetime import date, datetime mycode = 'print "Hello World!"' file = open('dates.pkl', 'rb') mydates = pickle.load(file) file.close() while True: today = date.today() if today.month == 4 and today.day == 01: hour = datetime.time(datetime.now()).hour min = datetime.time(datetime.now()).minute if hour == int(mydates['april04'][0]) and min == int(mydates['april04'][-2:]): exec mycode _exec_ executes a Python string like a program. To execute an actual python script use subprocess instead: import subprocess subprocess.call(["python", "myscript.py"]) Hope this helps. On 10/05/2012 11:55 AM, Luca Sanna wrote: > hi, > > I enter a calendar in an html page > in each calendar day, I enter a time that is used by the program to perform actions with python > > What can I use to do this? > > thanks > From torriem at gmail.com Fri Oct 5 22:58:46 2012 From: torriem at gmail.com (Michael Torrie) Date: Fri, 05 Oct 2012 20:58:46 -0600 Subject: notmm is dead! In-Reply-To: References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: <506F9E66.3050302@gmail.com> On 10/05/2012 07:43 PM, 88888 Dihedral wrote: > I think it is OK to have some string attatched in those open source projects. What are you talking about? What "string?" > Nowadays the software industry is just like the perfume and prtinting > and the audio-video entaertainment industry. True > The replication cost is so low. Don't forget the lawsuites in Facebook > about the participants charged the founder in the courts. What do lawsuits have to do with replication costs? I suppose a person can fail a turing test... From palmeira at gmail.com Fri Oct 5 23:27:36 2012 From: palmeira at gmail.com (palmeira) Date: Fri, 5 Oct 2012 20:27:36 -0700 (PDT) Subject: write binary with struct.pack_into Message-ID: <1349494056881-4991234.post@n6.nabble.com> Dear pythonists, I'm having a problem with read/write binary in python. I have a binary file that I need to read information, extract a array, modify this array and put these values into file again in same binary format. I need to use unpack_from and pack_into because sometimes gonna need read/write in the middle of file. Script: import struct bloco='>%df' %(252) #Binary format # READ fa=open('testIN.bin') my_array=struct.unpack_from(bloco,fa.read()[0*4:251*4]) # my_aray = 252 elements array ## This read is OK! #WRITE fb=open('testOUT.bin') test=struct.pack_into(bloco,fb.write()[0*4:251*4]) # ERROR in this WRITE Regards, Ronaldo Palmeira. -- View this message in context: http://python.6.n6.nabble.com/write-binary-with-struct-pack-into-tp4991234.html Sent from the Python - python-list mailing list archive at Nabble.com. From k.sahithi2862 at gmail.com Sat Oct 6 00:27:15 2012 From: k.sahithi2862 at gmail.com (SAHITHI) Date: Fri, 5 Oct 2012 21:27:15 -0700 (PDT) Subject: HOT TEMPTING PHOTOS & VIDEOS Message-ID: KEERIPULLA TAMIL MOVIE HOT PHOTOS http://actressgallery-images.blogspot.in/2012/10/keeripulla-movie-gallery.html CHIKKI MUKKI TAMIL MOVIE HOT SPICY GALLERY http://actressgallery-images.blogspot.in/2012/10/chikki-mukki-movie-gallery.html REGINA NEW ACTRESS HOT PHOTOS http://actressgallery-images.blogspot.in/2012/10/regina-actress.html Krishnam Vande Jagadgurum Telugu Movie Photos Stills http://actressgallery-images.blogspot.in/2012/10/krishnam-vande-jagadgurum-stills.html KAJL AGARWAL SPICY STILLS IN BROTHERS MOVIE http://actressgallery-images.blogspot.in/2012/10/brothers-movie-photos.html Cameraman Gangatho Rambabu Movie Stills http://actressgallery-images.blogspot.in/2012/10/cameraman-gangatho-rambabu-movie-stills.html DAMARUKAM MOVIE HOT SPCY GALLERY http://actressgallery-images.blogspot.in/2012/10/damarukam-movie-stills.html ACTRESS POORNA LATEST HOT PHOTOS http://actressgallery-images.blogspot.in/2012/09/poorna.html PRABHAS REBEL MOVIE STILLS http://actressgallery-images.blogspot.in/2012/09/rebel-movie-stills.html AGNATHAM MOVIE WALLPAPERS http://actressgallery-images.blogspot.in/2012/09/agnatham-movie-stills.html SADA HOT STILLS IN MYTHILI MOVIE http://actressgallery-images.blogspot.in/2012/09/mythili-movie-stills.html RIYA CHAKRAVARTHI LATEST GALLERY http://actressgallery-images.blogspot.in/2012/09/ria-chakravarthi.html TELISI TELIYAKA MOVIE STILLS http://actressgallery-images.blogspot.in/2012/09/telisi-teliyaka-movie-stills.html LIVE MOVIE LATEST PHOTOS http://actressgallery-images.blogspot.in/2012/09/live-movie-stills.html ANAGARIGAM 2 MOVIE HOT STILLS http://actressgallery-images.blogspot.in/2012/08/anagarigam-2-movie-stills.html CHARULATHA MOVIE SPICY STILLS http://actressgallery-images.blogspot.in/2012/08/charulatha-telugu-movie-images.html SAIBABA MOVIE IMAGES http://actressgallery-images.blogspot.in/2012/08/nagarjuna-shridi-sai-movie-stills.html SRIDEVI ENGLISH VINGLISH MOVIE IMAGES http://actressgallery-images.blogspot.in/2012/08/sri-devi-english-vinglish-movie-stills.html FOR HOT GIRLS YOUTUBE VIDEOS HYDREBADI LOVERS VIDEO http://youtu.be/835RKstl5WY University Girls Party EnjoymentVideo http://youtu.be/xvKiwWcDDM0 Hostel girls Secret Enjoyments Video http://youtu.be/LiX__IFTBoo Girls Dance ForBollywood Latest hits Video http://youtu.be/-5PDndnMPro Engineering college girls Enjoyment Video http://youtu.be/8itq-a9Mp_c GIRAFFE VIDEO IN ZOOPARK Video http://youtu.be/JTd9BWU9_4o LOVERS ENJOYMENT VIDEOS IN PARKS Video http://youtu.be/835RKstl5WY Crazy Cheer GirlsSuper Dance Videos http://youtu.be/f91izd0BdyU Yuvraj Singh Smashes Pakistan Bowler http://youtu.be/9y-kPCP0Ku4 Crazy Girl Super Dance http://youtu.be/f91izd0BdyU COMPLICATED TRUE LOVE STORY http://youtu.be/MUE_rZ0onsc Amrutha First night videos http://youtu.be/vk2foRUABao ENGENEERING COLLEGE GIRLS ENJOYMENT VIDOES http://youtu.be/8itq-a9Mp_c From dihedral88888 at googlemail.com Sat Oct 6 00:39:09 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 5 Oct 2012 21:39:09 -0700 (PDT) Subject: write binary with struct.pack_into In-Reply-To: References: Message-ID: <161b9212-9e78-4e88-b6dc-98a8b5cb285e@googlegroups.com> palmeira? 2012?10?6????UTC+8??11?27?47???? > Dear pythonists, > > > > I'm having a problem with read/write binary in python. > > I have a binary file that I need to read information, extract a array, > > modify this array and put these values into file again in same binary > > format. > > I need to use unpack_from and pack_into because sometimes gonna need > > read/write in the middle of file. > > > > Script: > > > > import struct > > bloco='>%df' %(252) #Binary format > > > > # READ > > fa=open('testIN.bin') > > my_array=struct.unpack_from(bloco,fa.read()[0*4:251*4]) # my_aray = 252 > > elements array > > ## This read is OK! > > > > #WRITE > > fb=open('testOUT.bin') > > test=struct.pack_into(bloco,fb.write()[0*4:251*4]) # ERROR in this WRITE > > > > > > > > > > Regards, > > > > Ronaldo Palmeira. > > > > > > > > > > -- > > View this message in context: http://python.6.n6.nabble.com/write-binary-with-struct-pack-into-tp4991234.html > > Sent from the Python - python-list mailing list archive at Nabble.com. Are you writing and reading files produce by different languages? The pickle part is better for OOP and glue logics in python. The heavy computing part should be done in CYTHON. From dihedral88888 at googlemail.com Sat Oct 6 00:39:09 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 5 Oct 2012 21:39:09 -0700 (PDT) Subject: write binary with struct.pack_into In-Reply-To: References: Message-ID: <161b9212-9e78-4e88-b6dc-98a8b5cb285e@googlegroups.com> palmeira? 2012?10?6????UTC+8??11?27?47???? > Dear pythonists, > > > > I'm having a problem with read/write binary in python. > > I have a binary file that I need to read information, extract a array, > > modify this array and put these values into file again in same binary > > format. > > I need to use unpack_from and pack_into because sometimes gonna need > > read/write in the middle of file. > > > > Script: > > > > import struct > > bloco='>%df' %(252) #Binary format > > > > # READ > > fa=open('testIN.bin') > > my_array=struct.unpack_from(bloco,fa.read()[0*4:251*4]) # my_aray = 252 > > elements array > > ## This read is OK! > > > > #WRITE > > fb=open('testOUT.bin') > > test=struct.pack_into(bloco,fb.write()[0*4:251*4]) # ERROR in this WRITE > > > > > > > > > > Regards, > > > > Ronaldo Palmeira. > > > > > > > > > > -- > > View this message in context: http://python.6.n6.nabble.com/write-binary-with-struct-pack-into-tp4991234.html > > Sent from the Python - python-list mailing list archive at Nabble.com. Are you writing and reading files produce by different languages? The pickle part is better for OOP and glue logics in python. The heavy computing part should be done in CYTHON. From maniandram01 at gmail.com Sat Oct 6 01:53:17 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 5 Oct 2012 22:53:17 -0700 (PDT) Subject: notmm is dead! In-Reply-To: References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: On Saturday, 6 October 2012 08:29:02 UTC+5:30, Michael Torrie wrote: > On 10/05/2012 07:43 PM, 88888 Dihedral wrote: > > > I think it is OK to have some string attatched in those open source projects. > > > > What are you talking about? What "string?" > > > > > Nowadays the software industry is just like the perfume and prtinting > > > and the audio-video entaertainment industry. > > > > True > > > > > The replication cost is so low. Don't forget the lawsuites in Facebook > > > about the participants charged the founder in the courts. > > > > What do lawsuits have to do with replication costs? > > > > I suppose a person can fail a turing test... You are talking to a bot. From maniandram01 at gmail.com Sat Oct 6 01:53:17 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Fri, 5 Oct 2012 22:53:17 -0700 (PDT) Subject: notmm is dead! In-Reply-To: References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: On Saturday, 6 October 2012 08:29:02 UTC+5:30, Michael Torrie wrote: > On 10/05/2012 07:43 PM, 88888 Dihedral wrote: > > > I think it is OK to have some string attatched in those open source projects. > > > > What are you talking about? What "string?" > > > > > Nowadays the software industry is just like the perfume and prtinting > > > and the audio-video entaertainment industry. > > > > True > > > > > The replication cost is so low. Don't forget the lawsuites in Facebook > > > about the participants charged the founder in the courts. > > > > What do lawsuits have to do with replication costs? > > > > I suppose a person can fail a turing test... You are talking to a bot. From mpg at elzevir.fr Sat Oct 6 02:27:25 2012 From: mpg at elzevir.fr (Manuel =?iso-8859-1?q?P=E9gouri=E9-Gonnard?=) Date: Sat, 6 Oct 2012 08:27:25 +0200 (CEST) Subject: try/except KeyError vs "if name in ..." Message-ID: Hi, I was looking at the example found here [1] which begins with: [1] http://docs.python.org/py3k/library/imp.html#examples def __import__(name, globals=None, locals=None, fromlist=None): # Fast path: see if the module has already been imported. try: return sys.modules[name] except KeyError: pass I was wondering if the formulation if name in sys.modules: return sys.modules[name] would be equivalent. IOW, is using try/except here only a matter of style or a necessity? I'm suspecting that maybe, in multithreaded environments, the second option may be subject to a race condition, if another thread removes name frome sys.modules between the if and the return, but as I'm not very familiar (yet) with Python threads, I'm not sure it is a real concern here. And maybe there are other reasons I'm completely missing for prefering EAFP over LBYL here? Thanks in advance for your comments. -- Manuel P?gouri?-Gonnard - http://people.math.jussieu.fr/~mpg/ From rosuav at gmail.com Sat Oct 6 02:51:17 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Oct 2012 16:51:17 +1000 Subject: write binary with struct.pack_into In-Reply-To: <1349494056881-4991234.post@n6.nabble.com> References: <1349494056881-4991234.post@n6.nabble.com> Message-ID: On Sat, Oct 6, 2012 at 1:27 PM, palmeira wrote: > import struct > bloco='>%df' %(252) #Binary format > > # READ > fa=open('testIN.bin') > my_array=struct.unpack_from(bloco,fa.read()[0*4:251*4]) # my_aray = 252 > elements array > ## This read is OK! > > #WRITE > fb=open('testOUT.bin') > test=struct.pack_into(bloco,fb.write()[0*4:251*4]) # ERROR in this WRITE You have a beautiful parallel here, but I think that's where your problem is. In the READ section, you have fa.read() which will read the whole file, and then you slice the resulting string. That's pretty inefficient for large files, but it'll work. But when you write, that completely does not work. (Even assuming you've opened read/write, per Dennis's comment.) >>> fb.write() Traceback (most recent call last): File "", line 1, in fb.write() TypeError: write() takes exactly 1 argument (0 given) It needs an argument of what to write out, it doesn't return a writable buffer suitable for pack_into. I recommend you completely rewrite your file handling to use actual seeks and file writes. Also, you'll want (I think) to use binary mode on your files; character encodings don't mean much when you're working with arrays of numbers. Finally, when you post issues, "ERROR in this WRITE" isn't very helpful. Please please post the full traceback (like in my trivial example above), as problems will be much more visible. Hope that's of some value! ChrisA From rosuav at gmail.com Sat Oct 6 03:19:20 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Oct 2012 17:19:20 +1000 Subject: Executing untrusted scripts in a sandboxed environment In-Reply-To: <4hrls608xbax633ej6s1n54j.1349475464556@email.android.com> References: <4hrls608xbax633ej6s1n54j.1349475464556@email.android.com> Message-ID: On Sat, Oct 6, 2012 at 8:22 AM, Robin Krahl wrote: > Hi all, > > I need to execute untrusted scripts in my Python application. To avoid security issues, I want to use a sandboxed environment. This means that the script authors have no access to the file system. They may only access objects, modules and classes that are "flagged" or "approved" for scripting. > > I read that I will not be able to do this with Python scripts. (See SandboxedPython page in the Python wiki [0] and several SE.com questions, e. g. [1].) So my question is: What is the best way to "embed" a script engine in a sandboxed environment that has access to the Python modules and classes that I provide? With extreme difficulty. A while back (couple years maybe? I don't remember), I ignored everyone's warnings and tried to make a sandboxed Python, embedded in a C++ application. It failed in sandboxing. With just some trivial tinkering using Python's introspection facilities, a couple of python-list people managed to read and write files, and other equally dangerous actions. Shortly thereafter, we solved the problem completely... by switching to JavaScript. Embedding CPython in an application simply doesn't afford sandboxing. To what extent do you actually need to run untrusted Python? Can you, for instance, sandbox the entire process (which wasn't an option for what we were doing)? Perhaps chrooting the Python interpreter will do what you need. But there may still be leaks, I don't know. ChrisA From wxjmfauth at gmail.com Sat Oct 6 03:27:41 2012 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 6 Oct 2012 00:27:41 -0700 (PDT) Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: References: Message-ID: <314ffb69-c89b-42f6-9af1-61005056ef91@googlegroups.com> Using Python on Windows is a dream. Python uses and needs the system, but the system does not use Python. Every Python version is installed in its own isolated space, site-packages included and without any defined environment variable. Every Python can be seen as a different application. Knowing this, it is a no-problem to use the miscellaneous versions; can be with the console, with an editor, with .bat or .cmd files, with the Windows "start menu" launcher, ... like any application. The file extension is a double sword. Do not use it or unregister it, the msi installer allows to do this. It is the same task/problem as with any file, .txt, .png, ... The new Python launcher is a redondant tool. A point of view from a multi-users desktop user. ---- In my mind, it is a mistake to deliver a ready preconfigurated installation. "TeX" (I may say, as usual) is doing fine. A "TeX" installation consists usually only in "TeX" engines installation/configuration. It let the user work the way he wishes. jmf From __peter__ at web.de Sat Oct 6 03:45:03 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 06 Oct 2012 09:45:03 +0200 Subject: write binary with struct.pack_into References: <1349494056881-4991234.post@n6.nabble.com> Message-ID: palmeira wrote: > Dear pythonists, > > I'm having a problem with read/write binary in python. > I have a binary file that I need to read information, extract a array, > modify this array and put these values into file again in same binary > format. > I need to use unpack_from and pack_into because sometimes gonna need > read/write in the middle of file. Use pack/unpack and file.seek() instead. > Script: > > import struct > bloco='>%df' %(252) #Binary format > > # READ > fa=open('testIN.bin') > my_array=struct.unpack_from(bloco,fa.read()[0*4:251*4]) # my_aray = 252 > elements array > ## This read is OK! > > #WRITE > fb=open('testOUT.bin') > test=struct.pack_into(bloco,fb.write()[0*4:251*4]) # ERROR in this WRITE However, I think you have picked the wrong API. So: # untested import sys import array offset = 0 N = 252 a = array.array("f") with open("testIN.bin", "rb") as f: f.seek(offset) a.read(f, N) if sys.byteorder == "little": a.byteswap() # process a if sys.byteorder == "little": a.byteswap() with open("testOUT.bin", "wb") as f: f.seek(offset) a.write(f) From steve+comp.lang.python at pearwood.info Sat Oct 6 04:33:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Oct 2012 08:33:19 GMT Subject: try/except KeyError vs "if name in ..." References: Message-ID: <506feccf$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Oct 2012 08:27:25 +0200, Manuel P?gouri?-Gonnard wrote: > Hi, > > I was looking at the example found here [1] which begins with: > > [1] http://docs.python.org/py3k/library/imp.html#examples > > def __import__(name, globals=None, locals=None, fromlist=None): > # Fast path: see if the module has already been imported. try: > return sys.modules[name] > except KeyError: > pass > > I was wondering if the formulation > > if name in sys.modules: > return sys.modules[name] > > would be equivalent. IOW, is using try/except here only a matter of > style or a necessity? Mostly style, but not entirely. If you expect that most of the time the module will be found, the try...except version will be faster. If you expect that most of the time the module will not be found, the "if name in" version will be faster. But see also: > I'm suspecting that maybe, in multithreaded environments, the second > option may be subject to a race condition, if another thread removes > name frome sys.modules between the if and the return, but as I'm not > very familiar (yet) with Python threads, I'm not sure it is a real > concern here. In practice, no, it would be very unusual for another thread to remove the name from sys.modules. So don't do that :) But in principle, yes, it is a race condition and yes it is a (small) concern. Since it is so easy to avoid even this tiny risk, why not use the try...except version and avoid it completely? -- Steven From gd.usenet at spamfence.net Sat Oct 6 04:49:55 2012 From: gd.usenet at spamfence.net (=?ISO-8859-1?Q?G=FCnther?= Dietrich) Date: Sat, 06 Oct 2012 10:49:55 +0200 Subject: try/except KeyError vs "if name in ..." References: Message-ID: Manuel P?gouri?-Gonnard wrote: >Hi, >I was looking at the example found here [1] which begins with: > >[1] http://docs.python.org/py3k/library/imp.html#examples > >def __import__(name, globals=None, locals=None, fromlist=None): > # Fast path: see if the module has already been imported. > try: > return sys.modules[name] > except KeyError: > pass > >I was wondering if the formulation > > if name in sys.modules: > return sys.modules[name] > >would be equivalent. IOW, is using try/except here only a matter of >style or a necessity? Somewhere I read a text regarding 'try:' versus 'if'. If you take the probabitility into consideration, how many times the test will fail or succeed, there are two possibilities: - If the test will fail only on very rare occasions: Use 'try:'. When the statement(s) in the try-path succeed, the try:/except: construct will not consume additional execution time (not even for the test). The statements will just be executed as they are. Only in the (rare) case of failure, the exception handling will take additional execution time (a considerably big amount). The fact, that in python it is not named 'error handling', but 'exception handling' reflects this. The failure should be the exception, also in matters of occurrence. - If the relation between success and failure is not predictable, or if the case of failure will be frequent, use 'if'. The failure of a 'try:' gives you a penalty in form of consumption of a high amount of execution time. So, in these constellations, it is better to accept the relatively small amount of execution time taken by the explicit test. Obviously, you can use 'try:' only, if there is the possibility to produce an exception on failure. In the other cases you must use the explicit test by 'if'. >I'm suspecting that maybe, in multithreaded environments, the second >option may be subject to a race condition, if another thread removes >name frome sys.modules between the if and the return, but as I'm not >very familiar (yet) with Python threads, I'm not sure it is a real >concern here. Your idea sounds reasonable, but I also am not yet familiar with threads. >And maybe there are other reasons I'm completely missing for prefering >EAFP over LBYL here? One reason might be what I described above. Best regards, G?nther From maniandram01 at gmail.com Sat Oct 6 05:10:20 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 6 Oct 2012 02:10:20 -0700 (PDT) Subject: Executing untrusted scripts in a sandboxed environment In-Reply-To: References: <4hrls608xbax633ej6s1n54j.1349475464556@email.android.com> Message-ID: <3585c6f6-4152-4163-873b-396a0f73ba3b@googlegroups.com> On Saturday, 6 October 2012 12:49:29 UTC+5:30, Chris Angelico wrote: > On Sat, Oct 6, 2012 at 8:22 AM, Robin Krahl wrote: > > > Hi all, > > > > > > I need to execute untrusted scripts in my Python application. To avoid security issues, I want to use a sandboxed environment. This means that the script authors have no access to the file system. They may only access objects, modules and classes that are "flagged" or "approved" for scripting. > > > > > > I read that I will not be able to do this with Python scripts. (See SandboxedPython page in the Python wiki [0] and several SE.com questions, e. g. [1].) So my question is: What is the best way to "embed" a script engine in a sandboxed environment that has access to the Python modules and classes that I provide? > > > > With extreme difficulty. A while back (couple years maybe? I don't > > remember), I ignored everyone's warnings and tried to make a sandboxed > > Python, embedded in a C++ application. It failed in sandboxing. With > > just some trivial tinkering using Python's introspection facilities, a > > couple of python-list people managed to read and write files, and > > other equally dangerous actions. Shortly thereafter, we solved the > > problem completely... by switching to JavaScript. > > > > Embedding CPython in an application simply doesn't afford sandboxing. > > To what extent do you actually need to run untrusted Python? Can you, > > for instance, sandbox the entire process (which wasn't an option for > > what we were doing)? Perhaps chrooting the Python interpreter will do > > what you need. But there may still be leaks, I don't know. > > > > ChrisA Something like ast.literal_eval may be useful. From maniandram01 at gmail.com Sat Oct 6 05:11:54 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 6 Oct 2012 02:11:54 -0700 (PDT) Subject: Executing untrusted scripts in a sandboxed environment In-Reply-To: References: Message-ID: <90140a07-b532-4de7-b764-233d1bb487b4@googlegroups.com> On Saturday, 6 October 2012 04:00:08 UTC+5:30, Robin Krahl wrote: > Hi all, > > I need to execute untrusted scripts in my Python application. To avoid security issues, I want to use a sandboxed environment. This means that the script authors have no access to the file system. They may only access objects, modules and classes that are "flagged" or "approved" for scripting. > > I read that I will not be able to do this with Python scripts. (See SandboxedPython page in the Python wiki [0] and several SE.com questions, e. g. [1].) So my question is: What is the best way to "embed" a script engine in a sandboxed environment that has access to the Python modules and classes that I provide? > > Thanks for your help. > > Best regards, > Robin > > [0] http://wiki.python.org/moin/SandboxedPython > [1] http://stackoverflow.com/questions/3068139/how-can-i-sandbox-python-in-pure-python >From http://wiki.python.org/moin/SandboxedPython "The Java and CLR/.NET runtimes support restricted execution, and these can be utilised through the Jython and IronPython variants of Python (as well as by other languages, obviously)." You can also check out http://doc.pypy.org/en/latest/sandbox.html for PyPy's sandbox From maniandram01 at gmail.com Sat Oct 6 05:11:54 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 6 Oct 2012 02:11:54 -0700 (PDT) Subject: Executing untrusted scripts in a sandboxed environment In-Reply-To: References: Message-ID: <90140a07-b532-4de7-b764-233d1bb487b4@googlegroups.com> On Saturday, 6 October 2012 04:00:08 UTC+5:30, Robin Krahl wrote: > Hi all, > > I need to execute untrusted scripts in my Python application. To avoid security issues, I want to use a sandboxed environment. This means that the script authors have no access to the file system. They may only access objects, modules and classes that are "flagged" or "approved" for scripting. > > I read that I will not be able to do this with Python scripts. (See SandboxedPython page in the Python wiki [0] and several SE.com questions, e. g. [1].) So my question is: What is the best way to "embed" a script engine in a sandboxed environment that has access to the Python modules and classes that I provide? > > Thanks for your help. > > Best regards, > Robin > > [0] http://wiki.python.org/moin/SandboxedPython > [1] http://stackoverflow.com/questions/3068139/how-can-i-sandbox-python-in-pure-python >From http://wiki.python.org/moin/SandboxedPython "The Java and CLR/.NET runtimes support restricted execution, and these can be utilised through the Jython and IronPython variants of Python (as well as by other languages, obviously)." You can also check out http://doc.pypy.org/en/latest/sandbox.html for PyPy's sandbox From rosuav at gmail.com Sat Oct 6 05:23:16 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Oct 2012 19:23:16 +1000 Subject: Executing untrusted scripts in a sandboxed environment In-Reply-To: <3585c6f6-4152-4163-873b-396a0f73ba3b@googlegroups.com> References: <4hrls608xbax633ej6s1n54j.1349475464556@email.android.com> <3585c6f6-4152-4163-873b-396a0f73ba3b@googlegroups.com> Message-ID: On Sat, Oct 6, 2012 at 7:10 PM, Ramchandra Apte wrote: > On Saturday, 6 October 2012 12:49:29 UTC+5:30, Chris Angelico wrote: >> On Sat, Oct 6, 2012 at 8:22 AM, Robin Krahl wrote: >> > What is the best way to "embed" a script engine in a sandboxed environment that has access to the Python modules and classes that I provide? >> >> With extreme difficulty. > > Something like ast.literal_eval may be useful. Not really; it's hardly sufficient. That sort of feature is handy for making an expression evaluator; for instance, you could implement a powerful calculator with it. But it's far too limited for most applications. The main problem is permitting some of the basic builtins (like True, False, len(), etc), without those objects being used as gateways. Did you know, for instance, that len.__self__.open() can be used to read and write files on the file system? ChrisA From mpg at elzevir.fr Sat Oct 6 06:08:26 2012 From: mpg at elzevir.fr (Manuel =?iso-8859-1?q?P=E9gouri=E9-Gonnard?=) Date: Sat, 6 Oct 2012 12:08:26 +0200 (CEST) Subject: try/except KeyError vs "if name in ..." References: <506feccf$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano scripsit : > If you expect that most of the time the module will be found, the > try...except version will be faster. If you expect that most of the time > the module will not be found, the "if name in" version will be faster. > Ok. In the particular case of __import__, I guess speed is not crucial since I doubt import often happen within a program's inner loop. But I'll remember that point for other cases anyway. >> I'm suspecting that maybe, in multithreaded environments, the second >> option may be subject to a race condition, if another thread removes >> name frome sys.modules between the if and the return, but as I'm not >> very familiar (yet) with Python threads, I'm not sure it is a real >> concern here. > > In practice, no, it would be very unusual for another thread to remove > the name from sys.modules. So don't do that :) > That wasn't my intention. But sometimes other people may be "creative" :) > But in principle, yes, it is a race condition and yes it is a (small) > concern. Since it is so easy to avoid even this tiny risk, why not use > the try...except version and avoid it completely? > Ok. Thanks for your explanations. -- Manuel P?gouri?-Gonnard - http://people.math.jussieu.fr/~mpg/ From sajuptpm at gmail.com Sat Oct 6 06:09:30 2012 From: sajuptpm at gmail.com (sajuptpm) Date: Sat, 6 Oct 2012 03:09:30 -0700 (PDT) Subject: Unpaking Tuple Message-ID: <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> Hi, I am using python 2.6. I need a way to make following code working without any ValueError . >>> a, b, c, d = (1,2,3,4) >>> a, b, c, d = (1,2,3). Note: Number of values in the tuple will change dynamically. I know in python 3, you can do `a, b, c, *d = (1, 2, 3)` and then d will contain any elements that didn't fit into a,b,c. Regards, Saju From mpg at elzevir.fr Sat Oct 6 06:09:35 2012 From: mpg at elzevir.fr (Manuel =?iso-8859-1?q?P=E9gouri=E9-Gonnard?=) Date: Sat, 6 Oct 2012 12:09:35 +0200 (CEST) Subject: try/except KeyError vs "if name in ..." References: Message-ID: G?nther Dietrich scripsit : > Somewhere I read a text regarding 'try:' versus 'if'. If you take the > probabitility into consideration, how many times the test will fail or > succeed, there are two possibilities: [...] Ok, thanks for the details! -- Manuel P?gouri?-Gonnard - http://people.math.jussieu.fr/~mpg/ From clp2 at rebertia.com Sat Oct 6 06:27:52 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Oct 2012 03:27:52 -0700 Subject: Unpaking Tuple In-Reply-To: <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> References: <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> Message-ID: On Sat, Oct 6, 2012 at 3:09 AM, sajuptpm wrote: > Hi, > > I am using python 2.6. > > I need a way to make following code working without any ValueError . >>>> a, b, c, d = (1,2,3,4) >>>> a, b, c, d = (1,2,3). > > Note: Number of values in the tuple will change dynamically. Then you arguably want a list, not a tuple. But at any rate: shortfall = 4 - len(your_tuple) your_tuple += (None,) * shortfall # assuming None is a suitable default a, b, c, d = your_tuple If you also need to handle the "too many items" case, use slicing: a, b, c, d = your_tuple[:4] Cheers, Chris From breamoreboy at yahoo.co.uk Sat Oct 6 06:36:49 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 06 Oct 2012 11:36:49 +0100 Subject: Executing untrusted scripts in a sandboxed environment In-Reply-To: <4hrls608xbax633ej6s1n54j.1349475464556@email.android.com> References: <4hrls608xbax633ej6s1n54j.1349475464556@email.android.com> Message-ID: On 05/10/2012 23:22, Robin Krahl wrote: > Hi all, > > I need to execute untrusted scripts in my Python application. To avoid security issues, I want to use a sandboxed environment. This means that the script authors have no access to the file system. They may only access objects, modules and classes that are "flagged" or "approved" for scripting. > > I read that I will not be able to do this with Python scripts. (See SandboxedPython page in the Python wiki [0] and several SE.com questions, e. g. [1].) So my question is: What is the best way to "embed" a script engine in a sandboxed environment that has access to the Python modules and classes that I provide? > > Thanks for your help. > > Best regards, > Robin > > [0] http://wiki.python.org/moin/SandboxedPython > [1] http://stackoverflow.com/questions/3068139/how-can-i-sandbox-python-in-pure-python > As good a starting point as any http://www.velocityreviews.com/forums/t716131-challenge-escape-from-the-pysandbox.html ? Also throw "python experimental sandbox" into your search engine and follow your nose, something might come up smelling of roses :) -- Cheers. Mark Lawrence. From d at davea.name Sat Oct 6 07:36:11 2012 From: d at davea.name (Dave Angel) Date: Sat, 06 Oct 2012 07:36:11 -0400 Subject: try/except KeyError vs "if name in ..." In-Reply-To: References: Message-ID: <507017AB.8090507@davea.name> On 10/06/2012 02:27 AM, Manuel P?gouri?-Gonnard wrote: > Hi, > > I was looking at the example found here [1] which begins with: > > [1] http://docs.python.org/py3k/library/imp.html#examples > > def __import__(name, globals=None, locals=None, fromlist=None): > # Fast path: see if the module has already been imported. > try: > return sys.modules[name] > except KeyError: > pass > > I was wondering if the formulation > > if name in sys.modules: > return sys.modules[name] > > would be equivalent. IOW, is using try/except here only a matter of > style or a necessity? > > I'm suspecting that maybe, in multithreaded environments, the second > option may be subject to a race condition, if another thread removes > name frome sys.modules between the if and the return, but as I'm not > very familiar (yet) with Python threads, I'm not sure it is a real > concern here. > > And maybe there are other reasons I'm completely missing for prefering > EAFP over LBYL here? > > Thanks in advance for your comments. > Guidelines for writing library code may very well be different than for writing your application. And if your application is trying to do something similar with *import*, chances are that it's calling a library function that already starts with the test against sys.modules. So if this is an application question, the answer is probably "don't do either one, just do the import, checking for the exceptions that it may throw." The distinction in performance between the success and failure modes of the try/catch isn't nearly as large as one of the other responses might lead you to believe. For example, a for loop generally terminates with a raise (of StopIteration exception), and that doesn't convince us to replace it with a while loop. Besides, in this case, the except code effectively includes the entire import, which would completely swamp the overhead of the raise. If we assume the question was more generally about EAFT vs. LBYL, and not just about the case of accessing the system data structure sys.modules, then the issues change somewhat. If we do a LBYL, we have to know that we've covered all interesting cases with our test. Multithreading is one case where we can get a race condition. There are times when we might be able to know either that there are not other threads, or that the other threads don't mess with the stuff we're testing. For example, there are enough problems with import and threads that we might just have a development policy that (in this program) we will do all our imports before starting any additional threads, and that we will never try to unload an import, single threaded or not. But for other conditions, we might be affected either by the system or by other processes within it. Or even affected by other asynchronous events over a network. If we do an EAFP, then we have to figure out what exceptions are possible. However, adding more exceptions with different treatments is quite easy, and they don't all have to be done at the same level. Some may be left for our caller to deal with. I think the major thing that people mind about try/catch is that it seems to break up the program flow. However, that paradigm grows on you as you get accustomed to it. -- DaveA From maniandram01 at gmail.com Sat Oct 6 08:38:38 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 6 Oct 2012 05:38:38 -0700 (PDT) Subject: sum function In-Reply-To: References: <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com> <04412893-e6ba-43cc-8d9c-7867f82af4d1@googlegroups.com> <397c5421-e28b-482e-82ce-6bf693056d51@googlegroups.com> Message-ID: <36bb20b7-d2cf-489d-b7af-8efc56cbb4c0@googlegroups.com> On Saturday, 6 October 2012 02:09:56 UTC+5:30, Dave Angel wrote: > On 10/05/2012 04:09 PM, Mike wrote: > > > Terry, > > > > > > I am not using the mail client. I am just posting on the site. > > > > And which site would that be (that you're using)? There are a few. I'm > > guessing you use google-groups. And all of them get gatewayed to the > > actual list, with differing numbers of bugs. > > > > I use email to access it directly. I solve one of the duplicate-message > > problems with google groups by automatically deleting any message > > addressed to google-groups. There are about 100 such messages each month. > > > > Another problem is that lots of these gateways post to both the > > newsgroup and to the python-list. > I found out earlier that this was why my posts was being double-posted in Google Groups. > > > > > > > Something wrong with this site. When you do individual reply, it does the double posting which it shouldn't. See "Ramachandra Apte's" reply. It is posted twice too. > > > > > > Thanks > > > > > > > > > > > > > > > -- > > > > DaveA From roy at panix.com Sat Oct 6 08:46:28 2012 From: roy at panix.com (Roy Smith) Date: Sat, 06 Oct 2012 08:46:28 -0400 Subject: Unpaking Tuple References: <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> Message-ID: In article , Chris Rebert wrote: > But at any rate: > shortfall = 4 - len(your_tuple) > your_tuple += (None,) * shortfall # assuming None is a suitable default > a, b, c, d = your_tuple > > If you also need to handle the "too many items" case, use slicing: > a, b, c, d = your_tuple[:4] I usually handle both of those cases at the same time: >>> a, b, c, d = (my_tuple + (None,) * 4)[:4] From rodrick.brown at gmail.com Sat Oct 6 09:25:20 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Sat, 6 Oct 2012 09:25:20 -0400 Subject: Executing untrusted scripts in a sandboxed environment In-Reply-To: <4hrls608xbax633ej6s1n54j.1349475464556@email.android.com> References: <4hrls608xbax633ej6s1n54j.1349475464556@email.android.com> Message-ID: <-919205995499869234@unknownmsgid> On Oct 5, 2012, at 6:32 PM, Robin Krahl wrote: > Hi all, > > I need to execute untrusted scripts in my Python application. To avoid security issues, I want to use a sandboxed environment. This means that the script authors have no access to the file system. They may only access objects, modules and classes that are "flagged" or "approved" for scripting. > > I read that I will not be able to do this with Python scripts. (See SandboxedPython page in the Python wiki [0] and several SE.com questions, e. g. [1].) So my question is: What is the best way to "embed" a script engine in a sandboxed environment that has access to the Python modules and classes that I provide? Checkout udacity.com I think there is a writeup on stackoverflow on how they accomplished their sandbox runtime env. > > Thanks for your help. > > Best regards, > Robin > > [0] http://wiki.python.org/moin/SandboxedPython > [1] http://stackoverflow.com/questions/3068139/how-can-i-sandbox-python-in-pure-python > -- > http://mail.python.org/mailman/listinfo/python-list From invalid at invalid.invalid Sat Oct 6 09:26:44 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 6 Oct 2012 13:26:44 +0000 (UTC) Subject: write binary with struct.pack_into References: <1349494056881-4991234.post@n6.nabble.com> Message-ID: On 2012-10-06, Dennis Lee Bieber wrote: > On Fri, 5 Oct 2012 20:27:36 -0700 (PDT), palmeira > declaimed the following in gmane.comp.python.general: > >> >> #WRITE >> fb=open('testOUT.bin') > > Unless you specify otherwise, open() defaults to read-only It also defaults to 'text' mode which does cr/lf translaction. That will break both reads and writes on any binary file containing 0x0a and 0x0d bytes. -- Grant From rosuav at gmail.com Sat Oct 6 09:52:47 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Oct 2012 23:52:47 +1000 Subject: write binary with struct.pack_into In-Reply-To: References: <1349494056881-4991234.post@n6.nabble.com> Message-ID: On Sat, Oct 6, 2012 at 11:26 PM, Grant Edwards wrote: > On 2012-10-06, Dennis Lee Bieber wrote: >> On Fri, 5 Oct 2012 20:27:36 -0700 (PDT), palmeira >> declaimed the following in gmane.comp.python.general: >> >>> >>> #WRITE >>> fb=open('testOUT.bin') >> >> Unless you specify otherwise, open() defaults to read-only > > It also defaults to 'text' mode which does cr/lf translaction. That > will break both reads and writes on any binary file containing 0x0a > and 0x0d bytes. And, in Python 3, it'll be returning Unicode characters too, unless the decode fails. You definitely want binary mode. ChrisA From steve+comp.lang.python at pearwood.info Sat Oct 6 11:08:38 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Oct 2012 15:08:38 GMT Subject: Unpaking Tuple References: <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> Message-ID: <50704975$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Oct 2012 08:46:28 -0400, Roy Smith wrote: > In article , > Chris Rebert wrote: > >> But at any rate: >> shortfall = 4 - len(your_tuple) >> your_tuple += (None,) * shortfall # assuming None is a suitable default >> a, b, c, d = your_tuple >> >> If you also need to handle the "too many items" case, use slicing: a, >> b, c, d = your_tuple[:4] > > I usually handle both of those cases at the same time: > >>>> a, b, c, d = (my_tuple + (None,) * 4)[:4] While that's fine for small tuples, if somebody wanted to mess with you, and passed (say) a million-item tuple, that would unnecessarily copy all million items before throwing all but four away. For the sake of a two-liner instead of a one-liner, you can avoid such nasty surprises: my_tuple = my_tuple[:4] a,b,c,d = my_tuple if len(my_tuple) == 4 else (my_tuple + (None,)*4)[:4] A similar solution: a,b,c,d = (my_tuple[:4] + (None, None, None, None))[:4] Here's a dumb one-liner, good for making people laugh at you: a,b,c,d = (x for i,x in enumerate(my_tuple + (None,)*4) if i < 4) and an obfuscated solution: from itertools import izip_longest as izip a,b,c,d = (None if x == (None,None) else x[0][1] for x in izip(zip ('izip', my_tuple), (None for izip in 'izip'))) But in my opinion, the best solution of all is a three-liner: if len(my_tuple) < 4: my_tuple += (None,)*(4 - len(my_tuple)) a,b,c,d = my_tuple[4:] -- Steven From joshua.landau.ws at gmail.com Sat Oct 6 11:31:16 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Sat, 6 Oct 2012 16:31:16 +0100 Subject: Combinations of lists In-Reply-To: References: <506C4B23.6020809@gmail.com> Message-ID: On 4 October 2012 16:12, Steen Lysgaard wrote: > 2012/10/4 Joshua Landau : > > On 3 October 2012 21:15, Steen Lysgaard wrote: > >> > >> Hi, > >> > >> thanks for your interest. Sorry for not being completely clear, yes > >> the length of m will always be half of the length of h. > > > > > > (Please don't top post) > > > > I have a solution to this, then. > > It's not short or fast, but it's a lot faster than yours. > > This is quite naive, because I don't know how to properly implement > > force_unique_combinations, but it runs. I hope this is right. If you need > > significantly more speed your best chance is probably Cython or C, > although > > I don't doubt 10x more speed may well be possible from within Python. > > > > > > Also, 88888 Dihedral is a bot, or at least pretending like crazy to be > one. > > Great, I've now got a solution much faster than what I could come up with. > Thanks to the both of you. > Don't use it though :P. I've something better, now I've used a few sanity-points up [it's much more interesting to solve *other* people's problems]. Please note that my implementations (old and new) return duplicates when the second list contains duplicates. It's fixable, but I'll only bother if you need it fixed. It runs in a very consistent 55% of the time, but it is longer. Here y'are. """Super algorithm.""" > > from itertools import combinations > from collections import Counter > > def multiples(counter): > """Counter -> set. > > Returns the set of values that occur multiple times. > """ > multiples = set() > > for item, number in counter.items(): > if number > 1: > multiples.add(item) > > return multiples > > #@profile > def pairwise_combinations(counter, countermultiples, counterset, length, > charmap): > # length is a LIE! > """Get the permutations of two lists. > > Do not call this directly unless you want to hassle yourself. > Use the wrapper provided, list_permute, instead. > """ > > # We will do the combinations in pairs, as each pair will not have order > and so > # [1, 2, 3, 4] is equivilant to [2, 1, 4, 3] but not [1, 3, 2, 4]. > > # This means that we get the full permutations without ever filtering. > > # Each pair along is a combination. > # We are combination-ing a set to prevent dulicates. > # As the combinations are of length 2, the only ones this will > # miss are of the type [x, x] (two of the same). > # This is accounted for by countermultiples. > pairs = combinations(counterset, 2) > > # Prepend with this > length -= 1 > prefix_char = charmap[length] > > # There's not reason to recurse, so don't bother with a lot of stuff > if not length: > for p_a, p_b in pairs: > yield [prefix_char+p_a, prefix_char+p_b] > for p in countermultiples: > yield [prefix_char+p, prefix_char+p] > return > > for p_a, p_b in pairs: > # Edit scope > # The recursion wont be able to use items we've already used > counter[p_a] -= 1 > counter_p_a = counter[p_a] # Quickref > if counter_p_a == 0: counterset.remove(p_a) # None left > elif counter_p_a == 1: countermultiples.remove(p_a) # Not plural > > counter[p_b] -= 1 > counter_p_b = counter[p_b] # Quickref > if counter_p_b == 0: counterset.remove(p_b) # None left > elif counter_p_b == 1: countermultiples.remove(p_b) # Not plural > > # Recurse > # Do the same, but for the next pair along > own_yield = [prefix_char+p_a, prefix_char+p_b] > for delegated_yield in pairwise_combinations(counter, countermultiples, > counterset, length, charmap): > yield own_yield + delegated_yield > > # Reset scope > counter[p_a] += 1 > if counter_p_a == 0: counterset.add(p_a) > elif counter_p_a == 1: countermultiples.add(p_a) > > counter[p_b] += 1 > if counter_p_b == 0: counterset.add(p_b) > elif counter_p_b == 1: countermultiples.add(p_b) > > > # Now do the same for countermultiples > # This is not itertools.chain'd because this way > # is faster and I get to micro-optomize inside > for p in countermultiples: > # Edit scope > # The recursion wont be able to use items we've already used > counter[p] -= 2 > counter_p = counter[p] # Quickref > > if counter_p == 0: > counterset.remove(p) # None left > countermultiples.remove(p) # Must have been in countermultiples, none left > > elif counter_p == 1: > countermultiples.remove(p) # Not plural > > # Recurse > # Do the same, but for the next pair along > own_yield = [prefix_char+p, prefix_char+p] > for delegated_yield in pairwise_combinations(counter, countermultiples, > counterset, length, charmap): > yield own_yield + delegated_yield > > # Reset scope > counter[p] += 2 > > if counter_p == 0: > counterset.add(p) > countermultiples.add(p) > > elif counter_p == 1: > countermultiples.add(p) > > def list_permute(first, second): > """Get the permutations of two lists as according to what you want, which > isn't really the > permutations of two lists but something close to it. It does what it > needs to, I think. > > This DOES NOT work when contains duplicates, as the result has > duplicates. The other > of mine does not work either. If this is a problem, it should be > fixable: sort > and when you encounter the duplicates generate in groups bigger than 2. > You cannot do as above > for pairs, so an intermittent filtering method will work best. I won't > implement this if it's > unneeded, though. > > This runs in 55% of the time of my previous one, with over twice the > number of lines. > W007! Lines! > """ > count = Counter(first) > return pairwise_combinations(count, multiples(count), set(count), > len(first)//2, list(reversed(second))) > > # TEST # > > second = "abcde" > first = sorted((second+second).upper()) > > n = 0 > for _ in list_permute(first, second): n += 1 > print(n) I release this under whatever permissive licence you want. -------------- next part -------------- An HTML attachment was scrubbed... URL: From news at blinne.net Sat Oct 6 11:55:49 2012 From: news at blinne.net (Alexander Blinne) Date: Sat, 06 Oct 2012 17:55:49 +0200 Subject: write binary with struct.pack_into In-Reply-To: References: Message-ID: <50705485$0$6629$9b4e6d93@newsspool2.arcor-online.net> First, you should consider reading the documentation of struct.unpack_from and struct.pack_into at http://docs.python.org/library/struct.html quite carefully. It says, that these commands take a parameter called offset, which names the location of the data in a buffer (e.g. an opened file). example: bloco='>%df' % (252) # Format string (252 floats) fa = open('testIN.bin', 'rb') # open for reading in binary mode off = 0 # suppose i want to read block at beginning of file my_array=struct.unpack_from(bloco, fa, off) #read data now write them to another file: fb = open('testOUT.bin', 'r+b') # open for updating in binary mode off = 0 # suppose i want to write block at beginning of file struct.pack_into(bloco, fb, off, *my_array) #write data to testOUT From jason at powerpull.net Sat Oct 6 13:14:47 2012 From: jason at powerpull.net (Jason Friedman) Date: Sat, 6 Oct 2012 11:14:47 -0600 Subject: parse an environment file In-Reply-To: References: Message-ID: > The only canned solution for parsing a bash script is bash. Think > about it the other way around: If you wanted to have a Python variable > made available to a bash script, the obvious thing to do is to invoke > Python. It's the same thing. I scratched my own itch: http://code.activestate.com/recipes/578280-parse-profile/. From rosuav at gmail.com Sat Oct 6 13:33:16 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 7 Oct 2012 04:33:16 +1100 Subject: parse an environment file In-Reply-To: References: Message-ID: On Sun, Oct 7, 2012 at 4:14 AM, Jason Friedman wrote: >> The only canned solution for parsing a bash script is bash. Think >> about it the other way around: If you wanted to have a Python variable >> made available to a bash script, the obvious thing to do is to invoke >> Python. It's the same thing. > > I scratched my own itch: > http://code.activestate.com/recipes/578280-parse-profile/. And there you have it! A subset of bash syntax and a Python parser. Job done! ChrisA From owens.darryl.lee at gmail.com Sat Oct 6 14:43:58 2012 From: owens.darryl.lee at gmail.com (Darryl Owens) Date: Sat, 6 Oct 2012 11:43:58 -0700 (PDT) Subject: I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool for my PhD. Message-ID: <62ab66e8-c647-4185-8be6-3b7ce5e61df8@googlegroups.com> I am currently starting my PhD in software quality assurance and have been doing a lot of reading round this subject. I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool i.e. a tool/methodology that can accept many languages for the following areas: ? Problems in code/coding errors ? Compiler bugs ? Language bugs ? Users mathematical model I would greatly appreciate any input and advice in this area, feel free to repost on this topic and/or contact me at: owens.darryl.lee at gmail.com Thank you in advance Darryl Owens From vasudevram at gmail.com Sat Oct 6 14:57:58 2012 From: vasudevram at gmail.com (vasudevram) Date: Sat, 6 Oct 2012 11:57:58 -0700 (PDT) Subject: fmap(), "inverse" of Python map() function In-Reply-To: References: <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> Message-ID: On Saturday, October 6, 2012 5:01:40 AM UTC+5:30, Devin Jeanpierre wrote: > On Fri, Oct 5, 2012 at 7:24 PM, Ian Kelly wrote: > > > I realize that. My point is that the function *feels* more like a > > > variant of reduce than of map. > > > > > >> If it's meant as a complaint, it's a poor one. > > > > > > It's not. > > > > Fair enough all around. Sorry for misunderstanding. > > > > -- Devin Thanks to all who replied. Always good to learn something new. - Vasudev From vasudevram at gmail.com Sat Oct 6 14:57:58 2012 From: vasudevram at gmail.com (vasudevram) Date: Sat, 6 Oct 2012 11:57:58 -0700 (PDT) Subject: fmap(), "inverse" of Python map() function In-Reply-To: References: <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> Message-ID: On Saturday, October 6, 2012 5:01:40 AM UTC+5:30, Devin Jeanpierre wrote: > On Fri, Oct 5, 2012 at 7:24 PM, Ian Kelly wrote: > > > I realize that. My point is that the function *feels* more like a > > > variant of reduce than of map. > > > > > >> If it's meant as a complaint, it's a poor one. > > > > > > It's not. > > > > Fair enough all around. Sorry for misunderstanding. > > > > -- Devin Thanks to all who replied. Always good to learn something new. - Vasudev From tjreedy at udel.edu Sat Oct 6 15:42:31 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Oct 2012 15:42:31 -0400 Subject: try/except KeyError vs "if name in ..." In-Reply-To: <507017AB.8090507@davea.name> References: <507017AB.8090507@davea.name> Message-ID: On 10/6/2012 7:36 AM, Dave Angel wrote: > The distinction in performance between the success and failure modes of > the try/catch isn't nearly as large as one of the other responses might > lead you to believe. For example, a for loop generally terminates with > a raise (of StopIteration exception), and that doesn't convince us to > replace it with a while loop. For statement generally loop many times, up to millions of times, without an exception being raised, whereas while statements test the condition each time around the loop. So the rule 'if failure is rare (less than 10-20%) use try', applies here. For if/them versus try/except, I don't worry too much about it. -- Terry Jan Reedy From christian at python.org Sat Oct 6 16:08:03 2012 From: christian at python.org (Christian Heimes) Date: Sat, 06 Oct 2012 22:08:03 +0200 Subject: [ann] pysha3 0.2.1 released Message-ID: Hello, today I've released pysha3 0.2.1 [1]. It's a standalone version of the SHA-3 extension that I merged into CPython's development branch (future 3.4) a couple of hours ago. It provides the Keccak [2] cryptographic hashing algorithm that was officially selected as SHA-3 by NIST a four days ago. The module implements 224, 256, 384 and 512 bits digest size. Arbitrarily-long output is not supported by the module as it's not part of the NIST interface. pysha3 is available for Python 2.6, 2.7, 3.2 and 3.3. It has been tested on Linux (X86, X86_64 with gcc 4.6 and clang), FreeBSD and Windows (X86, X86_64). 32 and 64bit Windows binaries for all supported Python versions are available on PyPI, too. Have fun, Christian [1] http://pypi.python.org/pypi/pysha3 [2] http://keccak.noekeon.org/ From vasudevram at gmail.com Sat Oct 6 18:07:00 2012 From: vasudevram at gmail.com (vasudevram) Date: Sat, 6 Oct 2012 15:07:00 -0700 (PDT) Subject: fmap(), "inverse" of Python map() function In-Reply-To: References: <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> Message-ID: <9b8beb5d-001b-4606-9ca3-d57aed9862ba@googlegroups.com> > Thanks to all who replied. Always good to learn something new. P.S. A reader posted a good comment with Scala as well as Python code for a compose function (basically same functionality as fmap, or more - the compose once, run many times thing). It's the 4th comment on my blog post. - Vasudev From vasudevram at gmail.com Sat Oct 6 18:07:00 2012 From: vasudevram at gmail.com (vasudevram) Date: Sat, 6 Oct 2012 15:07:00 -0700 (PDT) Subject: fmap(), "inverse" of Python map() function In-Reply-To: References: <727ec5d8-d292-4012-ba87-da77a1040c6a@googlegroups.com> Message-ID: <9b8beb5d-001b-4606-9ca3-d57aed9862ba@googlegroups.com> > Thanks to all who replied. Always good to learn something new. P.S. A reader posted a good comment with Scala as well as Python code for a compose function (basically same functionality as fmap, or more - the compose once, run many times thing). It's the 4th comment on my blog post. - Vasudev From demianbrecht at gmail.com Sat Oct 6 18:45:23 2012 From: demianbrecht at gmail.com (Demian Brecht) Date: Sat, 06 Oct 2012 15:45:23 -0700 Subject: Are ABCs an anti-pattern? In-Reply-To: <20121005195836.GA94783@snakebite.org> References: <506AF8C9.8060406@gmail.com> <20121005195836.GA94783@snakebite.org> Message-ID: <5070B483.1060507@gmail.com> On 12-10-05 12:58 PM, Trent Nelson wrote: > I like them. In particular, I like that I can enumerate all the > subclasses that happen to implement the ABC via the metaclass's > __subclasses__() method. As long as you have a common base class (which in your case is a requirement), then __subclasses__ works for introspecting child classes. It doesn't *really* have anything to do with abcs. > I also like that I can trust Python > not to instantiate a subclass of an ABC unless it meets all the > interface criteria I've stipulated. Another way to read this is that you don't trust those using your code to be bright enough to understand what your code is doing and what it requires. In my mind, this seems to somewhat contradict the philosophy of "we're all consenting adults here". Whether you utilize interfaces or not, code should be documented. Your documentation would be responsible for laying out the expected interface (again, whether you're using the interfaces or not). Code would fail at some point if a requirement on an interface hasn't been filled. The *one* nice thing is that it'll error on import rather than execution time, but to me, if your code is unit tested, then all these things should be caught almost immediately anyway. From my experience (again, *only* talking about Python here), it seem to me that less is generally more. Less code means less things to read and tie together, making it easier to grok overall (not to mention less overhead for the interpreter, but that's virtually moot due to the *very* little overhead in 99% of cases of uses features such as abcs). Using abcs not only lends itself to code bloat, but it also leads to over-engineering as once you fall into old OOP habits, you start getting back to un-Pythonic code (pretty subjective statement, I know :)). Again, please don't misunderstand my intentions here. I'm not arguing the need for abstract base classes in a strict OOP world. I'm arguing them as not genuinely being Pythonic. Thanks for your the feedback so far. -- Demian Brecht @demianbrecht http://demianbrecht.github.com From ethan at stoneleaf.us Sat Oct 6 21:13:46 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 06 Oct 2012 18:13:46 -0700 Subject: [ann] pysha3 0.2.1 released In-Reply-To: References: Message-ID: <5070D74A.4030106@stoneleaf.us> Christian Heimes wrote: > today I've released pysha3 0.2.1 [1]. > > pysha3 is available for Python 2.6, 2.7, 3.2 and 3.3. It has been tested > on Linux (X86, X86_64 with gcc 4.6 and clang), FreeBSD and Windows (X86, > X86_64). 32 and 64bit Windows binaries for all supported Python versions > are available on PyPI, too. > > [1] http://pypi.python.org/pypi/pysha3 > [2] http://keccak.noekeon.org/ Nice! Thanks! ~Ethan~ From skippy.hammond at gmail.com Sat Oct 6 22:33:38 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sun, 07 Oct 2012 13:33:38 +1100 Subject: Why is pylaucher in Python 3.3 being installed in Windows folder? In-Reply-To: References: <6aa17d70-b4a4-44e4-aef3-46596768979f@c20g2000vbz.googlegroups.com> <506ceea1$0$29978$c3e8da3$5496439d@news.astraweb.com> <61a80e13-ddeb-4d7e-9da3-1e7377f65a67@h16g2000vby.googlegroups.com> Message-ID: <5070EA02.7020306@gmail.com> On 5/10/2012 2:40 AM, Oscar Benjamin wrote: > Having them on PATH means that you can do: > > > py script.py > > and the effect will be analogous to (in a unix shell): > > $ ./script.py > > Of course the idea with the launcher is that you just do > > > script.py Unless you want a specific version - particularly for testing - eg: % py -3.2 script.py Mark From ian.g.kelly at gmail.com Sat Oct 6 23:13:24 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 6 Oct 2012 21:13:24 -0600 Subject: Coexistence of Python 2.x and 3.x on same OS In-Reply-To: <314ffb69-c89b-42f6-9af1-61005056ef91@googlegroups.com> References: <314ffb69-c89b-42f6-9af1-61005056ef91@googlegroups.com> Message-ID: On Sat, Oct 6, 2012 at 1:27 AM, wrote: > Using Python on Windows is a dream. > > Python uses and needs the system, but the system does > not use Python. > > Every Python version is installed in its own isolated > space, site-packages included and without any defined > environment variable. Every Python can be seen as a > different application. > Knowing this, it is a no-problem to use the miscellaneous > versions; can be with the console, with an editor, with > .bat or .cmd files, with the Windows "start menu" launcher, > ... like any application. > > The file extension is a double sword. Do not use it or > unregister it, the msi installer allows to do this. > It is the same task/problem as with any file, .txt, .png, ... > > The new Python launcher is a redondant tool. Yes, because all scripts are only ever run by the person who wrote them. The main benefit here is for distribution of Python scripts with version requirements. Just because you can rely on your Python installation to be in C:\Python27 doesn't mean you can rely on somebody else's installation to be there, or on their file associations to be configured for the correct version. From maniandram01 at gmail.com Sun Oct 7 00:15:09 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 6 Oct 2012 21:15:09 -0700 (PDT) Subject: I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool for my PhD. In-Reply-To: <62ab66e8-c647-4185-8be6-3b7ce5e61df8@googlegroups.com> References: <62ab66e8-c647-4185-8be6-3b7ce5e61df8@googlegroups.com> Message-ID: <1b18a4b3-853c-4423-b116-95ed3677f8f6@googlegroups.com> On Sunday, 7 October 2012 00:13:58 UTC+5:30, Darryl Owens wrote: > I am currently starting my PhD in software quality assurance and have been doing a lot of reading round this subject. I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool i.e. a tool/methodology that can accept many languages for the following areas: > > ? Problems in code/coding errors > > ? Compiler bugs > > ? Language bugs > > ? Users mathematical model > > I would greatly appreciate any input and advice in this area, feel free to repost on this topic and/or contact me at: owens.darryl.lee at gmail.com > > > > Thank you in advance > > > > Darryl Owens Does this have anything to do with Python? Banned from #python-offtopic till Christmas From maniandram01 at gmail.com Sun Oct 7 00:17:33 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 6 Oct 2012 21:17:33 -0700 (PDT) Subject: try/except KeyError vs "if name in ..." In-Reply-To: References: <507017AB.8090507@davea.name> Message-ID: On Sunday, 7 October 2012 01:12:56 UTC+5:30, Terry Reedy wrote: > On 10/6/2012 7:36 AM, Dave Angel wrote: > > > > > The distinction in performance between the success and failure modes of > > > the try/catch isn't nearly as large as one of the other responses might > > > lead you to believe. For example, a for loop generally terminates with > > > a raise (of StopIteration exception), and that doesn't convince us to > > > replace it with a while loop. > > > > For statement generally loop many times, up to millions of times, > > without an exception being raised, whereas while statements test the > > condition each time around the loop. So the rule 'if failure is rare > > (less than 10-20%) use try', applies here. For if/them versus > > try/except, I don't worry too much about it. > > > > -- > > Terry Jan Reedy I use try and except when I need to raise exceptions e.g.: try: value = vm.variables[name] except KeyError: raise NameError("variable name not defined in VM's variables") From maniandram01 at gmail.com Sun Oct 7 00:17:33 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 6 Oct 2012 21:17:33 -0700 (PDT) Subject: try/except KeyError vs "if name in ..." In-Reply-To: References: <507017AB.8090507@davea.name> Message-ID: On Sunday, 7 October 2012 01:12:56 UTC+5:30, Terry Reedy wrote: > On 10/6/2012 7:36 AM, Dave Angel wrote: > > > > > The distinction in performance between the success and failure modes of > > > the try/catch isn't nearly as large as one of the other responses might > > > lead you to believe. For example, a for loop generally terminates with > > > a raise (of StopIteration exception), and that doesn't convince us to > > > replace it with a while loop. > > > > For statement generally loop many times, up to millions of times, > > without an exception being raised, whereas while statements test the > > condition each time around the loop. So the rule 'if failure is rare > > (less than 10-20%) use try', applies here. For if/them versus > > try/except, I don't worry too much about it. > > > > -- > > Terry Jan Reedy I use try and except when I need to raise exceptions e.g.: try: value = vm.variables[name] except KeyError: raise NameError("variable name not defined in VM's variables") From rustompmody at gmail.com Sun Oct 7 01:02:45 2012 From: rustompmody at gmail.com (rusi) Date: Sat, 6 Oct 2012 22:02:45 -0700 (PDT) Subject: I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool for my PhD. References: <62ab66e8-c647-4185-8be6-3b7ce5e61df8@googlegroups.com> <1b18a4b3-853c-4423-b116-95ed3677f8f6@googlegroups.com> Message-ID: <980bf18c-75a8-46da-b9a8-7d53061716fa@ql4g2000pbc.googlegroups.com> On Oct 7, 9:15?am, Ramchandra Apte wrote: > On Sunday, 7 October 2012 00:13:58 UTC+5:30, Darryl Owens ?wrote: > > I am currently starting my PhD in software quality assurance and have been doing a lot of reading round this subject. I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool i.e. a tool/methodology that can accept many languages for the following areas: > > > ? ? ? ? ?Problems in code/coding errors > > > ? ? ? ? ?Compiler bugs > > > ? ? ? ? ?Language bugs > > > ? ? ? ? ?Users mathematical model > > > I would greatly appreciate any input and advice in this area, feel free to repost on this topic and/or contact me at: owens.darryl.... at gmail.com > > > Thank you in advance > > > Darryl Owens > > Does this have anything to do with Python? Why not? > > Banned from #python-offtopic till Christmas Did you wait for an answer? From maniandram01 at gmail.com Sun Oct 7 01:08:34 2012 From: maniandram01 at gmail.com (Ramchandra Apte) Date: Sat, 6 Oct 2012 22:08:34 -0700 (PDT) Subject: I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool for my PhD. In-Reply-To: <980bf18c-75a8-46da-b9a8-7d53061716fa@ql4g2000pbc.googlegroups.com> References: <62ab66e8-c647-4185-8be6-3b7ce5e61df8@googlegroups.com> <1b18a4b3-853c-4423-b116-95ed3677f8f6@googlegroups.com> <980bf18c-75a8-46da-b9a8-7d53061716fa@ql4g2000pbc.googlegroups.com> Message-ID: On Sunday, 7 October 2012 10:32:45 UTC+5:30, rusi wrote: > On Oct 7, 9:15?am, Ramchandra Apte wrote: > > > On Sunday, 7 October 2012 00:13:58 UTC+5:30, Darryl Owens ?wrote: > > > > I am currently starting my PhD in software quality assurance and have been doing a lot of reading round this subject. I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool i.e. a tool/methodology that can accept many languages for the following areas: > > > > > > > ? ? ? ? ?Problems in code/coding errors > > > > > > > ? ? ? ? ?Compiler bugs > > > > > > > ? ? ? ? ?Language bugs > > > > > > > ? ? ? ? ?Users mathematical model > > > > > > > I would greatly appreciate any input and advice in this area, feel free to repost on this topic and/or contact me at: owens.darryl.... at gmail.com > > > > > > > Thank you in advance > > > > > > > Darryl Owens > > > > > > Does this have anything to do with Python? > > > > Why not? > > > > > > > > Banned from #python-offtopic till Christmas > > > > Did you wait for an answer? no From dwightdhutto at gmail.com Sun Oct 7 01:55:54 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 7 Oct 2012 01:55:54 -0400 Subject: I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool for my PhD. In-Reply-To: <980bf18c-75a8-46da-b9a8-7d53061716fa@ql4g2000pbc.googlegroups.com> References: <62ab66e8-c647-4185-8be6-3b7ce5e61df8@googlegroups.com> <1b18a4b3-853c-4423-b116-95ed3677f8f6@googlegroups.com> <980bf18c-75a8-46da-b9a8-7d53061716fa@ql4g2000pbc.googlegroups.com> Message-ID: On Sun, Oct 7, 2012 at 1:02 AM, rusi wrote: > On Oct 7, 9:15 am, Ramchandra Apte wrote: >> On Sunday, 7 October 2012 00:13:58 UTC+5:30, Darryl Owens wrote: >> > I am currently starting my PhD in software quality assurance and have been doing a lot of reading round this subject. I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool i.e. a tool/methodology that can accept many languages for the following areas: >> >> > ? Problems in code/coding errors >> >> > ? Compiler bugs >> >> > ? Language bugs >> >> > ? Users mathematical model >> The main tests for python is: http://docs.python.org/library/unittest.html For other languages, and even in python, you can roll your own. I'd begin by algorithming each particular language's calls(based on the statistical probabilities of languages that are utilized, and designed in a hierarchical order of the utilization), language bugs, and mathematical models needed performed, then perform the necessary function calls/series of calls. Pass data, and check the returns. CMD errors in some cases, and checking for error logs from URL calls. I'd suggest the bug repositories for the OS, browser, or app framework the language is launched in(version/build #, etc), or some form of url scraping the data from these in order to correct/check known problems. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Sun Oct 7 02:03:59 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 7 Oct 2012 02:03:59 -0400 Subject: I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool for my PhD. In-Reply-To: References: <62ab66e8-c647-4185-8be6-3b7ce5e61df8@googlegroups.com> <1b18a4b3-853c-4423-b116-95ed3677f8f6@googlegroups.com> <980bf18c-75a8-46da-b9a8-7d53061716fa@ql4g2000pbc.googlegroups.com> Message-ID: On Sun, Oct 7, 2012 at 1:55 AM, Dwight Hutto wrote: > On Sun, Oct 7, 2012 at 1:02 AM, rusi wrote: >> On Oct 7, 9:15 am, Ramchandra Apte wrote: >>> On Sunday, 7 October 2012 00:13:58 UTC+5:30, Darryl Owens wrote: >>> > I am currently starting my PhD in software quality assurance and have been doing a lot of reading round this subject. I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool i.e. a tool/methodology that can accept many languages for the following areas: >>> >>> > ? Problems in code/coding errors >>> >>> > ? Compiler bugs >>> >>> > ? Language bugs >>> >>> > ? Users mathematical model >>> You could also utilize other unittests from other languages, and roll that into wrappers that checked for specific languages utilization, and it's probable errors, by initiating the unittest functions with a python call specific to the language being utilized. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Sun Oct 7 02:16:57 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 7 Oct 2012 02:16:57 -0400 Subject: I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool for my PhD. In-Reply-To: References: <62ab66e8-c647-4185-8be6-3b7ce5e61df8@googlegroups.com> <1b18a4b3-853c-4423-b116-95ed3677f8f6@googlegroups.com> <980bf18c-75a8-46da-b9a8-7d53061716fa@ql4g2000pbc.googlegroups.com> Message-ID: On Sun, Oct 7, 2012 at 2:03 AM, Dwight Hutto wrote: > On Sun, Oct 7, 2012 at 1:55 AM, Dwight Hutto wrote: >> On Sun, Oct 7, 2012 at 1:02 AM, rusi wrote: >>> On Oct 7, 9:15 am, Ramchandra Apte wrote: >>>> On Sunday, 7 October 2012 00:13:58 UTC+5:30, Darryl Owens wrote: >>>> > I am currently starting my PhD in software quality assurance and have been doing a lot of reading round this subject. I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool i.e. a tool/methodology that can accept many languages for the following areas: >>>> >>>> > ? Problems in code/coding errors >>>> >>>> > ? Compiler bugs >>>> >>>> > ? Language bugs >>>> >>>> > ? Users mathematical model >>>> > Maybe easier through checking particular error logs. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From dwightdhutto at gmail.com Sun Oct 7 02:50:37 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 7 Oct 2012 02:50:37 -0400 Subject: I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool for my PhD. In-Reply-To: References: <62ab66e8-c647-4185-8be6-3b7ce5e61df8@googlegroups.com> <1b18a4b3-853c-4423-b116-95ed3677f8f6@googlegroups.com> <980bf18c-75a8-46da-b9a8-7d53061716fa@ql4g2000pbc.googlegroups.com> Message-ID: On Sun, Oct 7, 2012 at 2:16 AM, Dwight Hutto wrote: > On Sun, Oct 7, 2012 at 2:03 AM, Dwight Hutto wrote: >> On Sun, Oct 7, 2012 at 1:55 AM, Dwight Hutto wrote: >>> On Sun, Oct 7, 2012 at 1:02 AM, rusi wrote: >>>> On Oct 7, 9:15 am, Ramchandra Apte wrote: >>>>> On Sunday, 7 October 2012 00:13:58 UTC+5:30, Darryl Owens wrote: >>>>> > I am currently starting my PhD in software quality assurance and have been doing a lot of reading round this subject. I am just trying to find out if there is any relevant/current research in the production of a generic quality assurance tool i.e. a tool/methodology that can accept many languages for the following areas: >>>>> >>>>> > ? Problems in code/coding errors >>>>> >>>>> > ? Compiler bugs >>>>> >>>>> > ? Language bugs >>>>> >>>>> > ? Users mathematical model >>>>> >> It is about 2:30 A.M. here, and I'm tossing out thoughts that could go deeper. You're looking for: >>>> > ? Problems in code/coding errors >>>> >>>> > ? Compiler bugs >>>> >>>> > ? Language bugs >>>> >>>> > ? Users mathematical model >>>> > The below is the base algorithm I see for every language: There are problems, and ways to test in every language. Some have more advanced tests based on their usage, and those who use them. You have identified the errors needed to be checked for: -Problems in code/coding errors -Compiler bugs -Language bugs -Users mathematical model 1. You have test methods in lots of languages for these, and you need to parse for the file extension, or something in the code that shows it has switched to a new language. I'm assuming classes and functions here 2. It seems like you should have a file/script in each language to check for as much as you can. 3. You could call these scripts via a python command line app, and have an app to display the output, and check for know error calls returned from the command line output(stderr/stdin/,etc), or the browsers output/error logs. 4. You could go to a lower level. 5. You're in python, so pick the best way to wrap and execute the above based on file extensions, and parsing, then run your test on portions of code if the have parameters or error values, or the code as a whole, and deal with each of the problems stated above. This is just to begin to understand your mentality of how you want to implement in python. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From franck at ditter.org Sun Oct 7 04:33:36 2012 From: franck at ditter.org (Franck Ditter) Date: Sun, 07 Oct 2012 10:33:36 +0200 Subject: question on log as an instance method Message-ID: Hi ! Here is Python 3.2.3, MacOSX-Lion Question : I may consider + as an hidden instance method , as 1+2 is equivalent to (1).__add__(2) ? I also consider __abs__ as an instance method : >>> (-2).__abs__() 2 Question 1 : could the parser cope with the mandatory space in 1 .__add__(2) ? Question 2 : After importing math, why can't I consider log as an instance method, after all ? >>> (4).__log__() AttributeError: 'float' object has no attribute '__log__' Thanks for your answers. franck From franck at ditter.org Sun Oct 7 04:50:38 2012 From: franck at ditter.org (Franck Ditter) Date: Sun, 07 Oct 2012 10:50:38 +0200 Subject: getting the state of an object Message-ID: Hi ! Another question. When writing a class, I have often to destructure the state of an object as in : def foo(self) : (a,b,c,d) = (self.a,self.b,self.c,self.d) ... big code with a,b,c,d ... So I use the following method : def state(self) : return (self.a,self.b,self.c,self.d) so as to write : def foo(self) : (a,b,c,d) = self.state() ... big code with a,b,c,d ... This is probably not the best Python way to code, is it ? Is there a simple way to get the *ordered* list of instance variables as given in the parameter list of __init__ ? __dict__ gives it but not in order... Thanks a lot, franck From clp2 at rebertia.com Sun Oct 7 05:47:05 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Oct 2012 02:47:05 -0700 Subject: question on log as an instance method In-Reply-To: References: Message-ID: On Sun, Oct 7, 2012 at 1:33 AM, Franck Ditter wrote: > Hi ! Here is Python 3.2.3, MacOSX-Lion > > Question 0 : I may consider + as an hidden instance method , as > 1+2 is equivalent to (1).__add__(2) ? No, it's not nearly that simple. It's technically equivalent to operator.add(1, 2) [ http://docs.python.org/library/operator.html#operator.add ], which hints that there's additional logic involved. Some examples of the complexities (in the general case): * special methods are looked up on the objects' classes, ignoring per-instance attributes; see http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes * trying to add objects of incompatible types raises TypeError rather than AttributeError (which one might otherwise expect when a class doesn't define __add__() [or similar]) * such TypeErrors are often raised directly by the interpreter itself, rather than from within the body of some specific implementation of an operator special method * falling back to reflected methods (in the case of +, __radd__() [ http://docs.python.org/reference/datamodel.html#object.__radd__ ]) when the normal method fails or is not defined * returning NotImplemented triggers fallback (or if already attempting fallback, may cause the operation to fail) > Question 2 : After importing math, Why would that be relevant? Python is not generally the sort of language that would have the mere importation of a std lib module significantly affect language semantics. > why can't I consider log as > an instance method, after all ? >>>> (4).__log__() > AttributeError: 'float' object has no attribute '__log__' Because Python just simply did not choose to make "take the (natural) logarithm of" a built-in, overloadable operation (hence, in part, why you had to `import math` to even be able to access that calculation). And it further didn't happen to define math.log() in terms of a .log() or .__log__() instance method. Basically, it's somewhat arbitrary and some historical reasons are involved. Cheers, Chris From steve+comp.lang.python at pearwood.info Sun Oct 7 06:04:15 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Oct 2012 10:04:15 GMT Subject: question on log as an instance method References: Message-ID: <5071539f$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Oct 2012 10:33:36 +0200, Franck Ditter wrote: > Question : I may consider + as an hidden instance method , as 1+2 is > equivalent to (1).__add__(2) ? I also consider __abs__ as an instance > method : >>>> (-2).__abs__() > 2 The short answer is, yes. The *correct* answer is, not quite. So-called "dunder" methods (Double leading and trailing UNDERscore) methods like __add__, __abs__, __len__ and many others are treated slightly differently from ordinary instance methods, but only when they are automatically invoked by Python. If you explicitly call `instance.__add__(value)`, __add__ is treated as an ordinary instance method. But when you call `instance + value`, Python automatically invokes the __add__ method, but using slightly different method resolution rules. This is done for the sake of speed. > Question 1 : could the parser cope with the mandatory space in 1 > .__add__(2) ? Why not try it and see? py> 1 .__add__(2) 3 > Question 2 : After importing math, why can't I consider log as an > instance method, after all ? >>>> (4).__log__() > AttributeError: 'float' object has no attribute '__log__' Because importing a module does not magically add new methods to classes. Floats do not have a __log__ method, because they don't need one. Importing math doesn't create such a method. Why would it? What is the purpose of __log__? math.log doesn't need it. -- Steven From clp2 at rebertia.com Sun Oct 7 06:18:21 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Oct 2012 03:18:21 -0700 Subject: getting the state of an object In-Reply-To: References: Message-ID: On Sun, Oct 7, 2012 at 1:50 AM, Franck Ditter wrote: > Hi ! > > Another question. When writing a class, I have often to > destructure the state of an object as in : > > def foo(self) : > (a,b,c,d) = (self.a,self.b,self.c,self.d) > ... big code with a,b,c,d ... I would generally strongly frown on doing that (at least if the destructuring is actually that trivial). The "self."s are only 5 characters; that's hardly burdensome or verbose. Just write it out each time, i.e.: def foo(self): ? code with self.a, self.b, self.c, self.d ... Or in the extreme case, use "s" instead of "self" (using the name "self" is just a convention; it's not a language keyword or anything). > So I use the following method : > > def state(self) : > return (self.a,self.b,self.c,self.d) > > so as to write : > > def foo(self) : > (a,b,c,d) = self.state() > ... big code with a,b,c,d ... > > This is probably not the best Python way to code, is it ? Indeed it isn't. Don't bother with the pointless destructuring. And/or refactor your method so it's less big. > Is there a simple way to get the *ordered* list of instance > variables as given in the parameter list of __init__ ? There is no guaranteed correspondence whatsoever between __init__()'s parameters and the resulting object's instance variables. At a minimum, such a hack would fail to account for instance variables that are merely derived from the parameters (e.g. self.length = len(some_list_param) ) or are initialized to constant values (e.g. self.cache = {} ). And then there's private instance variables (e.g. self._foo = foo_param ); if the parameter is named "_foo", you're doing it wrong. That said, you can obtain the names of the parameters using the `inspect` module in the std lib. > __dict__ gives it but not in order? You can actually "fix" that, not that I at all recommend doing so: http://docs.python.org/dev/reference/datamodel.html#preparing-the-class-namespace Cheers, Chris From clp2 at rebertia.com Sun Oct 7 06:25:31 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Oct 2012 03:25:31 -0700 Subject: question on log as an instance method In-Reply-To: References: Message-ID: On Sun, Oct 7, 2012 at 1:33 AM, Franck Ditter wrote: > As a matter of netiquette, please don't post from a plausible-but-invalid email address, especially at a domain that doesn't seem to belong to you. (I got a mailer-daemon bounce when replying to your posts.) If you must use an invalid address, then please make use of the ".invalid" TLD (that's what it's for!). Regards, Chris From oscar.j.benjamin at gmail.com Sun Oct 7 06:28:09 2012 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 7 Oct 2012 11:28:09 +0100 Subject: getting the state of an object In-Reply-To: References: Message-ID: On Oct 7, 2012 9:57 AM, "Franck Ditter" wrote: > > Hi ! > > Another question. When writing a class, I have often to > destructure the state of an object as in : > > def foo(self) : > (a,b,c,d) = (self.a,self.b,self.c,self.d) > ... big code with a,b,c,d ... > What's wrong with the above? It seems fine to me. Alternatively, don't bother: just use self.a etc. > So I use the following method : > > def state(self) : > return (self.a,self.b,self.c,self.d) > > so as to write : > > def foo(self) : > (a,b,c,d) = self.state() > ... big code with a,b,c,d ... This just seems needlessly confusing. Someone reading your code will have to see that line, find the state function, check the order of the return values and then confirm that it matches up with the order in the original line. The first version doesn't have this problem. You can see that it's correct just by looking at it. > This is probably not the best Python way to code, is it ? > Is there a simple way to get the *ordered* list of instance > variables as given in the parameter list of __init__ ? I don't know about simple but you can get the names of the arguments from the __init__ method object using the inspect module. Then you can use getattr te recover the attribute values. I wouldn't bother though. Explicit is better than implicit. If you want to extract the instance attributes as local variables then just write the one line that does it as in your first example. Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Oct 7 07:11:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 7 Oct 2012 22:11:03 +1100 Subject: getting the state of an object In-Reply-To: References: Message-ID: On Sun, Oct 7, 2012 at 7:50 PM, Franck Ditter wrote: > def foo(self) : > (a,b,c,d) = (self.a,self.b,self.c,self.d) > ... big code with a,b,c,d ... > This strikes me as ripe for bug introduction. There's no problem if you're just reading those values, and mutating them is equally fine, but suddenly you need a different syntax for modifying instance members. def foo(self) : (a,b,c,d) = (self.a,self.b,self.c,self.d) e = a+b c.append(1234) d=self.d = 57 # Oops, mustn't forget to assign both! Since Python lacks the extensive scoping rules of (say) C++, it's much simpler and safer to be explicit about scope by adorning your instance variable references with their "self." tags. There's a guarantee that you can use "self.a" in any situation where you want to manipulate that member, a guarantee that's not upheld by the local "a". In theory, I suppose you could use a C-style preprocessor to help you. class Foo(object): #define asdf self.asdf #define qwer self.qwer def __init__(self,a,q): asdf=a; qwer=q def __repr__(self): return "Foo(%s,%s)"%(asdf,qwer) This is not, however, Pythonic code. But if you made some kind of better declaration than #define, and used a preprocessor that understood Python indentation rules and flushed its token list at the end of the class definition, you could perhaps make this look not-ugly. I still wouldn't recommend it, though. ChrisA From steve+comp.lang.python at pearwood.info Sun Oct 7 08:09:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Oct 2012 12:09:14 GMT Subject: getting the state of an object References: Message-ID: <507170e9$0$29978$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Oct 2012 10:50:38 +0200, Franck Ditter wrote: > Hi ! > > Another question. When writing a class, I have often to destructure the > state of an object as in : > > def foo(self) : > (a,b,c,d) = (self.a,self.b,self.c,self.d) > ... big code with a,b,c,d ... There's your problem right there: "big code". Methods should be small, ideally no more than a dozen lines or so. In my experience, small methods that have a very tight focus on doing one thing make it much easier to write, debug and maintain the method, and as a bonus having to write "self.a" is less of a burden. I've just looked at one of my classes, picked randomly, and the largest method is twelve lines, the second largest is eight, and the average is three lines. > So I use the following method : > > def state(self) : > return (self.a,self.b,self.c,self.d) > > so as to write : > > def foo(self) : > (a,b,c,d) = self.state() > ... big code with a,b,c,d ... > > This is probably not the best Python way to code, is it ? Not really the best. But I've seen worse. If you *have* to write "big code with a,b,c,d" then this is probably acceptable. But better to refactor your big method into smaller methods that don't need to use self.a, self.b, self.c, self.d so many times that writing them explicitly is a nuisance. > Is there a > simple way to get the *ordered* list of instance variables as given in > the parameter list of __init__ ? What you have written in method "state" is the simple way. By the way, we prefer "instance attribute" or even "instance member" over "instance variable" here. -- Steven From miki.tebeka at gmail.com Sun Oct 7 09:08:53 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 7 Oct 2012 06:08:53 -0700 (PDT) Subject: getting the state of an object In-Reply-To: References: Message-ID: <12957bcf-78a3-4d80-9acd-19e1e31f9afc@googlegroups.com> > Is there a simple way to get the *ordered* list of instance Here's one way to do it (weather doing it is a good idea or not is debatable): from operator import attrgetter def __init__(self, a, b, c, d): self.a, self.b, self.c, self.d = a, b, c, d get = attrgetter('a', 'b', 'c', 'd') self.state = lambda: get(self) From roy at panix.com Sun Oct 7 09:56:04 2012 From: roy at panix.com (Roy Smith) Date: Sun, 07 Oct 2012 09:56:04 -0400 Subject: getting the state of an object References: <507170e9$0$29978$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <507170e9$0$29978$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > I've just looked at one of my classes, picked randomly, and the largest > method is twelve lines, the second largest is eight, and the average is > three lines. I took a look at a subtree of the project I'm working on now. 116 python files, 20 kloc, 330 functions (mostly class methods). I did a quick-and-dirty "grep -n" job on them to find the line numbers of the def statements, then another quick-and-dirty python script to find the differences, and summarize. Results below (second column is length of 'def' block in lines, first column is number of blocks of that length). This is just dumb line counting; no attempt to exclude block comments, white space, docstrings, etc. There's three different authors represented here, but I'd guess 70% of the code is mine. Of the three, I'm probably the one who writes the most refactored code (i.e. smallest functions). I just went and found the longest of these (193 lines). It starts with a 95 line block comment. Of the 100-or so lines of real code, I suppose with some effort it could have been refactored some, but not hugely. 7 3 19 4 12 5 17 6 10 7 16 8 10 9 6 10 8 11 11 12 4 13 8 14 9 15 13 16 4 17 8 18 9 19 5 20 9 21 3 22 6 23 5 24 4 25 4 26 4 27 3 28 2 29 1 30 3 31 4 32 4 33 8 34 2 35 2 36 3 37 2 39 1 40 3 41 1 42 3 43 2 44 2 45 1 46 2 47 1 48 1 51 2 54 1 55 2 56 2 59 1 60 1 62 1 63 1 64 1 65 1 74 1 75 1 78 1 94 1 100 1 105 1 148 1 164 1 193 From typetoken at gmail.com Sun Oct 7 12:15:43 2012 From: typetoken at gmail.com (Token Type) Date: Sun, 7 Oct 2012 09:15:43 -0700 (PDT) Subject: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? Message-ID: <2d6d84d4-0f70-4280-96e2-f9fe17d5be8b@googlegroups.com> In order to solve the following question, http://nltk.googlecode.com/svn/trunk/doc/book/ch02.html: ? Use one of the predefined similarity measures to score the similarity of each of the following pairs of words. Rank the pairs in order of decreasing similarity. How close is your ranking to the order given here, an order that was established experimentally by (Miller & Charles, 1998): car-automobile, gem-jewel, journey-voyage, boy-lad, coast-shore, asylum-madhouse, magician-wizard, midday-noon, furnace-stove, food-fruit, bird-cock, bird-crane, tool-implement, brother-monk, lad-brother, crane-implement, journey-car, monk-oracle, cemetery-woodland, food-rooster, coast-hill, forest-graveyard, shore-woodland, monk-slave, coast-forest, lad-wizard, chord-smile, glass-magician, rooster-voyage, noon-string. (1) First, I put the word pairs in a list eg. pairs = [(car, automobile), (gem, jewel), (journey, voyage) ]. According to http://nltk.googlecode.com/svn/trunk/doc/book/ch02.html, I need to put them in the following format so as to calculate teh semantic similarity : wn.synset('right_whale.n.01').path_similarity(wn.synset('minke_whale.n.01')). In this case, I need to use loop to iterate each element in the above pairs. How can I refer to each element in the above pairs, i.e. pairs = [(car, automobile), (gem, jewel), (journey, voyage) ]. What's the index for 'car' and for 'automobile'? Thanks for your tips. (2) Since I can't solve the above index issue. I try to use dictionary as follows: >>> import nltk >>> from nltk.corpus import wordnet as wn >>> pairs = {'car':'automobile', 'gem':'jewel', 'journey':'voyage'} >>> for key in pairs: word1 = wn.synset(str(key) + '.n.01') word2 = wn.synset(str(pairs[key])+'.n.01') similarity = word1.path_similarity(word2) print key+'-'+pairs[key],similarity car-automobile 1.0 journey-voyage 0.25 gem-jewel 0.125 Now it seems that I can calculate the semantic similarity for each groups in the above dictionary. However, I want to sort according to the similarity value in the result before print the result out. Can sort dictionary elements according to their values? This is one of the requirement in this exercise. How can we make each group of words (e.g. car-automobile, jounrney-voyage, gem-jewel) sorted according to their similarity value? Thanks for your tips. From dihedral88888 at googlemail.com Sun Oct 7 13:01:58 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 7 Oct 2012 10:01:58 -0700 (PDT) Subject: Problems building Python from hg trunk on Open SUSE In-Reply-To: References: Message-ID: <819a2b71-2fc5-4d7c-a8f2-7099a2962355@googlegroups.com> Skip Montanaro? 2012?10?6????UTC+8??8?25?06???? > I haven't messed around with Python 3 recently, so decided to give it > > a whirl again. I cloned the trunk (cpython) and set about it. This > > is on an OpenSUSE 12.1 system. I configured like so: > > > > ./configure --prefix=/home/skipm/.linux-local > > > > and ran the usual "make ; make install". > > > > I'm a bit perplexed about how it is installed. Instead of installing > > shared objects in > > > > /home/skipm/.linux-local/lib/python3.4/lib-dynload > > > > they were installed in > > > > /home/skipm/.linux-local/lib64/python3.4/lib-dynload > > > > (note the "lib64" vs. "lib"). This would be fine, except sys.path > > doesn't include the "lib64" version of this path: > > > > % PYTHONPATH= PYTHONSTARTUP= ~/.linux-local/bin/python3.4 -S > > Could not find platform dependent libraries > > Consider setting $PYTHONHOME to [:] > > Python 3.4.0a0 (default:26200f535296, Oct 3 2012, 12:48:07) > > [GCC 4.4.6 [TWW]] on linux > > >>> import sys > > >>> sys.path > > ['', '', '/home/skipm/.linux-local/lib/python34.zip', > > '/home/skipm/.linux-local/lib/python3.4/', > > '/home/skipm/.linux-local/lib/python3.4/plat-linux', > > '/home/skipm/.linux-local/lib/lib-dynload'] > > > > I see the message about setting PYTHONHOME. (That happens to be bad > > advice as sys.prefix and sys.exec_prefix are identical in this case.) > > What I don't understand is why directories containing "lib64" are not > > in sys.path by default, given that that's where "make install" put > > things. > > > > GCC is as delivered by The Written Word. (This is a work computer. > > The powers that be settled on TWW awhile ago for packaging all open > > source software we use on Linux and Solaris, thus removing a headache > > from our support staff.) It is: > > > > % gcc --version > > gcc (GCC) 4.4.6 [TWW] > > Copyright (C) 2010 Free Software Foundation, Inc. > > This is free software; see the source for copying conditions. There is NO > > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > > > The architecture looks like this: > > > > % uname -a > > Linux udesktop264 3.1.0-1.2-desktop #1 SMP PREEMPT Thu Nov 3 14:45:45 > > UTC 2011 (187dde0) x86_64 x86_64 x86_64 GNU/Linux > > > > I don't see anything in the output of "./configure --help" which > > relates to 64-bit install directories, though I do see some lines in > > config.log about guessing the architecture. Some cursory googling > > didn't turn up any promising web pages, and I didn't find anything in > > the various documentation files in the repo related to building > > Python. > > > > Any suggestions about how to resolve this would be appreciated. > > > > Thx, > > > > Skip I am waiting for JYTHON and IRON PYTHON to be upgraded. From dihedral88888 at googlemail.com Sun Oct 7 13:01:58 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 7 Oct 2012 10:01:58 -0700 (PDT) Subject: Problems building Python from hg trunk on Open SUSE In-Reply-To: References: Message-ID: <819a2b71-2fc5-4d7c-a8f2-7099a2962355@googlegroups.com> Skip Montanaro? 2012?10?6????UTC+8??8?25?06???? > I haven't messed around with Python 3 recently, so decided to give it > > a whirl again. I cloned the trunk (cpython) and set about it. This > > is on an OpenSUSE 12.1 system. I configured like so: > > > > ./configure --prefix=/home/skipm/.linux-local > > > > and ran the usual "make ; make install". > > > > I'm a bit perplexed about how it is installed. Instead of installing > > shared objects in > > > > /home/skipm/.linux-local/lib/python3.4/lib-dynload > > > > they were installed in > > > > /home/skipm/.linux-local/lib64/python3.4/lib-dynload > > > > (note the "lib64" vs. "lib"). This would be fine, except sys.path > > doesn't include the "lib64" version of this path: > > > > % PYTHONPATH= PYTHONSTARTUP= ~/.linux-local/bin/python3.4 -S > > Could not find platform dependent libraries > > Consider setting $PYTHONHOME to [:] > > Python 3.4.0a0 (default:26200f535296, Oct 3 2012, 12:48:07) > > [GCC 4.4.6 [TWW]] on linux > > >>> import sys > > >>> sys.path > > ['', '', '/home/skipm/.linux-local/lib/python34.zip', > > '/home/skipm/.linux-local/lib/python3.4/', > > '/home/skipm/.linux-local/lib/python3.4/plat-linux', > > '/home/skipm/.linux-local/lib/lib-dynload'] > > > > I see the message about setting PYTHONHOME. (That happens to be bad > > advice as sys.prefix and sys.exec_prefix are identical in this case.) > > What I don't understand is why directories containing "lib64" are not > > in sys.path by default, given that that's where "make install" put > > things. > > > > GCC is as delivered by The Written Word. (This is a work computer. > > The powers that be settled on TWW awhile ago for packaging all open > > source software we use on Linux and Solaris, thus removing a headache > > from our support staff.) It is: > > > > % gcc --version > > gcc (GCC) 4.4.6 [TWW] > > Copyright (C) 2010 Free Software Foundation, Inc. > > This is free software; see the source for copying conditions. There is NO > > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > > > The architecture looks like this: > > > > % uname -a > > Linux udesktop264 3.1.0-1.2-desktop #1 SMP PREEMPT Thu Nov 3 14:45:45 > > UTC 2011 (187dde0) x86_64 x86_64 x86_64 GNU/Linux > > > > I don't see anything in the output of "./configure --help" which > > relates to 64-bit install directories, though I do see some lines in > > config.log about guessing the architecture. Some cursory googling > > didn't turn up any promising web pages, and I didn't find anything in > > the various documentation files in the repo related to building > > Python. > > > > Any suggestions about how to resolve this would be appreciated. > > > > Thx, > > > > Skip I am waiting for JYTHON and IRON PYTHON to be upgraded. From breamoreboy at yahoo.co.uk Sun Oct 7 13:49:52 2012 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 07 Oct 2012 18:49:52 +0100 Subject: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? In-Reply-To: <2d6d84d4-0f70-4280-96e2-f9fe17d5be8b@googlegroups.com> References: <2d6d84d4-0f70-4280-96e2-f9fe17d5be8b@googlegroups.com> Message-ID: On 07/10/2012 17:15, Token Type wrote: > In order to solve the following question, http://nltk.googlecode.com/svn/trunk/doc/book/ch02.html: > ? Use one of the predefined similarity measures to score the similarity of each of the following pairs of words. Rank the pairs in order of decreasing similarity. How close is your ranking to the order given here, an order that was established experimentally by (Miller & Charles, 1998): car-automobile, gem-jewel, journey-voyage, boy-lad, coast-shore, asylum-madhouse, magician-wizard, midday-noon, furnace-stove, food-fruit, bird-cock, bird-crane, tool-implement, brother-monk, lad-brother, crane-implement, journey-car, monk-oracle, cemetery-woodland, food-rooster, coast-hill, forest-graveyard, shore-woodland, monk-slave, coast-forest, lad-wizard, chord-smile, glass-magician, rooster-voyage, noon-string. > > (1) First, I put the word pairs in a list eg. > pairs = [(car, automobile), (gem, jewel), (journey, voyage) ]. According to http://nltk.googlecode.com/svn/trunk/doc/book/ch02.html, I need to put them in the following format so as to calculate teh semantic similarity : wn.synset('right_whale.n.01').path_similarity(wn.synset('minke_whale.n.01')). > > In this case, I need to use loop to iterate each element in the above pairs. How can I refer to each element in the above pairs, i.e. pairs = [(car, automobile), (gem, jewel), (journey, voyage) ]. What's the index for 'car' and for 'automobile'? Thanks for your tips. > > (2) Since I can't solve the above index issue. I try to use dictionary as follows: >>>> import nltk >>>> from nltk.corpus import wordnet as wn >>>> pairs = {'car':'automobile', 'gem':'jewel', 'journey':'voyage'} >>>> for key in pairs: > word1 = wn.synset(str(key) + '.n.01') > word2 = wn.synset(str(pairs[key])+'.n.01') > similarity = word1.path_similarity(word2) > print key+'-'+pairs[key],similarity > > > car-automobile 1.0 > journey-voyage 0.25 > gem-jewel 0.125 > > Now it seems that I can calculate the semantic similarity for each groups in the above dictionary. However, I want to sort according to the similarity value in the result before print the result out. Can sort dictionary elements according to their values? This is one of the requirement in this exercise. How can we make each group of words (e.g. car-automobile, jounrney-voyage, gem-jewel) > sorted according to their similarity value? > Thanks for your tips. > In your for loop save the data in a list rather than print it out and sort according to this http://wiki.python.org/moin/HowTo/Sorting#Operator_Module_Functions -- Cheers. Mark Lawrence. From woooee at gmail.com Sun Oct 7 13:58:18 2012 From: woooee at gmail.com (woooee) Date: Sun, 7 Oct 2012 10:58:18 -0700 (PDT) Subject: Unpaking Tuple References: <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> Message-ID: <69987244-3aa8-441b-83e8-2275e75f2b83@ph9g2000pbb.googlegroups.com> On Oct 6, 3:09?am, sajuptpm wrote: > I need a way to make following code working without any ValueError . > > >>> a, b, c, d = (1,2,3,4) > >>> a, b, c, d = (1,2,3). Why is it necessary to unpack the tuple into arbitrary variables. a_tuple=(1,2,3) for v in a_tuple: print v for ctr in range(len(a_tuple)): print a_tuple[ctr] From subhabangalore at gmail.com Sun Oct 7 15:30:52 2012 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sun, 7 Oct 2012 12:30:52 -0700 (PDT) Subject: Question on Python Split Message-ID: <68fc8fcb-b356-4fce-8541-e2abf371fecf@googlegroups.com> Dear Group, Suppose I have a string as, "Project Gutenberg has 36000 free ebooks for Kindle Android iPad iPhone." I am terming it as, str1= "Project Gutenberg has 36000 free ebooks for Kindle Android iPad iPhone." I am working now with a split function, str_words=str1.split() so, I would get the result as, ['Project', 'Gutenberg', 'has', '36000', 'free', 'ebooks', 'for', 'Kindle', 'Android', 'iPad', 'iPhone.'] But I am looking for, ['Project Gutenberg', 'has 36000', 'free ebooks', 'for Kindle', 'Android iPad', 'iPhone'] This can be done if we assign the string as, str1= "Project Gutenberg, has 36000, free ebooks, for Kindle, Android iPad, iPhone," and then assign the split statement as, str1_word=str1.split(",") would produce, ['Project Gutenberg', ' has 36000', ' free ebooks', ' for Kindle', ' Android iPad', ' iPhone', ''] My objective generally is achieved, but I want to convert each group here in tuple so that it can be embedded, like, [(Project Gutenberg), (has 36000), (free ebooks), (for Kindle), ( Android iPad), (iPhone), ''] as I see if I assign it as for i in str1_word: print i ti=tuple(i) print ti I am not getting the desired result. If I work again from tuple point, I get it as, >>> tup1=('Project Gutenberg') >>> tup2=('has 36000') >>> tup3=('free ebooks') >>> tup4=('for Kindle') >>> tup5=('Android iPad') >>> tup6=tup1+tup2+tup3+tup4+tup5 >>> print tup6 Project Gutenberghas 36000free ebooksfor KindleAndroid iPad Then how may I achieve it? If any one of the learned members can kindly guide me. Thanks in Advance, Regards, Subhabrata. NB: Apology for some minor errors. From johannes_graumann at web.de Sun Oct 7 15:44:38 2012 From: johannes_graumann at web.de (Johannes Graumann) Date: Sun, 07 Oct 2012 22:44:38 +0300 Subject: Convert MAC to hex howto Message-ID: Dear all, I'm trying to convert '00:08:9b:ce:f5:d4' to '\x00\x08\x9b\xce\xf5\xd4' for use in magic packet construction for WakeOnLan like so: wolsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) wolsocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) wolsocket.sendto('\xff'*6 + '\x00\x08\x9b\xce\xf5\xd4'*16, (expectedlanbroadcast, 80)) This is what I came up whith, but I remain puzzled on how to preserver the leading '\h' ... thanks for any hint expectedservermac = '00:08:9b:ce:f5:d4' hexcall = str.split(expectedservermac,":") hexcall.insert(0,'') hexcall = "\\x".join(hexcall).decode('string_escape') Thanks for any pointers. Sincerely, Joh From tjreedy at udel.edu Sun Oct 7 15:53:35 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 07 Oct 2012 15:53:35 -0400 Subject: wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value? In-Reply-To: <2d6d84d4-0f70-4280-96e2-f9fe17d5be8b@googlegroups.com> References: <2d6d84d4-0f70-4280-96e2-f9fe17d5be8b@googlegroups.com> Message-ID: On 10/7/2012 12:15 PM, Token Type wrote: > In this case, I need to use loop to iterate each element in the above > pairs. How can I refer to each element in the above pairs, i.e. pairs > = [(car, automobile), (gem, jewel), (journey, voyage) ]. What's the > index for 'car' and for 'automobile'? Thanks for your tips. >>> pairs = [('car', 'automobile'), ('gem', 'jewel')] >>> pairs[0][0] 'car' >>> pairs[1][1] 'jewel' >>> for a,b in pairs: a,b ('car', 'automobile') ('gem', 'jewel') -- Terry Jan Reedy From no.email at nospam.invalid Sun Oct 7 15:56:07 2012 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 07 Oct 2012 12:56:07 -0700 Subject: Convert MAC to hex howto References: Message-ID: <7xipamcazs.fsf@ruckus.brouhaha.com> Johannes Graumann writes: > '00:08:9b:ce:f5:d4' > ... > hexcall = "\\x".join(hexcall).decode('string_escape') I think it's best not to mess with stuff like that. Convert to integers then convert back: mac = '00:08:9b:ce:f5:d4' hexcall = ''.join(chr(int(c,16)) for c in mac.split(':')) From python at mrabarnett.plus.com Sun Oct 7 16:01:07 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 07 Oct 2012 21:01:07 +0100 Subject: Question on Python Split In-Reply-To: <68fc8fcb-b356-4fce-8541-e2abf371fecf@googlegroups.com> References: <68fc8fcb-b356-4fce-8541-e2abf371fecf@googlegroups.com> Message-ID: <5071DF83.4010805@mrabarnett.plus.com> On 2012-10-07 20:30, subhabangalore at gmail.com wrote: > Dear Group, > > Suppose I have a string as, > > "Project Gutenberg has 36000 free ebooks for Kindle Android iPad iPhone." > > I am terming it as, > > str1= "Project Gutenberg has 36000 free ebooks for Kindle Android iPad iPhone." > > I am working now with a split function, > > str_words=str1.split() > so, I would get the result as, > ['Project', 'Gutenberg', 'has', '36000', 'free', 'ebooks', 'for', 'Kindle', 'Android', 'iPad', 'iPhone.'] > > But I am looking for, > > ['Project Gutenberg', 'has 36000', 'free ebooks', 'for Kindle', 'Android iPad', 'iPhone'] > > This can be done if we assign the string as, > > str1= "Project Gutenberg, has 36000, free ebooks, for Kindle, Android iPad, iPhone," > > and then assign the split statement as, > > str1_word=str1.split(",") > > would produce, > > ['Project Gutenberg', ' has 36000', ' free ebooks', ' for Kindle', ' Android iPad', ' iPhone', ''] > It can also be done like this: >>> str1 = "Project Gutenberg has 36000 free ebooks for Kindle Android iPad iPhone." >>> # Splitting into words: >>> s = str1.split() >>> s ['Project', 'Gutenberg', 'has', '36000', 'free', 'ebooks', 'for', 'Kindle', 'Android', 'iPad', 'iPhone.'] >>> # Using slicing with a stride of 2 gives: >>> s[0 : : 2] ['Project', 'has', 'free', 'for', 'Android', 'iPhone.'] >>> # Similarly for the other words gives: >>> s[1 : : 2] ['Gutenberg', '36000', 'ebooks', 'Kindle', 'iPad'] >>> # Combining them in pairs, and adding an extra empty string in case there's an odd number of words: >>> [(x + ' ' + y).rstrip() for x, y in zip(s[0 : : 2], s[1 : : 2] + [''])] ['Project Gutenberg', 'has 36000', 'free ebooks', 'for Kindle', 'Android iPad', 'iPhone.'] > My objective generally is achieved, but I want to convert each group here in tuple so that it can be embedded, like, > > [(Project Gutenberg), (has 36000), (free ebooks), (for Kindle), ( Android iPad), (iPhone), ''] > > as I see if I assign it as > > for i in str1_word: > print i > ti=tuple(i) > print ti > > I am not getting the desired result. > > If I work again from tuple point, I get it as, >>>> tup1=('Project Gutenberg') >>>> tup2=('has 36000') >>>> tup3=('free ebooks') >>>> tup4=('for Kindle') >>>> tup5=('Android iPad') >>>> tup6=tup1+tup2+tup3+tup4+tup5 >>>> print tup6 > Project Gutenberghas 36000free ebooksfor KindleAndroid iPad > It's the comma that makes the tuple, not the parentheses, except for the empty tuple which is just empty parentheses, i.e. (). > Then how may I achieve it? If any one of the learned members can kindly guide me. >>> [((x + ' ' + y).rstrip(), ) for x, y in zip(s[0 : : 2], s[1 : : 2] + [''])] [('Project Gutenberg',), ('has 36000',), ('free ebooks',), ('for Kindle',), ('Android iPad',), ('iPhone.',)] Is this what you want? If you want it to be a list of pairs of words, then: >>> [(x, y) for x, y in zip(s[0 : : 2], s[1 : : 2] + [''])] [('Project', 'Gutenberg'), ('has', '36000'), ('free', 'ebooks'), ('for', 'Kindle'), ('Android', 'iPad'), ('iPhone.', '')] From tjreedy at udel.edu Sun Oct 7 16:03:20 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 07 Oct 2012 16:03:20 -0400 Subject: Unpaking Tuple In-Reply-To: <69987244-3aa8-441b-83e8-2275e75f2b83@ph9g2000pbb.googlegroups.com> References: <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> <69987244-3aa8-441b-83e8-2275e75f2b83@ph9g2000pbb.googlegroups.com> Message-ID: On 10/7/2012 1:58 PM, woooee wrote: > On Oct 6, 3:09 am, sajuptpm wrote: >> I need a way to make following code working without any ValueError . >> >>>>> a, b, c, d = (1,2,3,4) >>>>> a, b, c, d = (1,2,3) You cannot 'make' buggy code work -- except by changing it. >>> a, b, c, *d = (1,2,3) >>> d [] > Why is it necessary to unpack the tuple into arbitrary variables. It is not necessary. > a_tuple=(1,2,3) > for v in a_tuple: > print v This is often the right way to access any iterable. > for ctr in range(len(a_tuple)): > print a_tuple[ctr] This is seldom the right way. See the example below. Unpacking is for when you have known-length iterables. For instance, enumerate produces pairs. >>> for i, v in enumerate('abc'): print('Item {} is {}.'.format(i, v)) Item 0 is a. Item 1 is b. Item 2 is c. -- Terry Jan Reedy From python at mrabarnett.plus.com Sun Oct 7 16:04:38 2012 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 07 Oct 2012 21:04:38 +0100 Subject: Convert MAC to hex howto In-Reply-To: References: Message-ID: <5071E056.5010802@mrabarnett.plus.com> On 2012-10-07 20:44, Johannes Graumann wrote: > Dear all, > > I'm trying to convert > '00:08:9b:ce:f5:d4' > to > '\x00\x08\x9b\xce\xf5\xd4' > for use in magic packet construction for WakeOnLan like so: > wolsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > wolsocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) > wolsocket.sendto('\xff'*6 + '\x00\x08\x9b\xce\xf5\xd4'*16, > (expectedlanbroadcast, 80)) > > This is what I came up whith, but I remain puzzled on how to preserver the > leading '\h' ... thanks for any hint > > expectedservermac = '00:08:9b:ce:f5:d4' > hexcall = str.split(expectedservermac,":") > hexcall.insert(0,'') > hexcall = "\\x".join(hexcall).decode('string_escape') > > Thanks for any pointers. > It looks like you're using Python 2, so: >>> s = '00:08:9b:ce:f5:d4' >>> "".join(chr(int(x, 16)) for x in s.split(":")) '\x00\x08\x9b\xce\xf5\xd4' From tjreedy at udel.edu Sun Oct 7 16:08:47 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 07 Oct 2012 16:08:47 -0400 Subject: Question on Python Split In-Reply-To: <68fc8fcb-b356-4fce-8541-e2abf371fecf@googlegroups.com> References: <68fc8fcb-b356-4fce-8541-e2abf371fecf@googlegroups.com> Message-ID: On 10/7/2012 3:30 PM, subhabangalore at gmail.com wrote: > If I work again from tuple point, I get it as, >>>> tup1=('Project Gutenberg') >>>> tup2=('has 36000') >>>> tup3=('free ebooks') >>>> tup4=('for Kindle') >>>> tup5=('Android iPad') These are strings, not tuples. Numbered names like this are a bad idea. >>>> tup6=tup1+tup2+tup3+tup4+tup5 >>>> print tup6 > Project Gutenberghas 36000free ebooksfor KindleAndroid iPad tup1=('Project Gutenberg') tup2=('has 36000') tup3=('free ebooks') tup4=('for Kindle') tup5=('Android iPad') print(' '.join((tup1,tup2,tup3,tup4,tup5))) >>> Project Gutenberg has 36000 free ebooks for Kindle Android iPad -- Terry Jan Reedy From johannes_graumann at web.de Sun Oct 7 16:38:26 2012 From: johannes_graumann at web.de (Johannes Graumann) Date: Sun, 07 Oct 2012 23:38:26 +0300 Subject: Convert MAC to hex howto References: <5071E056.5010802@mrabarnett.plus.com> Message-ID: MRAB wrote: > On 2012-10-07 20:44, Johannes Graumann wrote: >> Dear all, >> >> I'm trying to convert >> '00:08:9b:ce:f5:d4' >> to >> '\x00\x08\x9b\xce\xf5\xd4' >> for use in magic packet construction for WakeOnLan like so: >> wolsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) >> wolsocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) >> wolsocket.sendto('\xff'*6 + '\x00\x08\x9b\xce\xf5\xd4'*16, >> (expectedlanbroadcast, 80)) >> >> This is what I came up whith, but I remain puzzled on how to preserver >> the leading '\h' ... thanks for any hint >> >> expectedservermac = '00:08:9b:ce:f5:d4' >> hexcall = str.split(expectedservermac,":") >> hexcall.insert(0,'') >> hexcall = "\\x".join(hexcall).decode('string_escape') >> >> Thanks for any pointers. >> > It looks like you're using Python 2, so: > > >>> s = '00:08:9b:ce:f5:d4' > >>> "".join(chr(int(x, 16)) for x in s.split(":")) > '\x00\x08\x9b\xce\xf5\xd4' Many thanks! Joh From johannes_graumann at web.de Sun Oct 7 16:38:39 2012 From: johannes_graumann at web.de (Johannes Graumann) Date: Sun, 07 Oct 2012 23:38:39 +0300 Subject: Convert MAC to hex howto References: <7xipamcazs.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Johannes Graumann writes: >> '00:08:9b:ce:f5:d4' >> ... >> hexcall = "\\x".join(hexcall).decode('string_escape') > > I think it's best not to mess with stuff like that. Convert to integers > then convert back: > > mac = '00:08:9b:ce:f5:d4' > hexcall = ''.join(chr(int(c,16)) for c in mac.split(':')) Thanks to you as well! Joh From __peter__ at web.de Sun Oct 7 17:01:17 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 07 Oct 2012 23:01:17 +0200 Subject: Convert MAC to hex howto References: Message-ID: Johannes Graumann wrote: > Dear all, > > I'm trying to convert > '00:08:9b:ce:f5:d4' > to > '\x00\x08\x9b\xce\xf5\xd4' > for use in magic packet construction for WakeOnLan like so: > wolsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) > wolsocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) > wolsocket.sendto('\xff'*6 + '\x00\x08\x9b\xce\xf5\xd4'*16, > (expectedlanbroadcast, 80)) > > This is what I came up whith, but I remain puzzled on how to preserver the > leading '\h' ... thanks for any hint > > expectedservermac = '00:08:9b:ce:f5:d4' > hexcall = str.split(expectedservermac,":") > hexcall.insert(0,'') > hexcall = "\\x".join(hexcall).decode('string_escape') >>> import binascii >>> expectedservermac = '00:08:9b:ce:f5:d4' >>> binascii.unhexlify(expectedservermac.replace(":", "")) '\x00\x08\x9b\xce\xf5\xd4' From ye.youqun at eisoo.com Sun Oct 7 20:53:46 2012 From: ye.youqun at eisoo.com (=?UTF-8?B?5Y+25L2R576k?=) Date: Mon, 08 Oct 2012 08:53:46 +0800 Subject: how to run shell command like "< References: <506555B6.5040406@eisoo.com> <50664543.1050809@eisoo.com> Message-ID: <5072241A.8000201@eisoo.com> ? 2012-9-29 19:53, Kushal Kumaran ??: > On Sat, Sep 29, 2012 at 6:18 AM, ??? wrote: >> ? 2012-9-28 16:16, Kushal Kumaran ??: >>> On Fri, Sep 28, 2012 at 1:15 PM, ??? wrote: >>> >>>> Hi, all, >>>> >>>> I have the shell command like this: >>>> >>>> sfdisk -uM /dev/sdb<< EOT >>>> ,1000,83 >>>> ,,83 >>>> EOT >>>> >>>> >>>> I have tried subprocess.Popen, pexpect.spawn and os.popen, but none >>>> of >>>> these works, but when I type this shell command in shell, it is works >>>> fine. >>>> I wonder how to emulate this type of behavior in python , and if someone >>>> can >>>> figure out the reason why? >>>> >>>> The sample code of subprocess.Popen is: >>>> >>>> command = ["sfdisk", "-uM", target, "<>>> ",", 1000, ",", "83", "\r\n", >>>> ",", ",", "83", "\r\n", "EOT", "\r\n"] >>>> >>>> pobj = subprocess.Popen (command, bufsize=1, \ >>>> stderr=subprocess.PIPE, stdout=subprocess.PIPE) >>>> >>>> res = pobj.stderr.readline () >>>> if res is not None and pobj.returncode != 0: >>>> observer.ShowProgress (u"??? %s ?????" % target) >>>> return False >>>> >>> The "<>> command. If you use the communicate method, you can provide input as >>> an argument: >>> >>> command = ["sfdisk", "-uM", target ] >>> instructions = """ >>> ,1000,83 >>> ,,83 >>> """ >>> pobj = subprocess.Popen(command, stdin=subprocess.PIPE, >>> stdout=subprocess.PIPE, stderr=subprocess.PIPE) >>> (output, errors) = pobj.communicate(instructions) >> I tried this, but it is still not work. >> > What do you mean by "not work"? Sorry for replying so late, these days are long vocation in china. If I type command in shell line by line, the command will run as expected, but when I invoke the command in python, it is always failed. Which is what I mean "not work". > > - If you get an exception, copy the entire traceback into an email No exception occured. > > - If you do not get an exception, print out the value of the "errors" > variable to see why the command failed. You can also check > pobj.returncode for the exit status of the subprocess. I solved this problem as below: fop = os.popen ("sfdisk -uM %s < > A possibility is that you have to replace "sfdisk" with the full path > to the binary, if it cannot be located on the PATH. So you will > replace it with "/usr/sbin/sfdisk", or "/sbin/sfdisk", or wherever the > file actually is. > > >> If I want to read the output line by line and not put all output to memory buffer in one >> time, how to write the code? > You can read line by line by calling pobj.stdout.readline() and > pobj.stderr.readline(). You can send input to the process by calling > pobj.stdin.write(). If you manage this interaction "by hand", you > should not call communicate(). Also, you should be aware of the > problem mentioned in the subprocess documentation: > > "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." > > Is there any reason why you need to read line-by-line? You could use > communicate(), and then call stdout.splitlines() to get a list of > lines, if that's all you need. > From wuwei23 at gmail.com Sun Oct 7 21:19:05 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 7 Oct 2012 18:19:05 -0700 (PDT) Subject: notmm is dead! References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> Message-ID: <5e487f2e-81c5-4875-ae5c-e8e3b525ab72@ph9g2000pbb.googlegroups.com> On Oct 6, 12:59?pm, Michael Torrie wrote: > I suppose a person can fail a turing test... You did, yes :) From dwightdhutto at gmail.com Sun Oct 7 21:45:02 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Sun, 7 Oct 2012 21:45:02 -0400 Subject: notmm is dead! In-Reply-To: <5e487f2e-81c5-4875-ae5c-e8e3b525ab72@ph9g2000pbb.googlegroups.com> References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> <5e487f2e-81c5-4875-ae5c-e8e3b525ab72@ph9g2000pbb.googlegroups.com> Message-ID: On Sun, Oct 7, 2012 at 9:19 PM, alex23 wrote: > On Oct 6, 12:59 pm, Michael Torrie wrote: >> I suppose a person can fail a turing test... > > You did, yes :) > What is failed, but a timeline in this scenario, if you found the answer in the end? Failure becomes answer not given in interval required, but did anybody else, and if so...how many? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From wuwei23 at gmail.com Sun Oct 7 22:08:07 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 7 Oct 2012 19:08:07 -0700 (PDT) Subject: notmm is dead! References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> <5e487f2e-81c5-4875-ae5c-e8e3b525ab72@ph9g2000pbb.googlegroups.com> Message-ID: <597604fe-d1ae-495b-8ec7-780f61161f4e@ph9g2000pbb.googlegroups.com> On Oct 8, 11:45?am, Dwight Hutto wrote: > What is failed, but a timeline in this scenario, if you found the > answer in the end? It was a _joke_ referring to Michael Torrie's email addressing the 88888 Dihedral bot _as if it was a person_. > Failure becomes answer not given in interval required, but did anybody > else, and if so...how many? 23? I really have no idea what you're asking here. From torriem at gmail.com Sun Oct 7 22:54:32 2012 From: torriem at gmail.com (Michael Torrie) Date: Sun, 07 Oct 2012 20:54:32 -0600 Subject: notmm is dead! In-Reply-To: <597604fe-d1ae-495b-8ec7-780f61161f4e@ph9g2000pbb.googlegroups.com> References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> <5e487f2e-81c5-4875-ae5c-e8e3b525ab72@ph9g2000pbb.googlegroups.com> <597604fe-d1ae-495b-8ec7-780f61161f4e@ph9g2000pbb.googlegroups.com> Message-ID: <50724068.4080703@gmail.com> On 10/07/2012 08:08 PM, alex23 wrote: > On Oct 8, 11:45 am, Dwight Hutto wrote: >> What is failed, but a timeline in this scenario, if you found the >> answer in the end? > > It was a _joke_ referring to Michael Torrie's email addressing the > 88888 Dihedral bot _as if it was a person_. Well it would be useful to probe the bot's parameters... From g6dtjrhsr4 at gmail.com Sun Oct 7 22:55:41 2012 From: g6dtjrhsr4 at gmail.com (g6dtjrhsr4 at gmail.com) Date: Sun, 7 Oct 2012 19:55:41 -0700 (PDT) Subject: iPhone App To Help You Learn French Faster By Using Flashcards With Pictures Message-ID: http://tinyurl.com/frenchflashcardswithpictures - "French Flashcards with Pictures" is an iPhone app that will help you learn French faster by using flashcards with pictures (learn over 300 most commonly used words in the English / French language from A to Z), thanks. From yujian4newsgroup at gmail.com Sun Oct 7 23:02:49 2012 From: yujian4newsgroup at gmail.com (yujian) Date: Mon, 08 Oct 2012 11:02:49 +0800 Subject: How to control the internet explorer? In-Reply-To: References: <2d6d84d4-0f70-4280-96e2-f9fe17d5be8b@googlegroups.com> Message-ID: <50724259.50204@gmail.com> I want to save all the URLs in current opened windows, and then close all the windows. From wuwei23 at gmail.com Sun Oct 7 23:37:53 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 7 Oct 2012 20:37:53 -0700 (PDT) Subject: How to control the internet explorer? References: <2d6d84d4-0f70-4280-96e2-f9fe17d5be8b@googlegroups.com> Message-ID: <303d6d50-0672-4e76-8c3b-081ca433a8e3@p5g2000pbs.googlegroups.com> On Oct 8, 1:03?pm, yujian wrote: > I want to save all the URLs in current opened windows, ?and then close > all the windows. Try mechanize or Selenium. From jason at powerpull.net Sun Oct 7 23:42:04 2012 From: jason at powerpull.net (Jason Friedman) Date: Sun, 7 Oct 2012 21:42:04 -0600 Subject: notmm is dead! In-Reply-To: <50724068.4080703@gmail.com> References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> <5e487f2e-81c5-4875-ae5c-e8e3b525ab72@ph9g2000pbb.googlegroups.com> <597604fe-d1ae-495b-8ec7-780f61161f4e@ph9g2000pbb.googlegroups.com> <50724068.4080703@gmail.com> Message-ID: >> It was a _joke_ referring to Michael Torrie's email addressing the >> 88888 Dihedral bot _as if it was a person_. > > Well it would be useful to probe the bot's parameters... Five eights is a busy bot: http://www.velocityreviews.com/forums/t806110-p8-ok-lets-start-real-programming-in-c-for-problems.html http://www.edaboard.co.uk/a-cheap-or-free-version-of-system-verilog-t521889.html From torriem at gmail.com Sun Oct 7 23:45:34 2012 From: torriem at gmail.com (Michael Torrie) Date: Sun, 07 Oct 2012 21:45:34 -0600 Subject: notmm is dead! In-Reply-To: References: <506e282e$0$1726$c3e8da3$76491128@news.astraweb.com> <5e487f2e-81c5-4875-ae5c-e8e3b525ab72@ph9g2000pbb.googlegroups.com> <597604fe-d1ae-495b-8ec7-780f61161f4e@ph9g2000pbb.googlegroups.com> <50724068.4080703@gmail.com> Message-ID: <50724C5E.80501@gmail.com> On 10/07/2012 09:42 PM, Jason Friedman wrote: >>> It was a _joke_ referring to Michael Torrie's email addressing the >>> 88888 Dihedral bot _as if it was a person_. >> >> Well it would be useful to probe the bot's parameters... > > Five eights is a busy bot: > http://www.velocityreviews.com/forums/t806110-p8-ok-lets-start-real-programming-in-c-for-problems.html > http://www.edaboard.co.uk/a-cheap-or-free-version-of-system-verilog-t521889.html Indeed and he doesn't make much more sense in any of these venues. And it does not seem to engage in conversation on any of these other forums either. From dwightdhutto at gmail.com Mon Oct 8 00:18:45 2012 From: dwightdhutto at gmail.com (Dwight Hutto) Date: Mon, 8 Oct 2012 00:18:45 -0400 Subject: notmm is dead! In-Reply-To: <20121004141046.677dac1e8bf6dada0b6af6b3@gmail.com> References: <20121004141046.677dac1e8bf6dada0b6af6b3@gmail.com> Message-ID: On Thu, Oct 4, 2012 at 2:10 PM, Etienne Robillard wrote: > Dear list, > > Due to lack of energy and resources i'm really sad to announce the removal of notmm from pypi and bitbucket. I deleted > also my account from bitbucket as it was not really useful for me. Not 1 response? notmm will continue to be accessible from my master > site at http://gthc.org/dist/notmm until the server get down, as I cannot find money to pay for the hosting of notmm.org, > neither anyone to encourage the project so it can grow further. Saw a niche, and announced your takeover? > > I have tried to develop a coherent extension for Django using the open source model but I'm afraid to have been > bitten by its failure to encourage a free market over one dictated by profit and the use of cheap tricks to compete unfairly > with perhaps too much openness. I always will also continue to love and use free softwares but sadly it seems asking for a little > fairness is too much asked to competitors dedicated in stealing and subverting my work for their own advantages... > Then bring in an OS project of your own, and know that's what happens. > I therefore refuse to continue any longer being mocked by competitors asking excessive prices for having a broken Internet dictated by > a few companies and decide the content I should be visiting. > Just market penetration, not mocking. > Shall you have anything you wish saying I'll be open to discuss further on this list. I wish also to thanks the supporters > of the project who have invested time and energy into my business and dedication to the notmm project. It has to have an equal, or equivlilaint value to the current statistically valued features. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com From justmailharsh at gmail.com Mon Oct 8 05:50:37 2012 From: justmailharsh at gmail.com (justmailharsh at gmail.com) Date: Mon, 8 Oct 2012 02:50:37 -0700 (PDT) Subject: Reading properties file in Python, except using ConfigParser() In-Reply-To: References: Message-ID: On Friday, October 5, 2012 5:03:01 PM UTC+5:30, G?nther Dietrich wrote: > justmailharsh at gmail.com wrote: > > > > >How to read properties file in Python? I found ConfigParser() but it has a > > >'section' limitation, so looking for other alternatives. > > > > Have a look at PyYAML. > > > > > > > > Best regards, > > > > G?nther Thanks for responding guys. I got the solution from here - http://www.daniweb.com/software-development/python/threads/435902/reading-properties-file-in-python-except-using-configparser# Posting it here for others' benefit.. From bnrj.rudra at gmail.com Mon Oct 8 07:11:00 2012 From: bnrj.rudra at gmail.com (=?UTF-8?Q?=E0=A6=B0=E0=A7=81=E0=A6=A6=E0=A7=8D=E0=A6=B0_?= =?UTF-8?Q?=E0=A6=AC=E0=A7=8D=E0=A6=AF=E0=A6=BE=E0=A6=A3=E0=A6=BE?= =?UTF-8?Q?=E0=A6=B0=E0=A7=8D=E0=A6=9C=E0=A7=80?=) Date: Mon, 08 Oct 2012 12:11:00 +0100 Subject: tidy to convert google scholar page in xml Message-ID: <1349694660.6783.7.camel@roddur> Dear friends, I am trying to convert a google scholar page to xml. First, I am getting the mapge using the script: #!/usr/bin/python from HTMLParser import HTMLParser import urllib2 response = urllib2.urlopen(urllib2.Request("http://scholar.google.co.uk/scholar?q=albert+einstein%2B1905&btnG=&hl=en&as_sdt=0%2C5&as_sdtp=", headers={"User-Agent":"Mozilla/5.0 Cheater/1.0"})) f=open('sch.html','w') f.write(response.read()) Which is giving sch.html starting as: if I try tidy to convert this html page to xml, I get: $ tidy isn't allowed in
elements line 3 column 23 - Info:
previously mentioned /************************** AND MANY MORE WARNNING **************************/ Info: Document content looks like HTML 4.01 Transitional Info: No system identifier in emitted doctype 131 warnings, 0 errors were found! albert einstein+1905 - Google Scholar