asyncio awaitable object

2017-12-08 Thread ast

Hello,

According to: 
https://www.python.org/dev/peps/pep-0492/#await-expression

an awaitable object is:

- A native coroutine object returned from a native coroutine function
- A generator-based coroutine object returned from a function decorated 
with types.coroutine()

- An object with an __await__ method returning an iterator

I dont understand the last one.

For example in instruction "res = await obj"

where obj has a __await__ method returning an iterator

What kind of data this generator is supposed to provide when next() 
is applied to it and what are these data becoming ?


what res contains when the iterator has finished to iterate ?

It seems that PEP492 documentation says nothing about it (or I dont 
understand, english is not my native language)










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


Re: Anything similar to __END__ in perl

2017-12-08 Thread Karsten Hilbert
On Thu, Dec 07, 2017 at 11:55:48PM -0600, Peng Yu wrote:

> Hi, perl has __END__ which ignore all the lines below it.
> 
> Is there anything similar to __END__ in python? Thanks.

Something similar is:

import sys
sys.exit()

Karsten
-- 
GPG key ID E4071346 @ eu.pool.sks-keyservers.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: asyncio awaitable object

2017-12-08 Thread ast


"ast"  a écrit dans le message de 
news:[email protected]...

I made some experiment.

It seems that the iterator shall provide None values, an other value
raises an exception: "RuntimeError: Task got bad yield: 1"

and in instruction "res = await obj", res got the StopIteration exception
value

See my test program and output.

import asyncio

class Test:

   def __init__(self):
   self.i = 0
   def __await__(self):
   return self
   def __iter__(self):
   return self
   def __next__(self):
   if self.i < 5:
   self.i += 1
   return None
   else:
   raise StopIteration(11)

test = Test()

async def coro1():
   print("Enter coro1")
   res = await test
   print("end of coro1, res= ", res)

async def coro2():
   print("Enter coro2")
   for i in range(8):
   print("in coro2")
   await asyncio.sleep(0)

loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait([coro1(), coro2()]))

== RESTART ==
Enter coro1
Enter coro2
in coro2
in coro2
in coro2
in coro2
in coro2
end of coro1, res=  11
in coro2
in coro2
in coro2 


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


Re: Anything similar to __END__ in perl

2017-12-08 Thread Rustom Mody
On Friday, December 8, 2017 at 3:13:56 PM UTC+5:30, Karsten Hilbert wrote:
> On Thu, Dec 07, 2017 at 11:55:48PM -0600, Peng Yu wrote:
> 
> > Hi, perl has __END__ which ignore all the lines below it.
> > 
> > Is there anything similar to __END__ in python? Thanks.
> 
> Something similar is:
> 
>   import sys
>   sys.exit()

That will give syntax (or something) errors for what follows

I'd say something similar is """

eg

$ cat xyz.py
def f():
print("hello world")

f()

"""
Tyger Tyger burning bright
In the forests of the night
What immortal hand or eye
Dare frame thy fearful symmetry
"""
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anything similar to __END__ in perl

2017-12-08 Thread Karsten Hilbert
On Fri, Dec 08, 2017 at 02:19:13AM -0800, Rustom Mody wrote:

> > > Hi, perl has __END__ which ignore all the lines below it.
> > > 
> > > Is there anything similar to __END__ in python? Thanks.
> > 
> > Something similar is:
> > 
> > import sys
> > sys.exit()
> 
> That will give syntax (or something) errors for what follows

True enough, didn't think of that. However, OP asked for
something _similar_ :-)

Which proves that any answer needs a definition of "similar" by OP.

Or at least: how similar is similar _enough_ to __END__ in Perl.

Karsten
-- 
GPG key ID E4071346 @ eu.pool.sks-keyservers.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why won't slicing lists raise IndexError?

2017-12-08 Thread Ned Batchelder

On 12/7/17 9:02 PM, Python wrote:

Can you please explain to me 


Really, you just have to ignore him.

--Ned.

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


Re: why won't slicing lists raise IndexError?

2017-12-08 Thread Rick Johnson
Python wrote:

[...]
>
> In this snippet (which again, we agreed was an incomplete
> academic example):
>
> if item:
> process(item)
> else:
> do_without_item()
>
> Can you please explain to me what sort of Python
> syntactical construct do_without_item() could be, other
> than a call to a Python callable object (i.e. a function)?
> Then, could you explain to me how that particular
> syntactical construct is in any way equivalent to the pass
> statement?  Could you then explain to me how using that in
> the simple example given makes any sense whatsoever?

I have already backed my argument with multiple code
examples, exhaustive explanations, and even constructed a
metaphor that was slightly entertaining. Yet, none of those
are good enough? Alas, allow me to try once more.

Consider:

> if item:
> process(item)
> else:
> do_without_item()

The above code sample is semantically equivalent to the
following real-life "situational logic":

[man sits on couch and enjoys sports programming]

if thirsty:
grab_beer_from_fridge()
else:
stay_on_couch()

Above, just as with Terry's code, the else-clause cannot
justify itself. And why you ask? Because, we were _already_
on the damned couch! The else-clause is a "do nothing"
condition, hence, it is functionally equivalent to:

else:
pass

*HENCE*, it is super-freaking-fluous! Get it?

However. Here is an example which _can_ justify the else-
clause

if thirsty and (not tooLazyToMove):
grab_beer_from_fridge()
else:
tell_wife_to_grab_beer()

Heck, even tangential actions can be justified. Observe:

import random

if thirsty and (not tooLazyToMove):
grab_beer_from_fridge()
else:
random.choice([
scratch_self,
eat_tater_chip,
change_channel,
relieve_abdominal_pressure,
])()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: asyncio awaitable object

2017-12-08 Thread Ian Kelly
On Fri, Dec 8, 2017 at 2:08 AM, ast  wrote:
> Hello,
>
> According to: https://www.python.org/dev/peps/pep-0492/#await-expression
> an awaitable object is:
>
> - A native coroutine object returned from a native coroutine function
> - A generator-based coroutine object returned from a function decorated with
> types.coroutine()
> - An object with an __await__ method returning an iterator
>
> I dont understand the last one.
>
> For example in instruction "res = await obj"
>
> where obj has a __await__ method returning an iterator
>
> What kind of data this generator is supposed to provide when next() is
> applied to it and what are these data becoming ?
>
> what res contains when the iterator has finished to iterate ?
>
> It seems that PEP492 documentation says nothing about it (or I dont
> understand, english is not my native language)

I believe the reason that PEP492 doesn't specify that is because it
only creates the keywords and specifies where they can be used. What
values are passed by the iterator is an implementation detail of the
asyncio framework, and the intention is that async/await should be
usable by other async frameworks, not just asyncio. So the proper
answer to the question "what kind of data should the iterator provide"
is "it depends on framework".

An example implementation of an object with an __await__ method is an
asyncio.Future object. If you look at the definition of
asyncio.Future, you can find its __await__ method. Here it is:

__await__ = __iter__

Huh? To understand this, bear in mind that anywhere you can use
"await", you would previously have used "yield from". To "yield from"
something, that something must be iterable. So to "yield from" asyncio
Futures, they must be iterable, which means they must have an __iter__
method. The protocol that asyncio uses for __await__ is the same that
it uses __iter__, so when __await__ was added it returns an iterator
which made __await__ literally a drop-in replacement of __iter__. So
what does Future.__iter__ do?

def __iter__(self):
if not self.done():
self._asyncio_future_blocking = True
yield self  # This tells Task to wait for completion.
assert self.done(), "yield from wasn't used with future"
return self.result()  # May raise too.

It returns a generator that first checks if the future is already
done. If it is, it just returns its result (which raises a
StopIteration) without ever sleeping. Otherwise, it yields itself,
exactly once. The chain of "yield from" / "await"s ultimately pass
this future all the way down to the asyncio event loop, which adds it
to the scheduler. When the future is done, the task is resumed and the
flow of control goes back up the chain all the way to the futures,
which asserts for sanity that it is now done and returns its result.

So the answer to "what should the iterator yield for asyncio" is that
it should yield unfinished asyncio Futures one at a time, with the
expectation that they will be done when the iterator resumes.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why won't slicing lists raise IndexError?

