Re: unicode by default

2011-05-11 Thread harrismh777
Terry Reedy wrote: It does not matter how Python stored the unicode internally. Does this help? Your intent is signalled by how you open the file. Very much, actually, thanks. I was missing the 'internal' piece, and did not realize that if I didn't specify the encoding on the open that pytho

Re: unicode by default

2011-05-11 Thread harrismh777
Ben Finney wrote: I'd phrase that as: * Text is a sequence of characters. Most inputs to the program, including files, sockets, etc., contain a sequence of bytes. * Always know whether you're dealing with text or with bytes. No object can be both. * In Python 2, ‘str’ is the type f

Need Assistance on this program.

2011-05-11 Thread vijay swaminathan
Hi All, I'm new bie to python thread programming and would like to assistance on the attached code. In this, I'm calling a thread to invoke a command prompt and would like to print the "Thread as alive" as long as the command prompt is opened and would like to print "Thread is Dead" only when the

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 20:31:45 -0700 (PDT), alex23 wrote: : On May 12, 7:24 am, harrismh777 wrote: : > We need to move away from 'canned apps' to a new day where : > the masses can sit down to their computer and solve new problems with it : > through intuitive language skills.  Why not? : : Be

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 11 May 2011 21:42:10 GMT, Steven D'Aprano wrote: : *Potentially* different tests. Which is exactly the point. Given an : arbitrary object, the developer doesn't know what test is appropriate. : Should I write len(x) == 0 or list(x) == [] or x.next is None or : something else? How can I

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Thu, 12 May 2011 01:49:05 -0400, D'Arcy J.M. Cain wrote: : That's not programming. That's using a canned app that a programmer : wrote that takes your unstructured input and does something useful with : it. Spreadsheets are a primitive example of that. Google is a more : advanced examp

Re: unicode by default

2011-05-11 Thread harrismh777
John Machin wrote: On Thu, May 12, 2011 2:14 pm, Benjamin Kaplan wrote: If the file you're writing to doesn't specify an encoding, Python will default to locale.getdefaultencoding(), No such attribute. Perhaps you mean locale.getpreferredencoding() >>> import locale >>> locale.getpreferred

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 22:53:45 -0500, harrismh777 wrote: > alex23 wrote: >>> through intuitive language skills. Why not? >> Because the vast majority of them don't seem to want to be bothered? >> >> > That could very well be... but I have a hope for them. I honestly think > its not because they don

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Thu, 12 May 2011 17:44:07 +1200, Gregory Ewing wrote: : Roy Smith wrote: : > Hans Georg Schaathun wrote: : >>If both are numbers, they are converted to a common type. Otherwise, : >>objects of different types always compare unequal Actually, I did not. :-- hg -- http://mail.python.org/ma

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 20:16:01 -0700 (PDT), alex23 wrote: : Hans Georg Schaathun wrote: : > Revolutionary indeed, so why don't we exploit the revolution : > and write the programs to be as accessible as possible? : : Where do you draw the line, though? I said that, "as possible". You draw it

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 11 May 2011 21:47:27 GMT, Steven D'Aprano wrote: : On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote: : > One principle of object oriented programming is to bestow the objects : > with properties reflecting known properties from the domain being : > modelled. Lists do not have

Re: checking if a list is empty

2011-05-11 Thread D'Arcy J.M. Cain
On Wed, 11 May 2011 16:24:47 -0500 harrismh777 wrote: > D'Arcy J.M. Cain wrote: > Non-programmers should not be expected to program in 'C' nor in lisp... > > ... but non-programmers were able to program in BASIC jes fine... They still had to learn the language. > I contend that non-prog

Re: checking if a list is empty

2011-05-11 Thread Gregory Ewing
Roy Smith wrote: Hans Georg Schaathun wrote: If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal That's just the default treatment for unrelated types that don't know anything about each other. I would guess that the list's =

Re: NewBie Doubt in Python Thread Programming

