Re: Lies in education [was Re: The "loop and a half"]

2017-10-14 Thread Peter J. Holzer
On 2017-10-14 01:05, Steve D'Aprano  wrote:
> On Sat, 14 Oct 2017 07:15 am, Peter J. Holzer wrote:
>> On 2017-10-13 15:11, alister  wrote:
>>> On Sat, 14 Oct 2017 01:48:44 +1300, Gregory Ewing wrote:
 Steve D'Aprano wrote:
> I wasn't questioning where the data came from, but how the compiler can
> write to READ ONLY MEMORY which might not even be in the same continent
> as the compiler that generated the code.
 
 I thought it would be fairly obvious that by "put it in read-only
 memory" I meant "arrange for it to be in a location that is read-only at
 run time". Obviously it can't be read-only at *compile* time, just as a
 physical ROM can't be read-only at manufacture time.
>>>
>>> oh yes it can
>>> in the past for large quantitys the data in a ROM chip was part of the
>>> chip etching mask (unless you consider a blank silicon wafer to be
>>> "Programmable" by the etching process)rather than prom which used
>>> programmable fuses or prom which could be erased by UV light (assuming
>>> the chip was fitted with a window otherwise it was known as one time
>>> programmable EPROM)
>> 
>> He didn't say "programmable". He said that the is "not read-only".
>
> In context, we are talking about a computer program (the compiler) writing
> data to memory.

No, I don't think so. You keep talking about that, even though Gregory
hasn't used those exact words and has since clarfified that he didn't
mean it that way. Y'know, I'm all for writing as carefully und
unambiguously as possible and for discussing questionable wording
(especially in a large forum where many (including me) will have a
different native language), but we all are sloppy in our writing every
now and then and insisting that somebody must have meant X' because they
wrote X doesn't really help and gets boring pretty soon.

Right now I was replying to alister's claim that "yes [ROMs] can [be
read-only at manufacture time]". That doesn't have anything with
compilers. Where the information came from is irrelevant to the question
whether ROMS are read-only during manufacture. Certainly they are not
only read (I don't know if they are read at all, but I guess they are
during quality control), but information is put onto them. I think that
this process can be called "writing" (It's a lot closer to what has been
called "writing" for the last few millenia than what happenes to a RAM
chip during "writing"), but even that is a red herring as the word
"write" wasn't actually used (only "read").


> Your example of writing on paper is a good one, but it argues *against* your
> position, not for it. If you compile some code, then take a hex dump and
> print it out:
>
> gcc program.c
> xxd a.out | lp
>
> would you describe the process as "the compiler writes to the piece of paper"?

No, but the printer does. And that means that the paper is not
read-only. Which was the point of the exchange between Gregory and
alister. The compiler isn't in the game any more.

But there is a difference between printing the hex dump of the output of
the compiler and loading it into memory to be executed. The latter is
the intended purpose of the file. When a compile writes some data into
the ".rodata" section of the file, the intention is that this data
should be read-only at run-time. Therefore I consider the phrasing "the
compiler puts it into read-only memory", while certainly sloppy and not
technically correct, perfectly comprehensible. And I can't find anything
wrong with his revised phrasing "arrange for it to be in a location that
is read-only at run time". That's exactly what the compiler does. That
the compiler doesn't actually have control over what happens to the file
afterwards is immaterial.

hp


-- 
   _  | Peter J. Holzer| Fluch der elektronischen Textverarbeitung:
|_|_) || Man feilt solange an seinen Text um, bis
| |   | h...@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Heroku (was Re: Lies in education [was Re: The "loop and a half"])

2017-10-14 Thread Peter J. Holzer
On 2017-10-13 21:42, Ben Bacarisse  wrote:
> That's one way to put it.  Another is that to use Python I need to buy a
> new service that is already configured.

That's exactly the same for PHP. You can't use that either unless
somebody configured to server to use it.

The difference is that lots of providers started configuring their
servers for use of PHP in the late 1990s, but didn't do that for Python.

> If that's the way it's done, fine, but this sub-thread started with
> someone being surprised by the success of PHP.

Which probably boils down to the question: Why did providers offer PHP
and not Python? One reason might be that at the time no suitable web
framework for Python existed (Zope was released in 1999, and I remember
it to be rather heavy-weight). One reason might be that providers didn't
see PHP as a "real" programming language and therefore deemed it safer.

hp


-- 
   _  | Peter J. Holzer| Fluch der elektronischen Textverarbeitung:
|_|_) || Man feilt solange an seinen Text um, bis
| |   | h...@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Heroku (was Re: Lies in education [was Re: The "loop and a half"])

2017-10-14 Thread alister via Python-list
On Sat, 14 Oct 2017 11:41:08 +0200, Peter J. Holzer wrote:

> On 2017-10-13 21:42, Ben Bacarisse  wrote:
>> That's one way to put it.  Another is that to use Python I need to buy
>> a new service that is already configured.
> 
> That's exactly the same for PHP. You can't use that either unless
> somebody configured to server to use it.
> 
> The difference is that lots of providers started configuring their
> servers for use of PHP in the late 1990s, but didn't do that for Python.
> 
>> If that's the way it's done, fine, but this sub-thread started with
>> someone being surprised by the success of PHP.
> 
> Which probably boils down to the question: Why did providers offer PHP
> and not Python? One reason might be that at the time no suitable web
> framework for Python existed (Zope was released in 1999, and I remember
> it to be rather heavy-weight). One reason might be that providers didn't
> see PHP as a "real" programming language and therefore deemed it safer.
> 
> hp

could it have been that it was simply a default Apache module installed 
by whatever version of Linux was being used by the host?



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


Re: Lies in education [was Re: The "loop and a half"]

2017-10-14 Thread Steve D'Aprano
On Sat, 14 Oct 2017 08:26 pm, Peter J. Holzer wrote:

> On 2017-10-14 01:05, Steve D'Aprano  wrote:

