Re: Drawing Sinus curve in Python

2014-06-01 Thread Steven D'Aprano
then the problem will be that I can not control the length of this > line and the sine curve , that should be equal You have to get the maths right, otherwise the graph will be wrong. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3.2 has some deadly infection

2014-06-01 Thread Steven D'Aprano
On Mon, 02 Jun 2014 08:54:33 +1000, Tim Delaney wrote: > On 1 June 2014 12:26, Steven D'Aprano > wrote: > > >> "with cross-platform behavior preferred over system-dependent one" -- >> It's not clear how cross-platform behaviour has anything to do wi

Obfuscated Python hack

2014-06-02 Thread Steven D'Aprano
//2 A shiny penny for the first person to explain what's going on.[1] [1] Offer expires April 1st 2014. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Obfuscated Python hack

2014-06-02 Thread Steven D'Aprano
gt;> "5". But a cute hack. > > And not on Windows inside IDLE, where attempting to use 4 results in a > = RESTART = crash. Sounds like a bug in IDLE. What happens if you try it in Windows without IDLE, just using the standard interactive interpreter? -- St

Re: Python 3 is killing Python

2014-06-02 Thread Steven D'Aprano
hat a sufficiently advanced troll is indistinguishable from a crank. Whichever JMF is, please don't feed him attention. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3 is killing Python

2014-06-02 Thread Steven D'Aprano
ls, Pratchett trolls, Rowling trolls, D&D > trolls, WoW trolls, or what? Details matter. Now I think you're trolling :-) Internet troll. As I'm sure you know. http://rationalwiki.org/wiki/Don%27t_feed_the_Troll -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Strange Behavior

2014-06-02 Thread Steven D'Aprano
Outlook, Excel). The same applies to files demonstrating bugs. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: can someone explain the concept of "strings (or whatever) being immutable"

2014-06-03 Thread Steven D'Aprano
like this: s = "Hello" s += " World!" does not append to the existing string, but creates a new string, "Hello World!", and binds it to the name s. Then the two older strings, "Hello" and " World!" are free to be garbage collected. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Strange Behavior

2014-06-03 Thread Steven D'Aprano
On Tue, 03 Jun 2014 10:01:26 +0200, Peter Otten wrote: > Steven D'Aprano wrote: > >> On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: >> >>> I invoked the wrong bug.py :/ , works fine now (this happens to me >>> when im a bit tired sometimes...).

Re: Micro Python -- a lean and efficient implementation of Python 3

2014-06-03 Thread Steven D'Aprano
On Tue, 03 Jun 2014 13:27:11 +0100, Damien George wrote: > Hi, > > We would like to announce Micro Python, an implementation of Python 3 > optimised to have a low memory footprint. Fantastic! -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org

Re: Would a Python 2.8 help you port to Python 3?

2014-06-03 Thread Steven D'Aprano
rtially introduced 3 features such as "from __future__ import division" etc. Python 3.0 final was released on December 3rd, 2008, just two months (almost to the day) after 2.6. https://www.python.org/download/releases/2.6 https://www.python.org/download/releases/3.0 -- Steven D&

Re: Python 3.2 has some deadly infection

