Re: Safe file I/O to shared file (or SQLite) from multi-threaded web server

2010-01-02 Thread John Nagle
pyt...@bdurham.com wrote: I'm looking for the best practice way for a multi-threaded python web server application to read/write to a shared file or a SQLite database. What do I need to do (if anything) to make sure my writes to a regular file on disk or to a SQLite database are atomic in nature

Re: IOError - cannot create file (linux daemon-invoked script)

2010-01-02 Thread Cameron Simpson
On 02Jan2010 15:21, cassiope wrote: | [...] I want | to save a copy of the email in a particular directory which is | accessible to the Windows clients via samba. | | The strange thing is that even with the right user-id, I cannot seem | to write to the directory, getting an IOError exception.

Re: Any Swisses here?

2010-01-02 Thread J Sisson
On Sat, Jan 2, 2010 at 9:38 PM, n00m wrote: > What you achieved in the life? English mastery, for starters... -- http://mail.python.org/mailman/listinfo/python-list

Re: Any Swisses here?

2010-01-02 Thread n00m
On Jan 3, 5:30 am, Steve Holden wrote: > Zhu Sha Zang wrote: > >> [stuff and nonsense from a third party] > > WTF? > > We do get the occasional bigot dropping in from time to time. Best to > ignore them 'til they go away. > > regards >  Steve > -- > Steve Holden           +1 571 484 6266   +1 800

Re: Any Swisses here?

2010-01-02 Thread Steve Holden
Zhu Sha Zang wrote: >> [stuff and nonsense from a third party] > WTF? We do get the occasional bigot dropping in from time to time. Best to ignore them 'til they go away. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pyc

Re: Any Swisses here?

2010-01-02 Thread Zhu Sha Zang
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Em 03-01-2010 01:17, n00m escreveu: > Congrats! > Your choice -- to ban building of muslim mosques -- is the only choice > to save our civililazation. > This yellow plague (incl. Chinese etc) must be eliminated from our > Planet, > They are very cunnin

Any Swisses here?

2010-01-02 Thread n00m
Congrats! Your choice -- to ban building of muslim mosques -- is the only choice to save our civililazation. This yellow plague (incl. Chinese etc) must be eliminated from our Planet, They are very cunning critters, they can play on strings of compassion, but its riffraffs. What do you know about R

CMNDBOT 0.1 released

2010-01-02 Thread Bart Thate
new in this release: * updated the repository to GZRBOT code * a outputcache and poller gadget is now available to support writing to waves (right now the poller polls every minute) * RSS plugin looks stable todo: * make gozernet work .. this lets GZRBOT bots communicate with each other by using

Re: IOError - cannot create file (linux daemon-invoked script)

2010-01-02 Thread Christian Heimes
cassiope wrote: > The strange thing is that even with the right user-id, I cannot seem > to write to the directory, getting an IOError exception. Changing the > directory to world-writable fixes this. I can confirm the uid and gid > for the script by having the script print these values just befo

Re: Bare Excepts

2010-01-02 Thread Dave Angel
Steven D'Aprano wrote: On Sat, 02 Jan 2010 09:40:44 -0800, Aahz wrote: OTOH, if you want to do something different depending on whether the file exists, you need to use both approaches: if os.path.exists(fname): try: f = open(fname, 'rb') data = f.read() f.close(

Re: Python Concurrency Workshop, Jan 14-15, 2010

2010-01-02 Thread Robert Kern
On 2010-01-02 17:17 , Brian Blais wrote: On Jan 2, 2010, at 13:21 , Mike Howard wrote: Hi Dave, Chicago in January? How about moving it to Denver - it's a nice town and I live close by. Mike David Beazley wrote: Python Concurrency Workshop, v2.0 I think, in the spirit of the topic, they

Re: Dynamic text color

2010-01-02 Thread John Posner
On Sat, Jan 2, 2010 at 1:47 PM, Dave McCormick wrote: WooHoo!!! I got it!!! Yup, I am sure it can be optimized but it works!!! Hmmm ... it doesn't work for me ... RED for word in redList: new_Rword(complete, word) def new_Rword(complete, word): Tbox.tag_remov

Re: Significant whitespace

2010-01-02 Thread Mensanator
On Jan 2, 4:19 pm, Emile van Sebille wrote: > On 1/1/2010 5:05 PM Steven D'Aprano said... > > > In Python terms, imagine if we could write > > >      foriinrange(10): > > > instead of the usual > > >      for i in range(10): > > > Since the colon makes it unambiguous that it is some sort of block

Re: Dynamic text color