>> In context, we are talking about a computer program (the compiler) writing
>> data to memory.
> 
> No, I don't think so. You keep talking about that, even though Gregory
> hasn't used those exact words and has since clarfified that he didn't
> mean it that way.

But without clarifying what he meant. I've had to piece that together from
bits and pieces of random comments from other people. I still don't know
exactly what Greg intended to say, only what I have inferred.

Initially Greg said:

"If the compiler can tell where p is initially pointing, it 
could put the pointer in read-only memory."

and when I asked:

"If it's read-only, how can the compiler write to it?"

instead of clarifying what he meant, Greg defended his misleading choice of
words with:

"So, the factory is allowed to write to it. Possibly it's writing
data that came from... a compiler?"

So Greg himself has used the term "write" to describe the scenario he
describes, it is not just me.

It has taken, what, I guess something like a dozen or more back and forward
posts before Chris happened to casually mention that the *program loader*
(not compiler!) writes the data to *write-protected memory* (not ROM).

If only people had said that in the first place, instead of reinforcing my
misunderstanding by arguing whether or not the act of etching paths into a
silicon chip at a factory counts as the compiler writing.

We're all human and we all sometimes use sloppy phrasing. I know I do. But the
least we can do is try to be more aware of when we're causing more confusion
than insight, and instead of doubling down and defending the sloppy phrasing,
try to explain what we mean.


> Y'know, I'm all for writing as carefully und 
> unambiguously as possible and for discussing questionable wording
> (especially in a large forum where many (including me) will have a
> different native language), but we all are sloppy in our writing every
> now and then and insisting that somebody must have meant X' because they
> wrote X doesn't really help and gets boring pretty soon.

The problem is not the initial miscommunication. The problem is the insistence
on defending that miscommunication even in the face of confusion.

Right from my first comment on this topic, I said:

"I come from the days when ROM was actual ROM, burned in at
the factory."

because I already suspected that Greg was using "read-only" to mean something
other than read-only, but what I did not know.

Now maybe I could have been more explicit by asking "What the hell do you mean
by read-only memory, if you're not talking about actual ROM?" and the fact
that I didn't is *my* failure. (Mea culpa.)

But be reasonable, I had just asked almost exactly the same question not one
line earlier:

"If it's read-only, how can the compiler write to it?"

and (as far as I can see) *nobody* thought to actually answer my question
until perhaps a dozen posts later, when Chris more-or-less said:

- the compiler doesn't, but the program loader does;

- its not so much read-only memory as write-protected memory: 
  privileged code can still write to it.


(Have I got the details right? Or at least close enough?)


[...]
> Therefore I consider the phrasing "the
> compiler puts it into read-only memory", while certainly sloppy and not
> technically correct, perfectly comprehensible.

And here we go again. Instead of holding the author responsible for the poor
phrasing, the reader is blamed for not somehow inferring the author's
intended meaning.

"Somebody misunderstood Greg's sloppy and incorrect words to mean something
Greg didn't intend? And when given the opportunity to clarify, Greg failed to
do so and continued using the sloppy and incorrect phrasing? Oh, that's not
Greg's fault, it is the fault of the reader for not reading Greg's mind and
knowing what he really meant. I shall continue to defend the choice of words
which are LITERALLY WRONG rather than accept that somebody might have
legitimately misunderstood them."



> And I can't find anything 
> wrong with his revised phrasing "arrange for it to be in a location that
> is read-only at run time". That's exactly what the compiler does.

Except *read-only* is a misleading and poor way to describe it and it too is
LITERALLY WRONG. The program loader can write to it, and does so every single
time a program is run. Why is it called read-only when it isn't read-only or
even Write Once Read Many?

I am sure that nobody, including Greg and yourself, would describe /root on a
standard Linux/Unix system as "a read only directory" just because non-root
processes can't write to it. You'd probably describe it as write-protected,
or similar terminology.

And if somebody asked "How is it read-only, root can write to it?" I surely
hope you wouldn't double-down and insist that, no, it really, truly is
read-only even though root can write

Re: Heroku (was Re: Lies in education [was Re: The "loop and a half"])

2017-10-14 Thread Ben Bacarisse
"Peter J. Holzer"  writes:

> On 2017-10-13 21:42, Ben Bacarisse  wrote:
>> That's one way to put it.  Another is that to use Python I need to buy a
>> new service that is already configured.
>
> That's exactly the same for PHP. You can't use that either unless
> somebody configured to server to use it.

I was not using "I" generically.  *I* don't need to buy a service
configured to use PHP because:

> The difference is that lots of providers started configuring their
> servers for use of PHP in the late 1990s, but didn't do that for Python.
>
>> If that's the way it's done, fine, but this sub-thread started with
>> someone being surprised by the success of PHP.
>
> Which probably boils down to the question: Why did providers offer PHP
> and not Python? One reason might be that at the time no suitable web
> framework for Python existed (Zope was released in 1999, and I remember
> it to be rather heavy-weight). One reason might be that providers didn't
> see PHP as a "real" programming language and therefore deemed it
> safer.

That would be deeply ironic, given the security pain that it has turned
out to be!

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


Re: Lies in education [was Re: The "loop and a half"]

2017-10-14 Thread Chris Angelico
On Sat, Oct 14, 2017 at 10:12 PM, Steve D'Aprano
 wrote:
> But be reasonable, I had just asked almost exactly the same question not one
> line earlier:
>
> "If it's read-only, how can the compiler write to it?"
>
> and (as far as I can see) *nobody* thought to actually answer my question
> until perhaps a dozen posts later, when Chris more-or-less said:
>
> - the compiler doesn't, but the program loader does;
>
> - its not so much read-only memory as write-protected memory:
>   privileged code can still write to it.
>
>
> (Have I got the details right? Or at least close enough?)

