Re: Simple program question.

2013-06-10 Thread eschneider92
No. -- http://mail.python.org/mailman/listinfo/python-list

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Jonas Geiregat
On 11 Jun 2013, at 01:08, Fábio Santos wrote: > > On 10 Jun 2013 23:54, "Roel Schroeven" wrote: > > > > You could do something like: > > > > new_songs, old_songs = [], [] > > [(new_songs if s.is_new() else old_songs).append(s) for s in songs] > > > > But I'm not sure that that's any better than

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Peter Otten
Fábio Santos wrote: > On 10 Jun 2013 23:54, "Roel Schroeven" wrote: >> >> You could do something like: >> >> new_songs, old_songs = [], [] >> [(new_songs if s.is_new() else old_songs).append(s) for s in songs] >> >> But I'm not sure that that's any better than the long version. > > This is so be

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Terry Jan Reedy
On 6/10/2013 10:56 PM, Steven D'Aprano wrote: I was initially confused and reading the code still takes a small bit of extra mental energy. Idle stays confused and will wrongly color the list instance name until it is changed. Calling the file list 'fnames' or 'filenames' would have been clearer

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Steven D'Aprano
On Mon, 10 Jun 2013 20:30:41 -0700, rusi wrote: >> Certainly it would be a PITA, and defeat the purpose of having nested >> scopes, if inner names had to be globally unique. Wouldn't it be >> absolutely horrible if adding a global variable "foo"[1] suddenly meant >> that all your functions that us

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Roy Smith
In article , Roel Schroeven wrote: > new_songs, old_songs = [], [] > [(new_songs if s.is_new() else old_songs).append(s) for s in songs] Thanks kind of neat, thanks. I'm trying to figure out what list gets created and discarded. I think it's [None] * len(songs). -- http://mail.python.org/ma

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Chris Angelico
On Tue, Jun 11, 2013 at 1:02 PM, Steven D'Aprano wrote: > Apart from Erlang, got any other examples? Because it seems to me that in > languages with nested scopes or namespaces, shadowing higher levels is > exactly the right thing to do. Certainly it would be a PITA, and defeat > the purpose of ha

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Jason Swails
On Mon, Jun 10, 2013 at 7:26 PM, Dave Angel wrote: > On 06/10/2013 06:54 PM, Chris Angelico wrote: > >> On Tue, Jun 11, 2013 at 8:39 AM, Grant Edwards >> wrote: >> >>> On 2013-06-10, Terry Jan Reedy wrote: >>> >>> Another principle similar to 'Don't add extraneous code' is 'Don't rebind b

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread rusi
On Jun 11, 8:02 am, Steven D'Aprano wrote: > On Mon, 10 Jun 2013 19:36:44 -0700, rusi wrote: > > Pascal introduced the idea of block structure -- introduce a name at one > > level, override it at a lower level. [Ok ALgol introduced, Pascal > > popularized]. > > This has caused more trouble than it

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Steven D'Aprano
On Mon, 10 Jun 2013 19:36:44 -0700, rusi wrote: > Pascal introduced the idea of block structure -- introduce a name at one > level, override it at a lower level. [Ok ALgol introduced, Pascal > popularized]. > This has caused more trouble than it has solved. I take it you have never programmed in

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Steven D'Aprano
On Mon, 10 Jun 2013 20:14:55 -0400, Terry Jan Reedy wrote: > For instance, open Lib/idlelib/GrepDialog.py in an editor that colorizes > Python syntax, such as Idle's editor, jump down to the bottom and read > up, and (until it is patched) find > list.append(fn) > with 'list' c

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Steven D'Aprano
On Mon, 10 Jun 2013 17:20:58 -0700, Mark Janssen wrote: >>> list = [] >>> Reading further, one sees that the function works with two lists, a >>> list of file names, unfortunately called 'list', >> >> That is very good advice in general: never choose a variable name that >> is a keyword.

Re: Re-using copyrighted code

