Re: lambda in list comprehension acting funny

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 21:33:40 -0700, rusi wrote: > On Jul 11, 11:41 am, Daniel Fetchinson > wrote: >> funcs = [ lambda x: x**i for i in range( 5 ) ] print funcs[0]( 2 ) >> print funcs[1]( 2 ) >> print funcs[2]( 2 ) >> >> This gives me >> >> 16 >> 16 >> 16 >> >> When I was excepting >> >> 1 >> 2 >>

Re: Tkinter.event.widget: handler gets name instead of widget.

2012-07-12 Thread Frederic Rentsch
On Tue, 2012-07-10 at 15:11 -0700, Rick Johnson wrote: > I've tried to condense your code using the very limited info you have > provided. I have removed unnecessarily configuring of widgets and > exaggerated the widget borders to make debugging easier. Read below > for Q&A. > > ## START CONDENSED

Re: How to safely maintain a status file

2012-07-12 Thread Chris Angelico
On Fri, Jul 13, 2012 at 2:26 PM, wrote: > On Thursday, July 12, 2012 10:13:47 PM UTC-5, Steven D'Aprano wrote: >> Rick has obviously never tried to open a file for reading when somebody >> else has it opened, also for reading, and discovered that despite Windows >> being allegedly a multi-user op

Re: lambda in list comprehension acting funny

2012-07-12 Thread rusi
On Jul 11, 11:41 am, Daniel Fetchinson wrote: > funcs = [ lambda x: x**i for i in range( 5 ) ] > print funcs[0]( 2 ) > print funcs[1]( 2 ) > print funcs[2]( 2 ) > > This gives me > > 16 > 16 > 16 > > When I was excepting > > 1 > 2 > 4 > > Does anyone know why? > > Cheers, > Daniel Your expectatio

Re: How to safely maintain a status file

2012-07-12 Thread rantingrickjohnson
On Thursday, July 12, 2012 10:13:47 PM UTC-5, Steven D'Aprano wrote: > Rick has obviously never tried to open a file for reading when somebody > else has it opened, also for reading, and discovered that despite Windows > being allegedly a multi-user operating system, you can't actually have > mu

Re: How to safely maintain a status file

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 23:49:02 -0400, Gene Heskett wrote: > When I wanted to impress the visiting frogs, I often did something I > have never been able to do on any other operating system since, start > assembling a long assembly language file on one of the screens on the > color monitor, hit the cl

Writing a wrapper - any tips?

2012-07-12 Thread Temia Eszteri
I'm going to be looking into writing a wrapper for the Allegro 5 game development libraries, either with ctypes or Cython. They technically have a basic 1:1 ctypes wrapper currently, but I wanted to make something more pythonic, because it'd be next to impossible to deal with the memory management

Re: How to safely maintain a status file

2012-07-12 Thread Gene Heskett
On Thursday 12 July 2012 23:21:16 Steven D'Aprano did opine: > On Fri, 13 Jul 2012 12:12:01 +1000, Chris Angelico wrote: > > On Fri, Jul 13, 2012 at 11:20 AM, Rick Johnson > > > > wrote: > >> On Jul 12, 2:39 pm, Christian Heimes wrote: > >>> Windows's file system layer is not POSIX compatible.

Re: How to safely maintain a status file

2012-07-12 Thread Steven D'Aprano
On Fri, 13 Jul 2012 12:12:01 +1000, Chris Angelico wrote: > On Fri, Jul 13, 2012 at 11:20 AM, Rick Johnson > wrote: >> On Jul 12, 2:39 pm, Christian Heimes wrote: >>> Windows's file system layer is not POSIX compatible. For example you >>> can't remove or replace a file while it is opened by a p

Re: adding a simulation mode

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 14:20:18 +0100, andrea crotti wrote: > One thing that I don't quite understand is why some calls even if I > catch the exception still makes the whole program quit. Without seeing your whole program, we can't possibly answer this. But by consulting my crystal ball, I bet you

Re: adding a simulation mode

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 16:37:42 +0100, andrea crotti wrote: > 2012/7/12 John Gordon : >> In andrea crotti >> writes: >> >>> Well that's what I thought, but I can't find any explicit exit >>> anywhere in shutil, so what's going on there? >> >> Try catching SystemExit specifically (it doesn't inherit