Pretty close. There's a lot of levels of indirection involved. When a
program asks to manipulate a piece of memory, it uses a segment
selector and a memory location (offset); in most modern systems, a
flat memory model is used, where all identical offsets mean the same
piece of memory, so we tend to think of the offset as being the entire
pointer.

Those segment selectors refer to something in the segment table for
*that process*. That means that location 0x12345678 in my process
could be a completely different hunk of memory to location 0x12345678
in your process. (It's also possible that they're the same - loading
shared modules (DLL/SO) often just means mapping an already-loaded
block of memory into your process.) Your process is completely unaware
of any memory that it doesn't have access to. It also has no way to
violate the notion of "read-only", because that's a flag set on the
memory pages in that process's page table.

So when the program loader goes to work, it loads up a page of memory
from the disk, then grants this process read-only access to it, by
mapping that page into the process's memory space. The program loader,
being part of the kernel, isn't just "privileged" in the sense of
running as root/Administrator - it is the one that determines what
"root" even means. If root is able to manipulate a process's page
tables, it's only via kernel APIs.

As such, the concept of "read-only" is actually hard-wired in the
process's memory map. There's no way to violate that.

(I may have some details wrong, as it's a long time since I've worked
with any of this. Also, this is massively simplified. But I think it's
about right.)

> [...]
>> Therefore I consider the phrasing "the
>> compiler puts it into read-only memory", while certainly sloppy and not
>> technically correct, perfectly comprehensible.
>
> And here we go again. Instead of holding the author responsible for the poor
> phrasing, the reader is blamed for not somehow inferring the author's
> intended meaning.
>
> "Somebody misunderstood Greg's sloppy and incorrect words to mean something
> Greg didn't intend? And when given the opportunity to clarify, Greg failed to
> do so and continued using the sloppy and incorrect phrasing? Oh, that's not
> Greg's fault, it is the fault of the reader for not reading Greg's mind and
> knowing what he really meant. I shall continue to defend the choice of words
> which are LITERALLY WRONG rather than accept that somebody might have
> legitimately misunderstood them."