2013-06-10 Thread Steven D'Aprano
On Mon, 10 Jun 2013 08:42:07 +0200, Malte Forkel wrote: > Am 10.06.2013 07:31, schrieb Steven D'Aprano: >> >> But bringing it back to the original topic, I believe that the >> philosophy of FOSS is that we should try our best to honour the >> intentions of the writer, not to find some legal looph

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread rusi
On Jun 11, 5:14 am, Terry Jan Reedy wrote: > Many long-time posters have advised "Don't rebind built-in names*. > > * Unless you really mean to mask it, or more likely wrap it, such as > wrapping print to modify some aspect of its operation than one cannot do > with its keyword parameters. The poi

Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Denis McMahon
On Mon, 10 Jun 2013 03:42:38 -0700, Νικόλαος Κούρας wrote: > for key in sorted( months.values() ): > print(''' >%s > ''' % (months[key], key) ) > == > > please tell me Uli why this dont work as expected to. Because inside the for loop, your value 'key' i

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread rusi
On Jun 11, 5:53 am, Mark Janssen wrote: > > There's a subtle difference between a keyword and a built-in.  Good > > Python style generally avoids masking built-ins but allows it: > > Right, thank you for reminding me.  My C-mind put them in the same category. > -- > MarkJ > Tacoma, Washington Don

RE: Popen and reading stdout in windows

2013-06-10 Thread Joseph L. Casale
> You leave out an awful amount of detail. I have no idea what ST is, so > I'll have to guess your real problem. Ugh, sorry guys its been one of those days, the post was rather useless... I am using Popen to run the exe with communicate() and I have sent stdout to PIPE without luck. Just not su

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Mark Janssen
> There's a subtle difference between a keyword and a built-in. Good > Python style generally avoids masking built-ins but allows it: Right, thank you for reminding me. My C-mind put them in the same category. -- MarkJ Tacoma, Washington -- http://mail.python.org/mailman/listinfo/python-list

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Tim Chase
On 2013-06-10 17:20, Mark Janssen wrote: > >> list = [] > >> Reading further, one sees that the function works with two > >> lists, a list of file names, unfortunately called 'list', > > > > That is very good advice in general: never choose a variable name > > that is a keyword. > > Btw,

Re: "Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Mark Janssen
>> list = [] >> Reading further, one sees that the function works with two lists, a list of >> file names, unfortunately called 'list', > > That is very good advice in general: never choose a variable name > that is a keyword. Btw, shouldn't it be illegal anyway? Most compilers don't le

"Don't rebind built-in names*" - it confuses readers

2013-06-10 Thread Terry Jan Reedy
Many long-time posters have advised "Don't rebind built-in names*. * Unless you really mean to mask it, or more likely wrap it, such as wrapping print to modify some aspect of its operation than one cannot do with its keyword parameters. The point for this post is that such wrapping modify or

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Peter Otten
Chris Angelico wrote: > On Tue, Jun 11, 2013 at 6:34 AM, Roy Smith wrote: >> new_songs = [s for s in songs if s.is_new()] >> old_songs = [s for s in songs if not s.is_new()] > > Hmm. Would this serve? > > old_songs = songs[:] > new_songs = [songs.remove(s) or s for s in songs if s.is_new()] >

Re: py_compile vs. built-in compile, with __future__