2017-12-08 Thread Python
On Fri, Dec 08, 2017 at 05:12:35AM -0800, Rick Johnson wrote:
> I have already backed my argument with multiple code
> examples, exhaustive explanations

Which were all false and/or nonsensical.

> > if item:
> > process(item)
> > else:
> > do_without_item()
> 
> The above code sample is semantically equivalent to the
> following real-life "situational logic":
> 
> [man sits on couch and enjoys sports programming]
> 
> if thirsty:
> grab_beer_from_fridge()
> else:
> stay_on_couch()

So what you're ultimately saying is you're making an *assumption* that
the English phrase "do without item" MEANS to do nothing, and
therefore do_without_item() MUST be defined as pass.  However both of
those things are FALSE, and once again your entire argument is
completely invalid.  It's also true that such an assumption is
antithetical to the example.  So, your assumption is both logically
and contextually nonsensical.

If you're on a sinking boat, and you could stop the boat from sinking
if you had a rubber seal, but you don't have one, you're forced to
do_without_item().  Does that mean you're going to sit in the boat and
let it sink with you in it?  By your arguments, apparently YOU must...
But the rest of us would try to fix the leak another way, or failing
that, get the hell out of the boat.  I like our definition of
do_without_item() better.

Ned is right, you just need to be ingored.

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


scipy

2017-12-08 Thread Larry Martell
Trying to install scipy on ubuntu-trusty-64 running Python 2.7.6. It's
failing with:

$ sudo pip install scipy
Downloading/unpacking scipy
  Downloading scipy-1.0.0.tar.gz (15.2MB): 15.2MB downloaded
  Running setup.py (path:/tmp/pip_build_root/scipy/setup.py) egg_info
for package scipy
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown
distribution option: 'python_requires'

Followed by many screens full of errors. Is that just a warning or is
that the issue? I've installed many other packages without a problem
on this same system. What is the issue here?
-- 
https://mail.python.org/mailman/listinfo/python-list


Please tell me how to execute python file in Ubuntu by double

2017-12-08 Thread dhananjaysingh091298
Respected Sir/Mam,
I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am double
click in python program (Dhananjay.py),it is opening in Text Editor by Default
in Ubuntu.I want to run this program when i double click on it as any *.Exe
file executes as in Window.
Sir please help me.

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


pip3 file in Scripts folder is missing - Python installation - Tensor

2017-12-08 Thread pavan kopparthi
Hi,

Installed Python 3.6.3 Amd64 in Windows 10 OS.

Want to install Tensor flow using native pip as suggested...

C:\> *pip3 install --upgrade tensorflow*

But, observed that pip3 file in Scripts folder is missing. Also, Scripts folder
 is empty.

Reg,
Pavan Kumar K.



<#m_1095693827828497751_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

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


Re: Meaning of "Add Python to environment variables"

2017-12-08 Thread Thomas Jollans
On 03/12/17 18:32, John Yeung wrote:
> In the custom installation options for Python 3.6, what *exactly* does "Add
Python to environment variables" mean?
>
> Which environment variables are we talking about? I imagine one of them would
have to be PATH. Are there any others?


If the note on the "PrependPath" option in
https://docs.python.org/3/using/windows.html#installing-without-ui is complete
(which I believe it is, but I couldn't swear to it), it's PATH and PATHEXT.

-- Thomas

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


Re: Please tell me how to execute python file in Ubuntu by double

2017-12-08 Thread Thomas Jollans
On 2017-12-04 10:48, [email protected] wrote:
> Respected Sir/Mam,
> I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when i am
double click in python program (Dhananjay.py),it is opening in Text Editor by
Default in Ubuntu.I want to run this program when i double click on it as any
*.Exe file executes as in Window.
> Sir please help me.
>

https://askubuntu.com/a/544544


--
Thomas Jollans

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


Re: How to use a regexp here

2017-12-08 Thread Cecil Westerhof
Ned Batchelder  writes:

> On 12/4/17 4:36 AM, Cecil Westerhof wrote:
>> I have a script that was running perfectly for some time. It uses:
>>  array = [elem for elem in output if 'CPU_TEMP' in elem]
>>
>> But because output has changed, I have to check for CPU_TEMP at the
>> beginning of the line. What would be the best way to implement this?
>>
>
> No need for a regex just yet:
>
> â â â  array = [elem for elem in output if elem.startswith('CPU_TEMP')]

Yes, that is it. I should have known that. :'-(

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


Re: urllib2 urlopen takes too much time

2017-12-08 Thread Python
On Sun, Dec 03, 2017 at 09:49:45AM -0800, [email protected] wrote:
> On Tuesday, June 23, 2009 at 11:09:30 PM UTC-4, Aahz wrote:
> > In article ,
> > =?UTF-8?Q?Filip_Gruszczy=C5=84ski?=   wrote:
> > >
> > >I have encountered a performance problem using suds, which was traced
> > >down to _socket.recv. I am calling some web services and each of them
> > >uses about 0.2 sec and 99% of this time is spent on urllib2.urlopen,
> > >while the rest of the call is finished in milliseconds.
> >
> > What happens if you use urlopen() by itself?
>
> I am having the same issue.  Did you ever figure out a solution?
> The time delay is also the same, from .2 to .25 sec.  I need to stay
> with urlopen though so I can do a custom request header

Depending on your network conditions, this doesn't seem all that outrageous. 
Using tcpdump or some other packet sniffer should reveal what is going on, but
most likely urlopen() needs to do all of the following, every time it is
called:

  - resolve the address via DNS
 + 1 round trip: DNS request + response; possibly more if DNS
   doesn't have host entry and forwards...
  - initiate a TCP connection
 + three way handshake = 1.5 round trip times
  - send the request (.5 round trip)
  - wait for server processing (unknown time)
  - receive the response (.5 round trip time)

If the DNS server is busy, or the SOAP server is busy, add that latency to the
mix.  Assuming NO latency due to server load, you're still looking at 3.5 round
 trips to service the request, or 7 one-way (possibly 6, if the ACK contains
the request, which IIRC is allowed). .2s / 7 = ~29ms, so if the latency between
 server and client is 29ms or higher, that explains everything.  On a LAN I'd
hope for much better than 29ms latency (1ms is more typical), but it's not
outside the realm of possibility depending on network architecture and load.
Ping to the server will tell you that... if your network isn't blocking ICMP.

If the C# app is faster, my guess would be it is caching the DNS response
and/or maintaining persistent connections to the server, whereas urllib isn't,
though that's just a guess... I'm not familiar with the implementations of
either.  But again, a packet sniffer should show you exactly what's happening
and who is being slow.

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


Re: How to use a regexp here

2017-12-08 Thread Cecil Westerhof
Joel Goldstick  writes:

> On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder 
> wrote:
>
>> On 12/4/17 4:36 AM, Cecil Westerhof wrote:
>>
>>> I have a script that was running perfectly for some time. It uses:
>>>  array = [elem for elem in output if 'CPU_TEMP' in elem]
>>>
>>> But because output has changed, I have to check for CPU_TEMP at the
>>> beginning of the line. What would be the best way to implement this?
>>>
>>>
>> No need for a regex just yet:
>>
>> array = [elem for elem in output if elem.startswith('CPU_TEMP')]
>>
>> (btw, note that the result of this expression is a list, not an array, for
>> future Googling.)
>>
>> --Ned.
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
> I like Ned's clear answer, but I'm wondering why the original code would
> fail because the substring is at the start of the line, since 'in' would
> still be true no matter where the desired string is placed.  It would be
> useful to see some sample data of the old data, and the new data

There is now also a line that starts with:
PCH_CPU_TEMP:

And I do not want that one.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


Re: How to use a regexp here

2017-12-08 Thread Ned Batchelder
On 12/4/17 4:36 AM, Cecil Westerhof wrote:
> I have a script that was running perfectly for some time. It uses:
>  array = [elem for elem in output if 'CPU_TEMP' in elem]
>
> But because output has changed, I have to check for CPU_TEMP at the
> beginning of the line. What would be the best way to implement this?
>

No need for a regex just yet:

 â â â  array = [elem for elem in output if elem.startswith('CPU_TEMP')]

(btw, note that the result of this expression is a list, not an array, for
future Googling.)

--Ned.

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


Re: How to use a regexp here

2017-12-08 Thread Rick Johnson
Cecil Westerhof wrote:
> Joel Goldstick writes:

[...]

> > I like Ned's clear answer, but I'm wondering why the
> > original code would fail because the substring is at the
> > start of the line, since 'in' would still be true no
> > matter where the desired string is placed.  It would be
> > useful to see some sample data of the old data, and the
> > new data

@Goldstick

"Inclusion testing" will return false positives when the target is part of a
larger structure (aka: word). Observe:

>>> s = "Complex is better than complicated."
>>> "plex" in s
True
>>> "om" in s
True
>>> s.count("om")
2

I'm sure you already know this, and only made the comment because you did not
have all the data, but i thought it would be good to mention for any lurkers
who may be watching.

> There is now also a line that starts with: PCH_CPU_TEMP:
> And I do not want that one.

Yes. But be aware, that while the `str.startswith(target)` method is indeed
more efficient than a more generalized "inclusion test", if the target is not
_always_ at the beginning of the string, then your code is going to skip right
over valid match like a round stone skipping across the surface of a
glass-smooth lake. But if you are sure the target will always be at the
beginning of the string, then it is the best choice.

> --
> Cecil Westerhof
> Senior Software Engineer

Perhaps it's not politically correct for me to say this, but i've never been
one who cared much about political correctness, so i'm just going to say it...

If you really are a "_Senior_ software engineer", and that title is not simply
an ego-booster bestowed by your boss to a one-person-dev-team in order to avoid
 pay raises, then i would expect more competence from someone who holds such an
 esteemed title.

And even *IF* you are only vaguely familiar with Python, and even *IF*, you
rarely use Python in your projects, i don't think it's too much to ask of a
~~Senior~~ Software Engineer that they possess the basic skills required to
peruse the Python documentation and decide which method is most appropriate for
 the situation at hand. And if you're using Python on a regular basis, then you
 should be intimately familiar with _all_ methods of each major type.

Granted, your question did "hint" about the possibility of using a regexp
(although, based on the data you have provided so far, a string method will
suffice), but i would also expect a ~~Senior~~ Software Engineer to not only be
 knowledgeable of regexps, but also know when they are a strength and when they
 are a weakness.

Now, there are one of two ways you can take this advice:

(1) You can take it as a personal attack; get all huffy
about it; drop to the floor and flail your arms and legs
like a petulant two-year-old who didn't get the toy he
wanted; and learn nothing in the process.

or

(2) You can take it as what it is -> constructive criticism;
shower me with gratitude[1]; and become a better person and
a better programmer in the process.

The choice is yours.


[1] Well, i had to sneak something in there for myself, after all, it is the
season of giving, yes? O:-)

