Re: Final state of underlying sequence in islice

2010-11-05 Thread Shashank Singh
I have created an issue in roundup at http://bugs.python.org/issue10323. I was expecting the discussion to move to that place but since it has not, for the sake of completion I am quoting my response to Raymond that I had posted on roundup. > @Raymond: I don't have a particular use case where I ha

Re: Final state of underlying sequence in islice

2010-11-05 Thread Terry Reedy
On 11/5/2010 4:51 PM, Raymond Hettinger wrote: On Nov 5, 1:05 pm, Terry Reedy wrote: Currently, there are no promises or guarantees about the final state of the iterator. I interpret the current doc statement as a promise that becomes ambiguous when step> 1. You may have missed my point.

Re: Compare source code

2010-11-05 Thread Rustom Mody
As for tools' brokeness regarding spaces/tabs/indentation heres a thread on the emacs list wherein emacs dev Stefan Monnier admits to the fact that emacs' handling in this regard is not perfect. http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/1bd0c33a3e755730/89cbd920ee651b5a?q=

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Steven D'Aprano
On Sat, 06 Nov 2010 04:33:25 +, Steven D'Aprano wrote: > As far as the OP's question, I'm kind of surprised that he wasn't told > that Google is his friend. The very first hit for "python caret" answers > his question. If he had spent even five seconds googling, he would have > got his answer.

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Steven D'Aprano
On Fri, 05 Nov 2010 23:21:11 -0400, Philip Semanchuk wrote: > Take the OP's question. How is one supposed to find out about bitwise > operators in Python? AFAICT they're not mentioned in the tutorial, and > neither are decorators, assert(), global, exec, the ternary if > statement, etc. The tutor

Re: Compare source code

2010-11-05 Thread Seebs
On 2010-11-06, Steven D'Aprano wrote: > On Fri, 05 Nov 2010 08:17:02 +0530, Rustom Mody wrote: >> However the original question -- mixing tabs and spaces is bad -- has >> got lost in the flames. Do the most die-hard python fanboys deny this? >> And if not is it asking too much (say in python3) t

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Seebs
On 2010-11-06, Philip Semanchuk wrote: > The former refers to something that programmers would use to learn >the language once they've gone through the tutorial a few times. >The latter is great for writing a Python parser but isn't the >friendliest guide to language constructs. That sounds, then

Re: Exception Handling in Python 3

2010-11-05 Thread John Ladasky
On Oct 29, 8:53 am, rantingrick wrote: > I am the programmer, and when i say to my interpretor "show this > exception instead of that exception" i expect my interpretor to do > exactly as i say or risk total annihilation!! I don't want my > interpreter "interpreting" my intentions and then doing

Re: How find all childrens values of a nested dictionary, fast!

2010-11-05 Thread John Ladasky
On Nov 4, 10:21 am, de...@web.de (Diez B. Roggisch) wrote: > macm writes: >     for value in d.values(): >         if isinstance(value, dict): I'm not a Python guru, but... do you care that you're breaking duck typing here? I've had other programmers warn me against using isinstance() for this

Re: Compare source code

2010-11-05 Thread Seebs
On 2010-11-06, Steven D'Aprano wrote: > On Thu, 04 Nov 2010 19:37:25 +, Tim Harig wrote: >> Examples of communication channels that mangle white space abound. > Yes. So what? So something which is broken by them is brittle. And in every circumstance *other* than the syntax of Python, specif

Re: functions, list, default parameters

2010-11-05 Thread Steven D'Aprano
On Fri, 05 Nov 2010 12:17:00 +, Mark Wooding wrote: >> #1 Most default values are things like True, False, None, integer or >> string literals. Since they're literals, they will never change, so you >> only need to set them once. > > Right; so a half-decent compiler can notice this and optimi

Re: *** glibc detected *** gdb: malloc(): smallbin double linked list

2010-11-05 Thread Lawrence D'Oliveiro
In message , Nobody wrote: > I imagine that your extension code is trashing the heap, in which case, > valgrind is probably the answer. Something simpler to try first is to run the code with the MALLOC_CHECK_ environment variable set to 2 or 3. That might give a few more clues. -- http://mail.p

Re: Compare source code

