Re: object.enable() anti-pattern

2013-05-08 Thread Duncan Booth
d a separate cleanup stack and objects that require cleanup were pushed onto that stack after being fully constructed but before calling the initialisation that required cleanup. See http://www.developer.nokia.com/Community/Wiki/Two-phase_construction -- Duncan Booth -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is regex so slow?

2013-06-19 Thread Duncan Booth
skip to checking the 6th and then the 9th. It doesn't have to touch the intervening characters at all. Or as the source puts it: it's a mix between Boyer-Moore and Horspool, with a few more bells and whistles on the top. Also the regex library has to do a whole lot more than just figu

Re: Callable or not callable, that is the question!

2013-07-12 Thread Duncan Booth
and a utility method rather than just one or the other and also where you couldn't just have both. If you can persuade me that you need _handle_bool as both a static method and a utility function, you probably also need to explain why you can't just use both: class Pa

Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Duncan Booth
t Google's fault: they can't ignore the forwarding step otherwise spammers could bypass SPF simply by claiming to be forwarding the emails. It is simply a limitation of the SPF protocol. Fortunately they only use SPF as one indicator so real messages still get through. -- Duncan Booth -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Duncan Booth
Chris Angelico wrote: > On Tue, Jul 23, 2013 at 6:06 PM, Duncan Booth wrote: >> I have a very common situation where an overly strict SPF may cause >> problems: >> >> Like many people I have multiple email addresses which all end up in >> the same inbox. Th

Re: Dictless classes

2012-07-03 Thread Duncan Booth
> that every class will have a __dict__, and I wonder whether that is a > safe assumption. I believe so. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: How to safely maintain a status file

2012-07-09 Thread Duncan Booth
database once and then write out your status every few seconds. import sqlite3 con = sqlite3.connect('status.db') ... with con: cur = con.cursor() cur.execute('UPDATE ...', ...) and similar code to restore the status or create required tables on

Re: code review