Here comes santa claws...
Here comes santa claws...
...

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


Re: How to use a regexp here

2017-12-08 Thread Joel Goldstick
On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder  wrote:

> On 12/4/17 4:36 AM, Cecil Westerhof wrote:
>
>> I have a script that was running perfectly for some time. It uses:
>>  array = [elem for elem in output if 'CPU_TEMP' in elem]
>>
>> But because output has changed, I have to check for CPU_TEMP at the
>> beginning of the line. What would be the best way to implement this?
>>
>>
> No need for a regex just yet:
>
> array = [elem for elem in output if elem.startswith('CPU_TEMP')]
>
> (btw, note that the result of this expression is a list, not an array, for
> future Googling.)
>
> --Ned.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

I like Ned's clear answer, but I'm wondering why the original code would fail
because the substring is at the start of the line, since 'in' would still be
true no matter where the desired string is placed.  It would be useful to see
some sample data of the old data, and the new data

--
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays

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


Re: How to use a regexp here

2017-12-08 Thread Ned Batchelder
On 12/4/17 9:13 AM, Rick Johnson wrote:
> Perhaps it's not politically correct for me to say this, but
> i've never been one who cared much about political
> correctness, so i'm just going to say it...

Cecil, feel free to ignore the rest of Rick's message.â  His messages are
famous for their outrageous and/or abrasive tone, something he seems to revel
in.â  Luckily, it's not typical of the Python community.

--Ned.

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


Re: Please tell me how to execute python file in Ubuntu by double

2017-12-08 Thread Rick Johnson
On Monday, December 4, 2017 at 3:49:11 AM UTC-6, [email protected] wrote:
> I am Dhananjay Singh,Student of IIIT Manipur. Sir/Mam when
> i am double click in python program (Dhananjay.py),it is
> opening in Text Editor by Default in Ubuntu.I want to run
> this program when i double click on it as any *.Exe file
> executes as in Window. Sir please help me.

Sounds like your OS file associations are all botched-up and the ".py"
extention has been linked (either by you purposefully, as a system default, or
as the side-effect of something else) to a texteditor program. It's easy enough
 to change this setting in the OS, and i believe there is a Python module or
two for the task -- if that's your cup-o-tea.

Granted, opening a text editor for unknown files is always a wise default
system setting as it avoids any exploits that may be initiated by a hapless
neophyte. Take, for example, the braindead Windozes default setting for
autorun, which has been the source of many nasty exploits. I suppose that Gates
 figures his user base is so dumb that they can't even find the My Computer
icon and double click it in order to access the contents of a removable drive,
CD-ROM, or whatever STD riddled device they happen to plug in. The wise windoze
 user knows that disabling autorun is paramount to ensuring a secure
experience, among other braindead defaults.

This is not really a "python" question, and is actually generally applicable to
 Operating Systems. And the solution is specific to each platform.

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


Re: How to use a regexp here

2017-12-08 Thread Terry Reedy
On 12/4/2017 11:14 AM, Ned Batchelder wrote:
> On 12/4/17 9:13 AM, Rick Johnson wrote:
>> Perhaps it's not politically correct for me to say this, but
>> i've never been one who cared much about political
>> correctness, so i'm just going to say it...
>
> Cecil, feel free to ignore the rest of Rick's message.â  His messages are
> famous for their outrageous and/or abrasive tone, something he seems to
> revel in.â  Luckily, it's not typical of the Python community.

Or take Rick's 'rest' as a suggestion to reread Library Reference chapters 2,
3, 4 and in particular 4.7.

As for your idea of an RE, '^' matches the beginning of a line, and '$' the
end, though using .startswith, and .endswith, are easier if no other RE syntax
is needed for matching.

--
Terry Jan Reedy

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


Re: why won't slicing lists raise IndexError?

2017-12-08 Thread Random832
On Mon, Dec 4, 2017, at 13:54, Jason Maldonis wrote:
> Is there any background on why that doesn't raise an IndexError? Knowing
> that might help me design my extended list class better. For my specific
> use case, it would simplify my code (and prevent `if isinstance(item,
> slice)` checks) if the slicing raised an IndexError in the example I
> gave.

Slicing (of strings, lists, tuples, anyway) never raises an IndexError. If the
start is out of range it will return an empty list. I don't know. As for "why",
 it's just how the operation was designed. Perhaps it was considered that an
exception isn't needed because there's no ambiguity (i.e. there's no other
reason a slice operation can return a list shorter than the length implied by
the slice parameters).

Why would this simplify your code? What are you doing that would benefit from
an IndexError here?

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


Re: How to use a regexp here

2017-12-08 Thread Neil Cerutti
On 2017-12-04, Cecil Westerhof  wrote:
> Joel Goldstick  writes:
>
>> On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder 
>> wrote:
>>
>>> On 12/4/17 4:36 AM, Cecil Westerhof wrote:
>>>
 I have a script that was running perfectly for some time. It uses:
  array = [elem for elem in output if 'CPU_TEMP' in elem]

 But because output has changed, I have to check for CPU_TEMP at the
 beginning of the line. What would be the best way to implement this?


>>> No need for a regex just yet:
>>>
>>> array = [elem for elem in output if elem.startswith('CPU_TEMP')]
>>>
>>> (btw, note that the result of this expression is a list, not an array, for
>>> future Googling.)
>>>
>>> --Ned.
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>>>
>>
>> I like Ned's clear answer, but I'm wondering why the original code would
>> fail because the substring is at the start of the line, since 'in' would
>> still be true no matter where the desired string is placed.  It would be
>> useful to see some sample data of the old data, and the new data
>
> There is now also a line that starts with:
> PCH_CPU_TEMP:
>
> And I do not want that one.

You'll probably want to include the ':' in the startswith check, in case
someday they also add CPU_TEMP_SOMETHING:.