Saying that the compiler puts something into read-only memory is
skipping a lot of steps in the procedure - notably, it's making a
temporal jump right from compilation time to run time. Obviously the
data is in some form of read/write storage in between (eg a hard
drive), during which it can very well be mutated. So it's somewhat
defensible to consider that the compiler sorta-kinda places things
into the run-time process's memory (since the compiler (or the linker)
is what instructs the program loader how to arrange the process memory
tables), while still being reasonable to argue that, since the
compiler is writing to it, it must be read/write (which it is - in the
compiler's memory space). The distinction here is that there's been a
change in POV; each time, we're talking from the POV of the current
process, but that's a different process (compiler vs running program).

>> And I can't find anything
>> wrong with his revised phrasing "arrange for it to be in a location that
>> is read-only at run time". That's exactly what the compiler does.
>
> Except *read-only* is a misleading and poor way to describe it and it too is
> LITERALLY WRONG. The program loader can write to it, and does so every single
> time a program is run. Why is it called read-only when it isn't read-only or
> even Write Once Read Many?

It *is* read-only, from the POV of the running process. Nothing (other
than actual burned ROM) is truly read-only; possibly the flashable
BIOS is read-only from the POV of a running system, but I'm not even
sure of that. From the POV of the kernel, all RAM is read/write (I
think; there might be some exceptions, but certainly everything we're
looking at here is); from the POV of various processes, large slabs of
memory are read-only.

> I am sure that nobody, including Greg and yourself, would describe /root on a
> standard Linux/Unix system as "a read only di

test

2017-10-14 Thread Tiglath Suriol
test
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Heroku (was Re: Lies in education [was Re: The "loop and a half"])

2017-10-14 Thread Chris Angelico
On Sat, Oct 14, 2017 at 10:16 PM, Ben Bacarisse  wrote:
> "Peter J. Holzer"  writes:
>> Which probably boils down to the question: Why did providers offer PHP
>> and not Python? One reason might be that at the time no suitable web
>> framework for Python existed (Zope was released in 1999, and I remember
>> it to be rather heavy-weight). One reason might be that providers didn't
>> see PHP as a "real" programming language and therefore deemed it
>> safer.
>
> That would be deeply ironic, given the security pain that it has turned
> out to be!

Yup. And not exactly surprising to any security expert. The history of
computing - well, let's face it, the history of mankind - is littered
with stories of "this is simple and easy, we don't need to secure it"
turning into "this is actually a major problem". Sometimes we can
retrofit enough protection onto the system without fundamentally
breaking it (eg DNS, where a variety of forms of security have been
added); other times, we learn a new best-prac and keep going (eg
parameterized queries rather than risking SQL injection, which some
people still haven't learned, but a lot have); and other times, we
scrap the bad option and start a completely new way of doing things
(bye bye Java applets, bye bye Flash, let's do everything with JS),
which of course isn't necessarily perfect either, but is usually a big
enough advantage to be worth it.

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


BOTLIB #31 released - https://pypi.python.org/pypi/botlib

2017-10-14 Thread Bart Thate
BOTLIB #31 released - https://pypi.python.org/pypi/botlib 

BOTLIB is a python3 framework to use if you want to program CLI, IRC or XMPP 
bots.

features


BOTLIB provides the following features:

::

 object class   save/load to/from a json file.
 rest serverserve saved object’s over http.
 rss fetcherecho rss feeds to irc channels.
 udp server udp to bot to irc channel.
 watcher server run tail -f and have output send to IRC channel.
 email scanning scan mbox format to searchable botlib objects.
 json backend   objects are stored as json string in files on the fs.
 db iteration over stored objects.
 timestamp  time based filenames gives logging capabilities
 future future sensors should provide entry to the logger.

install
===

Clone the source:

:: 

 bart@okdan:~$ hg clone https://bitbucket.org/bthate/botlib

 You might need to do one of the following if the bot doesn't work:

 bart@okdan:~/botlib$ export PYTHONPATH="."
 bart@okdan:~/botlib$ export PYTHONIOENCODING="utf-8"

Another option is to download with pip3 and install globally:

::

 bart@okdan:~$ pip3 install botlib --upgrade

irc
===

Use -n , -s , -c  options to make the bot join the 
network:

::

 bart@okdan:~$ bot -i irc -n botlib -s irc.freenode.net -c \#botlib

You can use the -w option to write config values to ~/.bot/config/irc

xmpp


For the xmpp server use a ~/.sleekpass file with the password in it:

::

 bart@okdan:~$ cat "password" > ~/.sleekpass
 bart@okdan:~$ bot -i xmpp,rss --room=test@conference.localhost

users
=

One needs to add a users origin to be able to give the bot commands. One can 
add a user with the meet command:

::

 bart@okdan:~$ bot meet user@server
 user user@server created

To give the user a permission you can use the perm command:

::

 bart@okdan:~$ bot perm user@server ps
 ok user@server

The u command show the json dump of a user object:

::

 bart@okdan:~$ bot u user@server 
 {
 "_container": {
 "default": "",
 "path": "/home/bart/.bot/user/2017-10-12/21:05:52.095737",
 "prefix": "object",
 "saved": "Thu Oct 12 21:07:03 2017",
 "signature": "c113c4125f8c2a88d5b312e283792ae019c61a52"
 },
 "_type": "",
 "origin": "user@server",
 "perms": [
 "USER",
 "PS"
 ],
 "user": "user@server"
 }

The default shell user is root@shell and give all the commands that are 
available.

commands


The following commands are available:

::

 alias key, value alias. 
 announce  announce text on all channels in fleet. 
 begin begin stopwatch. 
 cfg   edit config files. 
 cmnds show list of commands. 
 deleted   show deleted records. 
 delperm   delete permissions of an user. 
 dump  dump objects matching the given criteria. 
 edit  edit and save objects. 
 end   stop stopwatch. 
 exit  stop the bot. 
 fetcher   fetch all rss feeds. 
 find  present a list of objects based on prompt input. 
 first show the first record matching the given criteria. 
 fix   fix a object by loading and saving it. 
 idle  see how long a channel/nick has been idle. 
 last  show last objectect matching the criteria. 
 license   display BOTLIB license. 
 load  force a plugin reload. 
 log   log some text. 
 loglevel  set loglevel. 
 loud  disable silent mode of a bot. 
 lsshow subdirs in working directory. 
 man   show descriptions of the available commands. 
 mbox  convert emails to botlib objects. 
 meet  create an user record. 
 nick  change bot nick on IRC. 
 perm  add/change permissions of an user. 
 permissions   show permissions granted to a user. 
 perms show permission of user. 
 pid   show pid of the BOTLIB bot. 
 psshow running threads. 
 rebootreboot the bot, allowing statefull reboot (keeping 
connections alive). 
 reloadreload a plugin. 
 restore   set deleted=False in selected records. 
 rmset deleted flag on objects. 
 rss   add a rss url. 
 save  make a kernel dump. 
 shop  add a shopitem to the shopping list. 
 show  show dumps of basic objects. 
 silentput a bot into silent mode. 
 start start a plugin. 
 stop  stop a plugin. 
 synchronize   synchronize rss feeds (fetch but don't show). 
 test  echo origin. 
 timer ti

Re: Return str to a callback raise a segfault if used in string formating

2017-10-14 Thread Stefan Behnel
Vincent Vande Vyvre schrieb am 13.10.2017 um 13:18:
> Le 13/10/17 à 12:39, Paul Moore a écrit :
>> As a specific suggestion, I assume the name of the created file is a
>> string object constructed in the C extension code, somehow. The fact
>> that you're getting the segfault with some uses of that string
>> (specifically, passing it to %-formatting) suggests that there's a bug
>> in the C code that constructs that string. That's where I'd start by
>> looking.

Absolutely.


> That was my first idea, because I can verify the instance of PyUnraw is not
> destroyed when I use the file name, but I was in trouble by the usage of
> the file name in string formatting.
> 
> For example I can use the file name into the slot i.e. shutil.copy(fname,
> "path/renamed.tiff")
> The file is correctly copied.
> 
> In fact, I can do anything with the file name except use it in string
> formatting, then your approach is probably a good way.
> 
> Into the CPython part I have a c-string pythonized by:
>     temp = self->outfname;
>     self->outfname = PyUnicode_FromString(ofname);
>     Py_XDECREF(temp);
> 
> and exposed to Python with:
> static PyMemberDef PyUnraw_members[] = {
>     {"out_file", T_OBJECT_EX, offsetof(PyUnraw, outfname), 0,
>  "Path of the decoded file"},

One more suggestion, in case this is actually your own C code: it's much
easier to write extension modules in Cython than in plain C and C-API code.
Much easier. There is a learning curve, sure, but it unburdens you from so
many pitfalls and boilerplate code that it's always worth switching. And
you also get faster code as a side-effect. How's that for a tradeoff. :)

Stefan
(Cython core developer)

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


Re: Return str to a callback raise a segfault if used in string formating

2017-10-14 Thread Vincent Vande Vyvre

Le 14/10/17 à 15:59, Stefan Behnel a écrit :

Vincent Vande Vyvre schrieb am 13.10.2017 um 13:18:

Le 13/10/17 à 12:39, Paul Moore a écrit :

As a specific suggestion, I assume the name of the created file is a
string object constructed in the C extension code, somehow. The fact
that you're getting the segfault with some uses of that string
(specifically, passing it to %-formatting) suggests that there's a bug
in the C code that constructs that string. That's where I'd start by
looking.

Absolutely.



That was my first idea, because I can verify the instance of PyUnraw is not
destroyed when I use the file name, but I was in trouble by the usage of
the file name in string formatting.

For example I can use the file name into the slot i.e. shutil.copy(fname,
"path/renamed.tiff")
The file is correctly copied.

In fact, I can do anything with the file name except use it in string
formatting, then your approach is probably a good way.

Into the CPython part I have a c-string pythonized by:
     temp = self->outfname;
     self->outfname = PyUnicode_FromString(ofname);
     Py_XDECREF(temp);

and exposed to Python with:
static PyMemberDef PyUnraw_members[] = {
     {"out_file", T_OBJECT_EX, offsetof(PyUnraw, outfname), 0,
  "Path of the decoded file"},

One more suggestion, in case this is actually your own C code: it's much
easier to write extension modules in Cython than in plain C and C-API code.
Much easier. There is a learning curve, sure, but it unburdens you from so
many pitfalls and boilerplate code that it's always worth switching. And
you also get faster code as a side-effect. How's that for a tradeoff. :)

Stefan
(Cython core developer)


Thanks, I know Cython but the code is already in C.

This is a lib released as a frontend.  Then usable only in command line.

It's not my own code, my job is to reimplement the main() function of 
the lib in CPython.


The work is nearly complete, I'm in the tests part.

I think I've found the problem, the string (a file path) is modified in 
c with "sprintf, snprintf, ..." And I plan to change that with some 
CPython equivalent function.



Vincent

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


Re: Return str to a callback raise a segfault if used in string formating

2017-10-14 Thread Paul Moore
On 14 October 2017 at 16:06, Vincent Vande Vyvre
 wrote:
> I think I've found the problem, the string (a file path) is modified in c
> with "sprintf, snprintf, ..." And I plan to change that with some CPython
> equivalent function.

Nice :-) Glad you found it.
Paul
-- 
https://mail.python.org/mailman/listinfo/python-list


Best practise for passing time as arguments

2017-10-14 Thread Andrew Z
Hello,
 I wonder what are the "best practises" for passing "time" parameters to
functions?
I noticed that sometimes i pass "time" as a str and then start "massaging"
it into delta or i need this time format or that format. Thats quite
annoying and inconsistent.
I use word "time" as a general word for date/time/timedelta types.

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


Re: Running flask on AWS SAM

2017-10-14 Thread Frustrated learner
export SERVER_NAME="0.0.0.0:3000 sam local start-api" 
just exports everything and does not execute.

I tried 
export SERVER_NAME="0.0.0.0:3000" sam local start-api 
comes back with the same error.

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


Re: Best practise for passing time as arguments

2017-10-14 Thread Marko Rauhamaa
Andrew Z :

>  I wonder what are the "best practises" for passing "time" parameters to
> functions?
> I noticed that sometimes i pass "time" as a str and then start "massaging"
> it into delta or i need this time format or that format. Thats quite
> annoying and inconsistent.

I do the same thing. It's not all that bad because the choice depends on
the needs of the application.

It's a slight bit annoying that I have to write parsing functions
myself, but it's not all that bad:

   def parse_date(date):
   return datetime.date(*map(int, date.split("-")))

   def parse_time(time):
   return datetime.time(*map(int, time.split(":")))

where "date" is expressed as "2017-10-14" and "time" [of day] as "19:39".


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


Re: Python 2 -> 3, urllib.urlopen (corrected the case)

2017-10-14 Thread Irv Kalb

> On Oct 13, 2017, at 3:27 PM, Irv Kalb  wrot
> If I take the same program and just modify the print statement to add 
> parentheses, then try to run it in Python 3.6 (on a Mac):
> 
> ...
> import urllib
> 
> # set the Yahoo finance url, set stock name, ask for last price
> fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'
> 
> # read all the data
> response = urllib.urlopen(fullURLWithParameters).read()
> 
> print('Response is: ', response)
> 
> I get the following:
> 
> Traceback (most recent call last):
>  File "   s/StockQuoteYahooAPIMinimal.py", line 9, in 
>response = urllib.urlopen(fullURLWithParameters).read()
> AttributeError: module 'urllib' has no attribute 'urlopen'
> 
> 

Thanks for the responses, but I still can't get it to work correctly.  With 
MRAB's suggestion, I've modified the code to be:

from urllib import request

# set the Yahoo finance url, set stock name, ask for last price
fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'

# read all the data
response = request.urlopen(fullURLWithParameters).read()

print('Response is: ', response)


But when I run that (Mac Python 3.6.1), I get:


Traceback (most recent call last):
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 1026, in _send_output
self.send(msg)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 964, in send
self.connect()
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 1400, in connect
server_hostname=server_hostname)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 
401, in wrap_socket
_context=self, _session=session)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 
808, in __init__
self.do_handshake()
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 
1061, in do_handshake
self._sslobj.do_handshake()
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 
683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 
(_ssl.c:749)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Python3 Intro Class/Module 9 - Dictionaries & Internet (not 
finished)/Module 9 Files/StockQuoteYahooAPIMinimal.py", line 9, in 
response = request.urlopen(fullURLWithParameters).read()
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 223, in urlopen
return opener.open(url, data, timeout)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 532, in open
response = meth(req, response)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 642, in http_response
'http', request, response, code, msg, hdrs)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 564, in error
result = self._call_chain(*args)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 504, in _call_chain
result = func(*args)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 756, in http_error_302
return self.parent.open(new, timeout=req.timeout)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 526, in open
response = self._open(req, data)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 544, in _open
'_open', req)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 504, in _call_chain
result = func(*args)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 1320, in do_open
raise URLError(err)
urllib.error

Re: Best practise for passing time as arguments

2017-10-14 Thread Thomas Jollans
On 14/10/17 19:34, Stefan Ram wrote:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>> a post. Use whatever is appropriate in the special case
>> given, or - to write a general library -, learn the design
>> of a good existing library, like Time4J, first.
> 
>   Though in many cases, an ISO 8601 time string 
>   represented by a (named )Python tuple should
>   be sufficient for a time stamp.
> 
>   E.g., ( year, month, day, hour, minute, seconds,
>   zone_offset ).
> 

Python provides a datetime (also: date, time, timedelta) type. Use it.

https://docs.python.org/3/library/datetime.html

When working with time zones, the standard library needs a little help.
Luckily, there's a module for that. https://pypi.python.org/pypi/pytz

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


Re: Best practise for passing time as arguments

2017-10-14 Thread Marko Rauhamaa
r...@zedat.fu-berlin.de (Stefan Ram):

>   Of course, you (the OP), should check out
>
> datetime.datetime
>
>   and
>
> datetime.timedelta
>
>   from the Python Library.

which he mentioned in his post.


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


Re: Python 2 -> 3, urllib.urlopen (corrected the case)

2017-10-14 Thread MRAB

On 2017-10-14 18:40, Irv Kalb wrote:



On Oct 13, 2017, at 3:27 PM, Irv Kalb  wrot
If I take the same program and just modify the print statement to add 
parentheses, then try to run it in Python 3.6 (on a Mac):

...
import urllib

# set the Yahoo finance url, set stock name, ask for last price
fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'

# read all the data
response = urllib.urlopen(fullURLWithParameters).read()

print('Response is: ', response)

I get the following:

Traceback (most recent call last):
 File "   s/StockQuoteYahooAPIMinimal.py", line 9, in 
   response = urllib.urlopen(fullURLWithParameters).read()
AttributeError: module 'urllib' has no attribute 'urlopen'




Thanks for the responses, but I still can't get it to work correctly.  With 
MRAB's suggestion, I've modified the code to be:

from urllib import request

# set the Yahoo finance url, set stock name, ask for last price
fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'

# read all the data
response = request.urlopen(fullURLWithParameters).read()

print('Response is: ', response)


But when I run that (Mac Python 3.6.1), I get:


Traceback (most recent call last):
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 1318, in do_open
 encode_chunked=req.has_header('Transfer-encoding'))
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 1239, in request
 self._send_request(method, url, body, headers, encode_chunked)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 1285, in _send_request
 self.endheaders(body, encode_chunked=encode_chunked)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 1234, in endheaders
 self._send_output(message_body, encode_chunked=encode_chunked)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 1026, in _send_output
 self.send(msg)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 964, in send
 self.connect()
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py",
 line 1400, in connect
 server_hostname=server_hostname)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 