2013-06-10 Thread dhyams
On Monday, June 10, 2013 6:36:04 PM UTC-4, Chris Angelico wrote: > On Tue, Jun 11, 2013 at 8:27 AM, dhyams wrote: > > > I guess I'll have to agree to disagree here...the situation I'm in is that > > I want a user to be able to write a mathematical plugin with as little > > effort as possible.

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Dave Angel
On 06/10/2013 06:54 PM, Chris Angelico wrote: On Tue, Jun 11, 2013 at 8:39 AM, Grant Edwards wrote: On 2013-06-10, Terry Jan Reedy wrote: Another principle similar to 'Don't add extraneous code' is 'Don't rebind builtins'. OK, we've all done it by accident (especially when starting out), b

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Tim Chase
On 2013-06-11 08:54, Chris Angelico wrote: > >> Another principle similar to 'Don't add extraneous code' is > >> 'Don't rebind builtins'. > > > > OK, we've all done it by accident (especially when starting out), > > but are there people that rebind builtins intentionally? > > There are times when

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Chris Angelico
On Tue, Jun 11, 2013 at 9:10 AM, Tim Chase wrote: > On 2013-06-11 08:50, Chris Angelico wrote: >> The iterator version strikes my fancy. Maybe this isn't of use to >> you, but I'm going to try my hand at making one anyway. >> >> >>> def iterpartition(pred,it): >> """Partition an iterable bas

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Fábio Santos
On 10 Jun 2013 23:54, "Roel Schroeven" wrote: > > You could do something like: > > new_songs, old_songs = [], [] > [(new_songs if s.is_new() else old_songs).append(s) for s in songs] > > But I'm not sure that that's any better than the long version. This is so beautiful! -- http://mail.python.or

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Tim Chase
On 2013-06-11 08:50, Chris Angelico wrote: > The iterator version strikes my fancy. Maybe this isn't of use to > you, but I'm going to try my hand at making one anyway. > > >>> def iterpartition(pred,it): > """Partition an iterable based on a predicate. > > Returns two iterables, for

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Chris Rebert
On Mon, Jun 10, 2013 at 1:34 PM, Roy Smith wrote: > I have a list, songs, which I want to divide into two groups. > Essentially, I want: > > new_songs = [s for s in songs if s.is_new()] > old_songs = [s for s in songs if not s.is_new()] > > but I don't want to make two passes over the list. I cou

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Chris Angelico
On Tue, Jun 11, 2013 at 8:39 AM, Grant Edwards wrote: > On 2013-06-10, Terry Jan Reedy wrote: > >> Another principle similar to 'Don't add extraneous code' is 'Don't >> rebind builtins'. > > OK, we've all done it by accident (especially when starting out), but > are there people that rebind built

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Chris Angelico
On Tue, Jun 11, 2013 at 6:34 AM, Roy Smith wrote: > new_songs = [s for s in songs if s.is_new()] > old_songs = [s for s in songs if not s.is_new()] Hmm. Would this serve? old_songs = songs[:] new_songs = [songs.remove(s) or s for s in songs if s.is_new()] Python doesn't, AFAIK, have a "destruct

Re: Split a list into two parts based on a filter?

2013-06-10 Thread Roel Schroeven
Roy Smith schreef: I have a list, songs, which I want to divide into two groups. Essentially, I want: new_songs = [s for s in songs if s.is_new()] old_songs = [s for s in songs if not s.is_new()] but I don't want to make two passes over the list. I could do: new_songs = [] old_songs = [] for

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Grant Edwards
On 2013-06-10, Terry Jan Reedy wrote: > Another principle similar to 'Don't add extraneous code' is 'Don't > rebind builtins'. OK, we've all done it by accident (especially when starting out), but are there people that rebind builtins intentionally? -- Grant Edwards grant.b.edwa

Re: py_compile vs. built-in compile, with __future__

2013-06-10 Thread Chris Angelico
On Tue, Jun 11, 2013 at 8:27 AM, dhyams wrote: > I guess I'll have to agree to disagree here...the situation I'm in is that I > want a user to be able to write a mathematical plugin with as little effort > as possible. So I want the "from __future__ import division" to be baked > into the plug

Re: py_compile vs. built-in compile, with __future__

2013-06-10 Thread dhyams
On Monday, June 10, 2013 4:59:35 PM UTC-4, Terry Jan Reedy wrote: > On 6/10/2013 11:33 AM, dhyams wrote: > > > The built-in compile() function has a "flags" parameter that one can > > > use to influence the "__future__" mechanism. However, > > > py_compile.compile, which I'm using to byte-compil

Re: Encoding questions (continuation)

2013-06-10 Thread Lele Gaifax
Steven D'Aprano writes: >> I did but docs confuse me even more. Can you pleas ebut it simple. > > Nikos, if you can't be bothered to correct your spelling mistakes, why > should we be bothered to answer your questions? Maybe he just want to prove we are smart enough... http://www.foxnews.com/s

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Terry Jan Reedy
On 6/10/2013 4:13 PM, Rui Maciel wrote: Terry Jan Reedy wrote: Three answers: Look how much trouble it has already caused ;-) Since you are a self-declared newbie, believe us! Since, be definition, useless code can do no good, it can only cause trouble. Think about it. I don't doubt that ther

