Alternate indent proposal for python 3000


I was considering putting together a proposal for an alternate block
syntax for python, and I figured I'd post it here and see what the
general reactions are. I did some searching, and while I found a lot
of tab vs space debates, I didn't see anything like what I'm thinking
of, so forgive me if this is a very dead horse.

Generally speaking, I like the current block scheme just fine. I use
python on a daily basis for system administration and text parsing
tasks, and it works great for me.

From time to time, though, I find myself needing a language for server-
side includes in web pages. Because of the need to indent (and
terminate indents), python seems an awkward choice for this, and it's
easy for me to see why php and perl are more popular choices for this
kind of task. Perhaps this is just my perception though.

I feel that including some optional means to block code would be a big
step in getting wider adoption of the language in web development and
in general. I do understand though, that the current strict indenting
is part of the core of the language, so... thoughts
Posted On: Sunday 4th of November 2012 11:58:58 PM Total Views:  163
View Complete with Replies

RELATED TOPICS OF Python Programming PROGRAMMING LANGUAGE




A proposal for attribute lookup failures

Proposal: When an attribute lookup fails for an object, check the top-level (and local scope) for a corresponding function or attribute and apply it as the called attribute if found, drop through to the exception otherwise. This is just syntactic sugar. Example: a = [1,2,3] a.len() # -> fails, # -> finds len() in the top-level symbol table, # -> applies len(a) # -> 3 a.foobar() # -> fails, # -> no foobar() in scope, # -> raise NameError Benefits: - Uniform OO style. Top-levels can be hidden as attributes of data. Most of the top-level functions / constructors can be considered as attributes of the data; e.g., an int() representation of a string can be considered as _part_ of the semantics of the string (i.e., one _meaning_ of the string is an int representation); but doing it this way saves from storing the int (etc) data as part of the actual object. The trade-off is speed for space. - Ability to "add" attributes to built-in types (which is requested all the time!!) without having to sub-class a built-in type and initialize all instances as the sub-class. E.g., one can simply define flub() in the top-level (local) namespace, and then use "blah".flub() as if the built-in str class provided flub(). - Backwards compatible; one can use the top-level functions when deed. No change to existing code required. - Seemingly trivial to implement (though I don't know much C). On attribute lookup failure, simply iterate the symbol table looking for a match, otherwise raise the exception (like current implementation). Drawbacks: - Could hide the fact that an extra (On) lookup on the symbol table is necessary for attribute lookup failure. (Maybe there could be a switch/pragma to enable (or disable) the functionality) - As above, attribute lookup failure requires an extra lookup on the symbol table, when normally it would fall through directly to exception. - \t Disclaimer: I realize that very often what seems good to me, ends up being half- assed, backwards and generally bad. So I'd appreciate input on this proposition. Don't take it that I think the idea is wonderful and am trying to push it. I am just throwing it out there to see what may become of it.
VIEWS ON THIS POST

180

Posted on:

Monday 5th November 2012
View Replies!

Re: two files into an alternate list

Tim Chase wrote: >> i have a file : >> file 1: >> 1 >> 2 >> 3 >> 4 >> 5 >> 6 >> >> file2: >> a >> b >> c >> d >> e >> f >> how do i make the two files into list like this = >> [1,a,2,b,3,c,4,d,5,e,6,f] > > from itertools import cycle > def serialize(*sources): > while True: > for source in sources: > yield source.next() > def stripper(iterator): > for thing in iterator: > yield thing.strip() > for thing in serialize( > stripper(file('file1.txt')), > stripper(file('file2.txt')) > ): > print thing > > As a previous responder noted, there are a number of ways to > treat the edge cases when the lengths of the files don't match. > Since you left the condition underqualified, I chose to let it > expire when the first one gave out rather than try and deal with > the complications of such ambiguity. > > -tkc > Or maybe just : >>> r = [] >>> for a, b in map(None , (int(i.strip('\n')) for i in open('file1.txt')) , (i.strip('\n') for i in open('file2.txt'))) : r.append(a) r.append(b) >>> r [1, 'a', 2, 'b', 3, 'c', 4, 'd', 5, 'e', None, 'f']
VIEWS ON THIS POST

107

Posted on:

Monday 5th November 2012
View Replies!

RE: sorteddict PEP proposal [started off as orderedict]