2010-11-05 Thread Seebs
On 2010-11-06, Steven D'Aprano wrote: > On Fri, 05 Nov 2010 18:45:39 +, Seebs wrote: >> On 2010-11-05, Steven D'Aprano >> wrote: >>> Well there's your problem -- you are relying on tools that operate by >>> magic. >> Wrong. > Really? Then how did the logic get screwed up from a mere copy-an

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Philip Semanchuk
On Nov 5, 2010, at 6:51 PM, Seebs wrote: > On 2010-11-05, Nobody wrote: >> However, it's still written for language lawyers. > >> IMHO, the lack of a reference manual for the language itself is a major >> hole in Python's documentation. > > I'm a bit lost here. Could you highlight some of the

Re: Compare source code

2010-11-05 Thread Steven D'Aprano
On Fri, 05 Nov 2010 08:17:02 +0530, Rustom Mody wrote: > However the original question -- mixing tabs and spaces is bad -- has > got lost in the flames. Do the most die-hard python fanboys deny this? > And if not is it asking too much (say in python3) that mixing tabs and > spaces be flagged as

Re: Using Python for a demonstration in historical linguistics

2010-11-05 Thread MRAB
On 06/11/2010 02:17, Dax Bloom wrote: Hello, In the framework of a project on evolutionary linguistics I wish to have a program to process words and simulate the effect of sound shift, for instance following the Rask's-Grimm's rule. I look to have python take a dictionary file or a string input

Re: Using Python for a demonstration in historical linguistics

2010-11-05 Thread Chris Rebert
On Fri, Nov 5, 2010 at 7:17 PM, Dax Bloom wrote: > Hello, > > In the framework of a project on evolutionary linguistics I wish to > have a program to process words and simulate the effect of sound > shift, for instance following the Rask's-Grimm's rule. I look to have > python take a dictionary fi

Using Python for a demonstration in historical linguistics

2010-11-05 Thread Dax Bloom
Hello, In the framework of a project on evolutionary linguistics I wish to have a program to process words and simulate the effect of sound shift, for instance following the Rask's-Grimm's rule. I look to have python take a dictionary file or a string input and replace the consonants in it with th

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Steven D'Aprano
On Fri, 05 Nov 2010 22:51:10 +, Seebs wrote: > On 2010-11-05, Nobody wrote: >> However, it's still written for language lawyers. > >> IMHO, the lack of a reference manual for the language itself is a major >> hole in Python's documentation. > > I'm a bit lost here. Could you highlight some

Re: Regular expression

2010-11-05 Thread MRAB
On 06/11/2010 01:25, Paul Hemans wrote: I need to extract the quoted text from : _("get this") The following works: re.compile( "_\(['\"]([^'\"]+)['\"]\)" ) However, I don't want to match if there is A-Z or a-z or 0-9 or _ immediately preceding the "_" so I have tried: "[^0-9a-zA-Z]*_\(['\"]([^'

Re: Compare source code

2010-11-05 Thread Steven D'Aprano
On Fri, 05 Nov 2010 18:45:39 +, Seebs wrote: > On 2010-11-05, Steven D'Aprano > wrote: >> On Thu, 04 Nov 2010 20:17:35 +, Seebs wrote: >>> That was the thing which bit me the worst. I had a fairly large block >>> of code in a first-pass ugly program. I wanted to start refactoring >>> it

Re: Compare source code

2010-11-05 Thread Steven D'Aprano
On Thu, 04 Nov 2010 17:45:58 +, Tim Harig wrote: >>> Python is the only language that I know that *needs* to specify tabs >>> versus spaces since it is the only language I know of which uses >>> whitespace formating as part of its syntax and structure. [...] > I am also aware of other langauge

Re: Compare source code

2010-11-05 Thread Steven D'Aprano
On Thu, 04 Nov 2010 19:37:25 +, Tim Harig wrote: > Examples of communication channels that mangle white space abound. Yes. So what? If your communication channel mangles your data, change your communication channel, don't expect users of clean communication channels to hand-enter error-corr

Re: Lupa 0.17 released - Lua in Python

2010-11-05 Thread Carl Banks
On Nov 5, 4:21 pm, Stefan Behnel wrote: > Hi all, > > I am happy to announce the release of Lupa 0.17, Lua in Python. > > http://pypi.python.org/pypi/lupa/0.17 > > Have fun, > > Stefan Thanks, interesting projection. Good idea. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: Why "flat is better than nested"?

