Re: Make a small function thread safe

2011-12-18 Thread Ian Kelly
On Sun, Dec 18, 2011 at 6:27 PM, Tim Delaney wrote: > On 18 December 2011 19:52, RangerElf wrote: >> >> Which is why the original .acquire() ... .release() idiom was wrong, this >> would better express the intent: >> >> try: >>  lock.acquire() >>  shared_container.append(...) >> finally: >>  lock

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Frank Millman
"Steven D'Aprano" wrote in message news:4eeea8eb$0$11091$c3e8...@news.astraweb.com... On Sun, 18 Dec 2011 18:35:47 -0800, alex23 wrote: Pre-namedtuple, I used to like using named slices for this: cPID = slice(19) pid = recs[cPID] You know, that is an incredibly simple thing and ye

Re: PyCon US 2012 sprints

2011-12-18 Thread Brian Curtin
2011/12/17 Ricardo Bánffy : > Hi folks. > > Next March I'm planning to attend PyCon US (for the first time) and > stay for the sprints. I am not sure how they work, however. Are there > any "first-timer guide to PyCon sprints"? I don't know of any such guide, but here's what usually happens: 1. R

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Chris Angelico
On Mon, Dec 19, 2011 at 1:23 PM, alex23 wrote: > Except, OMG, list() is RETURNING A LIST, which is an OBVIOUS type > constraint. I propose that: > >    args = @set list(args) > > Will coerce args into a list and then give me a set in return. Point to note: list,set = set,list # Request a death

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Steven D'Aprano
On Sun, 18 Dec 2011 20:00:59 -0700, Ian Kelly wrote: > On Sun, Dec 18, 2011 at 6:26 PM, Steven D'Aprano > wrote: >> On Sun, 18 Dec 2011 13:47:46 -0600, Evan Driscoll wrote: >> >> [...] >>> so unless you're opposed to using an editor more advanced than >>> Notepad, you'll type in "varargs", it'll

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Steven D'Aprano
On Sun, 18 Dec 2011 18:35:47 -0800, alex23 wrote: > Pre-namedtuple, I used to like using named slices for this: > > cPID = slice(19) > pid = recs[cPID] You know, that is an incredibly simple thing and yet it never dawned on me before now. Thank you for sharing that. -- Steven -- ht

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Ian Kelly
On Sun, Dec 18, 2011 at 6:26 PM, Steven D'Aprano wrote: > On Sun, 18 Dec 2011 13:47:46 -0600, Evan Driscoll wrote: > > [...] >> so unless you're opposed to using an editor more >> advanced than Notepad, you'll type in "varargs", it'll turn purple or >> whatever, and you'll go "oh that's a keyword.

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Cameron Simpson
On 17Dec2011 22:43, Evan Driscoll wrote: | On 12/17/2011 21:42, Chris Angelico wrote: | > Welcome to the list! If you're curious as to what's happened, check | > the archives: | > http://mail.python.org/pipermail/python-list/ | Thanks! Incidentally, is there a good way to respond to the original |

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread alex23
Roy Smith wrote: > A common convention > is that when you're unpacking a tuple (or a list, I suppose) and are > only interested in some of the elements, you unpack the others into "_". > Thus: > > _, _, _, _, pid, _, _, _ = recs[19] Pre-namedtuple, I used to like using named slices for this:

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread alex23
Evan Driscoll wrote: > My problem with it is that it in some sense is forcing me to make a > decision I don't care about. Yes, what we have now is less flexible, but > I have *never* said "man, I wish this *args parameter were a list > instead of a tuple". And if you _did_, then one of the first

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Rick Johnson
On Dec 18, 7:26 pm, Steven D'Aprano wrote: > Not everybody uses editors more advanced than Notepad. And they have no excuse for NOT using a better one. Well, except for a "foolish consistency" that is! > Even those who do > may not have an editor that understands Python keywords, or has an > obso

Re: Debugging a difficult refcount issue.

2011-12-18 Thread buck
Thanks Jack. I think printf is what it will come down to. I plan to put a little code into PyDict_New to print the id and the line at which it was allocated. Hopefully this will show me all the possible suspects and I can figure it out from there. I hope figuring out the file and line-number fr

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Steven D'Aprano
On Sun, 18 Dec 2011 13:47:46 -0600, Evan Driscoll wrote: [...] > so unless you're opposed to using an editor more > advanced than Notepad, you'll type in "varargs", it'll turn purple or > whatever, and you'll go "oh that's a keyword." Not everybody uses editors more advanced than Notepad. Even th