--
Neil Cerutti

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


Re: csv.DictReader line skipping should be considered a bug?

2017-12-08 Thread Skip Montanaro
> And I want to argue that the difference of behavior should be considered a
bug.

Sorry, that ship has sailed. If you want different behavior, subclassing
DictReader and providing your own next() implementation should be
straightforward. All you need to do is copy the existing implementation of
next() and strip out the comment and the while loop which follows it.

Skip

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


why won't slicing lists raise IndexError?

2017-12-08 Thread Jason Maldonis
I was extending a `list` and am wondering why slicing lists will never raise an
 IndexError, even if the `slice.stop` value if greater than the list length.

Quick example:

my_list = [1, 2, 3]
my_list[:100]  # does not raise an IndexError, but instead returns the full
list

Is there any background on why that doesn't raise an IndexError? Knowing that
might help me design my extended list class better. For my specific use case,
it would simplify my code (and prevent `if isinstance(item, slice)` checks) if
the slicing raised an IndexError in the example I gave.

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


Re: How to upload to Pythonhosted.org

2017-12-08 Thread waylan
After asking here, I found a mailing list post here:
https://mail.python.org/pipermail/distutils-sig/2015-May/026381.html

That post outlines a roadmap for shutting down pythonhosted. Unfortunately, it
seems that they skipped from step 1 to step 5 without bothering with steps 2,
3, & 4.

In any event, that list discussion seems to be the official word that things
are being shut down, which was what I was looking for.  It's unfortunate that
things weren't done more smoothly.

Also it seems that if you want to avoid search results showing up for the
pythonhosted content after you find a new host, they at least provide a way to
"delete" the content from pyhtonhosted. That way, Google will stop indexing it
and stop including it in search results. Unfortunately, all the existing links
across the internet are now dead with no way to redirect people.

Waylan

On Thursday, November 30, 2017 at 1:47:32 PM UTC-5, Irmen de Jong wrote:
> On 11/30/2017 03:31 AM, Ben Finney wrote:
> > Irmen de Jong  writes:
> >
> >> On 11/30/2017 02:06 AM, waylan wrote:
> >>> So, how do I upload an update to my documentation?
> >>
> >> I ran into the same issue. From what I gathered, Pythonhosted.org is
> >> in the process of being dismantled and it hasn't allowed new doc
> >> uploads for quite some time now. I switched to using readthedocs.io
> >> instead.
> >
> > The issue that many are facing is how to update the pages *at the
> > existing URL* to tell visitors where to go next. Cool URIs don't change
> > https://www.w3.org/Provider/Style/URI.html> but, when they do, we
> > are obliged to update the existing pages to point to the new ones.
>
> Sorry, yes, that is the problem I experience as well. My library's old
version
> documentation is somehow frozen on Pythonhosted.org (and obviously still pops
up as the
> first few google hits).
>
>
> > So, if pythonhosted.org is indeed being dismantled, there should be a
> > way to update the pages there for informing visitor where they should go
> > next.
> >
> > If that's not possible and instead the service is just locked down,
> > that's IMO a mistake.
>
> I agree with that. I think it's an unsolved issue until now, that gets some
discussion
> in this github issue https://github.com/pypa/warehouse/issues/582
>
>
> Irmen

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


Re: we want python software

2017-12-08 Thread Igor Korot
Hi, Tony,

On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff 
wrote:
> On 05/12/17 16:55, Igor Korot wrote:
>> Hi,
>>
>> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy
>>  wrote:
>>> Sir,
>>> I am b.tech student I would like to learn python. So please send
the python software.
>> Sorry, we don't send anything. You will have to go get it yourself. -)
>>
> Well, at least try to be helpful:
> https://www.python.org/downloads/

This is LMGIFY.
If they say they are tech students - they should know how to work with Google.

And I even tried to be polite. I should have probably write something like:

1. Open the Web browser.
2. In the "Address Bar" type "www.pyton.org". 3. Find the link which reads
"Downloads". Click on it. 4. Carefully read what version you need to install
for your OS. 5. Apply the acquired knowledge and download the appropriate
version. 6. Click on the installer (if on Windows). 7. Follow all the prompts.
8. Enjoy.

but this is too much for the tech student.

Thank you.

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

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


Re: How to use a regexp here

2017-12-08 Thread Cecil Westerhof
Neil Cerutti  writes:

> On 2017-12-04, Cecil Westerhof  wrote:
>> Joel Goldstick  writes:
>>
>>> On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder 
>>> wrote:
>>>
 On 12/4/17 4:36 AM, Cecil Westerhof wrote:

> I have a script that was running perfectly for some time. It uses:
>  array = [elem for elem in output if 'CPU_TEMP' in elem]
>
> But because output has changed, I have to check for CPU_TEMP at the
> beginning of the line. What would be the best way to implement this?
>
>
 No need for a regex just yet:

 array = [elem for elem in output if elem.startswith('CPU_TEMP')]

 (btw, note that the result of this expression is a list, not an array, for
 future Googling.)

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

>>>
>>> I like Ned's clear answer, but I'm wondering why the original code would
>>> fail because the substring is at the start of the line, since 'in' would
>>> still be true no matter where the desired string is placed.  It would be
>>> useful to see some sample data of the old data, and the new data
>>
>> There is now also a line that starts with:
>> PCH_CPU_TEMP:
>>
>> And I do not want that one.
>
> You'll probably want to include the ':' in the startswith check,
> in case someday they also add CPU_TEMP_SOMETHING:.

I already did. And to be really sure also included a space after it.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


Re: csv.DictReader line skipping should be considered a bug?

2017-12-08 Thread MRAB
On 2017-12-06 00:06, Steve D'Aprano wrote:
> On Wed, 6 Dec 2017 04:20 am, Jason wrote:
>
>> I ran into this:
>>
> https://stackoverflow.com/questions/27707581/why-does-csv-dictreader-skip-emp
ty-lines
>>
>> # unlike the basic reader, we prefer not to return blanks,
>> # because we will typically wind up with a dict full of None
>> # values
>>
>> while iterating over two files, which are line-by-line corresponding. The
>> DictReader skipped ahead many lines breaking the line-by-line
>> correspondence.
>
> Um... this doesn't follow. If they are line-by-line corresponding, then they
> should skip the same number of blank lines and read the same number of
> non-blank lines.
>
> Even if one file has blanks and the other does not, if you iterate the over
> the records themselves, they should keep their correspondence.
>
> I'm afraid that if you want to convince me this is a buggy design, you need
to
> demonstrate a simple pair of CSV files where the non-blank lines are
> corresponding (possibly with differing numbers of blanks in between) but the
> CSV readers get out of alignment somehow.
>
>
>> And I want to argue that the difference of behavior should be considered a
>> bug. It should be considered as such because: 1. I need to know what's in
>> the file to know what class to use.
>
> Sure. But blank lines don't tell you what class to use.
>
>> The file content should not break at-least-1-record-per-line.
>
> Blank lines DO break that requirement. A blank line is not a record.
>
>
>> There may me multiple lines per record in the
>> case of embedded new lines, but it should never no record per line.
>
> I disagree. A blank line is not a record. If I have (say) five fields, then:
>
> \n
>
> is a blank record with five empty fields. \n alone is just a blank. The
> DictReader correctly returns records with blank fields.
>
A blank line could be a record if there's only one field and it's empty.

[snip]

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


f-string

2017-12-08 Thread Steve D'Aprano
Anyone got a handy copy of Python 3.6 available to test something for me?

What does compile('f"{spam} {eggs}"', '', 'single') return?

What does eval()'ing the above compiled object do? If necessary, you may have
to define spam and eggs first.


Thanks in advance.


--
Steve
â £Cheer up,â Ø they said, â £things could be worse.â Ø So I cheered up, and
sure
enough, things got worse.

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


Re: f-string

2017-12-08 Thread Chris Angelico
On Wed, Dec 6, 2017 at 11:16 AM, Steve D'Aprano
 wrote:
> Anyone got a handy copy of Python 3.6 available to test something for me?
>
> What does compile('f"{spam} {eggs}"', '', 'single') return?
>
> What does eval()'ing the above compiled object do? If necessary, you may have
> to define spam and eggs first.
>
>

In 3.6a4+, which is the only 3.6 I have handy, it returns a code object.