2010-11-05 Thread Steven D'Aprano
On Fri, 05 Nov 2010 14:19:47 +0100, J. Gerlach wrote: > Am 28.10.2010 03:40, schrieb Steven D'Aprano: >> [ snip a lot of wise words ] > > Can I put this (translated) in the german python wiki? I guess it might > help more people to understand some decisions taken during python's > development - a

Regular expression

2010-11-05 Thread Paul Hemans
I need to extract the quoted text from : _("get this") The following works: re.compile( "_\(['\"]([^'\"]+)['\"]\)" ) However, I don't want to match if there is A-Z or a-z or 0-9 or _ immediately preceding the "_" so I have tried: "[^0-9a-zA-Z]*_\(['\"]([^'\"]+)['\"]\)" "[^\w]{0,1}_\(['\"]([^'\"]+

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Tim Chase
On 11/05/10 15:10, Grant Edwards wrote: On 2010-11-05, Tim Chase wrote: On 11/05/10 13:23, Matty Sarro wrote: I need it to output as 0x0a, and the exercise is requiring me to use %x to format the string. Any help would be appreciated. Though it feels hokey to me, using "%#04x" % 10 wor

Re: Final state of underlying sequence in islice

2010-11-05 Thread Raymond Hettinger
On Nov 5, 3:52 pm, Ian wrote: > On Nov 5, 2:51 pm, Raymond Hettinger wrote: > > > You may have missed my point.  I wrote the tools, the docs, and the > > tests. > > If you interpret a "promise" in text, I can assure you it was not > > intended.  The behavior *is* undefined because I never defined

Re: Compare source code

2010-11-05 Thread D'Arcy J.M. Cain
On 05 Nov 2010 20:14:47 GMT Seebs wrote: > I can just see how well this attitude must work in other circumstances: I guess this message ends the topic for me. Bye. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 4

[ANN] Lupa 0.17 released - Lua in Python

2010-11-05 Thread Stefan Behnel
Hi all, I am happy to announce the release of Lupa 0.17, Lua in Python. http://pypi.python.org/pypi/lupa/0.17 Have fun, Stefan What is Lupa? -- Lupa integrates the LuaJIT2 runtime [1] into CPython. It is a rewrite of LunaticPython in Cython with several advanced features. Thi

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Seebs
On 2010-11-05, Nobody wrote: > However, it's still written for language lawyers. > IMHO, the lack of a reference manual for the language itself is a major > hole in Python's documentation. I'm a bit lost here. Could you highlight some of the differences between "a reference manual for the langu

Re: Final state of underlying sequence in islice

2010-11-05 Thread Ian
On Nov 5, 2:51 pm, Raymond Hettinger wrote: > You may have missed my point.  I wrote the tools, the docs, and the > tests. > If you interpret a "promise" in text, I can assure you it was not > intended.  The behavior *is* undefined because I never defined it. > I'm happy to clarify the docs to mak

Re: ANN: PyQt v4.8.1 Released

2010-11-05 Thread Lawrence D'Oliveiro
In message , Дамјан Георгиевски wrote: >>> PyQt is available under the GPL and a commercial license. >> >> Surely you mean “proprietary” rather than “commercial”. There is >> nothing about the GPL that prevents “commercial” use. > > I think he means a license that *he* sells comercially :) Pre

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Philip Semanchuk
On Nov 5, 2010, at 5:21 PM, Nobody wrote: > On Fri, 05 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: > >> As others have said, ^ is for XOR. That's buried here in the >> documentation: >> http://docs.python.org/release/2.7/reference/... >> >> Not that I would have expected you to find it the

Re: *** glibc detected *** gdb: malloc(): smallbin double linked list

2010-11-05 Thread Nobody
On Fri, 05 Nov 2010 19:39:12 +, John Reid wrote: > I've compiled > Python 2.7 (r27:82500, Nov 2 2010, 09:00:37) [GCC 4.4.3] on linux2 > > with the following configure options > ./configure --prefix=/home/john/local/python-dbg --with-pydebug > > I've installed numpy and some other packages b

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Nobody
On Fri, 05 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: > As others have said, ^ is for XOR. That's buried here in the > documentation: > http://docs.python.org/release/2.7/reference/... > > Not that I would have expected you to find it there since that's pretty > dense. In fact, older versio

Re: decimal.py ver 2.6,2.7 not working with python 2.7