Re: py_compile vs. built-in compile, with __future__

2013-06-10 Thread Terry Jan Reedy
On 6/10/2013 11:33 AM, dhyams wrote: The built-in compile() function has a "flags" parameter that one can use to influence the "__future__" mechanism. However, py_compile.compile, which I'm using to byte-compile code, doesn't have an equivalent means to do this. That flag was added to compile b

Re: Re-using copyrighted code

2013-06-10 Thread llanitedave
On Monday, June 10, 2013 12:40:57 PM UTC-7, zipher wrote: > > Weird Al can be a complex case, because sometimes his songs are true > > parodies, and sometimes they're more satires. Parody has a pretty firm > > history of being protected under fair use, and Weird Al's MJ-inspired songs > > ("Fat

Split a list into two parts based on a filter?

2013-06-10 Thread Roy Smith
I have a list, songs, which I want to divide into two groups. Essentially, I want: new_songs = [s for s in songs if s.is_new()] old_songs = [s for s in songs if not s.is_new()] but I don't want to make two passes over the list. I could do: new_songs = [] old_songs = [] for s in songs: if s.

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Rui Maciel
Dave Angel wrote: > So why do you also have an instance attribute of the same name? Thanks to this thread, and after a bit of reading, I've finally managed to discover that in Python there are class attributes and instance attributes, the former working similarly to C++'s static member variable

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Ned Batchelder
On Monday, June 10, 2013 3:48:08 PM UTC-4, jmfauth wrote: > - > > > > A coding scheme works with three sets. A *unique* set > of CHARACTERS, a *unique* set of CODE POINTS and a *unique* > set of ENCODED CODE POINTS, unicode or not. > > The relation between the set of characters and the set

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Rui Maciel
Terry Jan Reedy wrote: > Three answers: > Look how much trouble it has already caused ;-) > Since you are a self-declared newbie, believe us! > Since, be definition, useless code can do no good, it can only cause > trouble. Think about it. I don't doubt that there might good reasons for that, but

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Rui Maciel
Terry Jan Reedy wrote: > On 6/10/2013 9:18 AM, Rui Maciel wrote: > >> class Model: >> points = [] >> lines = [] > > Unless you actually need keep the points and lines ordered by entry > order, or expect to keep sorting them by whatever, sets may be better > than lists. Testing

Re: Re-using copyrighted code

