Re: OT: This Swift thing

2014-06-11 Thread Gregory Ewing

Rustom Mody wrote:

JFTR: Information processing and (physics) energy are about as convertible
as say: "Is a kilogram smaller/greater than a mile?"


Actually, that's not true. There is a fundamental
thermodynamic limit on the minimum energy needed to
flip a bit from one state to the other, so in that
sense there's a relationship between watts and
bits per second.

We're nowhere near reaching that limit with
current technology, though. In principle, our
CPUs could be a lot more energy-efficient.

(That doesn't mean they would convert a smaller
proportion of their energy input into heat. It
means they would need less energy input in the
first place).

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


asyncio - how to stop loop?

2014-06-11 Thread Frank Millman
Hi all

I have a 'start.py' script that kicks off my program by starting a number of 
services.

For now, I stop it by allowing the user to press , after which I 
close down the services and stop the program. (For production I imagine it 
would be better to run it in the background and send it some kind of signal 
to terminate, but for testing this suffices.)

As one of the services is a 'listening' loop, which would normally prevent 
access to the keyboard, I start it in a separate thread. For example, when I 
was using cherrypy as the server, I had -

server = cherrypy.wsgiserver.CherryPyWSGIServer((host, port), 
dispatcher)
threading.Thread(target=server.start).start()
input('Press  to stop')
server.stop()

Now I am playing with asyncio, but I cannot get it to behave the same.

Here are my attempts. I use python 3.4.1, and I tested on Windows and 
Linux - the results are different on each platform.

First attempt - same as before

loop = asyncio.get_event_loop()
threading.Thread(target=loop.run_forever).start()
input('Press  to stop')
loop.stop()
loop.close()

Windows traceback -

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python34\lib\threading.py", line 920, in _bootstrap_inner
self.run()
  File "C:\Python34\lib\threading.py", line 868, in run
self._target(*self._args, **self._kwargs)
  File "C:\Python34\lib\asyncio\base_events.py", line 184, in run_forever
self._run_once()
  File "C:\Python34\lib\asyncio\base_events.py", line 795, in _run_once
event_list = self._selector.select(timeout)
AttributeError: 'NoneType' object has no attribute 'select'

With Linux, it does not terminate. If I press Ctrl_C, I get this traceback 
(hope there are no typos) -

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/threading.py", line 1294, in _shutdown
t.join()
  File "/usr/local/lib/python3.4/threading.py", line 1060, in join
self._wait_for_tstate_lock()
  File "/usr/local/lib/python3.4/threading.py", line 1076, in 
_wait_for_tstate_lock
elif lock.acquire(block, timeout):
KeyboardInterrupt


Second attempt - move the keyboard input to a separate thread

def stop_loop():
input('Press  to stop')
loop.stop()
loop.close()

loop = asyncio.get_event_loop()
threading.Thread(target=stop_loop).start()
loop.run_forever()

With Windows, it works - the program closes cleanly.

With Linux, it does not terminate. If I press Ctrl_C, I get this traceback 
(hope there are no typos) -

Traceback (most recent call last):
  File "test_async.py", line 20, in 
loop.run_forever()
  File "/usr/local/lib/python3.4/asyncio.base_events.py", line 184, in 
run_forever
self._run_once()
  File "/usr/local/lib/python3.4/asyncio.base_events.py", line 795, in 
_run_once
event_list = self._selector.select(timeout)
  File "/usr/local/lib/python3.4/asyncio.selectors.py", line 424, in select
fd_event_list = self._epoll.poll(timeout, max_cv)
KeyboardInterrupt


Third attempt - get the loop to close itself (cannot use in practice, but 
see what happens)

def stop_loop():
loop.stop()
loop.close()

loop = asyncio.get_event_loop()
loop.call_later(2, stop_loop)
loop.run_forever()

Both platforms show the same traceback, after two seconds -

Traceback (most recent call last):
  File "C:\Documents and Settings\frank\aib\aib_async\test_async.py", line 
29, in 
loop.run_forever()
  File "C:\Python34\lib\asyncio\base_events.py", line 184, in run_forever
self._run_once()
  File "C:\Python34\lib\asyncio\base_events.py", line 795, in _run_once
event_list = self._selector.select(timeout)
AttributeError: 'NoneType' object has no attribute 'select'

Can anyone suggest a way to get the loop to stop cleanly?

Thanks

Frank Millman



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-11 Thread Gregory Ewing

Steven D'Aprano wrote:
Everything *eventually* gets converted to heat, but not immediately. 
There's a big difference between a car that gets 100 miles to the gallon, 
and one that gets 1 mile to the gallon.


With a car, the engine converts some of its energy to
kinetic energy, which is subsequently dissipated as heat,
so it makes sense to talk about the ratio of kinetic
energy produced to energy wasted directly as heat.

But when you flip a bit, there's no intermediate form
of energy -- the bit changes state, and heat is produced.
So all of the heat is waste heat.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-11 Thread Gregory Ewing

Chris Angelico wrote:

So, let me get this straight. A CPU has to have a fan, but a car
engine doesn't, because the car's moving at a hundred kays an hour. I
have a suspicion the CPU fan moves air a bit slower than that.


If the car were *always* moving at 100km/h, it probably
wouldn't need a fan.