2010-11-05 Thread Terry Reedy
On 11/5/2010 3:14 PM, robert roze wrote: Aha! yes, you figured it out. My PYTHONPATH env variable had an old experiment in it, which happened to be called numbers.py. Take it out, and decimal.py works fine. Python has a large test suite in Lib/test, which includes test_decimal.py. It is run d

Re: Final state of underlying sequence in islice

2010-11-05 Thread Raymond Hettinger
On Nov 5, 1:05 pm, Terry Reedy wrote: > > Currently, there are no promises or guarantees about the final state > > of the iterator. > > I interpret the current doc statement as a promise that becomes > ambiguous when step > 1. You may have missed my point. I wrote the tools, the docs, and the te

Re: Compare source code

2010-11-05 Thread Terry Reedy
On 11/5/2010 3:33 PM, D'Arcy J.M. Cain wrote: my language. Use Perl or C or even pybraces. http://timhatch.com/projects/pybraces/ "I work with a guy who hates Python's significant whitespace and wishes that he could just use curly braces." I am offering no solutions. Except you just did

Re: Compare source code

2010-11-05 Thread Seebs
On 2010-11-05, Grant Edwards wrote: > On 2010-11-05, Seebs wrote: >> On 2010-11-05, Emile van Sebille wrote: >>> So, which of your tools are you married to that are causing your issues? >> Python. > I think you should quit using Python and choose a language that works > with whatever tools are

Re: Compare source code

2010-11-05 Thread Seebs
On 2010-11-05, D'Arcy J.M. Cain wrote: > The simple fact is that the combination of your tools and Python is > broken. The combination of my tools and Python is not. That's lucky > for me since I really, really like IAS. That's unlucky for people who > have to work with tools that mangle code.

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Terry Reedy
On 11/5/2010 9:43 AM, Matty Sarro wrote: Hey Everyone, Just curious - I'm working on a program which includes a calculation of a circle, and I found myself trying to use pi*radius^2, and getting errors that data types float and int are unsupported for "^". Now, I realized I was making the mistake

Re: Compare source code

2010-11-05 Thread Seebs
On 2010-11-05, Ethan Furman wrote: > The verifiable benefit for me is ease of use, ease of thought, ease of > typing... I realize these are not benefits for everyone, but they are > for some -- and I would venture a guess that the ease of thought benefit > is one of the primary reasons Python i

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Grant Edwards
On 2010-11-05, Tim Chase wrote: > On 11/05/10 13:23, Matty Sarro wrote: >>> I'm currently trying to convert a digit from decimal to hex, >>> however I need the full 4 digit hex form. Python appears to >>> be shortening the form. >>> Example: >>> >>> num = 10 >>> num = "%x"%(num) >>> print(num) >>>

Re: Final state of underlying sequence in islice

2010-11-05 Thread Terry Reedy
On 11/5/2010 4:58 AM, Raymond Hettinger wrote: Shashank Singh wrote: Are there any promises made with regard to final state of the underlying sequence that islice slices? Currently, there are no promises or guarantees about the final state of the iterator. I interpret the current doc sta

Re: How convert list to nested dictionary?