>>> spam = "((spam))"
>>> eggs = "!!eggs!!"
>>> compile('f"{spam} {eggs}"', '', 'single')
 at 0x7f0f82bf7db0, file "", line 1>
>>> eval(_)
'((spam)) !!eggs!!'
>>> dis.dis(compile('f"{spam} {eggs}"', '', 'single'))
  1   0 LOAD_NAME0 (spam)
  2 FORMAT_VALUE 0
  4 LOAD_CONST   0 (' ')
  6 LOAD_NAME1 (eggs)
  8 FORMAT_VALUE 0
 10 BUILD_STRING 3
 12 PRINT_EXPR
 14 LOAD_CONST   1 (None)
 16 RETURN_VALUE

Same is true in 3.7 alphas.

ChrisA

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


Re: Please tell me how to execute python file in Ubuntu by double click

2017-12-08 Thread Steve D'Aprano
On Tue, 5 Dec 2017 07:58 pm, Lawrence Dâ ÖOliveiro wrote:

> On Tuesday, December 5, 2017 at 3:39:26 AM UTC+13, Rick Johnson wrote:
>>
>> Sounds like your OS file associations are all botched-up ...
>
> Linux doesnâ Öt do â £OS file associationsâ Ø.


Then how does my Linux box know that when I double-click on a text file, it
launches kwrite rather than (say) the Gimp or LibreOffice?

When I right-click on a mp4 video, I get a menu that includes a Open With
command that shows (amount others) Kaffeine, mplayer and VLC.

If you mean the Linux *kernel* doesn't do file associations, then you should
have said so.

But why do you care about the kernel? Would you think it even the *tiniest*
useful to claim that "Linux doesn't do email" because it is sendmail or postfix
 (or similar) that sends email rather than the Linux kernel itself?



--
Steve

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


Re: f-string

2017-12-08 Thread Chris Angelico
On Wed, Dec 6, 2017 at 11:54 AM, John Pote  wrote:
>
> On 06/12/2017 00:16, Steve D'Aprano wrote:
>>
>> Anyone got a handy copy of Python 3.6 available to test something for me?
>>
>> What does compile('f"{spam} {eggs}"', '', 'single') return?
>>
>> What does eval()'ing the above compiled object do? If necessary, you may
>> have
>> to define spam and eggs first.
>
> SPAM scrambled
>
> Py version on Win 7 box
> Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit
> (AMD64)] on win32
>
> Any help?

I think Steve just wanted to see what we'd all define spam and eggs as.

ChrisA
*ducking for cover*

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


Re: we want python software

2017-12-08 Thread Tony van der Hoff
On 05/12/17 16:55, Igor Korot wrote:
> Hi,
>
> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy
>  wrote:
>> Sir,
>> I am b.tech student I would like to learn python. So please send the
python software.
> Sorry, we don't send anything. You will have to go get it yourself. -)
>
Well, at least try to be helpful:
https://www.python.org/downloads/

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


Python homework

2017-12-08 Thread nick martinez2 via Python-list
I have a question on my homework. My homework is to write a program in which
the computer simulates the rolling of a die 50 times and then prints
(i). the most frequent side of the die (ii). the average die value of all
rolls. I wrote the program so it says the most frequent number out of all the
rolls for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I
need. This is what I have so far:
import random

def rollDie(number):
rolls = [0] * 6
for i in range(0, number):
roll=int(random.randint(1,6))
rolls[roll - 1] += 1
return rolls

if __name__ == "__main__":
result = rollDie(50)
print (result)
print(max(result))

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


Re: csv.DictReader line skipping should be considered a bug?

2017-12-08 Thread Steve D'Aprano
On Wed, 6 Dec 2017 04:20 am, Jason wrote:

> I ran into this:
>
https://stackoverflow.com/questions/27707581/why-does-csv-dictreader-skip-empty
-lines
>
> # unlike the basic reader, we prefer not to return blanks,
> # because we will typically wind up with a dict full of None
> # values
>
> while iterating over two files, which are line-by-line corresponding. The
> DictReader skipped ahead many lines breaking the line-by-line
> correspondence.

Um... this doesn't follow. If they are line-by-line corresponding, then they
should skip the same number of blank lines and read the same number of
non-blank lines.

Even if one file has blanks and the other does not, if you iterate the over the
 records themselves, they should keep their correspondence.

I'm afraid that if you want to convince me this is a buggy design, you need to
demonstrate a simple pair of CSV files where the non-blank lines are
corresponding (possibly with differing numbers of blanks in between) but the
CSV readers get out of alignment somehow.


> And I want to argue that the difference of behavior should be considered a
> bug. It should be considered as such because: 1. I need to know what's in
> the file to know what class to use.

Sure. But blank lines don't tell you what class to use.

> The file content should not break at-least-1-record-per-line.

Blank lines DO break that requirement. A blank line is not a record.


> There may me multiple lines per record in the
> case of embedded new lines, but it should never no record per line.

I disagree. A blank line is not a record. If I have (say) five fields, then:

\n

is a blank record with five empty fields. \n alone is just a blank. The
DictReader correctly returns records with blank fields.


> 2.  It's a premature optimization. If skipping blank lines is desirable,
> then have another class on top of DictReader, maybe call it
> EmptyLineSkippingDictReader.

No, that's needless ravioli code. The csv module already defines a basic reader
 that doesn't skip blank lines. Having two different DictReaders, one which
doesn't work correctly because it wrongly expands blank lines to collections of
 blank fields, is not helpful.

Perhaps if they were called BrokenDictReader for the one which expands blank
lines to empty records, and DictReader for the one which correctly skips blank
lines.


> 3. The intent of DictReader is to return a
> dict, nothing more, therefore the change of behavior isn inappropriate.

No, if all you want is a dict, call dict() or use the dict display {}. The
intent of DictReader is to *read a CSV file and extract the records* as a dict.
 Since blank lines aren't records, they should be skipped.


> Does anyone agree, or am I crazy?

I wouldn't want to guess your mental health based just on this isolated
incident, but if I had to make a diagnosis, I'd say, yes, crazy as a loon.

*wink*




--
Steve

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


Re: why won't slicing lists raise IndexError?

2017-12-08 Thread Rick Johnson
Steve D'Aprano wrote:

[...]

> You've already been told that there's no indication or
> reason to believe that it is a non-action. You've already
> been given at least one possible action. It isn't a non-
> action, it is two distinct actions:
>
> - the action you take when the slice is non-empty;
>
> - the action you take when the slice is empty.

When Python follows a logic clause like a train skating along a set of railroad
 tracks, and finds itself in a *GHOST TOWN*, that's not an action -- "Steve-o"
-- it's a non-
action.

Listen, I think it might help you to understand the absurdity of this
else-clause if you ruminate about this code using a metaphor. Below, i've
defined some fictional characters and objects that will live in a little
metaphorical world, and futhermore, explained how these characters and objects
relate to our real-life code example.



TERRY("THE BUILDER"): Terry is a personable fella who builds
little shanty towns for a living.

IF_VILLE: This is the first of two towns that Terry
establish in our little metaphorical world. And although
it's not quite the shining-city-on-a-hill that he, or the
inhabitants, had envisioned, he did manage to build a proper
train platform and a small warehouse for strong
deliverables, so we shouldn't be too critical of his work
here.

ELSE_VILLE: This is the "other" town that Terry establish.
However, after slaving away in the hot desert sun building
IF_VILLE all day, Terry decided to go home and drink a case
of beer, became drunk, and then forgot all about his
responsibilities to develope ELSE_VILLE. This has happened
before. But we typically forgive Terry for his irresponsible
nature simple because he's such a personable fella. However,
if this gets any worse, we may have to give him an
intervention.

KENNY_LINTER: Kenny Linter is a faithful civil servant who's
sole job is to inspect little shanty towns. And though he's
a little short on manners, he is typically competent
_enough_ to tell us if our towns are built to quality
standards, and if they're not built to quality standards,
well, it's his job to annoy us until we repair them.
Unfortunately, i've got some bad news to share with you.
After hastily exiting the train in ELSE-VILLE last night and
not realizing there was no platform in this town (Thanks
Terry!), KENNY_LINTER has broken both of his legs, fractured
an arm, and scratched his face up pretty bad. So i doubt
we'll be hearing from him in this episode, but stay tuned
for future appearances.