2011-05-11 Thread vijay swaminathan
I tried using QThread as well.. But the problem is, on the run method when i invoke the command prompt, it sends out the finished signal... I want it to send out the finished signal only on closing the command prompt that is invoked earlier in my process. guess some logic to be implement inside r

Re: unicode by default

2011-05-11 Thread John Machin
On Thu, May 12, 2011 2:14 pm, Benjamin Kaplan wrote: > > If the file you're writing to doesn't specify an encoding, Python will > default to locale.getdefaultencoding(), No such attribute. Perhaps you mean locale.getpreferredencoding() -- http://mail.python.org/mailman/listinfo/python-list

Re: unicode by default

2011-05-11 Thread Benjamin Kaplan
On Wed, May 11, 2011 at 8:44 PM, harrismh777 wrote: > Steven D'Aprano wrote: >>> >>> You need to understand the difference between characters and bytes. >> >> http://www.joelonsoftware.com/articles/Unicode.html >> >> is also a good resource. > > Thanks for being patient guys, here's what I've done

Re: unicode by default

2011-05-11 Thread John Machin
On Thu, May 12, 2011 1:44 pm, harrismh777 wrote: > By > default it looks like Python3 is writing output with UTF-8 as default... > and I thought that by default Python3 was using either UTF-16 or UTF-32. > So, I'm confused here... also, I used the character sequence \u00A3 > which I thought was UT

Re: unicode by default

2011-05-11 Thread Terry Reedy
On 5/11/2011 11:44 PM, harrismh777 wrote: Steven D'Aprano wrote: You need to understand the difference between characters and bytes. http://www.joelonsoftware.com/articles/Unicode.html is also a good resource. Thanks for being patient guys, here's what I've done: astr="pound sign" asym="

Re: unicode by default

2011-05-11 Thread Ben Finney
MRAB writes: > You need to understand the difference between characters and bytes. Yep. Those who don't need to join us in the third millennium, and the resources pointed out in this thread are good to help that. > A string contains characters, a file contains bytes. That's not true for Python

Re: lightweight way to create new projects from templates

2011-05-11 Thread Chris Angelico
On Thu, May 12, 2011 at 4:34 AM, Jonathan Hartley wrote: > Hi. > > I'm looking for a quick way to create new Python projects from a template. > > I understand that 'Paste' (http://pythonpaste.org/) is one way to do this, > but I find Paste very intimidating because of all the functionality it > in

Re: checking if a list is empty

2011-05-11 Thread harrismh777
alex23 wrote: through intuitive language skills. Why not? Because the vast majority of them don't seem to want to be bothered? That could very well be... but I have a hope for them. I honestly think its not because they don't want to be bothered, rather they just think its too far past the

Re: unicode by default

2011-05-11 Thread John Machin
On Thu, May 12, 2011 11:22 am, harrismh777 wrote: > John Machin wrote: >> (1) You cannot work without using bytes sequences. Files are byte >> sequences. Web communication is in bytes. You need to (know / assume / >> be >> able to extract / guess) the input encoding. You need to encode your >> outp

Re: checking if a list is empty

2011-05-11 Thread Chris Angelico
On Thu, May 12, 2011 at 7:02 AM, Ian wrote: > In the "real world"  lists of zero items do not exist. > You don't go shopping with a shopping list of zero items. Actually, yes you do. You maintain your shopping list between trips; whenever you need something, you put it on the list immediately. Th

Re: checking if a list is empty

2011-05-11 Thread Chris Torek
In article <4dc6a39a$0$29991$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano wrote: >In English, [the word "not"] negates a word or statement: > >"the cat is not on the mat" --> "the cat is on the mat" is false. As a mostly off topic aside, English is considerably more complicated than that.

Re: unicode by default

2011-05-11 Thread harrismh777
Steven D'Aprano wrote: You need to understand the difference between characters and bytes. http://www.joelonsoftware.com/articles/Unicode.html is also a good resource. Thanks for being patient guys, here's what I've done: astr="pound sign" asym=" \u00A3" afile=open("myfile", mode='w') afil

Learning new languages (was: checking if a list is empty)

