Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-11 Thread Steven D'Aprano
On Tue, 11 Dec 2012 16:08:34 -0500, Dave Cinege wrote: > On Tuesday 11 December 2012 03:12:19 Steven D'Aprano wrote: > >> Is this intended as a ready-for-production class? > > For me, yes. In production code. > >> py> d = Thesaurus() >> py> d['

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-11 Thread Steven D'Aprano
On Tue, 11 Dec 2012 16:08:34 -0500, Dave Cinege wrote: > On Tuesday 11 December 2012 03:12:19 Steven D'Aprano wrote: > >> Is this intended as a ready-for-production class? > > For me, yes. In production code. > >> py> d = Thesaurus() >> py> d['

Re: Hollow square program

2012-12-12 Thread Steven D'Aprano
x27;t think that is acceptable here. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Steven D'Aprano
ve just won an award for Most Cognitive Dissonance Exhibited In The Shortest Time. I'm not sure how you can yell at somebody that Google users should be dead in one post, and then nine minutes later say this. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: samba 4 release

2012-12-12 Thread Steven D'Aprano
amba has provided secure, stable and fast file and print services for all clients using the SMB/CIFS protocol, such as all versions of DOS and Windows, OS/2, Linux and many others. Samba is an important component to seamlessly integrate Linux/Unix Servers and Desktops into Active Directory environm

Re: ANNOUNCE: Thesaurus - a recursive dictionary subclass using attributes

2012-12-12 Thread Steven D'Aprano
o magical and complicated to be interested in using it in production code as it stands now. [1] Well, technically there's another way: one might reimplement the functionality of super() in your own code, and avoid using super() while having all the usual joys of reinventing the wheel. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: samba 4 release

2012-12-12 Thread Steven D'Aprano
On Wed, 12 Dec 2012 17:18:43 -0700, Michael Torrie wrote: > Now if we could just get an Exchange replacement that actually doesn't > suck... But but but... if it didn't contain sufficient levels of suckage, it would hardly be a replacement for Exchange, would it?!?!? :-P --

Re: Using regexes versus "in" membership test?

2012-12-12 Thread Steven D'Aprano
ch line, or something else. Where I expect you *will* see a good benefit is: * you have many lines to search; * but only a few actually match the regex; * the regex is quite complicated, and needs to backtrack a lot; * but you can eliminate most of the "no match" cases with a simple substring match. If you are in this situation, then very likely you will see a big benefit from a two-pass search: for line in log: if any(substr in line for substr in list_of_substrings): # now test against a regex Otherwise, maybe, maybe not. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: why does dead code costs time?

2012-12-12 Thread Steven D'Aprano
health to you" "Best wishes" "Sincerest regards" only less formal. Does the Internet not work where you are? Googling for "define:cheers" or "definition cheers" should have answered that question. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

testing

2012-12-13 Thread Steven D'Aprano
Testing testing 1 2 3 4. I've sent at two posts that appear to have been eaten by the Great Usenet Monster. Will this fare any better? Time to find out. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Where to contribute Unicode General Category encoding/decoding

2012-12-13 Thread Steven D'Aprano
'a final quotation mark'), 'Pi': r('Punctuation, Initial', 'Initial_Punctuation', 'an initial quotation mark'), 'Po': r('Punctuation, Other', 'Other_Punctuation', 'a punctuation mark of other type'), 'Ps': r('Punctuation, Open', 'Open_Punctuation', 'an opening punctuation mark (of a pair)'), 'S' : r('Symbol', 'Symbol', 'Sc | Sk | Sm | So'), 'Sc': r('Symbol, Currency', 'Currency_Symbol', 'a currency sign'), 'Sk': r('Symbol, Modifier', 'Modifier_Symbol', 'a non-letterlike modifier symbol'), 'Sm': r('Symbol, Math', 'Math_Symbol', 'a symbol of mathematical use'), 'So': r('Symbol, Other', 'Other_Symbol', 'a symbol of other type'), 'Z' : r('Separator', 'Separator', 'Zl | Zp | Zs'), 'Zl': r('Separator, Line', 'Line_Separator', 'U+2028 LINE SEPARATOR only'), 'Zp': r('Separator, Paragraph', 'Paragraph_Separator', 'U+2029 PARAGRAPH SEPARATOR only'), 'Zs': r('Separator, Space', 'Space_Separator', 'a space character (of various non-zero widths)'), } del r Usage is then trivially the same as normal dict and attribute access: py> GC['Ps'].desc 'an opening punctuation mark (of a pair)' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: OOP noob question: Mixin properties