> From: Paul Hankin > > > Here's a first go. Sorting occurs when the keys are iterated over, > making it fast (almost as a dict) for construction, insertion, and > deletion, but slow if you're iterating a lot. You should look at some > use cases to decide if this approach is best, or if a sorted > datastructure should be used instead, but my instinct is that this is > a decent approach. Certainly, you're unlikely to get a simpler > implementation > > class sorteddict(dict): > "A sorted dictionary" > def __init__(self, arg=None, cmp=None, key=None, reverse=False): > if arg: > super(sorteddict, self).__init__(arg) > else: > super(sorteddict, self).__init__() > self._cmp = cmp > self._key = key > self._reverse = reverse > def keys(self): > return sorted(super(sorteddict, self).keys(), cmp=self._cmp, > key=self._key, reverse=self._reverse) > def iter_keys(self): > return (s for s in self.keys()) > def items(self): > return [(key, self[key]) for key in self.keys()] > def iter_items(self): > return ((key, self[key]) for key in self.keys()) > def values(self): > return [self[key] for key in self.keys()] > def iter_values(self): > return (self[key] for key in self.keys()) > def __str__(self): > return '{' + ', '.join('%s: %s' % (repr(k), repr(v)) > for k, v in self.iter_items()) + '}' > def __repr__(self): > return str(self) > def __iter__(self): > return self.iter_keys() You could speed up keys() at the cost of memory if you maintained a list of keys in the instance. Doing so would let you use an "unsorted" flag that gets set when a new key is added and checked when keys() is called. If the flag is unset, just return a copy of the list. Otherwise, sort the list in place, return a copy, and unset the flag. (Copies because you don't want the master key list to be modified by code using the class.) The use case for this seems to be when you have a dictionary that you need to often work through in sorted order. Sorting the keys every time keys() is called isn't an improvement over using a regular dict and sorting the keys normally. So the extra memory cost of maintaining an internal keys list looks reasonable to me. -- -Bill Hamilton
VIEWS ON THIS POST

188

Posted on:

Monday 5th November 2012
View Replies!

Only one week left for PyCon proposals!

There is only one week left for PyCon tutorial & scheduled talk proposals. If you've been thinking about making a proposal, now's the time! Tutorial details and instructions here: http://us.pycon.org/2008/tutorials/proposals/ Scheduled talk details and instructions here: http://us.pycon.org/2008/conference/proposals/ The deadline is Friday, November 16. Don't put it off any longer! PyCon 2008: http://us.pycon.org -- David Goodger PyCon 2008 Chair -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHNSxarqIPjB1FxosRA3jCAJ92ns7uhdthR/Mo2NtNCYYlecRXyACffNrP Q9eUyWT4iqW3R4JbYc9Ab6w= =XcuL -----END PGP SIGNATURE-----
VIEWS ON THIS POST

151

Posted on:

Monday 5th November 2012
View Replies!

Getting indented code snippets into blogger

I got tired of Bloggers inadequate comment editor so wrote this for transforming code snippets: ========================= ''' blogspace.py Turns leading spaces into HTML   tokens which shows as correct indentation on Blogger comment fields (and maybe other blogs). Donald. 'Paddy' McCarthy Sept 2011 ''' import fileinput, re for l in fileinput.input(): print re.sub(r'^(\s*)\s', lambda m: ' '*m.end(), l.rstrip()) ========================= If you find it works on other blogs then please reply.to this thread. - Paddy.
VIEWS ON THIS POST

74

Posted on:

Monday 5th November 2012
View Replies!

Reminder: call for proposals "Python Language and Libraries Track"for Europython 2006

Registration for Europython (3-5 July) at CERN in Geneva is now open, if you feel submitting a talk proposal there's still time until the 31th of May. If you want to talk about a library you developed, or you know well and want to share your knowledge, or about how you are making the best out of Python through inventive/elegant idioms and patterns (or if you are a language guru willing to disseminate your wisdom), you can submit a proposal for the Python Language and Libraries track """ A track about Python the Language, all batteries included. Talks about the language, language evolution, patterns and idioms, implementations (CPython, IronPython, Jython, PyPy ...) and implementation issues belong to the track. So do talks about the standard library or interesting 3rd-party libraries (and frameworks), unless the gravitational pull of other tracks is stronger. """ The full call and submission links are at: http://www.europython.org/sections/t...-for-proposals Samuele Pedroni, Python Language and Libraries Track Chair
VIEWS ON THIS POST