2011-05-11 Thread Teemu Likonen
* 2011-05-11T20:26:48+01:00 * Hans Georg Schaathun wrote: > On Wed, 11 May 2011 14:44:37 -0400, Prasad, Ramit >wrote: >> I claim to be able to program (Java/Python), but would be absolutely >> lost programming in Lisp. It is more than just "learning the syntax", >> it includes a thought paradi

Re: checking if a list is empty

2011-05-11 Thread alex23
On May 12, 7:24 am, harrismh777 wrote: > We need to move away from 'canned apps' to a new day where > the masses can sit down to their computer and solve new problems with it > through intuitive language skills.  Why not? Because the vast majority of them don't seem to want to be bothered? -- h

Re: checking if a list is empty

2011-05-11 Thread alex23
Hans Georg Schaathun wrote: > Revolutionary indeed, so why don't we exploit the revolution > and write the programs to be as accessible as possible? Where do you draw the line, though? No decorators, as they're not intuitively obvious? No custom descriptors, as that requires a deeper knowledge o

Re: unicode by default

2011-05-11 Thread Steven D'Aprano
On Thu, 12 May 2011 03:31:18 +0100, MRAB wrote: >> Another question... in mail I'm receiving many small blocks that look >> like sprites with four small hex codes, scattered about the mail... >> mostly punctuation, maybe? ... guessing, are these unicode code points, >> and if so what is the best w

Re: unicode by default

2011-05-11 Thread MRAB
On 12/05/2011 02:22, harrismh777 wrote: John Machin wrote: (1) You cannot work without using bytes sequences. Files are byte sequences. Web communication is in bytes. You need to (know / assume / be able to extract / guess) the input encoding. You need to encode your output using an encoding tha

Re: unicode by default

2011-05-11 Thread harrismh777
John Machin wrote: (1) You cannot work without using bytes sequences. Files are byte sequences. Web communication is in bytes. You need to (know / assume / be able to extract / guess) the input encoding. You need to encode your output using an encoding that is expected by the consumer (or use an

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 17:38:58 -0500, harrismh777 wrote: > Steven D'Aprano wrote: >>> modelled. Lists do not have truth values in the application domain >> Yes they do. Empty lists are nothing, ergo false, and non-empty lists >> are something, ergo true. >> >> > No they don't. Empty lists are empt

pymultimouse access violation error

2011-05-11 Thread jpiee
A couple of years back Oscar Lindberg wrote a program called pymultimouse, which has a homepage at http://code.google.com/p/pymultimouse/. I've been using the file rawinputreader.py, which is avaliable in the zipped folder in the downloads section of the above link. I'm trying to get raw mou

Re: urllib2 request with binary file as payload

2011-05-11 Thread John Machin
On Thu, May 12, 2011 10:20 am, Michiel Sikma wrote: > Hi there, > I made a small script implementing a part of Youtube's API that allows > you to upload videos. It's pretty straightforward and uses urllib2. > The script was written for Python 2.6, but the server I'm going to use > it on only has 2.

urllib2 request with binary file as payload

2011-05-11 Thread Michiel Sikma
Hi there, I made a small script implementing a part of Youtube's API that allows you to upload videos. It's pretty straightforward and uses urllib2. The script was written for Python 2.6, but the server I'm going to use it on only has 2.5 (and I can't update it right now, unfortunately). It seems t

Re: unicode by default

2011-05-11 Thread John Machin
On Thu, May 12, 2011 8:51 am, harrismh777 wrote: > Is it true that if I am > working without using bytes sequences that I will not need to care about > the encoding anyway, unless of course I need to specify a unicode code > point? Quite the contrary. (1) You cannot work without using bytes seque

Re: checking if a list is empty

2011-05-11 Thread harrismh777
harrismh777 wrote: Lists by themselves, empty or not, cannot have a 'truth' in an of themselves. ... forgot., Based on Ian's comment a couple of days ago... if alist: ... is actually : if bool(alist): I think this is more than just semantics or silly argumentation.

Re: checking if a list is empty