2013-06-10 Thread Chris Angelico
On Tue, Jun 11, 2013 at 5:40 AM, Mark Janssen wrote: >> Weird Al can be a complex case, because sometimes his songs are true >> parodies, and sometimes they're more satires. Parody has a pretty firm >> history of being protected under fair use, and Weird Al's MJ-inspired songs >> ("Fat" and "E

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Ian Kelly
On Mon, Jun 10, 2013 at 7:57 AM, Rui Maciel wrote: > # Case A: this works > model.points[0].position = [2,3,4] > line.points > > # Case B: this doesn't work > test.model.points[0] = test.Point(5,4,7) > line.points > > > > Is there a Python way of getting the same effect with Case B? It's inform

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Terry Jan Reedy
On 6/10/2013 9:18 AM, Rui Maciel wrote: class Model: points = [] lines = [] Unless you actually need keep the points and lines ordered by entry order, or expect to keep sorting them by whatever, sets may be better than lists. Testing that a point or line is in the model wil

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Terry Jan Reedy
On 6/10/2013 12:09 PM, Rui Maciel wrote: We've established that you don't like attribute declarations, at least those you describe as not fulfill a technical purpose. What I don't understand is why you claim that that would "cause nothing but trouble". Three answers: Look how much trouble it

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread jmfauth
- A coding scheme works with three sets. A *unique* set of CHARACTERS, a *unique* set of CODE POINTS and a *unique* set of ENCODED CODE POINTS, unicode or not. The relation between the set of characters and the set of the code points is a *human* table, created with a sheet of paper and a pe

Re: Popen and reading stdout in windows

2013-06-10 Thread Dave Angel
On 06/10/2013 02:37 PM, Joseph L. Casale wrote: I have a use where writing an interim file is not convenient and I was hoping to iterate through maybe 100k lines of output by a process as its generated or roughly anyways. Seems to be a common question on ST, and more easily solved in Linux. Anyo

Re: Re-using copyrighted code

2013-06-10 Thread Mark Janssen
> Weird Al can be a complex case, because sometimes his songs are true > parodies, and sometimes they're more satires. Parody has a pretty firm > history of being protected under fair use, and Weird Al's MJ-inspired songs > ("Fat" and "Eat It") are clearly parodies. (As is his more recent Lady

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Dave Angel
On 06/10/2013 01:42 PM, Rui Maciel wrote: Peter Otten wrote: Have you read the code in the interpreter session I posted? If you do not agree that the demonstrated behaviour is puzzling I'll have to drop my claim... I don't see how it should be puzzling. You've deleted the attribute, so it c

Re: Re-using copyrighted code

2013-06-10 Thread Joshua Landau
On 10 June 2013 17:29, llanitedave wrote: > However, I have yet to see an example of source code that qualifies as either > parody or satire under any standard. You should try reading Perl. -- http://mail.python.org/mailman/listinfo/python-list

Re: Popen and reading stdout in windows

2013-06-10 Thread Grant Edwards
On 2013-06-10, Joseph L. Casale wrote: > I have a use where writing an interim file is not convenient and I > was hoping to iterate through maybe 100k lines of output by a process > as its generated or roughly anyways. > > Seems to be a common question on ST, and more easily solved in Linux. > An

Re: Questions on "import" and "datetime"

2013-06-10 Thread Dave Angel
On 06/10/2013 01:01 PM, Zachary Ware wrote: On Mon, Jun 10, 2013 at 10:37 AM, Yunfei Dai wrote: Hi all, Hi Yunfei, I have some questions on "import": 1."from datetime import datetime" works well. But I am confused why "import datetime.datetime" leads to importerror. "from xlrd import ope

Popen and reading stdout in windows

2013-06-10 Thread Joseph L. Casale
I have a use where writing an interim file is not convenient and I was hoping to iterate through maybe 100k lines of output by a process as its generated or roughly anyways. Seems to be a common question on ST, and more easily solved in Linux. Anyone currently doing this with Python 2.7 in windows

Re: Build Python 2.7.5 - Modules missing

2013-06-10 Thread Skip Montanaro
> It carried on with the installation OK, but I don't understand the last > sentence in the message. How can I find out exactly what modules are > missing, and what I need to do to make sure they are built next time? Some of them won't ever build, as they are platform-dependent. For example, if y

Build Python 2.7.5 - Modules missing

2013-06-10 Thread Walter Hurry
On building Python 2.7.5 I got the following message: Python build finished, but the necessary bits to build these modules were not found: dl imageoplinuxaudiodev spwd sunaudiodev To find the necessary bits, look in setup.py in

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Rui Maciel
Peter Otten wrote: > Have you read the code in the interpreter session I posted? > > If you do not agree that the demonstrated behaviour is puzzling I'll have > to drop my claim... I don't see how it should be puzzling. You've deleted the attribute, so it ceassed to exist. > Likewise if you

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Peter Otten
Rui Maciel wrote: > Peter Otten wrote: > >> I don't understand the question. My original point was that you should >> omit class attributes that don't fulfill a technical purpose. >> > > You've said the following: > > >> class Point: > > Don't add > >> position = [] > > to your cod

Re: Simple converter of files into their hex components... but i can't arrange utf-8 parts!

2013-06-10 Thread blatt447477
Hi Chris, your critics are welcome! But perhaps the majority of them has been caused by font problems in my posting. Google should put as default a "mono" font! Or perhaps it has been a mistake on my part to not configure correctly the output of my post (I even didn't change my nickname... so you r

Re: Questions on "import" and "datetime"

2013-06-10 Thread Zachary Ware
On Mon, Jun 10, 2013 at 10:37 AM, Yunfei Dai wrote: > Hi all, Hi Yunfei, > > I have some questions on "import": > > 1."from datetime import datetime" works well. But I am confused why "import > datetime.datetime" leads to importerror. "from xlrd import open_workbook" > could be replaced by "fr

PDF in a Bottle - creating PDF using xtopdf, ReportLab, Bottle and Python

2013-06-10 Thread vasudevram
Hi list, Might be of interest: PDF in a Bottle - creating PDF using xtopdf, ReportLab, Bottle and Python http://jugad2.blogspot.in/2013/05/pdf-in-bottle-creating-pdf-using-xtopdf.html - Vasudev Ram Python, Linux and open source training and development www.dancingbison.com -- http://mail.py

Re: Encoding questions (continuation)

2013-06-10 Thread Fábio Santos
On 10 Jun 2013 15:04, "Νικόλαος Κούρας" wrote: > > Τη Δευτέρα, 10 Ιουνίου 2013 2:41:07 μ.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε: > > On Mon, 10 Jun 2013 14:13:00 +0300, Νικόλαος Κούρας wrote: > > > > > > > > > Τη Δευτέρα, 10 Ιουνίου 2013 1:42:25 μ.μ. UTC+3, ο χρήστης Andreas > > > > > Persting

Re: Re-using copyrighted code

2013-06-10 Thread llanitedave
On Sunday, June 9, 2013 2:08:54 PM UTC-7, zipher wrote: > > > > Fair use has nothing to do with money. It depends on how the work is > > > used and how you've changed it. Weird Al's song parodies are fair use, > > > even though he sells them. > > > > That can't really be claimed without a ca

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Rui Maciel
Peter Otten wrote: > I don't understand the question. My original point was that you should > omit class attributes that don't fulfill a technical purpose. > You've said the following: > class Point: Don't add > position = [] to your code. That's not a declaration, but a class attr

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Peter Otten
Rui Maciel wrote: > Peter Otten wrote: > >> Rui Maciel wrote: >> >>> How do you guarantee that any object of a class has a specific set of >>> attributes? >> >> You don't. > > > What's your point regarding attribute assignments in class declarations, > then? I don't understand the question.

Questions on "import" and "datetime"

2013-06-10 Thread Yunfei Dai
Hi all, I have some questions on "import": 1."from datetime import datetime" works well. But I am confused why "import datetime.datetime" leads to importerror. "from xlrd import open_workbook" could be replaced by "from xlrd.open_workbook" without any problem. The only difference here is that

Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread russ . pobox
for key, value in sorted(months.items(), key=lambda x:x[1]): print("""'\t%s'\n""" % (value, key)) Explanation: - - - - - - dict.items is a method associated with dicts just like dict.keys or dict.values, and returns a list of (key, value) pairs. sorted and some other builtin functions have

py_compile vs. built-in compile, with __future__

2013-06-10 Thread dhyams
The built-in compile() function has a "flags" parameter that one can use to influence the "__future__" mechanism. However, py_compile.compile, which I'm using to byte-compile code, doesn't have an equivalent means to do this. Is this by design, or would this be considered a bug? I'm just wantin

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Rui Maciel
Peter Otten wrote: > Rui Maciel wrote: > >> How do you guarantee that any object of a class has a specific set of >> attributes? > > You don't. What's your point regarding attribute assignments in class declarations, then? Rui Maciel -- http://mail.python.org/mailman/listinfo/python-list

Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread Ulrich Eckhardt
Am 10.06.2013 15:37, schrieb Νικόλαος Κούρας: Τη Δευτέρα, 10 Ιουνίου 2013 4:14:33 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt έγραψε: Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας: Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt έγραψε: for key in sorted( months.ke

testfixtures 3.0.1 Released!

2013-06-10 Thread Chris Withers
Hi All, I'm pleased to announce the release of testfixtures 3.0.1. This is a bug fix release featuring the following changes: - Some documentation tweaks and clarifications. - Fixed a bug which masked exceptions when using compare() with a broken generator. - Fixed a bug when comparing a g

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Peter Otten
Rui Maciel wrote: > How do you guarantee that any object of a class has a specific set of > attributes? You don't. Such a guarantee is like the third wheel on a bike -- it doesn't improve the overall experience. PS: I'd rather not mention the memory-saving technique that is sometimes abused,

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Rui Maciel
Peter Otten wrote: > Rui Maciel wrote: > >> Peter Otten wrote: >> >>> Don't add >>> position = [] >>> >>> to your code. That's not a declaration, but a class attribute and in the >>> long run it will cause nothing but trouble. >> >> Why's that? > > Especially with mutable attributes it's

Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread Νικόλαος Κούρας
Since dict.keys() return a list of the keys in the dict and the keys are associated with the dict's values why doesnt it work the other way around too? I'm talking about this: [code] for key in sorted( months.keys() ): print(''' %s ''' % (months[key], key)

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 2:59:03 μ.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε: > On Mon, 10 Jun 2013 00:10:38 -0700, nagia.retsina wrote: > > > > > Τη Κυριακή, 9 Ιουνίου 2013 3:31:44 μ.μ. UTC+3, ο χρήστης Steven D'Aprano > > > έγραψε: > > > > > >> py> c = 'α' > > >> py> ord(c) > > >> 9

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Peter Otten
Rui Maciel wrote: > Peter Otten wrote: > >> Don't add >> >>>position = [] >> >> to your code. That's not a declaration, but a class attribute and in the >> long run it will cause nothing but trouble. > > Why's that? Especially with mutable attributes it's hard to keep track whether you are o

Re: Re-using copyrighted code

2013-06-10 Thread Ethan Furman
On 06/10/2013 05:57 AM, Robert Kern wrote: On 2013-06-08 22:31, Malte Forkel wrote: Hello, I have written a small utility to locate errors in regular expressions that I want to upload to PyPI. Before I do that, I would like to learn a litte more about the legal aspects of open-source software.

Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 4:14:33 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt έγραψε: > Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας: > > > >Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich > > > Eckhardt έγραψε: > > > > > > for key in sorted( months.keys() ): > > > pri

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Rui Maciel
Rui Maciel wrote: > # Case B: this doesn't work > test.model.points[0] = test.Point(5,4,7) Disregard the "test." bit. I was testing the code by importing the definitions as a module. Rui Maciel -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Rui Maciel
Peter Otten wrote: > Don't add > >>position = [] > > to your code. That's not a declaration, but a class attribute and in the > long run it will cause nothing but trouble. Why's that? Rui Maciel -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding questions (continuation)

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 2:41:07 μ.μ. UTC+3, ο χρήστης Steven D'Aprano έγραψε: > On Mon, 10 Jun 2013 14:13:00 +0300, Νικόλαος Κούρας wrote: > > > > > Τη Δευτέρα, 10 Ιουνίου 2013 1:42:25 μ.μ. UTC+3, ο χρήστης Andreas > > > Perstinger έγραψε: > > > > > > > >>> s = b'\xce\xb1' > > > > >

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Rui Maciel
Roy Smith wrote: > Have you tried running the code you wrote? It does that already! When > you do something like: > > my_list = [obj1, obj2] > > in Python, the objects are stored by reference (not just lists, all > assignments are by reference). I've tested the following: model = Model() mo

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Peter Otten
Rui Maciel wrote: > Let: > - class Point be a data type which is used to define points in space > - class Line be a data type which possesses an aggregate relationship with > objects of type Point > - class Model be a container class which stores collections of Point and > Line objects > > > Ess

Re: Newbie: question regarding references and class relationships

2013-06-10 Thread Roy Smith
In article , Rui Maciel wrote: > Essentially, a Model object stores lists of Point objects and Line objects, > and Line objects include references to Point objects which represent the > starting and ending point of a line. > > class Point: > position = [] > > def __init__(sel

Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 4:14:33 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt έγραψε: > Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας: > > > >Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich > > > Eckhardt έγραψε: > > > > > > for key in sorted( months.keys() ): > > > pri

Newbie: question regarding references and class relationships

2013-06-10 Thread Rui Maciel
Let: - class Point be a data type which is used to define points in space - class Line be a data type which possesses an aggregate relationship with objects of type Point - class Model be a container class which stores collections of Point and Line objects Essentially, a Model object stores lis

Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Ulrich Eckhardt
Am 10.06.2013 11:48, schrieb Νικόλαος Κούρας: After many tried this did the job: for key in sorted(months.items(),key=lambda num : num[1]): print(''' %s ''' % (key[1], key[0]) ) This code is still sending a misleading message. What you are referring to as "ke

Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread Ulrich Eckhardt
Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας: >Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt έγραψε: for key in sorted( months.keys() ): print(''' %s ''' % (months[key], key) ) this in fact works, it sorts the dict by its keys()

Re: Re-using copyrighted code

2013-06-10 Thread Robert Kern
On 2013-06-08 22:31, Malte Forkel wrote: Hello, I have written a small utility to locate errors in regular expressions that I want to upload to PyPI. Before I do that, I would like to learn a litte more about the legal aspects of open-source software. What would be a good introductory reading?

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Steven D'Aprano
On Mon, 10 Jun 2013 00:10:38 -0700, nagia.retsina wrote: > Τη Κυριακή, 9 Ιουνίου 2013 3:31:44 μ.μ. UTC+3, ο χρήστης Steven D'Aprano > έγραψε: > >> py> c = 'α' >> py> ord(c) >> 945 > > The number 945 is the characters 'α' ordinal value in the unicode > charset correct? Correct. > The command i

Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Steven D'Aprano
On Mon, 10 Jun 2013 03:42:38 -0700, Νικόλαος Κούρας wrote: > for key in sorted( months.values() ): > please tell me Uli why this dont work as expected to. Because values are not keys. You are looking at the values, and trying to use them as keys. months = {'Φεβρουάριος':2, 'Ιανουάριος':1} prin

Re: Encoding questions (continuation)

2013-06-10 Thread Steven D'Aprano
On Mon, 10 Jun 2013 14:13:00 +0300, Νικόλαος Κούρας wrote: > Τη Δευτέρα, 10 Ιουνίου 2013 1:42:25 μ.μ. UTC+3, ο χρήστης Andreas > Perstinger έγραψε: > > > >>> s = b'\xce\xb1' > > > > >>> s[0] > > > > 206 > > 's' is a byte object, how can you treat it as a string asking to present > you its

Encoding questions (continuation)

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 1:42:25 μ.μ. UTC+3, ο χρήστης Andreas Perstinger έγραψε: > >>> s = b'\xce\xb1' > > >>> s[0] > > 206 's' is a byte object, how can you treat it as a string asking to present you its first character? > > >>> s[1] > > 177 's' is a byte object, how can you treat i

Re: Reply to post 'Tryign to add a valkue to a set'

2013-06-10 Thread Νικόλαος Κούρας
>Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt έγραψε: for key in sorted( months.keys() ): print(''' %s ''' % (months[key], key) ) this in fact works, it sorts the dict by its keys() was mistaken before but the sorting aint correct

Re: Changing filenames from Greeklish => Greek (subprocess complain)

2013-06-10 Thread Andreas Perstinger
On 10.06.2013 11:59, Νικόλαος Κούρας wrote: s = 'α' s.encode('utf-8') > b'\xce\xb1' 'b' stands for binary right? No, here it stands for bytes: http://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals b'\xce\xb1' = we are looking at a byte in a hexadecim

Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Νικόλαος Κούρας
Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt έγραψε: > Am 10.06.2013 10:29, schrieb Νικόλαος Κούρας: > > > for key in sorted( months.values() ): > >^^^ ^^ > > > > > KeyError 1 ??!! All i did was to tell python to sort the dictionary

Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Ulrich Eckhardt
Am 10.06.2013 10:04, schrieb Νικόλαος Κούρας: months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4, 'Μάϊος':5, 'Ιούνιος':6, \ 'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9, 'Οκτώβριος':10, 'Νοέμβριος':11, 'Δεκέμβριος':12 } for key in sorted( months.keys() ): =

Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Ulrich Eckhardt
Am 10.06.2013 10:29, schrieb Νικόλαος Κούρας: for key in sorted( months.values() ): ^^^ ^^ KeyError 1 ??!! All i did was to tell python to sort the dictionary values, which are just integers. ...and which you then proceed to use as key, which is obviously wrong.

  1   2   >