2012-12-13 Thread Steven D'Aprano
n self.render_to_response(data, cache, cache_timeout, cache_key) > > Then again, maybe the more functional approach is better for its > simplicity? I actually prefer a functional response, up to the point where I'm passing so many arguments to functions that I can't keep track of what's what. Then I refactor into a class. > Hopefully I'm not boring ya'll to death. :D No worries :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Running a python script under Linux

2012-12-13 Thread Steven D'Aprano
of getting Python 2.7, it runs under Python 2.4 and gives me system errors. When I run env directly, it ignores my alias: steve@ando ~]$ /usr/bin/env python -V Python 2.4.3 What am I doing wrong? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: os.system and subprocess odd behavior

2012-12-14 Thread Steven D'Aprano
> file3", shell = True) 0 py> os.system("cat < file1 > file4") 0 py> quit() [steve@ando ~]$ cat file2 hello world [steve@ando ~]$ cat file3 hello world [steve@ando ~]$ cat file4 hello world I have run this multiple times, as an unprivileged user, as the root user, and as sudo. It works perfectly every time. Please check your code. Perhaps you have over-simplified the problem. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: What are the minimum requirements to get a job in?

2012-12-14 Thread Steven D'Aprano
spective, but I don't think it is wise to hire somebody who is likely to leave for greener pastures just as you are starting to rely on them. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Unicode

2012-12-16 Thread Steven D'Aprano
r code. It gives indentation errors, you don't tell us what modules you're using, and you haven't reduced the example down to the critical parts that demonstrate the failure. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Pastebin [was: Trying to make a basic Python score counter in a game... will not count.]

2012-12-16 Thread Steven D'Aprano
te directly in the body of your email, chances are it is too large to expect people to debug for you. But you can try adding it as an attachment (.py, not .doc), and only if you can't do that for some reason, then maybe a paste bin is appropriate. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: python-daemon

2012-12-17 Thread Steven D'Aprano
On Sun, 16 Dec 2012 08:59:46 -0800, rurpy wrote: > Or you could repost from other than GG if you don't mind being a tool of > someone else's political agenda. We're all tools of someone's political agenda. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Unicode

2012-12-17 Thread Steven D'Aprano
code without the full traceback is like trying to read a book by reading only every third page. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Delete dict and subdict items of some name

2012-12-17 Thread Steven D'Aprano
l problem. Oh wait, I see you already know this! Sorry for the noise. *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Is it possible monkey patch like this?

2012-12-18 Thread Steven D'Aprano
;[z] Suppose you pass x=1, y={} so that x+y fails. What do you expect Python to do if you tell it not to stop at an exception? What will it print? What result should it return? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern-match & Replace - help required

2012-12-19 Thread Steven D'Aprano
, >decrypt(taxpayer.enc_name), >taxpayer.age, >taxpayer.occupation >FROM taxpayer WHERE (taxpayer.id IS NOT NULL);' > > Can somebody please help? Can you do this? stmnt = r_stmnt That should do what you are asking. If that doesn't solve your problem,

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread Steven D'Aprano
y pure accident, you lined up the "else" statement with the for loop, instead of what you needed: for line in tm: ... blah blah blah for word in words: if word in word_counts: # better name than "dict" ... blah blah blah else: ... > for word, count in dict.iteritems(): > print word + ":" + str(count) And this bit is okay too. Good luck! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern-match & Replace - help required

2012-12-19 Thread Steven D'Aprano
'ham') if offset != -1: lunch = lunch[:offset] + 'spam' + lunch[offset + len('ham'):] print(lunch) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Py 3.3, unicode / upper()

2012-12-19 Thread Steven D'Aprano
nother character By memory: s = "a"*10 s = s.replace("a", "b") or equivalent. Hardly representative of normal string processing, and likely to be the worst-performing operation on new Unicode strings. And yet even so, many people reported either a mild slow

Re: Data Driven Process

2012-12-20 Thread Steven D'Aprano
e tell you what button to click or command to give? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Data Driven Process

2012-12-20 Thread Steven D'Aprano
arcpy.mapping.MapDocument('CURRENT') > df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0] > df.zoomToSelectedFeatures() How do you expect to zoom to selected features if you have no selected features? Before this line, you need to select the feature you want to zoom t