THE_TRAIN: The Train represents our Python script.

THE_TRACKS: The (railroad)tracks represent our program
logic. And the train's course is bound to these tracks

THE_ENGINEER: This is the Python runtime which "drives" the
train.

THE_TRACK_SWITCH: The Track Switch is a mechanical section
of the track (aka: logic gate) placed approximately halfway
between the train station and the two shanty towns that
Terry built. The switch allows the train to travel in one of
two directions -- one leading to IF_VILLE, and one leading
to ELSE_VILLE. Now, the mechanical apparatus of the switch
is spring loaded, and thus, by default, it always sends a
passing train to ELSE_VILLE. However, there is a tiny
control button mounted on a nearby fence post, one which
when pressed, will align the tracks with IF_VILLE. However,
since the trains in this metaphor have no brakes, and since
the button is really ~really~ small -- and since i couldn't
think of a more creative scenario! -- there is only one
creature who can press this button (TRUTHY_CLAWS!). And she
presses this button using one of her long pointy claws, and
thus, can send the train towards IF_VILLE.

TRUTHY_CLAWS: TruthyClaws (or "TC", as we like to call her)
is a mostly harmless anthropomorphized version of a
marsupial who's long claws only seem useful (at least upon
first sight) for causing a dreadful fright. But in reality,
these claws serve a vital purpose in our little metaphorical
world. You see, of ~all~ the characters in our little
universe, only TC (using one of her dreadfully long claws)
can press the little button on the TRACK_SWITCH and send us
along a path to IF-VILLE. And, every time TC takes a ride
with us in the train, she presses the little button for us,
and off we go to IF-VILLE (Hooray!). However, sometimes us
guys get a little rowdy and tell dirty jokes during the
trip, and TC, being uptight and all, tends to get offended,
and sometimes she refuses to ride with us. So, whenever TC
is with us, we always go to IF-VILLE, but if she's off
pouting somewhere, the train goes to ELSE-VILLE

THE_TRACK_DEVIL: The Track Devil is a supernatural being in
the mold of Loki who specializes in all forms of mischievous
pranks. And you ne

Re: Python homework

2017-12-08 Thread MRAB
On 2017-12-06 01:33, nick.martinez2--- via Python-list wrote:
> I have a question on my homework. My homework is to write a program in which
the computer simulates the rolling of a die 50
> times and then prints
> (i). the most frequent side of the die
> (ii). the average die value of all rolls.
> I wrote the program so it says the most frequent number out of all the rolls
for example (12,4,6,14,10,4) and will print out "14" instead of 4 like I need.
> This is what I have so far:
> import random
>
> def rollDie(number):
>  rolls = [0] * 6
>  for i in range(0, number):
>  roll=int(random.randint(1,6))
>  rolls[roll - 1] += 1
>  return rolls
>
> if __name__ == "__main__":
>  result = rollDie(50)
>  print (result)
>  print(max(result))
>
What is "rolls"? It's the number of times each side came up.

In the last line you asked it for the maximum number of times a side came up,
and that's what you got.

You now just have to figure out _which_ side of the die that count corresponds
to.

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


Re: f-string

2017-12-08 Thread Ned Batchelder
On 12/5/17 7:16 PM, Steve D'Aprano wrote:
> compile('f"{spam} {eggs}"', '', 'single')

$ python3.6
Python 3.6.3 (default, Octâ  4 2017, 06:03:25)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> compile('f"{spam} {eggs}"', '', 'single')
 at 0x105e79660, file "", line 1>
 >>> co = _
 >>> spam = 17
 >>> eggs = 34
 >>> eval(co)
'17 34'
 >>> dis.dis(co)
 â  1â â â â â â â â â â  0 LOAD_NAMEâ â â â â â â â â â â â â â â  0
