Re: raise None

2015-12-31 Thread Steven D'Aprano
se for their functions or not. Sometimes it will, and sometimes it won't. The only new part here is the idea that we could streamline the code in the caller if "raise None" was a no-op. Instead of writing this: exc = _validate(x) if exc is not None: raise exc we could write: raise _validate(x) which would make this idiom more attractive. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Newbie: Check first two non-whitespace characters

2015-12-31 Thread Steven D'Aprano
On Fri, 1 Jan 2016 10:25 am, Mark Lawrence wrote: > Congratulations for writing up one of the most overengineered pile of > cobblers I've ever seen. You should get out more. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Newbie: Check first two non-whitespace characters

2015-12-31 Thread Steven D'Aprano
se ValueError("invalid string") This will probably be slower for small strings, but faster for HUGE strings (tens of millions of characters). But I expect it will be fast enough. It is simple enough to skip tabs as well as spaces. Easiest way is to match on any whitespace: regex = re.compile(r'\w*\[\w*\{') -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Happy New Year

2015-12-31 Thread Steven D'Aprano
the more entertaining of our cranks (not mentioning any names, but we know who they are...), may 2016 be a better year than 2015 for us all. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: We will be moving to GitHub

2016-01-01 Thread Steven D'Aprano
ub_monoculture.html Oh, and talking about DVCS: https://bitquabit.com/post/unorthodocs-abandon-your-dvcs-and-return-to-sanity/ -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: What meaning is '[: , None]'?

2016-01-02 Thread Steven D'Aprano
mpy.newaxis. http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html In this case, w_A[:, None] returns a "view" of the original w_A array. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: (Execution) Termination bit, Alternation bit.

2016-01-03 Thread Steven D'Aprano
On Sun, 3 Jan 2016 12:18 pm, Skybuck Flying wrote: > Should be easy to turn that somewhat pseudo code into python code ! :) If it is so easy, why won't you do it? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Ajax Request + Write to Json Extremely Slow (Webpage Crawler)

2016-01-03 Thread Steven D'Aprano
This may entirely be a red herring, but if it were my code, I'd try replacing that last line with: reply_cids.extend(extract_reply_cids(html)) and see if it makes any difference. If it doesn't, you can keep the new version or revert back to the version using +=, entirely up to y

Re: What use of 'sum' in this line code?

2016-01-03 Thread Steven D'Aprano
n error: py> yy = map(sum, [13, 22, 33, 41]) Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable Try replacing the list-of-mystery-things with a list of lists: map(sum, [[1, 2, 3], [4, 5, 6], [7, 8, 9]]) and see what you get. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: raise None

2016-01-03 Thread Steven D'Aprano
On Mon, 4 Jan 2016 02:31 pm, Chris Angelico wrote: > On Mon, Jan 4, 2016 at 2:04 PM, Rustom Mody wrote: >> On Thursday, December 31, 2015 at 9:05:58 PM UTC+5:30, Steven D'Aprano >> wrote: >>> But I think it is a real issue. I believe in beautiful tracebacks tha

Re: raise None

2016-01-03 Thread Steven D'Aprano
quot;, line 1425, in CHECK_BINOP TypeError: unsupported operand type(s) for +: 'int' and 'list' When you open that ticket, be so good as to add me to the Nosy list. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: raise None

2016-01-03 Thread Steven D'Aprano
On Fri, 1 Jan 2016 09:48 am, Chris Angelico wrote: > On Fri, Jan 1, 2016 at 7:18 AM, Ben Finney > wrote: [...] >> As best I can tell, Steven is advocating a way to obscure information >> from the traceback, on the assumption the writer of a library knows that >>

Re: What is the fastest way to do 400 HTTP requests using requests library?

2016-01-04 Thread Steven D'Aprano
e, then create N threads, where N will need to be determined by experiment, but will probably be something like 4 or 8, and let each thread pop a request from the queue as needed. Are you experienced with threads? Do you need further information about using threads and queues? -- S