2012-07-16 Thread Duncan Booth
names. Albert raised the subject of Algol 68 which if I remember correctly used := for assignment and = to bind names (although unlike Python you couldn't then re-bind the name to another object in the same scope). -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Error

2012-07-30 Thread Duncan Booth
drop you into the debugger so you can examine what's going on in more detail. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: is implemented with id ?

2012-09-06 Thread Duncan Booth
nsactions are comitted (or aborted). This means that global objects can be safely read from multiple threads without any semaphore locking. See http://mail.python.org/pipermail/pypy-dev/2012-September/010513.html -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-10 Thread Duncan Booth
are created. For the comparison to be the limiting factor you have to be doing a lot of comparisons on the same string (otherwise creating the string would be the limiting factor), so at the expense of a single dictionary insertion when the string is created you can get guaranteed O

Re: Comparing strings from the back?

2012-09-11 Thread Duncan Booth
trings are interned, if s is not t then s != t as well". Right if the strings differ only in the last character, but the rest of this thread has been about how, for random strings, the not-equal case is O(1) as well. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-11 Thread Duncan Booth
;t think you've misunderstood how it work, but so far as I can see the code doesn't attempt to short circuit the "not equal but interned" case. The comparison code doesn't look at interning at all, it only looks for identity as a shortcut. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Decorators not worth the effort

2012-09-14 Thread Duncan Booth
method itself and nowhere else. Alternatively use named values for different categories of timeouts and adjust them on startup so instead of a default of `timeout= 15` you would have a default `timeout=MEDIUM_TIMEOUT` or whatever name is appropriate. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: 'indent'ing Python in windows bat

2012-09-20 Thread Duncan Booth
is is a CMD script python -x %~f0 "%1" echo Back in the CMD script goto :eof """ import sys print("Welcome to Python") print("Arguments were {}".format(sys.argv)) print("Bye!") You can put the Python code either before or after the triple-quote string containing the CMD commands, just begin the file with a goto to skip into the batch commands and end them by jumping to eof. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Java singletonMap in Python

2012-09-24 Thread Duncan Booth
e cases in Java where you have a method that takes a map as an argument and you want to pass in a map with a single kep/value pair. In that case it lets you replace 3 lines of Java with 1. e.g. from the comments: "If you have a simple select statement like "select foo from bar where id = :ba

Re: + in regular expression

2012-10-05 Thread Duncan Booth
:= concatenation | basic-re concatenation ::= simple-re basic-re basic-re ::= element | element quantifier element ::= group | nc-group | "." | "^" | "$" | char | charset quantifier = "*" | "+" | "?" | "{" NUMBER "}" | &q

Re: + in regular expression

2012-10-09 Thread Duncan Booth
most of the others in existence) tend more to the spaghetti code than following a grammar (_parse is a 238 line function). So I think it really is just trying to match existing regular expression parsers and any possible grammar is an excuse for why it should be the way it is rather than

Re: Insert item before each element of a list

2012-10-09 Thread Duncan Booth
old list slicing: >>> x = [1,2,3] >>> y = ['insertme']*(2*len(x)) >>> y[1::2] = x >>> y ['insertme', 1, 'insertme', 2, 'insertme', 3] -- Duncan Booth -- http://mail.python.org/mailman/listinfo/python-list

Re: portable unicode literals

2012-10-16 Thread Duncan Booth
ork in 3.1 and 3.2 there is the uprefix import hook: https://bitbucket.org/vinay.sajip/uprefix -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python interactive help()

2012-10-19 Thread Duncan Booth
ented under 'built-in functions'. http://docs.python.org/library/functions.html#help -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Testing against multiple versions of Python

2012-10-19 Thread Duncan Booth
don't > remembers. I do not see anything on PyPI. Any advice is welcome! > Not exactly what you asked for, but if you clone https://github.com/collective/buildout.python then a single command will build Python 2.4, 2.5, 2.6, 2.7, 3.2, and 3.3 on your system. -- Duncan Booth h

Re: Add if...else... switch to doctest?

2012-10-19 Thread Duncan Booth
parate functions: if sys.platform=='win32': def function(): """ >>> function() [1, 2] """ return [1, 2] else: def function(): """ >>> function() [1, 2, 3]

Re: Python interactive help()

2012-10-19 Thread Duncan Booth
Mark Lawrence wrote: > On 19/10/2012 09:56, Duncan Booth wrote: >> Mark Lawrence wrote: >> >>> Good morning/afternoon/evening all, >>> >>> Where is this specific usage documented as my search engine skills have >>> let me down? By this I mea

Re: Float to String "%.7e" - diff between Python-2.6 and Python-2.7

2012-10-30 Thread Duncan Booth
calhost ~]$ /opt/local/bin/python2.6 -c "print('%.20e'% 2.096732150e+02,'%.7e'%2.096732150e+02)" ('2.096732149009e+02', '2.0967321e+02') What do you get printing the value on 2.6 with a '%.20e' format? I seem to remember that 2.7 rewrote float parsing because previously it was buggy. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Haskell -> Python

2012-11-03 Thread Duncan Booth
): yield [h]+tail for t in options(tail): yield [head]+t For a more 'functional' version there is also the Python 3.3 variant: def options(heaps): if not heaps: return [] head, *tail = heaps yield from ([h]+tail for h in range(head)) yield from ([he

Re: isinstance(.., file) for Python 3

2012-11-08 Thread Duncan Booth
her checking types at all? def foo(file_or_string): try: data = file_or_string.read() except AttributeError: data = file_or_string ... use data ... -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple Question regarding running .py program

2012-11-22 Thread Duncan Booth
the default lockscreen widget swipe left from the lockscreen until you get to a page with only a '+', add the new widget there, then long press that widget and drag it to be the rightmost page. Then you should be sorted just so long as you don't have any friends with December

Re: how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread Duncan Booth
option so that if the certificate ever does change in the future the command will fail rather than prompting. Alternatively use --non-interactive --trust-server-cert to just accept any old server regardless what certificate it uses, but be aware that this impacts security. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread Duncan Booth
ou use (if the svn server is also used by other machines then connect to it using the external hostname rather than localhost). Or just use http:// configured to allow access through localhost only. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: re.search when used within an if/else fails

2012-11-29 Thread Duncan Booth
xpands to the next multiple of 8 spaces. >>> if 1: ... print "yes" # space + tab ... print "no" # eight spaces ... yes no If tab expanded to exactly 8 spaces the leading space would have forced an indentation error, but it didn't. -- Duncan Booth

Re: Problem with calling function from dll

2012-12-13 Thread Duncan Booth
c_int)] _GetComputerNameW.restype = c_int def GetComputerName(): buf = create_unicode_buffer(255) len = c_int(255) if not _GetComputerNameW(buf, len): raise RuntimeError("Failed to get computer name") return buf.value[:len.value] print GetComputerName() -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Python USB control on Windows 7?