2011-05-11 Thread Gregory Ewing
Hans Georg Schaathun wrote: 0 is a number as real and existent as any other, one would think that the empty list is also as real and existent as any other list. 0 does have some special properties, though, such as being the additive identity and not having a multiplicative inverse. Adding fals

Re: unicode by default

2011-05-11 Thread harrismh777
Ian Kelly wrote: Ian, Benjamin, thanks much. The `unicode' class was renamed to `str', and a stripped-down version of the 2.X `str' class was renamed to `bytes'. ... thank you, this is very helpful. > If I do not specify any code points above ascii 0xFF does any of this > matter

Re: Merge multiple source directories into one package with distutils?

2011-05-11 Thread Gregory Ewing
Miki Tebeka wrote: .py files from more than one source directory into a single package when installing? The Selenium Python bindings does something like that, have a look at http://selenium.googlecode.com/svn/trunk/setup.py Unless I'm missing something, nothing out of the ordinary is happenin

Re: checking if a list is empty

2011-05-11 Thread harrismh777
Steven D'Aprano wrote: modelled. Lists do not have truth values in the application domain Yes they do. Empty lists are nothing, ergo false, and non-empty lists are something, ergo true. No they don't. Empty lists are empty lists... which just happen to become False when type cast bool(lis

Re: unicode by default

2011-05-11 Thread Benjamin Kaplan
On Wed, May 11, 2011 at 2:37 PM, harrismh777 wrote: > hi folks, >   I am puzzled by unicode generally, and within the context of python > specifically. For one thing, what do we mean that unicode is used in python > 3.x by default. (I know what default means, I mean, what changed?) > >   I think p

Re: py3k buffered IO - flush() required between read/write?

2011-05-11 Thread Martin P. Hellwig
On 11/05/2011 19:08, Genstein wrote: On 11/05/2011 19:24, Terry Reedy wrote: writing and reading. If you want others to look at this more, you should 1) produce a minimal* example that demonstrates the questionable behavior, and 2) show the comparative outputs that raise your question. Thanks

Re: Recursion or iteration (was Fibonacci series recursion error)

2011-05-11 Thread Hans Mulder
On 03/05/2011 09:52, rusi wrote: [If you believe it is, then try writing a log(n) fib iteratively :D ] It took me a while, but this one seems to work: from collections import namedtuple Triple = namedtuple('Triple', 'hi mid lo') Triple.__mul__ = lambda self, other: Triple( self.hi * othe

Re: unicode by default

2011-05-11 Thread Ian Kelly
On Wed, May 11, 2011 at 3:37 PM, harrismh777 wrote: > hi folks, >   I am puzzled by unicode generally, and within the context of python > specifically. For one thing, what do we mean that unicode is used in python > 3.x by default. (I know what default means, I mean, what changed?) The `unicode'

Re: checking if a list is empty

2011-05-11 Thread Steven Howe
On 05/11/2011 02:47 PM, Steven D'Aprano wrote: On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote: One principle of object oriented programming is to bestow the objects with properties reflecting known properties from the domain being modelled. Lists do not have truth values in the

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 20:13:35 +0100, Hans Georg Schaathun wrote: > One principle of object oriented programming is to bestow the objects > with properties reflecting known properties from the domain being > modelled. Lists do not have truth values in the application domain Yes they do. Empty list

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 19:05:03 +, Chris Torek wrote: > In article <4dcab8bf$0$29980$c3e8da3$54964...@news.astraweb.com> Steven > D'Aprano wrote: >>When you call len(x) you don't care about the details of how to >>calculate the length of x. The object itself knows so that you don't >>have to. T

unicode by default

2011-05-11 Thread harrismh777
hi folks, I am puzzled by unicode generally, and within the context of python specifically. For one thing, what do we mean that unicode is used in python 3.x by default. (I know what default means, I mean, what changed?) I think part of my problem is that I'm spoiled (American, ascii he

Re: py3k buffered IO - flush() required between read/write?