(spam)
 â â â â â â â â â â â â â  2 FORMAT_VALUEâ â â â â â â â â â â â  0
 â â â â â â â â â â â â â  4 LOAD_CONSTâ â â â â â â â â â â â â â  0 ('
')
 â â â â â â â â â â â â â  6 LOAD_NAMEâ â â â â â â â â â â â â â â  1
(eggs)
 â â â â â â â â â â â â â  8 FORMAT_VALUEâ â â â â â â â â â â â  0
 â â â â â â â â â â â â  10 BUILD_STRINGâ â â â â â â â â â â â  3
 â â â â â â â â â â â â  12 PRINT_EXPR
 â â â â â â â â â â â â  14 LOAD_CONSTâ â â â â â â â â â â â â â  1
(None)
 â â â â â â â â â â â â  16 RETURN_VALUE


--Ned.

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


Re: f-string

2017-12-08 Thread MRAB
On 2017-12-06 00:16, Steve D'Aprano wrote:
> Anyone got a handy copy of Python 3.6 available to test something for me?
>
> What does compile('f"{spam} {eggs}"', '', 'single') return?
>
> What does eval()'ing the above compiled object do? If necessary, you may have
> to define spam and eggs first.
>
>
> Thanks in advance.
>
>
Microsoft Windows [Version 10.0.15063] (c) 2017 Microsoft Corporation. All
rights reserved.

C:\Users\MRAB>py -3.6
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> spam = 'SPAM'
 >>> eggs = 'EGGS'
 >>> c = compile('f"{spam} {eggs}"', '', 'single')
 >>> c
 at 0x0269E2020C00, file "", line 1>
 >>> eval(c)
'SPAM EGGS'
 >>>

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


[RELEASE] Python 3.6.4rc1 and 3.7.0a3 now available for testing

2017-12-08 Thread Ned Deily
Announcing the immediate availability of Python 3.6.4 release candidate 1 and
of Python 3.7.0 alpha 3!

Python 3.6.4rc1 is the first release candidate for Python 3.6.4, the next
maintenance release of Python 3.6.  While 3.6.4rc1 is a preview release and,
thus, not intended for production environments, we encourage you to explore it
and provide feedback via the Python bug tracker (https://bugs.python.org).
3.6.4 is planned for final release on 2017-12-18 with the next maintenance
release expected to follow in about 3 months.  You can find Python 3.6.4rc1 and
 more information here:
https://www.python.org/downloads/release/python-364rc1/

Python 3.7.0a3 is the third of four planned alpha releases of Python 3.7, the
next feature release of Python.  During the alpha phase, Python 3.7 remains
under heavy development: additional features will be added and existing
features may be modified or deleted.  Please keep in mind that this is a
preview release and its use is not recommended for production environments. 
The next preview release, 3.7.0a4, is planned for 2018-01-08. You can find
Python 3.7.0a3 and more information here:
https://www.python.org/downloads/release/python-370a3/

--
  Ned Deily
  [email protected] -- []

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


Re: f-string

2017-12-08 Thread John Pote

On 06/12/2017 00:16, Steve D'Aprano wrote:
> Anyone got a handy copy of Python 3.6 available to test something for me?
>
> What does compile('f"{spam} {eggs}"', '', 'single') return?
>
> What does eval()'ing the above compiled object do? If necessary, you may have
> to define spam and eggs first.
>
>
> Thanks in advance.
>
>
rslt = compile('f"{spam} {eggs}"', '', 'single')

print( rslt )
print( "\n" )

spam = "SPAM"
eggs = "scrambled"
eRslt = eval( 'f"{spam} {eggs}"' )
print( eRslt )

Ran above test file and got,
 >>python36 compiletest.py
 at 0x02120E40, file "", line 1>


SPAM scrambled
 >>

Py version on Win 7 box
Python 3.6.3 (v3.6.3:2c5fed8, Octâ  3 2017, 18:11:49) [MSC v.1900 64 bit
(AMD64)] on win32

Any help?
John

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


Re: we want python software

2017-12-08 Thread Rustom Mody
On Wednesday, December 6, 2017 at 3:10:24 AM UTC+5:30, Igor Korot wrote:
> Hi, Tony,
>
> On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff  wrote:
> > On 05/12/17 16:55, Igor Korot wrote:
> >> Hi,
> >>
> >> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy wrote:
> >>> Sir,
> >>> I am b.tech student I would like to learn python. So please send
the python software.
> >> Sorry, we don't send anything. You will have to go get it yourself. -)
> >>
> > Well, at least try to be helpful:
> > https://www.python.org/downloads/
>
> This is LMGIFY.
> If they say they are tech students - they should know how to work with
Google.
>
> And I even tried to be polite. I should have probably write something like:
>
> 1. Open the Web browser.
> 2. In the "Address Bar" type "www.pyton.org".
> 3. Find the link which reads "Downloads". Click on it.
> 4. Carefully read what version you need to install for your OS.
> 5. Apply the acquired knowledge and download the appropriate version.
> 6. Click on the installer (if on Windows).
> 7. Follow all the prompts.
> 8. Enjoy.
>
> but this is too much for the tech student.

You are assuming that the strangeness of the request is about 'tech'
[engineering/tech existed centuries before computers]

Do remember one can be a tech-{student,professional} without
- ever having encountered free-software
- internet/USENET culture

â | from which pov the request would not look so odd

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


Re: we want python software

2017-12-08 Thread Abhiram R
On Wed, Dec 6, 2017 at 10:08 AM, km  wrote:

> I dont know how these students are selected into b tech stream in India.
> they are so dumb. All they know is a to open a program we need to double
> click it and it runs.
>
> â ïWe were all once "dumb". We learnt it because someone Taught us. I'd
rather not entertain such or refrain from condescending replies that would
further discourage people from trying to get into the field. With all the
emphasis on the Python "community", it's important not to be so dismissive.


Thanks
Abhiram â ï




>
>
> On Wed, Dec 6, 2017 at 9:19 AM, Rustom Mody  wrote:
>
> > On Wednesday, December 6, 2017 at 3:10:24 AM UTC+5:30, Igor Korot wrote:
> > > Hi, Tony,
> > >
> > > On Tue, Dec 5, 2017 at 11:10 AM, Tony van der Hoff  wrote:
> > > > On 05/12/17 16:55, Igor Korot wrote:
> > > >> Hi,
> > > >>
> > > >> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy wrote:
> > > >>> Sir,
> > > >>> I am b.tech student I would like to learn python. So please
> > send the python software.
> > > >> Sorry, we don't send anything. You will have to go get it yourself.
> -)
> > > >>
> > > > Well, at least try to be helpful:
> > > > https://www.python.org/downloads/
> > >
> > > This is LMGIFY.
> > > If they say they are tech students - they should know how to work with
> > Google.
> > >
> > > And I even tried to be polite. I should have probably write something
> > like:
> > >
> > > 1. Open the Web browser.
> > > 2. In the "Address Bar" type "www.pyton.org".
> > > 3. Find the link which reads "Downloads". Click on it.
> > > 4. Carefully read what version you need to install for your OS.
> > > 5. Apply the acquired knowledge and download the appropriate version.
> > > 6. Click on the installer (if on Windows).
> > > 7. Follow all the prompts.
> > > 8. Enjoy.
> > >
> > > but this is too much for the tech student.
> >
> > You are assuming that the strangeness of the request is about 'tech'
> > [engineering/tech existed centuries before computers]
> >
> > Do remember one can be a tech-{student,professional} without
> > - ever having encountered free-software
> > - internet/USENET culture
> >
> > â | from which pov the request would not look so odd
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> --
> https://mail.python.org/mailman/listinfo/python-list
>



--
-Abhiram R
áÉ$

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


Re: we want python software

2017-12-08 Thread Ethan Furman
On 12/05/2017 09:27 PM, km wrote:

[snip]

Many things in this world are frustrating, but being hateful will not solve
anything.  Please control yourself.

--
~Ethan~

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


Re: Python homework

2017-12-08 Thread ssghotra1997
import random

def rollDie(num):
sides = {'One':0, 'Two':0,'Three':0,'Four':0,'Five':0,'Six':0}

for i in range(num):
rolls = int(random.randint(1, 6))
if rolls == 1:
sides['One'] += 1
if rolls == 2:
sides['Two'] += 1
if rolls == 3:
sides['Three'] += 1
if rolls == 4:
sides['Four'] += 1
if rolls == 5:
sides['Five'] += 1
if rolls == 6:
sides['Six'] += 1

return sides,max(sides,key=sides.get)

print(rollDie(50))


*** OUTPUT *
({'One': 10, 'Two': 7, 'Three': 7, 'Four': 11, 'Five': 7, 'Six': 8}, 'Four')

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


Re: [Python-Dev] [RELEASE] Python 3.6.4rc1 and 3.7.0a3 now available

2017-12-08 Thread Hasan Diwan
Congrats to all involved! -- Hâ ï

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


Re: we want python software

2017-12-08 Thread Steve D'Aprano
On Wed, 6 Dec 2017 03:45 pm, Abhiram R wrote:

> On Wed, Dec 6, 2017 at 10:08 AM, km  wrote:
>
>> I dont know how these students are selected into b tech stream in India.
>> they are so dumb. All they know is a to open a program we need to double
>> click it and it runs.
>>
>> We were all once "dumb". We learnt it because someone Taught us.


Since you're so open to being corrected, let me remind you to read your posts
before sending. Somehow you managed to introduce an extra > quote marker at the
 beginning of your own comment, (the line starting "We were all once...").
Check it out here:

https://mail.python.org/pipermail/python-list/2017-December/729112.html

and you will see that your comment is quoted, as if it were written by the
person you are replying to.

(Normally I wouldn't bother mentioning something so trivial, but since you make
 the excellent point that we don't learn to correct mistakes unless we have
them pointed out, I thought I'd do so.)


> I'd rather not entertain such or refrain from condescending replies

I think you have misunderstood the word "condescending".

It is condescending to assume that the OP, Jyothiswaroop Reddy, is a fragile
and delicate little hothouse flower that needs protecting from reality where
people will tell you "Don't be so lazy and don't waste our time".

I prefer to expect more of people and let them meet my expectations, than to
downgrade my expectations and coddle them into a spiral of lower and lower
competence and ability.

(By the way Rustom, if you're reading, thank you for that link to the video a
few weeks ago about teaching 2 + 2 = 22. My blood pressure just about doubled
watching it.)




--
Steve
â £Cheer up,â Ø they said, â £things could be worse.â Ø So I cheered up, and
sure
enough, things got worse.

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


Re: f-string

2017-12-08 Thread Steve D'Aprano
On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote:

> On Wed, Dec 6, 2017 at 11:54 AM, John Pote 
> wrote:
>>
>> On 06/12/2017 00:16, Steve D'Aprano wrote:
>>>
>>> Anyone got a handy copy of Python 3.6 available to test something for me?
>>>
>>> What does compile('f"{spam} {eggs}"', '', 'single') return?

[...]

> I think Steve just wanted to see what we'd all define spam and eggs as.
>
> ChrisA
> *ducking for cover*

Possibly duck eggs :-)


I was thinking of responding to your comment on Python-Ideas that said there is
 no way to represent an unevaluated f-string in Python, but then I decided that
 even for me that was too pedantic.




--
Steve
â £Cheer up,â Ø they said, â £things could be worse.â Ø So I cheered up, and
sure
enough, things got worse.

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


Re: f-string

2017-12-08 Thread Chris Angelico
On Wed, Dec 6, 2017 at 8:24 PM, Steve D'Aprano
 wrote:
> On Wed, 6 Dec 2017 12:21 pm, Chris Angelico wrote:
>
>> On Wed, Dec 6, 2017 at 11:54 AM, John Pote 
>> wrote:
>>>
>>> On 06/12/2017 00:16, Steve D'Aprano wrote:

 Anyone got a handy copy of Python 3.6 available to test something for me?

 What does compile('f"{spam} {eggs}"', '', 'single') return?
>
> [...]
>
>> I think Steve just wanted to see what we'd all define spam and eggs as.
>>
>> ChrisA
>> *ducking for cover*
>
> Possibly duck eggs :-)
>
>
> I was thinking of responding to your comment on Python-Ideas that said there
> is no way to represent an unevaluated f-string in Python, but then I decided
> that even for me that was too pedantic.
>

Considering that it isn't an object, it'd be on par with saying that there's no
 way to represent an unevaluated "if-else" expression. You can wrap it in a
function and carry that function around, or you can use the source code and
then exec it when you need it, but neither of those really represents an
unevaluated f-string - they represent something else that might be equivalent.
So yeah, even for the great D'Aprano, that would be a bit too pedantic. :)

ChrisA

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


Re: we want python software