2012-12-21 Thread Duncan Booth
In this year's Christmas Raffle at work I won a 'party-in-a-box' including USB fairy lights. They sit boringly on all the time, so does anyone know if I can toggle the power easily from a script? My work PC is running Win7. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pass and return

2012-12-21 Thread Duncan Booth
atic way is to use a doc-string as the only body, that way you can also explain why you feel the need for an empty function. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Brython - Python in the browser

2012-12-21 Thread Duncan Booth
e.tostring(snippet) 'Hello world' > > With the tree syntax proposed in Brython it would just be > > doc <= DIV('hello '+B('world')) > > If "pythonic" means concise and readable, which one is more pythonic ? > The one that doesn't do unexpected things with operators. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python USB control on Windows 7?

2012-12-23 Thread Duncan Booth
Chris Angelico wrote: > On Sun, Dec 23, 2012 at 6:28 PM, Tim Roberts wrote: >> Duncan Booth wrote: >>> >>>In this year's Christmas Raffle at work I won a 'party-in-a-box' >>>including USB fairy lights. >>> >>>They sit borin

Re: Over 30 types of variables available in python ?

2013-01-07 Thread Duncan Booth
chaouche yacine wrote: > > booleans > ints, floats, longs, complexes > strings, unicode strings > lists, tuples, dictionaries, dictionary views, sets, frozensets, > buffers, bytearrays, slices functions, methods, code > objects,modules,classes, instances, types, nulls (there is exactly one > obj

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

2013-01-10 Thread Duncan Booth
access your {l[1]}. {l[0]} people might say {prog.NAME} has no {tc.no}.''').format(prog=prog, l=l, tc=tc) if hasattr(prog, 'VERSION'): print 'But I challenge them to write code {tc.way} clean without it

Re: handling return codes from CTYPES

2013-01-21 Thread Duncan Booth
still get the same > response (65535). Tell the function what type to return before you call it: InitScanLib = sLib.InitScanLib InitScanLib.restype = c_short See http://docs.python.org/2/library/ctypes.html#return-types You can also tell it what parameter types to expect which will make calling it simpler. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Else statement executing when it shouldnt

2013-01-22 Thread Duncan Booth
tp://docs.python.org/2/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Else statement executing when it shouldnt

2013-01-22 Thread Duncan Booth
Duncan Booth wrote: > Matching 'if' or 'for' or 'while'. > or of course 'try'. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: mysql solution

2013-01-24 Thread Duncan Booth
counter.page = %s AND visitors.host=%s''', (useros, browser, date, page, host)) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Python regular expression syntax is not intuitive.

2012-01-25 Thread Duncan Booth
ntax, it originated with Perl. Try complaining to a Perl group instead. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: Python regular expression syntax is not intuitive.

2012-01-25 Thread Duncan Booth
ideas support > our ideology. Perl style regexes are not Pythonic. They violate our > philosophy in too many places. > Or we could implement de-facto standards where they exist. *plonk* -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: except clause syntax question

2012-01-31 Thread Duncan Booth
A, B, C] exceptions[1:1] = exceptions, ... except exceptions as e: # argh! Abitrarily nested tuples of exceptions cannot contain loops so the code simply needs to walk through the tuples until it finds a match. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: frozendict

2012-02-09 Thread Duncan Booth
sort the items before putting them in a tuple, otherwise how do you handle two identical dicts that return their items in a different order? -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: frozendict

2012-02-09 Thread Duncan Booth
Nathan Rice wrote: > On Thu, Feb 9, 2012 at 5:33 AM, Duncan Booth > wrote: >> Nathan Rice wrote: >> >>> I put dicts in sets all the time.  I just tuple the items, but that >>> means you have to re-dict it on the way out to do anything useful >>> wit

Re: frozendict

2012-02-09 Thread Duncan Booth
} >>> dict(dict.fromkeys('me')) {'m': None, 'e': None} >>> dict(dict(dict.fromkeys('me'))) {'e': None, 'm': None} -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-14 Thread Duncan Booth
ndary bacterial infections, but they are not effective against viruses. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-15 Thread Duncan Booth
Rick Johnson wrote: > On Feb 14, 5:31 am, Duncan Booth wrote: >> Rick Johnson wrote: >> > BS! With free healthcare, those who would have allowed their immune >> > system fight off the flu, now take off from work, visit a local >> > clinic, and get pumped fu