2011-05-11 Thread Terry Reedy
On 5/11/2011 3:08 PM, Genstein wrote: On 11/05/2011 19:24, Terry Reedy wrote: writing and reading. If you want others to look at this more, you should 1) produce a minimal* example that demonstrates the questionable behavior, and 2) show the comparative outputs that raise your question. Thanks

Re: checking if a list is empty

2011-05-11 Thread harrismh777
D'Arcy J.M. Cain wrote: Non-programmers should be able to program? Should non-doctors be able to doctor? Should cars be built so that anyone can intuitively fix them without a mechanic? Non-programmers should not be expected to program in 'C' nor in lisp... ... but non-programmers were

Re: checking if a list is empty

2011-05-11 Thread harrismh777
Hans Georg Schaathun wrote: Code is quite often published to document algorithms, methods and formulæ for the purpose of scientific research. Since there is no universal language which suits everything and everyone, this is exactly what happens. One has to have the rudimentary knowledge to read

Re: How to deal with optional argument evaluation

2011-05-11 Thread Ethan Furman
Rodrick Brown wrote: I'm having a hard time dealing with the following scenario My class takes a hash like the following: rdargs = {'env:'prod','feed':'opra','hostname':'host13dkp1','process':'delta','side':'a','zone','ny'} All the keys in this hash can be optional. I'm having a hard time

Re: checking if a list is empty

2011-05-11 Thread Ian
On 11/05/2011 20:13, Hans Georg Schaathun wrote: On Wed, 11 May 2011 12:17:33 -0700, Ethan Furman wrote: : 'if li' *is* KISS. It /might/ be in some contexts, but a priori it is not, as it superimposes a truth value on a data type which is otherwise a pretty accurate model of real objects (

How to deal with optional argument evaluation

2011-05-11 Thread Rodrick Brown
I'm having a hard time dealing with the following scenario My class takes a hash like the following: rdargs = {'env:'prod','feed':'opra','hostname':'host13dkp1','process':'delta','side':'a','zone','ny'} All the keys in this hash can be optional. I'm having a hard time dealing with all 36 possibl

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 14:44:37 -0400, Prasad, Ramit wrote: : > Someone who knows how to program is never clueless starting a new : >language. Newbie, may be, but he knows most of the constructions : >and semantic principles to look for; most of it is learning the syntax. : : I claim to be able

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 12:17:33 -0700, Ethan Furman wrote: : 'if li' *is* KISS. It /might/ be in some contexts, but a priori it is not, as it superimposes a truth value on a data type which is otherwise a pretty accurate model of real objects (outside python). One principle of object oriented pr

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 14:59:34 -0400, Prasad, Ramit wrote: : Fair enough. I am a sheep, so I do what other (more knowledgeable) : people do. It is a fair assumption (for my specific code writing : environments) that everyone who is going to read my code understands : "if x:" notation or is expe

RE: Proper way to handle errors in a module

2011-05-11 Thread Prasad, Ramit
The simple but code heavy system is to create two functions. One that raises an error and one that returns None or something that is mutually agreed to be invalid. You can even get away with one of them doing the actual work and the other one just as a wrapper. I feel too lazy to fix the mistak

RE: checking if a list is empty

2011-05-11 Thread Prasad, Ramit
> Someone who knows how to program is never clueless starting a new >language. Newbie, may be, but he knows most of the constructions >and semantic principles to look for; most of it is learning the syntax. I claim to be able to program (Java/Python), but would be absolutely lost programming in

Re: py3k buffered IO - flush() required between read/write?

2011-05-11 Thread Genstein
On 11/05/2011 19:24, Terry Reedy wrote: writing and reading. If you want others to look at this more, you should 1) produce a minimal* example that demonstrates the questionable behavior, and 2) show the comparative outputs that raise your question. Thanks for a quick response. Perhaps I was be

Re: checking if a list is empty

2011-05-11 Thread Chris Torek
In article <4dcab8bf$0$29980$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano wrote: >When you call len(x) you don't care about the details of how to calculate >the length of x. The object itself knows so that you don't have to. The >same applies to truth testing. > >I have a data type that

Re: checking if a list is empty