2014-06-03 Thread Steven D'Aprano
¶ Python 3 works correctly, whether you use print or sys.stdout: [steve@ando ~]$ python3.3 -c "import sys; sys.stdout.write(u'ñβж\n')" ñβж (although I haven't tested it on Windows). -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: OT: This Swift thing

2014-06-03 Thread Steven D'Aprano
eve that PyPy has a GIL-less mode, although I may have confabulated that. I don't know whether Nuitka has a GIL, although Cython does, as do CPython and Stackless. The GIL is not a language feature, it is an implementation feature. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: OT: This Swift thing

2014-06-03 Thread Steven D'Aprano
On Wed, 04 Jun 2014 00:19:34 +0300, Marko Rauhamaa wrote: > Sturla Molden : > >> A Python with static typing would have been far better, IMHO. > > I don't think static typing and Python should be mentioned in the same > sentence. Guido disagrees with you: https://www.python.org/~guido/static-

Re: OT: This Swift thing

2014-06-03 Thread Steven D'Aprano
Internet. Nice to see old traditions haven't been forgotten. > We even have a couple of clucks on our side of the world that refuse to > even get their feet wet in python because they hate the indentation > paradigm. Chances are that they use *exactly the same* indentation rules as P

Re: immutable vs mutable

2014-06-03 Thread Steven D'Aprano
tb.org/esr/faqs/smart-questions.html I have found that (like much from Eric S Raymond) it's more idiosyncratic and pretentious than a useful educational tool. Although this is aimed at Java programmers, I think it is MUCH more accessible: http://sscce.org/ -- Steven -- https://mai

Re: Micro Python -- a lean and efficient implementation of Python 3

2014-06-03 Thread Steven D'Aprano
orrect behaviour. The bit could be a flag recording whether the string contains any surrogate pairs. If the flag was 0, all string operations could assume a constant 2-bytes-per-character. If the flag was 1, it could fall back to walking the string checking for surrogate pairs. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Micro Python -- a lean and efficient implementation of Python 3

2014-06-04 Thread Steven D'Aprano
lers may well not > meet, but if you're talking about universality, you need Unicode. It's > that simple. > Maybe there's a use-case for a microcontroller that works in ISO-8859-5 > natively, thus using only eight bits per character, That won't even make the Russians happy, since in Russia there are multiple incompatible legacy encodings. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3.2 has some deadly infection

2014-06-04 Thread Steven D'Aprano
ode sense? Of course not, that would be silly. The concept of encodings is bigger than just text, and in that sense zip compression is an encoding which encodes non-random data into a different format which generally takes up less space. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Micro Python -- a lean and efficient implementation of Python 3

2014-06-04 Thread Steven D'Aprano
tively simple string library, graphemes are too hard. Code points are simple, and the language can deal with code points without caring about their semantics. For instance, in English, I might not want to insert letters between the q and u of "queen", since in English u (nearly)

Re: Lambda function Turing completeness

2013-07-31 Thread Steven D'Aprano
On Wed, 31 Jul 2013 13:53:26 +0700, Musical Notation wrote: > Is it possible to write a Turing-complete lambda function (which does > not depend on named functions) in Python? lambda s: eval(s) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Script that converts between indentation and curly braces in Python code

2013-07-31 Thread Steven D'Aprano
y indentation is no different. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Unexpected results comparing float to Fraction

2013-07-31 Thread Steven D'Aprano
On Wed, 31 Jul 2013 15:23:21 -0500, Tony the Tiger wrote: > On Mon, 29 Jul 2013 15:43:24 +0000, Steven D'Aprano wrote: > >> Am I the only one who is surprised by this? > > Most likely. > > Floats aren't precise enough to be equal to a (true) fraction. > flo

Re: PEP8 79 char max

2013-08-01 Thread Steven D'Aprano
have a table >> of mnemonics/opcodes/instruction-format/addressing-modes. > > > Why are you writing an assembler? Maybe he's (re-)creating PyPy :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP8 revised: max line lengths

2013-08-01 Thread Steven D'Aprano
egative. The consensus seems to be, if you have a line of code that is more than 79 characters, and less than 100 characters, and there is no clean way to break it over multiple lines, then it is acceptable to not break it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: outputting time in microseconds or milliseconds

2013-08-02 Thread Steven D'Aprano
http://bugs.python.org/issue1982 Unfortunately, the %S.%f codes do not appear to work for me on Linux using Python 2.6, 2.7 or 3.3. Perhaps you will have better luck. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Correct Way to Write in Python

2013-08-03 Thread Steven D'Aprano
raise TypeError('names must be strings') self.name = name if __name__ == '__main__': # Running as a script, call the main function. customer = Customer("XYX") bank = Bank() bank.customers.append(customer) The above is still not what I call professional quality -- no doc strings (documentation), and the bank doesn't actually do anything, but it's a start. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Minions are Python Powered!

2013-08-03 Thread Steven D'Aprano
ot Found tries to set a cookie that doesn't expire for FIVE YEARS. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 2.7.5 incompatible

2013-08-03 Thread Steven D'Aprano
a screenshot and posting that here. But 99 times out of 100, you should be able to copy and paste the text, or at least re-type it if it is short. That will do for a start. If any of my instructions are unclear, feel free to ask for more help, but remember, more detail is usuall

Re: Print word from list

2013-08-03 Thread Steven D'Aprano
string. Instead, you want to do this: pie = pie.split() Now pie will be a list of individual words. You can print the entire list: print(pie) or print each word separately: for filling in pie: print(filling) Or pick out one specific filling: print(pie[2]) # should print 'pecan&#

Re: Removing matching items from a list?

2013-08-03 Thread Steven D'Aprano
cter is seen, otherwise increments the counter by 1. There's a ready-made tool for doing that: from collections import Counter counts = Counter(item[0] for item in pHands[0]) but under the hood, it's essentially doing the same thing as I wrote above. Steps 2 and 3 can be done together: new_list = [] for item in pHand[0]: c = item[0] # Look up the character in the counter. if counts[c] < 4: new_list.append(item) pHand[0] = new_list -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Removing matching items from a list?

2013-08-03 Thread Steven D'Aprano
On Sat, 03 Aug 2013 19:06:05 -0400, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> 2) Then go through those initial letters, and pick out the ones equal >> to 4 (or should that be "four

Re: Removing matching items from a list?

2013-08-03 Thread Steven D'Aprano
remove.append(card) Or you could do this at the same time as you build the counter. I leave it to you to work out how to do that. The important thing is, you have to start by asking the question, "How would I do this task?" before you can write Python code for it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie: static typing?

2013-08-05 Thread Steven D'Aprano
und no tutorial on how to implement it. Try Cobra instead. It's Python-like syntax, but allows static typing. http://cobra-language.com/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie: static typing?

2013-08-06 Thread Steven D'Aprano
g the exception: try: flag = obj & 8 except TypeError: flag = False Or just don't do anything: flag = obj & 8 If obj is the wrong type, you will get a perfectly fine exception at run- time. Why do extra work do try to detect the failure when Python will do it for you? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Class hierarchy problem

2013-08-06 Thread Steven D'Aprano
. return SupABB(args) Either way, the design risks becoming a horrible mess, but you might be able to use it. Good luck! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

PEP 450 Adding a statistics module to Python

2013-08-09 Thread Steven D'Aprano
I am seeking comments on PEP 450, Adding a statistics module to Python's standard library: http://www.python.org/dev/peps/pep-0450/ Please read the FAQs before asking anything :-) Also relevant: http://bugs.python.org/issue18606 -- Steven -- http://mail.python.org/mailman/lis

Re: right adjusted strings containing umlauts

2013-08-09 Thread Steven D'Aprano
f either looks like an encoding cookie: encoding = cookie # optionally check the end of the file as well close file if encoding is None: encoding = 'utf-8' read from file using encoding -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: beginner question (True False help)

2013-08-09 Thread Steven D'Aprano
tice the line at the top of this message, starting with ">"? That's what you previously wrote.) If you need help configuring your email program to quote the previous message, just ask. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Basic Doubt

2013-08-10 Thread Steven D'Aprano
catch it. Calling isinstance should be rare; calling type to check for an exact class even rarer. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Basic Doubt

2013-08-11 Thread Steven D'Aprano
ist and its copy are, in fact, equal. If they aren't equal, the test fails. In this case, the assertions are there as verifiable comments. They communicate to the reader, "These are the assumptions this test relies on", except unlike comments, if the assumptions are violated, the test will fail. Unlike comments, they cannot ever get out of date. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Basic Doubt

2013-08-11 Thread Steven D'Aprano
his apparently arbitrary rule, but they don't need to learn it *right now* if they don't want. In any case, the rule can include "When in doubt, use equals". I'm good with that :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Elegant compare

2013-08-11 Thread Steven D'Aprano
def __ne__(self, other): if not isinstance(other, MyClass): return NotImplemented return bool(self._compare(other)) and so on. You can save a certain amount of repetition (by my count, six lines of code) by pulling out the "if not isinstance" chec

Re: Am I not seeing the Error?

2013-08-11 Thread Steven D'Aprano
broken. :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Basic Doubt

2013-08-11 Thread Steven D'Aprano
ject. Maybe it's an > address, maybe it's not. Only your implementation knows for sure. /steve cheers from the audience Thank you for mentioning this. Using Jython: >>> x = 10 >>> id(x) 1 And using IronPython: >>> x = 10 >>> id(x) 43 &qu

Re: Could you verify this, Oh Great Unicode Experts of the Python-List?

2013-08-11 Thread Steven D'Aprano
ith combining characters correctly. (It's a hard problem to solve, and really needs support from the font. In some languages, the same accent will appear in different places depending on the character they are attached to, or the other accents there as well. Or so I've been lead to believe.) > ¹ https://dev.twitter.com/docs/counting- > characters#Definition_of_a_Character Looks reasonable to me. No obvious errors to my eyes. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Could you verify this, Oh Great Unicode Experts of the Python-List?

2013-08-11 Thread Steven D'Aprano
On Sun, 11 Aug 2013 10:44:40 +0100, Joshua Landau wrote: > On 11 August 2013 10:09, Steven D'Aprano > wrote: >> The reason some accented letters have single code point forms is to >> support legacy charsets; the reason some only exist as combining >> character

Re: PEP 450 Adding a statistics module to Python

2013-08-11 Thread Steven D'Aprano
rporate environments. But I've already said that in the PEP. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Basic Doubt

2013-08-11 Thread Steven D'Aprano
you don't. However type(obj).__name__ should be better. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Calling Python macro from ctypes

2013-08-12 Thread Steven D'Aprano
self._FuncPtr((name_or_ordinal, self)) AttributeError: python3.3: undefined symbol: PyUnicode_MAX_CHAR_VALUE -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: back with more issues

2013-08-12 Thread Steven D'Aprano
terrupt it. So I'm not really sure what you actually intend to do. My guess is that what you actually want is something like this: for i in range(10): player = Player() print("Player", i, "has value", player.attr) This ought to get you started. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling Python macro from ctypes

2013-08-12 Thread Steven D'Aprano
On Mon, 12 Aug 2013 13:42:14 +0200, Peter Otten wrote: > Steven D'Aprano wrote: > >> Is it possible to call a Python macro from ctypes? For example, Python >> 3.3 introduces some new macros for querying the internal representation >> of strings: >> >>

Re: multithreading in python

2013-08-13 Thread Steven D'Aprano
"%d : %s " %(score, path) > print "EN" > > > x = MyClass() I suspect that when the main thread exits, and your other threads are still running, you may be in trouble. But I'm not a threading expert, so I could be wrong. However, I would put something like this at the end: for thread in x.threads: x.join() that way the main thread cannot finish until each of the subthreads are. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Am I not seeing the Error?

2013-08-13 Thread Steven D'Aprano
early to mid 1980s. I may have even written some of it myself :-) Anyway, I don't think we should badger Devyn, we're not his dad and we're not the code police. All we can do is continue to demonstrate good, idiomatic, *working* Python code, and hopefully he will learn to write the same. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling Python macro from ctypes