Re: Strange effect with import

2012-12-20 Thread Steven D'Aprano
eal" code it's unfortunately not > possible to pass that number to whatever is going to use it in the > other file, I have to simulate a kind of global variable > shared between different files. Well, I find that hard to believe. "Not convenient"? I could believe

Re: Py 3.3, unicode / upper()

2012-12-20 Thread Steven D'Aprano
y one of *your* classes, methods, functions, modules and variables are using non-ASCII names, you will still use ASCII strings for built-in functions and standard library modules. > What should a Python user think, if he sees his strings are comsuming > more memory just because he uses non ascii characters WRONG! His strings are consuming just as much memory as they need to. You cannot fit ten thousand different characters into a single byte. A single byte can represent only 2**8 = 256 characters. Two bytes can only represent 65536 characters at most. Four bytes can represent the entire range of every character ever represented in human history, and more, but it is terribly wasteful: most strings do not use a billion different characters, and so use of a four-byte character encoding uses up to four times as much memory as necessary. You are imagining that non-ASCII users are being discriminated against, with their strings being unfairly bloated. But that is not the case. Their strings would be equally large in a Python wide-build, give or take whatever overhead of the string object that change from version to version. If you are not comparing a wide-build of Python to Python 3.3, then your comparison is faulty. You are comparing "buggy Unicode, cannot handle the supplementary planes" with "fixed Unicode, can handle the supplementary planes". Python 3.2 narrow builds save memory by introducing bugs into Unicode strings. Python 3.3 fixes those bugs and still saves memory. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Brython - Python in the browser

2012-12-20 Thread Steven D'Aprano
xt of the language you are using, not some other language. If you are using a DSL, then normal Python rules don't necessarily apply. <= in particular looks just like a left-pointing arrow and is an obvious candidate for overloading. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Pass and return

2012-12-21 Thread Steven D'Aprano
ement in, just to satisfy the compiler, you get the same result: > def test(): > pass Also a function which immediately exists and return None. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Brython - Python in the browser

2012-12-21 Thread Steven D'Aprano
and ugly? :-P -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Brython - Python in the browser

2012-12-22 Thread Steven D'Aprano
if we did so, it still wouldn't have anything to do with numeric division. > Taking a string modulo a tuple doesn't make any sense in itself, Taking an integer cross an integer doesn't make any sense if you haven't learned the meaning of the + operator. Why insist that o

Re: urllib.error.HTTPError: HTTP Error 403: Forbidden

2012-12-23 Thread Steven D'Aprano
ease do not try to screen-scrape Wikipedia. Instead, use their API for accessing pages. http://en.wikipedia.org/wiki/Wikipedia:Creating_a_bot -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to detect the character encoding in a web page ?

2012-12-24 Thread Steven D'Aprano
in their right mind. To say nothing of 15 year old websites that use a legacy encoding. And to support those, you may need to guess the encoding, and for that, chardetect.py is the solution. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Custom alphabetical sort

2012-12-24 Thread Steven D'Aprano
houldn't advertise what it is.) The OP's post was correctly labelled with an encoding, and not an obscure one: Content-Type: text/plain; charset=ISO-8859-1 which if I remember correctly is Latin-1. If your newsreader can't handle that, surely it should default to UTF-8, which

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread Steven D'Aprano
ument for *instance* methods, not class methods. For class methods, the conventional first argument is "cls", not "self". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread Steven D'Aprano
shared across instances, what Python users usually call an "instance attribute" or even just "attribute". As I see it, it is not Python being inconsistent. What do you consider is inconsistent by *avoiding* the use of "class variable" to mean an attribute or member attached to a class? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-26 Thread Steven D'Aprano
On Tue, 25 Dec 2012 16:19:21 -0800, Rick Johnson wrote: > On Tuesday, December 25, 2012 4:56:44 PM UTC-6, Steven D'Aprano wrote: > >> Rick, what makes you think that this is logically inconsistent? >> "Method" is the accepted name for functions attached to clas

Re: How to get time.strptime()?

2012-12-26 Thread Steven D'Aprano
ooked at the _strptime.py source code and nothing stands out to explain why the _strptime function might not be defined. So that seems like a question about mod_wsgi. I suggest you start here: http://code.google.com/p/modwsgi/wiki/WhereToGetHelp If you do get an answer, please post it here a