Re: How to safely maintain a status file

2012-07-12 Thread Chris Angelico
On Fri, Jul 13, 2012 at 11:20 AM, Rick Johnson wrote: > On Jul 12, 2:39 pm, Christian Heimes wrote: >> Windows's file system layer is not POSIX compatible. For example >> you can't remove or replace a file while it is opened by a process. > > Sounds like a reasonable fail-safe to me. POSIX says

Re: adding a simulation mode

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 15:17:03 +0100, andrea crotti wrote: > Well that's what I thought, but I can't find any explicit exit anywhere > in shutil, so what's going on there? Hard to say, since you don't give any context to your question. When replying to posts, please leave enough quoted to establis

Re: How to safely maintain a status file

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 15:05:26 +0200, Christian Heimes wrote: > You need to flush the data to disk as well as the metadata of the file > and its directory in order to survive a system crash. The close() > syscall already makes sure that all data is flushed into the IO layer of > the operating system

Re: Python and Qt4 Designer

2012-07-12 Thread Vincent Vande Vyvre
On 12/07/12 08:42, Jean Dubois wrote: > On 12 jul, 02:59, Vincent Vande Vyvre > wrote: >> On 11/07/12 17:37, Jean Dubois wrote: >> >> >> >> >> >> >> >>> I'm trying to combine python-code made with QT4 designer with plain >>> python statements like >>> file = open("test","w") >>> Can anyone tell me

Re: How to safely maintain a status file

2012-07-12 Thread Rick Johnson
On Jul 12, 2:39 pm, Christian Heimes wrote: > Windows's file system layer is not POSIX compatible. For example > you can't remove or replace a file while it is opened by a process. Sounds like a reasonable fail-safe to me. Not much unlike a car ignition that will not allow starting the engine if

Re: How to safely maintain a status file

2012-07-12 Thread Christian Heimes
Am 12.07.2012 19:43, schrieb Laszlo Nagy: > Well, I didn't know that this is going to work. At least it does not > work on Windows 7 (which should be POSIX compatible?) Nope, Windows's file system layer is not POSIX compatible. For example you can't remove or replace a file while it is opened by a

Re: adding a simulation mode

2012-07-12 Thread Dieter Maurer
andrea crotti wrote at 2012-7-12 14:20 +0100: >One thing that I don't quite understand is why some calls even if I >catch the exception still makes the whole program quit. >For example this > >try: >copytree('sjkdf', 'dsflkj') >Popen(['notfouhd'], shell=True) >except Excepti

Re: syntax error message

2012-07-12 Thread MRAB
On 12/07/2012 18:48, John Magness wrote: Using Python 3.2.3 In shell I made a simple program; dog=2,cat=3,cow=dog+cat Entered cow and received 5 as answer Saved-as Trial-1.py in a user folder Went to folder and select "edit with shell" for that file Trial-1.py displayed, clicked save, run and the

Re: How to safely maintain a status file

2012-07-12 Thread Laszlo Nagy
Windows doesn't suppport atomic renames if the right side exists. I suggest that you implement two code paths: if os.name == "posix": rename = os.rename else: def rename(a, b): try: os.rename(a, b) except OSError, e: if e.errno != 183:

syntax error message

2012-07-12 Thread John Magness
Using Python 3.2.3 In shell I made a simple program; dog=2,cat=3,cow=dog+cat Entered cow and received 5 as answer Saved-as Trial-1.py in a user folder Went to folder and select "edit with shell" for that file Trial-1.py displayed, clicked save, run and then run module to activate program got messag

Re: How to safely maintain a status file

2012-07-12 Thread Laszlo Nagy
This is not a contradiction. Although the rename operation is atomic, the whole "change status" process is not. It is because there are two operations: #1 delete old status file and #2. rename the new status file. And because there are two operations, there is still a race condition. I see no co

Re: How to safely maintain a status file

2012-07-12 Thread Laszlo Nagy
Sorry, but you are wrong. It's just one operation that boils down to "point name to a different inode". After the rename op the file name either points to a different inode or still to the old name in case of an error. The OS guarantees that all processes either see the first or second state (in

Re: lambda in list comprehension acting funny