185

Posted on:

Monday 5th November 2012
View Replies!

Reminder: PyCon proposals due in a week

The deadline for PyCon 2006 submissions is now only a week away. If you've been procrastinating about putting your outline together, now's the time to get going... Call for Proposals: http://www.python.org/pycon/2006/cfp Proposal submission site: http://submit.python.org/ --amk
VIEWS ON THIS POST

151

Posted on:

Monday 5th November 2012
View Replies!

Reminder: PyCon proposal deadline now two weeks away

Remember to send in your proposals for PyCon 2005; the deadline for submissions is December 31st, only two weeks away. Read the call for proposals for more details: http://www.python.org/pycon/2005/cfp.html Proposal submission site: http://submit.pycon.org PyCon will also feature BoF sessions, sprints, lightning talks, and open space for discussions. Please see the PyCon wiki at http://www.python.org/moin/PyConDC2005 for more information, and to record your ideas and plan your events. --amk
VIEWS ON THIS POST

210

Posted on:

Monday 5th November 2012
View Replies!

vim newb - indenting python comments

I'm just starting to use vim. It has helped me do a lot of repetitive editing of Python files. One problem I have is that the >> indent in normal mode doesn't work when a line starts with the # character. Any idea what I'm doing wrong
VIEWS ON THIS POST

115

Posted on:

Monday 5th November 2012
View Replies!

indentation

every time I switch editor all the script indentation get mixed up, and python start giving me indentation weird errors. indentation also hard to follow because it invisible unlike brackets { } is there any solution to this problems
VIEWS ON THIS POST

53

Posted on:

Wednesday 7th November 2012
View Replies!

Call for proposals -- PyCon 2009

Call for proposals -- PyCon 2009 -- =============================================================== Want to share your experience and expertise PyCon 2009 is looking for proposals to fill the formal presentation tracks. The PyCon conference days will be March 27-29, 2009 in Chicago, Illinois, preceded by the tutorial days (March 25-26), and followed by four days of development sprints (March 30-April 2). Previous PyCon conferences have had a broad range of presentations, from reports on academic and commercial projects to tutorials and case studies. We hope to continue that tradition this year. Online proposal submission will open on September 29, 2008. Proposals will be accepted through November 03, with acceptance notifications coming out on December 15. For the detailed call for proposals, please see: We look forward to seeing you in Chicago!
VIEWS ON THIS POST

445

Posted on:

Wednesday 7th November 2012
View Replies!

py3k feature proposal: field auto-assignment in constructors

There is a pattern that occurs fairly often in constructors in Python and other OOP languages. Let's take an example: class Server(object): def __init__(self, host, port, protocol, bufsize, timeout): self.host = host self.port = port self.protocol = protocol self.bufsize = bufsize self.maxthreads = maxthreads self.timeout = timeout Imho, in the class above the assignment to instance fields does not contain much programming logic and therefore can be safely 'abstracted away' by the language itself with a syntax which would look something like this: class Server(object): def __init__(self, @host, @port, @protocol, @bufsize, @timeout): pass This would be equivalent to the first example above, yet it does not obfuscate the code in any way. Or does it It does look much cleaner to me. Of course, the ampersand is just an arbitrary choice and might have bad connotations for those who read it as 'take address of' but @ has some allusion to delegates which maybe is ok. I am not an experienced programmer and I am not sure if this is necessarily a good idea, so I wanted to get some feedback from more experienced Pythonistas before submitting it elsewhere.
VIEWS ON THIS POST

157

Posted on:

Wednesday 7th November 2012
View Replies!

Tab indentions on different platforms?

, I seem to be having problems with running my python code, written on a Mac, on Linux and Windows boxes. It seems like the problem has to do with tab indention, particularly I've noticed that my code will completely ignore try statements. Has anyone had a similar problem
VIEWS ON THIS POST

231

Posted on:

Wednesday 7th November 2012
View Replies!

Last chance for PyCon talk & tutorial proposals!