Re: How to get time.strptime()?

2012-12-26 Thread Steven D'Aprano
s sharp edge, and who should have been responsible to do so? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-26 Thread Steven D'Aprano
rgument on counter-factuals (assumptions about English language which are not, in fact, true) then even if your reasoning is utterly logical in every step, the conclusion is still dubious. [1] Ah who am I kidding? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the name of a function while defining it

2012-12-27 Thread Steven D'Aprano
one" and > "two". I'm afraid you're going to be disappointed. There is no possible way for one() and two() as shown above to report different names, because they are the same function object. py> two = lambda : "one" py> one = two py> one is two True py&g

Re: Finding the name of a function while defining it

2012-12-27 Thread Steven D'Aprano
Spanish Inquisition!" ... py> name = "spam" py> func = globals()[name] py> func() 'NOBODY expects the Spanish Inquisition!' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the name of a function while defining it

2012-12-27 Thread Steven D'Aprano
return x[0][2] def invert(n): if n != 0: return 1/n else: me = get_current_function_name() raise ZeroDivisionError('divide by zero error in func %s' % me) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the name of a function while defining it

2012-12-27 Thread Steven D'Aprano
On Thu, 27 Dec 2012 07:32:16 -0600, Tim Chase wrote: > Depending on where in the code you are, the same function object also > has a local name of "fn". It's madness until you understand it, and > then it's beauty :) "This is madness!" "N

Re: Finding the name of a function while defining it

2012-12-27 Thread Steven D'Aprano
On Thu, 27 Dec 2012 10:09:01 -0500, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> On Wed, 26 Dec 2012 23:46:31 -0800, Abhas Bhattacharya wrote: >> >> >> > two = lamba : &quo

Re: New to python, do I need an IDE or is vim still good enough?

2012-12-27 Thread Steven D'Aprano
personal preference for a specific IDE, then good for them, I certainly wouldn't tell them that they shouldn't use it. [1] KDE 3 only. KDE 4 is unspeakable. Gedit from Gnome 2 is almost a good substitute. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: noob can't install python modules/scripts

2012-12-28 Thread Steven D'Aprano
hing else. You need to run the "easy_install BeautifulSoup4" command from the system shell, not Python. Try that, and if there's another error, please copy and paste the exact command you used, and the full error message. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Confused about logger config from within Python (3)

2012-12-28 Thread Steven D'Aprano
do so is with the unittest module: # after defining the class above import unittest unittest.main() which then prints: py> unittest.main() No handlers could be found for logger "__main__" . -- Ran 1 test in 0.045s

Re: Confused about logger config from within Python (3)

2012-12-28 Thread Steven D'Aprano
t level is WARNING, which means that only events of this level and above will be tracked, unless the logging package is configured to do otherwise. [end quote] http://docs.python.org/dev/howto/logging.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: dict comprehension question.

2012-12-31 Thread Steven D'Aprano
s, but they can't do everything, and very often even if they can do something they shouldn't because it makes the code inefficient or unreadable. There's nothing wrong with a two or three liner. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: father class name

2012-12-31 Thread Steven D'Aprano
ethod. I don't believe that talking about the constructor __new__ is so complicated that we should ignore the actual error and go of on a wild- goose chase about the initialiser __init__, especially since adding an __init__ method to the class *won't solve the problem*. Sorry Chris, I t

Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Steven D'Aprano
y when I change a lot of my mappings. It seems to me, that by the time I would have searched for the right command to use, decided which of the (multiple) matching commands is the right one, then used the command, it would have been quicker and less distracting to have just done the editing by hand. But now I'm just repeating myself. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: New to python, do I need an IDE or is vim still good enough?

2012-12-31 Thread Steven D'Aprano
the line number. Assuming that your functions and methods are not obnoxiously huge, I think having a good class browser which lets you jump directly to functions or methods is *far* more useful than line numbers, in this context. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: ignore case only for a part of the regex?

2012-12-31 Thread Steven D'Aprano
t, then match: py> 'Straße'.casefold() 'strasse' Curiously, there is an uppercase ß in old German. In recent years some typographers have started using it instead of SS, but it's still rare, and the official German rules have ß transform into SS and vice versa. I

Re: pygame - importing GL - very bad...