2010-01-02 Thread John Posner
On Sat, Jan 2, 2010 at 1:47 PM, Dave McCormick wrote: WooHoo!!! I got it!!! Yup, I am sure it can be optimized but it works!!! Dave, please ignore a couple of my bogus complaints in the previous message: ... you call function new_Rword() before you define it ... this version also has

Re: Bare Excepts

2010-01-02 Thread Steven D'Aprano
On Sun, 03 Jan 2010 01:10:51 +1100, Lie Ryan wrote: > On 1/2/2010 9:42 PM, Steven D'Aprano wrote: >> On Fri, 01 Jan 2010 15:27:57 -0800, myle wrote: >> >>> Why we should prefer ``if: ...'' over a ``try: ... except something: >>> pass'' block? >> >> We shouldn't, not in general. > > One exception

Re: Bare Excepts

2010-01-02 Thread Steven D'Aprano
On Sat, 02 Jan 2010 09:40:44 -0800, Aahz wrote: > OTOH, if you want to do something different depending on whether the > file exists, you need to use both approaches: > > if os.path.exists(fname): > try: > f = open(fname, 'rb') > data = f.read() > f.close() > r

Re: Python Concurrency Workshop, Jan 14-15, 2010

2010-01-02 Thread Brian Blais
On Jan 2, 2010, at 13:21 , Mike Howard wrote: Hi Dave, Chicago in January? How about moving it to Denver - it's a nice town and I live close by. Mike David Beazley wrote: Python Concurrency Workshop, v2.0 I think, in the spirit of the topic, they should hold it at both

Re: Xah's Edu Corner: Teach Ourself Programing In Ten Years?