401, in wrap_socket
 _context=self, _session=session)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 
808, in __init__
 self.do_handshake()
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 
1061, in do_handshake
 self._sslobj.do_handshake()
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 
683, in do_handshake
 self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 
(_ssl.c:749)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
   File "/Python3 Intro Class/Module 9 - Dictionaries & Internet (not finished)/Module 9 
Files/StockQuoteYahooAPIMinimal.py", line 9, in 
 response = request.urlopen(fullURLWithParameters).read()
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 223, in urlopen
 return opener.open(url, data, timeout)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 532, in open
 response = meth(req, response)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 642, in http_response
 'http', request, response, code, msg, hdrs)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 564, in error
 result = self._call_chain(*args)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 504, in _call_chain
 result = func(*args)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 756, in http_error_302
 return self.parent.open(new, timeout=req.timeout)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 526, in open
 response = self._open(req, data)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 544, in _open
 '_open', req)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 504, in _call_chain
 result = func(*args)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 1361, in https_open
 context=self._context, check_hostname=self._check_hostname)
   File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py",
 line 1320, in do_o

Re: Best practise for passing time as arguments

2017-10-14 Thread Marko Rauhamaa
Thomas Jollans :

> When working with time zones, the standard library needs a little help.
> Luckily, there's a module for that. https://pypi.python.org/pypi/pytz