2013-01-01 Thread Steven D'Aprano
pylint may still complain, but you can ignore it. By deleting the name "format", that will unshadow the builtin format. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Handling Special characters in python

2013-01-01 Thread Steven D'Aprano
96 to an n-dash character, you need to identify the encoding to use. (Aside: and *stop* using it. It is 2013 now, anyone who is not using UTF-8 is doing it wrong. Legacy encodings are still necessary for legacy data, but any new data should always using UTF-8.) CP 1252 is one possible encoding,

Re: numpy has got newtonsmethod?

2013-01-01 Thread Steven D'Aprano
hile being in scipy source directory; please exit the scipy source tree first, and relaunch your python interpreter. Do you understand what a source directory is? It is a directory (a folder) with the source code in it. Leave the scipy directory, and re- start Python, then try importing sci

Re: pygame - importing GL - very bad...

2013-01-01 Thread Steven D'Aprano
On Wed, 02 Jan 2013 00:49:36 +0100, someone wrote: > On 01/01/2013 12:49 PM, Steven D'Aprano wrote: > > On Tue, 01 Jan 2013 12:00:32 +0100, someone wrote: > > > >> See this code (understand why I commented out first line): > >> > >> # from OpenG

Re: pylint, was Re: pygame - importing GL - very bad...

2013-01-02 Thread Steven D'Aprano
explicitly going against PEP 8. > You shouldn't have to use those underscores very often. After all, > there is seldom a need for a non-const global value, right? Don't think > of it as a pylint problem, but as a hint from pylint that perhaps you > should use fewer globals. That at least is good advice. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Important questions about __future__

2013-01-03 Thread Steven D'Aprano
__.py)? It's defined in the C source code for the CPython compiler. Look in future.c. http://hg.python.org/cpython/file/944e86223d1f/Python/future.c -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Question on for loop

2013-01-03 Thread Steven D'Aprano
e it as "var[0]", "var[1]" etc. var = ['banana', 'apple', 'mango'] print var[0] # prints 'banana' print var[1] # prints 'apple' print var[2] # prints 'mango' Of course "var" is not a very good variable name. "fruit" or "fruits" would be better. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Yet another attempt at a safe eval() call

2013-01-03 Thread Steven D'Aprano
Error("'import' prohibited") for c in '_"\'.': if c in expr: raise ParseError('prohibited char %r' % c) if len(expr) > 120: raise ParseError('expression too long') globals = {'__builtins__': None} locals = symbolTable return eval(expr, globals, locals) # fingers crossed! I can't think of any way to break out of these restrictions, but that may just mean I'm not smart enough. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Yet another attempt at a safe eval() call

2013-01-04 Thread Steven D'Aprano
> > Will ast.literal_eval do what you want? No. Grant needs to support variables, not just literal constants, hence the symbol table. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Need a specific sort of string modification. Can someone help?

2013-01-06 Thread Steven D'Aprano
+1 QOTW Thank you for sharing this with us. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Numpy outlier removal

2013-01-06 Thread Steven D'Aprano
s://secure.graphpad.com/guides/prism/6/statistics/index.htm http://www.webapps.cee.vt.edu/ewr/environmental/teach/smprimer/outlier/outlier.html http://stats.stackexchange.com/questions/38001/detecting-outliers-using-standard-deviations -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Numpy outlier removal

2013-01-06 Thread Steven D'Aprano
On Mon, 07 Jan 2013 02:29:27 +, Oscar Benjamin wrote: > On 7 January 2013 01:46, Steven D'Aprano > wrote: >> On Sun, 06 Jan 2013 19:44:08 +, Joseph L. Casale wrote: >> >>> I have a dataset that consists of a dict with text descriptions and >>>

Re: Over 30 types of variables available in python ?

2013-01-07 Thread Steven D'Aprano
namedtuple; There is one standard built-in mapping type: dict plus at least two more in the standard library, defaultdict and ordereddict; etc. You can read the docs more easily than I can copy the types out. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2013-01-07 Thread Steven D'Aprano
ht re.match('h.$', 'hbxihi') will match ‘hi’ ,but it does not .so > why ? re.match only matches at the *start* of the string, so "h.$" tries to match: * start of string * literal h * any character * end of string You want re.search, which will search the en

Re: what’s the difference between socket.send() and socket.sendall() ?