2010-01-02 Thread Wanna-Be Sys Admin
Alain Picard wrote: > [Aplogies about the wild cross-post follow-up --- I guess the topic > [really > is relevant to most programming communities.] No, it's not relevant. Xah Lee is a self spammer, in that he spams about himself, tries to get people hyped up about him and thinks he's impressing

Re: IOError - cannot create file (linux daemon-invoked script)

2010-01-02 Thread Steve Holden
cassiope wrote: > I have a daemon on a Linux system that supports a number of Windows > clients. Among the functions is to send e-mails, which is > sufficiently complicated that I fork() a separate process which gets > setuid to a lesser user, and calls a python script which does the > actual form

Re: Windows 7 : any problems installing or running Python ?

2010-01-02 Thread Lewis Cawthorne
I'm not Skippy, but I do have my wife's Toshiba Satellite running Windows 7 Home Premium laying around. I figured that since I am fairly well set to duplicate all the information you gave in your problem, I would take a look. The bad news is that Python works great on it, so your problem ne

IOError - cannot create file (linux daemon-invoked script)

2010-01-02 Thread cassiope
I have a daemon on a Linux system that supports a number of Windows clients. Among the functions is to send e-mails, which is sufficiently complicated that I fork() a separate process which gets setuid to a lesser user, and calls a python script which does the actual formatting and emailing (the d

Re: Where is "urllib2" module in windows python3.1.1?

2010-01-02 Thread Hidekazu IWAKI
Hi. Thank you for the answers. Oh, sorry. It was one of the changes from .2.x to 3.x. I didn't know. There are really important and a lot of changes. Thank you! At 01 Jan 2010 13:57:03 + Duncan Booth wrote: > Hidekazu IWAKI wrote: > > > Hi; > > I'd like to import "urllib2" in windows pytho

Re: Xah's Edu Corner: Teach Ourself Programing In Ten Years?

2010-01-02 Thread Emile van Sebille
On 1/2/2010 1:14 AM Xah Lee said... These books are the bedrock of the industry. It is not because people are impatient, or that they wish to hurry, but rather, it is the condition of the IT industry, in the same way modern society drives people to live certain life styles. Turing complete. On

Re: Xah's Edu Corner: Teach Ourself Programing In Ten Years?

2010-01-02 Thread John Bokma
Alain Picard writes: > If you want to change the world, you start by changing yourself. Like for starters setting a follow-up to header, especially if you spam 4 groups. But Xah is Xah. -- John Bokma Read my blog: http://johnbokma.com/ Hire me (Perl/Python): http://castleamber.com/ -- http:/

Re: Significant whitespace

2010-01-02 Thread Emile van Sebille
On 1/1/2010 5:05 PM Steven D'Aprano said... In Python terms, imagine if we could write foriinrange(10): instead of the usual for i in range(10): Since the colon makes it unambiguous that it is some sort of block construct, and it starts with "for", it must be a for loop. Pretty horr

Re: Xah's Edu Corner: Teach Ourself Programing In Ten Years?

2010-01-02 Thread Alain Picard
[Aplogies about the wild cross-post follow-up --- I guess the topic really is relevant to most programming communities.] Xah Lee writes: > To see this in a different context, suppose you need to pass a > important Math XYZ exam or review in your career or get a certificate, > but you don't rem

Re: Exception as the primary error handling mechanism?

2010-01-02 Thread Terry Reedy
On 1/2/2010 10:04 AM, Peng Yu wrote: For my own interest, I want understand the run time behavior of python That depends on the implementation. and what details causes it much slower. A language feature that slows all implementation is the dynamic name/slot binding and resolution. Any imp

Re: whoops: create a splash window in python

2010-01-02 Thread Peter Decker
On Thu, Dec 31, 2009 at 12:31 AM, Ron Croonenberg wrote: > is there a way, in python, to create a splash window and when the program > has completed disappears by sending a msg to it? (I tried creating two gtk > windows but gtk_main doesn't seem to return unless it gets closed.) It's really simp

Re: Dangerous behavior of list(generator)

2010-01-02 Thread Martin v. Loewis
> I'm asking about why the behavior of a StopIteration exception being > handled from the `expression` of a generator expression to mean "stop > the loop" is accepted by "the devs" as acceptable. I may be late to this discussion, but the answer is "most definitely yes". *Any* exception leads to t

Re: Dangerous behavior of list(generator)

2010-01-02 Thread Martin v. Loewis
>> Bottom line, I'm going to have to remove this pattern from my code: >> >> foo = (foo for foo in foos if foo.bar).next() I recommend to rewrite this like so: def first(gen): try: return gen.next() except StopIteration: raise ValueError, "No first value" foo = first(foo for foo in

Thx (Was: assert type([]) == type(()) )

2010-01-02 Thread VanceE
A big Thank You to all for the answer (and the hints). That sure explains a lot. Again, Thank you very much. Cheers, Vance -- http://mail.python.org/mailman/listinfo/python-list

Re: assert type([]) == type(())

2010-01-02 Thread Mel
VanceE wrote: > Just curious. > > type([]) == type(()) > is False as expected > > and > > assert type([]) == type(()) > throws an AssertionError as expected. > > However the following is not an error > > for x in []: > assert type(x) == type(()) > > I expected an AssertionError but get n

Re: Dynamic text color

2010-01-02 Thread Dave McCormick
WooHoo!!! I got it!!! Yup, I am sure it can be optimized but it works!!! John, I have to admit that I spent several hours working on this before I looked at your example, then I spent another several hours getting this far. Would never have gotten it with out you help. Thanks!!! Also reading t

Re: Python Concurrency Workshop, Jan 14-15, 2010

2010-01-02 Thread Mike Howard
Hi Dave, Chicago in January? How about moving it to Denver - it's a nice town and I live close by. Mike David Beazley wrote: Python Concurrency Workshop, v2.0 January 14-15, 2010 Chicago, Illinois http://www.dabe

Re: Bare Excepts

2010-01-02 Thread Aahz
In article <034f1009$0$1277$c3e8...@news.astraweb.com>, Steven D'Aprano wrote: > >The try version is also better whenever there could be a race condition. >For example, when opening a file, you might be tempted to do this: > >if os.path.exists(filename): >f = open(filename, 'r') >text =

Re: assert type([]) == type(())

2010-01-02 Thread Jan Kaliszewski
However the following is not an error for x in []: assert type(x) == type(()) Trying to iterate over an empty sequence or iterator causes 0 (zero) steps of iteration -- so above assert statement is never run. Cheers, *j -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/

Re: assert type([]) == type(())

2010-01-02 Thread Tim Chase
However the following is not an error for x in []: assert type(x) == type(()) I expected an AssertionError but get no errors at all. Any explaination? number_of_times_through_the_loop = 0 for x in []: assert type(x) == type(()) number_of_times_through_the_loop += 1 print nu

Re: assert type([]) == type(())

2010-01-02 Thread Wojciech Muła
VanceE wrote: > for x in []: > assert type(x) == type(()) > > I expected an AssertionError but get no errors at all. > Any explaination? [] is an empty sequence, so your loop executes exactly 0 times. :) for x in [None]: assert ... w. -- http://mail.python.org/mailman/listinfo/py

Re: assert type([]) == type(())

2010-01-02 Thread Josh Holland
On 2010-01-02, VanceE wrote: > for x in []: > assert type(x) == type(()) > > I expected an AssertionError but get no errors at all. > Any explaination? That loop never runs. It immediately raises a StopIteration and the body is never executed. cf. for x in []: print "In loop body" You w

assert type([]) == type(())

2010-01-02 Thread VanceE
Just curious. type([]) == type(()) is False as expected and assert type([]) == type(()) throws an AssertionError as expected. However the following is not an error for x in []: assert type(x) == type(()) I expected an AssertionError but get no errors at all. Any explaination? BTW I'm us

Re: Potential Conflicts by Installing Two Versions of Python (Windows)?

2010-01-02 Thread Nobody
On Fri, 01 Jan 2010 17:37:40 -0800, W. eWatson wrote: > I suspect that if one installs v2.4 and 2.5, or any two versions, that > one will dominate, or there will be a conflict. I suppose it would not > be possible to choose which one should be used. Comments? The only inherent conflict is that

Re: Append Problem

2010-01-02 Thread Victor Subervi
On Sat, Jan 2, 2010 at 10:46 AM, Steve Holden wrote: > > See the .sig. Of course I'm a businessman. > Nice site! In that case, respectfully I disagree! beno -- http://mail.python.org/mailman/listinfo/python-list

Re: Append Problem

2010-01-02 Thread Steve Holden
Victor Subervi wrote: [...] > While the learning you have performed in getting this system to work > (for some rather questionable value of "work", I can't help feeling, but > we'll overlook the horrors induced by your lack of programming > experience) is a testament to your persist

Re: Append Problem

2010-01-02 Thread Victor Subervi
There isn't a tuple is sight there - you are dealing with lists, and you > are modifying the very list you are iterating over. > > Try rewriting the code to create a new list from the old one (i.e. > iterate over catChains and have your code append to an initially empty > list called, for example,

Re: Exception as the primary error handling mechanism?

2010-01-02 Thread Martin v. Loewis
> For my own interest, I want understand the run time behavior of python > and what details causes it much slower. Although people choose python > for its programming efficiency, but sometimes the runtime still > matters. This is an important aspect of the language. I'm wondering > this is not even

Re: Exception as the primary error handling mechanism?

2010-01-02 Thread Peng Yu
On Sat, Jan 2, 2010 at 6:05 AM, Diez B. Roggisch wrote: > Peng Yu schrieb: >> >> On Thu, Dec 31, 2009 at 11:24 PM, Chris Rebert wrote: >>> >>> On Thu, Dec 31, 2009 at 8:47 PM, Peng Yu wrote: I observe that python library primarily use exception for error handling rather than use e

Re: Windows 7 : any problems installing or running Python ?

2010-01-02 Thread David M Covey Sr.
Hello Skippy, In response to your message "Windows 7 : any problems installing or running Python ?" I found posted at (http://mail.python.org/pipermail/python-list/2009-August/1215524.html), I've got to say that I can't seem to get any version of Python to work on my computer. I have a Toshiba

Re: Bare Excepts

2010-01-02 Thread Lie Ryan
On 1/2/2010 9:42 PM, Steven D'Aprano wrote: On Fri, 01 Jan 2010 15:27:57 -0800, myle wrote: Why we should prefer ``if: ...'' over a ``try: ... except something: pass'' block? We shouldn't, not in general. One exception (pun intended) is if the try-block have a side effect that is difficul

Re: Endless loop

2010-01-02 Thread vsoler
On 2 ene, 14:21, Ulrich Eckhardt wrote: > vsoler wrote: > > class stepper: > >     def __getitem__(self, i): > >         return self.data[i] > > > X=stepper() > > X.data="Spam" > > for item in X: > >     print item, > > > ... what I get is     S p a m     which seems logical to me since the > > lo

Re: Append Problem

2010-01-02 Thread Steve Holden
Victor Subervi wrote: > Hi; > I have the following code snippet: > > print 'Original: ', catChains, '' > while i < MAXLEVEL: > flag = 0 > j = 0 > while j < len(parents): > for chain in catChains: > if parents[j] == chain[len(chain)-1]: > chain.append(childre

Re: Endless loop

2010-01-02 Thread Ulrich Eckhardt
vsoler wrote: > class stepper: > def __getitem__(self, i): > return self.data[i] > > X=stepper() > X.data="Spam" > for item in X: > print item, > > ... what I get is S p a m which seems logical to me since the > loop stops after the 4th character. I think you're mistaking

Re: Endless loop

2010-01-02 Thread alexru
On Jan 2, 3:50 pm, vsoler wrote: > My question is: why does this second script not stop after printing > number 3?  what made the first one stop while the second one will not? First one will raise IndexError when string is over, second one won't. -- http://mail.python.org/mailman/listinfo/pytho

Re: Trying to run a sudo command from script

2010-01-02 Thread Steve Holden
Paul Kölle wrote: > Am 01.01.2010 23:55, schrieb Kent Tenney: >> Howdy, > Hi Kent, > >> A script running as a regular user sometimes wants >> to run sudo commands. >> >> It gets the password with getpass. >> pw = getpass.getpass() >> >> I've fiddled a bunch with stuff like >> proc = subprocess.Pop

Re: Exception as the primary error handling mechanism?

2010-01-02 Thread Martin v. Loewis
> I mentioned an "exception stack" above, though I'm not 100% sure if that is > the proper term. I think that exceptions can be stacked upon each other > (e.g. an HTTPD throwing a high-level RequestError when it encounters a low- > level IOError) and that that is also how the backtrace is implem

Endless loop

2010-01-02 Thread vsoler
hello, I'm learning Python and OOP, and I am confronted with a rather theoretical problem. If I run the following script: class stepper: def __getitem__(self, i): return self.data[i] X=stepper() X.data="Spam" for item in X: print item, ... what I get is S p a m which se

Re: Exception as the primary error handling mechanism?

2010-01-02 Thread Diez B. Roggisch
Peng Yu schrieb: On Thu, Dec 31, 2009 at 11:24 PM, Chris Rebert wrote: On Thu, Dec 31, 2009 at 8:47 PM, Peng Yu wrote: I observe that python library primarily use exception for error handling rather than use error code. In the article API Design Matters by Michi Henning Communications of th

Re: Significant whitespace

2010-01-02 Thread Steven D'Aprano
On Sat, 02 Jan 2010 10:42:39 +, Duncan Booth wrote: > Donn wrote: > >> On Saturday 02 January 2010 00:02:36 Dan Stromberg wrote: >>> I put together a page about significant whitespace (and the lack >>> thereof). >> The only thing about Python's style that worries me is that it can't be >> co

Re: Exception as the primary error handling mechanism?

2010-01-02 Thread Ulrich Eckhardt
Peng Yu wrote: > Could somebody let me know how the python calls and exceptions are > dispatched? Is there a reference for it? I'm not a Python expert, but I have read some parts of the implementation. Hopefully someone steps up if I misrepresent things here... In order to understand Python exce

Append Problem

2010-01-02 Thread Victor Subervi
Hi; I have the following code snippet: print 'Original: ', catChains, '' while i < MAXLEVEL: flag = 0 j = 0 while j < len(parents): for chain in catChains: if parents[j] == chain[len(chain)-1]: chain.append(children[j]) print '1: ', catChains, ''

Re: Significant whitespace

2010-01-02 Thread Duncan Booth
Donn wrote: > On Saturday 02 January 2010 00:02:36 Dan Stromberg wrote: >> I put together a page about significant whitespace (and the lack >> thereof). > The only thing about Python's style that worries me is that it can't > be compressed like javascript can*, and perhaps that will prevent it >

Re: Bare Excepts

2010-01-02 Thread Steven D'Aprano
On Fri, 01 Jan 2010 15:27:57 -0800, myle wrote: > Why we should prefer ``if: ...'' over a ``try: ... except something: > pass'' block? We shouldn't, not in general. Often, the if test is just as expensive as actually doing it. E.g.: if x in mylist: position = mylist.index(x) else: do_s

Re: Trying to run a sudo command from script

2010-01-02 Thread Paul Kölle
Am 01.01.2010 23:55, schrieb Kent Tenney: Howdy, Hi Kent, A script running as a regular user sometimes wants to run sudo commands. It gets the password with getpass. pw = getpass.getpass() I've fiddled a bunch with stuff like proc = subprocess.Popen('sudo touch /etc/foo'.split(), stdin=subpr

Xah's Edu Corner: Teach Ourself Programing In Ten Years?

2010-01-02 Thread Xah Lee
On Dec 25 2009, 12:44 am, r...@rpw3.org (Rob Warnock) wrote: > jos...@corporate-world.lisp.de wrote: > > +--- > | p...@informatimago.com (Pascal J. Bourguignon) wrote: > | > LOL Yeah right! Give gavino ten years of rest to let > | > his unconscious mind work on it! > | > | Norvig's 'Te

Re: Exception as the primary error handling mechanism?

2010-01-02 Thread Stephen Hansen
On Fri, Jan 1, 2010 at 5:36 PM, Peng Yu wrote: > >> Otherwise, could some python expert explain to me why exception is > >> widely used for error handling in python? Is it because the efficiency > >> is not the primary goal of python? > > > > Correct; programmer efficiency is a more important goa