2011-05-11 Thread Ethan Furman
Hans Georg Schaathun wrote: On Wed, 11 May 2011 13:50:54 -0400, Prasad, Ramit wrote: : I find this argument to be flawed. Should I stop using built-in : generators instead of range/xrange for looping through lists? : Certainly for loops with loop counting are understood more widely : than g

RE: checking if a list is empty

2011-05-11 Thread Prasad, Ramit
>Common to what? I'd try the lowest common denominator of >legibility and effictiveness. >It is just KISS. Fair enough. I am a sheep, so I do what other (more knowledgeable) people do. It is a fair assumption (for my specific code writing environments) that everyone who is going to read my code

lightweight way to create new projects from templates

2011-05-11 Thread Jonathan Hartley
Hi. I'm looking for a quick way to create new Python projects from a template. I understand that 'Paste' (http://pythonpaste.org/) is one way to do this, but I find Paste very intimidating because of all the functionality it includes. I'm not even sure whether 'creating new projects from temp

Re: py3k buffered IO - flush() required between read/write?

2011-05-11 Thread Terry Reedy
On 5/11/2011 12:27 PM, Genstein wrote: In py3k is it necessary to flush() a file between read/write calls in order to see consistent results? I ask because I have a case under Python 3.2 (r32:88445) where it does appear to be, on both Gentoo Linux and Windows Vista. I've naturally read http://

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 13:50:54 -0400, Prasad, Ramit wrote: : I find this argument to be flawed. Should I stop using built-in : generators instead of range/xrange for looping through lists? : Certainly for loops with loop counting are understood more widely : than generators. Should I stop using

Re: Proper way to handle errors in a module

2011-05-11 Thread Andrew Berg
On 2011.05.11 12:57 PM, Patty wrote: > Hi Andrew - > > Sometimes you want an exception come up and then use that information to > take your > program in some direction. Right, but I'm wondering how I should handle errors in a module, where different people will want their programs to do different

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 10:31:59 -0600, Ian Kelly wrote: : (x + 3 for x in xs if x % 2 == 1) Interesting. Thanks. That might come in handy some time. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 10:27:49 -0400, D'Arcy J.M. Cain wrote: : When did we come to the idea that people should be able to program in a : language without actually learning it? The fact that Python comes so : close to that possibility is nothing short of revolutionary. Revolutionary indeed, s

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Thu, 12 May 2011 02:05:21 +1000, Chris Angelico wrote: : In a Bourne shell script, if ends with fi... case ends with esac... so : file would end with... hmm. Yeah, I think it's best to know the : language you're trying to comprehend, and/or actually look at context : instead of shoving a

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 11 May 2011 16:26:40 GMT, Steven D'Aprano wrote: : > 1. My concern was not about clueless newbies. They need to : > learn. My concern is about experienced scientists and engineers who : > are simply new to python. : : Which makes them clueless newbies *about Python*. I don't care how

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On Wed, 11 May 2011 10:33:51 -0400, D'Arcy J.M. Cain wrote: : Non-programmers should be able to program? That was not really what I suggested; I was primarily talking about reading programs and commenting on formulæ and algorithms. : Should non-doctors be able to doctor? If I were God, I mi

Re: Proper way to handle errors in a module

2011-05-11 Thread Roy Smith
In article , Andrew Berg wrote: > I'm a bit new to programming outside of shell scripts (and I'm no expert > there), so I was wondering what is considered the best way to handle > errors when writing a module. Do I just let exceptions go and raise > custom exceptions for errors that don't trigge

Re: Proper way to handle errors in a module

2011-05-11 Thread MRAB
On 11/05/2011 18:29, Andrew Berg wrote: I'm a bit new to programming outside of shell scripts (and I'm no expert there), so I was wondering what is considered the best way to handle errors when writing a module. Do I just let exceptions go and raise custom exceptions for errors that don't trigger

Re: Proper way to handle errors in a module

2011-05-11 Thread Patty
- Original Message - From: "Andrew Berg" To: Sent: Wednesday, May 11, 2011 10:29 AM Subject: Proper way to handle errors in a module I'm a bit new to programming outside of shell scripts (and I'm no expert there), so I was wondering what is considered the best way to handle errors