In practice, all cars do have fans (even the ones that
aren't air-cooled), for the occasions when they're not
moving that fast.

(BTW, so-called water-cooled engines are really air-cooled
too, just not by air flowing directly over the engine
block. (Although marine engines may be an exception.))

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Micro Python -- a lean and efficient implementation of Python 3

2014-06-11 Thread alister
On Wed, 11 Jun 2014 08:29:06 +1000, Tim Delaney wrote:

> On 11 June 2014 05:43, alister  wrote:
> 
> 
>> Your error reports always seem to resolve around benchmarks despite
>> speed not being one of Pythons prime objectives
>>
>>
> By his own admission, jmf doesn't use Python anymore. His only reason to
> remain on this emailing/newsgroup is to troll about the FSR. Please
> don't reply to him (and preferably add him to your killfile).
> 

I couldn't kill file JMF I find his posts useful
Every time i find myself agreeing with him I know I have got it wrong.



-- 
The nice thing about Windows is - It does not just crash, it displays a
dialog box and lets you press 'OK' first.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: First time I looked at Python was(...)

2014-06-11 Thread alister
On Tue, 10 Jun 2014 22:15:29 +0100, Carlos Anselmo Dias wrote:

> Hi...
> 
> I don't understand the 'problem' of several people ...
> 
> I created one post because I've several projects, I'm looking for one
> team of experienced experts in Python to work in my projects ... asap
> ... I provided one script(I'm not one expert in Python) to help people
> think and described the projects(briefly) ...

Congratulations
This is the first time in this whole thread that you have stated you are 
asking for programmers to assist with a project.

Thank you  this is the missing piece of information that we have become 
fed-up been asking for.

This is not a recruiting forum so you would be better of asking elsewhere.
when you do please help yourself by not only stating that you are trying 
to recruit programmer but also give some indication on the scope of the 
project





-- 
A compliment is something like a kiss through a veil.
-- Victor Hugo
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: try/except/finally

2014-06-11 Thread alister
On Wed, 11 Jun 2014 00:00:49 +, Steven D'Aprano wrote:

> On Wed, 11 Jun 2014 06:37:01 +1000, Chris Angelico wrote:
> 
>> I don't know a single piece of programming advice which, if taken as an
>> inviolate rule, doesn't at some point cause suboptimal code.
> 
> "Don't try to program while your cat is sleeping on the keyboard."

My cat is a better programmer than I am !



-- 
Hors d'oeuvres -- a ham sandwich cut into forty pieces.
-- Jack Benny
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: First time I looked at Python was(...)

2014-06-11 Thread Carlos Anselmo Dias


On 06/11/2014 09:34 AM, alister wrote:

On Tue, 10 Jun 2014 22:15:29 +0100, Carlos Anselmo Dias wrote:


Hi...

I don't understand the 'problem' of several people ...

I created one post because I've several projects, I'm looking for one
team of experienced experts in Python to work in my projects ... asap
... I provided one script(I'm not one expert in Python) to help people
think and described the projects(briefly) ...

Congratulations
This is the first time in this whole thread that you have stated you are
asking for programmers to assist with a project.

Thank you  this is the missing piece of information that we have become
fed-up been asking for.

This is not a recruiting forum so you would be better of asking elsewhere.
when you do please help yourself by not only stating that you are trying
to recruit programmer but also give some indication on the scope of the
project







Hi ...

Good morning ...

What a confusion/headache(...)

I'm waiting for traffic of search engines in one subsection of one main 
section to step forward with the organization of what I described 
briefly I'd write ...



Like I explained there are 500 millions of thumbs to import and 20 
million of thumbs every month in that sub-section ...


I don't need assistance, I'll need one team of programmers to work ...

I'm not writing more posts/emails.

(...)

Best regards,
Carlos
--
https://mail.python.org/mailman/listinfo/python-list


Re: First time I looked at Python was(...)

2014-06-11 Thread Carlos Anselmo Dias


On 06/11/2014 05:42 AM, Michael Torrie wrote:

On 06/10/2014 03:15 PM, Carlos Anselmo Dias wrote:

Hi...

I don't understand the 'problem' of several people ...

I created one post because I've several projects, I'm looking for one
team of experienced experts in Python to work in my projects ... asap
... I provided one script(I'm not one expert in Python) to help people
think and described the projects(briefly) ...

Your e-mails are so difficult to parse and understand that your message
was lost in the noise.  In fact this is the first post of yours that I
can even partly understand.  Your unconventional and incorrect sentence
structure makes it very hard to understand you.  I doubt most people
reading your e-mails can even tell what you want and why you are writing.


People start calling me troll,etc-> Are this people not insane? And I
don't understand their paranoia ...

After you post a dozen undecipherable posts (literally I cannot
understand them), and keep posting undecipherable, strange sentence
fragments, surely it's understandable why people are frustrated and
annoyed.  You excuse yourself by saying English isn't your first
language.  Well, we say, please correct your sentence structure, speak
simply and clearly, don't get upset, and you'll get people responding to
you positively.


Those who call me troll ... look at the mirror and criticize what I
wrote if you're capable of ... with sense and reasoning ... not like
someone absurd who is not capable of and tries to demonstrate that is
the greatest ... these people should get real ...

I'd criticize what you wrote if I could understand it.  I for one still
do not know what these "projects" of yours are, or what kind of help you
desire.  If you need to hire programming assistance, just say so.  State
your terms of hire.  There are freelancers on this list.  If you're
looking for free help, you might get some of that, especially if the
projects themselves will be open source.


The www,etc is full of ridiculous people with ridiculous ideas/projects 
...considering themselves the greatest,etc and are nothing but a bunch 
of absurd ... ones worst than the others ... "SHIT to be more precise!"


Copy/paste of 2 emails I sent (...)


---1st---

Hi ...

Good morning ...

What a confusion/headache(...)

I'm waiting for traffic of search engines in one subsection of one main 
section to step forward with the organization of what I described 
briefly I'd write ...



Like I explained there are 500 millions of thumbs to import and 20 
million of thumbs every month in that sub-section ...


I don't need assistance, I'll need one team of programmers to work ...

I'm not writing more posts/emails.

(...)

Best regards,
Carlos

---2nd 

If I was thinking that people were capable of understanding what's about 
... exceeding the barrier of databases, billions of files indexed,etc 
... look at that like client apis ... with logs, advertisement, etc 
integrated ... in main-sections with sub-sections ... with control of 
cache, web-services, etc ... I tried to resume it briefly and it's about 
what I described here ...


I want that people (can) think about it ... like I wrote ... when the 
sub-section of one main section starts receiving traffic from search 
engines ... it will be possible to think in other main sections, 
organize everything,etc ...


(...)

Best regards,
Carlos
--
https://mail.python.org/mailman/listinfo/python-list


基于cython的即时编译器cyjit,欢迎大家提建议

2014-06-11 Thread 1989lzhh
我正在写一个使用cython code作为后端的即时编译器名为cyjit,将python code 转换为cython code再编译为c 
extension导入.设计上主要参考numba.jit的思路,使用decorate来指定要编译的function,例如:
from cyjit import jit
@jit('int(int,int)')
def add(a,b):
return a+b
add(1,2)#compiled

@jit('int(int,int)',
locals='''
int c
''')
def add1(a,b):
c=add(a,b)# fast invoked
return c
add1(1,2)

目前还不支持类型推导,需要手动使用c的语法对局部变量进行定义。
编译过程是在jit函数中完成的,后续计划将编译过程移到函数运行时完成,实现重载。
目前支持编译cache,第一次运行需要编译,时间稍慢,再次运行直接导入编译好的extension,速度就很快了。

欢迎大家fork,pull,提建议。
https://github.com/liuzhenhai/cyjit



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Micro Python -- a lean and efficient implementation of Python 3

2014-06-11 Thread Ben Finney
alister  writes:

> On Wed, 11 Jun 2014 08:29:06 +1000, Tim Delaney wrote:
> > By his own admission, jmf doesn't use Python anymore. His only
> > reason to remain on this emailing/newsgroup is to troll about the
> > FSR. Please don't reply to him (and preferably add him to your
> > killfile).
>
> I couldn't kill file JMF I find his posts useful

That's fine, kill-filing his posts is a matter that affects only you.

But please do not reply to them, nor taunt him in unrelated posts; it
disrupts this forum.
Instead, give him no reason to think anyone is interested.

-- 
 \ “Too many pieces of music finish too long after the end.” —Igor |
  `\   Stravinskey |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Python's re module and genealogy problem

2014-06-11 Thread BrJohan

For some genealogical purposes I consider using Python's re module.

Rather many names can be spelled in a number of similar ways, and in 
order to match names even if they are spelled differently, I will build 
regular expressions, each of which is supposed to match  a number of 
similar names.


I guess that there will be a few hundred such regular expressions 
covering most popular names.


Now, my problem: Is there a way to decide whether any two - or more - of 
those regular expressions will match the same string?


Or, stated a little differently:

Can it, for a pair of regular expressions be decided whether at least 
one string matching both of those regular expressions, can be constructed?


If it is possible to make such a decision, then how? Anyone aware of an 
algorithm for this?

--
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-11 Thread Steven D'Aprano
On Wed, 11 Jun 2014 19:50:20 +1200, Gregory Ewing wrote:

> Chris Angelico wrote:
>> So, let me get this straight. A CPU has to have a fan, but a car engine
>> doesn't, because the car's moving at a hundred kays an hour. I have a
>> suspicion the CPU fan moves air a bit slower than that.

I'm not sure where Chris' message comes from, I can't see the original, 
so I'm guessing the context.

Air cooled cars don't just cool the engine when they are travelling at 
100kmh. Some air-cooled engines used a fan to blow extra air over the 
cooling fins, but many did not. Normal air flow is sufficient to keep 
them in a safe operating temperature, the hot engine warms the air, which 
flows away and is replaced by cooler air.

It's possible to design CPUs to work the same way. My wife is using a PC 
right now with a 1.66GHz Atom CPU and no CPU fan. Even though the power 
supply fan died, the machine is still running perfectly, with two laptop 
HDDs, and no overheating. 1.66GHz is plenty fast enough for web browsing, 
word processing, email, etc.

Go back 30 years, and I don't think that the average PC needed a CPU fan. 
Possibly not even a case fan. Just the normal air flow over a small heat 
sink was enough. And of course, your mobile phone has no room for a heat 
sink, unless it's tiny, and no fan. And people expect it to keep working 
even when shoved in their pocket.


> If the car were *always* moving at 100km/h, it probably wouldn't need a
> fan.
>
> In practice, all cars do have fans (even the ones that aren't
> air-cooled), for the occasions when they're not moving that fast.

That may be true of water-cooled engines *now*, but it's not a law of 
engineering. Many air-cooled engines do not (did not) require a fan, or 
only needed the extra cooling when stuck idling for long periods in hot 
weather. E.g. Beetles didn't use a fan. (A great idea for Germany, not so 
much for hot and dusty Southern California, as my wife can tell you.)


> (BTW, so-called water-cooled engines are really air-cooled too, just not
> by air flowing directly over the engine block. (Although marine engines
> may be an exception.))

Yes, technically water-cooled engines are cooled by air too. The engine 
heats a coolant (despite the name, usually not water these days) which 
then heats the air.


-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-11 Thread Roy Smith
In article <[email protected]>,
 Steven D'Aprano  wrote:

> Yes, technically water-cooled engines are cooled by air too. The engine 
> heats a coolant (despite the name, usually not water these days) which 
> then heats the air.

Not water???  I'm not aware of any water-cooled engines which use 
anything other than water.  Well, OK, it's really a solution of ethylene 
or propylene glycol in water, but the water is what does most of the 
heat transfer.  The glycol is just there to provide freezing point 
depression and boiling point elevation.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: try/except/finally

2014-06-11 Thread Roy Smith
In article ,
 alister  wrote:

> On Wed, 11 Jun 2014 00:00:49 +, Steven D'Aprano wrote:
> 
> > On Wed, 11 Jun 2014 06:37:01 +1000, Chris Angelico wrote:
> > 
> >> I don't know a single piece of programming advice which, if taken as an
> >> inviolate rule, doesn't at some point cause suboptimal code.
> > 
> > "Don't try to program while your cat is sleeping on the keyboard."
> 
> My cat is a better programmer than I am !

My girlfriend's cat is smarter than me!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python's re module and genealogy problem

2014-06-11 Thread Robert Kern

On 2014-06-11 13:23, BrJohan wrote:

For some genealogical purposes I consider using Python's re module.

Rather many names can be spelled in a number of similar ways, and in order to
match names even if they are spelled differently, I will build regular
expressions, each of which is supposed to match  a number of similar names.

I guess that there will be a few hundred such regular expressions covering most
popular names.

Now, my problem: Is there a way to decide whether any two - or more - of those
regular expressions will match the same string?

Or, stated a little differently:

Can it, for a pair of regular expressions be decided whether at least one string
matching both of those regular expressions, can be constructed?

If it is possible to make such a decision, then how? Anyone aware of an
algorithm for this?


And if that isn't the best straight line for the old saying, I don't know what 
is.

  http://en.wikiquote.org/wiki/Jamie_Zawinski

Anyways, to your new problem, yes it's possible. Search for "regular expression 
intersection" for possible approaches. You will probably have to translate the 
regular expression to a different formalism or at least a different library to 
implement this.


Consider just listing out the different possibilities. All of your regexes 
should be "well-behaved" given the constraints of the domain (tightly bounded, 
at least). There are tools that help generate matching strings from a Python 
regex. This will help you QA your regexes, too, to be sure that they match what 
you expect them to and not match non-names.


  https://github.com/asciimoo/exrex

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
https://mail.python.org/mailman/listinfo/python-list


My last message(...)

2014-06-11 Thread Carlos Anselmo Dias

Hi ...

So I'm not receiving more emails from Python mailing list or 
posting/sending more messages ...


I'm keeping your emails that I received to contact all of you when it 
will be time to step forward ...


If you want you can send me your cv or one small text to 
[email protected] ... You can use my email too ...


If what I wrote is not enough(describing the projects,etc), to be honest 
I wouldn't write anything else besides that ...


I'm not really interested in what you did, I'm interested in what you're 
capable of doing and what you're capable of doing is integrated in one 
team of Python programmers to organize, manage, develop, implement 
everything related with ...


My messages are with the subject 'python team(...)' + 'First time I 
looked at Python was(...)'


(...)

Best regards,
Carlos
--
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-11 Thread Steven D'Aprano
On Wed, 11 Jun 2014 19:41:12 +1200, Gregory Ewing wrote:

> Steven D'Aprano wrote:
>> Everything *eventually* gets converted to heat, but not immediately.
>> There's a big difference between a car that gets 100 miles to the
>> gallon, and one that gets 1 mile to the gallon.
> 
> With a car, the engine converts some of its energy to kinetic energy,
> which is subsequently dissipated as heat, so it makes sense to talk
> about the ratio of kinetic energy produced to energy wasted directly as
> heat.
> 
> But when you flip a bit, there's no intermediate form of energy -- the
> bit changes state, and heat is produced. So all of the heat is waste
> heat.

Not the point. There's a minimum amount of energy required to flip a bit. 
Everything beyond that is, in a sense, just wasted. You mentioned this 
yourself in your previous post. It's a *really* tiny amount of energy: 
about 17 meV at room temperature. That's 17 milli electron-volt, or 
2.7×10^-21 joules. In comparison, Intel CMOS transistors have a gate 
charging energy of about 62500 eV (1×10^-14 J), around 3.7 million times 
greater.

Broadly speaking, if the fundamental thermodynamic minimum amount of 
energy needed to flip a bit takes the equivalent of a single grain of 
white rice, then our current computing technology uses the equivalent of 
175 Big Macs.

(There are approximately 50 grains of rice in a gram, and a gram of rice 
is about 1.3 Calories. A Big Mac is about 550 Calories. You do the maths.)


-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: asyncio - how to stop loop?

2014-06-11 Thread Ian Kelly
On Wed, Jun 11, 2014 at 1:19 AM, Frank Millman  wrote:
> First attempt - same as before
>
> loop = asyncio.get_event_loop()
> threading.Thread(target=loop.run_forever).start()
> input('Press  to stop')
> loop.stop()
> loop.close()

Each event loop is hosted by a specific thread.  In this case you're
getting the event loop of the main thread and then trying to run it in
a separate thread, which is not a good idea.  You can run an event
loop in a separate thread, but you should install a separate event
loop for that thread if you do (and then when you interact with the
loop, do so in a thread-safe manner -- see below).

> Second attempt - move the keyboard input to a separate thread
>
> def stop_loop():
> input('Press  to stop')
> loop.stop()
> loop.close()
>
> loop = asyncio.get_event_loop()
> threading.Thread(target=stop_loop).start()
> loop.run_forever()

One issue here is that (like most event loop implementations) event
loops are not thread-safe.  To make a call to the event loop across
threads, you should be using the call_soon_threadsafe method, e.g.
"loop.call_soon_threadsafe(loop.stop)".  You'll also want to make sure
that the event loop has actually stopped before you call loop.close --
see below.

> Third attempt - get the loop to close itself (cannot use in practice, but
> see what happens)
>
> def stop_loop():
> loop.stop()
> loop.close()
>
> loop = asyncio.get_event_loop()
> loop.call_later(2, stop_loop)
> loop.run_forever()

I think what's happening here is that per the docs loop.close should
not be called while the loop is running.  You've called loop.stop but
you're still inside a callback, which is a bit of a gray area.  You
probably don't need to call loop.close at all, but if you want to do
so I suggest putting it after the run_forever call, so you can be
certain the loop has stopped when it's called.

Putting all that together, you should have something like this:

def stop_loop():
input('Press  to stop')
loop.call_soon_threadsafe(loop.stop)

loop = asyncio.get_event_loop()
threading.Thread(target=stop_loop).start()
loop.run_forever()
loop.close()  # optional
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python's re module and genealogy problem

2014-06-11 Thread Thomas Rachel

Am 11.06.2014 14:23 schrieb BrJohan:


Can it, for a pair of regular expressions be decided whether at least
one string matching both of those regular expressions, can be constructed?

If it is possible to make such a decision, then how? Anyone aware of an
algorithm for this?


Just a feeling-based statement: I don't think that is easily possible.

Every RE can potentially match an infinite number of statements.

Just have a look at

re1 = re.compile('A43.*')
re2 = re.compile('.*[0-9][A-F]')

It can easily seen that the area these REs work on is different; they 
are orthogonal.


So there is an infinite number of strings these REs match.


Thomas

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python's re module and genealogy problem

2014-06-11 Thread Mark H Harris

On 6/11/14 8:26 AM, Robert Kern wrote:

Anyways, to your new problem, yes it's possible. Search for "regular
expression intersection" for possible approaches.


I agree,  I would not use a decision (decision tree) but would consider 
a set of filters from most specific to least specific.


marcus


--
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-11 Thread Rustom Mody
On Wednesday, June 11, 2014 1:11:12 PM UTC+5:30, Gregory Ewing wrote:
> Steven D'Aprano wrote:
> > Everything *eventually* gets converted to heat, but not immediately. 
> > There's a big difference between a car that gets 100 miles to the gallon, 
> > and one that gets 1 mile to the gallon.

> With a car, the engine converts some of its energy to
> kinetic energy, which is subsequently dissipated as heat,
> so it makes sense to talk about the ratio of kinetic
> energy produced to energy wasted directly as heat.

> But when you flip a bit, there's no intermediate form
> of energy -- the bit changes state, and heat is produced.
> So all of the heat is waste heat.

Actually the car-drive and the bit-flip are much more identical than
different.  Its just that the time-scales are minutes/hours in one
case and nanoseconds or less in the other so our powers of
visualization are a bit taxed.

In more detail:

One drives a car from A to B for an hour (assume no change in 
height above sea level so no potential difference).
All the energy that was there as petrol has been dissipated as heat.

A bit flips from zero to one. Pictorially
(this needs to be fixed-pitch font!):

   +-
   | 
   | 
   | 
---+ 

However in reality that 'square' wave is always actually sloped


   +--
  /  
 /
/
---+

Now for say CMOS technology, one may assume no currents in both zero
and one states (thats the C in CMOS). However when its neither zero
nor one (the sloping part) there will be current and therefore heat.

So just as the car burns energy in going from A to B, the flipflop
burns it in going from 0 to 1


Steven D'Aprano wrote:
> Not the point. There's a minimum amount of energy required to flip a bit.
> Everything beyond that is, in a sense, just wasted. You mentioned this
> yourself in your previous post. It's a *really* tiny amount of energy:
> about 17 meV at room temperature. That's 17 milli electron-volt, or
> 2.7×10^-21 joules. In comparison, Intel CMOS transistors have a gate
> charging energy of about 62500 eV (1×10^-14 J), around 3.7 million times
> greater.
>  
> Broadly speaking, if the fundamental thermodynamic minimum amount of
> energy needed to flip a bit takes the equivalent of a single grain of
> white rice, then our current computing technology uses the equivalent of
> 175 Big Macs. 

Well thats in the same realm as saying that by E=mc² a one gram stone can yield
21 billion calories energy.

[Ive forgotten how the units stack up, so as usual relyin on google
instead of first principles:

http://en.wikipedia.org/wiki/Mass%E2%80%93energy_equivalence#Practical_examples
:-)
]

ie. from a a pragmatic/engineering pov we know as much how to use
Einstein's energy-mass-equivalence to generate energy as we know how
to use Landauer's principle to optimally flip bits.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python's re module and genealogy problem

2014-06-11 Thread Michael Torrie
On 06/11/2014 06:23 AM, BrJohan wrote:
> For some genealogical purposes I consider using Python's re module.
> 
> Rather many names can be spelled in a number of similar ways, and in 
> order to match names even if they are spelled differently, I will build 
> regular expressions, each of which is supposed to match  a number of 
> similar names.
> 
> I guess that there will be a few hundred such regular expressions 
> covering most popular names.
> 
> Now, my problem: Is there a way to decide whether any two - or more - of 
> those regular expressions will match the same string?
> 
> Or, stated a little differently:
> 
> Can it, for a pair of regular expressions be decided whether at least 
> one string matching both of those regular expressions, can be constructed?
> 
> If it is possible to make such a decision, then how? Anyone aware of an 
> algorithm for this?

You might want to search for fuzzy matching algorithms. Years ago, there
was an algorithm called soundex that would generate fuzzy fingerprints
for words that would hide differences in spelling, etc.  Unfortunately
such an algorithm would be language dependent.  The problem you are
trying to solve is one of those very hard problems in computers and math.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Micro Python -- a lean and efficient implementation of Python 3

2014-06-11 Thread Michael Torrie
On 06/10/2014 01:43 PM, alister wrote:
> On Tue, 10 Jun 2014 12:27:26 -0700, wxjmfauth wrote:
>> BTW, very easy to explain.

Yeah he keeps saying that, but he never does explain--just flails around
and mumbles "unicode.org."  Guess everyone has to have his or her
windmill to tilt at.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 基于cython的即时编译器cyjit,欢迎大家提建议

2014-06-11 Thread mm0fmf

On 11/06/2014 10:37, 1989lzhh wrote:

我正在写一个使用cython code作为后端的即时编译器名为cyjit,将python code
转换为cython code再编译为c extension导入.设计上主要参考numba.jit的思路,
使用decorate来指定要编译的function,例如:
from cyjit import jit
@jit('int(int,int)')
def add(a,b):
 return a+b
add(1,2)#compiled

@jit('int(int,int)',
 locals='''
 int c
 ''')
def add1(a,b):
 c=add(a,b)# fast invoked
 return c
add1(1,2)

目前还不支持类型推导,需要手动使用c的语法对局部变量进行定义。
编译过程是在jit函数中完成的,后续计划将编译过程移到函数运行时完成,实现
重载。
目前支持编译cache,第一次运行需要编译,时间稍慢,再次运行直接导入编译好
的extension,速度就很快了。

欢迎大家fork,pull,提建议。

https://github.com/liuzhenhai/cyjit



You might say that but I couldn't possibly comment.



--
https://mail.python.org/mailman/listinfo/python-list


Re: Python's re module and genealogy problem

2014-06-11 Thread Nick Cash

On 06/11/2014 10:35 AM, Michael Torrie wrote:
> On 06/11/2014 06:23 AM, BrJohan wrote:
>> For some genealogical purposes I consider using Python's re module.
>>
>> Rather many names can be spelled in a number of similar ways, and in 
>> order to match names even if they are spelled differently, I will build 
>> regular expressions, each of which is supposed to match  a number of 
>> similar names.
> You might want to search for fuzzy matching algorithms. Years ago, there
> was an algorithm called soundex that would generate fuzzy fingerprints
> for words that would hide differences in spelling, etc.  Unfortunately
> such an algorithm would be language dependent.  The problem you are
> trying to solve is one of those very hard problems in computers and math.
>

Soundex is actually not horrible, but it is definitely only for English
names. Newer variants of Metaphone
(http://en.wikipedia.org/wiki/Metaphone) are significantly better, and
support quite a few other languages.  Either one would most likely be
better than the regex approach.

Side note: if your data happens to be in MySQL then it has a builtin
"sounds_like()" function that compares strings using soundex.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 基于cython的即时编译器cyjit,欢迎大家提建议

2014-06-11 Thread Skip Montanaro
> You might say that but I couldn't possibly comment.

You could run the message through Google Translate. It's not
publication quality translation, but serves the needs in this
instance. (Gmail offers to translate the OP's message for me.)

Here's what GT produced (successfully translates the Chinese, but
destroys the code structure in the process - what's wrong with those
people at Google? ):

> I'm writing a cython code using the compiler as a backend instant named 
> cyjit, the python code
> Convert cython code is then compiled c extension import. Designed primarily 
> reference numba. jit ideas,
> Use decorate to specify compile function, for example:
> from cyjit import jit
> @ Jit ('int (int, int)')
> def add (a, b):
> return a + b
> add (1,2) # compiled
>
> @ Jit ('int (int, int)',
> locals ='' '
> int c
> '' ')
> def add1 (a, b):
> c = add (a, b) # fast invoked
> return c
> add1 (1,2)
>
> Currently does not support the type of derivation, C syntax to use local 
> variables defined manually.
> Jit compilation process is done in the function of Follow-up plans to move to 
> complete the compilation process runtime functions to achieve overloading.
> Currently supports compilation cache, you need to compile the first run, 
> slower time, Run again compiled directly into the extension, the speed very 
> quickly.
>
> Welcome to fork, pull, and suggestions.
>
> https://github.com/liuzhenhai/ cyjit

The concept looks like of interesting.

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 基于cython的即时编译器cyjit,欢迎大家提建议

2014-06-11 Thread 1989lzhh
sorry,wrong version post

发自我的 iPhone

> 在 Jun 12, 2014,0:16,mm0fmf  写道:
> 
>> On 11/06/2014 10:37, 1989lzhh wrote:
>> 我正在写一个使用cython code作为后端的即时编译器名为cyjit,将python code
>> 转换为cython code再编译为c extension导入.设计上主要参考numba.jit的思路,
>> 使用decorate来指定要编译的function,例如:
>> from cyjit import jit
>> @jit('int(int,int)')
>> def add(a,b):
>> return a+b
>> add(1,2)#compiled
>> 
>> @jit('int(int,int)',
>> locals='''
>> int c
>> ''')
>> def add1(a,b):
>> c=add(a,b)# fast invoked
>> return c
>> add1(1,2)
>> 
>> 目前还不支持类型推导,需要手动使用c的语法对局部变量进行定义。
>> 编译过程是在jit函数中完成的,后续计划将编译过程移到函数运行时完成,实现
>> 重载。
>> 目前支持编译cache,第一次运行需要编译,时间稍慢,再次运行直接导入编译好
>> 的extension,速度就很快了。
>> 
>> 欢迎大家fork,pull,提建议。
>> 
>> https://github.com/liuzhenhai/cyjit
> 
> You might say that but I couldn't possibly comment.
> 
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python's re module and genealogy problem

2014-06-11 Thread Simon Ward


On 11 June 2014 13:23:14 BST, BrJohan  wrote:
>For some genealogical purposes I consider using Python's re module.
>
>Rather many names can be spelled in a number of similar ways, and in 
>order to match names even if they are spelled differently, I will build
>
>regular expressions, each of which is supposed to match  a number of 
>similar names.

As has been mentioned, you probably want to look at fuzzy matching algorithms 
rather than aiming at regular expressions, although a quick search suggests 
there has been some work on fuzzy matching with regular expressions[1].

>Now, my problem: Is there a way to decide whether any two - or more -
>of 
>those regular expressions will match the same string?

If your regexes are truly regular expressions (see [2]*) then they represent 
regular languages[3], which are really sets. The intersection of these,  is 
another regular language. If you test the string against this it will also 
match both original languages.

(*this only mentions back references, but I think the look-ahead/behind 
assertions are also non-regular)

[1]: http://laurikari.net/tre/about/
[2]: 
https://en.wikipedia.org/wiki/Regular_expression#Patterns_for_non-regular_languages
[3]: https://en.wikipedia.org/wiki/Regular_language

Simon
-- 
Sent from Kaiten Mail. Please excuse my brevity.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python's re module and genealogy problem

2014-06-11 Thread Vlastimil Brom
2014-06-11 14:23 GMT+02:00 BrJohan :
> For some genealogical purposes I consider using Python's re module.
>...
>
> Now, my problem: Is there a way to decide whether any two - or more - of
> those regular expressions will match the same string?
>
> Or, stated a little differently:
>
> Can it, for a pair of regular expressions be decided whether at least one
> string matching both of those regular expressions, can be constructed?
> --
> https://mail.python.org/mailman/listinfo/python-list

Hi,
i guess, you could reuse some available generators for strings
matching a given regular expression, see e.g.:
http://stackoverflow.com/questions/492716/reversing-a-regular-expression-in-python/
for example a pyparsing recipe:
http://stackoverflow.com/questions/492716/reversing-a-regular-expression-in-python/5006339#5006339

which might be general enough for your needs - of course, you cannot
use unbound quantifiers, backreferences, etc.

Then you can test for identical strings in the generated outputs -
e.g. using the set(...) and its intersection method.

You might also check a much more powerful regex library
https://pypi.python.org/pypi/regex

which, beyond other features, also supports the mentioned fuzzy matches, cf.

>>> regex.findall(r"\bSm(?:ith){e<3}\b", "Smith Smithe Smyth Smythe Smijth")
['Smith', 'Smithe', 'Smyth', 'Smythe', 'Smijth']
>>>
(but, of course, you will have to be careful with this feature in
order to reduce false positives)

hth,
   vbr
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Thoughts on SQL vs ORM

2014-06-11 Thread suamere

> I'm afraid I don't understand what all that means.
> 
> 
> 
> But I invariably go for SQL over any abstraction paradigm.

When presented with options, these are the possible stances:

1. (Lead) Become educated on the options and decide on one.
2. (Follow) Become educated on the options and remain impartial.
3. Remain ignorant of the similarities/differences and decide on one.
4. (Get out of the way) Remain ignorant of the similarities/differences and 
remain impartial.

Of course, deciding on one could also be a case-by-case basis.  Maybe for one 
use you decide on one for one reason, and for the other case you decide on 
another option.

Thank you for choosing number 3 and casting a vote without understanding.  Any 
other stance is understandable, but like most people, you choose to hurt the 
social group you are participating in by making uninformed decisions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Thoughts on SQL vs ORM

2014-06-11 Thread Chris Angelico
On Thu, Jun 12, 2014 at 5:39 AM,   wrote:
> When presented with options, these are the possible stances:
>
> 1. (Lead) Become educated on the options and decide on one.
> 2. (Follow) Become educated on the options and remain impartial.
> 3. Remain ignorant of the similarities/differences and decide on one.
> 4. (Get out of the way) Remain ignorant of the similarities/differences and 
> remain impartial.
>
> Of course, deciding on one could also be a case-by-case basis.  Maybe for one 
> use you decide on one for one reason, and for the other case you decide on 
> another option.
>
> Thank you for choosing number 3 and casting a vote without understanding.  
> Any other stance is understandable, but like most people, you choose to hurt 
> the social group you are participating in by making uninformed decisions.
>

That's not quite fair. Suppose I'm looking at working with a
PostgreSQL database, and I have five options:

1) Write SQL and use libpq (if C) or psycopg2 (if Python)
2) Use Fred's Fancy Feature-Rich Database Interface
3) Use Joe's Simple Database Interface
4) Use Nancy's Dict-Like Database Interface
5) Bypass all libraries and open a socket connection on port 5432

I have a fairly good understanding of what's needed for option 5, as
I've worked with Pike's PostgreSQL module. And it's a lot of work, so
I wouldn't do it. (That would be your choice 1, "Lead".) But it's not
worth my time to learn three pieces of middle-ware before making my
decision, so I'm going to remain fairly ignorant of at least two of
them - I'd look at their quick-start guides and basic feature lists,
possibly pick one of them to explore in detail, and then make a
decision between that and the first option. Ultimately, I have to make
a decision, because code can't be impartial - either I'm using some
module or I'm not - and it's usually impossible to truly become
educated on all the options.

So I'd say there's more of a spectrum between your choices 1 and 3
than you imply. Perhaps I can word it this way: Choose one of the
options you know about, and the quality of the decision scales with
the number of other options you also know. (Which is why I like to
know huge numbers of programming languages. When I choose Python for a
job, it's because it's better than possibly a hundred other languages
that I could have chosen.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is MVC Design Pattern good enough?

2014-06-11 Thread Terry Reedy

On 6/11/2014 2:27 PM, Stefan Ram wrote:

Mark Lawrence  writes:

IDLE is available on all platforms and is written in tkinter.  But
personally I'd rather use the command line :)


   In the meantime, I have learned that tkinter in fact has
   become part of a standard Python implementations, and in
   fact it looks easier to use than Swing (but I have only
   looked at seven lines of Python-tkinter code so far).

   A naked-objects framework should be easy to implement
   because AFAIK it treats all objects the same, so one does
   only have to code a single View and Controller for a
   »generic object« and some general utility operations.


I though about trying naked-objects with tkinter and I think it should 
be reasonably possible. I have too much else to do but would like to see 
what could be done.


--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: 基于cython的即时编译器cyjit,欢迎大家提建议

2014-06-11 Thread 1989lzhh


在 Jun 12, 2014,1:16,Skip Montanaro  写道:

>> You might say that but I couldn't possibly comment.
> 
> You could run the message through Google Translate. It's not
> publication quality translation, but serves the needs in this
> instance. (Gmail offers to translate the OP's message for me.)
> 
> Here's what GT produced (successfully translates the Chinese, but
> destroys the code structure in the process - what's wrong with those
> people at Google? ):
Thanks skip, I post the email into wrong mail list, I will rewrite it into 
English. :)
> 
>> I'm writing a cython code using the compiler as a backend instant named 
>> cyjit, the python code
>> Convert cython code is then compiled c extension import. Designed primarily 
>> reference numba. jit ideas,
>> Use decorate to specify compile function, for example:
>> from cyjit import jit
>> @ Jit ('int (int, int)')
>> def add (a, b):
>> return a + b
>> add (1,2) # compiled
>> 
>> @ Jit ('int (int, int)',
>> locals ='' '
>> int c
>> '' ')
>> def add1 (a, b):
>> c = add (a, b) # fast invoked
>> return c
>> add1 (1,2)
>> 
>> Currently does not support the type of derivation, C syntax to use local 
>> variables defined manually.
>> Jit compilation process is done in the function of Follow-up plans to move 
>> to complete the compilation process runtime functions to achieve overloading.
>> Currently supports compilation cache, you need to compile the first run, 
>> slower time, Run again compiled directly into the extension, the speed very 
>> quickly.
>> 
>> Welcome to fork, pull, and suggestions.
>> 
>> https://github.com/liuzhenhai/ cyjit

The translation's quality is quite good, I will edit it and post here again. 
Thanks
> 
> The concept looks like of interesting.
> 
> Skip
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


A JIT compiler 'cyjit' using cython code as a backend

2014-06-11 Thread 1989lzhh
> I'm writing a JIT compiler named cyjit using cython code as a backend. It 
> designed primarily reference numba.jit. the jitted python function will be 
> converted to cython code then compiled to c extension.
> Use decorate to specify compiled function.

> for example:
> from cyjit import jit
> @ jit ('int (int, int)')
> def add (a, b):
> return a + b
> add (1,2) # compiled
> 
> @ jit ('int (int, int)',
> locals ='' '
> int c
> '' ')
> def add1 (a, b):
> c = add (a, b) # fast invoked
> return c
> add1 (1,2)
> 
> Currently cyjit does not support type defer, the local variables can be 
> defined manually using C syntax.
> Jit compilation process is done inside jit decorate. I am planing to
> move compilation process into function's runtime to achieve overload like 
> numba.jit.

> Currently cyjit supports compilation cache, the compilation will happen at 
> the first run, it will take longer time. When you run it again, it will load 
> the compiled extension directly. 
> 
> Welcome to fork, pull, and suggestions.
> 
> https://github.com/liuzhenhai/cyjit
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-11 Thread Steven D'Aprano
On Wed, 11 Jun 2014 08:48:36 -0400, Roy Smith wrote:

> In article <[email protected]>,
>  Steven D'Aprano  wrote:
> 
>> Yes, technically water-cooled engines are cooled by air too. The engine
>> heats a coolant (despite the name, usually not water these days) which
>> then heats the air.
> 
> Not water???  I'm not aware of any water-cooled engines which use
> anything other than water.  Well, OK, it's really a solution of ethylene
> or propylene glycol in water, but the water is what does most of the
> heat transfer.  The glycol is just there to provide freezing point
> depression and boiling point elevation.

Would you consider it fair to say that, say, vinegar is "not water"? 
Depending on the type of vinegar, it is typically around 5-10% acetic 
acid, and the rest water. Spirit vinegar can be as much as 20% acetic 
acid, which still leaves 80% water.

How about brandy, which is typically 35%-60% alcohol, with most of the 
rest being water? Or household bleach, which is typically a 3-6% solution 
of sodium hypochlorite? Or milk (85-90% water)? I think it is fair to 
describe those as "not water". You shouldn't try to put out a fire by 
pouring a bottle of brandy on it.

Automotive cooling fluid in modern sealed radiators is typically a 
mixture of 50% anti-freeze and 50% water.

Back in the day, car radiators were *literally* water-cooled in the sense 
that the radiator was filled with 100% water. You filled it from the tap 
with drinking water. In an emergency, say broken down in the desert, you 
could drink the stuff from the radiator to survive. If you tried that 
with many modern cars, you would die a horrible death.



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-11 Thread Steven D'Aprano
On Wed, 11 Jun 2014 08:28:43 -0700, Rustom Mody wrote:

> Steven D'Aprano wrote:
>
>> Not the point. There's a minimum amount of energy required to flip a
>> bit. Everything beyond that is, in a sense, just wasted. You mentioned
>> this yourself in your previous post. It's a *really* tiny amount of
>> energy: about 17 meV at room temperature. That's 17 milli
>> electron-volt, or 2.7×10^-21 joules. In comparison, Intel CMOS
>> transistors have a gate charging energy of about 62500 eV (1×10^-14 J),
>> around 3.7 million times greater.
>>  
>> Broadly speaking, if the fundamental thermodynamic minimum amount of
>> energy needed to flip a bit takes the equivalent of a single grain of
>> white rice, then our current computing technology uses the equivalent
>> of 175 Big Macs.
> 
> Well thats in the same realm as saying that by E=mc² a one gram stone
> can yield 21 billion calories energy.
[...]
> ie. from a a pragmatic/engineering pov we know as much how to use
> Einstein's energy-mass-equivalence to generate energy as we know how to
> use Landauer's principle to optimally flip bits.

You know, I think that the people of Hiroshima and Nagasaki and Chernobyl 
and Fukushima (to mention only a few places) might disagree.

We know *much more* about generating energy from E = mc^2 than we know 
about optimally flipping bits: our nuclear reactions convert something of 
the order of 0.1% of their fuel to energy, that is, to get a certain 
yield, we "merely" have to supply about a thousand times more fuel than 
we theoretically needed. That's about a thousand times better than the 
efficiency of current bit-flipping technology.

We build great big clanking mechanical devices out of lumps of steel that 
reach 25% - 50% of the theoretical maximum efficiency:

https://en.wikipedia.org/wiki/Thermal_efficiency

while our computational technology is something of the order of 0.1% 
efficient. I'm just pointing out that our computational technology uses 
over a million times more energy than the theoretical minimum, and 
therefore there is a lot of room for efficiency gains without sacrificing 
computer power. I never imagined that such viewpoint would turn out to be 
so controversial.




-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-11 Thread Gregory Ewing

Steven D'Aprano wrote:
Automotive cooling fluid in modern sealed radiators is typically a 
mixture of 50% anti-freeze and 50% water.


Sometimes it's even more than 50%, at which point
you really have an antifreeze-cooled engine. :-)

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


About python while statement and pop()

2014-06-11 Thread hito koto
Hello,all
I'm first time,

I want to make a while statement which can function the same x.pop () and 
without the use of pop、how can i to do?

i want to change this is code:

def foo(x):
y = []
while x !=[]:
y.append(x.pop())
return y
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:About python while statement and pop()

2014-06-11 Thread Dave Angel
hito koto  Wrote in message:
> Hello,all
> I'm first time,
> 
> I want to make a while statement which can function the same x.pop () and 
> without the use of pop、how can i to do?

No idea what the question means. Are you just trying to rewrite
 the loop in a python implementation where pop is broken?
 


> 
> i want to change this is code:
> 
> def foo(x):
> y = []
> while x !=[]:
> y.append(x.pop())
> return y

Perhaps you're looking for the extend method. 

-- 
DaveA

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: About python while statement and pop()

2014-06-11 Thread Vincent Vande Vyvre

Le 12/06/2014 05:12, hito koto a écrit :

Hello,all
I'm first time,

I want to make a while statement which can function the same x.pop () and 
without the use of pop、how can i to do?

i want to change this is code:

def foo(x):
 y = []
 while x !=[]:
 y.append(x.pop())
 return y

Something like that :

def foo(x):
return reversed(x)

--
Vincent V.V.
Oqapy  . Qarte 
 . PaQager 

--
https://mail.python.org/mailman/listinfo/python-list


Re: About python while statement and pop()

2014-06-11 Thread Chris Angelico
On Thu, Jun 12, 2014 at 1:40 PM, Vincent Vande Vyvre
 wrote:
> Le 12/06/2014 05:12, hito koto a écrit :
>
>> Hello,all
>> I'm first time,
>>
>> I want to make a while statement which can function the same x.pop () and
>> without the use of pop、how can i to do?
>>
>> i want to change this is code:
>>
>> def foo(x):
>>  y = []
>>  while x !=[]:
>>  y.append(x.pop())
>>  return y
>
> Something like that :
>
> def foo(x):
> return reversed(x)

That doesn't do the same thing, though. Given a list x, the original
function will empty that list and return a new list in reverse order,
but yours will return a reversed iterator over the original list
without changing it. This is more accurate, but still not identical,
and probably not what the OP's teacher is looking for:

def foo(x):
y = x[::-1]
x[:] = []
return y

If the mutation of x is unimportant, it can simply be:

def foo(x):
return x[::-1]

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Lines on a tkinter.Canvas

2014-06-11 Thread Pedro Izecksohn
  The code available from:
http://izecksohn.com/pedro/python/canvas/testing.py
  draws 2 horizontal lines on a Canvas. Why the 2 lines differ on thickness and 
length?

  The Canvas' method create_line turns on at least 2 pixels. But I want to turn 
on many single pixels on a Canvas. How should I do this? Canvas has no method 
create_pixel or create_point.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-11 Thread Chris Angelico
On Thu, Jun 12, 2014 at 12:08 PM, Steven D'Aprano
 wrote:
> I'm just pointing out that our computational technology uses
> over a million times more energy than the theoretical minimum, and
> therefore there is a lot of room for efficiency gains without sacrificing
> computer power. I never imagined that such viewpoint would turn out to be
> so controversial.

The way I understand it, you're citing an extremely theoretical
minimum, in the same way that one can point out that we're a long way
from maximum entropy in a flash memory chip, so it ought to be
possible to pack a lot more data onto a USB stick. The laws of physics
tend to put boundaries that are ridiculously far from where we
actually work - I think most roads have speed limits that run a fairly
long way short of c.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: This Swift thing

2014-06-11 Thread Gene Heskett
On Wednesday 11 June 2014 22:11:53 Gregory Ewing did opine
And Gene did reply:
> Steven D'Aprano wrote:
> > Automotive cooling fluid in modern sealed radiators is typically a
> > mixture of 50% anti-freeze and 50% water.
> 
> Sometimes it's even more than 50%, at which point
> you really have an antifreeze-cooled engine. :-)

There have been cases where that 50% may have been exceeded actually 
driving on the streets.

At least 3 decades back, not too long before caddy came out with the 
northstar engine, which was rigged to get you home at a reasonable speed 
even if the radiator had been holed & the coolant lost.  They used a wee 
bit of the knowledge gained from keeping Smokey Yunick is experimenting 
cash.  He had an old VW Rabbit that was both a parts car, and the test 
bed. Two cylinder motor, I suspect built on a Harley 78cid crankcase, no 
radiator, no air cooling.  Ceramic cylinders and pistons, it ran at a 
quite high internal temperature because the cylinders were insulated from 
losing heat by fiberglass blankets.  It displaced 78 cid, made about 150 
HP, and got well over 120 mpg running around in Daytona Beach.  The one 
magazine article said it hadn't lost a stoplight grand prix ever but 
Smokey stopped that by making whoever was driving it, 100% responsible for 
any tickets it collected.

It would have been gawdawful expensive to put it into production since 
those 2 cylinders & pistons cost more than the complete V8 Northstar 
engine.

I thought it was one radically cool idea at the time.  And I am amazed 
that something like it has not invaded the automotive world what with all 
the emphasis on both high mileage & decent horsepower caused by the high 
petro prices.  Today I'd imagine a new cat converter might need to be 
built because at those temps and compression ratio's, I can see a hugely 
illegal amount of the various nitrogen oxides the EPA wouldn't tolerate. 

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: About python while statement and pop()

2014-06-11 Thread hito koto
2014年6月12日木曜日 12時58分27秒 UTC+9 Chris Angelico:
> On Thu, Jun 12, 2014 at 1:40 PM, Vincent Vande Vyvre
> 
>  wrote:
> 
> > Le 12/06/2014 05:12, hito koto a écrit :
> 
> >
> 
> >> Hello,all
> 
> >> I'm first time,
> 
> >>
> 
> >> I want to make a while statement which can function the same x.pop () and
> 
> >> without the use of pop、how can i to do?
> 
> >>
> 
> >> i want to change this is code:
> 
> >>
> 
> >> def foo(x):
> 
> >>  y = []
> 
> >>  while x !=[]:
> 
> >>  y.append(x.pop())
> 
> >>  return y
> 
> >
> 
> > Something like that :
> 
> >
> 
> > def foo(x):
> 
> > return reversed(x)
> 
> 
> 
> That doesn't do the same thing, though. Given a list x, the original
> 
> function will empty that list and return a new list in reverse order,
> 
> but yours will return a reversed iterator over the original list
> 
> without changing it. This is more accurate, but still not identical,
> 
> and probably not what the OP's teacher is looking for:
> 
> 
> 
> def foo(x):
> 
> y = x[::-1]
> 
> x[:] = []
> 
> return y
> 
> 
> 
> If the mutation of x is unimportant, it can simply be:
> 
> 
> 
> def foo(x):
> 
> return x[::-1]
> 
> 
> 
> ChrisA


I want to use while statement,

for example:
>>> def foo(x):
... y = []
... while x !=[]:
... y.append(x.pop())
... return y
...
>>> print foo(a)
[[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
>>> a
[]   but this is empty 
>>> so,I want to leave a number of previous (a = [[1, 2, 3, 4],[5, 6, 7, 8, 
>>> 9],[10]])

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: About python while statement and pop()

2014-06-11 Thread Chris Angelico
On Thu, Jun 12, 2014 at 2:56 PM, hito koto  wrote:
> I want to use while statement,

This sounds like homework. Go back to your teacher/tutor for
assistance, rather than asking us to do the work for you; or at very
least, word your question in such a way that we can help you to learn,
rather than just give you the answer.

Second problem: You're using Google Groups. This makes your posts
messy, especially when you quote someone else's text. Please either
fix your posts before sending them, or read and post by some other
means, such as the mailing list:

https://mail.python.org/mailman/listinfo/python-list

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: About python while statement and pop()

2014-06-11 Thread Steven D'Aprano
On Wed, 11 Jun 2014 21:56:06 -0700, hito koto wrote:

> I want to use while statement,
> 
> for example:
 def foo(x):
> ... y = []
> ... while x !=[]:
> ... y.append(x.pop())
> ... return y
> ...
 print foo(a)
> [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
 a
> []   but this is empty
 so,I want to leave a number of previous (a = [[1, 2, 3, 4],[5, 6, 7,
 8, 9],[10]])


I wouldn't use a while statement. The easy way is:

py> a = [[1, 2, 3, 4],[5, 6, 7, 8, 9],[10]]
py> y = a[::-1]
py> print y
[[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
py> print a
[[1, 2, 3, 4], [5, 6, 7, 8, 9], [10]]

If you MUST use a while loop, then you need something like this:


def foo(x):
y = []
index = 0
while index < len(x):
y.append(x[i])
i += 1
return y


This does not copy in reverse order. To make it copy in reverse order, 
index should start at len(x) - 1 and end at 0.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: About python while statement and pop()

2014-06-11 Thread hito koto
2014年6月12日木曜日 14時43分42秒 UTC+9 Steven D'Aprano:
> On Wed, 11 Jun 2014 21:56:06 -0700, hito koto wrote:
> 
> 
> 
> > I want to use while statement,
> 
> > 
> 
> > for example:
> 
>  def foo(x):
> 
> > ... y = []
> 
> > ... while x !=[]:
> 
> > ... y.append(x.pop())
> 
> > ... return y
> 
> > ...
> 
>  print foo(a)
> 
> > [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
> 
>  a
> 
> > []   but this is empty
> 
>  so,I want to leave a number of previous (a = [[1, 2, 3, 4],[5, 6, 7,
> 
>  8, 9],[10]])
> 
> 
> 
> 
> 
> I wouldn't use a while statement. The easy way is:
> 
> 
> 
> py> a = [[1, 2, 3, 4],[5, 6, 7, 8, 9],[10]]
> 
> py> y = a[::-1]
> 
> py> print y
> 
> [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
> 
> py> print a
> 
> [[1, 2, 3, 4], [5, 6, 7, 8, 9], [10]]
> 
> 
> 
> If you MUST use a while loop, then you need something like this:
> 
> 
> 
> 
> 
> def foo(x):
> 
> y = []
> 
> index = 0
> 
> while index < len(x):
> 
> y.append(x[i])
> 
> i += 1
> 
> return y
> 
> 
> 
> 
> 
> This does not copy in reverse order. To make it copy in reverse order, 
> 
> index should start at len(x) - 1 and end at 0.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Hi, Steven:
Thanks,

My goal is to be able to in many ways python

Sorry, I was mistake,
I want to leave a number of previous (a = [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]] 
)
-- 
https://mail.python.org/mailman/listinfo/python-list