Re: What is the fastest way to do 400 HTTP requests using requests library?

2016-01-05 Thread Steven D'Aprano
just want to download things in a rush. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Steven D'Aprano
On Wednesday 06 January 2016 10:25, Thomas 'PointedEars' Lahn wrote: > Robert wrote: > >> I just wonder that the cmd line function sum may be different from the >> .py file used. One is numpy package, the other is a general one. Then, >> how can I further make it clear for this guess? > > Among

Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Steven D'Aprano
On Wednesday 06 January 2016 07:37, John Gordon wrote: > The built-in function sum() returns a single value, not a list, so this > is a reasonable error. Not quite. It depends on what arguments you give it. py> a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] py> sum(a, []) [1, 2, 3, 4, 5, 6, 7, 8, 9] Bu

Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread Steven D'Aprano
On Wednesday 06 January 2016 07:25, Robert wrote: > Why is there difference between cmd line and .py file? Almost certainly because you are not running exactly the same code each time. > I run below code, which is downloaded from link: Your code fails on the first line with NameError: n

Re: Question about a class member

2016-01-07 Thread Steven D'Aprano
https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html It has a sample method here: https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html#hmmlearn.hmm.GaussianHMM.sample You should try googling for help before asking questions: https://duckduckgo.com/ht

Re: Unable to access module attribute with underscores in class method, Python 3

2016-01-08 Thread Steven D'Aprano
you could also try this: py> __a = 1 py> class Test: ... def method(self): ... x = eval("__a") ... print(x) ... py> Test().method() 1 But don't do that. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Unable to access module attribute with underscores in class method, Python 3

2016-01-08 Thread Steven D'Aprano
On Sat, 9 Jan 2016 03:16 am, Chris Angelico wrote: > On Sat, Jan 9, 2016 at 3:07 AM, Steven D'Aprano > wrote: >> If you absolutely insist that you must must must continue to use a double >> underscore name, you could also try this: >> >> py> __a = 1 >>

Re: licenses

2016-01-09 Thread Steven D'Aprano
ey. You still have to obey the licence. - But if there are special conditions that apply to you, it doesn't hurt for you to ask for a special licence. The worst that will happen is that they will ignore you, or say no. And finally: - Check with your lawyer. -- Steven -- https

Re: Help on return type(?)

2016-01-09 Thread Steven D'Aprano
ype] > > Specifically, could you explain the meaning of > > { > ...}[cov_type] > > to me? It is a dictionary lookup. { ... } sets up a dictionary with keys 'spherical' 'tied' 'diag' 'full' then { ... }[cov_type]

Re: Python 3.4.4 Install

2016-01-09 Thread Steven D'Aprano
ckup. Also, you should make sure you scan your system for viruses (possibly you have a randsomware virus encrypting files behind your back) and do a disk check in case the disk is dying. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface"

2016-01-10 Thread Steven D'Aprano
he ENTIRE traceback, starting from the line: Traceback (most recent call last) to the end of the error message. This will (hopefully) show us which line of your code caused the error. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: When I need classes?

2016-01-10 Thread Steven D'Aprano
s, but sometimes classes will make problems easier to solve. And sometimes classes make problems harder to solve. It depends on the problem. This may help you: http://kentsjohnson.com/stories/00014.html -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface"

2016-01-10 Thread Steven D'Aprano
are running code which is different from what you have posted here. Perhaps your ACTUAL code (not the pretend code you showed us) includes a try...except block like this: try: some code goes here except Exception as err: print(err) sys.exit() or similar. If so, TAKE IT OUT. That is destroying useful debugging information and making it more difficult to solve your problem. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: What use of these _ prefix members?

2016-01-10 Thread Steven D'Aprano
e, class, method, attribute or variable, you can assume that it is private (unless explicitly documented otherwise) and avoid it. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Confusing on bool data object or class function?