Re: Make a small function thread safe

2011-12-18 Thread Tim Delaney
On 18 December 2011 19:52, RangerElf wrote: > Which is why the original .acquire() ... .release() idiom was wrong, this > would better express the intent: > > try: > lock.acquire() > shared_container.append(...) > finally: > lock.release() > No - this is very bad. The lock must be acquired ou

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Rick Johnson
On Dec 18, 8:35 am, Eelco wrote: > On Dec 18, 6:33 am, Evan Driscoll wrote: > Good point; technically the askeriskes could be kept for backwards > compatibility, but that would break 'there should only be one way to > do it'. I believe it's high time for the upper society of this community to r

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Rick Johnson
On Dec 17, 11:33 pm, Evan Driscoll wrote: > On 12/17/2011 22:52, buck wrote:> Try these on for size. > > >      head, @tuple tail = sequence > >      def foo(@list args, @dict kwargs): pass > >      foo(@args, @kwargs) > > > For backward compatibility, we could say that the unary * is identical to

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Rick Johnson
On Dec 17, 10:52 pm, buck wrote: > [...] > As for the separator, let's examine the available ascii punctuation. > Excluding valid variable characters, whitespace, and operators, we have: > > ! -- ok. No, there are better uses for that char. > " -- can't use this. Would look like a string. > # --

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Chris Angelico
On Mon, Dec 19, 2011 at 9:55 AM, HoneyMonster wrote: > When the user selects a row and clicks a button, I am using: > pos = self.grid_1.GetGridCursorRow() to establish which tuple in recs is > involved, and then pid = recs[pos][4] to determine the key value (I > suspected that accessing recs direc

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread HoneyMonster
On Mon, 19 Dec 2011 07:51:08 +1100, Chris Angelico wrote: > On Mon, Dec 19, 2011 at 6:41 AM, HoneyMonster > wrote: >> My question is doubtless a very easy one to answer: Say I want the >> ninth element in the twentieth tuple put into variable PID, I can do >> this, bearing in mind that numbering

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Roy Smith
In article , Chris Angelico wrote: > If you're absolutely certain that you'll always get precisely one > value from a query, this becomes rather more useful: > > mode = conn.query("SELECT mode FROM config WHERE id=5")[0][0] Although, if you're going to do that, you might as well take advantage

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Chris Angelico
On Mon, Dec 19, 2011 at 6:41 AM, HoneyMonster wrote: > My question is doubtless a very easy one to answer: Say I want the ninth > element in the twentieth tuple put into variable PID, I can do this, > bearing in mind that numbering starts at zero: > > tup = recs[19] > PID = tup[8] > > But there mu

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Roy Smith
In article , HoneyMonster wrote: > I think I rather like Python! +1 QOTD? -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread HoneyMonster
On Sun, 18 Dec 2011 15:04:13 -0500, Roy Smith wrote: > In article , > HoneyMonster wrote: > >> Hi, >> >> I'm just starting to learn Python, so please bear with me. I have in my >> program an object (recs) which is a list of tuples (returned as such by >> a database query). > > Sounds like a s

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Evan Driscoll
On 12/18/2011 8:35, Eelco wrote: > No, its not type *checking*, its type *declaration*. I tried to go to > great lengths to point that out, but it appears I did not do a very > good job :). Type declaration is exactly what I want, and insofar this > syntax has already found adoptation elsewhere, il

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Roy Smith
In article , HoneyMonster wrote: > Hi, > > I'm just starting to learn Python, so please bear with me. I have in my > program an object (recs) which is a list of tuples (returned as such by a > database query). Sounds like a standard database interface -- each tuple represents one row in the

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Evan Driscoll
On 12/18/2011 1:31, Steven D'Aprano wrote: > And rebutted. Modesty[1] prevents me from quoting myself, but here are > some links to searches: > > http://duckduckgo.com/?q=python+asterisk > http://duckduckgo.com/?q=python+* OK, so if you search using the right search engine, you *might* get a link

Re: Newbie Question: Obtain element from list of tuples