Re: OT: Entitlements [was Re: Python usage numbers]

2012-02-15 Thread Duncan Booth
Arnaud Delobelle wrote: > On 15 February 2012 09:47, Duncan Booth > wrote: >> Rick Johnson wrote: > [...] > > Perhaps it's a bit presumptuous of me but... > > It's tempting to react to his inflammatory posts, but after all Rick > is a troll and ex

Re: #line in python

2012-02-20 Thread Duncan Booth
ers in the whole file: see http://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html for some code that shows you what's in a .pyc -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: #line in python (dirty tricks)

2012-02-20 Thread Duncan Booth
foo() File "foo.bar", line 47, in foo File "evil.txt", line 667, in bar Evil line 667 RuntimeError: oops -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Please verify!!

2012-02-24 Thread Duncan Booth
ng at all like Notepad. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: sum() requires number, not simply __add__

2012-02-24 Thread Duncan Booth
result for some user defined types and never having converted my code to C I have no idea whether or not the performance for the intended case would be competitive with the builtin sum though I don't see why it wouldn't be. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: [RELEASED] Python 3.3.0 alpha 1

2012-03-05 Thread Duncan Booth
something about that. Also the what's new doesn't mention PEP 414 although the release page does. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python is readable

2012-03-15 Thread Duncan Booth
as text editors or indeed humans) to understand. A little bit of redundancy in the grammar is seen as a good way to minimise errors. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python is readable

2012-03-16 Thread Duncan Booth
argument which can be used to conditionally acquire the lock and return a boolean indicating success or failure. When used inside a `with` statement you can't pass in the optional argument so it acquires it unconditionally but still returns the success status which is either True or it never r

Re: string interpolation for python

2012-04-02 Thread Duncan Booth
t;Are you $name$?" > Template: >>>> Template("Are you $name?").substitute(name=name) > It is three to one in compactness, what a magic 3! You can avoid the duplication fairly easily: >>> name='Peter' >>> 'Are you {name}?&#

Re: Python Gotcha's?

2012-04-05 Thread Duncan Booth
Steven D'Aprano wrote: > JSON expects double-quote marks, not single: > v = json.loads("{'test':'test'}") fails > v = json.loads('{"test":"test"}') succeeds > You mean JSON expects a string with valid

Re: pyjamas / pyjs

2012-05-04 Thread Duncan Booth
rough gmane in which case I still need to sign up to the list to post but definitely don't want to receive emails. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Help doing it the "python way"

2012-05-24 Thread Duncan Booth
for x, y in coords: yield x, y-1 yield x, y+1 new_coords = list(vertical_neighbours(coords)) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Hashable object with self references OR how to create a tuple that refers to itself

2012-06-18 Thread Duncan Booth
empting to add the tuple to itself you've broken the rules for reference counting. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Updated blog post on how to use super()

2011-06-02 Thread Duncan Booth
to the method in Base. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: how to avoid leading white spaces

2011-06-08 Thread Duncan Booth
e there is that the 're' module was imported in both cases: C:\Python27>python -c "import sys; print('re' in sys.modules)" True C:\Python32>python -c "import sys; print('re' in sys.modules)" True Steven is right to assert that there&#x

Re: how to inherit docstrings?

2011-06-09 Thread Duncan Booth
3.2.3 20030502 (Red Hat Linux 3.2.3-52)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class C(object): ..."Hello world" ... >>> C.__doc__ = "whatever" Traceback (most recent call last): File "", line 1, in ? TypeError: attribute '__doc__' of 'type' objects is not writable >>> -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: how to write to registry without admin rights on win vista/7

2011-06-24 Thread Duncan Booth
n everything works. > > How can I do it to write to registry without "Run As Admin" ? This might give you some pointers: http://stackoverflow.com/questions/130763/request-uac-elevation-from-within-a-python-script -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: what's the big deal for print()

2011-06-27 Thread Duncan Booth
get the same result in Python 2, you have to use sys.stdout.write (). > That isn't entirely true: you could set the `softspace` attribute on sys.stdout, but that is even messier. >>> def foo(): ... print 1, ... sys.stdout.softspace=0 ... print 2, ... sys.stdout.softspace=0 ... print 3 ... >>> foo() 123 -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Using decorators with argument in Python