2013-08-13 Thread Steven D'Aprano
On Tue, 13 Aug 2013 10:11:29 +0200, Stefan Behnel wrote: > Steven D'Aprano, 13.08.2013 08:25: >> On Mon, 12 Aug 2013 13:42:14 +0200, Peter Otten wrote: >>> Steven D'Aprano wrote: >>> >>>> Is it possible to call a Python macro from ctypes? For ex

Re: PEP 450 Adding a statistics module to Python

2013-08-13 Thread Steven D'Aprano
PEP, you will see that this proposal is to have a Python implementation of statistics functions, not a thin wrapper around another language. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a value that follows string.find()

2013-08-13 Thread Steven D'Aprano
On Tue, 13 Aug 2013 16:03:46 -0700, englishkevin110 wrote: > On Tuesday, August 13, 2013 5:58:07 PM UTC-5, Joel Goldstick wrote: [fixing Joel's top-posting] >> On Tue, Aug 13, 2013 at 6:51 PM, <> wrote: >> >> > I know the title doesn't make much sense, but I didnt know how to >> > explain my p

Re: Could you verify this, Oh Great Unicode Experts of the Python-List?

2013-08-13 Thread Steven D'Aprano
es are sent at once. SMS delivery is not guaranteed *at all*. It's a best-effort delivery service, which means the telco can drop any SMSes it feels like, for any reason it likes, without notice or notification. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
tream you are using, and a bunch of other rules that make it a little more complicated than just "automatically convert". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: many constructors in a class?

2013-08-15 Thread Steven D'Aprano
u need further details, please ask. [1] The constructor is __new__, not __init__. __init__ is called to initialise the instance after __new__ constructs it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
s = """Triple-quote string\r ... containing carriage-return+newline line\r ... endings.""" py> s 'Triple-quote string\r\ncontaining carriage-return+newline line\r \nendings.' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
nsionless, light-year has dimensions of Length, and therefore the value depends on the units you measure in: 1 light-year: = 3.724697e+17 inches = 0.30660139 parsec = 9.4607305e+12 kilometres etc. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
ract pure number, but it's still a number in a way that "light-year" (or "mile", or "gram", or "second") is not. Mole is like dozen. Light-year is like mile. And Avagadro's Number is like "twelve", only a bit bigger :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
eople, a dozen couples, or a dozen football teams, a mole of oxygen molecules is not the same as a mole of oxygen atoms. But it's still the same number of things in each case, only the thing differs. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
ractical unit to place the order, and the supplier no doubt had to convert that unit back into mass in order to weigh it out and supply it. If you want a kilogram of X, why not order a kilogram of X, instead of converting it into megamol? Sigh, I know the answer to that question. "We'

Re: .split() Qeustion

2013-08-15 Thread Steven D'Aprano
On Fri, 16 Aug 2013 04:39:16 +, Steven D'Aprano wrote: > On Thu, 15 Aug 2013 22:56:57 +, Dave Angel wrote: > >> To expand a little on that, the unit of "amount of something" is a >> "gram mole", which is 6.2 **23 grams times the molecular (or at

Re: How to I do this in Python ?

2013-08-16 Thread Steven D'Aprano
my script to create 100 of files like sp1 , sp2 ,sp3,.. > sp100 .. using the same syntax To generate the various file names, you need to loop over a counter from 1 to 100, and stick the count into a string. Use a for-loop and the range function: for i in range(1, 101): filename = "sp" + str(i) open(filename, "a").close() If you are a C programmer, you might prefer this style: filename = "sp%d" % i Or a more object-oriented style: filename = "sp{:d}".format(i) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 450 Adding a statistics module to Python

2013-08-16 Thread Steven D'Aprano
imal module, it will probably remain pure-Python for a few releases, but I hope that in the future the statistics module will gain a C-accelerated version. (Or Java-accelerated for Jython, etc.) I expect that PyPy won't need one. But because it's not really aimed at number- crunching megabytes of data, speed is not the priority. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Proper use of the codecs module.

2013-08-16 Thread Steven D'Aprano
There is no such built-in function though. By default, Python files are buffered, so it won't literally read one character from disk at a time. The actual disk IO will read a bunch of bytes into a memory buffer, and then read from the buffer. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: .split() Qeustion

2013-08-16 Thread Steven D'Aprano
sualise a hair. No need to relate things to the speed of light, which most people cannot visualise, or the circumference of the earth, or the distance from New York to Tokyo, or from Venus to Mars at aphelion :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Importing variables non-deterministic?

2013-08-17 Thread Steven D'Aprano
"from struct_global import y" is practically syntactic sugar for this: import struct_global y = struct_global.y > Is there any way to see where a > variable resolves to? You just did. You inspected the variable "y", and you saw that it is assigned the value 62. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Check for the type of arguments

2013-08-17 Thread Steven D'Aprano
exceptions stop execution of the current code. What they don't do is kill the interactive interpreter. That would be foolish. The whole point of the interactive interpreter is that it is supposed to be interactive and keep going even if you make a mistake. You're not supposed to use it for running live production code. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation unpythonic?

2013-08-17 Thread Steven D'Aprano
ing to *inspect* private attributes, for debugging. Python makes that easy. Treat other programmers as adults, and they in turn will treat you the same way. If they insist on messing with your private single-underscore _attributes, you can't stop them, but that's okay, you don't have to be sympathetic when they shoot their foot off. Just slap them with a large halibut[1] and laugh. [1] Another Monty Python reference. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python getters and setters

2013-08-17 Thread Steven D'Aprano
atter what it is. You don't have to play a game of "Guess the method name" with every class you come across. # Yes, this is good, consistent design len(myrecord.field) len(obj.data) len(data.value) len(collection[key]) # No, this is crappy, inconsistent design myrecord.field_len()

Re: Python getters and setters

2013-08-17 Thread Steven D'Aprano
On Sun, 18 Aug 2013 00:52:06 +0200, Irmen de Jong wrote: > On 17-8-2013 19:18, Steven D'Aprano wrote: [...] >> How is this: >> >> obj.data_length() >> >> easier for the user than this? >> >> len(obj.data) >> >> > It's not

Re: Encapsulation unpythonic?

2013-08-19 Thread Steven D'Aprano
On Sun, 18 Aug 2013 18:15:10 +0100, Joshua Landau wrote: > On 17 August 2013 17:17, Steven D'Aprano > wrote: >> On Sat, 17 Aug 2013 05:26:32 -0700, fsaldan1 wrote: >>> how do I >>> deal with the fact that other programmers can easily alter the values >>

Re: How to I do this in Python ?

2013-08-19 Thread Steven D'Aprano
ck ? Alternative to what? If you mean, alternative to *not* storing it in the user's directory, then yes, it is :-) Drawbacks -- yes. I hate it when applications dump temporary files in my home directory. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Importing variables non-deterministic?

2013-08-19 Thread Steven D'Aprano
On Mon, 19 Aug 2013 10:16:36 +0200, Antoon Pardon wrote: > Op 19-08-13 09:45, Dave Angel schreef: >> Antoon Pardon wrote: >> >>> Op 17-08-13 17:01, Steven D'Aprano schreef: >>>> >>>> And here you re-import the name "y" from struct_g

Re: Importing variables non-deterministic?

2013-08-19 Thread Steven D'Aprano
d I expect that any future "no-rebind" constants will also be capable of being worked around. This is Python, not Haskell or Ada. But, naming convention or no naming convention, it is still valuable to get an exception if you accidentally rebind something that you shouldn't rebind. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: opposite of __init__.py

2013-08-19 Thread Steven D'Aprano
re your code finishes: def main(): do_this() do_that() if __name__ == '__main__': main() shutdown() If you care about code running even if an exception takes place: if __name__ == '__main__': try: main() finally: shutdown() -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Importing variables non-deterministic?

2013-08-19 Thread Steven D'Aprano
On Mon, 19 Aug 2013 16:57:37 +, Steven D'Aprano wrote: > def func(x): > ... > > # later > save_func = func > func = lambda x, y: do_stuff(x, 3*y)-4 result = > something_that_calls_func() > func = save_func > > > Nasty, horrible code, yes? But it&

Re: default python os x

2013-08-19 Thread Steven D'Aprano
and 2.6 on my laptop. "python1.5" etc unsets the startup file environment variable, since my startup file assumes 2.4 or better. "python3.4" points to a local copy in my home directory. Otherwise, python3.3, python3.2, etc. work as expected. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Importing variables non-deterministic?

2013-08-19 Thread Steven D'Aprano
On Mon, 19 Aug 2013 22:34:00 +0200, Antoon Pardon wrote: > Op 19-08-13 19:05, Steven D'Aprano schreef: > > >> I wish Python had stronger support for enforcing constantness, to whit, >> some way to say "you can't rebind or delete this name once it is >>

Re: Is this PEP-able? (syntax for functools.partial-like functionality)

2013-08-19 Thread Steven D'Aprano
r example, Enums are a common, and standard, feature in many programming languages. Enums will be introduced to Python in 3.4, but even they don't get special syntax. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Beginer of python,could I write a personal blog using cherrtpy?

2013-08-20 Thread Steven D'Aprano
/stable/appendix/success.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Basic Python Query

2013-08-21 Thread Steven D'Aprano
e, and you call one of its methods: instance = SomeClass() instance.method(extra, args) then Python automatically uses the instance as the "self" argument. This is equivalent to: SomeClass.method(instance, extra, args) # inside the method, self=instance except Python does it for you, instead of you needing to write it out in full like that. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation unpythonic?

2013-08-21 Thread Steven D'Aprano
On Wed, 21 Aug 2013 12:52:06 -0400, random832 wrote: > On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote: >> In this toy example, both parties are at fault: the author of Parrot >> for unnecessary data-hiding of something which is so obviously a useful >> piece of

Re: pydoc vs. non-def'd methods

2013-08-21 Thread Steven D'Aprano
here was between ham and eggs. I would much prefer to see that ham was just an alias: class Spam: def eggs(self): """eggs docstring""" pass ham = eggs which brings us back to the beginning of your post :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: New book: Python in Practice

2013-08-22 Thread Steven D'Aprano
ok's web page (http://www.qtrac.eu/pipbook.html) has the table of > contents and a link to a free PDF of Chapter 1 so you can see if it > appeals to you. The book's examples are also available for download from > that page. > > I hope you'll take a look:-) Looks good!

Re: Basic Python Query

2013-08-22 Thread Steven D'Aprano
On Thu, 22 Aug 2013 09:45:43 -0400, Ned Batchelder wrote: > So that I understand what's going on, what's the bad thing that happens > with a multi-part message? I would have thought that mail readers would > choose the preferred part, or is it something to do with the message > quoting? This is

Re: Basic Python Query

2013-08-22 Thread Steven D'Aprano
use. [...] > In summary, I find that modelling something to "use a thread" is much > clearer than modelling it as "is a thread". The rest of your arguments seem good to me, but not compelling. I think they effectively boil down to personal taste. I write lots of non-OOP code, but when it comes to threads, I prefer to subclass Thread. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python variable as a string

2013-08-23 Thread Steven D'Aprano
py> adict[key] = "whatever you like" py> adict {"['a', 'b', 'c', 'd']": 'whatever you like'} Or if you prefer: py> {key: "whatever"} {"['a', 'b', 'c', 'd']": 'whatever'} If you want something else, you'll need to explain more carefully what you want. > Or maybe i should do things differently? Possibly. What sort of things did you have in mind? :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Setting the value of True

2013-08-23 Thread Steven D'Aprano
e they are considered fundamental to the inner workings of Python, unlike mere builtins like len, map, etc. and therefore should be protected. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: can't get utf8 / unicode strings from embedded python

2013-08-23 Thread Steven D'Aprano
the characters you would like. * You may need to change the way data gets into your C++ Log function. If it expects bytes, you may need to use u"...".encode('utf-8') rather than just u"...". But since I don't understand how data is getting into your Log function, I can't be sure about this. I think that is everything. Does that fix your problem? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Fast conversion of numbers to numerator/denominator pairs

2013-08-23 Thread Steven D'Aprano
27;.join([str(digit) for digit in digits])) if sign: num = -num return num, 10**-exp which is faster, but not fast enough. Any suggestions? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Exception Handling Practices / Patterns