2010-11-05 Thread Arnaud Delobelle
Peter Otten <__pete...@web.de> writes: > Boris Borcic wrote: > >> Arnaud Delobelle wrote: >>> macm writes: >>> Hi Folks How convert list to nested dictionary? >>> l ['k1', 'k2', 'k3', 'k4', 'k5'] >>> result {'k1': {'k2': {'k3': {'k4': {'k5': {}}

Re: Compare source code

2010-11-05 Thread Ian
On Nov 5, 12:35 pm, John Nagle wrote: >     INTERLISP's editor allowed the user to select a block of > LISP code and make it into a function.  The selected block > would be analyzed to determine which local variables it referenced, > and a new function would be created with those parameters.  The

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Tim Chase
On 11/05/10 13:23, Matty Sarro wrote: I'm currently trying to convert a digit from decimal to hex, however I need the full 4 digit hex form. Python appears to be shortening the form. Example: num = 10 num = "%x"%(num) print(num) a num = 10 num = "%#x"%(num) print(num) 0xa I need it to ou

Re: How convert list to nested dictionary?

2010-11-05 Thread macm
Ok. Done >>> def appendNested(nest, path, val): ... nest2 = nest ... for key in path[:-1]: ... nest2 = nest2[key] ... nest2[path[-1]].append(val) ... return nest ... >>> >>> l = ['k1','k2','k3','k4','k5'] >>> ndict = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) >>

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Matty Sarro
It's ok, people who refer to a labret piercing as a "la-BRAY" piercing are also incorrect. It's pronounced lab-RET, as its base word is the latin "labretta." French as a language shall doom us all :) On Fri, Nov 5, 2010 at 2:54 PM, Philip Semanchuk wrote: > > On Nov 5, 2010, at 12:43 PM, Peter Pe

*** glibc detected *** gdb: malloc(): smallbin double linked list

2010-11-05 Thread John Reid
Hi, I've compiled Python 2.7 (r27:82500, Nov 2 2010, 09:00:37) [GCC 4.4.3] on linux2 with the following configure options ./configure --prefix=/home/john/local/python-dbg --with-pydebug I've installed numpy and some other packages but when I try to run my extension code under gdb I get the er

Re: Compare source code

2010-11-05 Thread D'Arcy J.M. Cain
On Fri, 5 Nov 2010 18:13:44 + (UTC) Tim Harig wrote: > > care about. If no one was on a crusade to convince people that > > indentation as syntax (can we call is IAS from now on?) was evil then I > > wouldn't be posting anything at all on the subject. I am being totally > > reactionary here.

Re: Compare source code

2010-11-05 Thread Ethan Furman
Tim Harig wrote: The use of whitespace was a stylistic change and stylistic holy wars exist because it is almost impossible to prove that any reasonable style has benefit over another. That whitespace causes issues is verifiable. I find it hard to concluded that that whitespace based syntax is

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Matty Sarro
I actually was able to get it working a few minutes after posting the question. My apologies for not posting a followup :) I ended up using the following format: num = 10 num = "%#0.2x"%(num) print(num) It works, however I'm not sure if it'd be considered very "pythonic" or not. Thanks for your t

RE: decimal.py ver 2.6,2.7 not working with python 2.7

2010-11-05 Thread robert roze
Hi Chris, Aha! yes, you figured it out. My PYTHONPATH env variable had an old experiment in it, which happened to be called numbers.py. Take it out, and decimal.py works fine. Thank you, Bob >What does the following output for you?: > >import numbers >print(numbers.__file__) >print(dir(numbe

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Grant Edwards
On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro wrote: > I'm currently trying to convert a digit from decimal to hex, however I need > the full 4 digit hex form. Python appears to be shortening the form. > Example: > > num = 10 > num = "%x"%(num) > print(num) > >>a > > num = 10 > num = "%#x"%(num) >

Re: Compare source code

2010-11-05 Thread Grant Edwards
On 2010-11-05, Seebs wrote: > On 2010-11-05, Emile van Sebille wrote: >> So, which of your tools are you married to that are causing your issues? > > Python. I think you should quit using Python and choose a language that works with whatever tools are causing all your white-space corruption prob

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Chris Rebert
On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro wrote: > I'm currently trying to convert a digit from decimal to hex, however I need > the full 4 digit hex form. Python appears to be shortening the form. > Example: > > num = 10 > num = "%x"%(num) > print(num) > >>a > > num = 10 > num = "%#x"%(num) >

Re: How convert list to nested dictionary?

2010-11-05 Thread macm
Hi Peter Thanks a lot for your tips and codes, Cake Recipes are good to learn! So I post just basic issues. Hopping a good soul like you can help me! But I am still learning... : ) Best Regards macm On 5 nov, 15:40, Peter Otten <__pete...@web.de> wrote: > macm wrote: > > thanks a lot all. Al

Re: Compare source code

2010-11-05 Thread Seebs
On 2010-11-05, Emile van Sebille wrote: > So, which of your tools are you married to that are causing your issues? Python. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nos...@seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Philip Semanchuk
On Nov 5, 2010, at 12:43 PM, Peter Pearson wrote: > On Fri, 5 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: >> >> BTW the more common name for this character is caret (ka-RAY). > > Yes, it's caret, but no, it's KA-rit, almost the same as > carrot. It's straight from Latin, with no detour th

Re: Compare source code

2010-11-05 Thread Seebs
On 2010-11-05, Steven D'Aprano wrote: > On Thu, 04 Nov 2010 20:17:35 +, Seebs wrote: >> That was the thing which bit me the worst. I had a fairly large block >> of code in a first-pass ugly program. I wanted to start refactoring it, >> so I moved a big hunk of code into a method (with plans

Re: Compare source code

2010-11-05 Thread Seebs
On 2010-11-05, Steven D'Aprano wrote: > How does an edit accidentally add a trailing space to a large number of > lines? I would love to know the answer to this question. However, empirically, it happens. My guess would be cutting and pasting in some way. > So we keep coming back to work-arou

Re: Compare source code

2010-11-05 Thread John Nagle
On 11/5/2010 3:41 AM, Steven D'Aprano wrote: On Thu, 04 Nov 2010 20:17:35 +, Seebs wrote: * I /do/ have a significant problem with cutting and pasting code in Python. In most languages, I can haul a chunk of code about, hit C-M-q, and Emacs magically indents the result properl

Re: Compare source code

2010-11-05 Thread Emile van Sebille
On 11/5/2010 11:13 AM Tim Harig said... It is simply hard for me to accept that your solution is better when it is telling us that we have to abandon thousands of tools that other solutions manage to work with without difficulty. I only work with a few tools none of which alter or strip leading

Re: decimal.py ver 2.6,2.7 not working with python 2.7

2010-11-05 Thread Chris Rebert
On Fri, Nov 5, 2010 at 10:50 AM, robert roze wrote: > I have a 'Python 2.7' installed. > > It seems like the decimal.py module that comes with the Python2.7 package is > not working. I hope I'm wrong, but here's why I think so: > > If I simply try to import the module, I get this error: > imp

Re: Compare source code

2010-11-05 Thread Tim Harig
On 2010-11-05, Grant Edwards wrote: > On 2010-11-05, Tim Harig wrote: >> On 2010-11-05, Steven D'Aprano wrote: >>> On Thu, 04 Nov 2010 21:47:59 +, Tim Harig wrote: >>> I have seen huge patches caused by nothing more then some edit that accidently added a trailing space to a large n

Using %x to format number to hex and number of digits

2010-11-05 Thread Matty Sarro
I'm currently trying to convert a digit from decimal to hex, however I need the full 4 digit hex form. Python appears to be shortening the form. Example: num = 10 num = "%x"%(num) print(num) >a num = 10 num = "%#x"%(num) print(num) >0xa I need it to output as 0x0a, and the exercise is requirin

Re: Compare source code

2010-11-05 Thread Tim Harig
On 2010-11-05, Alain Ketterlin wrote: > Terry Reedy writes: > >> If you add the normally redundant information in the form of explicit >> dedents (anything starting with '#' and distinguishable from normal >> comments), then it is not too hard to re-indent even after all indents >> have been remo

ANN: Leo 4.8 beta 1 released

2010-11-05 Thread Edward K. Ream
Leo 4.8 beta 1 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.8: -- - Leo n

decimal.py ver 2.6,2.7 not working with python 2.7

2010-11-05 Thread robert roze
I have a 'Python 2.7' installed. It seems like the decimal.py module that comes with the Python2.7 package is not working. I hope I'm wrong, but here's why I think so: If I simply try to import the module, I get this error: >>> import decimal Traceback (most recent call last): File "", line

Re: Compare source code

2010-11-05 Thread Tim Harig
On 2010-11-04, D'Arcy J.M. Cain wrote: > On Thu, 4 Nov 2010 19:37:25 + (UTC) > Tim Harig wrote: >> On 2010-11-04, D'Arcy J.M. Cain wrote: >> You are the one who seems to be on a crusade against against braces. It > > You totally misunderstand me. I am not on a crusade of any sort. I am I

Re: Exception handling with NameError

2010-11-05 Thread Zeynel
On Nov 5, 1:26 pm, Peter Otten <__pete...@web.de> wrote: > Of course I'm only guessing because you don't provide enough context. > > Peter Thanks. This is the problem I am having, in general: K = [] # a container list K = ["A", "B"] ARCHIVE = [] # a list where items from K is archived ARCHIV

Re: Compare source code

2010-11-05 Thread Grant Edwards
On 2010-11-05, Tim Harig wrote: > On 2010-11-05, Steven D'Aprano wrote: >> On Thu, 04 Nov 2010 21:47:59 +, Tim Harig wrote: >> >>> I have seen huge patches caused by nothing more then some edit that >>> accidently added a trailing space to a large number of lines. White >>> space mangling ha

Re: Compare source code

2010-11-05 Thread Tim Harig
On 2010-11-05, Steven D'Aprano wrote: > On Thu, 04 Nov 2010 21:47:59 +, Tim Harig wrote: > >> I have seen huge patches caused by nothing more then some edit that >> accidently added a trailing space to a large number of lines. White >> space mangling happens all the time without people even k

Re: How convert list to nested dictionary?

2010-11-05 Thread Peter Otten
macm wrote: > thanks a lot all. All solutions work fine. > > while I am doing my home work. > Reading "Learning Python" and much more. > > Let me ask again to close my doubts: > l = ['k1', 'k2', 'k3', 'k4', 'k5'] d = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) d > {'k1'

Re: How to get dynamically-created fxn's source?

2010-11-05 Thread Peter Otten
gb345 wrote: > For a project I'm working on I need a way to retrieve the source > code of dynamically generated Python functions. (These functions > are implemented dynamically in order to simulate "partial application" > in Python.[1]) The ultimate goal is to preserve a textual record > of tran

Re: How to get dynamically-created fxn's source?

2010-11-05 Thread Emile van Sebille
On 11/5/2010 9:55 AM gb345 said... In any case, the problem remains of how to extract the dynamically-generated function's source code. Are you looking for the source code of the dynamically created wrapper function (effectively the piece that calls the original function) or of the wrapped

Re: Exception handling with NameError

2010-11-05 Thread Peter Otten
Zeynel wrote: > I want to append new input to list SESSION_U without erasing its > content. I try this: > > ... > try: > SESSION_U.append(UNIQUES) > except NameError: > SESSION_U = [] > SESSION_U.append(UNIQUES) > ... > I would think that at fir

Exception handling with NameError

2010-11-05 Thread Zeynel
Hello, I want to append new input to list SESSION_U without erasing its content. I try this: ... try: SESSION_U.append(UNIQUES) except NameError: SESSION_U = [] SESSION_U.append(UNIQUES) ... I would think that at first try I would get the NameEr

How to get dynamically-created fxn's source?

2010-11-05 Thread gb345
For a project I'm working on I need a way to retrieve the source code of dynamically generated Python functions. (These functions are implemented dynamically in order to simulate "partial application" in Python.[1]) The ultimate goal is to preserve a textual record of transformations performed

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Peter Pearson
On Fri, 5 Nov 2010 10:12:05 -0400, Philip Semanchuk wrote: > > BTW the more common name for this character is caret (ka-RAY). Yes, it's caret, but no, it's KA-rit, almost the same as carrot. It's straight from Latin, with no detour through French. -- To email me, substitute nowhere->spamcop, in

Re: How convert list to nested dictionary?

2010-11-05 Thread macm
Hi Folks thanks a lot all. All solutions work fine. while I am doing my home work. Reading "Learning Python" and much more. Let me ask again to close my doubts: >>> l = ['k1', 'k2', 'k3', 'k4', 'k5'] >>> d = reduce(lambda x,y: {y:x}, reversed(l), {'/':[1,2,3]}) >>> d {'k1': {'k2': {'k3': {'k4':

Re: What is the best way to handle a missing newline in the following case

2010-11-05 Thread Neil Cerutti
On 2010-11-05, Paul Rudin wrote: > "danmcle...@yahoo.com" writes: >>> The problem is when I get to the last line. When the program >>> sees '\n' after the 9, everything works fine. However, when >>> there isn't a '\n', the program doesn't process the last >>> line. >>> >>> What would be the best

Re: What is the best way to handle a missing newline in the following case

2010-11-05 Thread Paul Rudin
"danmcle...@yahoo.com" writes: >> The problem is when I get to the last line. When the program sees '\n' >> after the 9, everything works fine. However, when there isn't a '\n', >> the program doesn't process the last line. >> >> What would be the best approach to handle the case of the possible

Re: What is the best way to handle a missing newline in the following case

2010-11-05 Thread danmcle...@yahoo.com
> The problem is when I get to the last line. When the program sees '\n' > after the 9, everything works fine. However, when there isn't a '\n', > the program doesn't process the last line. > > What would be the best approach to handle the case of the possible > missing '\n' at the end of the file?

Re: What is the best way to handle a missing newline in the following case

2010-11-05 Thread Peter Otten
chad wrote: > I have an text file with the following numbers > > 1 > 3 > 5 > 7 > 3 > 9 > > > > Now the program reads in this file. When it encounters a '\n', it will > do some stuff and then move to the next line. For example, it will > read 1 and then '\n'. When it sees '\n', it will do some

What is the best way to handle a missing newline in the following case

2010-11-05 Thread chad
I have an text file with the following numbers 1 3 5 7 3 9 Now the program reads in this file. When it encounters a '\n', it will do some stuff and then move to the next line. For example, it will read 1 and then '\n'. When it sees '\n', it will do some stuff and go on to read 3. The problem i

Re: newbie qns : how do i use xmldiff?

2010-11-05 Thread No Name
I had to do some fishing around to figure this much out. Hope it helps. from input import * # From the xmldiff directory from fmes import * # From the xmldiff directory from format import *# From the xmldiff directory from StringIO import * # Build your original tree text1 = '123' st

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Philip Semanchuk
On Nov 5, 2010, at 9:43 AM, Matty Sarro wrote: > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int are unsupported for "^". Now, I realized I was > ma

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Matty Sarro
Thanks everyone, that explains it :) -Matty On Fri, Nov 5, 2010 at 9:43 AM, Matty Sarro wrote: > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int ar

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Shashwat Anand
On Fri, Nov 5, 2010 at 7:26 PM, Krister Svanlund wrote: > On Fri, Nov 5, 2010 at 2:43 PM, Matty Sarro wrote: > > Hey Everyone, > > Just curious - I'm working on a program which includes a calculation of a > > circle, and I found myself trying to use pi*radius^2, and getting errors > > that data

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread D'Arcy J.M. Cain
On Fri, 5 Nov 2010 09:43:25 -0400 Matty Sarro wrote: > now working. However, what exactly does ^ do? I know its used in regular > expressions but I can't seem to find anything about using it as an operator. It's the XOR operator. Try "help('^')" for more detail. By the way, it's "caret", not "c

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Daniel Urban
> However, what exactly does ^ do? Bitwise XOR: http://docs.python.org/py3k/reference/expressions.html#binary-bitwise-operations -- http://mail.python.org/mailman/listinfo/python-list

Re: How convert list to nested dictionary?

2010-11-05 Thread Peter Otten
Boris Borcic wrote: > Arnaud Delobelle wrote: >> macm writes: >> >>> Hi Folks >>> >>> How convert list to nested dictionary? >>> >> l >>> ['k1', 'k2', 'k3', 'k4', 'k5'] >> result >>> {'k1': {'k2': {'k3': {'k4': {'k5': {}} >>> >>> Regards >>> >>> macm >> >> reduce(lambda x,y: {y:x}, re

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Vlastimil Brom
2010/11/5 Matty Sarro : > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int are unsupported for "^". Now, I realized I was > making the mistake of using

Re: Silly newbie question - Carrot character (^)

2010-11-05 Thread Krister Svanlund
On Fri, Nov 5, 2010 at 2:43 PM, Matty Sarro wrote: > Hey Everyone, > Just curious - I'm working on a program which includes a calculation of a > circle, and I found myself trying to use pi*radius^2, and getting errors > that data types float and int are unsupported for "^". Now, I realized I was >

Silly newbie question - Carrot character (^)

2010-11-05 Thread Matty Sarro
Hey Everyone, Just curious - I'm working on a program which includes a calculation of a circle, and I found myself trying to use pi*radius^2, and getting errors that data types float and int are unsupported for "^". Now, I realized I was making the mistake of using '^' instead of "**". I've correct

Re: How convert list to nested dictionary?

2010-11-05 Thread Boris Borcic
Arnaud Delobelle wrote: macm writes: Hi Folks How convert list to nested dictionary? l ['k1', 'k2', 'k3', 'k4', 'k5'] result {'k1': {'k2': {'k3': {'k4': {'k5': {}} Regards macm reduce(lambda x,y: {y:x}, reversed(l), {}) d={} while L : d={L.pop():d} -- http://mail.python.org/

Re: Why "flat is better than nested"?

2010-11-05 Thread J. Gerlach
Am 28.10.2010 03:40, schrieb Steven D'Aprano: > [ snip a lot of wise words ] Can I put this (translated) in the german python wiki? I guess it might help more people to understand some decisions taken during python's development - and I'm to lazy to do something similar myself ;) Greetings from B

  1   2   >