2011-06-30 Thread Duncan Booth
creates a decorator factory from a decorator and passes its arguments through to the underlying decorator. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-18 Thread Duncan Booth
no > lower-case and a 40-column limit > on the TV display. > But you try and tell the young > people today that... > and they won't believe ya'. Acorn System One: 9 character 7 segment led display and 25 key keypad, 1Kb RAM, 512 bytes ROM. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: __set__ method is not called for class attribute access

2011-08-05 Thread Duncan Booth
_metaclass__ = MyMeta y = 5 >>> MyClass.x = 20 Updating var "x" >>> MyClass.x Retrieving var "x" 20 However note that if you do this you can access "x" only directly on the class not on an instance of the class: >>> MyClass().x Traceback (most recent call last): File "", line 1, in MyClass().x AttributeError: 'MyClass' object has no attribute 'x' -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: __set__ method is not called for class attribute access

2011-08-07 Thread Duncan Booth
Peter Otten <[email protected]> wrote: > Duncan Booth wrote: > >> The descriptor protocol only works when a value is being accessed or set >> on an instance and there is no instance attribute of that name so the >> value is fetched from the underlying class. > &

Re: allow line break at operators

2011-08-10 Thread Duncan Booth
guages it might be legal, but this is Python. without the parentheses it is a syntax error. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: __set__ method is not called for class attribute access

2011-08-10 Thread Duncan Booth
can be got or set even when > they shadow an instance attribute. You're (probably) thinking of > __getattr__ which isn't invoked when an instance attribute exists. Yes, Peter Otten already corrected me on that point last Friday and I posted thanking him on Sunday. --

Re: surprising interaction between function scope and class namespace

2011-08-15 Thread Duncan Booth
ME/STORE_NAME instead of LOAD_FAST/STORE_FAST and LOAD_NAME looks first in local scope and then in global. I suspect that http://docs.python.org/reference/executionmodel.html#naming-and-binding should say something about this but it doesn't. -- Duncan Booth http://kupuguy.blogspot.com --

Re: How to install easy_install on windows ?

2011-08-17 Thread Duncan Booth
asy_install.py > install module_name Or even just use: C:\Your Python Directory\scripts\easy_install install module_name as easy_install will also add a .exe to your Python's 'scripts' folder. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Floating point multiplication in python

2011-09-06 Thread Duncan Booth
n32 Type "help", "copyright", "credits" or "license" for more information. >>> print(1.1*1.1) 1.2102 -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Reference Cycles with instance method

2011-03-09 Thread Duncan Booth
have saved the bound method so that whenever you call it later it gets the correct 'self' parameter. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Get Path of current Script

2011-03-14 Thread Duncan Booth
to giving you the current directory from a script (and might be what you want if you haven't changed it since the script started). -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Abend with cls.__repr__ = cls.__str__ on Windows.

2011-03-18 Thread Duncan Booth
foo = Foo() print(str(foo)) -- for Python 3.2 the command: C:\Temp>c:\python32\python bug.py generates a popup: python.exe - Application Error The exception unknown software exception (0xcfd) occurred in the application at location 0x1e08a325.

Re: Guido rethinking removal of cmp from sort method

2011-03-28 Thread Duncan Booth
sing simple key functions? Since you've got two keys you will of course need to make two calls to 'sort'. e.g. data.sort(key=itemgetter(1), reverse=True) data.sort(key=itemgetter(0)) -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Equivalent code to the bool() built-in function

2011-04-18 Thread Duncan Booth
credits" or "license" for more information. >>> 2-1 is 1 1 >>> True is 1 0 >>> (True is 1) is 0 0 >>> (True is 1) is False 1 The code for the win32api made use of this fact to determine whether to pass int or bool types through to COM methods. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Case study: debugging failed assertRaises bug

2011-04-26 Thread Duncan Booth
atement in the test. Also, assertRaises has a weird dual life as a context manager: I never knew that before today. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Equivalent code to the bool() built-in function

2011-04-28 Thread Duncan Booth
gt; False or False or True or False True but using != for 'xor' doesn't extend the same way: >>> False != False != True False You can use 'sum(...)==1' for a larger number of values but do have to be careful that all of them are bools (or 0|1). -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: What other languages use the same data model as Python?

2011-05-02 Thread Duncan Booth
rogram which used call by name to alias I and A[I] in some recursive calls. Not nice. Fortunately even at that time it was mostly being taught as an oddity; real programming was of course done in Algol 68C or BCPL. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: "raise (type, value, traceback)" and "raise type, value, traceback"

2011-05-03 Thread Duncan Booth
guess that it is a hangover from the days when exceptions were strings and you couldn't use inheritance to group exceptions. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Why do directly imported variables behave differently than those attached to imported module?

2011-05-04 Thread Duncan Booth
referenced will prevent their methods being deleted and any functions or methods that are still accessible will keep the globals alive as long as required. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a set into list

2011-05-16 Thread Duncan Booth
, 9, 1, 4, 7] or for that mattter: >>> list(set([3, 32, 4, 32, 5, 9, 2, 6])) [32, 2, 3, 4, 5, 6, 9] -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Why did Quora choose Python for its development?