2013-08-24 Thread Steven D'Aprano
ame") else: handle_error() It's wrong for a couple of reasons: - just because the file exists, doesn't mean you can open it; - even if the file exists when you call the os.path.exists function, doesn't mean it will still exist a millisecond later when you try to open it. Hope this is helpful, -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Exception Handling Practices / Patterns

2013-08-24 Thread Steven D'Aprano
ept that the latter indicates a deliberate choice > rather than an indication of carelessness or laziness. > > A bare except: is a disservice to the next maintainer of the code. Do you know anyone who maintains code typed in the interactive interpreter? :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: List getting extended when assigned to itself

2013-08-24 Thread Steven D'Aprano
ing at index. If you wish to insert a sequence as a single object, you have two choices: you can use the list insert() method, or you can wrap the sequence in a list, and then use slice assignment: py> L = [1, 2, 3, 4, 5] py> L[2:4] = [L] py> L [1, 2, [...], 5] -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: python eval function

2013-08-25 Thread Steven D'Aprano
id of it, and use setattr like you have already been told: setattr(self, fieldName, fieldValue) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting request's source site

2013-08-26 Thread Steven D'Aprano
etc.. That would be the "referer" header in the HTTP request. (Note that it is an accidental misspelling of "referrer".) Including a referrer is not compulsory, so be prepared for it not to be available. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

<    65   66   67   68   69   70   71   72   73   74   >