Even better:

   sudo dnf install python3-pytz


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


Re: Python 2 -> 3, urllib.urlopen (corrected the case)

2017-10-14 Thread Ben Bacarisse
Irv Kalb  writes:

Lots of detail snipped.  I hope it won't matter...

>  (_ssl.c:749)>
>
> Huh???
>
> I've read a bunch of documentation, and it looks like I'm doing
> everything right, but I cannot get this to work.  Any other
> suggestions to get this 3 line program to work correctly?

Just a data point...  It works here:

$ python3 t.py
Response is:  b'156.99\n'
$ cat t.py
import urllib.request
fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'
# read all the data
response = urllib.request.urlopen(fullURLWithParameters).read()

print('Response is: ', response)
$ python3 --version
Python 3.5.2

Maybe you are missing some crucial certificates?  Presumably Python
finds them is standard paces, so it would be worth trying other accesses
of the URL.  For example, here:

$ wget -q -O - 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1' 
156.99

Finally, wget -S shows that the resource has moved.  It is now at

  Location: http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1

I don't think this has anything to do with your problem, but it's worth
noting.

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


Re: Best practise for passing time as arguments

2017-10-14 Thread Chris Angelico
On Sun, Oct 15, 2017 at 5:20 AM, Marko Rauhamaa  wrote:
> Thomas Jollans :
>
>> When working with time zones, the standard library needs a little help.
>> Luckily, there's a module for that. https://pypi.python.org/pypi/pytz
>
> Even better:
>
>sudo dnf install python3-pytz

How is that better? It's the same thing, packaged differently, and
thus only available on Red Hat-family systems, and depends on the
update cycle of your OS.

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


Re: Python 2 -> 3, urllib.urlOpen

2017-10-14 Thread Mark Lawrence via Python-list

On 13/10/17 23:27, Irv Kalb wrote:

One of the colleges where I teach has just moved from Python 2 to Python 3.  I am in 
the process of converting my beginning Python class from Python 2 to Python 3.  
Everything has gone smoothly, until I just tried to convert some code that imports 
and uses urllib.urlOpen to fetch data through an API.  I am using an API that I found 
here:http://www.jarloo.com/yahoo_finance/ 


As a minimal example, I am trying to get the latest stock price for Apple.

The following example works perfectly in Python 2:

import urllib

