Re: Tabs for indentation & Spaces for alignment in Python 3?
Michael Torrie : > In fact a decent editor that is auto-indenting code would, at least in > C or C++ mode, do that automatically. A decent editor frees you from this dilemma entirely: (custom-set-variables '(indent-tabs-mode nil)) HT belongs together with VT, SOH and ETB. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Parsing XML Using XPATH for Python
On Tuesday, December 2, 2014 11:52:37 PM UTC+1, John Gordon wrote:
> In Uzoma Ojemeni
> writes:
>
> > I am new to Python - a few days old - and I would appreciate some help.
>
> > I want write a python code to parse the below XML as below:-
>
> > ServingCell--NeighbourCell
> > L41_NBR3347_1--L41_NBR3347_2
> > L41_NBR3347_1--L41_NBR3347_3
> > L41_NBR3347_1--L41_NBR3349_1
> > L41_NBR3347_1--L41_NBREA2242_1
>
> >
> >
> >
> > 1
> >
> >
> >
> > lDot0 > lDot0 >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
> In plain English, it looks like you want to do this:
>
> 1. Print a header.
> 2. For each element:
> 3. Find the child element.
> 4. For each child element:
> 5. Print the "id" attributes of the element and the
> element.
>
> Translated to python, that would look something like this:
>
> # import the xml library code
> import xml.etree.ElementTree as ET
>
> # load your XML file
> tree = ET.parse('cells.xml')
>
> # get the root element
> root = tree.getroot()
>
> # print a header
> print("ServingCell--NeighbourCell")
>
> # find each child element
> for serving_cell in root.findall('LteCell'):
>
># find the child element
>attributes = serving_cell.find('attributes')
>
># find each child element
>for neighbor in attributes.findall('LteNeighboringCellRelation'):
>
># print the id's of the serving and neighbor cells
>print("%s--%s" % (serving_cell.attrib['id'],
> neighbor.attrib['id']))
>
> --
> John Gordon Imagine what it must be like for a real medical doctor to
> [email protected] 'House', or a real serial killer to watch 'Dexter'.
Thank you Guys. I will implement and feedback if i find any problems.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Tabs for indentation & Spaces for alignment in Python 3?
On 12/06/2014 01:40 AM, Marko Rauhamaa wrote: > Michael Torrie : > >> In fact a decent editor that is auto-indenting code would, at least in >> C or C++ mode, do that automatically. > > A decent editor frees you from this dilemma entirely: > > (custom-set-variables > '(indent-tabs-mode nil)) What dilemma? Do you mean you can avoid the drama of tabs by going all spaces? Of course in Python this is the recommended course. But that's typically not what I, or most people, use in C or C++. And one of the OP's points is that by using tabs for indent, and spaces for alignment, you can have the best of both worlds. Programmers can set their tab size to anything they want, and it still looks good (except of Linux kernel source code, which only will ever look right at tabs equivalent to 8 spaces). He wanted to know if he could still do that in Python3, and the answer is "yes" although we recommend highly just sticking to pep8 4 space characters per indent and no tabs whatsoever. Of course any validly-formatted Python code (or C code) can be made to look right and work right by running autopep8[1] on it. Just like "indent" can make your C code fit whatever style guide you need. [1] https://pypi.python.org/pypi/autopep8/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Tabs for indentation & Spaces for alignment in Python 3?
On Sun, Dec 7, 2014 at 3:41 AM, Michael Torrie wrote: > What dilemma? Do you mean you can avoid the drama of tabs by going all > spaces? Of course in Python this is the recommended course. Actually it's only one of several recommended courses, but otherwise yes. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Tabs for indentation & Spaces for alignment in Python 3?
Michael Torrie : > What dilemma? Do you mean you can avoid the drama of tabs by going all > spaces? Of course in Python this is the recommended course. > > But that's typically not what I, or most people, use in C or C++. "Most people"? Hm. I don't know most people. Anyway. Who cares about "most people"? > And one of the OP's points is that by using tabs for indent, and > spaces for alignment, you can have the best of both worlds. I certainly doesn't sound that way. > Programmers can set their tab size to anything they want, and it still > looks good That's anything but true. I see zigzaggy diffs all the time. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Tabs for indentation & Spaces for alignment in Python 3?
On 12/06/2014 09:57 AM, Marko Rauhamaa wrote: >> And one of the OP's points is that by using tabs for indent, and >> spaces for alignment, you can have the best of both worlds. > > I certainly doesn't sound that way. Why is that? > >> Programmers can set their tab size to anything they want, and it still >> looks good > > That's anything but true. I see zigzaggy diffs all the time. You're not reading what I'm writing, at least understanding it. The idea behind using tabs for indent and spaces for alignment are clear enough: >--->---blah (one, >--->---..two So obviously your zigzaggy diffs are showing that the person who wrote the code is *not* using tabs for indent and spaces for alignment. Must just be using tabs. Since tabs and spaces are not visibly distinguished, it's not readily apparent when one is properly using tabs and spaces together, and not apparent that your editor is doing it properly, so in Python most people recommend never mixing tabs and spaces, although you *can* do that in the way I've described if you really want to. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tabs for indentation & Spaces for alignment in Python 3?
On 6 December 2014 03:04:48 GMT+00:00, Michael Torrie wrote: >On 12/05/2014 07:31 PM, Ned Batchelder wrote: >> This is a perfect example! The code (with tabs as >--- and leading >> spaces as .) is: >> >> >---if (!list_empty(pending)) >> >--->---ret = list_first_entry(pending, struct async_entry, >> >--->--->--->---...domain_list)->cookie; >> >> Now, display it in your editor with tabs set to four spaces: >> >> >---if (!list_empty(pending)) >> >--->---ret = list_first_entry(pending, struct async_entry, >> >--->--->--->---...domain_list)->cookie; > >However, a conscientious programmer knows that tabs could be >arbitrarily >sized, so he would never do that. Instead he would do: > > >---if (!list_empty(pending)) > >--->---ret = list_first_entry(pending, struct async_entry, > >--->---...domain_list)->cookie; > >Which under the heretical tab size of 4: > >---if (!list_empty(pending)) > >--->---ret = list_first_entry(pending, struct async_entry, > >--->---...domain_list)->cookie; Not every programmer is as conscientious in the first of place, and that's far easier to get wrong than just agreeing to stick to one thing. This is why (often more rigid) style guides (or rather policies) exist. Maybe we should sack such programmers regardless of their other abilities instead of forcing all, including the conscientious, programmers to adhere to strict style policies? While I like the idea, I think that a slap on the wrist and a bit of re-indentation/re-alignment is all that is necessary (although I have worked with people who consider pure style changes to be a sin too). Simon -- https://mail.python.org/mailman/listinfo/python-list
Re: Tabs for indentation & Spaces for alignment in Python 3?
On 12/06/2014 10:12 AM, Simon Ward wrote: > Not every programmer is as conscientious in the first of place, and > that's far easier to get wrong than just agreeing to stick to one > thing. This is why (often more rigid) style guides (or rather > policies) exist. Sure, but in the world of braces languages, reformatting crappy code is fairly trivial > Maybe we should sack such programmers regardless of their other > abilities instead of forcing all, including the conscientious, > programmers to adhere to strict style policies? While I like the > idea, I think that a slap on the wrist and a bit of > re-indentation/re-alignment is all that is necessary (although I have > worked with people who consider pure style changes to be a sin too). I suppose if an employee continually submits commits that violate the coding standard after being asked time and again to not do that, and is too lazy to run his code through GNU indent probably should be fired. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tabs for indentation & Spaces for alignment in Python 3?
Michael Torrie : > So obviously your zigzaggy diffs are showing that the person who wrote > the code is *not* using tabs for indent and spaces for alignment. Source code lives easily for ten years or longer. It is touched by numerous people in different groups or even companies under different stylistic preferences. In fact, people rarely have the luxury or inclination to think in terms of style. > Since tabs and spaces are not visibly distinguished, it's not readily > apparent when one is properly using tabs and spaces together, Your "properly" is different from my "properly," I bet. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: jitpy - Library to embed PyPy into CPython
On Fri, Dec 5, 2014 8:54 PM CET Mark Lawrence wrote: >For those who haven't heard thought this might be of interest >https://github.com/fijal/jitpy Interesting, but it is not clear to me when you would use jitpy instead of pypy. Too bad pypy alone was not included in the benchmarks (cython would have also been nice). -- https://mail.python.org/mailman/listinfo/python-list
Re: jitpy - Library to embed PyPy into CPython
Albert-Jan Roskam wrote: > Interesting, but it is not clear to me when you would use jitpy instead > of pypy. Too bad pypy alone was not included in the benchmarks (cython > would have also been nice). And Numba can JIT compile this far better than PyPy and jitpy. Sturla -- https://mail.python.org/mailman/listinfo/python-list