2011-12-18 Thread Arnaud Delobelle
On 18 December 2011 19:41, HoneyMonster wrote: > Hi, > > I'm just starting to learn Python, so please bear with me. I have in my > program an object (recs) which is a list of tuples (returned as such by a > database query). > > My question is doubtless a very easy one to answer: Say I want the nin

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Evan Driscoll
On 12/18/2011 2:36, Steven D'Aprano wrote: > The barrier to new keywords in Python is very high. Not going to > happen for something that already has perfectly good syntax already > familiar to Python and Ruby programmers. Might else well try to get C > and Java to stop using "..." (ellipses). I ag

Newbie Question: Obtain element from list of tuples

2011-12-18 Thread HoneyMonster
Hi, I'm just starting to learn Python, so please bear with me. I have in my program an object (recs) which is a list of tuples (returned as such by a database query). My question is doubtless a very easy one to answer: Say I want the ninth element in the twentieth tuple put into variable PID,

Re: Question about Reading from text file with Python's Array class

2011-12-18 Thread Tim Chase
On 12/18/11 12:33, traveller3141 wrote: To test this, I made a small sample file (sillyNums.txt) as follows; 109 345 2 1234556 f=open("sillyNums.txt","r") data = array.array('i') data.fromstring(f.read(data.itemsize* bufferSize)) print data The output was nonsense: array('i', [171520049, 171258

Tumia the first Object-Oriented Internet Directory

2011-12-18 Thread Paka Small
Hi, To my knowledge Tumia (http://www.tumia.org) is the first internet directory structured according to the object-oriented paradigm. Currently Tumia is in its baby years. To illustrate the object- oriented concept consider below "Navigate from Earth Global Warming 2000 AD to Mitigating Solar Ene

Re: Question about Reading from text file with Python's Array class

2011-12-18 Thread Peter Otten
traveller3141 wrote: > I've been trying to use the Array class to read 32-bit integers from a > file. There is one integer per line and the integers are stored as text. > For problem specific reasons, I only am allowed to read 2 lines (2 32-bit > integers) at a time. > > To test this, I made a sm

Question about Reading from text file with Python's Array class

2011-12-18 Thread traveller3141
I've been trying to use the Array class to read 32-bit integers from a file. There is one integer per line and the integers are stored as text. For problem specific reasons, I only am allowed to read 2 lines (2 32-bit integers) at a time. To test this, I made a small sample file (sillyNums.txt) as

Re: Debugging a difficult refcount issue.

2011-12-18 Thread Jack Diederich
I don't have any great advice, that kind of issue is hard to pin down. That said, do try using a python compile with --with-debug enabled, with that you can turn your unit tests on and off to pinpoint where the refcounts are getting messed up. It also causes python to use plain malloc()s so valgr

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Eelco
On 18 dec, 18:03, Steven D'Aprano wrote: > On Sun, 18 Dec 2011 06:13:37 -0800, Eelco wrote: > > Casts or conversions are a runtime concept; im talking about > > declarations. That seems to be the source of your confusion. > > Everything in Python happens at runtime, apart from compilation of sourc

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Steven D'Aprano
On Sun, 18 Dec 2011 06:13:37 -0800, Eelco wrote: > Casts or conversions are a runtime concept; im talking about > declarations. That seems to be the source of your confusion. Everything in Python happens at runtime, apart from compilation of source code into byte code. Python doesn't have declar

Re: Debugging a difficult refcount issue.

2011-12-18 Thread buck
On Saturday, December 17, 2011 11:55:13 PM UTC-8, Paul Rubin wrote: > buck writes: > > I tried to pinpoint this intermediate allocation with a similar > > PyDict_New/LD_PRELOAD interposer, but that isn't working for me[2]. > > Did you try a gdb watchpoint? I didn't try that, since that piece of

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Joshua Landau
I'm just going to throw myself in the conversation obtusely.I felt we needed some real code. These are literally the first two samples I had on hand. !!! OUT OF CONTEXT REAL CODE ALERT !!! ### formatter = formatter.format(**color).replace("(","{").replace(")","}")

Re: calculate difference between two timestamps [newbie]

2011-12-18 Thread nukeymusic
On 18 dec, 13:58, Lie Ryan wrote: > On 12/18/2011 10:43 PM, Peter Otten wrote: > > > > > > > > > > > nukeymusic wrote: > > >> On 17 dec, 12:20, "Günther Dietrich"  wrote: > >>> nukeymusic  wrote: > I'm trying to calculate the difference in seconds between two > > >>> [...] > > >> import d

Re: calculate difference between two timestamps [newbie]

2011-12-18 Thread nukeymusic
On 18 dec, 16:01, Peter Otten <__pete...@web.de> wrote: > nukeymusic wrote: > > thanks and also thanks to all the others who were so kind to help me > > out with my first python-script. > > I tested your alternatives and they work, the only a minor > > inconvenience is that the first line of the in

Re: calculate difference between two timestamps [newbie]

2011-12-18 Thread Peter Otten
nukeymusic wrote: > thanks and also thanks to all the others who were so kind to help me > out with my first python-script. > I tested your alternatives and they work, the only a minor > inconvenience is that the first line of the inputfile gets lost i.e. > the first timestamp should become zero (

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Eelco
On Dec 18, 6:33 am, Evan Driscoll wrote: > On 12/17/2011 22:52, buck wrote:> Try these on for size. > > >      head, @tuple tail = sequence > >      def foo(@list args, @dict kwargs): pass > >      foo(@args, @kwargs) > > > For backward compatibility, we could say that the unary * is identical to

Re: calculate difference between two timestamps [newbie]

2011-12-18 Thread nukeymusic
On 18 dec, 13:58, Lie Ryan wrote: > On 12/18/2011 10:43 PM, Peter Otten wrote: > > > > > > > > > > > nukeymusic wrote: > > >> On 17 dec, 12:20, "Günther Dietrich"  wrote: > >>> nukeymusic  wrote: > I'm trying to calculate the difference in seconds between two > > >>> [...] > > >> import d

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Eelco
On Dec 18, 5:52 am, buck wrote: > I like the spirit of this. Let's look at your examples. Glad to see an actual on-topic reply; thanks. > > Examples of use: > >     head, tail::tuple = ::sequence > >     def foo(args::list, kwargs::dict): pass > >     foo(::args, ::kwargs) > > My initial reactio

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Eelco
On Dec 18, 1:59 am, Steven D'Aprano wrote: > On Sat, 17 Dec 2011 06:38:22 -0800, Eelco wrote: > > Type constraints: > > > In case the asterisk is not used to signal unpacking, but rather to > > signal packing, its semantics is essentially that of a type constraint. > > "Type constraint" normally r

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Chris Angelico
On Mon, Dec 19, 2011 at 12:58 AM, Roy Smith wrote: > In addition to print and type, I'm a big fan of dir().  Often, I know an > object has a method to do what I want, but I can't remember the name. > For example, the other day, I was using a set (which I don't use very > often).  I needed the meth

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Roy Smith
In article , Chris Angelico wrote: > > Never underestimate the power of Python's introspection tools, especially > > the two simplest ones: print and type. Often you will learn more in 10 > > minutes experimentation than in an hour googling. > > +1 QOTW. I refer to this as "IIDPIO debugging" (E

Re: how to run python-script from the python promt? [absolute newbie]

2011-12-18 Thread nukeymusic
On 18 dec, 13:39, Lie Ryan wrote: > On 12/18/2011 10:00 PM, nukeymusic wrote: > > > > > > > > > > > How can I load a python-script after starting python in the > > interactive mode? > > I tried with > load 'myscript.py' > myscript.py > myscript > > > but none of these works, so the

Re: calculate difference between two timestamps [newbie]

2011-12-18 Thread Lie Ryan
On 12/18/2011 10:43 PM, Peter Otten wrote: nukeymusic wrote: On 17 dec, 12:20, "Günther Dietrich" wrote: nukeymusic wrote: I'm trying to calculate the difference in seconds between two [...] import datetime date1 = datetime.datetime.strptime("Dec-13-09:47:12", "%b-%d-%H:%M:%S") date2 =

Re: how to run python-script from the python promt? [absolute newbie]

2011-12-18 Thread Lie Ryan
On 12/18/2011 10:00 PM, nukeymusic wrote: How can I load a python-script after starting python in the interactive mode? I tried with load 'myscript.py' myscript.py myscript but none of these works, so the only way I could work further until now was copy/paste line per line of my python-script

Re: Module msvcrt for Python

2011-12-18 Thread Virgil Stokes
On 18-Dec-2011 11:31, Virgil Stokes wrote: I am running Python 2.6.6 on a Windows Vista platform and for some reason the module msvcrt is not present. How can I install the msvcrt module in my Python 2.6.6? God Jul :-) I found the problem! My code was using Python 2.5 (inside cygwin) by defa

Re: how to run python-script from the python promt? [absolute newbie]

2011-12-18 Thread Kev Dwyer
nukeymusic wrote: > How can I load a python-script after starting python in the > interactive mode? > I tried with load 'myscript.py' myscript.py myscript > > but none of these works, so the only way I could work further until > now was copy/paste line per line of my python-script to

Re: calculate difference between two timestamps [newbie]

2011-12-18 Thread Peter Otten
nukeymusic wrote: > On 17 dec, 12:20, "Günther Dietrich" wrote: >> nukeymusic wrote: >> >I'm trying to calculate the difference in seconds between two >> >> [...] >> >> >>> import datetime >> >>> date1 = datetime.datetime.strptime("Dec-13-09:47:12", >> >>> "%b-%d-%H:%M:%S") date2 = >> >>> dateti

Re: how to run python-script from the python promt? [absolute newbie]

2011-12-18 Thread Chris Angelico
On Sun, Dec 18, 2011 at 10:00 PM, nukeymusic wrote: > How can I load a python-script after starting python in the > interactive mode? > I tried with load 'myscript.py' myscript.py myscript > > but none of these works, so the only way I could work further until > now was copy/paste line

how to run python-script from the python promt? [absolute newbie]

2011-12-18 Thread nukeymusic
How can I load a python-script after starting python in the interactive mode? I tried with >>>load 'myscript.py' >>>myscript.py >>>myscript but none of these works, so the only way I could work further until now was copy/paste line per line of my python-script to the interactive mode prompt I do k

Module msvcrt for Python

2011-12-18 Thread Virgil Stokes
I am running Python 2.6.6 on a Windows Vista platform and for some reason the module msvcrt is not present. How can I install the msvcrt module in my Python 2.6.6? God Jul :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: calculate difference between two timestamps [newbie]

2011-12-18 Thread nukeymusic
On 17 dec, 12:20, "Günther Dietrich" wrote: > nukeymusic wrote: > >I'm trying to calculate the difference in seconds between two > > [...] > > >>> import datetime > >>> date1 = datetime.datetime.strptime("Dec-13-09:47:12", "%b-%d-%H:%M:%S") > >>> date2 = datetime.datetime.strptime("Dec-13-09:47:3

Re: Bug in multiprocessing.reduction?

2011-12-18 Thread Kev Dwyer
Yaşar Arabacı wrote: > You can see my all code below, theoritically that code should work I > guess. But I keep getting this error: > [SUBWARNING/MainProcess] thread for sharing handles raised exception : > --- > Tracebac

Re: Make a small function thread safe

2011-12-18 Thread RangerElf
Which is why the original .acquire() ... .release() idiom was wrong, this would better express the intent: try: lock.acquire() shared_container.append(...) finally: lock.release() But like everyone mentions, the with statement takes care of all that in a more readable and compact fashion.

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Steven D'Aprano
On Sat, 17 Dec 2011 21:03:01 -0600, Evan Driscoll wrote: > Something like ML or Haskell, which does not even allow integer to > double promotions, is very strong typing. Something like Java, which > allows some arithmetic conversion and also automatic stringification (a > la "1" + 1) is somewhere

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Chris Angelico
On Sun, Dec 18, 2011 at 6:31 PM, Steven D'Aprano wrote: > My normal first place to look for something is Wikipedia. Enjoy it before > SOPA kills it. > > http://en.wikipedia.org/wiki/Asterisk#Programming_languages I would never expect to find this sort of thing in the article on the asterisk; mayb

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-18 Thread Steven D'Aprano
On Sat, 17 Dec 2011 23:33:27 -0600, Evan Driscoll wrote: > This would suggest perhaps some keywords might be called for instead of > operators. The barrier to new keywords in Python is very high. Not going to happen for something that already has perfectly good syntax already familiar to Python

Re: Debugging a difficult refcount issue.

2011-12-18 Thread Paul Rubin
buck writes: > I tried to pinpoint this intermediate allocation with a similar > PyDict_New/LD_PRELOAD interposer, but that isn't working for me[2]. Did you try a gdb watchpoint? -- http://mail.python.org/mailman/listinfo/python-list