2011-05-23 Thread Duncan Booth
p all but 3 of their 132 claims? It isn't at all obvious yet who is going to be 'screwed over hard'. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: bug in str.startswith() and str.endswith()

2011-05-27 Thread Duncan Booth
7;abcd'.startswith('abc', 0, 2) False Likewise the start parameter for endswith. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-27 Thread Duncan Booth
e 2, in foo bar(y=2, **kwargs) TypeError: bar() got multiple values for keyword argument 'y' -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-27 Thread Duncan Booth
There's a reason why Python 2 requires you to be explicit about the class; you simply cannot work it out automatically at run time. Python 3 fixes this by working it out at compile time, but for Python 2 there is no way around it. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-30 Thread Duncan Booth
t does it to change the default action from silently overwriting any argumement passing up the chain to raising an error if you attempt to overwrite it without first checking whether it exists. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Struggling with basics

2005-09-25 Thread Duncan Booth
Jason wrote: > My first problem (lack of understanding of course) is that if I run the > above, I get an error saying: > > print "%s - %s" % name,score > TypeError: not enough arguments for format string > > Now I understand what it's saying, but I don't understand why. > The problem is

Re: @staticmethod, backward compatibility?

2005-09-27 Thread Duncan Booth
Neal Becker wrote: > How can I write code to take advantage of new decorator syntax, while > allowing backward compatibility? > > I almost want a preprocessor. > > #if PYTHON_VERSION >= 2.4 > @staticmethod > ... > > > Since python < 2.4 will just choke on @staticmethod, how can I do this? > >

Re: A quick c.l.p netiquette question

2005-09-29 Thread Duncan Booth
Richie Hindle wrote: > > [Peter] >> Does it really have to be 158 lines to demonstrate these few issues? > > I think you missed the other Peter's second post, where he points to > his program: http://www.pick.ucam.org/~ptc24/yvfc.html > > I didn't read every one of his 158 lines, but his code i

Re: Python 3! Finally!

2005-10-01 Thread Duncan Booth
Stefan Behnel wrote: > Hi! > > I just firefoxed to Python.org and clicked on the bz2 link at > http://python.org/2.4.2/ and what did I get? > > Python-3.4.2.tar.bz2 !! > > Python 3 - what we've all been waiting for, finally, it's there! > > Weird, though, the md5sum is the same as for the Pyth

Re: "no variable or argument declarations are necessary."

2005-10-03 Thread Duncan Booth
Antoon Pardon wrote: > Well I'm a bit getting sick of those references to standard idioms. > There are moments those standard idioms don't work, while the > gist of the OP's remark still stands like: > > egold = 0: > while egold < 10: > if test(): > ego1d = egold + 1 > Oh come on.

Re: "no variable or argument declarations are necessary."

2005-10-03 Thread Duncan Booth
Antoon Pardon wrote: > A language where variable have to be declared before use, would allow > to give all misspelled (undeclared) variables in on go, instead of > just crashing each time one is encounterd. Wrong. It would catch at compile-time those misspellings which do not happen to coincide

Re: "no variable or argument declarations are necessary."

2005-10-03 Thread Duncan Booth
Antoon Pardon wrote: > >> and worse it adds a burden on everyone reading the code who >> has more lines to read before understanding the code. > > Well maybe we should remove all those comments from code too, > because all it does is add more lines for people to read. You'll get no argument fr

  1   2   3   4   5   6   7   8   9   10   >