Re: Py3k,email header handling

2011-05-11 Thread Terry Reedy
On 5/11/2011 12:27 PM, TheSaint wrote: Steven D'Aprano wrote: Before you re-write it, you should run 2to3 over it and see how much it can do automatically: Widely done, only the results from some query has radically changed on favour of unicode. Errors raising about results which are not stri

RE: checking if a list is empty

2011-05-11 Thread Prasad, Ramit
>The audience I am concerned about is the ones who are over-educated >into using and having used a score of different meanings of the same >symbols. They will be used to their intuition being wrong when they >move into a new context. Being explicit will help them. I find this argument to be fla

RE: checking if a list is empty

2011-05-11 Thread Prasad, Ramit
> I don't mean to insult anyone, but I've heard and read all the arguments > against Python's truth-testing, and they >don't impress me in the slightest. Most of them strike me as silly. The only >argument that carries any weight to me is >one which I haven't seen anyone raise: >"if x:" turns so

Proper way to handle errors in a module

2011-05-11 Thread Andrew Berg
I'm a bit new to programming outside of shell scripts (and I'm no expert there), so I was wondering what is considered the best way to handle errors when writing a module. Do I just let exceptions go and raise custom exceptions for errors that don't trigger a standard one? Have the function/method

Re: checking if a list is empty

2011-05-11 Thread Eric Snow
All of this just boils down to Python providing an implicit bool cast in syntactic situations that expect conditional expressions, including if [1]. So "if x:" is equivalent to "if bool(x)". Perhaps that is the part that is not immediately obvious, being implicit to Python conditional syntax. Py

Re: checking if a list is empty

2011-05-11 Thread Ian Kelly
On Wed, May 11, 2011 at 8:34 AM, Hans Georg Schaathun wrote: > E.g. Anyone who has used list/set comprehension in Z, haskell, set theory, > or whereever will understand python list comprehension immediately. They would understand the underlying concept. But would somebody who is not a Python pr

py3k buffered IO - flush() required between read/write?

2011-05-11 Thread Genstein
Hey all, Apologies if this is a dumb question (self = Python noob), but under py3k is it necessary to flush() a file between read/write calls in order to see consistent results? I ask because I have a case under Python 3.2 (r32:88445) where it does appear to be, on both Gentoo Linux and Wind

Re: Py3k,email header handling

2011-05-11 Thread TheSaint
Steven D'Aprano wrote: > Before you re-write it, you should run 2to3 over it and see how much it > can do automatically: Widely done, only the results from some query has radically changed on favour of unicode. Errors raising about results which are not strings anymore. > I'm afraid I don't u

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 15:34:28 +0100, Hans Georg Schaathun wrote: > On 11 May 2011 13:45:52 GMT, Steven D'Aprano >wrote: > : Do you think that we should avoid chained comparisons, class methods, > : closures, co-routines, decorators, default values to functions, : > delegation, doc tests, exc

Re: checking if a list is empty

2011-05-11 Thread Chris Angelico
On Thu, May 12, 2011 at 1:50 AM, Steven D'Aprano wrote: > On Wed, 11 May 2011 15:05:45 +0100, Hans Georg Schaathun wrote: > >> My concern was with the reader and not the writer. >> >> What could elif mean other than else: if? > > The first time I read Python code, I had literally no idea what to m

Re: NewBie Doubt in Python Thread Programming

2011-05-11 Thread Wojtek Mamrak
2011/5/11 Chris Angelico : > On Thu, May 12, 2011 at 1:16 AM, Wojtek Mamrak wrote: >> Is there any special reason you don't want to use QThread? >> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details > > Other than that QThread is part of QT and threading isn't, what ar

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 15:05:45 +0100, Hans Georg Schaathun wrote: > My concern was with the reader and not the writer. > > What could elif mean other than else: if? It could mean "Oh, the author has made a stupid typo, I better fix it." It could mean "What does the elif command do?" The first ti