# set the Yahoo finance url, set stock name, ask for last price
fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'

# read all the data
response = urllib.urlopen(fullURLWithParameters).read()

print 'Response is: ', response

This is asking for a stock name (s=) and I am adding in aapl as a stock symbol.  I am 
also adding a "flag" parameter (f=) and setting it to l1 to get the last trade 
price.  When I run this in Python 2, I see:

Response is:  156.99


If I take the same program and just modify the print statement to add 
parentheses, then try to run it in Python 3.6 (on a Mac):


import urllib

# set the Yahoo finance url, set stock name, ask for last price
fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'

# read all the data
response = urllib.urlopen(fullURLWithParameters).read()

print('Response is: ', response)

I get the following:

Traceback (most recent call last):
   File "   s/StockQuoteYahooAPIMinimal.py", line 9, in 
 response = urllib.urlopen(fullURLWithParameters).read()
AttributeError: module 'urllib' has no attribute 'urlopen'


I've looked at the Python 3.6 documentation for urllib, and I see that certain 
calls have been changed and others have been eliminated.  But my eyes glaze 
over trying to figure out what to use instead.

My question is: Is there a simple (hopefully one or two line) replacement for my call 
to url lib.urlopen().read()

I know that there are other modules out there that handle requests (like the 
Requests module), but this is a strictly controlled university environment.  I 
cannot download any external packages (other then pygame, which I got special 
permission for) onto the computers in the school.  Therefore, I'm looking for 
something in the Python 3.6 Standard Library.

Thanks in advance,

Irv



Hopefully this https://docs.python.org/3/howto/pyporting.html will help.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Best practise for passing time as arguments

2017-10-14 Thread Marko Rauhamaa
Chris Angelico :

> On Sun, Oct 15, 2017 at 5:20 AM, Marko Rauhamaa  wrote:
>> Even better:
>>
>>sudo dnf install python3-pytz
>
> How is that better? It's the same thing, packaged differently, and
> thus only available on Red Hat-family systems, and depends on the
> update cycle of your OS.

Use the native updater your distro.

Several nice things follow from the OS packaging:

 * You don't have to have *two* separate security update/bug fix
   streams. Once you've added pytz to your OS package collection, you'll
   get updates with the routine OS updates.

 * You have the benefit of a major outside entity vetting your packages.
   PyPI doesn't have any such oversight: https://arstechnica.com/in
   formation-technology/2017/09/devs-unknowingly-use-malicious-modules-pu
   t-into-official-python-repository/>.

   (Of course, one shouldn't overestimate the security of
   volunteer-maintained distros, either, but PyPI allows anybody to
   submit any junk they want.)

 * If you want to release your software to others, your third-party
   dependency statement becomes more concise and possible more
   acceptable to your customer. Also, you don't have to ship the
   third-party package yourself.

   Your customer likely knows how to update native distro packages, but
   may not be familiar with Python and its ecosystem. Depending only on
   the distro relieves you from educating your customer about PyPI.


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


Re: Best practise for passing time as arguments

2017-10-14 Thread Chris Angelico
On Sun, Oct 15, 2017 at 7:57 AM, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> On Sun, Oct 15, 2017 at 5:20 AM, Marko Rauhamaa  wrote:
>>> Even better:
>>>
>>>sudo dnf install python3-pytz
>>
>> How is that better? It's the same thing, packaged differently, and
>> thus only available on Red Hat-family systems, and depends on the
>> update cycle of your OS.
>
> Use the native updater your distro.
>
> Several nice things follow from the OS packaging:
>
>  * You don't have to have *two* separate security update/bug fix
>streams. Once you've added pytz to your OS package collection, you'll
>get updates with the routine OS updates.
>
>  * You have the benefit of a major outside entity vetting your packages.
>PyPI doesn't have any such oversight: https://arstechnica.com/in
>formation-technology/2017/09/devs-unknowingly-use-malicious-modules-pu
>t-into-official-python-repository/>.
>
>(Of course, one shouldn't overestimate the security of
>volunteer-maintained distros, either, but PyPI allows anybody to
>submit any junk they want.)
>
>  * If you want to release your software to others, your third-party
>dependency statement becomes more concise and possible more
>acceptable to your customer. Also, you don't have to ship the
>third-party package yourself.
>
>Your customer likely knows how to update native distro packages, but
>may not be familiar with Python and its ecosystem. Depending only on
>the distro relieves you from educating your customer about PyPI.

* You get into the habit of posting distro-specific (not just
OS-specific) commands to global mailing lists.

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


Re: Best practise for passing time as arguments

2017-10-14 Thread Marko Rauhamaa
Chris Angelico :

> * You get into the habit of posting distro-specific (not just
> OS-specific) commands to global mailing lists.

And? I don't mind you posting the instructions for any other Linux
distro. Chances are the translation into my distro is somewhat obvious.
At least it would encourage me to find out.

In no way would I be annoyed by equivalent instructions for alternative
operating systems such as OSX or Windows (assuming Python and the
relevant packages are available on those operating systems, which I have
no knowledge of).


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


Re: Best practise for passing time as arguments

2017-10-14 Thread Chris Angelico
On Sun, Oct 15, 2017 at 8:15 AM, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> * You get into the habit of posting distro-specific (not just
>> OS-specific) commands to global mailing lists.
>
> And? I don't mind you posting the instructions for any other Linux
> distro. Chances are the translation into my distro is somewhat obvious.
> At least it would encourage me to find out.
>
> In no way would I be annoyed by equivalent instructions for alternative
> operating systems such as OSX or Windows (assuming Python and the
> relevant packages are available on those operating systems, which I have
> no knowledge of).

Or, you could just post a link to PyPI, which applies to all platforms
at once, and let people work out their own platform-specific
alternatives for themselves. Oh hey, that's what Thomas already did.

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


Re: Best practise for passing time as arguments