2012-07-12 Thread Rotwang
On 12/07/2012 04:59, Steven D'Aprano wrote: On Wed, 11 Jul 2012 08:41:57 +0200, Daniel Fetchinson wrote: funcs = [ lambda x: x**i for i in range( 5 ) ] Here's another solution: from functools import partial funcs = [partial(lambda i, x: x**i, i) for i in range(5)] Notice that the arguments

Re: lambda in list comprehension acting funny

2012-07-12 Thread Ian Kelly
On Wed, Jul 11, 2012 at 9:59 PM, Steven D'Aprano wrote: > On Wed, 11 Jul 2012 08:41:57 +0200, Daniel Fetchinson wrote: > >> funcs = [ lambda x: x**i for i in range( 5 ) ] > > Here's another solution: > > from functools import partial > funcs = [partial(lambda i, x: x**i, i) for i in range(5)] > >

Re: How to safely maintain a status file

2012-07-12 Thread Ross Ridge
Laszlo Nagy: > This is not a contradiction. Although the rename operation is atomic, > the whole "change status" process is not. It is because there are two > operations: #1 delete old status file and #2. rename the new status > file. And because there are two operations, there is still a race > co

PSF Python Brochure is ready to print: accepting ad orders now!

2012-07-12 Thread PSF Python Brochure Project Team
The PSF Python Brochure Project has finished the content and layout phase. The first full format pre-production issues were shown at the PSF booth during the EuroPython Conference 2012 in Florence, Italy, and caused a lot of excitement - to print the brochure we now need supporting sponsors. Pleas

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
2012/7/12 John Gordon : > In andrea crotti > writes: > >> Well that's what I thought, but I can't find any explicit exit >> anywhere in shutil, so what's going on there? > > Try catching SystemExit specifically (it doesn't inherit from Exception, > so "except Exception" won't catch it.) > > --

Re: adding a simulation mode

2012-07-12 Thread John Gordon
In andrea crotti writes: > Well that's what I thought, but I can't find any explicit exit > anywhere in shutil, so what's going on there? Try catching SystemExit specifically (it doesn't inherit from Exception, so "except Exception" won't catch it.) -- John Gordon A is for

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
Well that's what I thought, but I can't find any explicit exit anywhere in shutil, so what's going on there? -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: PollyReports 1.5 -- Band-oriented PDF Report Generator

2012-07-12 Thread Chris Gonnerman
Wow, I posted this on Github weeks ago, and got no feedback; put it on PyPI at the same time, with the same results; but one day on the Python list and I have lots of excellent feedback. I've just posted PollyReports 1.5.1, with no operational changes. The package includes a corrected testpoll

Re: adding a simulation mode

