Re: When do default parameters get their values set?

2014-12-09 Thread Duncan Booth
led the first time you ran the code and isn't recompiled unless the source code changes). The default parameters are actually evaluated when the 'def' statement is executed and the function object is created from the default arguments and the previously compiled code block. -- Duncan

Re: Storage Cost Calculation

2014-09-28 Thread Duncan Booth
tional RAM was paged in as necessary but I don't think the RAM in the B was ever expandable. -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: newbee

2014-08-13 Thread Duncan Booth
e between the two systems. > All of the above should work just fine on a Pi. The only thing I thing you could have added is that you also have the option of using Idle to edit and run Python programs. If you are running Raspian on your Pi then you will find an icon to run Idle sitting on the initial desktop. There's an introduction to using Idle on the Raspberry Pi at http://www.raspberrypi.org/documentation/usage/python/ -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-08-05 Thread Duncan Booth
Steven D'Aprano wrote: > Duncan Booth wrote: > >> Steven D'Aprano wrote: >> >>> Unfortunately, software development on Windows is something of a >>> ghetto, compared to the wide range of free tools available for >>> Linux. > &

Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-08-05 Thread Duncan Booth
Automatic deployment to Windows Azure. Extensive support for Django (including Intellisense and debugging for templates and various Django specific commands such as sync db and admin shell). -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: eval [was Re: dict to boolean expression, how to?]

2014-08-05 Thread Duncan Booth
;t work. For that matter I don't understand why tuple.__new__ needs to be pre-bound. Just referring to tuple.__new__ directly in the exec simplifies things even more as there is no need to specify any namespaces. exec """def __new__(_cls, %(argtxt)s): return tuple.__new__(_cls, (%(argtxt)s))""" % { 'argtxt': argtxt } also passes the tests. -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: Multi-line commands with 'python -c'

2014-06-01 Thread Duncan Booth
Peter Otten <__pete...@web.de> wrote: > Duncan Booth wrote: > >> Chris Angelico wrote: >> >>> On Sat, May 31, 2014 at 7:42 AM, Devin Jeanpierre >>> wrote: >>>> In unix shells you can literally use a new line. Or is that only >> bash?

Re: Multi-line commands with 'python -c'

2014-05-31 Thread Duncan Booth
k("."): if len(dirs + files) == 1: print(root) ' $ python -c $script File "", line 1 import ^ SyntaxError: invalid syntax -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: Multi-line commands with 'python -c'

2014-05-30 Thread Duncan Booth
and in Powershell ISE up-arrow pulls it back as a single unit for easy editing: PS C:\python33> python -c @" import os for root, dirs, files in os.walk('.'): if len(dirs + files) == 1: print(root) "@ .\Doc .\Lib\concurrent\__pycache__ .\Lib\curses\__pycache__ ... and so on

Re: IDE for python

2014-05-29 Thread Duncan Booth
Duncan Booth wrote: > Sameer Rathoud wrote: > >> On Wednesday, May 28, 2014 5:16:41 PM UTC+5:30, Greg Schroeder wrote: >>> > > Please suggest, if we have any free ide for python development. >>> >>> >>> >>> Anything that writes

Re: IDE for python

2014-05-29 Thread Duncan Booth
go, and cloud computing with client libraries for > Windows, Linux and MacOS. > > Designed, developed, and supported by Microsoft and the community. -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: Forking PyPI package

2014-05-29 Thread Duncan Booth
pwdhash / pwdhash.py.egg-info / PKG-INFO): Author: Lev Shamardin Author-email: shamar...@gmail.com License: BSD Still better to get in touch with the author, but he has actually stated the license albeit in the most minimal way possible. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Proper deletion of selected items during map iteration in for loop: Thanks to all

2014-04-28 Thread Duncan Booth
aracter strings then each string needs I think at least 45 bytes (64 bit Python 2.x, up to double that in Python 3.x) but the list only needs one 8 byte pointer per key. I would always choose this simple solution until such time as it is proved to be a problem. -- Duncan Booth -- https://

Re: object().__dict_

2014-04-23 Thread Duncan Booth
t__ and the > object does not accept new attributes. > Please explain what's going on. > > Not all classes have a __dict__ attribute. Mostly builtin classes (e.g. tuple, list, int, ...), but also if you have an class using __slots__ which subclasses a class with no __dict__ it won't have a __dict__. Subclasses don't remove attributes, they only add them (although in Python you can bend that rule it still applies here). Therefore for any classes to not have a __dict__ attribute the ultimate base class 'object' has to not have a __dict__. The consequence, as you found out, is that you cannot add attributes to an instance of 'object()', you have to create at least an empty subclass which doesn't include a `__slots__` attribute to get a class that can accept arbitrary attributes. -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: Tuples and immutability