2016-01-10 Thread Steven D'Aprano
t; for the underlying mechanism that allows this to work. (Warning: descriptors are considered very advanced material.) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Understanding " 'xml.etree.ElementTree.Element' does not support the buffer interface"

2016-01-11 Thread Steven D'Aprano
On Tue, 12 Jan 2016 08:54 am, Saran Ahluwalia wrote: > Hi Steven: > > Just as an update - apparently there were bytes in the Windows Command > Terminal that were interrupting the process execution. I didn't realize > this was happening until I dug around Windows' Q&

OT: There are no words for how broken everything is

2016-01-11 Thread Steven D'Aprano
There are no words to explain just how broken everything is. This post tries: https://medium.com/message/everything-is-broken-81e5f33a24e1 but barely covers even a fraction of the breakage. Thanks goodness for anti-virus, right? One of the leading anti-virus vendors in the world, TrendMicro, h

Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict

2016-01-12 Thread Steven D'Aprano
he comma after "item". The comma turns the assignment into sequence unpacking. Normally we would write something like this: a, b, c, d = four_items but you can unpack a sequence of one item too. If you really want to make it obvious that the comma isn't a typo: (item,) = d.values()

Re: subscripting Python 3 dicts/getting the only value in a Python 3 dict

2016-01-12 Thread Steven D'Aprano
py> next(iter(d.values())) 'value' > This resembles a list just too much, making the coder's intent harder > to understand. This is **very** subjective, of course. I'm sorry, I don't understand what you mean by "resembles a list"? What does? In what way? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: When I need classes?

2016-01-12 Thread Steven D'Aprano
ot Java: http://dirtsimple.org/2004/12/python-is-not-java.html And Java is not Python either: http://dirtsimple.org/2004/12/java-is-not-python-either.html -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Which Python editor has this feature?

2016-01-12 Thread Steven D'Aprano
(he never seems to care about Asians or other non-Latin based characters, only French and other European ones) and that this small performance decrease shows that Python can't do Unicode. I think that is fair to say that he is what the English call "a nutter". -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: When I need classes?

2016-01-12 Thread Steven D'Aprano
On Wednesday 13 January 2016 14:36, Rustom Mody wrote: > 1. Python the LANGUAGE, is rather even-handed in paradigm choice: Choose > OO, imperative, functional or whatever style pleases/suits you > 2. Python LIBRARIES however need to make committing choices. Users of > those then need to align wit

Stop writing Python 4 incompatible code

2016-01-12 Thread Steven D'Aprano
Quote: With the end of support for Python 2 on the horizon (in 2020), many package developers have made their packages compatible with both Python 2 and Python 3 by using constructs such as: if sys.version_info[0] == 2: # Python 2 code else: # P

Re: Building list

2016-01-13 Thread Steven D'Aprano
On Thu, 14 Jan 2016 02:23 am, Eddy Quicksall wrote: > What list do I use for building issues? I'm building 3.5.1. You can ask here. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Stop writing Python 4 incompatible code

2016-01-13 Thread Steven D'Aprano
nge from 2.5 to 2.6. (I bet most people don't even know that 2.6 broke backwards-compatibility.) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: me, my arm, my availability ...

2016-01-13 Thread Steven D'Aprano
On Thu, 14 Jan 2016 07:47 am, Laura Creighton wrote: > > I fell recently. Ought to be nothing, [...] Ouch! Much ouch! Hope you get well soon Laura! My best wishes and sympathies to you! -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: me, my arm, my availability ...

2016-01-13 Thread Steven D'Aprano
ving the response which I'm having right now: "I don't think it's Laura who is high on drugs, prescription or otherwise, but you!" :-) Seriously, sorry for being That Guy who asks you to analyse what I expect is meant as a joke, but I have no idea where the humour is. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: [Python-ideas] Password masking for getpass.getpass

2016-01-13 Thread Steven D'Aprano
t; that will read your credit card number as you type it and then fire it > off to be stored on my server before you've even hit the Submit > button. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: [Python-ideas] Password masking for getpass.getpass

2016-01-13 Thread Steven D'Aprano
different domains, each more and more dodgy-looking than the last. And that's just the "legitimate" (for some definition of) scripts. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Stop writing Python 4 incompatible code

2016-01-13 Thread Steven D'Aprano
On Thu, 14 Jan 2016 11:40 am, Bernardo Sulzbach wrote: > On Wed, Jan 13, 2016 at 10:10 PM, Steven D'Aprano > wrote: >> (...) 4.0 (assuming there is one) > > Isn't it just a matter of time? Do you think it is even possible not > to have Python 4 eventually? 3.

Re: Stop writing Python 3.5 incompatible code :-)

2016-01-14 Thread Steven D'Aprano
On Thursday 14 January 2016 17:27, Frank Millman wrote: > So my test was - > > except ValueError as e: > if str(e).startswith('need'): > # 0 rows returned > else: > # > 1 rows returned > > This has worked for years, but with 3.5 it stopped working. It took me a > while to

Re: Stop writing Python 4 incompatible code

2016-01-14 Thread Steven D'Aprano
On Thursday 14 January 2016 14:29, Rick Johnson wrote: > On Wednesday, January 13, 2016 at 9:08:40 PM UTC-6, Chris Angelico wrote: >> You're talking about a very serious matter between two legal entities >> - if someone was *fired* because of social, technological, or other >> problems with Python

Re: Stop writing Python 4 incompatible code

2016-01-14 Thread Steven D'Aprano
On Fri, 15 Jan 2016 02:30 am, Rick Johnson wrote: > I represent Absolutely nobody except yourself. The entertainment value of your trolling has now dipped below the annoyance value. Into the sin-bin you go for another three months. Enjoy your time in the kill-file. -- Steven -- ht

Re: Python best practices

2016-01-15 Thread Steven D'Aprano
quot;best practice" any more, but you can still learn something from them.) At the interactive interpreter, read the Zen of Python: import this -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Using 'Or'

2016-01-16 Thread Steven D'Aprano
llo' py> "goodbye" or "hello" 'goodbye' py> "" or "something" 'something' Think of `or` as the following: - if the first string is the empty string, return the second string; - otherwise always return the first string. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Using 'Or'

2016-01-16 Thread Steven D'Aprano
outs." message = random.choice(["", "I like boiled cabbage."]) print( message or default ) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: print size limit

2016-01-16 Thread Steven D'Aprano
problem, instead of talking in vague generalities, we might be able to suggest a solution. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there a limit to the characters used in a print statement?

2016-01-16 Thread Steven D'Aprano
Are you sure that the problem is with print and not the conversion? Again, your question is little more than some vague generalities with no real detail. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Keen eyes

2016-01-16 Thread Steven D'Aprano
20;j++){} > return 1 > } js> j js: "", line 13: uncaught JavaScript runtime exception: ReferenceError: "j" is not defined. at :13 js> a() 1 js> j 10 js> b() 1 js> j 20 And this is the language that 95% of the Internet uses... my brain hurts. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

OT The fiction section

2016-01-17 Thread Steven D'Aprano
https://pbs.twimg.com/media/CWgV0ruUsAAcUD7.jpg -- Steve -- https://mail.python.org/mailman/listinfo/python-list

Re: Error handling with @parallel decorator

2016-01-17 Thread Steven D'Aprano
On Monday 18 January 2016 17:15, Ankur Agrawal wrote: > I am trying to catch Abort exception. When I use fabric's run(...) method, > the host it tries to connect is not available and so it aborts with > connect time out exception. I am not able to catch it. Following is a two > different ways of c

Re: Why generators take long time?

2016-01-19 Thread Steven D'Aprano
ssion: 100 loops, best of 3: 0.965 usec per loop 100 loops, best of 3: 0.914 usec per loop 100 loops, best of 3: 0.981 usec per loop 100 loops, best of 3: 0.931 usec per loop So there's plenty of random variation in the times. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Why generators take long time?