Re: checking if a list is empty

2011-05-11 Thread Ethan Furman
Hans Georg Schaathun wrote: On 11 May 2011 13:36:02 GMT, Steven D'Aprano wrote: : > In this case, the interpretation of an arbitrary object as a boolean is : > peculiar for python. : : Incorrect. It is widespread among many languages. Programmers have been : writing conditional tests usi

Re: checking if a list is empty

2011-05-11 Thread Redcat
On Wed, 11 May 2011 10:33:51 -0400, D'Arcy J.M. Cain wrote: > Non-programmers should be able to program? Wasn't that sort of the premise behind Visual Basic? I don't know if that was the intention, but it sure was the result in a lot of cases. -- http://mail.python.org/mailman/listinfo/python-l

Re: NewBie Doubt in Python Thread Programming

2011-05-11 Thread Chris Angelico
On Thu, May 12, 2011 at 1:16 AM, Wojtek Mamrak wrote: > Is there any special reason you don't want to use QThread? > http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details Other than that QThread is part of QT and threading isn't, what are the advantages of QThread? Is it

Re: NewBie Doubt in Python Thread Programming

2011-05-11 Thread Wojtek Mamrak
Is there any special reason you don't want to use QThread? http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qthread.html#details regards 2011/5/11 Chris Angelico : > On Wed, May 11, 2011 at 7:08 PM, vijay swaminathan wrote: >> Sorry. My intention was not to send out a private message.

Re: checking if a list is empty

2011-05-11 Thread Chris Angelico
On Thu, May 12, 2011 at 12:00 AM, Hans Georg Schaathun wrote: > The fact that you need to list language by language which objects > evaluate as false or equivalent to false illustrates that this has > to be learnt language by language. Allowing arbitrary objects is > one thing, the particular in

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 11 May 2011 13:45:52 GMT, Steven D'Aprano wrote: : Do you think that we should avoid chained comparisons, class methods, : closures, co-routines, decorators, default values to functions, : delegation, doc tests, exceptions, factory functions, generator : expressions, inheritance, itera

Re: checking if a list is empty

2011-05-11 Thread D'Arcy J.M. Cain
On Wed, 11 May 2011 15:05:45 +0100 Hans Georg Schaathun wrote: > What could elif mean other than else: if? If run by an elf? Who knows. You do, of course, if you have learned the basics of the language you are using. > if x could, for instance, mean "if x is defined". It could also mean "if

Re: checking if a list is empty

2011-05-11 Thread D'Arcy J.M. Cain
On Wed, 11 May 2011 11:47:42 +0100 Hans Georg Schaathun wrote: > However, programming is often as much about developing ideas in a large > and complex community, where perfect universal mastery of one language > is not an option, because half the community do not normally use that > language or ar

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 11 May 2011 12:14:46 GMT, Steven D'Aprano wrote: : Not knowing that you can write "if x" instead of "if x == []" is like not : knowing that you can write : : elif condition : : instead of : : else: : if condition My concern was with the reader and not the writer.

Re: checking if a list is empty

2011-05-11 Thread Hans Georg Schaathun
On 11 May 2011 13:36:02 GMT, Steven D'Aprano wrote: : > In this case, the interpretation of an arbitrary object as a boolean is : > peculiar for python. : : Incorrect. It is widespread among many languages. Programmers have been : writing conditional tests using arbitrary values since 1958

Re: checking if a list is empty

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 11:47:42 +0100, Hans Georg Schaathun wrote: > On Sat, 07 May 2011 21:57:13 -0700, Ethan Furman >wrote: > : If you're going to use a language, and use it well, you have to learn > : how that language works. > > And if the world evolves around the compiler and you, that ad

Re: Py3k,email header handling

2011-05-11 Thread Steven D'Aprano
On Wed, 11 May 2011 16:04:13 +0800, TheSaint wrote: > Now python 3.2 (and some version before) started to use byte, rather > than text strings, almost for all data handling in compliance to > unicode. My problem arise that my program handle text strings, so I'd > like to rewrite the code Before y

  1   2   >