2014-03-07 Thread Duncan Booth
hrow an exception on assigning to the element if the old value and new value are the same object? If I say: a = ("spam", [10, 30], "eggs") then a[0] = a[0] won't actually mutate the object. So tuples could let that silently pass. Then you would be able to s

Re: intersection, union, difference, symmetric difference for dictionaries

2014-02-25 Thread Duncan Booth
;t matter whether they were small strings or full-length novels, creating a set from a dict doesn't duplicate any strings. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list

Re: [RELEASED] Python 3.4.0 release candidate 1

2014-02-11 Thread Duncan Booth
/pip from pypi. Did your system have network access? What happens if you enable the installer log by running: msiexec /i python-3.4.0rc1.amd64.msi /L*v logfile.txt Does it put any useful messages in logfile.txt? -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: Vedr: What does """ means in python?

2014-02-10 Thread Duncan Booth
ompt running as administrator enter "Set-ExecutionPolicy RemoteSigned") and you can just do: powershell .\Pythoncerts.ps1 I also use Powershell interactively so I have the filters defined in my startup ($Home\Documents\WindowsPowerShell\profile.ps1): filter py() { $_ | py.exe ($args -replace'(\\*)"','$1$1\"') } filter python() { $_ | c:\Python33\python.exe ($args -replace'(\\*)"','$1$1\"') } -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: Google Cloud Platform and GlassSolver Project

2014-02-10 Thread Duncan Booth
Correct: "Cat Facts for Glass" > > Incorrect: "Glass Cat Facts", "Glassy Cat Photos" -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Ifs and assignments

2014-01-03 Thread Duncan Booth
do have to be sure to get the sentinel value correct as it will only break for the expected terminal False, not for 0, "", or None. -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: Newbie question. Are those different objects ?

2013-12-23 Thread Duncan Booth
Gregory Ewing wrote: > rusi wrote: >> Good idea. Only you were beaten to it by about 2 decades. > > More than 2, I think. > > Algol: x := y Wher := is pronounced 'becomes'. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list

Re: extracting a heapq in a for loop - there must be more elegant solution

2013-12-03 Thread Duncan Booth
) if H else sentinel, sentinel): print(N) Alternatively your 'in_sequence' function would look better without the exception handling: def in_sequence(H) : while H: yield heappop(H) -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: Newbie - Trying to Help a Friend

2013-11-20 Thread Duncan Booth
nd how many numbers up to x are not divisible by a, b, or c, which would be a case of re-using some of the above code. For extra credit, calculate and use the least common multiple of a,b and c instead of just using their product. -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list

Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Duncan Booth
s and exception classes (subclasses of BaseException) are permitted. This means the structure can be as deeply nested as you wish, but can never be recursive and no checks against recursion need to be implemented. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Slicing with negative strides

2013-10-29 Thread Duncan Booth
7;t feel that you have to join yet > another list.) > For those of us that don't really want to join another mailing list, could you summarise what change is being proposed? -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Mysql's mysql module

2013-10-07 Thread Duncan Booth
think the answers to questions 1 and 3 are yes and no respectively. No idea about #2. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Duncan Booth
ions get removed > from the stack traces just because they happened to end in tail calls. Quite so. Losing some stack frames in the traceback because tail recursion was optimised is probably no big deal. Losing arbitrary stack frames because of a more widespread tail call optimisation would n

Re: Tail recursion to while iteration in 2 easy steps

2013-10-04 Thread Duncan Booth
Neil Cerutti wrote: > On 2013-10-03, Duncan Booth wrote: >> It isn't hard to imagine adding a TAIL_CALL opcode to the >> interpreter that checks whether the function to be called is >> the same as the current function and if it is just updates the >> arguments an

Re: Tail recursion to while iteration in 2 easy steps

2013-10-03 Thread Duncan Booth
e code block. If the function doesn't match it would simply fall through to doing the same as the current CALL_FUNCTION opcode. There is an issue that you would lose stack frames in any traceback. Also it means code for this modified Python wouldn't run on other non-modified interpreter

Re: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-20 Thread Duncan Booth
;t know how well it works on a tablet but it would be worth trying. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Python in XKCD today

2013-09-13 Thread Duncan Booth
Roy Smith wrote: > http://xkcd.com/1263/ So now I guess someone has to actually implement the script. At least, that's (sort of) what happened for xkcd 353 so there's a precedent. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list

Re: semicolon at end of python's statements

2013-09-05 Thread Duncan Booth
gt; That brings back memories all right, but its not as good as the version I remember as it doesn't 'fix' the logical operator priorities. -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list

Re: semicolon at end of python's statements

2013-09-05 Thread Duncan Booth
syntactic elements are for. > > ChrisA > Someone I knew actually used these definitions when writing C in a Pascalish, Algol68ish style (if I remembered them correctly): #define IF if((( #define AND ))&&(( #define OR )||( #define THEN ))){ #define ELSE }else{ #define FI } -- Duncan Booth http://kupuguy.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list

Re: .split() Qeustion

2013-08-15 Thread Duncan Booth
o solve. > """[1:-1].split("\n") > > ? I suppose the question really is whether the author of the second example really meant to start with the word 'evelopments'? If that was a mistake, then the first one is demonstrably less error prone. If it was intentional then the second one is definitely less readable. Either way I think you've proved that the first way of writing it is more readable. -- 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: 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: 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: 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: 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: Running simultaneuos "FOR" loops

