Re: Most "pythonic" syntax to use for an API client library
I highly recommend going with the last approach. With the last approach you can pass around objects in proper OOP fashion. This will be familiar to most contributors to your project and most devs that you hire. foo = api.customers(1) if bar==baz: foo.update(Name='Leroy') else: foo.delete() On Mon, Apr 29, 2019 at 4:43 AM Jonathan Leroy - Inikup via Python-list wrote: > > Hi all, > > I'm writing a client library for a REST API. The API endpoints looks like > this: > /customers > /customers/1 > /customers/1/update > /customers/1/delete > > Which of the following syntax do you expect an API client library to > use, and why? > > 1/ > api.customers_list() > api.customers_info(1) > api.customers_update(1, name='Bob') > api.customers_delete(1) > > 2/ > api.customers.list() > api.customers.info(1) > api.customers.update(1, name='Bob') > api.customers.delete(1) > > 3/ > api.customers.list() > api.customers(1).info() > api.customers(1).update(name='Bob') > api.customers(1).delete() > > ...any other? > > #3 seems to be more "pretty" to me, but I did not find any "official" > recommendation online. > > Thanks. > > -- > Jonathan. > -- > https://mail.python.org/mailman/listinfo/python-list -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- https://mail.python.org/mailman/listinfo/python-list
Re: CURSES WINDOWS
Your subject line will sure draw attention to the topic! On Tue, Sep 4, 2018 at 8:33 PM shinobi wrote: > > Hello All, > > can anyone please let me know what's the path to port linux python curses > program to Windows? > > Thanks > > -- > https://mail.python.org/mailman/listinfo/python-list -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- https://mail.python.org/mailman/listinfo/python-list
Re: WANT: bad code in python (for refactoring example)
There are some nice changes in here. You can mention to the students that I really appreciated the work done on the menu loop. You took an example of code that had grown piecemeal and become reasonably unmaintainable, and refactored it to be very maintainable in the future. Good luck to all class participants! On Fri, Feb 17, 2017 at 3:47 PM, Makoto Kuwata <k...@kuwata-lab.com> wrote: > On Thu, Feb 16, 2017 at 6:34 AM, Dotan Cohen <dotanco...@gmail.com> wrote: > >> I think that we can help each other! This is my own code, back when I >> was writing Python like PHP: >> https://github.com/dotancohen/burton > > > Year, this is a good example code for me to do refactoring. > > I created a pull request. This will be shown to my students. > > https://github.com/dotancohen/burton/pull/20/files > > I hope you favor this PR. > > -- > regards, > makoto kuwata > -- > https://mail.python.org/mailman/listinfo/python-list -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- https://mail.python.org/mailman/listinfo/python-list
Re: WANT: bad code in python (for refactoring example)
I think that we can help each other! This is my own code, back when I was writing Python like PHP: https://github.com/dotancohen/burton It is badly in need of a Pythonic refactor! Have at it, and I'll be happy to accept any pull requests. On Wed, Feb 15, 2017 at 12:44 AM, Makoto Kuwata <k...@kuwata-lab.com> wrote: > Hi, > > Is there any *just right* python code to refactor? > In other words, I'm finding bad code example in python. > > (background) > I'm teaching Python to some novice programmer, and > want to show refactoring example to them. > > (required) > * not good code > * not too large (for novice programmer) > * not too complex (for novice programmer) > * released under open source license > > If you know good material in github or bitbucket to refactor, > let me know it. > > -- > regards, > kwatch > -- > https://mail.python.org/mailman/listinfo/python-list -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- https://mail.python.org/mailman/listinfo/python-list
Re: PiCxx
On Sun, Mar 29, 2015 at 1:20 PM, Robert Kern robert.k...@gmail.com wrote: Please consider using a recognized open source license. Your project looks interesting, but I won't touch it with the current license. http://opensource.org/licenses I agree about the licensing. Many devs won't even evaluate the code for technical merits with an unestablished, unclear, and unfamiliar license like that. The donate anything concept is a cute idea, but put the idea in either an informal request if you BSD license the code, or as a condition for a commercial license if you GPL the code. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- https://mail.python.org/mailman/listinfo/python-list
Re: To whoever hacked into my Database
On Fri, Nov 8, 2013 at 7:11 PM, ru...@yahoo.com wrote: Long before you showed up here, I noticed the tendency to not answer questions directly but to jerk people off by giving hints or telling them to do something other than they want to do. Often that is good because the original request was for something that the OP really didn't want to do. But sometimes the OP knows they want to do (but doesn't want or is unable to clearly explain why) and when they clearly state that, yes, they do want to do it their way, their question should be answered in good faith or, for those who just can't tell how to do something wrong, ignored. Instead the response is typically a lot of hostility directed at them for not taking advice. In other words, the advice here is not free advice, but come with the price that you are expected to except it gratefully whether it was what you asked for or not. I think you are quite right to reject advice that does not do what you want and ask again for advice that does. FWIW, I am quite sure there are other readers of this group who feel the same way, but most people aren't willing to subject themselves to the bullying that will be directed at anyone who publicly agrees with you. It is the same way in real life too as I'm sure you know. Just wanted to let you know that not everybody here is an asshole. It is just that assholes, by their nature, are the loudest. When I've been given advice on this list or others that does not directly answer my question, I've found that the advice comes from one of two types of posters: 1) Those who don't understand my question, possibly due to my own failure to properly articulate. -or- 2) Those who understand my predicament better than I do, and show my how to get the results that I need despite my own failure to understand what exactly I need. With Python specifically, the latter far outnumber the former. When somebody here is giving advice, I listen humbly. Likewise I advise any newcomer to do. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- https://mail.python.org/mailman/listinfo/python-list
Re: ANN: psutil 1.0.0 released
Thanks, this looks really nice. I was duplicating some of this for my CLI-based webserver control panel: https://github.com/dotancohen/burton As soon as I integrate psutil into Burton I'll add it to the README and such. How would you like me to mention attribution exactly? -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for a new router
On Tue, Jul 9, 2013 at 7:57 AM, Chris Angelico ros...@gmail.com wrote: I recommend you go to a small local store that has friendly people and real service, tell them what you're needing, and support local business with your custom. That'll be more helpful to you than asking on a mailing list that's about Python. :) ChrisA Chris, the account that you replied to is just a spam account for his link at the bottom. Helpfully, it appears that Nabble has removed the link and left only the text. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Must we include urllib just to decode a URL-encoded string, when using Requests?
I am using the Requests module to access remote URLs. Sometimes I need to URL-decode or URL-encode a string (via RFC 3986). Must I import urllib or urllib2 just to use their quote() and unquote() methods? Does not Requests have such an ability, and perhaps I just cannot find it? On Stack Overflow [1] I found this wonderful function: def unquote(url): return re.compile('%([0-9a-fA-F]{2})',re.M).sub(lambda m: chr(int(m.group(1),16)), url) I am already importing the 're' module so that is not an issue. I am concerned, though, that this might not work for some non-ASCII characters such as some esoteric symbols or Korean/Chinese/Japanese characters. [1] http://stackoverflow.com/a/15627281/343302 -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Must we include urllib just to decode a URL-encoded string, when using Requests?
On Thu, Jun 13, 2013 at 4:20 PM, Robert Kern robert.k...@gmail.com wrote: Yes. Do you think there is a problem with doing so? I'm pretty sure that Requests will use either urllib or urllib2, depending on what is available on the server. I would like to use whatever Requests is currently using, rather than import the other. Can I tell which library Requests is currently using and use that? -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Must we include urllib just to decode a URL-encoded string, when using Requests?
On Thu, Jun 13, 2013 at 4:34 PM, Robert Kern robert.k...@gmail.com wrote: I'm pretty sure that Requests will use either urllib or urllib2, depending on what is available on the server. No, it doesn't. It gets its quote() function from urllib always. I see, thanks. Then that is what I will do as well! I would like to use whatever Requests is currently using, rather than import the other. Can I tell which library Requests is currently using and use that? The only thing I can think that you are talking about is the difference between Python 2 and Python 3. In Python 2, it's urllib.quote() and in Python 3, it's urllib.parse.quote(), but that's a Python-version issue, not something to do with requests, per se. requests does have a compatibility layer, internally, that pastes over those issues, but I don't think that is intended to be a stable public API that you should rely on. You should handle that kind of switch yourself if you care about compatibility across both versions of Python. https://github.com/kennethreitz/requests/blob/master/requests/compat.py#L86 Great, thank you Robert. I see that Requests is calling both urllib and urllib2. For some reason I thought that is rather wasteful and should be avoided. I was probably wrong! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Must we include urllib just to decode a URL-encoded string, when using Requests?
On Thu, Jun 13, 2013 at 4:44 PM, Burak Arslan burak.ars...@arskom.com.tr wrote: On 06/13/13 16:25, Dotan Cohen wrote: paste this to your python console, it'll show you what modules requests imports: import sys p = set(sys.modules) import requests for m in sorted(set(sys.modules) - p): print(m) Thank you. Python is a beautiful language, I cannot believe that the set(sys.modules)-p line does what it does! Interestingly, on my system with Python3 neither urllib nor urllib2 are imported, only urllib3 which I had not heard of until now: __future__ _json atexit cgi chardet html http.cookiejar http.cookies json json.decoder json.encoder json.scanner logging mimetypes netrc queue requests requests.api requests.auth requests.compat requests.cookies requests.defaults requests.exceptions requests.hooks requests.models requests.sessions requests.status_codes requests.structures requests.utils shlex six six.moves threading urllib3 urllib3._collections urllib3.connectionpool urllib3.exceptions urllib3.filepost urllib3.packages urllib3.packages.mimetools_choose_boundary urllib3.packages.ssl_match_hostname urllib3.poolmanager urllib3.request urllib3.response urllib3.util -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Monty Python in Syria
On Thu, Aug 16, 2012 at 3:01 AM, Terry Reedy tjre...@udel.edu wrote: But it has nothing to do with Monty Python either, that I can see. Nor is there a video to see the context of (OP said For context, start the video at 1:00.) Perhaps link is erroneous. At 1:00 the captor asks the pilot to state his name, then asks him to state his quest. I was expecting the third question to be about favourite colours or swallows. Marking something OT does not excuse it. It should still be related. We cannot allow 1000s of OT posts a day, marked OT or not. Agreed. An incidence is not a phenomenon. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
OT: Monty Python in Syria
And now for something completely different. Not programming related, but at 1:20 I was expecting a different question: http://www.aljazeera.com/news/middleeast/2012/08/2012813103922872697.html I figured if anybody could appreciate that, it would be the folks here. Enjoy! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Monty Python in Syria
On Wed, Aug 15, 2012 at 5:41 PM, Dotan Cohen dotanco...@gmail.com wrote: And now for something completely different. Not programming related, but at 1:20 I was expecting a different question: http://www.aljazeera.com/news/middleeast/2012/08/2012813103922872697.html I figured if anybody could appreciate that, it would be the folks here. Enjoy! For context, start the video at 1:00. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: open office in another language?
Enjoy this relevant article: http://developers.slashdot.org/story/12/01/14/008236/code-cleanup-culls-libreoffice-cruft Dotan Cohen http://what-is-what.com/what_is/open_office.html -- http://mail.python.org/mailman/listinfo/python-list
Re: open office in another language?
On Wed, Jan 11, 2012 at 00:17, Sean Wolfe ether@gmail.com wrote: hmm I didn't know this, nice to know. Yes, C++ is still enough overhead that I wouldn't want to try extending it ... I bet the code is a whole lot to try and grok. When Apache got the LibreOffice project they heavily refactored the code. As a result, LO is considered less of a monstrosity to hack on than Open Office. That said, if your goal is to try to extend an application, then being written in Java as opposed to C++ would be an advantage, not a disadvantage. Especially in an application the size of OOo. That said, only a few dialogues and wizards (none critical) are written in Java. Most is C++. It would be nice to have an office suite in a newer language that is easier to tinker with. Take a look at Calligra, C++ with Qt. It is supposed to be very easy to extend and port, in fact that was a design goal. http://calligra-suite.org/ -- Dotan Cohen http://what-is-what.com/what_is/python.html -- http://mail.python.org/mailman/listinfo/python-list
Re: open office in another language?
On Fri, Jan 13, 2012 at 18:46, Nelle Varoquaux Once again, a nitpick. Apache did not get the LibreOffice project, but the Openoffice.org project from Oracle. LibreOffice is a fork of openoffice and a foundation independant from Apache. Work has been done to simplify the code, but I wouldn't say it is much better: they can do a limited amount of job with a limited amount of developpers (mostly old OOo devs). So yes, there are less comments written in german than there used to, but it is still a very old, buggy code in which changing a line causes lots of pain. Sorry, you are correct. Apache did refactor OOo in order to integrate it with Apache coding practices. LO is, however, heavily refactored from what I understand. Note that this may all be heresy, I've not looked at the code of either! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: staticmethod makes my brain hurt
On Thu, Nov 17, 2011 at 09:37, Ian Kelly ian.g.ke...@gmail.com wrote: On Wed, Nov 16, 2011 at 11:44 PM, Dotan Cohen dotanco...@gmail.com wrote: Try this (untested): class C: @staticmethod def foo(): pass print inside, C.foo, callable(C.foo) If you had tested this, you would have found that you get a NameError, since C is not yet bound inside the class block where you define it. I hadn't tested, I'm at work far from Idle. Just shooting from the hip. For that matter, though, this does work in Java (I'm pretty sure but again, untested right now). -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: staticmethod makes my brain hurt
On Thu, Nov 17, 2011 at 04:30, Roy Smith r...@panix.com wrote: When I run this (python 2.6.1): class C: @staticmethod def foo(): pass print inside, foo, callable(foo) print outside, C.foo, callable(C.foo) I get: inside staticmethod object at 0x421df0 False outside function foo at 0x41e6f0 True I don't understand. Why is foo not callable inside of the class definition? Where this comes up is that I'm trying to use a callable default in mongoengine: class User(Document): @staticmethod def _get_next_id(): [blah, blah, blah] return id user_id = IntField(required=True, default=_get_next_id) The way mongoengine works is if callable(default) is true, it calls default() to get the real value to use. At the point where the IntField() call is made, _get_next_id is not callable, and eventually I end up with: ValidationError: staticmethod object at 0x2a3c1a0 could not be converted to int Try this (untested): class C: @staticmethod def foo(): pass print inside, C.foo, callable(C.foo) -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Regex to match all trailing whitespace _and_ newlines.
On Thu, Sep 1, 2011 at 13:30, Peter Otten __pete...@web.de wrote: Dotan Cohen wrote: In the terrific Anki [1] application I am trying to remove trailing whitespace from form fields. This is my regex: [\n+\s+]$ My attempt: sub = re.compile(r\s*?(\n|$)).sub sub(EOL, alpha \nbeta \r\n\ngamma\n) 'alphaEOLbetaEOLEOLgammaEOL' sub(EOL, alpha \nbeta \r\n\ngamma) 'alphaEOLbetaEOLEOLgammaEOL' sub(EOL, alpha \nbeta \r\n\ngamma\t) 'alphaEOLbetaEOLEOLgammaEOL' Hi Peter, sorry for the _late_ reply. It turns out that Anki stores newlines internally as br, since its display model is based on HTML. Thanks, though! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Regex to match all trailing whitespace _and_ newlines.
In the terrific Anki [1] application I am trying to remove trailing whitespace from form fields. This is my regex: [\n+\s+]$ Actually, even simplifying it to [\n] or [\r\n] is not matching any newlines! What might be the cause of this? Note that I am not entering the regex in Python code, I am entering it in a regex-supporting Find/Replace dialogue in Anki. Anki is written in Python. Thanks. [1] ankisrs.net -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabs -vs- Spaces: Tabs should have won.
On Mon, Jul 18, 2011 at 02:55, Andrew Berg I think the reason the idea isn't dead is because of the emergence of new devices with small displays (tablets/smartphones/etc.) and their increasing popularity. When writing code that is meant to be run on desktops or servers, the 80-column limit is mostly irrelevant, but Python running on these small devices, especially with Python code being interpreted rather than compiled, it's convenient to edit code on those platforms, where there is a significant column limit. Let me see if I understand: because there exists a possibility that someone might want (not need) to edit code on a telephone to make a quick edit to code being interpreted on that machine, _all_ Python code should limit itself to a line width that may or may not wrap on a telephone screen? Is that the argument in favor of an 80-character line width? -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabs -vs- Spaces: Tabs should have won.
On Sat, Jul 16, 2011 at 19:51, rantingrick rantingr...@gmail.com wrote: -- Evidence: Tabs ARE superior! -- I am also a recent spaces-to-tabs convert. One of the reasons is that I've discovered that programing in a non-fixed width font is a real pleasure, but the spaces are too narrow. Tabs alleviate that. I'm still looking for the perfect programming font. Suggestions welcomed. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabs -vs- Spaces: Tabs should have won.
On Sun, Jul 17, 2011 at 11:35, Andrew Berg bahamutzero8...@gmail.com wrote: programing in a non-fixed width font is a real pleasure If you're masochistic, maybe. Do you find fixed-width fonts ugly? I don't find that fixed-width fonts are ugly, but variable-width fonts sure are more of a pleasure. And with code-colouring in any good IDE, there is no real need to have the dot or other tiny characters jump out and announce their presence. So long as the indentation lines up (which it does, with tabs or spaces) then I do not see any problem with variable-width. What are the counter-arguments? I really would like to know why anyone would use a non-fixed-width font for programming. Aesthetics. I'm still looking for the perfect programming font. Suggestions welcomed. I use Courier New. Have you looked at the Droid fixed-width fonts? Very nice, and easy to distinguish 0 from o or O. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabs -vs- Spaces: Tabs should have won.
On Sun, Jul 17, 2011 at 14:51, Thorsten Kampe thors...@thorstenkampe.de wrote: * Dotan Cohen (Sun, 17 Jul 2011 14:11:40 +0300) So long as the indentation lines up (which it does, with tabs or spaces) then I do not see any problem with variable-width. What are the counter-arguments? Alignment doesn't line up. They do with tabs. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabs -vs- Spaces: Tabs should have won.
On Sun, Jul 17, 2011 at 15:53, Thomas 'PointedEars' Lahn pointede...@web.de wrote: I am also a recent spaces-to-tabs convert. One of the reasons is that I've discovered that programing in a non-fixed width font is a real pleasure, but the spaces are too narrow. Tabs alleviate that. Not using a fixed-width font avoids this problem and others in the first place. I'm still looking for the perfect programming font. Suggestions welcomed. I can recommend Consolas (Windows) or Inconsolata (elsewhere), which are designed for programming and are near perfect in that regard. However, I have decided for Deja Vu Sans Mono for reading and writing Usenet articles because it supports more Unicode characters and can be sized appropriately for running text. I have used those three in the past. Terrific fonts each of them, especially Inconsolata if I remember correctly. But, all of them are fixed-width fonts. I do not understand how you can consider using a non-fixed-width font in programming a real pleasure as many them show a lot of ambiguities in source code. Take for example the lowercase l (el) vs. the capital I (ai) vs. the | (pipe) character, or the 0 (zero) vs. the capital O (oh) character in Arial. The ambiguity has never been an issue for me. In the unlikely event that an l (el) is in the place of a pipe, the code won't compile and I'll get an error on the line in question. Though that has never actually happened: the IDE is double-checking way before the code gets to the compiler. Zero vs. O (oh), I've never had this issue either and even if one key was hit in place of the other (they are close by) then either the IDE or compiler would catch it, or it would result in a minor bug in a text string. It simply isn't an issue. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabs -vs- Spaces: Tabs should have won.
On Sun, Jul 17, 2011 at 17:29, gene heskett ghesk...@wdtv.com wrote: I'm still looking for the perfect programming font. Suggestions welcomed. When you find it Dotan, let me know, I've been looking since the later '70's. Hey there Gene! Are you not on every mailing list on the internet old man?!? I have also come to the conclusion that the perfect woman, the perfect physics theory, and the perfect programming font are all illusions that men will stride their entire lives in search for but will never find. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabs -vs- Spaces: Tabs should have won.
On Sun, Jul 17, 2011 at 20:57, rantingrick rantingr...@gmail.com wrote: Such a system of rigorous formatting rules requires much less interpreter logic. Python will be leaner and meaner. There won't be any more arguing about how to format code. There will only be one way; the correct way! Choose to follow it or die of exceptions; your choice. Do you know that Python 4000 is the only language in the world whose vocabulary gets smaller every year?' -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabs -vs- Spaces: Tabs should have won.
On Sun, Jul 17, 2011 at 21:20, Thorsten Kampe thors...@thorstenkampe.de wrote: The past is bickering over selfish personal freedoms, the future of is unity. And a tab is *exactly* four spaces. Not three. Not five. Not eight. For you, for me, and for the rest of the world. Amen! Four is the number thou shalt indent, and the number of the indenting shall be four. Six thou shalt not indent, neither indent thou two, excepting that thou then proceed to four. Eight is right out. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tabs -vs- Spaces: Tabs should have won.
On Sun, Jul 17, 2011 at 22:53, Thomas 'PointedEars' Lahn pointede...@web.de wrote: It simply isn't an issue. Apparently it is *has not been* an issue for *you* *yet*. There are languages (like Python) that are compiled just-in-time. Besides, neither an IDE nor a compiler can (always) recognize that foo[b0r] is not foo[bOr] (which really is not a far-fetched example as the O and zero keys are adjacent to each other on in keyboard layouts). You do not want such an ambiguity to bite you later. I do agree that in a weakly-typed language such as python one might conceivably try to use an undeclared variable and the IDE and compiler won't catch that. However 0 vs. O would more likely be 0 vs. o as one would really have to mess up bad to not only press the wrong key but also hit shift at the same time. 0 and o are no harder to distinguish in a VWF than in a FWF. For that matter, why is it assumed that fixed-width fonts by nature better distinguish 0 from O, or any other ambiguous characters? My current system (Kubuntu 11.04, default VWF font in Firefox whatever it may be) distinguished 0 from O just fine. Also I/1 and l/1 are easy to distinguish, but I agree that I/l are not. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?
On Sat, Jun 18, 2011 at 01:09, Xah Lee xah...@gmail.com wrote: thanks. didn't know about Ducky keyboard. Looks good. Also nice to hear your experience about Truly Ergonomic keyboard. I like it, see my first-hour review here: http://geekhack.org/showwiki.php?title=Island:18154 no actually i don't know how to make normal letter keys as (ctrl, alt) modifiers. You'll need a usb hid remapper. (there's a couple for mac os x i linked on my site but i couldn't verify cuz am now on a 6 years old powerpc with outdated mac os x) For Windows, Microsoft made a layout maker. I haven't used it so i don't know if it allows mapping letter keys as modifier. Have you tried it? I use Kubuntu Linux. i don't know much about the subject but from what i read am guessing it's possible, because each key just send up/down signals. (whether you are using usb or ps/2 makes a difference too.) (am assumbing above that you want to put modifiers in normal letter key positions. But if all you want to do is swap modifier among themselves, that's pretty easy. Lots of tools to do that for mac and windows.) Actually, most of the modifiers are just switched among themselves. Only Win is in a normal-keyboard location. But even if you succeded in putting modifiers to letter key positions, you may run into problems with key ghosting, because the circuits are desigend to prevent ghosting on qwerty layout only (with mod keys in their normal positions). Unless your keyboard is actually full n-key- roll-over. I doubt that this is n-key rollover, but it is I think 6-key rollover and in any case I personally use sticky keys as I have difficulty pressing more than one key at a time. But in the general sense that is good to know, if other people use the layout they will need to be aware of that. Thanks! maybe some of these are useful info, but maybe you are quite beyond that. Thanks for your info too. Good luck. just Xah Thanks Xah! I will not be online for the next three weeks, so a reply will be much delayed! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?
On Sat, Jun 18, 2011 at 14:40, Xah Lee xah...@gmail.com wrote: very nice review! and on geekhack.org too — the hardcore keyboard mod site! I enjoyed reading it. Yes, that is some forum! Wait until I post my mods. You've never seen such abused input devices, I hope. i only started to use linux this month, from 10 years hiatus. First thing to do there is remap keys to the way i like of course. But am not familiar on how-to there. Seems xmodmap is becoming obsolete and XKB is in place. There's a couple nice sites about XKB but havn't had a chance to study them yet. XKB is pretty configurable but some stuff is not well documented. Here are some of my bookmarked resources, to get you started: // Making new layouts http://wiki.linuxquestions.org/wiki/Altering_or_Creating_Keyboard_Maps http://www.x.org/wiki/XKB http://www.freedesktop.org/wiki/Software/XKeyboardConfig http://wiki.linuxquestions.org/wiki/Configuring_keyboards http://wiki.linuxquestions.org/wiki/Background:_How_keyboards_work http://www.xfree86.org/4.2.0/xmodmap.1.html // Enabling multimedia keys (also useful for the former) http://abesto.host22.com/2009/04/microsoft-ergonomic-4000-and-linux.html http://en.gentoo-wiki.com/wiki/Microsoft_Natural_Ergonomic_Keyboard_4000 https://wiki.kubuntu.org/KDEMultimediaKeys http://linux.oneandoneis2.org/keys.html http://cweiske.de/howto/xmodmap/allinone.html http://linux.die.net/man/8/setkeycodes http://rick.vanrein.org/linux/funkey/ http://juliano.info/en/Blog:Memory_Leak/Linux,_KDE:_Mapping_functions_to_extra_keys http://linux.playofmind.net/extra_keys/ http://dev-loki.blogspot.com/2006/04/mapping-unsupported-keys-with-xmodmap.html And as I know you to be an Emac man: https://github.com/r0adrunner/Space2Ctrl May i ask you a few questions down the road? (maybe we can add each other on google talk or some social network) Sure, I'll email you from my personal email account soon. But after a few more hours, I won't be available until late July. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?
On Fri, Jun 17, 2011 at 20:43, Xah Lee xah...@gmail.com wrote: u r aware that there are already tens of layouts, each created by programer, thinking that they can create the best layout? Yes. Mine is better :) Had Stallman not heard of VI when he set out to write Emacs? if not, check 〈Computer Keyboards, Layouts, Hotkeys, Macros, RSI ⌨〉 xahlee.org/Periodic_dosage_dir/keyboarding.html on layout section. Lots people all creating layouts. also, you want to put {Enter, Tab}, etc keys in the middle, but I don't understand from ur website how u gonna do that since it requires keyboard hardware modification. e.g. r u creating key layout on PC keyboard or are you creating hardware keyboard Key layout? The former is a dime a million, the latter is rare but also there are several sites all trying to do it. Talk is cheap, the hardest part is actually to get money to finance and manufacture it. The latest one, which i deem good, is Truely Ergonomic keyboard. It sells for $200 and is in pre-order only now. I ordered the Truley Ergonomic keyboard, I waited for half a year after delivery was supposed to happen to request my money back. Too many delays, so in the end I bought a Ducky mechanical (Cherry Browns) instead. I am writing a software keyboard layout. I'm actually having a hard time moving the modifier keys (Alt, Ctrl) to a new location. If you know how to do that I would much appreciate some advice, I'll post the problem here or in private mail. Thanks, Lee. (or should that be Thanks, Xah?) -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?
On Wed, Jun 15, 2011 at 11:30, Chris Angelico ros...@gmail.com wrote: Competing rumour: The layout was designed such that typewriter could be typed out using only the top row, to improve demo speed by a factor of three. Utter nonsense. The QWERTY keyboard was - and this is verified fact - designed the way is was because the inventor's mother in law's initials were AS and his father is law was DF. The letter combinations JK and L; were his childrens' initials. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?
On Wed, Jun 15, 2011 at 15:19, rusi rustompm...@gmail.com wrote: Thank you rusi! Tell me, where can I read more about the advantages of each finger? Googling turns up nothing. My intention is to improved the Noah ergonomic keyboard layout. Thanks! Dont know how to answer that! I only have my experience to go by :-) If you've spent a childhood and many of your adult hours breaking your hands on Czerny http://en.wikipedia.org/wiki/Carl_Czerny and Hanon eg exercise 4 http://www.hanon-online.com/the-virtuoso-pianist/part-i/exercise-n-4/ you will come to similar conclusions. I should warn however that even for a modern electronic piano the action is larger and heavier than a typical (computer) keyboard and for a real/acoustic piano with a foot long slice of wood moved for each keystroke its probably an order of magnitude heavier. So its not exactly clear how much the experience of one carries over to the other Thanks. From testing small movements with my fingers I see that the fourth finger is in fact a bit weaker than the last finger, but more importantly, it is much less dexterous. Good to know! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?
On Mon, Jun 13, 2011 at 10:21, Elena egarr...@gmail.com wrote: On 13 Giu, 06:30, Tim Roberts t...@probo.com wrote: Studies have shown that even a strictly alphabetical layout works perfectly well, once the typist is acclimated. Once the user is acclimated to move her hands much more (about 40% more for Qwerty versus Dvorak), that is. And disproportionate usage of fingers. On QWERTY the weakest fingers (pinkies) do almost 1/4 of the keypresses when modifier keys, enter, tab, and backspace are taken into account. I'm developing a QWERTY-based layout that moves the load off the pinkies and onto the index fingers: http://dotancohen.com/eng/noah_ergonomic_keyboard_layout.html There is a Colemak version in the works as well. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?
On Wed, Jun 15, 2011 at 06:00, rusi rustompm...@gmail.com wrote: For keyboarding (in the piano/organ sense) the weakest finger is not the fifth/pinky but the fourth. Because for the fifth you will notice that the natural movement is to stiffen the finger and then use a slight outward arm-swing; for thumb, index and middle, they of course have their own strength. The fourth has neither advantage. IOW qwerty is not so bad as it could have been if it were qewrty (or asd was sad) Thank you rusi! Tell me, where can I read more about the advantages of each finger? Googling turns up nothing. My intention is to improved the Noah ergonomic keyboard layout. Thanks! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner needs advice
If you disagree, then I invite you to list one example of two different things that are compatible. Men and women. MS Office and Open Office. IE6 and HTML. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner needs advice
On Tue, May 31, 2011 at 21:29, Ian Kelly ian.g.ke...@gmail.com wrote: On Tue, May 31, 2011 at 11:56 AM, Dotan Cohen dotanco...@gmail.com wrote: If you disagree, then I invite you to list one example of two different things that are compatible. Men and women. This is a slightly different sense of the word compatible than we have been discussing: able to work together to perform a function, not interchangeable. MS Office and Open Office. Nope. Remember, the assertion by harrismh777 was that all you have to do to prove incompatibility is to show 'one' (1) test case where compatibility fails. As one example, any Calc document that uses the EASTERSUNDAY function will fail in Excel, since Excel does not provide it. I could easily come up with other examples (let's not even get into the differences in macros), but one is all I need. IE6 and HTML. :-) Ian, I'm surprised, you of all people might have noticed that my sarcasm was intended to point out exactly that no two things are compatible, least of all those things designed with compatibility as a design spec! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner needs advice
On Fri, May 27, 2011 at 23:40, harrismh777 harrismh...@charter.net wrote: You have erected a straw-man... once again. I think that is a red herring, not a strawman. Most 2.x code *will not* run correctly in 3.x/ Most of the best improvements and enhancements of 3.x will not back-port to below 2.7, and almost none of them will back-port before 2.6 (class decorations, for instance). Although it is true that 2.x code will not run in a 3.x environment, the changes to the code are minimal. This would be akin to saying that a 2008 Peugeot 407 will not drive on a Canadian road because the license plate is a different shape. Just go an put a different plastic license plate holder on the Peugeot and it will run fine on the Canadian road. The changes to bring Python 2 code into Python 3 code are minimal, and it would be a terrific learning experience for the OP to go back and revise his old code to do just that. Furthermore, the OP is not just learning Python for the fun of learning Python. If that were the case, then I would agree that Python 3 is the way to go. The OP needs to use imaging libraries which may not yet work in Python 3 (I have not checked, but it is very likely that they do not). Therefore Python 3 is a non-starter in any case. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's super() considered super!
On Thu, May 26, 2011 at 19:39, Raymond Hettinger pyt...@rcn.com wrote: It would also be great if some of you would upvote it on HackerNews. Here's a link to the super() how-to-guide and commentary: bit.ly/ iFm8g3 Is that the same link as in the OP? I don't click on blind links, so if it isn't then please post a direct link. Thanks. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's super() considered super!
On Thu, May 26, 2011 at 21:38, Ian Kelly ian.g.ke...@gmail.com wrote: It's a link to ycombinator: http://news.ycombinator.com/item?id=2588262 Thanks. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Why did Quora choose Python for its development?
On Fri, May 20, 2011 at 19:39, Beliavsky beliav...@aol.com wrote: I thought this essay on why one startup chose Python was interesting. http://www.quora.com/Why-did-Quora-choose-Python-for-its-development PHP was out of the question. Facebook is stuck on that for legacy reasons, not because it's the best choice right now.[1] Our main takeaway from that experience is that programming language choice is very important and is extremely costly to change. Python was a language that Charlie and I both knew reasonably well (though I know it a lot better now than I did when we started). We also briefly considered C#, Java, and Scala. The biggest issues with Python are speed and the lack of typechecking. C# seemed pretty promising. As a programming language, it's great, but: •We didn't want to be on the Microsoft stack. We were up for learning something new, and MS SQL Server actually seemed pretty good, but we knew we'd need to integrate with lots of open source code that has only second-class support for .NET, if it supports it at all. Also, most of the best engineers these days are used to open source stuff. •We didn't want to take the risk of being on Mono (an open source implementation of C#/.NET). It's not clear how long funding will be around for that project, and I'd heard of various performance problems. Plus, it seemed like everything else in the C# ecosystem would assume we were on the Microsoft stack. For a lot of little reasons, Java programs end up being longer and more painful to write than the equivalent Python programs. It's also harder to interoperate with non-Java stuff. Scala had a lot of the downsides of Java and the JVM, although it wasn't quite as bad. The language seemed a little too new and like it would bring some unnecessary risk (for example, who knows how good will support be in 10 years). Two other languages we very briefly thought about were OCaml and Haskell (neither had big enough ecosystems or good enough standard libraries, and both were potentially too hard for some designers/data analysts/non-engineers who might need to write code). We decided that Python was fast enough for most of what we need to do (since we push our performance-critical code to backend servers written in C++ whenever possible). As far as typechecking, we ended up writing very thorough unit tests which are worth writing anyway, and achieve most of the same goals. We also had a lot of confidence that Python would continue to evolve in a direction that would be good for the life of our codebase, having watched it evolve over the last 5 years. So far, we've been pretty happy with the choice. There's a small selection bias, but all of the employees who'd been working with other languages in the past have been happy to transition to Python, especially those coming from PHP. Since starting the following things have happened: •Python 2.6 got to the point where enough of the libraries we used were compatible with it, and we made a very easy transition to it. •Tornado (web framework) was released as open source, and we moved our live updating web service to that. •PyPy got to the point where it looks like it will eventually be usable and will give us a significant speedup. All together, these give us confidence that the language and ecosystem is moving in a good direction. [1] What are the horrors of PHP? and Do Facebook engineers enjoy programming in PHP? and Why hasn't Facebook migrated away from PHP? and What are some of the advantages of PHP over other programming languages? for more on that. Via Nizameddin Haşim Ordulu and JR Ignacio. -- http://mail.python.org/mailman/listinfo/python-list They considered Haskell and OCaml and not a single mention of Perl? -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: obviscating python code for distribution
On Wed, May 18, 2011 at 10:36, Hans Georg Schaathun h...@schaathun.net wrote: But then, nothing is secure in any absolute sense. The best you can do with all your security efforts is to manage risk. Since obfuscation increases the cost of mounting an attack, it also reduces risk, and thereby provides some level of security. Obviously, if your threat sources are dedicated hackers or maybe MI5, there is no point bothering with obfuscation, but if your threat source is script kiddies, then it might be quite effective. The flip side is that the developer will not know about weaknesses until much later in the development, when making changes to the underlying code organization may be difficult or impossible. In this early phase of development, he should actually encourage the script kiddies to report the bugs. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: obviscating python code for distribution
On Wed, May 18, 2011 at 20:24, Chris Angelico ros...@gmail.com wrote: But you CAN make a system 100% secure against network-based attacks. Only by unplugging the network cable. This is called an air gap, and is common in military installations. Anything with a cable plugged in is hackable. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: obviscating python code for distribution
On Wed, May 18, 2011 at 20:24, Chris Angelico ros...@gmail.com wrote: Denial of service attacks are the hardest to truly defend against, and if your level of business is low enough, you can probably ignore them in your code, and deal with them by human (Hmm, we seem to be getting ridiculous amounts of traffic from XX.YY.ZZ.*, I think I'll put a temporary ban on that /24). Although some really nasty DOSes can be blocked fairly easily, so it's worth thinking about them. The python code should not be concerned with DDoS, that is what iptables is for. Remember, never do in code what Linux will do for you. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: obviscating python code for distribution
On Mon, May 16, 2011 at 07:40, Chris Angelico ros...@gmail.com wrote: And I'm sure Steven will agree with me that this is not in any way a bad thing. I've written hundreds of such programs myself (possibly thousands), and they have all served their purposes. On a slightly larger scale, there are even more programs that have never left the walls of my house, having been written for my own family - not because I'm afraid someone else will steal them, but because they simply are of no value to anyone else. But hey, if anyone wants a copy of my code that's basically glue between [obscure application #1] and [obscure application #2] that does [obscure translation] as well to save a human from having to do it afterwards, sure! You're welcome to it! :) However, I do not GPL my code; I prefer some of the other licenses (such as CC-BY-SA), unless I'm working on a huge project that's not meant to have separate authors. For something that by and large is one person's work, I think it's appropriate to give attribution. But discussion of exactly _which_ open source license to use is a can of worms that's unlikely to be worth opening at this stage. Actually, Chris, those applications are probably no less valuable to be open source than Linux or Firefox. The reason is that when one goes to learn a new language it is valuable to look at existing real world code. However, the code available online generally falls into one of two categories: 1) Simple sample code, which demonstrates a principle or technique 2) Full-blown FOSS application with hundreds of source files and a build It sounds to me like your home-brew code might be one of the missing links between the two. It won't be so tiny as to be trivial, but it won't be so huge as to be beyond the grasp of novices. I for one would love to look over such code. I'll learn something, without a doubt. Maybe someone might even spot a bug or make a suggestion to improve it. And almost invariably, any problem that I've ever had someone has had first. So while you might have been one of the first have a need to interface FooWidget with PlasmoidBar, someone after you will in fact need just the code to do that. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: learnpython.org - an online interactive Python tutorial
On Wed, Apr 20, 2011 at 20:15, Ron ron.rei...@gmail.com wrote: Hey everyone. I've written an online interactive Python tutorial atop Google App Engine: http://www.learnpython.org. All you need to do is log in using your Google account and edit the wiki to add your tutorials. Read more on the website. Thanks for your help, and I would appreciate if you help me spread the word, and give me feedback on the website. -- http://mail.python.org/mailman/listinfo/python-list Nice work! I notice that the Next Chapter link does not work. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: learnpython.org - an online interactive Python tutorial
On Fri, Apr 22, 2011 at 09:38, harrismh777 harrismh...@charter.net wrote: If an operation like (+) is used to add 1 + '1' then the string should be converted to int and the addition should take place, returning a reference to object int (2). No, the int 1 should be cast to a string, and the result should be the string '11'. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Another location of the PyGTK tutorial
http://gitorious.org/pygtk-tutorial On Sat, Apr 2, 2011 at 19:53, craf p...@vtr.net wrote: Hi. Anyone know if the pygtk tutorial that was in this direction http://www.learnpygtk.org/pygtktutorial/index.html, can be located elsewhere. Regards. Cristian -- http://mail.python.org/mailman/listinfo/python-list -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Another location of the PyGTK tutorial
http://gitorious.org/pygtk-tutorial On Fri, Apr 1, 2011 at 21:03, craf p...@vtr.net wrote: Hi. Anyone know if the pygtk tutorial that was in this direction http://www.learnpygtk.org/pygtktutorial/index.html, can be located elsewhere. Regards. Cristian -- http://mail.python.org/mailman/listinfo/python-list -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems of Symbol Congestion in Computer Languages
On Tue, Mar 1, 2011 at 05:30, rusi rustompm...@gmail.com wrote: Had there been more meta keys, it might be nice to have a symbol for each key on the keyboard. I personally have experimented with putting the symbols as regular keys and the numbers as the Shifted versions. It's great for programming. Hmmm... Clever! Is it X or Windows? Can I have your setup? It's X, on Kubuntu. I've since destroyed that layout, but you can easily play around in /usr/share/X11/xkb/symbols/us or whichever layout you prefer. I am working on another one, though, actually I just stared working on it yesterday. It's currently broken (I'm in the middle of troubleshooting it) but you can see what I currently have here: http://dotancohen.com/eng/keyboard_layout.html One problem we programmers face is that keyboards were made for typists not programmers. Yes, I'm trying to solve that! Ideally in the end all the brackets including {} won't need modifier keys. Give me some feedback, please, on that layout. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems of Symbol Congestion in Computer Languages
On Tue, Mar 1, 2011 at 07:04, Xah Lee xah...@gmail.com wrote: hi Russ, there's a programer's dvorak layout i think is bundled with linux. or you can do it with xmodmap on X-11 or AutoHotKey on Windows, or within emacs... On the mac, you can use keyboardMaestro, Quickeys, or just write a os wide config file yourself. You can see tutorials and sample files for all these here http://xahlee.org/Periodic_dosage_dir/keyboarding.html i'd be interested to know what Dotan Cohen use too. You can see what I started working on yesterday, but it's far from finished: http://dotancohen.com/eng/keyboard_layout.html I tried reaching you on Skype yesterday, Xah, but I think that you blocked me suspecting that I may be a bot. Try to Skype-chat with me at user dotancohen, I think that we can help each other. i tried the swapping number row with symbols a few years back. didn't like it so much because numbers are frequently used as well, especially when you need to enter a series of numbers. e.g. heavy math, or dates 2010-02-28. One can use the number pad but i use that as extra programable buttons. I don't like the number pad so I'm looking for another solution. I wired up a spring-off lightswitch to the Shift key and I operate it with my foot. It's great but it only works when I'm home: it is too ridiculous to take with me. I'm wiring up two more for Ctrl an Alt, too bad it's too cumbersome to have ESC, Enter, and Backspace there as well. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems of Symbol Congestion in Computer Languages
You miss the canonical bad character reuse case: = vs ==. Had there been more meta keys, it might be nice to have a symbol for each key on the keyboard. I personally have experimented with putting the symbols as regular keys and the numbers as the Shifted versions. It's great for programming. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and unicode
On Mon, Sep 20, 2010 at 05:42, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: Use the PEP 263 encoding declaration URL:http://www.python.org/dev/peps/pep-0263/ to let Python know the encoding of the program source file. While PEPs are valuable, once accepted or rejected they become historical documents. They don't necessarily document the current behaviour of the language. See here for documentation on encoding declarations: http://docs.python.org/reference/lexical_analysis.html#encoding-declarations This is the first time that I've read the PEP document regarding Unicode / UTF-8. I see that it mentions that the declaration must be on the second or first line of the file. Is this still true in Python 3? I have been putting it further down (still before all python code, but after some comments) in code that I write (for my own use, not commercial code). -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and unicode
On Mon, Sep 20, 2010 at 12:20, Peter Otten __pete...@web.de wrote: It may work by accident, if you declare it as UTF-8, because that is also the default in Python 3. That does seem to be the case. Thank you for the enlightenment and information. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to set a cookie within a python script
2010/8/4 Νίκος nikos.the.gr...@gmail.com: Encodings still give me headaches. I try to understand them as different ways to store data in a media. Tell me something. What encoding should i pick for my scripts knowing that only contain english + greek chars?? iso-8859-7 or utf-8 and why? Always use UTF-8, every modern system supports it, and it will let you use any arbitrary character that you need, such as maybe a smiley or a Euro sign. You will avoid headaches with databases and files and all sorts of other things that you don't yet expect. Declare it in the HTTP header, and in the HTML meta tag. Trust me, I maintain gibberish.co.il which specializes in encoding problems. Just use UTF-8 everywhere and you will save a lot of headaches. Can i save the sting lets say Νίκος in different encodings and still print out correctly in browser? No. ascii = the standard english character set only, right? Pretty much, plus the numbers, some symbols, and a few nonprinting characters. Read here: http://en.wikipedia.org/wiki/Ascii -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to set a cookie within a python script
On Wed, Aug 4, 2010 at 18:30, Dave Angel da...@ieee.org wrote: Depends on how sure you are that your program will never need characters outside your greek character set. Remember Y2K? Don't forget that the Euro symbol is outside the Greek character set. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to set a cookie within a python script
On Tue, Aug 3, 2010 at 18:41, Dave Angel da...@ieee.org wrote: I don't understand your wording. Certainly the server launches the python script, and captures stdout. It then sends that stream of bytes out over tcp/ip to the waiting browser. You ask when does it become html ? I don't think the question has meaning. ׁHTML is just plain text. So the answer to the question is that ideally, the plain text that is sent to stdout would already be HTML. print ( titleMy Greek Page/title\n ) -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Ignorance and Google Groups (again)
On 2 July 2010 05:10, D'Arcy J.M. Cain da...@druid.net wrote: On Thu, 1 Jul 2010 21:34:15 +0300 Dotan Cohen dotanco...@gmail.com wrote: I'm one of them. Gmail is great for mailing lists, though I would never use it as a personal email client. But I'm more of a lurker than a poster on this list, so D'Arcy won't miss me anyway. As the song says. How can I miss you if you won't go away. :-) I've never heard that, but it sounds line a great line. Googling now! As I explained, I don't block just because you are on gmail.com. I only block if you use Google Groups to post via news. Yes, I got to that part after I posted. I should have read to whole thread first. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Ignorance and Google Groups (again)
On 1 July 2010 00:06, Stephen Hansen me+list/pyt...@ixokai.io wrote: Gmail and Google Groups are not one and the same. There's a number of people who subscribe to the list directly, use Gmail, and don't go anywhere near Google Groups. I'm one of them. Gmail is great for mailing lists, though I would never use it as a personal email client. But I'm more of a lurker than a poster on this list, so D'Arcy won't miss me anyway. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert .doc to .pdf
On 14 June 2010 20:03, Thomas Jollans tho...@jollans.com wrote: On 06/14/2010 01:19 PM, Thales wrote: Good morning, I need to convert some files from .doc to .pdf. I've googled it a little bit and all the solutions I've found used the OpenOffice API, but I can't use it. Anybody knows a library that I can use to do it? Why can't you use OpenOffice? This is the real question. OOo can even be installed on a machine with no video card and run as a service in order to convert documents. The OP might also be interested in this gem from a prominent Wine dev: http://dag.wieers.com/home-made/unoconv/ Any answer to the question will depend on why the OP cannot run OOo, and most likely the answer will be a fix for how to in fact run it anyway (or MSO). -- Dotan Cohen http://gibberish.co.il http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: (a==b) ? 'Yes' : 'No'
On 30 March 2010 18:40, gentlestone tibor.b...@hotmail.com wrote: Hi, how can I write the popular C/JAVA syntax in Python? Java example: return (a==b) ? 'Yes' : 'No' My first idea is: return ('No','Yes')[bool(a==b)] Is there a more elegant/common python expression for this? I'm a little late to the party, but I just saw this in Dive Into Python: multiple = 1024 if a_kilobyte_is_1024_bytes else 1000 It's kind of sloppy as the condition is between the possible values, but it works. -- Dotan Cohen http://bido.com http://what-is-what.com Please CC me if you want to be sure that I read your message. I do not read all list mail. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Regex Story
Unreasonable phobia to regex is just as much harmful as overuse of it. Agreed. I did not mean to sound as if I am against the use of regular expressions. -- Dotan Cohen http://bido.com http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: The Regex Story
I would have agreed with you if someone were to make the statement until a few weeks ago; somehow in the last week or so, the mood about regex seems to has shifted to regex is not suitable for anything type of mood. As soon as someone (OP or not) proposed a regex solution, someone else would retort with don't use regex use string-builtins or pyparsing. It appears that the group has developed some sense of regexphobia; some people pushes using string builtins for moderately complex requirement and suggested pyparsing for not-so complex need and that keeps shrinking regex sweet spot. But that's just my inherently subjective observation. Isn't that a core feature of a high-level language such as Python? Providing the tools to perform common or difficult tasks easily thought built in functions? I am hard pressed to think of a situation in which a regex is preferable to a built-in function. -- Dotan Cohen http://bido.com http://what-is-what.com Please CC me if you want to be sure that I read your message. I do not read all list mail. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Regex Story
Regexes do have their uses. It's a case of knowing when they are the best approach and when they aren't. Agreed. The problems begin when the when they aren't is not recognised. -- Dotan Cohen http://bido.com http://what-is-what.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Timer
What can I put there to remove the splash page after 5 seconds? Javascript. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il Please CC me if you want to be sure that I read your message. I do not read all list mail. -- http://mail.python.org/mailman/listinfo/python-list
Re: Generic Python Benchmark suite?
What do you suggest? $ man time -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: HAppy New Year
2010/1/2 baboucarr sanneh sanne...@hotmail.com: Hi guys, Jus want to wish you a happy new year to u all.. 1.Copy the content below and Paste it on a Notepad. 2 . Use replace all (Ctrl + H) 3. Type in ‘6’ in the ‘find what’ column 4. Type in _ (underscore) in the ‘replace with’ column 5. Click on replace all. Wow, I just love Windows users. Sending this to the Python list? Paste on a notepad?!? The Replace All function in a notepad is Ctrl-H?!?? What does H stand for?!?!? Explicit instructions how to :%s/6/_/g in a notepad?!?!? Happy new year! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: HAppy New Year
What I want to know is why didn't he just write \ ... original long string ... .replace(6, _) Uf! Why didn't I think of that?! But watch that snarkiness ... I'm a Windows user too! That's fine, I know that fresh air has to get into the basement somehow ! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Language mavens: Is there a programming with if then else ENDIFsyntax?
The OP explicitly said no block delimiters. Your example uses {..}, and doesn't have endif. Just out of habit. I think that PHP, like C, lets you avoid the block deliminators so long as the block all fits on one line. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Language mavens: Is there a programming with if then else ENDIF syntax?
2009/11/16 Steve Ferg steve.ferg.bitbuc...@gmail.com: This is a question for the language mavens that I know hang out here. It is not Python related, except that recent comparisons of Python to Google's new Go language brought it to mind. NOTE that this is *not* a suggestion to change Python. I like Python just the way it is. I'm just curious about language design. For a long time I've wondered why languages still use blocks (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements. I've often thought that a language with this kind of block-free syntax would be nice and intuitive: if condition then do stuff elif condition then do stuff else do stuff endif Note that you do not need block delimiters. Obviously, you could make a more Pythonesque syntax by using a colon rather then then for the condition terminator. You could make it more PL/I-like by using do, etc. You can write shell scripts using if ... fi, but other than that I don't recall a language with this kind of syntax. Does anybody know a language with this kind of syntax for ifThenElseEndif? PHP has exactly this: if (condition) { // stuff } elseif (otherContition) { // otherStuff } elseif (yetAnotherCondition) { // yetOtherStuff } Furthermore, PHP has the switch statement: http://php.net/manual/en/control-structures.switch.php switch ($i) { case 0: echo i equals 0; break; case 1: echo i equals 1; break; case 2: echo i equals 2; break; } The break commands end the switch, and they can be removed to have multiple matches perform multiple functions. Is there any particular reason why this might be a *bad* language- design idea? It is about as far from OO as one could get. Whether or not that is bad depends on the use case. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyfora, a place for python
My personal preference would be a link in each sub-paragraph in the official documentation to a wiki page devoted to that specific aspect of the Python language. A place were users could augment the documentation by providing sample code and by expanding out the documentation for those of us who don't live and breath Python in our sleep. Real Python coders would not click on the user wiki links and all of us newbies could communicate with each other. But until a place like that exists, perhaps Pyfora will get us part way there. The PHP documentation has this feature: user comments right on the same page (no link to a wiki, though). It's great, most of the best usage practices that I have learned in that language came from the user's comments, not from the official documentation itself. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
notmm uses Python 2.6 and will probably work just fine with Python 3000. The only reference to notmm that I could find in Google was this thread! I am free, no matter what rules surround me. If I find them tolerable, I tolerate them; if I find them too obnoxious, I break them. I am free because I know that I alone am morally responsible for everything I do. -- Robert A. Heinlein Heinlein said that? It's been a long time since I've read Heinlein, and his quotes are as vivid as his books. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
... The point is that I want to use only _Python_ features, not Django/Mako/whatever features. However I am aware that some things I should not touch for security reasons. That is why I want a framework: to provide the security aspects of things like converting UTF-8, database escaping, etc. My 2 cents... A very valuable 2 cents. Thanks. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
It is clear and obvious. But it has the template engine duplicating a function that Python has built in. My goal is to learn reusable Python (reusable for non-web projects). My goal is not to find the quickest way to a website. Please correct me if I'm wrong, but you did learn HTML, CSS and SQL, didn't you ? How do any of these languages relates to Python ?-) HTML and CSS yes, but just enough SQL to fake it. None of those languages relate to Python, each language performs a different function. However, the template language looks completely redundant as it duplicates functionality of the language that I intend to learn. won't help me learn Python any more than learning PHP would. So going from PHP to Django is pointless. Please get out of the server page mindset. Templates are just that : templates. Period. You don't use templates to write your *applicative* code. I understand that. I meant reusable knowledge, not reusable code. There's very few reusable knowledge to be gained from templating code anyway- even if using a python-based template system like Mako. Unless you think doing a loop or a conditional are things you need to learn ?-) I would say that one needs to know how to do a for loop in Python, in order to program in Python! Then use Mako - it uses plain Python to manage the presentation logic. Now we're talking! I will look further into Pylons and Mako. Beware that the above comments about how less there's to learn from the templates code still apply - basically, the programming part of a template is restricted to simple branching, iterations, and variable substitution. I see. I don't expect to ever have a team, Possibly not. But as strange as it migh be, there are other peoples that do, and most of these frameworks are written by professional web programmers. I therefore counter that these frameworks were designed for people unlike myself, which easily explains my resistance to them. The point is that I want to use only _Python_ features, not Django/Mako/whatever features. If so, you shouldn't use *any* third-part libs, and possibly not even the stdlib. THat is going just a bit far! More seriously : reinventing the wheel - unless for educational purposes - is not really pythonic. If what you want is to learn, write your own framework, template system, form handling etc... You'll very certainly find out that they suck big time compared to existing projects, but you'll learn _at least_ one thing: that writing a sensible non-trivial framework or lib is *hard*. Actually, I konw just how hard it is. PHP and some C in university. However I am aware that some things I should not touch for security reasons. That is why I want a framework: to provide the security aspects of things like converting UTF-8, from what and to what ?-) Into and out of the database. string / unicode encoding and decoding is a builtin Python feature. I know, but I need to play with it a bit before I become comfortable with how it is handled. database escaping, Already provided by any DB-API compliant connector, at least if correctly used. Now there's *much* more in security (specially when doing web programming) than this... Of course. But these are the relevant issues for Python. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
I took a look a both yesterday. They are both generic text templating systems that seem to pretty much do the same thing. I suspect you will prefer Mako since it avoids duplicating Python's comtrol structures. But I think it worthwhile to look at both anyway since doing so will help to separate the concepts from the particular implementations. My take on them is this: when text mixes code that is meant to be interpreted and text data meant to be taken literally, some means must be devised to distinguish the two. In programs files, the code is left unquoted and the text data is quoted. In template files, the marking is reversed: the literal text is left unquoted and the code *is* quoted. In Mako, expressions are quoted with braces ({...}), single statements with '%' prefix, and multiple statements as well as Mako tags with % Thanks, Terry, that should save me some time. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
I think you're misunderstanding how Python and the web work together. Python is not PHP -- it was not designed to replace HTML, and it is in itself not a templating language. If you would like to use Python code embedded in HTML, the way PHP is typically used, you may want to look at Python Server Pages (http://www.modpython.org/live/current/doc-html/pyapi-psp.html) which are provided by mod_python. I see, thank you! This is what has been bothering and confusing me. I started with HTML and added PHP later, and the PHP fit in nicely embedded in the HTML, and even though it's now HTML embedded in PHP the principals are the same. Python doesn't seem to work that way, and I have been having a hard time wrapping my head around just why. Just so you know (as I think this is what is causing much of the misunderstanding here), most Python web frameworks *do not* subscribe to the traditional model of the web, where URLs represent files on a server. (In the case of PHP, Python Server Pages, or CGI scripts, these are augmented files which are executed by the server, but it's the same concept). Instead, they typically map URLs to arbitrary code. I don't think that I like that idea. I will give it a fair chance, though, now that it problem has been identified. Thank you very much for helping me understand this important distinction. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
2009/10/29 Albert Hopkins mar...@letterboxes.org: On Wed, 2009-10-28 at 16:38 +0200, Dotan Cohen wrote: return HttpResponse(unmaintanable_html % data) That's fine for single variables, but if I need to output a table of unknown rows? I assume that return means the end of the script. Therefore I should shove the whole table into a variable and then copy that variable to the array data? No, if you use a templating system like Django's then basically you pass a QuerySet to your template. A QuerySet is basically a pointer to a SQL query, for example. The templating system just knows to expect an iterable, it can be a list of rows or it can be a QuerySet which does a fetch from a database. No need to shove an entire table into a variable. Sounds like the system is trying to outsmart the programmer here. Another advantage if templates for many is that it allows programmers to do what they do best (write code) while letting web designers do what they do best (designing web pages) without them walking over each other (that much). I do see that advantage. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
As is, in my case. Actually, what use case is there for having Apache reprocess the HTML output of the script? compression, cache, whatever... Thanks. I actually did think of compression. It's not that it was unclear, but that it's innaccurate. outputting to stdout is an implementation detail, and should not be exposed at the applicative code level. Dealing with appropriate abstraction - here, an HttpResponse object - is far better (well, IMHO of course... - standard disclaimers, YMMV etc). I see. I believe that is called Dotan's Razor: a slight inaccuracy saves a lengthy explanation. but also impacts your mental map of what's going on... You're thinking in terms of streams and stdout, which, while not that far from actual implementation (in the end it always boils down to bits sent over the wires...), might not be the right level of abstraction when it comes to application programming. Seeing how the templating engines work, I now know why my choice of words bothered you. In fact, I was thinking in terms of PHP's linear progress through the code which is not quite valid here. Thank you for taking the time to set me straight. What I saw is already complex enough to justify using better tools IMHO. Or to make better use of the one you have. I am beginning to see how true that is. I'd personnaly suggest either Mako (possibly one of the best Python templating systems) or Django's (well documented and beginner-friendly). I will examine them both this weekend. Thanks! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Feedback wanted on programming introduction (Python in Windows)
What would be good is if there was a balancing book eg. one specifically targeting ubuntu, which is gaining popularity as we mail. Agreed 100%. I opened this thread as I am learning Python, but my platform is Kubuntu. Of the students in my faculty, about one third have already moved to Ubuntu or some other Linux distribution. Windows-only tutorials just look outdated, even if their principles apply to other OSs as well. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
Perhaps this might better answer your questions: http://docs.djangoproject.com/en/dev/topics/templates/#id1 Actually, that example just proves my point! Look at this templating code: {% for entry in blog_entries %} h2{{ entry.title }}/h2 p{{ entry.body }}/p {% endfor %} Why would I want to learn that when Python already has a real for loop? I know HTML, and I have a goal of learning Python for it's reusability (desktop apps, for instance). I don't want to learn some templating language that duplicates what Python already has built in! I think that I will use the HTTP-abstraction features of Django, but disregard the templates. My code might be uglier, but the knowledge will be transferable to other projects. My ultimate goal is not to make the latest greatest website. My ultimate goal is to port my perfectly functional website to a language that will benefit me by knowing it. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
A webframework is *written* in python. Your whole line of argumentation boils down to I can write things myself in python, why use libraries/frameworks. Yes. You can also delete your standard-lib, and code everything in there yourself - with the same argument. Using a framework is about proven solutions for common problems, letting you focus on working on your actual application code. While I know that to be true in the general sense, from what I've looked at Django and other frameworks it seems that the web frameworks push the coder to use templates, not letting him near the HTML. For instance, I was looking for a class / framework that provided a proven method of decoding cookies (setting them is no problem), decoding POST and GET variables, escaping variables for safe entry into MySQL, and other things. Django and the other frameworks seem to force the user to use templates. I just want the functions, and to print the HTML as stdout to the browser making the request. I had to settle on PHP to do this, which admittedly is what PHP was invented to do. However, for obvious reasons, I would have prefered to code in Python. In fact, I still would. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
While I know that to be true in the general sense, from what I've looked at Django and other frameworks it seems that the web frameworks push the coder to use templates, not letting him near the HTML. For instance, I was looking for a class / framework that provided a proven method of decoding cookies (setting them is no problem), decoding POST and GET variables, escaping variables for safe entry into MySQL, and other things. Django and the other frameworks seem to force the user to use templates. I just want the functions, and to print the HTML as stdout to the browser making the request. I had to settle on PHP to do this, which admittedly is what PHP was invented to do. However, for obvious reasons, I would have prefered to code in Python. In fact, I still would. I should probably expand on this: How can I get an array with all the GET variables in Python? How can I get an array with all the POST variables in Python? How can I get an array with all the COOKIE variables in Python? How can I get the request URI path (everything after http://[www.?]example.com/)? That's all I want: no templates and nothing between me and the HTML. The HTTP headers I can output to stdout myself as well. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
I should probably expand on this: How can I get an array with all the GET variables in Python? How can I get an array with all the POST variables in Python? How can I get an array with all the COOKIE variables in Python? How can I get the request URI path (everything after http://[www.?]example.com/)? That's all I want: no templates and nothing between me and the HTML. The HTTP headers I can output to stdout myself as well. Again: if you insist on doing everything yourself - then of course any library or framework isn't for you. I insist on handling the HTML myself. As for converting the request variables into Python variables, if a class/framework makes that easier then I would gladly use it. My question was serious. How can I do those things? But then do you deal with headers correctly? Yes, so far as I know. This is actually simpler than the HTML, just be careful not to output two newline characters in sequence (thereby ending the header). Do you respect character encodings? Yes! UTF-8 from database to scripting language to HTTP request. Form-encodings? Yes, UTF-8 the in the other direction. However, as form data can be spoofed, I would like a function that checks it. Does Python have such a function? What class does? Is your generated HTML valid? Naturally, even though this is not a Python issue. Are timestamp-formats generated according to RFCs for your cookies? Yes, this is not a problem. Is there some gothcha that I am unaware of? Do you parse content negotiation headers? No. I hate sites that do that. If the page is available in another language, their is a link in the corner. I think you underestimate the task it is to make a webapplication good. Probably, but that would not depend on the scripting language. I make bad webapplications in PHP too! And even if not, what you will do is ... code your own webframework. That is why I am looking for a class that handles the backend stuff, but lets _me_ handle the HTML. Because there is a lot of boilerplate otherwis. If that's a learning-experience your after, fine. Besides, yes, you can get all these things nonetheless. You just don't need them most of the time. And at least pylons/TG2 lets you return whatever you want instead, as a string. Not via print though - which is simply only for CGI, and no other means (e.g. mod_wsgi) of python-web-programming. I am trying to follow you here. What is return whatever you want? Return HTML to stdout to be sent to the browser? -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
2009/10/28 Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid: Dotan Cohen a écrit : declarative mapping of urls to code Apache does this, unless I am misunderstanding you. Using url rewriting ? Yes, fine. Then tell me how you implement reverse url generation (like Django or Routes do). I have no idea what reverse url generation is. I assume that the user will call http://example.com/path/to/script.py?var1=hellovar2=world script.py would live in /home/user/site-name/public_html/path/to/ of code to templates Those who code in HTML don't need this. ??? I would prefer to output everything from html to /html with print statements. I don't want some framework wrapping my output in tags, I want the tags to be part of the output. In any case it's not hard to call a function in a class that writes the HTML before the content, then write the content, then call another function that writes the HTML after the content. Hmmm, yummy ! And SO maintainable... Yes, why not? This is how my sites are run, though in PHP instead of Python. No prepackaged templates. PHP *is* a template language. This is, in general what I'm doing: ?php // process GET POST and cookie variables, deal with mysql if needed $title=blah; include_once/path/to/headerFile; print $content; include_once/path/to/footerFile; exit(); ? I would really like to know what else. So far, I am not convinced that a framework offers anything that is not already easily accomplished in Python. Given that we're talking about Python frameworks, it seems obvious that what they do can be accomplished in Python. Now the question is how much you like to write the same boring and error-prone boilerplate code project after project... Like I said before, I don't want to have to maintain the functions that turn the HTTP environment into Python variables, or the code that manages database connections. Functions that escape data to be sent to MySQL (to prevent sql injection) would be nice. Other than that, it's all on me. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
While I know that to be true in the general sense, from what I've looked at Django and other frameworks it seems that the web frameworks push the coder to use templates, not letting him near the HTML. Well... there must be a reason, for sure... No ? ֹYes, but I don't like it. Django and the other frameworks seem to force the user to use templates. Not at all. Nothing prevents you from shooting yourself in the foot and generating HTML by hand in your view functions (or request handler methods etc, depending on the framework). How is this done in Django, then? This is just plain stupid wrt/ readability, maintainability, reuse and whatnot, but hey, if you want to waste your time, please do. As far as i'm concerned, I'm very happy to let the HTML coder write the HTML part and the application programmer write the applicative part - even when I end up wearing both caps. I've done stupider things. I just want the functions, and to print the HTML as stdout to the browser making the request. I had to settle on PHP to do this, Why so ? Almost any programming language can do CGI. And I settled on PHP because it does what I need. However, I would prefer to move it to Python for the benefit of using the same language in the different places that I code for (such as personal applications for the desktop, pyqt). -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
How can I get an array with all the GET variables in Python? How can I get an array with all the POST variables in Python? How can I get an array with all the COOKIE variables in Python? How can I get the request URI path (everything after http://[www.?]example.com/)? That's all I want: no templates and nothing between me and the HTML. The HTTP headers I can output to stdout myself as well. $python help(cgi) help(cgitb) help(Cookie) help(urlparse) help(os.environ) GET variables: - import os,cgi if os.environ.has_key('QUERY_STRING'): getv = cgi.parse_qs(os.environ['QUERY_STRING']) print getv.keys() Other examples is very simple too... Thanks, Mikhail. I now have a bit to google on. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
I have no idea what reverse url generation is. It's a mean to avoid hard-coding urls in your application code - the url is fully generated by the 'url mapping' system. I don't need that, see below. I assume that the user will call http://example.com/path/to/script.py?var1=hellovar2=world script.py would live in /home/user/site-name/public_html/path/to/ Now try to use apache url rewrites to use nice urls (like, /section-name/sub-section-name/article-name instead of path/to/script-serving-articles.wtf?id=42). Good luck. Actually, currently in the example url http://example.com/path/to/script.py?var1=hellovar2=world the script is /home/user/site-name/public_html/path/ (with no filename extension) and the script.py is actually page.html which is an arbitrary, descriptive string and not part of the script filename. See the pages on http://dotancohen.com for examples. I would prefer to output everything from html to /html with print statements. I don't want some framework wrapping my output in tags, I want the tags to be part of the output. You're confusing the framework and the templating system. The framework by itself won't wrap your output in anything, nor even forces you to output HTML. This is what I was hoping to hear. I don't remember the details, but I had a hard time outputting the HTML myself in Django. I will play with it again soon if I get the chance. Also FWIW, it's HTTP, so we don't have outputs, we have HTTP responses. Clearly. I was referring to stdout being send to the browser as the http response. I think I mentioned that, but I apologize for being unclear. Yes, why not? Let's say I want to reuse your app with a different presentation. Do I have to fork the whole application and send my HTML coder dig into your applicative code just to rewrite the HTML parts ? No, just replace two files. In that manner it is templating. Again, an example from the current PHP code: ?php $variables_for_header=blah; include /path/to/header.inc; // content here include /path/to/footer.inc; ? Like I said before, I don't want to have to maintain the functions that turn the HTTP environment into Python variables, HTTP environment ??? Oh, you mean HTTP requests etc... Well, the cgi module already provides some basic support here. Does it? I will look into that. I assume that basic support means making the cookie, GET and POST variables easily accessible. I google, but cannot find any exapmles of this online. or the code that manages database connections. Functions that escape data to be sent to MySQL (to prevent sql injection) would be nice. Any DB-API compliant module already provide this - granted you use it correctly. I know. This is will use correctly, I promise! Other than that, it's all on me. Your choice... Hey! Since when am I not under attack? :) -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
While I know that to be true in the general sense, from what I've looked at Django and other frameworks it seems that the web frameworks push the coder to use templates, not letting him near the HTML. Well... there must be a reason, for sure... No ? ֹYes, but I don't like it. Why so ? What's your problem with templating systems, exactly ? They don't give me the control over the HTML that I would like. I'm probably stuck in 1998 when they didn't exist, but I like to write the HTML myself. Django and the other frameworks seem to force the user to use templates. Not at all. Nothing prevents you from shooting yourself in the foot and generating HTML by hand in your view functions (or request handler methods etc, depending on the framework). How is this done in Django, then? def index(request): unmaintanable_html = html head titleIndex/title /head body h1Embedded HTML is a PITA/h1 pbut some like pains.../p /body /html return HttpResponse(unmaintanable_html) And if I need to add a variable or three in there? Static HTML I can do without Python. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
I insist on handling the HTML myself. I just don't get how embedding HTML in applicative code - a well-known antipattern FWIW - relates to handling the HTML yourself. Can you *please* explain how a templating system prevents you from handling the HTML yourself. From the little that I played with Django, it looked like I would (for the sake of argument I am just using the term output, but the intention should be clear) output Hello, world! and Django would mangle that into htmlbodypHello, world!/p/body/html. It did not look like I had any control over the tags at all. And even if not, what you will do is ... code your own webframework. That is why I am looking for a class that handles the backend stuff, but lets _me_ handle the HTML. For God's sake : *why on earth do you believe that using a templating system will make you loose _any_ control on the HTML code ???* Because that's what I've seen of them. And at least pylons/TG2 lets you return whatever you want instead, as a string. Not via print though - which is simply only for CGI, and no other means (e.g. mod_wsgi) of python-web-programming. I am trying to follow you here. What is return whatever you want? Return HTML to stdout to be sent to the browser? please leave stdout out of here - it's HTTP, so what we have are HTTP requests and HTTP responses - not stdin nor stdout. Using these streams as a mean of communication between the web server and the applicative code is just plain old low-level GCI stuff. Your application code shouldn't have any knowledge of this implementation detail - it should receive (a suitable representation of) an HTTP request, and generate (a suitable representation of) an HTTP response. Can you provide a code example of printing the variable torvalds in the GET request? http://example.com/page.py?torvalds=tux Should return this: htmlbodyptux/p/body/html And something similar for a POST request? I hate to ask for code, but this conversation would be easier that way. Thanks. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
I insist on handling the HTML myself. As for converting the request variables into Python variables, if a class/framework makes that easier then I would gladly use it. My question was serious. How can I do those things? Using a framework? In Pylons/TG2, my code looks like this: def some_form_action(self, name, email, password): so HTTP-variables get parsed, validated, converted, and *then* passed to my actual code. I know how to call a function, but how do I use the variables? How do I respond (I am avoiding the term output) with the value of the GET variable torvalds, for example? And similarly for a POST variable? But then do you deal with headers correctly? Yes, so far as I know. This is actually simpler than the HTML, just be careful not to output two newline characters in sequence (thereby ending the header). Oh my god. If two newlines are all you think that there is to properly writing HTTP-headers, no wonder *you* wonder what to use a webframework for. I was being brief. I don't pretend to know the whole protocol by heart, but I get by that far. :) Do you respect character encodings? Yes! UTF-8 from database to scripting language to HTTP request. And if the browser sends them in different encoding? Frameworks make you deals with unicode only. Decoding/Encoding, setting the necessary That's what I wrote below: Form-encodings? Yes, UTF-8 the in the other direction. However, as form data can be spoofed, I would like a function that checks it. Does Python have such a function? What class does? Frameworks do check for HTTP-headers that contain the encoding, and thus convert incoming data to unicode. That is useful, thanks. Is your generated HTML valid? Naturally, even though this is not a Python issue. Naturally with print-statements? Carefully with print statements. Do you parse content negotiation headers? No. I hate sites that do that. If the page is available in another language, their is a link in the corner. Again, you don't seem to really know much about webapps. Content-negotiation isn't about languages, it's about content-types. Such as serving HTML or JSON from the same URL. But let me guess, you hate applications that do that? I used to serve WML-specific decks to known mobile UA's, but I've stopped. I don't have the *slightest* doubt about that. In fact, I'm pretty sure you can make pretty bad webapplications in pretty much everything you touch. Good luck with that. I am a mechanical engineering student, not CS. I am doing this for my own use and enjoyment. I don't need luck with that, I don't have any customers. If someone were to come along asking me to code for them, I would send them to you! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
*Why* on earth do you think using a templating system will give you any less control on the generated HTML ? Because I am wrong. I have already come to that conclusion. I know that Python is far enough developed that if I feel that I am fighting it, then _I_ am in the wrong, not Python. However, I still need to see that Python can do what I need in a comfortable fashion. And if I need to add a variable or three in there? - first solution : use string formatting python 2.x example: unmaintanable_html = html head title%(title)s/title /head body h1%(h1)s/h1 p%(text)s/p /body /html data = dict( title=index, h1=Poor man's templating, text=Won't get you very far... ) return HttpResponse(unmaintanable_html % data) That's fine for single variables, but if I need to output a table of unknown rows? I assume that return means the end of the script. Therefore I should shove the whole table into a variable and then copy that variable to the array data? - second solution: do basically the same thing with a template system - which will give you much more power and options... I will look further into the Django templates, I promise. But I would still like to know how to work with Python proper. Static HTML I can do without Python. Sorry, I forgot to setup a database etc for this example !-) I meant that I would like to see how to output variables, which you have shown. Thanks. I am stubborn, but I am willing to learn. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
It did not look like I had any control over the tags at all. I can tell you you have full control over the whole HTTP response's content and headers. And FWIW, this has nothing to do with templating systems. That's good to know. Actually, it's more that good: I am looking into Django again. Can you provide a code example of printing the variable torvalds in the GET request? http://example.com/page.py?torvalds=tux Should return this: htmlbodyptux/p/body/html And something similar for a POST request? Using which framework ? If it's about Turbogears, I don't use it so I can't answer. If it's using Pylons, you can use almost whatever templating system you want - or not use any. If it's with Django, do you want it with or without the templating system ? I'd love to see the non-templating Pylons example, and/or the Django example. Better yet, a link to example code or the appropriate chapter of TFM would be welcome. So far as I can tell, the fine manual does not cover non-template output. I hate to ask for code, but this conversation would be easier that way. Mmmm May I suggest that you first read the relevant documentation for the aforementionned frameworks ? Yes, please! Where in the Django docs is the relevant chapter? Ok, here's a Django example without a template: # views.py def index(request): torvalds = request.GET.get(torvalds, No torvalds here) return HttpResponse(htmlbody%s/body/html % torvalds) Allright, but what if I need to output in the middle of the page? Say, one row of a table that is neither the end nor beginning of the code? I ask because the construct return makes me believe that this is not good for this purpose. and here's an exemple using a template: # templates/index.html html body {{ torvalds }} /body /html # views.py def index(request): torvalds = request.GET.get(torvalds, No torvalds here) return render_to_response(index.html, dict(torvalds=torvalds)) Again, how could I output something in the middle of the page with the templates? -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
I've already given you that for TG: class RootController(BaseController): @expose() def page(self, torwalds=None): return htmlbodyp%s/p/body/html % (torwalds if torwalds else Does return mean that this could not be used in the middle of a page? Of course nobody would do it that way. Instead, you'd define a template html xmlns:py='http://genshi.edgewall.org/'bodyp${torvalds}/p/body/html And then your code becomes: @expose(your.template.path) def page(self, torwalds=None): return dict(torwalds=torwalds) Separation of code from HTML-code. Which most people agree is a good thing. And no worries about having to make torwalds a string. Yes, I like to separate HTML from code. However, often I need to output something in the middle of the page. How could I do that with a template? Now let's say you want torwalds to be not-empty, and a number: @expose(your.template.path) @validate(dict(torwalds=Int(not_empty=True)), error_handler=some_error_handler_controller_action) def page(self, torwalds=None): return dict(torwalds=torwalds) That is nice, I will read more about the error_handler functions. Thanks. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
Actually, currently in the example url http://example.com/path/to/script.py?var1=hellovar2=world the script is /home/user/site-name/public_html/path/ (with no filename extension) and the script.py is actually page.html which is an arbitrary, descriptive string and not part of the script filename. Better than the first example wrt/ SEO, but this still ties your url space to implementation AFAICT. Yes, but for the purposes of my needs this is fine and preferable. SEO was in fact the reason that I started doing this. Clearly. I was referring to stdout being send to the browser as the http response. s/browser/web server/ - it's the web server that reads your app's stdout and send it (as is or not FWIW) back to the client. As is, in my case. Actually, what use case is there for having Apache reprocess the HTML output of the script? And this output to stdout thingie is just the ipc scheme used for CGI - there are other possible interfaces between the application code and the web server. Other possible interfaces between the application code and the web server? Maybe you are referring to the interface with the database server? Enlighten me, please! I am not a programmer by trade, only by hobby. I think I mentioned that, but I apologize for being unclear. It's not that it was unclear, but that it's innaccurate. outputting to stdout is an implementation detail, and should not be exposed at the applicative code level. Dealing with appropriate abstraction - here, an HttpResponse object - is far better (well, IMHO of course... - standard disclaimers, YMMV etc). I see. I believe that is called Dotan's Razor: a slight inaccuracy saves a lengthy explanation. Sorry, but all I can replace here are the header and footer - if I want to generate a different markup for the content here part, I have to modify your applicative code. I've written web apps that way myself (some 7 years ago), and still have to maintain some web apps written that way, you know... Quite so, I though that is what you wanted. Yes, the HTML is hard-coded into the script. I am learning to abstract and even use object-oriented approaches, though. Does it? I will look into that. I assume that basic support means making the cookie, GET and POST variables easily accessible. GET and POST at least - I don't exactly remember how it works for cookies. That much I should be able to google when I get to it. I google, but cannot find any exapmles of this online. Well, no one in it's own mind would still use CGI (except perhaps for very trivial stuff) when you have way better solutions. What I am doing _is_ trivial. However, I thank you for explaining my options and I will take a second look at them. Hey! Since when am I not under attack? :) Mmm... yes, I tend to be a bit offensive sometimes - please don't take it personnaly and forgive me for my lack of social skills. What I express are of course _my_ opinions (most of them based on experience but that's not the point), and I've never killed anyone for having a different POV - even if I'm pretty sure they are wrong !-) Be offensive! I take no offence, I understand that your goal is to help me. I am a hard learner: I recognize that you are teaching me the better way, but I need convincing as to why it is better. Bruno said so is good, but saves you coding time down the line is a lot more convincing! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
What do you mean by in the middle of the page? Do you mean, for instance, the behavior of middle.php in the following PHP example: ?php include_once(beginning.inc.php); include_once(middle.php); include_once(end.inc.php); ? Is that what you are after? Yes, that is what I am after. For instance, if one were to look at the source code of http://dotancohen.com they would see !-- / HEADER --. All the HTML up to that point was output by bigginin.inc.php. Similarly, near the end exists div class=bottomfiller, all the code from there is generated by end.inc.php. These two files are included in every page of the site. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is python so sad?
Maybe we should change it to def ...(...(: ... class ...(...(: I disagree. It looks like one smiley is drooling into the other smiley's mouth. Two smileys, one function? Yuk! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Web development with Python 3.1
Why the push to use a framework, and why the resistance from the OP? Does the OP need to work with cookies or other http-specific features? In fact, other than cookies, what http-specific features exist? Does Python have a built-in framework for making available GET and POST variables? Database queries should be no different than in other Python apps. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list