2013-01-07 Thread Steven D'Aprano
or annoy those you are asking for help. (Apologies to anyone on the "tutor" mailing list who has already seen this message earlier today.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

[Offtopic] Line fitting [was Re: Numpy outlier removal]

2013-01-07 Thread Steven D'Aprano
ren't there, or missing the patterns which are there. At best line fitting by eye is prone to honest errors; at worst, it is open to the most deliberate abuse. We have eyes and brains that evolved to spot the ripe fruit in trees, not to spot linear trends in noisy data, and fit

Re: [Offtopic] Line fitting [was Re: Numpy outlier removal]

2013-01-07 Thread Steven D'Aprano
asonable by eyeballing it. [1] Or if your data is so accurate and noise-free that you hardly have to care about errors, since there clearly is one and only one straight line that passes through all the points. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [Offtopic] Line fitting [was Re: Numpy outlier removal]

2013-01-07 Thread Steven D'Aprano
On Tue, 08 Jan 2013 06:43:46 +1100, Chris Angelico wrote: > On Tue, Jan 8, 2013 at 4:58 AM, Steven D'Aprano > wrote: >> Anyone can fool themselves into placing a line through a subset of non- >> linear data. Or, sadly more often, *deliberately* cherry picking fake >&

Re: [Offtopic] Line fitting [was Re: Numpy outlier removal]

2013-01-08 Thread Steven D'Aprano
ve a line pointing more or less in the right direction. But for anything where accuracy is required, line fitting by eye is down in the pits of things not to do, right next to "making up the answers you prefer". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [Offtopic] Line fitting [was Re: Numpy outlier removal]

2013-01-08 Thread Steven D'Aprano
t;Pfff, facts, you can prove anything that's even remotely true with facts!" -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Regex not matching a string

2013-01-09 Thread Steven D'Aprano
example code that demonstrates your problem. Or, in this case, *fails* to demonstrate the problem. import re haystack = "aaa\naaa /*xxxThis is a test comment \nxxx*/aaa\naaa\n" needle = "This is a test comment" pattern = re.compile(r'/\*.*?'+ needle + '.*?\*/&#x

Re: How to call wget by python ?

2013-01-09 Thread Steven D'Aprano
would do but using only Python. https://duckduckgo.com/?q=python%20wget Or you could search for "python call external command" and then use wget as that external command. https://duckduckgo.com/?q=python%20call%20external%20command -- Steven -- http://mail.python.org/mailman/listinfo/python-list

RIse and fall of languages in 2012

2013-01-09 Thread Steven D'Aprano
number 8: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: RIse and fall of languages in 2012

2013-01-10 Thread Steven D'Aprano
t feeling." If you are going to criticise TIOBE's methodology, and then make your own claims for language popularity, you really need to demonstrate that your methodology is better. > Javascript > may not be glamorous but it is *the* glue that makes the web run. And web development is a tiny fraction of all software development. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Probabilistic unit tests?

2013-01-10 Thread Steven D'Aprano
methods. Write your own function to decide whether or not something passed, then count how many times it passed: count = 0 for n in range(5): count += self.run_some_test() # returns 0 or 1, or a fuzzy score if count < some_cut_off: self.fail() -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: pylint or similar to test version-specific language constructs?

2013-01-11 Thread Steven D'Aprano
operator will fail, without any need for a separate > test. You don't even need tests for the code that includes the ternary operator. The module simply won't compile in Python 2.4, you get a SyntaxError when you try to import it or run it. You don't need PyLint to check for *illegal syntax*. Python already does that. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Module access syntax

2013-01-11 Thread Steven D'Aprano
rt lib::gui::tkinter::dialogs.SimpleDialog as Blah Before thinking about the syntax, you need to think about the behaviour, identify what actual problem you hope to solve, and how you hope to solve it. Not just throw random syntax around and hope that it's "obvious". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Probabilistic unit tests?

2013-01-11 Thread Steven D'Aprano
y, it should generate approximately equal numbers of "male" and "female" values. So he writes a unit test to check that the numbers are roughly equal. This is an appropriate test, although as I already suggested earlier, unit tests are not well suited for non-deterministic testing. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Module access syntax

2013-01-11 Thread Steven D'Aprano
a module as a singleton, I need to use one syntax; if I use a custom type as a singleton, I have to use different syntax. Whichever choice I make *today*, if the implementation changes, the required syntax changes and my code will break. [1] Well, almost. There are ways to accidentally or deliberately confuse the import machinery. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Module access syntax

2013-01-11 Thread Steven D'Aprano
whether it is a function, a method, a class or something else. The implementation could change, and you need not care. If you actually do care what the type of simpledialog is, you can find out easily: type(lib.gui.simpledialog) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Python training "text movies"

2013-01-12 Thread Steven D'Aprano
tbird.net/larks/tmovies.html For the benefit of those who don't have web access at the moment, or who don't like to click on random links they don't know anything about, would you like to say a few words describing what "text movies" are, and how you think these m

Re: Subgraph Drawing

2013-01-13 Thread Steven D'Aprano
It will take time. Calculations don't just happen instantly, the more work you have to do the longer they take. The last alternative is to ask on a specialist numpy list. But I expect they will probably tell you the same thing. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Subgraph Drawing

2013-01-13 Thread Steven D'Aprano
On Sun, 13 Jan 2013 20:01:21 -0800, subhabangalore wrote: > there are other solution of converting back the matrix to graph should I > try that? Yes. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart (Terminolgy): "Class"

2013-01-14 Thread Steven D'Aprano
this one is TKO in round 3. A template is certainly not correct for class-based OOP languages like Python, since it implies *copying*. It might be more appropriate for prototype-cased OOP languages like Javascript. [...] > Now since "methods" and "functions" (PyWart on these terms coming soon!) Oh I can barely contain my excitement. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Module access syntax

2013-01-14 Thread Steven D'Aprano
On Sun, 13 Jan 2013 21:22:57 -0800, Rick Johnson wrote: > On Saturday, January 12, 2013 12:45:03 AM UTC-6, Steven D'Aprano wrote: >> On Fri, 11 Jan 2013 20:34:20 -0800, Rick Johnson wrote: >> > [...] >> So what do you do for, say, os.path? According to the first

Re: PyWart (Terminolgy): "Class"

2013-01-14 Thread Steven D'Aprano
chool follows the "Don't feed the trolls" > motto and ignores him, the other trolls him right back. I object to that characterisation. I am not dishonestly making provocative statements when I engage with Rick. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: strace of python shows nonsense

2013-01-14 Thread Steven D'Aprano
gt; site-packages that does not exist? Subdirs of site-packages that are not > included in sys.path?) What is python doing there, and why? And, more > importantly, how can this be corrected? What's the value of the environment variable PYTHONPATH? Do you have a PYTHONSTARTUP s

Re: code explanation

2013-01-14 Thread Steven D'Aprano
er method simply looks up an attribute with the same name, and calls it as a function with whatever args and kwargs it gets. Does this help? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart (Terminolgy): "Class"

2013-01-15 Thread Steven D'Aprano
> dict_ = {} py> thingy = type(name, bases, dict_) py> isinstance(thingy, type) True py> thingy Classes are instances of type. That is reality in Python. Classes are objects just like ints and strings and lists. This is a fundamental design choice of Python. Deal with it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a more elegant way to handle determing fail status?

2013-01-15 Thread Steven D'Aprano
that are etiher None, or the number of tests that were > failed. Why set them to None when no tests failed? If no tests failed, why not just use 0? That is, instead of the counters being "the number of failures, or None", they could be "the number of failures". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Exception error paths far too verbose

2013-01-16 Thread Steven D'Aprano
ath and just pay attention to the file name. If you don't know which directory the file is in, printing the full path is essential. On the other hand, abbreviating the path gains you practically nothing when you know where the file is, and costs you a lot when you don't. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Using inner dict as class interface

2013-01-16 Thread Steven D'Aprano
e a it was the dict d. Then make it a dict: class C(dict): def some_other_methods(self): pass my_dict = C(key="value") # or C({"key": "value"}) print len(my_dict) print my_dict['key'] my_dict.some_other_methods() -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: To make a method or attribute private

2013-01-16 Thread Steven D'Aprano
e with a single underscore > indicates that the variable should be treated as > ‘private’. ... Please do not send HTML emails to this newsgroup. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Param decorator - can you suggest improvements

2013-01-17 Thread Steven D'Aprano
NTINEL = object() def param(arg=SENTINEL): nonlocal default if arg is SENTINEL: return default else: default = arg return arg if name is not None: param.__name__ = name return param -- Steven -- http://mail.python.org/mailman/listinfo/python-list

<    7   8   9   10   11   12   13   14   15   16   >