2012-07-12 Thread John Gordon
In andrea crotti writes: > try: > copytree('sjkdf', 'dsflkj') > Popen(['notfouhd'], shell=True) > except Exception as e: > print("here") > behaves differently from: > try: > Popen(['notfouhd'], shell=True) > copytree('sjkdf', 'dsflkj') >

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
One way instead that might actually work is this def default_mock_action(func_name): def _default_mock_action(*args, **kwargs): print("running {} with args {} and {}".format(func_name, args, kwargs)) return _default_mock_action def mock_fs_actions(to_run): """Take a function

Re: introduction and first question about multithreading

2012-07-12 Thread Dave Angel
On 07/11/2012 03:51 AM, Vojtěch Polášek wrote: > Greetings, > My name is Vojta and I am blind student. I am slowly learning Python for > about 4 years and I like it alot, mostly its ability to run on various > platforms. > My primary system is Ubuntu 12.04, but I have Windows XP at hand. I am > usi

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
One thing that I don't quite understand is why some calls even if I catch the exception still makes the whole program quit. For example this try: copytree('sjkdf', 'dsflkj') Popen(['notfouhd'], shell=True) except Exception as e: print("here") behaves differently f

Re: How to safely maintain a status file

2012-07-12 Thread Hans Mulder
On 12/07/12 14:30:41, Laszlo Nagy wrote: >> You are contradicting yourself. Either the OS is providing a fully >> atomic rename or it doesn't. All POSIX compatible OS provide an atomic >> rename functionality that renames the file atomically or fails without >> loosing the target side. On POSIX OS

Re: How to safely maintain a status file

2012-07-12 Thread Christian Heimes
Am 12.07.2012 14:30, schrieb Laszlo Nagy: > This is not a contradiction. Although the rename operation is atomic, > the whole "change status" process is not. It is because there are two > operations: #1 delete old status file and #2. rename the new status > file. And because there are two operation

Re: ANN: PollyReports 1.5 -- Band-oriented PDF Report Generator

2012-07-12 Thread Rodrick Brown
On Jul 11, 2012, at 8:44 PM, Simon Cropper wrote: > On 12/07/12 00:06, Chris Gonnerman wrote: >> I've held off announcing this until I was sure it was really stable; >> it's been 19 days since I made the last change to it, so here goes. >> PollyReports is my Python module for report generation. I

Re: ANN: PollyReports 1.5 -- Band-oriented PDF Report Generator

2012-07-12 Thread Chris Gonnerman
Apparently my test hasn't kept up with my update. I'll get it revised soon and make a new release. BTW... who is Simon? I wrote the tutorial. (Solomoriah is an old handle I still use a lot since it's less common than Chris.) -- Chris. On 07/12/2012 03:32 AM, Johann Spies wrote: On 12 Jul

Re: How to safely maintain a status file

2012-07-12 Thread Laszlo Nagy
Renaming files is the wrong way to synchronize a crawler. Use a database that has ACID properties, such as SQLite. Far fewer I/O operations are required for small updates. It's not the 1980s any more. I agree with this approach. However, the OP specifically asked about "how to update stat

Re: How to safely maintain a status file

2012-07-12 Thread Laszlo Nagy
You are contradicting yourself. Either the OS is providing a fully atomic rename or it doesn't. All POSIX compatible OS provide an atomic rename functionality that renames the file atomically or fails without loosing the target side. On POSIX OS it doesn't matter if the target exists. This is no

Re: lambda in list comprehension acting funny

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 09:44:15 +, Alister wrote: > On Wed, 11 Jul 2012 08:43:11 +0200, Daniel Fetchinson wrote: > >>> funcs = [ lambda x: x**i for i in range( 5 ) ] [...] > Having read Steve's explanation in the other thread (which I think has > finally flipped the light switch on lambda for m

Re: ANN: PollyReports 1.5 -- Band-oriented PDF Report Generator

2012-07-12 Thread Andreas Perstinger
On Thu, 12 Jul 2012 16:59:06 +1000 Chris Angelico wrote: > On Thu, Jul 12, 2012 at 3:35 PM, Andreas Perstinger > wrote: > > Do you mean this license?: > > http://packages.python.org/PollyReports/license.html > > > > It's the standard license for NetBSD projects and approved by OSI: > > http://w

Re: lambda in list comprehension acting funny

2012-07-12 Thread Alister
On Wed, 11 Jul 2012 08:43:11 +0200, Daniel Fetchinson wrote: >> funcs = [ lambda x: x**i for i in range( 5 ) ] >> print funcs[0]( 2 ) >> print funcs[1]( 2 ) >> print funcs[2]( 2 ) >> >> This gives me >> >> 16 16 16 >> >> When I was excepting >> >> 1 >> 2 >> 4 >> >> Does anyone know why? > > And m

Re: lambda in list comprehension acting funny

2012-07-12 Thread Robert Kern
On 7/11/12 9:21 PM, John Ladasky wrote: Exactly. It's threads like these which remind me why I never use lambda. I would rather give a function an explicit name and adhere to the familiar Python syntax, despite the two extra lines of code. I don't even like the name "lambda". It doesn't tel

Re: lambda in list comprehension acting funny

2012-07-12 Thread Mark Lawrence
On 12/07/2012 07:18, Steven D'Aprano wrote: On Wed, 11 Jul 2012 22:04:51 -0700, 8 Dihedral wrote: I have to make sure my functor to keep the state variable values for different objects that call the same functor to behave correctly in order to avoid passing extra parameters in various obj

Re: ANN: PollyReports 1.5 -- Band-oriented PDF Report Generator

2012-07-12 Thread Chris Angelico
On Thu, Jul 12, 2012 at 3:35 PM, Andreas Perstinger wrote: > Do you mean this license?: > http://packages.python.org/PollyReports/license.html > > It's the standard license for NetBSD projects and approved by OSI: > http://www.opensource.org/licenses/bsd-license.php > > and GPL-compatible: > http: