Re: threading

2014-04-06 Thread Marko Rauhamaa
Paul Rubin : > I keep hearing about all the perils of threading bugs and it just > hasn't happened to me in Python as far as I know. Good for you. I'm saying the first step to thread-safe code is to have a healthy fear of the perils. > The main trick is to not share any mutable data between thre

Re: threading

2014-04-06 Thread Paul Rubin
Marko Rauhamaa writes: > Since then both Windows and Java have come up with their own I/O > multiplexing facilities. Now we see Python follow suit with asyncio. That all happened because threads in those systems are rather expensive. GHC and Erlang have fast lightweight threads/processes and prog

Re: threading

2014-04-06 Thread Ben Finney
Chris Angelico writes: > On Mon, Apr 7, 2014 at 1:48 PM, Roy Smith wrote: > > There is (or at least, was) another reason. Creating a new process > > used to be far more expensive than creating a new thread. In modern > > Unix kernels, however, the cost difference has become much less, so > > thi

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Marko Rauhamaa
Steven D'Aprano : > That's why optimizers like PyPy generally produce code like this: > > if some guard condition is true: > run fast optimized branch > else: > fall back on standard Python There you go! You are using Python-esque syntax to communicate a CS idea. Marko

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Steven D'Aprano
On Sun, 06 Apr 2014 20:45:47 -0400, Terry Reedy wrote: > On 4/6/2014 7:48 PM, Steven D'Aprano wrote: >> On Sun, 06 Apr 2014 23:10:47 +0300, Marko Rauhamaa wrote: >> >>> Steven D'Aprano : >>> On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: > Python, BTW, is perfectly suitable for

Re: threading

2014-04-06 Thread Marko Rauhamaa
Ben Finney : > The *whole point* of threading (AFAIK) is to share memory and other > process-distinct resources. Another way to look at it is that threads were pushed as a magic bullet to manage the complexities of network programming. They were fashionable in Windows and Java. The idea was that

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Marko Rauhamaa
Steven D'Aprano : > On Sun, 06 Apr 2014 23:10:47 +0300, Marko Rauhamaa wrote: >> It is academic because the author, Raymond Smullyan, was a professor >> of philosophy and, more importantly, my professor selected that as a >> textbook for us graduate students. > > Ah. Well they do that, don't they?

Re: threading

2014-04-06 Thread Chris Angelico
On Mon, Apr 7, 2014 at 1:48 PM, Roy Smith wrote: > There is (or at least, was) another reason. Creating a new process used > to be far more expensive than creating a new thread. In modern Unix > kernels, however, the cost difference has become much less, so this is > no longer a major issue. U

Re: threading

2014-04-06 Thread Roy Smith
In article , Ben Finney wrote: > The *whole point* of threading (AFAIK) is to share memory and other > process-distinct resources. There is (or at least, was) another reason. Creating a new process used to be far more expensive than creating a new thread. In modern Unix kernels, however, t

Re: Python streaming media server

2014-04-06 Thread Wesley
在 2014年4月6日星期日UTC+8下午8时52分37秒,Sturla Molden写道: > Wesley wrote: > > > > >> Not open source, but there is a famous closed-source one called YouTube. > > > > > > Are you kidding? > > > I know youtube, but do you think we can use it setup our own streaming > > media server? > > > > Obviousl

Re: threading

2014-04-06 Thread Rustom Mody
On Monday, April 7, 2014 8:24:37 AM UTC+5:30, Onder Hazaroglu wrote: > Hello, > I've been using threading library to run some experiments parallel. There is > no message passing between my threads but still it messes up somehow. The > results are different than running it separated. Basically I exp

Re: threading

2014-04-06 Thread Ben Finney
Onder Hazaroglu writes: > I've been using threading library to run some experiments parallel. Threading is very difficult to get right, much more so than the usual separation into distinct processes. How did you decide against the normal means of parallel execution and instead choose threading?

threading

2014-04-06 Thread Onder Hazaroglu
Hello, I've been using threading library to run some experiments parallel. There is no message passing between my threads but still it messes up somehow. The results are different than running it separated. Basically I experiment with three threads working on three different files but the results a

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Rustom Mody
On Monday, April 7, 2014 12:16:54 AM UTC+5:30, Chris Angelico wrote: > On Mon, Apr 7, 2014 at 4:13 AM, Rustom Mody wrote: > >> Using Python at the design stage would be what Steven's talking about > >> - actually using it to build the theory of programming. I have about > >> as much experience in

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Rustom Mody
On Monday, April 7, 2014 6:15:47 AM UTC+5:30, Terry Reedy wrote: > On 4/6/2014 7:48 PM, Steven D'Aprano wrote: > > On Sun, 06 Apr 2014 23:10:47 +0300, Marko Rauhamaa wrote: > >> Steven D'Aprano : > >>> On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: > Python, BTW, is perfectly suitab

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Terry Reedy
On 4/6/2014 7:48 PM, Steven D'Aprano wrote: On Sun, 06 Apr 2014 23:10:47 +0300, Marko Rauhamaa wrote: Steven D'Aprano : On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: Python, BTW, is perfectly suitable for computer science. I don't think it is. Python is not a pure functional la

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Steven D'Aprano
On Sun, 06 Apr 2014 23:10:47 +0300, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: >>> Python, BTW, is perfectly suitable for computer science. >> >> I don't think it is. Python is not a pure functional language, so it's >> very difficult

[ANN] ClamAV for Python 0.2!

2014-04-06 Thread Ryan Gonzalez
Announcing ClamAV for Python 0.2! ClamAV for Python is a set of pure-Python bindings for libclamav. This version adds basic support for callbacks and makes it work under Python 3. Check it out of PyPIand GitHub . Repo

Re: Yet Another Switch-Case Syntax Proposal

2014-04-06 Thread Chris Angelico
On Mon, Apr 7, 2014 at 6:13 AM, Michael Torrie wrote: > On 04/06/2014 12:07 PM, Chris Angelico wrote: >> This has a slight oddity of parsing (in that an expression can >> normally have a comparison in it); if you really want to use the >> result of a comparison inside a case block, you'd have to p

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Mark Lawrence
On 06/04/2014 21:10, Marko Rauhamaa wrote: Many classic CS ideas are expressed in terms of an Algol-like language. Nothing would prevent you from framing those ideas in a Python-like (pseudo)language. The question is mostly whether you prefer begin/end, braces or indentation. Of course whilst

Re: Yet Another Switch-Case Syntax Proposal

2014-04-06 Thread Ian Kelly
On Sun, Apr 6, 2014 at 11:49 AM, Lucas Malor <3kywjyd...@snkmail.com> wrote: > On 3 April 2014 20:12, Ian Kelly ian.g.kelly-at-gmail.com > |python-list@python.org| wrote: >> Use this instead [of continue]: > >> >> switch day case in ("Mon", "Tue", "Wed", "Thu", "Fri"): >> go_to_work = True >>

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Marko Rauhamaa
Chris Angelico : >>> * unfaithful husbands on an island ruled by female logicians >> >> I don't know that one. > > Me neither, although I can see elements of classic logic analysis > elements. Islands ruled by logicians, people who always tell the truth > / always tell exact falsehoods, etc, etc.

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Marko Rauhamaa
Steven D'Aprano : > On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: >> Python, BTW, is perfectly suitable for computer science. > > I don't think it is. Python is not a pure functional language, so it's > very difficult to prove anything about the code apart from running it. Many cla

Re: Yet Another Switch-Case Syntax Proposal

2014-04-06 Thread Michael Torrie
On 04/06/2014 12:07 PM, Chris Angelico wrote: > This has a slight oddity of parsing (in that an expression can > normally have a comparison in it); if you really want to use the > result of a comparison inside a case block, you'd have to parenthesize > it. But it's easy enough to explain to a human

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Chris Angelico
On Mon, Apr 7, 2014 at 4:13 AM, Rustom Mody wrote: > Is the diff between cvs/svn and git "just one vcs or another"? The theory of version control, or source control, or whatever you want to call it, can be found in some of the docs for those systems (git goes into some depth about the Directed Ac

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Rustom Mody
On Sunday, April 6, 2014 11:24:15 PM UTC+5:30, Chris Angelico wrote: > On Mon, Apr 7, 2014 at 3:31 AM, Rustom Mody wrote: > > However consider that some of the things that people did around 40 years > > ago and do today > > - use FORTRAN for numerical/simulation work -- now use scipy/sage etc > >

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Chris Angelico
On Mon, Apr 7, 2014 at 4:09 AM, Mark Lawrence wrote: > On 06/04/2014 18:27, Chris Angelico wrote: >> >> (plus, why on earth can't they afford a few more forks in the >> interests of hygiene??!?). > > > They couldn't get the purchase order for these capital cost items past the > accountants. That

Re: Yet Another Switch-Case Syntax Proposal

2014-04-06 Thread Chris Angelico
On Mon, Apr 7, 2014 at 3:49 AM, Marco S. wrote: > switch day case in briefing_days: > > lunch_time = datetime.time(11, 30) > meeting_time = datetime.time(12, 30) > case not in briefing_days + festive_days: > > lunch_time = datetime.time(12) > meeting_time = datetime.time(14) > case

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Mark Lawrence
On 06/04/2014 18:27, Chris Angelico wrote: (plus, why on earth can't they afford a few more forks in the interests of hygiene??!?). They couldn't get the purchase order for these capital cost items past the accountants. -- My fellow Pythonistas, ask not what our language can do for you, ask

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Chris Angelico
On Mon, Apr 7, 2014 at 3:31 AM, Rustom Mody wrote: > However consider that some of the things that people did around 40 years > ago and do today > > - use FORTRAN for numerical/simulation work -- now use scipy/sage etc > - NLP with Lisp/Prolog -- look at Nltk > - ??? with Data Analysis in Pandas

Re: Yet Another Switch-Case Syntax Proposal

2014-04-06 Thread Marco S.
On 3 April 2014 20:12, Ian Kelly ian.g.kelly-at-gmail.com | python-list@python.org| wrote: > Use this instead [of continue]: > > switch day case in ("Mon", "Tue", "Wed", "Thu", "Fri"): > go_to_work = True > day_type = "ferial" > if day in ("Tue", "Thu"): > lunch_time = datetime

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Rustom Mody
On Sunday, April 6, 2014 10:22:21 PM UTC+5:30, Steven D'Aprano wrote: > On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: > > Mark H Harris : > >> On 4/4/14 4:53 AM, Steven D'Aprano wrote: > >>> Python is not a computer-science-ey language. > >> Every programming language is interesting fr

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Chris Angelico
On Mon, Apr 7, 2014 at 2:52 AM, Steven D'Aprano wrote: > (4) This is the category which I was referring to when I said that Python > wasn't a "computer-science-ey language": do people use Python for > research into language-independent fundamental principles of computation? > I don't think so. I a

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Steven D'Aprano
On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote: > Mark H Harris : > >> On 4/4/14 4:53 AM, Steven D'Aprano wrote: >>> Python is not a computer-science-ey language. >> >> Every programming language is interesting from a comp sci standpoint. >> Some are more useful for research; python is

Re: Mutable objects inside tuples - good or bad?

2014-04-06 Thread Rustom Mody
On Sunday, April 6, 2014 1:40:58 PM UTC+5:45, Devin Jeanpierre wrote: > > You can choose to define mutability that way, but in many contexts > you'll find that definition not very useful. > > c is such that you could have another variable d, where the following > interpreter session fragment is e

Re: How can I parse this correctly?

2014-04-06 Thread Tim Chase
On 2014-04-06 14:21, Ben Finney wrote: > I assume you mean you will be creating ‘datetime.date’ objects. What > will you set as the month and day? > > Alternatively, if you just want to do integer arithmetic on the > year, you don't need the ‘datetime’ module at all. Even if you do the arithmetic

Re: Python streaming media server

2014-04-06 Thread Sturla Molden
Wesley wrote: >> Not open source, but there is a famous closed-source one called YouTube. > > Are you kidding? > I know youtube, but do you think we can use it setup our own streaming media > server? Obviously not. Before YouTube was bought by Google, it was common knowledge that it ran on S

Re: How can I parse this correctly?

2014-04-06 Thread Mark Lawrence
On 06/04/2014 12:54, Chris Angelico wrote: On Sun, Apr 6, 2014 at 9:32 PM, Mark Lawrence wrote: I'd recommend using this import statement in Python 2 so you get used to print being a function. from __future__ import print_function Or better still, just write Python 3 code - then you get to t

Re: How can I parse this correctly?

2014-04-06 Thread Chris Angelico
On Sun, Apr 6, 2014 at 9:32 PM, Mark Lawrence wrote: > I'd recommend using this import statement in Python 2 so you get used to > print being a function. > > from __future__ import print_function Or better still, just write Python 3 code - then you get to take advantage of all the fancy new featu

Re: Python streaming media server

2014-04-06 Thread Mark Lawrence
On 06/04/2014 05:31, Wesley wrote: 在 2014年4月5日星期六UTC+8下午6时11分02秒,Wesley写道: Hi, Anyone knows open source streaming media server written by Python? I am trying to setup a streaming media server in python, wanna find an existing one and have a look. Thanks. Wesley After a lot google w

Re: How can I parse this correctly?

2014-04-06 Thread Mark Lawrence
On 06/04/2014 09:17, Chris Angelico wrote: On Sun, Apr 6, 2014 at 4:29 PM, Anthony Papillion wrote: No particular reason at all. I've Bern dabbling in Python for the last bit and am just writing code based on the samples or examples I'm finding. What was the tipoff that this was not Python 3?

Re: Mutable objects inside tuples - good or bad?

2014-04-06 Thread Devin Jeanpierre
On Sun, Apr 6, 2014 at 1:25 AM, Chris Angelico wrote: > On Sun, Apr 6, 2014 at 5:55 PM, Devin Jeanpierre > wrote: >> Agreed. Putting mutable objects inside tuples is common and totally OK. > > There are many programming habits that can cause problems, even though > they won't break Python and ar

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Marko Rauhamaa
Mark H Harris : > On 4/4/14 4:53 AM, Steven D'Aprano wrote: >> Python is not a computer-science-ey language. > > Every programming language is interesting from a comp sci standpoint. > Some are more useful for research; python is one of those. > > For what reasons do you disagree? Computer scienc

Re: A data conversion question

2014-04-06 Thread Peter Otten
Mok-Kong Shen wrote: > A newbie's question of curiosity: > > If I have > > g=[1,[2]] and > > bg=bytearray(str(g),"latin-1") > > could I somehow get back from bg a list g1 that is the same as g? Not for arbitrary values, but for lists, ints, and a few other types that's not a problem: >>> g

Re: How can I parse this correctly?

2014-04-06 Thread Chris Angelico
On Sun, Apr 6, 2014 at 6:16 PM, Ben Finney wrote: >> print int(row['YEAR'] or ) > > “foo or bar” is not a Pythonic way to get a default value; it relies on > quirks of implementation and is not expressive as to the meaning you > intend. > > Rather, be explicit: > > # Default to the beginni

Re: Mutable objects inside tuples - good or bad?

2014-04-06 Thread Chris Angelico
On Sun, Apr 6, 2014 at 5:55 PM, Devin Jeanpierre wrote: > On Sun, Apr 6, 2014 at 12:25 AM, Gary Herron > wrote: >> On 04/05/2014 11:53 PM, John Ladasky wrote: >>> >>> I find this programming pattern to be useful... but can it cause problems? >> >> No. >> >> What kind of problems are you consideri

Re: Keeping track of things with dictionaries

2014-04-06 Thread Peter Otten
Giuliano Bertoletti wrote: > I frequently use this pattern to keep track of incoming data (for > example, to sum up sales of a specific brand): > > = > > # read a brand record from a db > ... > > # keep track of brands seen > obj = brands_seen.get(brandname)

Re: How can I parse this correctly?

2014-04-06 Thread Chris Angelico
On Sun, Apr 6, 2014 at 4:29 PM, Anthony Papillion wrote: > No particular reason at all. I've Bern dabbling in Python for the last bit > and am just writing code based on the samples or examples I'm finding. What > was the tipoff that this was not Python 3? Would there be a large difference > in t

Re: How can I parse this correctly?

2014-04-06 Thread Ben Finney
Anthony Papillion writes: > On Apr 5, 2014, at 23:21, Ben Finney wrote: > > Alternatively, if you just want to do integer arithmetic on the > > year, you don't need the ‘datetime’ module at all. > > True. But I do actually need to some date based calculations. > Basically I'm processing a large

A data conversion question

2014-04-06 Thread Mok-Kong Shen
A newbie's question of curiosity: If I have g=[1,[2]] and bg=bytearray(str(g),"latin-1") could I somehow get back from bg a list g1 that is the same as g? Thanks in advance. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Mark H Harris
On 4/4/14 4:53 AM, Steven D'Aprano wrote: > Python is not a computer-science-ey language. Really ? > It is of little or no > interest to computer scientists involved in the mathematics of > computation, ... you mean no one except me, then ? > or compiler-theory, or type-theory, or any o

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Mark H Harris
On 4/4/14 4:53 AM, Steven D'Aprano wrote: Python is not a computer-science-ey language. Really ? It is of little or no interest to computer scientists involved in the mathematics of computation, ... you mean no one except me, then ? or compiler-theory, or type-theory, or any of the

Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-04-06 Thread Mark H Harris
On 4/4/14 4:53 AM, Steven D'Aprano wrote: Python is not a computer-science-ey language. Every programming language is interesting from a comp sci standpoint. Some are more useful for research; python is one of those. For what reasons do you disagree? marcus -- https://mail.python.org/mail

Re: Mutable objects inside tuples - good or bad?

2014-04-06 Thread Devin Jeanpierre
On Sun, Apr 6, 2014 at 12:25 AM, Gary Herron wrote: > On 04/05/2014 11:53 PM, John Ladasky wrote: >> >> I find this programming pattern to be useful... but can it cause problems? > > No. > > What kind of problems are you considering? It won't break Python. It's > perfectly legal code. Agreed. Pu

Keeping track of things with dictionaries

2014-04-06 Thread Giuliano Bertoletti
I frequently use this pattern to keep track of incoming data (for example, to sum up sales of a specific brand): = # read a brand record from a db ... # keep track of brands seen obj = brands_seen.get(brandname) if obj is None: obj = Brand() brands_s

Re: Mutable objects inside tuples - good or bad?

2014-04-06 Thread Gary Herron
On 04/05/2014 11:53 PM, John Ladasky wrote: I find this programming pattern to be useful... but can it cause problems? No. What kind of problems are you considering? It won't break Python. It's perfectly legal code. The tuple c is still immutable, consisting of two specific objects, and (a