Thanks to all the proposal authors so far, we have received lots of proposals for PyCon talks & tutorials. But we'd like to have even more. Alas, the proposal submission deadline should have been set after a weekend, not before. So we have decided to extend the proposal submission deadline to Monday, November 19 at midnight (Chicago time). This gives you a *whole extra weekend* to write up your talk and tutorial ideas! If you've been procrastinating, stop! Get started on a proposal instead! See the call for conference talk proposals: http://us.pycon.org/2008/conference/proposals/ Topic ideas: http://wiki.python.org/moin/Talk_Subjects http://wiki.python.org/moin/PyCon200...bc40fa18a17f40 See the call for tutorial proposals http://us.pycon.org/2008/tutorials/proposals/ Topic ideas from the PyCon 2007 feedback: http://wiki.python.org/moin/PyCon200.../TutorialIdeas I hope to see (and hear) you at PyCon 2008! http://us.pycon.org -- David Goodger, PyCon 2008 Chair -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHPTCwrqIPjB1FxosRA3ZPAJ0SbjNXEC6oQUaPISeHKwZdX9RkqACguFSG 9AG/gWr09vg2DodgucuUAes= =TN01 -----END PGP SIGNATURE----
VIEWS ON THIS POST

248

Posted on:

Wednesday 7th November 2012
View Replies!

Re: two files into an alternate list

That depends: What do you want when you have these two files: file 1: a b c file 2: 1 2 3 4 5 Options: *['a',1,'b',2,'c',3,None,4,None,5] *['a',1,'b',2,'c',3,4,5] *['a',1,'b',2,'c',3] *Throw an exception And what if file 1 has more lines than file 2 Cheers, Cliff 1 On Mon, Oct 29, 2007 at 09:50:51PM +0530, Beema shafreen wrote regarding two files into an alternate list: > Delivered-To: python-list@bag.python.org > Date: Mon, 29 Oct 2007 21:50:51 +0530 > From: "Beema shafreen" > To: python-list@python.org > Subject: two files into an alternate list > Precedence: list > List-Id: General discussion list for the Python programming language > > List-Unsubscribe: , > > List-Archive: > List-Post: > List-Help: > List-Subscribe: , > > Errors-To: python-list-bounces+jcd=sdf.lonestar.org@python.org > > hi everybody , > i have a file : > file 1: > 1 > 2 > 3 > 4 > 5 > 6 > file2: > a > b > c > d > e > f > how do i make the two files into list like this = > [1,a,2,b,3,c,4,d,5,e,6,f] > regards > shafreen > -- > http://mail.python.org/mailman/listinfo/python-list
VIEWS ON THIS POST

61

Posted on:

Wednesday 7th November 2012
View Replies!

Best way to generate alternate toggling values in a loop?

I'm writing this little Python program which will pull values from a database and generate some XHTML. I'm generating a where I would like the alternate 's to be and What is the best way to do this I wrote a little generator (code snippet follows). Is there a better (more "Pythonic") way to do this # Start of Code def evenOdd(): values = ["Even", "Odd"] state = 0 while True: yield values[state] state = (state + 1) % 2 # Snippet trClass = evenOdd() stringBuffer = cStringIO.StringIO() for id, name in result: stringBuffer.write(''' %d %s ''' % (trClass.next(), id, name)) # End of Code
VIEWS ON THIS POST

69

Posted on:

Wednesday 7th November 2012
View Replies!

IndentationError: unexpected indent

I have this class: class case(blop.case): def __init__(self, n, a, b): blop.case.__init__(self) print 'Monty Python's Flying Circus has a ' within it...' ... ... But I get an error when I run the .py script from shell saying: print 'Monty ...
VIEWS ON THIS POST

171

Posted on:

Saturday 10th November 2012
View Replies!

Re: Using the indent method

, I am using elementtree to write an XML document and I am having a hard time adding the correct indentation. I have tried using the indent method, but I can not figure out how to use it. Any ...
VIEWS ON THIS POST

55

Posted on:

Sunday 11th November 2012
View Replies!

Difficulty with "inconsistent use of tabs and spaces in indentation"in file called

I've been trying for a couple days to build a program using pyObjC on a mac, I'm stuck on this error: : inconsistent use of tabs and spaces in indentation Traceback (most recent call last): File "setup.py", line 59, in ...
VIEWS ON THIS POST

58

Posted on:

Sunday 11th November 2012
View Replies!

Looking for indent advice howto in emacs python-mode

Here's what I want to do: if ( ( v == 1 ) or ( v == 2 ) or ( v == 3 ) ): pass but emacs (left to its own devices, does this. if ( ( v ...
VIEWS ON THIS POST

121

Posted on:

Sunday 25th November 2012
View Replies!