2016-01-19 Thread Steven D'Aprano
On Tue, 19 Jan 2016 09:24 pm, Oscar Benjamin wrote: > On 19 Jan 2016 10:16, "Steven D'Aprano" wrote: >> >> [steve@ando ~]$ python -m timeit -s "from collections import deque" >> -s "it = iter([i for i in xrange(1000)])" "deque(it

Re: Is this an attribute?

2016-01-19 Thread Steven D'Aprano
x27;t mean attribute foo exists. I can use attribute syntax to look up an attribute that doesn't exist, and Python will raise AttributeError. The question is, perhaps that attribute gets created elsewhere. You would need to read all the source code, or read the documentation, to see where and u

Re: How to fix my imports/file structure

2016-01-20 Thread Steven D'Aprano
On Thursday 21 January 2016 12:26, Travis Griggs wrote: > I wrote a simple set of python3 files for emulating a small set of mongodb > features on a 32 bit platform. I fired up PyCharm and put together a > directory that looked like: > > minu/ > client.py > database.py > collection.py

Re: How to use the docstring in this property example

2016-01-20 Thread Steven D'Aprano
On Thursday 21 January 2016 15:00, Robert wrote: > Hi, > > I read below code snippet on link: > https://docs.python.org/2/library/functions.html#property Property docstrings are hard to get to. But with the class C you gave, this works in the interactive interpreter: help(C.__dict__['x']) dis

Re: Same function but different names with different set of default arguments

2016-01-21 Thread Steven D'Aprano
ible difference between the first and second method. The third method, using functools.partial, is considerably faster, BUT remember that this only effects the time it takes to call the function g(). If g() actually does any work, the time spent doing the work will *far* outweigh the overhead of calling the function. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: How to simulate C style integer division?

2016-01-21 Thread Steven D'Aprano
ion with truncation towards zero. n = a//b if (a < 0) != (b < 0): n += 1 return n -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: importing: what does "from" do?

2016-01-21 Thread Steven D'Aprano
an only import them from where they actually exist. from math import path # fails, because there is no math.path from os import path # succeeds, because os.path does exist You can't import int.hexdump if you haven't written a file int/hexdump.py. > I have these function definitions: > > codec/objects.py:47:def hexdump (s, l = None): > int/struct_phy.py:26:def hexdump (s, l = None): > > both in modules. > > It fails to load: > > from struct_phy import hexdump > > or: > > from int.struct_phy import hexdump > ImportError: cannot import name hexdump At this point, I'm so confused by your setup that I'm about to give up and go to bed. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: importing: what does "from" do?

2016-01-21 Thread Steven D'Aprano
If you run from utilities import hexdump and Python gives you an ImportError, the most likely issue is that there is no such name "hexdump" in that file. Are you sure you are looking at the same file? What does this tell you? import utilities print(utilities.__file__) Does it

Re: How to simulate C style integer division?

2016-01-21 Thread Steven D'Aprano
a = 3**1000 * 2 py> b = 3**1000 py> float(a)/b # Exact answer should be 2 Traceback (most recent call last): File "", line 1, in OverflowError: long int too large to convert to float Note that Python gets the integer division correct: py> a//b 2L And even gets tru

Re: import locale and print range on same line

2016-01-23 Thread Steven D'Aprano
On Sat, 23 Jan 2016 09:02 pm, [email protected] wrote: > However I need to put the code on one single line. Why? Is the Enter key on your keyboard broken? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: import locale and print range on same line

2016-01-23 Thread Steven D'Aprano
On Sun, 24 Jan 2016 12:19 am, Chris Angelico wrote: > On Sun, Jan 24, 2016 at 12:07 AM, Steven D'Aprano > wrote: >> On Sat, 23 Jan 2016 09:02 pm, [email protected] wrote: >> >>> However I need to put the code on one single line. >> >> Why? Is the Enter