2013-04-23 Thread Duncan Booth
sorted(class_count), sorted(pixel_count)): also you don't need to call the `iterkeys()` method as you need them all to sort and just treating the dict as a sequence will do the right thing. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: howto remove the thousand separator

2013-04-19 Thread Duncan Booth
ing the locale module, just be sure to set the correct locale first: >>> import locale >>> locale.setlocale(locale.LC_ALL, '') 'English_United Kingdom.1252' >>> locale.atoi('1,000') 1000 >>> locale.atof('1,000') 1000.0 >

Re: What are some other way to rewrite this if block?

2013-03-18 Thread Duncan Booth
should_be_on <= 24.0 and 0.0 <= came_on <= 24.0): raise ValueError('time not in range') if should_be_on - EARLY_DELTA <= came_on <= should_be_on + LATE_DELTA: return 'on time' if came_on > should_be_on: return 'delayed'

Re: Unicode

2013-03-15 Thread Duncan Booth
t characters: >>> repr(a) "u'\\xb5m'" >>> repr(b) "u'\\u03bcm'" a contains unicode MICRO SIGN, b contains GREEK SMALL LETTER MU -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Newbie

2013-02-22 Thread Duncan Booth
Steve Simmons wrote: > > On 22/02/2013 15:26, Duncan Booth wrote: >> Rui Maciel wrote: >> >>> Chris Angelico wrote: >>> >>>> On Fri, Feb 22, 2013 at 10:58 PM, Rui Maciel >>>> wrote: >>>>> Mitya Sirenef wrote: &

Re: Python Newbie

2013-02-22 Thread Duncan Booth
ame block, or did you think it was talking about the placement of the opening brace on the same line as the `if` statement? I believe that Mitya was talking about the former but that you assumed the latter. -- Duncan Booth -- http://mail.python.org/mailman/listinfo/python-list

Re: FYI: AI-programmer

2013-02-22 Thread Duncan Booth
ogram? > We already have a Python interpreter written in Python that (in most cases) runs faster than the original, which is pretty much the same thing. All it needs is a bit of AI stuck on to critique the code and complain about the weather and you're done. -- Duncan Booth -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggested feature: slice syntax within tuples (or even more generally)?

2013-02-14 Thread Duncan Booth
ith a step?: {1:2:3} You can't just allow ':' to generate slice objects everwhere without introducing ambiguity, so your proposal would have to be to allow slice objects in wider but still restricted contexts. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: real-time monitoring of propriety system: embedding python in C or embedding C in python?

2013-02-05 Thread Duncan Booth
course mix the two. If it's more convenient put the main loop in Python but use callbacks from the library to handle the values as they appear, but again that probably just complicates things. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: confusion with decorators

2013-02-04 Thread Duncan Booth
es, but after the first run of the program all of the modules (nto the script) will have been compiled once and don't compile again until the source changes. -- 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: 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: 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: 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: 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: 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: 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: 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: 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

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: 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

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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: + 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: + 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: 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: '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: 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: 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: 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-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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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 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: 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: [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: 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: 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: #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: #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: 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: 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

  1   2   3   4   5   6   7   8   9   10   >