2017-12-08 Thread Percival John Hackworth
On 05-Dec-2017, km wrote
(in article):

> I dont know how these students are selected into b tech stream in India.
> they are so dumb. All they know is a to open a program we need to double
> click it and it runs.- windoze legacy. most of the time they pay huge
> amount to a greedy college and get into tech stream.
> Now that Java boom (jobs) is over in India and python is booming in AI and
> machine learning these people want to learn python and get easy jobs
> (software coolies). pls dont even entertain such posts.
A friend who deals with outsource Indian developers told me something
interesting. Apparently, the programmers are paid very poorly in India.
Managers are paid much better. So the career path over there is to "pay your
dues" writing code, then become a manager where you no longer have to write
code. It means that all the product teams that are outsourced to India
*always* get new, green people because as soon as they get any good, they
become managers.

That explains a lot, doesn't it. It also means when your company lays off a lot
 of technical staff and outsources tech pubs, 1st line support, and development
 to India, the people left in the US are the "Tiger Team" to fix screw ups or
major issues in a product release. Then they sell the company.

Another friend hired a programmer from India to develop a java-based web site
to sell their product in the iOS App Store. He asked me to look at problems
they were having with the site. I'm a sysadmin, not a java programmer, but I
knew that you're not supposed to run a Tomcat web server as root. According to
friends, you're not supposed to expose Tomcat to the internet at all. That's
not what this developer did. It looked like it was a school project that he
setup stuff but didn't know how it's done in production with security enabled.
Nor could he deal with AWS.

It's a nightmare out there for people looking to get development done "on the
cheap". The good people (e.g. the friends I asked for advice) are to busy to do
 such little projects to bother. So the market is left with Junior people in
India making crap. It's not a question of them taking jobs away from U.S.
developers. It's a question of the good ones already have work. Can we train
Joe to setup Wordpress and secure it or write a Java Web site when all he's
done before is manufacturing or worked in a grocery store.

Other groups aren't so nice to beginners - the perl group is brutal and tell a
student to do their own homework. I'm just dipping my toe into python here and
you guys more helpful. Mostly because there's so much possibility in python
(compared to other scripting languages).

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


Re: f-string

2017-12-08 Thread Steve D'Aprano
On Wed, 6 Dec 2017 11:54 am, John Pote wrote:

[...]
> Ran above test file and got,
>  >>python36 compiletest.py
>  at 0x02120E40, file "", line 1>
>
>
> SPAM scrambled

Thanks everyone, that's what I wanted to see.



--
Steve
â £Cheer up,â Ø they said, â £things could be worse.â Ø So I cheered up, and
sure
enough, things got worse.

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


Re: How to use a regexp here

2017-12-08 Thread breamoreboy
On Monday, December 4, 2017 at 9:44:27 AM UTC, Cecil Westerhof wrote:
> I have a script that was running perfectly for some time. It uses:
> array = [elem for elem in output if 'CPU_TEMP' in elem]
>
> But because output has changed, I have to check for CPU_TEMP at the
> beginning of the line. What would be the best way to implement this?
>
> --
> Cecil Westerhof
> Senior Software Engineer
> LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Use https://docs.python.org/3/library/stdtypes.html#str.startswith instead of
the test for `in`.

--
Kindest regards.

Mark Lawrence.

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


Save and load initialized class

2017-12-08 Thread Bob van der Poel
I'm trying to something simple (yeah, right). Mainly I want to have a bunch
of variables which my program needs and uses to be in a saveable/loadable
block. Currently I have then all as a bunch of globals which works, but
trying to keep track of them and the correct spellings, etc becomes a bit
of maintenance nightmare. So, demonstrating all my cleverness I came up
with:

class Opts():
 var1 = 123
 var2 = "hello world"

Notationally, it looks much like the variables are stored in a separate
module. I can call these options from within a function with the simple
notation:

  if Opts.var1 == 99 ...

And, if I need to change a value I can:

 global
 Opts.var1 = 0

Further, and importantly, I can save the lot with:

  json.dump(Opts.__dict__, open("mybuffer", "w"))

But, I can't figure out how to load the saved data back into my program.
Doing

  z=json.load (open("mybuffer", "r"))

loads a dictionary ... which makes sense since that is what I saved. So,
can I now reset the values in Opts from a saved dictionary?

Best,


-- 

 Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: [email protected]
WWW:   http://www.mellowood.ca
-- 
https://mail.python.org/mailman/listinfo/python-list


repeating posts

2017-12-08 Thread Rustom Mody
Repeating old posts again appearing

[No not complaining… I know people are working on it. Thanks Skip and whoever 
else]

Just thought I'd mention they are now mildly mojibaked
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to use a regexp here

2017-12-08 Thread Cecil Westerhof
Rick Johnson  writes:

>> There is now also a line that starts with: PCH_CPU_TEMP:
>> And I do not want that one.
>
> Yes. But be aware, that while the `str.startswith(target)`
> method is indeed more efficient than a more generalized
> "inclusion test", if the target is not _always_ at the
> beginning of the string, then your code is going to skip
> right over valid match like a round stone skipping across
> the surface of a glass-smooth lake. But if you are sure the
> target will always be at the beginning of the string, then
> it is the best choice.

Yes, I am sure it is always at the beginning of the line. (It is output from
the Linux sensors command.)

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


Re: why won't slicing lists raise IndexError?

2017-12-08 Thread breamoreboy
On Monday, December 4, 2017 at 7:10:01 PM UTC, Jason Maldonis wrote:
> I was extending a `list` and am wondering why slicing lists will never
> raise an IndexError, even if the `slice.stop` value if greater than the
> list length.
>
> Quick example:
>
> my_list = [1, 2, 3]
> my_list[:100]  # does not raise an IndexError, but instead returns the full
> list
>
> Is there any background on why that doesn't raise an IndexError? Knowing
> that might help me design my extended list class better. For my specific
> use case, it would simplify my code (and prevent `if isinstance(item,
> slice)` checks) if the slicing raised an IndexError in the example I gave.

This is explained in the Python tutorial for strings
https://docs.python.org/3/tutorial/introduction.html#strings, as a list is a
sequence just like a string it will act in exactly the same way.

--
Kindest regards.

Mark Lawrence.

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


How to use a regexp here

2017-12-08 Thread Cecil Westerhof
I have a script that was running perfectly for some time. It uses:
array = [elem for elem in output if 'CPU_TEMP' in elem]

But because output has changed, I have to check for CPU_TEMP at the beginning
of the line. What would be the best way to implement this?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

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


Re: f-string

2017-12-08 Thread Chris Angelico
On Tue, Dec 5, 2017 at 6:37 PM, Ned Batchelder  wrote:
> On 12/5/17 7:16 PM, Steve D'Aprano wrote:
>> compile('f"{spam} {eggs}"', '', 'single')
>
> $ python3.6
> Python 3.6.3 (default, Octâ  4 2017, 06:03:25)
> [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> compile('f"{spam} {eggs}"', '', 'single')
>  at 0x105e79660, file "", line 1>
>  >>> co = _
>  >>> spam = 17
>  >>> eggs = 34
>  >>> eval(co)
> '17 34'
>  >>> dis.dis(co)
>  â  1â â â â â â â â â â  0 LOAD_NAMEâ â â â â â â â â â â â â â â  0
> (spam)
>  â â â â â â â â â â â â â  2 FORMAT_VALUEâ â â â â â â â â â â â  0
>  â â â â â â â â â â â â â  4 LOAD_CONSTâ â â â â â â â â â â â â â  0 ('
> ')
>  â â â â â â â â â â â â â  6 LOAD_NAMEâ â â â â â â â â â â â â â â  1
> (eggs)
>  â â â â â â â â â â â â â  8 FORMAT_VALUEâ â â â â â â â â â â â  0
>  â â â â â â â â â â â â  10 BUILD_STRINGâ â â â â â â â â â â â  3
>  â â â â â â â â â â â â  12 PRINT_EXPR
>  â â â â â â â â â â â â  14 LOAD_CONSTâ â â â â â â â â â â â â â  1
> (None)
>  â â â â â â â â â â â â  16 RETURN_VALUE
>

We have another batch of duplicated messages coming through. Are they
related to the previous issue? Possibly noteworthy: they all seem to
have a consistent issue with character encoding.

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