Re: Calculating longitudinal acceleration, lateral acceleration and normal acceleration

2016-01-23 Thread Steven D'Aprano
On Sunday 24 January 2016 11:27, Robert James Liguori wrote: > Is there a python library to calculate longitudinal acceleration, lateral > acceleration and normal acceleration? Calculate acceleration of what? I think we need some more detail before we can give a sensible answer, but you could t

Re: Calculating longitudinal acceleration, lateral acceleration and normal acceleration

2016-01-23 Thread Steven D'Aprano
Second attempt. On Sunday 24 January 2016 11:27, Robert James Liguori wrote: > Is there a python library to calculate longitudinal acceleration, lateral > acceleration and normal acceleration? Calculate acceleration of what? I think we need some more detail before we can give a sensible answer

Re: psss...I want to move from Perl to Python

2016-01-28 Thread Steven D'Aprano
if you use the wrong sigil, and then I get confused. Is there a good discussion of how names and references work in Perl, equivalent to Ned's discussion? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: >>> %matplotlib inline results in SyntaxError: invalid syntax

2016-01-29 Thread Steven D'Aprano
at, or perhaps finding a better tutorial that actually bothers to mention what it needs to run. (You have read the tutorial from the beginning, yes?) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: psss...I want to move from Perl to Python

2016-01-29 Thread Steven D'Aprano
ogramming* is introduced before classes. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Steven D'Aprano
On Sat, 30 Jan 2016 09:47 am, Ben Finney wrote: > Steven D'Aprano writes: > >> You should have started with the official tutorial: >> >> https://docs.python.org/2/tutorial/ > > And these days the default recommendation should be to start with the > of

Re: Heap Implementation

2016-01-30 Thread Steven D'Aprano
On Sunday 31 January 2016 09:47, Sven R. Kunze wrote: > @all > What's the best/standardized tool in Python to perform benchmarking? timeit -- Steve -- https://mail.python.org/mailman/listinfo/python-list

Re: psss...I want to move from Perl to Python

2016-01-30 Thread Steven D'Aprano
On Sunday 31 January 2016 09:18, Gregory Ewing wrote: > Rustom Mody wrote: >> 1. One can use string-re's instead of compiled re's > > And I gather that string REs are compiled on first use and > cached, so you don't lose much by using them most of the > time. Correct. The re module keeps a cache

Re: x=something, y=somethinelse and z=crud all likely to fail - how do i wrap them up

2016-01-30 Thread Steven D'Aprano
gate class. Pick whichever is more relevant to your specific situation. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: x=something, y=somethinelse and z=crud all likely to fail - how do i wrap them up