2017-10-14 Thread Christopher Reimer
On Oct 14, 2017, at 10:44 AM, Thomas Jollans  wrote:
> 
>> On 14/10/17 19:34, Stefan Ram wrote:
>> r...@zedat.fu-berlin.de (Stefan Ram) writes:
>>> a post. Use whatever is appropriate in the special case
>>> given, or - to write a general library -, learn the design
>>> of a good existing library, like Time4J, first.
>> 
>>  Though in many cases, an ISO 8601 time string 
>>  represented by a (named )Python tuple should
>>  be sufficient for a time stamp.
>> 
>>  E.g., ( year, month, day, hour, minute, seconds,
>>  zone_offset ).
>> 
> 
> Python provides a datetime (also: date, time, timedelta) type. Use it.
> 
> https://docs.python.org/3/library/datetime.html
> 
> When working with time zones, the standard library needs a little help.
> Luckily, there's a module for that. https://pypi.python.org/pypi/pytz
> 
> -- Thomas
> -- 
> https://mail.python.org/mailman/listinfo/python-list

I wrote a blog post about muddling through the timestamp problem, showing 
examples for datetime, slice-and-dice text, and pytz. Since I was dealing with 
time zone-specific timestamps, I went with pytz in the end.

https://www.kickingthebitbucket.com/2017/04/04/the-python-time-zone-rabbit-hole/

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


Re: Python 2 -> 3, urllib.urlopen (corrected the case)

2017-10-14 Thread Irv Kalb
Thank you!

> On Oct 14, 2017, at 12:10 PM, Ben Bacarisse  wrote:
> 
> Irv Kalb  writes:
> 
> Lots of detail snipped.  I hope it won't matter...
> 
>> > (_ssl.c:749)>
>> 
>> Huh???
>> 
>> I've read a bunch of documentation, and it looks like I'm doing
>> everything right, but I cannot get this to work.  Any other
>> suggestions to get this 3 line program to work correctly?
> 
> Just a data point...  It works here:
> 
> $ python3 t.py
> Response is:  b'156.99\n'
> $ cat t.py
> import urllib.request
> fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'
> # read all the data
> response = urllib.request.urlopen(fullURLWithParameters).read()
> 
> print('Response is: ', response)
> $ python3 --version
> Python 3.5.2
> 

I have not tried this on anything but my Mac.  I'm running 3.6.1

> Maybe you are missing some crucial certificates?  Presumably Python
> finds them is standard paces, so it would be worth trying other accesses
> of the URL.  

I am just using an absolutely standard install from Python.org

> For example, here:
> 
> $ wget -q -O - 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1' 
> 156.99
> 
> Finally, wget -S shows that the resource has moved.  It is now at
> 
>  Location: http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1
> 
> I don't think this has anything to do with your problem, but it's worth
> noting.
> 
> -- 
> Ben.
> 

That DID fix it.  I changed the URL to add 'download/' and it worked perfectly.

Apparently, Python 3 differs from Python 2 in the way that it is handling a 
missing/forwarding URL, because the original code in Python 2.7 works perfectly.

Thanks very much for tracking this down!

Irv

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


Re: Python 2 -> 3, urllib.urlopen (corrected the case)

2017-10-14 Thread Ben Bacarisse
Irv Kalb  writes:

> Thank you!

You're welcome.


>> Just a data point...  It works here:
>> 
>> $ python3 t.py
>> Response is:  b'156.99\n'
>> $ cat t.py
>> import urllib.request
>> fullURLWithParameters = 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'
>> # read all the data
>> response = urllib.request.urlopen(fullURLWithParameters).read()
>> 
>> print('Response is: ', response)
>> $ python3 --version
>> Python 3.5.2
>
> I have not tried this on anything but my Mac.  I'm running 3.6.1

>> For example, here:
>> 
>> $ wget -q -O - 'http://finance.yahoo.com/d/quotes.csv?s=aapl&f=l1' 
>> 156.99
>> 
>> Finally, wget -S shows that the resource has moved.  It is now at
>> 
>>  Location: http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1
>> 
>> I don't think this has anything to do with your problem, but it's worth
>> noting.
>
> That DID fix it.  I changed the URL to add 'download/' and it worked
> perfectly.

That's... interesting.

> Apparently, Python 3 differs from Python 2 in the way that it is
> handling a missing/forwarding URL, because the original code in Python
> 2.7 works perfectly.

Python 3 works for me.  I still suspect it's some system difference
rather than being, say, a 3.6.1 vs 3.5.2 difference.  What happens if
you change the URL to use https rather than http?

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


Re: An endless loop

2017-10-14 Thread Steve D'Aprano
On Sun, 15 Oct 2017 01:43 pm, Dennis Lee Bieber wrote:

> On 15 Oct 2017 02:10:15 GMT, r...@zedat.fu-berlin.de (Stefan Ram) declaimed
> the following:
[...]
>>def poly( n, length ):
>>i = 0
>>while i < n:
>>forward( length )
>>left( 360/n )
>>
> 
> A clear example of why a pre-determined loop is better using "for" then
> emulated with a non-deterministic "while".
> 
> for i in range(n):
> 
> avoids having to write separate initialization, test, and increment
> statements.

This, a thousand times this.



I'm reminded of an old joke:

A mathematician, a physicist, an engineer and a computer programmer are
discussing prime numbers and whether or not every odd number is prime.

The mathematician says "3 is prime, 5 is prime, 7 is prime. So by induction,
all odd numbers must be prime."

The physicist says "3 is prime, 5 is prime, 7 is prime, 9 is an experimental
error, 11 is prime, 13 is prime... within 83% confidence limits, all odd
numbers are prime."

The engineer says "3 is prime, 5 is prime, 7 is prime, for safety we better
treat 9 as prime, 11 is prime..."

The computer programmer says "Listen you guys, you're all doing it wrong. I've
written a program to check for primes, it says: 1 is prime, 1 is prime, 1 is
prime, 1 is prime ..."





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