2016-01-31 Thread Steven D'Aprano
elf.get_class(li_item, 'vip')) price_dollar = self.get_text( self.get_class(li_item, 'lvprice prc')) bids = self.get_text( self.get_class(li_item, 'lvformat') time_hrs = self.get_time(self.get_class(li_item, 'tme')) shipping = self.get_shipping( self.get_class(li_item, 'lvshipping') print('{} {} {} {} {}'.format( link, price_dollar, time_hrs, shipping, bids)) print('-'*70) Obviously I haven't tested this code. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: psss...I want to move from Perl to Python

2016-01-31 Thread Steven D'Aprano
On Sun, 31 Jan 2016 02:48 pm, Cameron Simpson wrote: > I have. I've got one right here. It happens to be in perl, but it has been > in need of a recode in Python for a long time. It has about 3000 regexps. Wow. What's the code do? -- Steven -- https://mail.python.org/mailman

Re: x=something, y=somethinelse and z=crud all likely to fail - how do i wrap them up

2016-01-31 Thread Steven D'Aprano
On Sun, 31 Jan 2016 08:40 pm, Chris Angelico wrote: > On Sun, Jan 31, 2016 at 8:21 PM, Steven D'Aprano > wrote: >> Hmmm. Well, I've never used lxml, but the first obvious problem I see is >> that your lines: >> >> description = li_item.find_c

Re: carry **arguments through different scopes/functions

2016-01-31 Thread Steven D'Aprano
something_complex: handler-call for id 5 {'something_complex': } one_id: 5 something_complex: handler-call for id 4 {'something_complex': } one_id: 4 something_complex: handler-call for id 3 {'something_complex': } one_id: 3 something_complex: handler-call for id 2 {'something_complex': } one_id: 2 something_complex: handler-call for id 1 {'something_complex': } one_id: 1 something_complex: 7 is in -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Calculator

2016-02-01 Thread Steven D'Aprano
Hi Ryan, and welcome! On Tuesday 02 February 2016 06:30, Ryan Young wrote: > I am new to Python but have known Java for a few years now. With python, > so far, so good! I created a simple calculator to calculate the total cost > of a meal. My variables were tip tax total and order. I am confused

Re: Heap Implementation

2016-02-01 Thread Steven D'Aprano
On Tuesday 02 February 2016 06:32, Sven R. Kunze wrote: > On 31.01.2016 02:48, Steven D'Aprano wrote: >> On Sunday 31 January 2016 09:47, Sven R. Kunze wrote: >> >>> @all >>> What's the best/standardized tool in Python to perform benchmarking? >> t

Re: Data storing

2016-02-02 Thread Steven D'Aprano
MySQL, **especially** if you need to support non-ASCII (Unicode) data. But really, to decide which would be best for you, we would need to know a lot more about your application and its requirements. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Behaviour of list comprehensions

2016-02-02 Thread Steven D'Aprano
range(6, -1, -1): d=date.today() - timedelta(i) t = d.year, d.month, d.day date_list.append(t) return date_list Because this function returns an actual list, there is no need to call list() on the result. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Mutant Registration: Implicit or Explicit

2016-02-03 Thread Steven D'Aprano
ld_dict are just two names for the one dict. In general, mutator functions and methods should not return the object they just mutated, unless there is a good reason to do so (e.g. decorators). -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Reply to whom? (was: Efficient Wrappers for Instance Methods)

2016-02-03 Thread Steven D'Aprano
possibly AOL (if there is anyone on AOL who knows how to send email). Yahoo and AOL do not interact well with mailing lists. As they say on the mailman mailing list, "Friends don't let friends use Yahoo email addresses." -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: _siftup and _siftdown implementation

2016-02-04 Thread Steven D'Aprano
your code? Somebody else's code? A library? Which library? What do they do? Where are they from? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-06 Thread Steven D'Aprano
On Sunday 07 February 2016 14:02, INADA Naoki wrote: > Python 3 is a disaster because of incompatibility with Python 2. How is that a disaster? What is your criteria for deciding what is, and isn't, a disaster? According to TIOBE, Python's popularity continues to grow: http://www.tiobe.com/ind

Re: A sets algorithm

2016-02-08 Thread Steven D'Aprano
On Tuesday 09 February 2016 02:11, Chris Angelico wrote: > That's fine for comparing one file against one other. He started out > by saying he already had a way to compare files for equality. What he > wants is a way to capitalize on that to find all the identical files > in a group. A naive appro

Re: Storing a big amount of path names

2016-02-11 Thread Steven D'Aprano
> easily be _more_. Yep. Back in the early days, interned strings were immortal and lasted forever. That wasted memory, and is no longer the case. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: What is heating the memory here? hashlib?

2016-02-13 Thread Steven D'Aprano
', buffering=40*M) as f: and see whether that helps. By the way, do you need a cryptographic checksum? sha256 is expensive to calculate. If all you are doing is trying to match files which could have the same content, you could use a cheaper hash, like md5 or even crc32. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: How to properly override the default factory of defaultdict?

2016-02-14 Thread Steven D'Aprano
On Monday 15 February 2016 11:17, Herman wrote: > I want to pass in the key to the default_factory of defaultdict Just use a regular dict and define __missing__: class MyDefaultDict(dict): def __missing__(self, key): return "We gotcha key %r right here!" % key If you want a per-in

Re: Make a unique filesystem path, without creating the file

2016-02-14 Thread Steven D'Aprano
On Monday 15 February 2016 11:08, Ben Finney wrote: > I am unconcerned with whether there is a real filesystem entry of that > name; the goal entails having no filesystem activity for this. I want a > valid unique filesystem path, without touching the filesystem. Your phrasing is ambiguous. If y

Re: Make a unique filesystem path, without creating the file

2016-02-14 Thread Steven D'Aprano
On Monday 15 February 2016 12:19, Ben Finney wrote: > One valid filesystem path each time it's accessed. That is, behaviour > equivalent to ‘tempfile.mktemp’. > > My question is because the standard library clearly has this useful > functionality implemented, but simultaneously warns strongly aga

Re: repr( open('/etc/motd', 'rt').read() )

2016-02-15 Thread Steven D'Aprano
On Tuesday 16 February 2016 00:05, Veek. M wrote: > When I do at the interpreter prompt, > repr( open('/etc/motd', 'rt').read() ) Opening and reading MOTD is a needless distraction from your actual question. This demonstrates the issue most simply: # at the interactive interpreter py> s = "tex

Re: Multiple Assignment a = b = c

2016-02-16 Thread Steven D'Aprano
STORE_SUBSCR 21 LOAD_CONST 0 (None) 24 RETURN_VALUE If you do the swap in the other order, it works: py> L = [10, 20, 30, 40, 50] py> a = 3 py> L[a], a = a, L[a] py> print a 40 py> print L [10, 20, 30, 3, 50] In all cases, the same rule applies: - evaluate the right hand side from left-most to right-most, pushing the values onto the stack; - perform assignments on the left hand side, from left-most to right-most. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: asyncio - run coroutine in the background

2016-02-16 Thread Steven D'Aprano
On Wed, 17 Feb 2016 01:17 am, Marko Rauhamaa wrote: > Ok, yes, but those "background tasks" monopolize the CPU once they are > scheduled to run. Can you show some code demonstrating this? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Make a unique filesystem path, without creating the file

2016-02-16 Thread Steven D'Aprano
and I > have no good reason to violate that constraint. Since your test doesn't know what filesystem your code will be running on, you can't make any assumptions about what paths are valid or not valid. > Almost. I want the filesystem paths to be valid because the system under > test expects them, it may perform its own validation, If the system tries to validate paths, it is broken. That's how you get broken applications that insist that all file names must be located in C:\\My Documents. The application should allow the file system to validate paths. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: I m facing some problem while opening the interpreter. how can I resolve the issue?

2016-02-16 Thread Steven D'Aprano
On Wednesday 17 February 2016 06:55, Chinmaya Choudhury wrote: > Please guide me. > #Chinmay > > Sent from Mail for Windows 10 How can we help you when we don't know what problem you have? Is the computer turned on? Is the mouse plugged in? Are you double-clicking the icon on the desktop? Wh

Re: Will file be closed automatically in a "for ... in open..." statement?

2016-02-16 Thread Steven D'Aprano
On Wednesday 17 February 2016 15:04, [email protected] wrote: > Thanks for these detailed explanation. Both statements will close file > automatically sooner or later and, when considering the exceptions, "with" > is better. Hope my understanding is right. > > But, just curious, how do you know

Python keyword args can be any string

2016-02-17 Thread Steven D'Aprano
Today I learned that **kwargs style keyword arguments can be any string: py> def test(**kw): ... print(kw) ... py> kwargs = {'abc-def': 42, '': 23, '---': 999, '123': 17} py> test(**kwargs) {'': 23, '123': 17, '---': 999, 'abc-def': 42} Bug or feature? -- Steve -- https://mail.python

<    53   54   55   56   57   58   59   60   61   62   >