Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Paul Rubin
Rustom Mody  writes:
> eg haskell (ghc) is written in ghc
> Where did the first bootstrap start from?

The very earliest Haskell implementation was written in Lisp.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Paul Rubin
BartC  writes:
>  But my suggestion was to have required a keyword in front of
> such expressions.

Should there be a keyword in front of a line containing "sqrt(x)" ?
What about "launch(missiles)" ?

The compiler can't tell which of those expressions has a side effect.
The first might be buggy code but the second is idiomatic.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: help with program

2016-03-26 Thread Terry Reedy

On 3/26/2016 6:48 PM, Chris Angelico wrote:

On Sun, Mar 27, 2016 at 7:38 AM, Jerry Martens
 wrote:

hi im trying to run this program and it opens a screen really ast
and closes it faster withou any results.



There are a few ways you could do this. One is to run it from the
command line. Another is to put this line at the end of the program:

input("Press enter to exit. ")


For a tkinter program, use 'root.mainloop()' instead, where root is
usually an instance of tkinter.Tk.


That should bring up the same screen (called a "console") and then
have it wait until you're done reading it.


If at a terminal, 'python -i file.py' not only keeps the program open, 
but brings up an interactive prompt so you can interact with the 
program.  This is useful for development.



A third way is to edit your code using Idle, and run it from there.


IDLE emulates 'python -i file-in-editor.py'


I haven't done that in a while, though, so the details might have
changed in the recent versions.


Still F5 or the menu entry.

--
Terry Jan Reedy

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


Re: Threading is foobared?

2016-03-26 Thread Random832
On Sat, Mar 26, 2016, at 23:18, Ben Finney wrote:
> What you've demonstrated is that at least one host is violating
> communication standards by altering existing reference fields on
> messages in transit.

The usenet gateway relays posts that originated on the mailing list to
usenet with their *Message-ID* replaced wholesale with
"" - 90% of the time when I've traced
a broken thread this has been to blame, and I've complained at least
twice of this before, once not two weeks ago.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Paul Rubin
Steven D'Aprano  writes:
> For example, would you consider that this isolated C code is
> "meaningless"?
> int i = n + 1;

It's meaningful as long as n is in a certain range of values so there's
no overflow.

> But according to the standard, it's "meaningless", since it might
> overflow, and signed int overflow is Undefined Behaviour.

No it's not meaningless if it "might" overflow, it's meaningless if it
-does- overflow, so the compiler can do whatever it wants in that case.
The compiler is only obliged to do anything specific in the case where
there is no overflow, so if it can get some speedups by only generating
code for the non-overflow case, it does so:

http://kristerw.blogspot.com/2016/02/how-undefined-signed-overflow-enables.html

> Compilers are well known for only doing what you tell them to do, not what
> you want them to do. But in the case of C and C++ they don't even do what
> you tell them to do.

They do what you tell them, not what you meant to tell them or what you
thought you were telling them.  That goes way back before compilers and
computers.  Think of all the stories about a guy rubbing lamps and
getting three wishes.  Srsly though, the conclusion is that C and C++
are terrible languages if you want to code anything really solid, not
that the compilers are doing anything bad.  Unfortunately there's a
mountain of legacy code full of such errors, and still a lot of C
programmers out there who don't understand the issue.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Rustom Mody
On Sunday, March 27, 2016 at 10:32:34 AM UTC+5:30, Rustom Mody wrote:
> I had an impression of seeing some discussion on this and resolved not
> to incorporate.

Meaning: I think I remember something about a resolution -- after some debate
-- not to OO-ify the C/Unix errno system
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-26 Thread Paul Rubin
beliav...@aol.com writes:
> yy = list(chain.from_iterable([list(repeat(aa,nrep)) for aa in xx]))

The chain approach seems more natural to me:

  yy = list(chain.from_iterable(map(lambda x: [x,x], xx)))

may make the doubling more obvious, and in Python 3 it should avoid the
intermediate lists since map creates a generator.  Depending on the
usage, you might also not need the outermost list, making yy a lazy
generator as well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Another Key Binding Question

2016-03-26 Thread Wildman via Python-list
On Sat, 26 Mar 2016 17:47:02 +, MRAB wrote:

> On 2016-03-26 17:10, Wildman via Python-list wrote:
>> I use some key bindings in my program.  They are declared
>> like this:
>>
>>  root.bind("" + "q", quit)
>>  root.bind("" + "q", quit)
>>  root.bind("" + "Q", quit)
>>  root.bind("" + "Q", quit)
>>
>> The above binds both Alt keys with upper and lower case 'q'.
>> Is there a way to combine the statements above into one
>> statement?
>>
> Try this:
> 
>  root.bind("", quit)
>  root.bind("", quit)
> 
> The first is for either "Alt" key plus the "Q" key and Caps Lock turned off.

Works perfectly.

> The second is for either "Alt" key plus the "Q" key and Caps Lock turned on.

Also works, however, I discovered if I leave out 'Lock' it
still works with caps on.  It also works with caps off while
holding either Shift key and hitting Alt-q.  I tested it with
Python 2.7 and 3.4.

Well at least I can cut the number of lines down to two per
binding like this:

root.bind("", quit)
root.bind("", quit)

Once again I am in your debt.  Thank you.

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Rustom Mody
On Sunday, March 27, 2016 at 2:15:22 AM UTC+5:30, Terry Reedy wrote:
> On 3/26/2016 1:43 PM, Rustom Mody wrote:
> 
> > There is this nice piece of OO called the exception hierarchy:
> 
>  > https://docs.python.org/2/library/exceptions.html#exception-hierarchy
> 
> https://docs.python.org/3/library/exceptions.html#exception-hierarchy
> 
> > BaseException ⊇ Exception ⊇ EnvironmentError ⊇ IOError
> 
> BaseException ⊇ Exception ⊇ ⊇ OSError
> 
> > At this point it would have been completely natural for IOError to continue
> > subclassing to all the typical errors
> > - File not found
> > - No Space left on device
> 
> Which is why we now have
> 
>+-- OSError
>|+-- BlockingIOError
>|+-- ChildProcessError
>|+-- ConnectionError
>||+-- BrokenPipeError
>||+-- ConnectionAbortedError
>||+-- ConnectionRefusedError
>||+-- ConnectionResetError
>|+-- FileExistsError
>|+-- FileNotFoundError
>|+-- InterruptedError
>|+-- IsADirectoryError
>|+-- NotADirectoryError
>|+-- PermissionError
>|+-- ProcessLookupError
>|+-- TimeoutError
> 
> 'no space' is MemoryError, but that is a hardward, not OS matter.
> 
> > But instead we have an integer errno and we must inquire what that is to
> > figure out what the exact IOError was
> 
> This statement is obsolete, but explains why the above was added in 3.3.

Thanks Terry for the correction
I had an impression of seeing some discussion on this and resolved not
to incorporate.
Glad to be wrong on that
However my general point is hardly about errno but about the lineage/legacy
of python.
And this is only strengthened by your correction
Thanks to American politics being in the air I learnt a new word the other day:
'birther'.
My point is python is 'birthed' in Unix-land
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Chris Angelico
On Sun, Mar 27, 2016 at 3:05 PM, Gregory Ewing
 wrote:
> Gene Heskett wrote:
>>
>> But I learned a lot about hot ($2400F) iron too.
>
>
> 2400 dollars farenheit? That's an intriguing unit...
>
> Or is it meant to be the temperature in hex?

Hex, obviously. Which is something like five thousand Kelvin, in decimal.

Yeah that's hot.

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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Gregory Ewing

Gene Heskett wrote:

But I learned a lot about hot ($2400F) iron too.


2400 dollars farenheit? That's an intriguing unit...

Or is it meant to be the temperature in hex?

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


Re: setup

2016-03-26 Thread eryk sun
On Sat, Mar 26, 2016 at 6:20 PM, Joel Goldstick
 wrote:
> I'm guessing you are on windows and you could google the error code, but
> also search the list because this question has been asked and answered I
> believe

A little knowledge helps. An upper word of 0x8007 indicates a COM
HRESULT error (0x8000) that originated as a Windows error (facility
7). Se we know that the lower word value of 0x0570 is a common Windows
error code that can be found in the following list:

https://msdn.microsoft.com/en-us/library/ms681381

You'll find that it's ERROR_FILE_CORRUPT, i.e. the file or directory
is corrupted and unreadable. The most likely cause is a bad download.
I wonder whether the OP used the web installer, which downloads
components as required. If there's something dubious about the way it
downloads from python.org, that would explain the relative frequency
of this error for 3.5 installs.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Interpretation

2016-03-26 Thread Steven D'Aprano
On Sat, 26 Mar 2016 03:33 am, Dennis Ngeno wrote:

> My programs have never combile, they keep telling me , systax error even
> after copy pasting

Dennis, if Python is complaining that you have a SyntaxError, it means you
have written something which the interpreter cannot understand. We cannot
possibly tell what you have done wrong if you don't show us what you wrote,
and what the error message says.


SyntaxError can mean many different errors, for example:


- you have misspelled a keyword (e.g. "dfe" instead of "def", "clas" instead
of "class", "ipmort" instead of "import");


- you tried to use a keyword as a variable (e.g. "class = 23");

- you have not indented a code block correctly, e.g. inconsistent
indentation in a single code block:

def function():
print(1)  # four spaces indent
print(2)  # eight spaces! this is inconsistent
  print(3)  # now two spaces!


or forgetting to indent a code block:

def function():
print(1)  # no indentation at all


If you mix spaces and tabs, Python can sometimes get confused about the
indentation, so you should always use *only* spaces or *only* tabs, never
both in the same block.


- you have too many, or too few, brackets and parentheses, or they are in
the wrong place, e.g.:

def function():
result = math.sin(1.245  # oops, forgot the closing parenthesis
return result + 1


Errors with brackets and parentheses can be the most annoying ones, because
sometimes Python cannot tell that there is an error until the line *after*
where the error is. So in this case, it will say that there's a SyntaxError
in the last line, "return result + 1", when the real error is in the
previous line.

SyntaxError tells you that your code is written wrongly and Python doesn't
understand what you mean. You have to look at the code and fix the syntax
problem. If you show us the line of code that Python is complaining about,
and maybe the line before it, we can help.




-- 
Steven

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


Re: Interpretation

2016-03-26 Thread Steven D'Aprano
On Sun, 27 Mar 2016 02:22 pm, Mario R. Osorio wrote:

> OTOH, python code is not supposed to be compiled.

Technically, Python code is compiled, to byte-code rather than machine-code,
but still compiled.

That's what is inside the .pyc files you will often see after importing
modules. And Python even has a built-in function called "compile" that
takes source code and compiles it a code object:

py> x = compile("value = 23", "", "single")
py> type(x)

py> print(x)
 at 0xb7993300, file "", line 1>
py> eval(x)
py> print(value)
23



-- 
Steven

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


Re: Interpretation

2016-03-26 Thread Ben Finney
"Mario R. Osorio"  writes:

> On Saturday, March 26, 2016 at 5:59:04 AM UTC-4, Dennis Ngeno wrote:
> > My programs have never combile, they keep telling me , systax error even
> > after copy pasting
>
> No pun intended, but I hope you are not typing your code like you
> typed your message.

Many people don't have English as a first language, or are otherwise
impaired from typing English text.

The issue is important though, Dennis: communication is at the core of
programming. You'll need to take care with what you write in your code,
and in your messages; both are communications and clear writing is very
helpful.

> OTOH, python code is not supposed to be compiled.

That's simply untrue: Python code is compiled every day on countless
machines. It is compiled to various formats, but the process is none the
less compilation.

Don't make the mistake of a narrow definition of “compile” which is
unhelpful in modern languages like Python.

> Another tip: If you really are copying and pasting, I'd recommend you
> first paste the code to the text editor of your like and MAKE SURE YOU
> ARE NOT MIXING SPACES AND TAB CHARACTERS FOR INDENTATION PURPOSES.

Dennis, you should choose a text editor that handles program code well.
A “word processor” program makes different trade-offs, altering text in
a way that is not helpful for writing program code.

For an overview of the range of programmer's text editors, see
https://wiki.python.org/moin/PythonEditors>. To start with you can
use the “IDLE” development environment that comes installed with Python.

-- 
 \  “Puritanism: The haunting fear that someone, somewhere, may be |
  `\ happy.” —Henry L. Mencken |
_o__)  |
Ben Finney

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


Re: How to make Python interpreter a little more strict?

2016-03-26 Thread Steven D'Aprano
On Sun, 27 Mar 2016 10:30 am, John Pote wrote:

> So intrigued by this question I tried the following
> def fnc( n ):
>  print "fnc called with parameter '%d'" % n
>  return n
> 
> for i in range(0,5):
>  if i%2 == 0:
>  fnc
>  next
>  print i
> 
> and got the same result as the OP

In this case, the two lines "fnc" and "next" simply look up the function
names, but without actually calling them. They're not quite "no-ops", since
they can fail and raise NameError if the name doesn't exist, but otherwise
they might as well be no-ops.


> A couple of tests showed that the only important thing about the name in
> the if clause is that it is known at runtime and then it is silently
> ignored.

Right. What actually happens is that Python evaluates the expression,
generates the result, and then if that result isn't used, a microsecond
later the garbage collector deletes it. In this case, the expression
consists of only a single name: "fnc", or "next".

If you have a more complex expression, Python can do significant work before
throwing it away:

[x**3 for x in range(1)]


generates a list of cubed numbers [0, 1, 8, 27, ...]. Then the garbage
collector sees that nothing refers to that list, and it is available to be
deleted, so it deletes it.

Why does Python bother generating the list only to throw it away a
microsecond later? Because the interpreter can't easily tell if the
calculations will have any side-effects. It might turn out that something
in the expression ends up setting a global variable, or printing output, or
writing to a file, or who knows what?

Now, you and I can read the line and see that (assuming range hasn't been
overridden) there are no side-effects from calculating cubes of numbers.
But the Python interpreter is very simple-minded and not as smart as you or
I, so it can't tell, and so it plays it safe and does the calculations just
in case. Future versions of the interpreter may be smarter.

In cases where Python *can* tell that there are no side-effects, it may
ignore stand-alone expressions that don't do anything useful.


> However, if the name is not known/accessible at run time a 'NameError'
> is raised,
> NameError: name 'mynewfn123' is not defined

Correct.



> On the other hand the following if clause
>  if i%2 == 0:
>  fncnext
> 
> results in a compiler error,
> D:\projects\python
>  >>python next.py
>File "next.py", line 9
>  fnc next
> ^
> SyntaxError: invalid syntax
> 
> This is all for Python 2.7.9. (Don't know about Python 3).

Python 3 will be more-or-less the same. Python 3 might be a bit smarter
about recognising expressions that have no side-effects and that can be
ignored, but not much more.


> So I have sympathy with the OP, I would expect the compiler to pick this
> up - indeed it does so for two (or more ?) unused names on a single
> line. That is unless someone can give a useful use of this behaviour or
> is there something going on under the Python hood I'm not aware of?

In Python, variables AND FUNCTIONS are created dynamically, and can be
deleted or created as needed. So Python doesn't know if your function "fnc"
actually exists or not until runtime. Just because you defined it using def
doesn't mean that it will still be around later: maybe you have called:

del fnc

or possibly reassigned the variable:

fnc = "Surprise! Not a function any more!"

So the compiler can't tell whether 

fnc

is a legal line or not. Maybe fnc exists, maybe it doesn't, it will have to
actually evaluate the expression to find out, and that happens at runtime.

But the compiler can recognise syntax errors:

fnc next

is illegal syntax, as are:

1234fnc
fnc?
x = ) (

and for those, you will get an immediate SyntaxError before the code starts
running.


> It would be all to easy to write a series of lines just calling
> functions and forget the () on one of them. Not fun programming.

In theory, you are correct. But in practice, it's not really as big a
problem as you might think. Very, very few functions take no arguments.
There is this one:

import random
r = random.random  # oops, forgot to call the function

for example, but most functions take at least one argument:

r = random.randint(1, 6)

There are a few functions or methods that you call for their side-effects,
like Pascal "procedures" or C "void functions":

mylist.sort()

and yes, it is annoying when you forget the brackets (round brackets or
parentheses for any Americans reading) and the list doesn't sort, but
that's the exception rather than the rule. And if you're worried about
that, you can run a "linter" which check your source code for such
potential problems.

Google for PyLint, PyFlakes, PyChecker, Jedi, etc if you want more
information about linters, or just ask here. I can't tell you too much
about them, as I don't use them, but somebody will probably answer.





-- 
Steven

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

Re: Interpretation

2016-03-26 Thread Mario R. Osorio
On Saturday, March 26, 2016 at 5:59:04 AM UTC-4, Dennis Ngeno wrote:
> My programs have never combile, they keep telling me , systax error even
> after copy pasting

No pun intended, but I hope you are not typing your code like you typed your 
message.

OTOH, python code is not supposed to be compiled.

Another tip: If you really are copying and pasting, I'd recommend you first 
paste the code to the text editor of your like and MAKE SURE YOU ARE NOT MIXING 
SPACES AND TAB CHARACTERS FOR INDENTATION PURPOSES.

Use either, or but do not mix them, specially not on the same line. IMHO, it is 
best to always use spaces, but some people do prefer tabs.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading is foobared?

2016-03-26 Thread Ben Finney
Steven D'Aprano  writes:

> Am I the only one who has noticed that threading of posts here is
> severely broken? It's always been the case that there have been a few
> posts here and there that break threading, but now it seems to be much
> more common.

I can't give an objective assessment of whether it has increased or to
what extent.

Thanks for pointing out an objective symptom, though: munging of the
message ID values in various fields.

The resulting broken threads are a constant source of annoyance. I don't
know whether any one host is the culprit, or whether there are many
hosts that are munging the message IDs.

What you've demonstrated is that at least one host is violating
communication standards by altering existing reference fields on
messages in transit.

-- 
 \  “It is difficult to get a man to understand something when his |
  `\   salary depends upon his not understanding it.” —Upton Sinclair, |
_o__) 1935 |
Ben Finney

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


Threading is foobared?

2016-03-26 Thread Steven D'Aprano
Am I the only one who has noticed that threading of posts here is severely
broken? It's always been the case that there have been a few posts here and
there that break threading, but now it seems to be much more common.

For instance, I see Jerry Martens' post "help with program". According to my
newsreader, KNode, there are no replies to that thread. But I see a reply
from Chris A. Chris' reply has a header line:

In-Reply-To: <1392737302.749065.1459024715818.javamail.ya...@mail.yahoo.com>

but Jerry's original has:

References:
<1392737302.749065.1459024715818.javamail.yahoo@mail.yahoo.com>

Notice the difference? Here the two values lined up:

<1392737302.749065.1459024715818.javamail.yahoo@mail.yahoo.com>
<1392737302.749065.1459024715818.javamail.ya...@mail.yahoo.com>



-- 
Steven

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


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Chris Angelico
On Sun, Mar 27, 2016 at 1:44 PM, Steven D'Aprano  wrote:
> If [anyone] takes over the world and bans C, insisting that it be
> replaced with a new language of his own design called "T", the
> *implementation* of CPython would have to change, but the *interface*, the
> language itself, won't have to change one iota.

Nah. We'd just be rebels and rename "gcc" to "t" and keep right on going :)

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


Re: help with program

2016-03-26 Thread Steven D'Aprano
On Sun, 27 Mar 2016 07:38 am, Jerry Martens wrote:

> hi im trying to run this program and it opens a screen really ast and
> closes it faster withou any results. 

Put this at the very end of your program:

# Python 2 version
raw_input('Press the Enter key to exit... ')


# Python 3 version
input('Press the Enter key to exit... ')


That will halt and wait for you to press the exit key before closing the
window.



-- 
Steven

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


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Steven D'Aprano
On Sun, 27 Mar 2016 04:43 am, Rustom Mody wrote:

> On Saturday, March 26, 2016 at 4:09:41 PM UTC+5:30, Steven D'Aprano wrote:
>> On Sat, 26 Mar 2016 04:30 pm, Rustom Mody wrote:
>> 
>> > For one thing its good to remember that we wouldn't be here without
>> > python Python wouldn't be what it is without CPython
>> 
>> There is nothing about Python that relies on the C standard being as it
>> is.
> 
> Um lets see...
> There is this nice piece of OO called the exception hierarchy:
> https://docs.python.org/2/library/exceptions.html#exception-hierarchy
> 
> So we have
> BaseException ⊇ Exception ⊇ EnvironmentError ⊇ IOError
> At this point it would have been completely natural for IOError to
> continue subclassing to all the typical errors
> - File not found
> - No Space left on device
> etc etc

You cannot possibly be serious. Are you *really* trying to argue that it is
because of the C standard that the Python exception hierarchy isn't
sufficiently nuanced for your taste?

The air conditioner in my car struggles on hot days. The compressor of the
air condition was designed by an engineer using software running on a
computer running Windows. Windows is written in C or C++. Therefore the C
standard is responsible for my car being hot.

In any case, you might like to consider the Python 3 exception hierarchy
before trying to defend your proposition:

https://docs.python.org/3/library/exceptions.html#exception-hierarchy



> But instead we have an integer errno and we must inquire what that is to
> figure out what the exact IOError was
> Are you suggesting that python's errno module:
> https://docs.python.org/2/library/errno.html
> And C's http://man7.org/linux/man-pages/man3/errno.3.html
> are coincidentally related?

Of course it's not a coincidence. The documentation explicitly states that
the names and values of the constants are taken from the C header file
errno.h. So what? If I somehow convince Guido to add a list of standard Go
error codes into the standard library, does that mean that the Python
language is dependent on Go?


>> There are Python implementations that are not written in C or C++:
>> 
>> Jython (Java)
>> IronPython (C# for .Net or Mono)
>> CLPython (Lisp)
>> Berp (Haskell)
> 
> As best as I know
> - Java is written in C
> - Lisp is written in C
> - Haskell is written in C

To my knowledge, all four of Java, C#, Lisp and Haskell are self-hosted
languages. Even if a particular (say) Haskell compiler happens to have been
written in C, it could have been written using Rust, D, Ada, Forth, PL/I, 
Modula 2, Java, Pascal, assembly language, etc. without changing anything
about Haskell.

You could replace "C" with any systems language such as "Fortran", and the
Python language would be absolutely identical. You could even write the C
ABI using Fortran.

(CPython can call Fortran libraries even though it is written in C -- why
couldn't a Fortran implementation call C libraries? There's no reason it
couldn't -- Nim, for example, has a foreign function interface capable of
calling C code even though the compiler was written in Pascal.)

I'm not saying that the amount of effort required would be the same. I'm not
saying that there are no influences in the design and practice of the
Python interpreter due to C -- obviously that would be silly, Guido is a C
programmer, of course he has been influenced by C. But many of those
influences are "Don't do what C does!".

Clearly C is important in the real world, and for practical and historical
reasons Python was written in C. But those reasons aren't fundamental to
the Python language, in the way that compatibility with C is fundamental to
C++. If Donald Trump takes over the world and bans C, insisting that it be
replaced with a new language of his own design called "T", the
*implementation* of CPython would have to change, but the *interface*, the
language itself, won't have to change one iota.


> Notice a certain pattern?
> Yeah some of them may be self-hosting
> eg haskell (ghc) is written in ghc
> Where did the first bootstrap start from?

Where did the first C compiler start from?

C is not some magical language that exists at the very heart of all
programming. Programming existed before it, and even today there are
corners of the computing world which don't rely on C, not even indirectly.
The development of C started in 1969, and it is generally agreed to have
first been more-or-less complete in 1972. The famous K&R C book didn't come
out until 1978, and C wasn't standarized until 1989. There were many years
of high-level computing before C was even a concept in Dennis Richie's
mind. The first Fortran compiler wasn't written in C.

Due to the ubiquity of C in 2016, it may be *convenient* to write your first
compiler for a language in C, but it is not *necessary*. The first Nim
compiler was written in Pascal, and if Nim isn't self-hosting, that doesn't
mean it couldn't be.


[...]
> So... Ahem... C is unsafe... Right... Prefer C++ ??

No, of course n

Re: How to make Python interpreter a little more strict?

2016-03-26 Thread BartC

On 26/03/2016 23:30, John Pote wrote:


So intrigued by this question I tried the following
def fnc( n ):
 print "fnc called with parameter '%d'" % n
 return n

for i in range(0,5):
 if i%2 == 0:
 fnc
 next
 print i

and got the same result as the OP



A couple of tests showed that the only important thing about the name in
the if clause is that it is known at runtime and then it is silently
ignored.
However, if the name is not known/accessible at run time a 'NameError'
is raised,
NameError: name 'mynewfn123' is not defined

On the other hand the following if clause
 if i%2 == 0:
 fncnext


The results aren't surprising once you know what's going on.

If you have:

   fnc

then this name is evaluated (it refers to a function object given your 
definition. Then that value is discarded. But this:


   kljgkjhgjk

is not defined anywhere, and it can't evaluate it, raising the name 
error. While in:


   fnc()

the 'fnc' is evaluated, and then it's called (when it should give a 
parameter error as your def expects one). But


   abc def

is just a syntax error as usually two identifiers can't be adjacent 
(AFAIK) except where the first is a reserved word.



So I have sympathy with the OP, I would expect the compiler to pick this
up - indeed it does so for two (or more ?) unused names on a single
line. That is unless someone can give a useful use of this behaviour or
is there something going on under the Python hood I'm not aware of?


This one of those features I think that do have the odd use but most of 
the time just result in perplexing results or hard-to-find bugs. It 
could have been eliminated from the language (especially as many people 
aren't even aware of the possibilities) with little loss.


Someone who desperately wants to evaluate a name or expression can 
always use something like:


 def test(x):pass

 test(fnc)

for the same purpose. But this time it's obvious. (Ideally it would be a 
built-in construct to avoid the call overhead.)



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


Re: How to make Python interpreter a little more strict?

2016-03-26 Thread John Pote



On 26/03/2016 12:05, Chris Angelico wrote:

On Fri, Mar 25, 2016 at 11:06 PM, Aleksander Alekseev  wrote:

Recently I spend half an hour looking for a bug in code like this:

eax@fujitsu:~/temp$ cat ./t.py
#!/usr/bin/env python3

for x in range(0,5):
 if x % 2 == 0:
 next
 print(str(x))

eax@fujitsu:~/temp$ ./t.py
0
1
2
3
4

Is it possible to make python complain in this case? Or maybe solve
such an issue somehow else?

I think what you're looking for here is an acknowledgement that
evaluating the name "next" accomplishes nothing. That's not really
something the Python interpreter should be looking at (hey, you might
have good reason for doing that), but there are linters that can
detect this kind of dead code. Some of them tie into programmer's
editors, so you could get a nice little warning message right in the
window where you're typing your code. Look into some of the top-end
editors (free or commercial) and see what you think of them - they can
save you no end of time.

ChrisA

So intrigued by this question I tried the following
def fnc( n ):
print "fnc called with parameter '%d'" % n
return n

for i in range(0,5):
if i%2 == 0:
fnc
next
print i

and got the same result as the OP

D:\projects\python
>>python next.py
0
1
2
3
4
D:\projects\python
>>

A couple of tests showed that the only important thing about the name in 
the if clause is that it is known at runtime and then it is silently 
ignored.
However, if the name is not known/accessible at run time a 'NameError' 
is raised,

NameError: name 'mynewfn123' is not defined

On the other hand the following if clause
if i%2 == 0:
fncnext

results in a compiler error,
D:\projects\python
>>python next.py
  File "next.py", line 9
fnc next
   ^
SyntaxError: invalid syntax

This is all for Python 2.7.9. (Don't know about Python 3).

So I have sympathy with the OP, I would expect the compiler to pick this 
up - indeed it does so for two (or more ?) unused names on a single 
line. That is unless someone can give a useful use of this behaviour or 
is there something going on under the Python hood I'm not aware of?


It would be all to easy to write a series of lines just calling 
functions and forget the () on one of them. Not fun programming.
It's also a good reminder that the meaning of a keyword in language A is 
not necessarily the same in language B (ie 'next', Python)
So on this last point is this behaviour of Python defined somewhere in 
the docs?


Regards all,
John

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


Re: repeat items in a list

2016-03-26 Thread beliavsky--- via Python-list
On Saturday, March 26, 2016 at 7:30:14 PM UTC-4, Mark Lawrence wrote:
> On 26/03/2016 22:12, beliavsky--- via Python-list wrote:
> > I can create a list that has repeated elements of another list as follows:
> >
> > xx = ["a","b"]
> > nrep = 3
> > print xx
> > yy = []
> > for aa in xx:
> >  for i in range(nrep):
> >  yy.append(aa)
> > print yy
> >
> > output:
> > ['a', 'b']
> > ['a', 'a', 'a', 'b', 'b', 'b']
> >
> > Is there a one-liner to create a list with repeated elements?
> >
> 
> yy = [aa for aa in xx for _ in range(nrep)]
> 
> I suggest that you try this sort of the thing at an interactive prompt, 
> it's a great way to learn.
> 
> You might also want to take a look at the itertools module 
> https://docs.python.org/3/library/itertools.html.  This is often used in 
> building structures like the ones you've been asking about today.  To me 
> it is the Swiss Army Knife of the stdlib.

Thanks for the one-liner, which I prefer to the one I made up using itertools:

yy = list(chain.from_iterable([list(repeat(aa,nrep)) for aa in xx]))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-26 Thread beliavsky--- via Python-list
On Saturday, March 26, 2016 at 7:24:10 PM UTC-4, Erik wrote:
> Hi,
> 
> On 26/03/16 22:12, beliavsky--- via Python-list wrote:
> > I can create a list that has repeated elements of another list as follows:
> >
> > xx = ["a","b"]
> > nrep = 3
> > print xx
> > yy = []
> > for aa in xx:
> >  for i in range(nrep):
> >  yy.append(aa)
> > print yy
> >
> > output:
> > ['a', 'b']
> > ['a', 'a', 'a', 'b', 'b', 'b']
> >
> > Is there a one-liner to create a list with repeated elements?
> 
> yy = reduce(lambda a, b: a + b, ([i] * nrep for i in xx), [])
> 
> Or, if you want to "import operator" first, you can use 'operator.add' 
> instead of the lambda (but you _did_ ask for a one-liner ;)).
> 
> Out of interest, why the fascination with one-liners?

Thanks for your reply. Sometimes when I program in Python I think I am not 
using the full capabilities of the language, so I want to know if there are
more concise ways of doing things.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-26 Thread Mark Lawrence

On 26/03/2016 22:12, beliavsky--- via Python-list wrote:

I can create a list that has repeated elements of another list as follows:

xx = ["a","b"]
nrep = 3
print xx
yy = []
for aa in xx:
 for i in range(nrep):
 yy.append(aa)
print yy

output:
['a', 'b']
['a', 'a', 'a', 'b', 'b', 'b']

Is there a one-liner to create a list with repeated elements?



yy = [aa for aa in xx for _ in range(nrep)]

I suggest that you try this sort of the thing at an interactive prompt, 
it's a great way to learn.


You might also want to take a look at the itertools module 
https://docs.python.org/3/library/itertools.html.  This is often used in 
building structures like the ones you've been asking about today.  To me 
it is the Swiss Army Knife of the stdlib.


--
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: repeat items in a list

2016-03-26 Thread Erik

Hi,

On 26/03/16 22:12, beliavsky--- via Python-list wrote:

I can create a list that has repeated elements of another list as follows:

xx = ["a","b"]
nrep = 3
print xx
yy = []
for aa in xx:
 for i in range(nrep):
 yy.append(aa)
print yy

output:
['a', 'b']
['a', 'a', 'a', 'b', 'b', 'b']

Is there a one-liner to create a list with repeated elements?


yy = reduce(lambda a, b: a + b, ([i] * nrep for i in xx), [])

Or, if you want to "import operator" first, you can use 'operator.add' 
instead of the lambda (but you _did_ ask for a one-liner ;)).


Out of interest, why the fascination with one-liners?

E.

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


Re: setup

2016-03-26 Thread Joel Goldstick
On Sat, Mar 26, 2016 at 6:52 PM, Youssef Ghorab 
wrote:

> dear python,i'm having a problem when i'm setting up the program
> 0x80070570 problem
> if you please could give me any advice will be cool.
> thanks in advance
> --
> https://mail.python.org/mailman/listinfo/python-list
>

I'm guessing you are on windows and you could google the error code, but
also search the list because this question has been asked and answered I
believe

-- 
Joel Goldstick
http://joelgoldstick.com/ 
http://cc-baseballstats.info/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-26 Thread Cameron Simpson

On 26Mar2016 15:12, beliav...@aol.com  wrote:

I can create a list that has repeated elements of another list as follows:

xx = ["a","b"]
nrep = 3
print xx
yy = []
for aa in xx:
   for i in range(nrep):
   yy.append(aa)
print yy

output:
['a', 'b']
['a', 'a', 'a', 'b', 'b', 'b']

Is there a one-liner to create a list with repeated elements?


Sure. As with all one liners, there comes a degree of complexity when it gets 
in the way of readability; you must decide what is better in your use case.


Look up the chain() function from the itertools module. Generate 2 (or nrep) 
length lists from each element of the original list and chain() them together.  
That gets you an iterable of all the elements. If you really need a list out 
the end instead of the iterable of the elements, convert the iterable to a list 
(hint: lists can be initialised with iterables).


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: help with program

2016-03-26 Thread Mark Lawrence

On 26/03/2016 20:38, Jerry Martens wrote:

any help would be appreciated! or could you please point me to a good forum for 
total noobs?thank you for your time and effort!



https://mail.python.org/mailman/listinfo/tutor also available at 
gmane.comp.python.tutor.


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


setup

2016-03-26 Thread Youssef Ghorab
dear python,i'm having a problem when i'm setting up the program 
0x80070570 problem 
if you please could give me any advice will be cool.
thanks in advance 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exclude every nth element from list?

2016-03-26 Thread Mark Lawrence

On 26/03/2016 22:08, beliavsky--- via Python-list wrote:

On Saturday, March 26, 2016 at 1:02:06 PM UTC-4, Gary Herron wrote:

On 03/26/2016 09:49 AM, beliavsky--- via Python-list wrote:

I can use x[::n] to select every nth element of a list. Is there a one-liner to 
get a list that excludes every nth element?


Yes:

  >>> L=list(range(20))
  >>> [x   for i,x in enumerate(L)   if i%3 != 0]
[1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19]


Gary Herron



Thanks to you and others who replied. I see that enumerate is a useful function.



It is, but you may like to note that you don't have to count from zero. 
 The 'start' keyword can be set to anything you like.


--
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: help with program

2016-03-26 Thread Chris Angelico
On Sun, Mar 27, 2016 at 7:38 AM, Jerry Martens  wrote:
> hi im trying to run this program and it opens a screen really ast and closes 
> it faster withou any results. im totally a noob. everything i google is 
> confusing. do i need to place this is in a folder or just run from command 
> line? i have the latest version of python. im running win 7. any help would 
> be appreciated! or could you please point me to a good forum for total 
> noobs?thank you for your time and effort!
>

Hi!

There are a few ways you could do this. One is to run it from the
command line. Another is to put this line at the end of the program:

input("Press enter to exit. ")

That should bring up the same screen (called a "console") and then
have it wait until you're done reading it.

A third way is to edit your code using Idle, and run it from there. I
haven't done that in a while, though, so the details might have
changed in the recent versions.

All the best!

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


help with program

2016-03-26 Thread Jerry Martens
hi im trying to run this program and it opens a screen really ast and closes it 
faster withou any results. im totally a noob. everything i google is confusing. 
do i need to place this is in a folder or just run from command line? i have 
the latest version of python. im running win 7. any help would be appreciated! 
or could you please point me to a good forum for total noobs?thank you for your 
time and effort!
-- 
https://mail.python.org/mailman/listinfo/python-list


repeat items in a list

2016-03-26 Thread beliavsky--- via Python-list
I can create a list that has repeated elements of another list as follows:

xx = ["a","b"]
nrep = 3
print xx
yy = []
for aa in xx:
for i in range(nrep):
yy.append(aa)
print yy

output:
['a', 'b']
['a', 'a', 'a', 'b', 'b', 'b']

Is there a one-liner to create a list with repeated elements?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exclude every nth element from list?

2016-03-26 Thread beliavsky--- via Python-list
On Saturday, March 26, 2016 at 1:02:06 PM UTC-4, Gary Herron wrote:
> On 03/26/2016 09:49 AM, beliavsky--- via Python-list wrote:
> > I can use x[::n] to select every nth element of a list. Is there a 
> > one-liner to get a list that excludes every nth element?
> 
> Yes:
> 
>  >>> L=list(range(20))
>  >>> [x   for i,x in enumerate(L)   if i%3 != 0]
> [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19]
> 
> 
> Gary Herron
> 
> 
> -- 
> Dr. Gary Herron
> Department of Computer Science
> DigiPen Institute of Technology
> (425) 895-4418

Thanks to you and others who replied. I see that enumerate is a useful function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Cameron Simpson

On 26Mar2016 02:36, Thomas 'PointedEars' Lahn  wrote:

Ned Batchelder wrote:

Chris, I apologize for Thomas.


How dare you to speak for me,


Because it is something you never say: sorry for my rudeness.


and *again* the rest of the subscribers?


He speaks for me at least, on this topic. I was tempted to say this yesterday 
after Ned, but didn't because his words were well chosen. But now:


Chris, I too apologise for Thomas' tone. With one or two exceptions, I have 
found this to be one of the most civil and welcoming fora on the net and hope 
you get good help and discussion here.



There is nothing to apologize for when I am *helping* someone by giving them
useful information.


Items of useful information shielded behind concealing walls of apparent anger 
and contempt. That is not a helpful delivery style, and it actively drives away 
new people.


May I recommend the film "Harvey"? As the lead character says at one point: "I 
used to be smart. I recommend nice." I used to be something of a hothead 
myself; I hope that I have matured.


[...]

Politeness is another thing you should try sometime, as I see that, your
having no valid argument at all, you like to throw dirt instead.

[...]

Your previous tone makes this admonition ineffective. Based on my samples, Ned 
is far beyond you in politeness.


My personal practice is usually to leave post that offend or disparage or 
otherwise have an agressive tone alone, or to snip the rant-like sections and 
address _only_ the technical content to try to keep the discussion on topic and 
civil. But not always, as evidenced here.


Thomas: your tone and delivery _is_ unhelpful to others, and comes across as 
hostile, at least to my eyes and evidently to others.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Chris Angelico
On Sun, Mar 27, 2016 at 4:43 AM, Rustom Mody  wrote:
> On Saturday, March 26, 2016 at 4:09:41 PM UTC+5:30, Steven D'Aprano wrote:
>> On Sat, 26 Mar 2016 04:30 pm, Rustom Mody wrote:
>>
>> > For one thing its good to remember that we wouldn't be here without python
>> > Python wouldn't be what it is without CPython
>>
>> There is nothing about Python that relies on the C standard being as it is.
>
> Um lets see...
> There is this nice piece of OO called the exception hierarchy:
> https://docs.python.org/2/library/exceptions.html#exception-hierarchy
>
> So we have
> BaseException ⊇ Exception ⊇ EnvironmentError ⊇ IOError
> At this point it would have been completely natural for IOError to continue
> subclassing to all the typical errors
> - File not found
> - No Space left on device
> etc etc
>
> But instead we have an integer errno and we must inquire what that is to
> figure out what the exact IOError was
> Are you suggesting that python's errno module:
> https://docs.python.org/2/library/errno.html
> And C's http://man7.org/linux/man-pages/man3/errno.3.html
> are coincidentally related?

You're reading documentation that's aimed at C programmers for the
same reason as above - aiming at C makes it accessible to the most
people. But errno is not inherently bound to C; if I were to build a
language interpreter in Fortran, I could make errno available to it.
What you're looking at isn't so much a C thing as a Linux thing;
Python makes available the Linux error code as a means of
disambiguating similar errors.

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


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Terry Reedy

On 3/26/2016 1:43 PM, Rustom Mody wrote:


There is this nice piece of OO called the exception hierarchy:


> https://docs.python.org/2/library/exceptions.html#exception-hierarchy

https://docs.python.org/3/library/exceptions.html#exception-hierarchy


BaseException ⊇ Exception ⊇ EnvironmentError ⊇ IOError


BaseException ⊇ Exception ⊇ ⊇ OSError


At this point it would have been completely natural for IOError to continue
subclassing to all the typical errors
- File not found
- No Space left on device


Which is why we now have

  +-- OSError
  |+-- BlockingIOError
  |+-- ChildProcessError
  |+-- ConnectionError
  ||+-- BrokenPipeError
  ||+-- ConnectionAbortedError
  ||+-- ConnectionRefusedError
  ||+-- ConnectionResetError
  |+-- FileExistsError
  |+-- FileNotFoundError
  |+-- InterruptedError
  |+-- IsADirectoryError
  |+-- NotADirectoryError
  |+-- PermissionError
  |+-- ProcessLookupError
  |+-- TimeoutError

'no space' is MemoryError, but that is a hardward, not OS matter.


But instead we have an integer errno and we must inquire what that is to
figure out what the exact IOError was


This statement is obsolete, but explains why the above was added in 3.3.

--
Terry Jan Reedy


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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Michael Torrie
On 03/26/2016 11:49 AM, Michael Torrie wrote:
> Well said, Ned, and a good reminder for me, and I suspect all of us, to
> considering how we communicate.  It's our nature to think problems lie
^^
Sigh.  Consider.  And proof read.

> with everyone else but us (as witnessed by recent posts from another
> list member in this own thread), and it's good to be reminded to look
> inward as well.


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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Thomas 'PointedEars' Lahn
Mark Lawrence wrote:

> On 24/03/2016 20:53, c...@isbd.net wrote:
>> I use Python wherever I can and find this list (as a usenet group via
>> gmane) an invaluable help at times.
>>
>> Occasionally I have to make forays into Javascript, can anyone
>> recommend a place similar to this list where Javascript questions can
>> be asked?  The trouble is that there are very many usenet Javascript
>> lists and it's difficult to guess which one[es] might be good.
> 
> Perhaps this http://transcrypt.org/ is the way to go? :)

Unfortunately, no.  It needs attention from an expert in the targeted field.

To begin with, the “JavaScript” version (actually, only an ECMAScript 
*2015*-compliant version) of the original Python code considers a "class" as 
sealed (properties being only accessor properties with a getter), when in 
Python that is not the case:

class C:
def foo (self):
pass

o = C()
C.foo = lambda self, bar: print(bar)

# prints "baz"
o.foo("baz")

Further, to set up multiple inheritance in a conforming implementation of 
ECMAScript, one must not only set up the instance properties as by the 
constructor of a type, but also the *prototype* chain.  In fact, a Proxy 
instance would be required to really set up the *emulation* of such a 
branching prototype chain for any ECMAScript object.

This list of implementation mistakes is not exhaustive, but ECMAScript 
implementations are beyond the scope of this newsgroup/mailing list.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exclude every nth element from list?

2016-03-26 Thread BartC

On 26/03/2016 16:49, beliav...@aol.com wrote:

I can use x[::n] to select every nth element of a list.


I would use x[n-1::n] if 'nth' means the 3rd element of 
[10,20,30,40,...] is 30. Otherwise every selection will include the 
first, no matter what n is.


--
Bartc


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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Michael Torrie
On 03/26/2016 05:37 AM, Ned Batchelder wrote:
> [...]

> Has anyone ever said to you, "Thanks, Thomas! Lots of people were giving
> me answers, but they were all so kind and polite about it, I couldn't
> see what they were saying.  Finally, your blunt direct manner got
> through to me, so now I understand."  Of course not. It's absurd.
> Bluntness doesn't help learning.  It just makes *you* feel good.  
> 
> Points of correctness are useless without points of connection.  You
> have to talk to people in a way that they will hear.  If you can't be
> bothered, then you are just wasting your time, and earning a negative
> reputation for yourself.
> [...]

Well said, Ned, and a good reminder for me, and I suspect all of us, to
considering how we communicate.  It's our nature to think problems lie
with everyone else but us (as witnessed by recent posts from another
list member in this own thread), and it's good to be reminded to look
inward as well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Rustom Mody
On Saturday, March 26, 2016 at 4:09:41 PM UTC+5:30, Steven D'Aprano wrote:
> On Sat, 26 Mar 2016 04:30 pm, Rustom Mody wrote:
> 
> > For one thing its good to remember that we wouldn't be here without python
> > Python wouldn't be what it is without CPython
> 
> There is nothing about Python that relies on the C standard being as it is.

Um lets see...
There is this nice piece of OO called the exception hierarchy:
https://docs.python.org/2/library/exceptions.html#exception-hierarchy

So we have
BaseException ⊇ Exception ⊇ EnvironmentError ⊇ IOError
At this point it would have been completely natural for IOError to continue
subclassing to all the typical errors 
- File not found
- No Space left on device
etc etc

But instead we have an integer errno and we must inquire what that is to
figure out what the exact IOError was
Are you suggesting that python's errno module:
https://docs.python.org/2/library/errno.html
And C's http://man7.org/linux/man-pages/man3/errno.3.html
are coincidentally related?

> There are Python implementations that are not written in C or C++:
> 
> Jython (Java)
> IronPython (C# for .Net or Mono)
> CLPython (Lisp)
> Berp (Haskell)

As best as I know 
- Java is written in C
- Lisp is written in C
- Haskell is written in C


Notice a certain pattern?
Yeah some of them may be self-hosting
eg haskell (ghc) is written in ghc
Where did the first bootstrap start from?

And if you think those levels of distance render the C origin irrelevant,
here is a famous Turing award lecture:
https://www.ece.cmu.edu/~ganger/712.fall02/papers/p761-thompson.pdf
by (surprise-surprise!) the creator of C-Unix

... shows how to make a Trojan and ends with

The moral is obvious.  You can't trust code that you did not totally
create yourself.  (Especially code from companies that employ people
like me.)  No amount of source-level verification or scrutiny will
protect you from using untrusted code.

So... Ahem... C is unsafe... Right... Prefer C++ ??
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Another Key Binding Question

2016-03-26 Thread MRAB

On 2016-03-26 17:10, Wildman via Python-list wrote:

I use some key bindings in my program.  They are declared
like this:

 root.bind("" + "q", quit)
 root.bind("" + "q", quit)
 root.bind("" + "Q", quit)
 root.bind("" + "Q", quit)

The above binds both Alt keys with upper and lower case 'q'.
Is there a way to combine the statements above into one
statement?


Try this:

root.bind("", quit)
root.bind("", quit)

The first is for either "Alt" key plus the "Q" key and Caps Lock turned off.

The second is for either "Alt" key plus the "Q" key and Caps Lock turned on.

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


Re: PLEASE HELP -- TOTALLY NEW TO PYTHON

2016-03-26 Thread Joel Goldstick
On Sat, Mar 26, 2016 at 1:31 AM, Juan Dent  wrote:

>
> I am trying to run ‘python cppdep.py’ but get the following:
>
>
> 
> analyzing dependencies among all components ...
> Traceback (most recent call last):
>   File "cppdep.py", line 675, in 
> main()
>   File "cppdep.py", line 643, in main
> calculate_graph(digraph)
>   File "cppdep.py", line 570, in calculate_graph
> (cycles, dict_node2cycle) = make_DAG(digraph, key_node)
>   File "/Users/juandent/Downloads/cppdep-master/networkx_ext.py", line 79,
> in make_DAG
> for ind in range(len(subgraphs)-1, -1, -1):
> TypeError: object of type 'generator' has no len()
>
>
> Please, I know no python and am in a hurry to get this working… Please help
>
>
> Regards,
> Juan
> --
> https://mail.python.org/mailman/listinfo/python-list
>

As a painless quick try I would change this line:

for ind in range(len(subgraphs)-1, -1, -1):

to this:

for ind in range(len(list(subgraphs))-1, -1, -1):

If that works, when you have time track down what is really going on.
-- 
Joel Goldstick
http://joelgoldstick.com/ 
http://cc-baseballstats.info/
-- 
https://mail.python.org/mailman/listinfo/python-list


Another Key Binding Question

2016-03-26 Thread Wildman via Python-list
I use some key bindings in my program.  They are declared
like this:

root.bind("" + "q", quit)
root.bind("" + "q", quit)
root.bind("" + "Q", quit)
root.bind("" + "Q", quit)

The above binds both Alt keys with upper and lower case 'q'.
Is there a way to combine the statements above into one
statement?

-- 
 GNU/Linux user #557453
May the Source be with you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exclude every nth element from list?

2016-03-26 Thread Vincent Vande Vyvre

Le 26/03/2016 18:06, Vincent Vande Vyvre a écrit :

Le 26/03/2016 17:49, beliavsky--- via Python-list a écrit :
I can use x[::n] to select every nth element of a list. Is there a 
one-liner to get a list that excludes every nth element?

Something like that:

>>> l = list("lkodjuyhrtgfedcvfg")
>>> l
['l', 'k', 'o', 'd', 'j', 'u', 'y', 'h', 'r', 't', 'g', 'f', 'e', 'd', 
'c', 'v', 'f', 'g']

>>> ll = [c for i, c in enumerate(l) if i % 3]
>>> ll.insert(0, l[0])
>>> ll
['l', 'k', 'o', 'j', 'u', 'h', 'r', 'g', 'f', 'd', 'c', 'f', 'g']



Vincent

Correction, it's more correct with the insert before the list comprehension

>>> l.insert(0, "_")
>>> ll = [c for i, c in enumerate(l) if i % 3]
>>> ll
['l', 'k', 'd', 'j', 'y', 'h', 't', 'g', 'e', 'd', 'v', 'f']
--
https://mail.python.org/mailman/listinfo/python-list


Re: Exclude every nth element from list?

2016-03-26 Thread Peter Otten
beliavsky--- via Python-list wrote:

> I can use x[::n] to select every nth element of a list. Is there a
> one-liner to get a list that excludes every nth element?

del x[::n]

;)

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


Re: Exclude every nth element from list?

2016-03-26 Thread Vincent Vande Vyvre

Le 26/03/2016 17:49, beliavsky--- via Python-list a écrit :

I can use x[::n] to select every nth element of a list. Is there a one-liner to 
get a list that excludes every nth element?

Something like that:

>>> l = list("lkodjuyhrtgfedcvfg")
>>> l
['l', 'k', 'o', 'd', 'j', 'u', 'y', 'h', 'r', 't', 'g', 'f', 'e', 'd', 
'c', 'v', 'f', 'g']

>>> ll = [c for i, c in enumerate(l) if i % 3]
>>> ll.insert(0, l[0])
>>> ll
['l', 'k', 'o', 'j', 'u', 'h', 'r', 'g', 'f', 'd', 'c', 'f', 'g']



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


Re: Exclude every nth element from list?

2016-03-26 Thread Erik

On 26/03/16 16:49, beliavsky--- via Python-list wrote:

I can use x[::n] to select every nth element of a list. Is there a one-liner to 
get a list that excludes every nth element?


(e for i, e in enumerate(x) if i % n)

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


Re: Exclude every nth element from list?

2016-03-26 Thread Bob Gailer
On Mar 26, 2016 12:50 PM, "beliavsky--- via Python-list" <
python-list@python.org> wrote:
>
> I can use x[::n] to select every nth element of a list. Is there a
one-liner to get a list that excludes every nth element?

[y for (i,y) in enumerate(x) if i % n]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exclude every nth element from list?

2016-03-26 Thread Gary Herron

On 03/26/2016 09:49 AM, beliavsky--- via Python-list wrote:

I can use x[::n] to select every nth element of a list. Is there a one-liner to 
get a list that excludes every nth element?


Yes:

>>> L=list(range(20))
>>> [x   for i,x in enumerate(L)   if i%3 != 0]
[1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19]


Gary Herron


--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: PLEASE HELP -- TOTALLY NEW TO PYTHON

2016-03-26 Thread Gary Herron

On 03/25/2016 10:31 PM, Juan Dent wrote:

I am trying to run ‘python cppdep.py’ but get the following:


 I would guess that this code was written some time ago for Python2, 
but that you have downloaded and run it with Python3.


Try installing Python2 instead of Python3.   Or try talking whoever 
wrote it into converting it to Python3.


Or my guess is completely wrong and the code is buggy and won't run 
until fixed.  (Which brings up the questions: What is cppdep.py? Who 
wrote it?  How do you know that it runs?)



Gary Herron





analyzing dependencies among all components ...
Traceback (most recent call last):
   File "cppdep.py", line 675, in 
 main()
   File "cppdep.py", line 643, in main
 calculate_graph(digraph)
   File "cppdep.py", line 570, in calculate_graph
 (cycles, dict_node2cycle) = make_DAG(digraph, key_node)
   File "/Users/juandent/Downloads/cppdep-master/networkx_ext.py", line 79, in 
make_DAG
 for ind in range(len(subgraphs)-1, -1, -1):
TypeError: object of type 'generator' has no len()


Please, I know no python and am in a hurry to get this working… Please help


Regards,
Juan



--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418


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


Exclude every nth element from list?

2016-03-26 Thread beliavsky--- via Python-list
I can use x[::n] to select every nth element of a list. Is there a one-liner to 
get a list that excludes every nth element? 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Gene Heskett
On Saturday 26 March 2016 11:35:52 Larry Martell wrote:

> On Sat, Mar 26, 2016 at 11:31 AM, Gene Heskett  
wrote:
> > On Saturday 26 March 2016 07:52:05 Larry Martell wrote:
> >> As my wife once said, "If you start with 'Listen, asshole, ...'
> >> they probably won't hear what you have to say after that.
> >
> > She is 100% correct, but try as I might, I can't quite believe that
> > your missus would ever use that plain a language.  She is too good
> > at dressing it up.  She reminds me of our now passed Senator Bobbie
> > Byrd, who could tell somebody to go to hell in such flowery language
> > that they looked forward to the trip.
>
> Gene, she can curse like a sailor when needed.

The key is "when needed".  Been known to do that myself. I did, 60 years 
ago have a 10 minute monologue of swearing practiced up, no 4 letter 
word used twice. But common sense has prevailed and I've forgotten 9 
minutes of it by now. No longer 10' tall & bulletproof I guess. :)

The years do that to a body, so now my std excuse is that if I had of 
known I was going to live this long, I would have taken better care of 
myself.  But I would have had to start practicing that the summer of 
1960 when, for lack of a better job, I spent several months in an iron 
foundry. Woman and at that point, 2 kids to feed. But I learned a lot 
about hot ($2400F) iron too.

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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Larry Martell
On Sat, Mar 26, 2016 at 11:31 AM, Gene Heskett  wrote:
> On Saturday 26 March 2016 07:52:05 Larry Martell wrote:
>> As my wife once said, "If you start with 'Listen, asshole, ...' they
>> probably won't hear what you have to say after that.
>
> She is 100% correct, but try as I might, I can't quite believe that your
> missus would ever use that plain a language.  She is too good at
> dressing it up.  She reminds me of our now passed Senator Bobbie Byrd,
> who could tell somebody to go to hell in such flowery language that they
> looked forward to the trip.

Gene, she can curse like a sailor when needed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Gene Heskett
On Saturday 26 March 2016 07:52:05 Larry Martell wrote:

> On Sat, Mar 26, 2016 at 7:37 AM, Ned Batchelder  
wrote:
> > Thomas, you don't have to choose between correct and nice.  It's
> > possible to be both.
>
> "I'm not good, I'm not nice, I'm just right."
>
> That was written by Stephen Sondheim and it's from his musical Into
> The Woods. It's said by the witch. That used to be my sig back in
> usenet days, and more then one person said "Who said that? Rush
> Limbaugh?"
>
> > I can see that you are knowledgeable, and I really appreciate the
> > energy you put into answering questions.  You are very generous with
> > your time. But when you bark correct things at people, they don't
> > hear you.  Your helpful energy is being overshadowed by your blunt
> > rude manner.
>
> As my wife once said, "If you start with 'Listen, asshole, ...' they
> probably won't hear what you have to say after that.

She is 100% correct, but try as I might, I can't quite believe that your 
missus would ever use that plain a language.  She is too good at 
dressing it up.  She reminds me of our now passed Senator Bobbie Byrd, 
who could tell somebody to go to hell in such flowery language that they 
looked forward to the trip.

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


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread BartC

On 26/03/2016 14:30, Chris Angelico wrote:

On Sun, Mar 27, 2016 at 1:09 AM, BartC  wrote:

I'm surprised that both C and Python allow statements that apparently do
nothing. In both, an example is:

   x

on a line by itself. This expression is evaluated, but then any result
discarded. If there was a genuine use for this (for example, reporting any
error with the evaluation), then it would be simple enough to require a
keyword in front.


Tell me, which of these is a statement that "does nothing"?

foo
foo.bar
foo["bar"]
foo.__call__
foo()
int(foo)

All of them are expressions to be evaluated and the result discarded.
I'm sure you'll recognize "foo()" as useful code, but to the
interpreter, they're all the same.


Out of that lot, only foo() is something that is commonly written both 
as an expression and standalone statement.



And any one of them could raise an
exception rather than emit a value; for instance, consider these code
blocks:

# Personally, I prefer doing it the other way, but
# if you have a big Py2 codebase, this will help
# port it to Py3.
try: raw_input
except NameError: raw_input = input

try: int(sys.argv[1])
except IndexError:
 print("No argument given")
except ValueError:
 print("Not an integer")

In each case, the "dummy evaluation" of an expression is used as a way
of asking "Will this throw?". That's why this has to be squarely in
the hands of linters, not the main interpreter; there's nothing that
can't in some way be useful.


But notice that to render such an evaluation 'useful', you've put 'try:' 
in front, which is also a cue to the reader.


Now you can't just do that anyway (try expects an except block to 
follow). But my suggestion was to have required a keyword in front of 
such expressions. Then no linter is needed. And stops some 
head-scratching from people who have to read the code.


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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Mark Lawrence

On 24/03/2016 20:53, c...@isbd.net wrote:

I use Python wherever I can and find this list (as a usenet group via
gmane) an invaluable help at times.

Occasionally I have to make forays into Javascript, can anyone
recommend a place similar to this list where Javascript questions can
be asked?  The trouble is that there are very many usenet Javascript
lists and it's difficult to guess which one[es] might be good.



Perhaps this http://transcrypt.org/ is the way to go? :)

--
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: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Chris Angelico
On Sun, Mar 27, 2016 at 1:09 AM, BartC  wrote:
> I'm surprised that both C and Python allow statements that apparently do
> nothing. In both, an example is:
>
>   x
>
> on a line by itself. This expression is evaluated, but then any result
> discarded. If there was a genuine use for this (for example, reporting any
> error with the evaluation), then it would be simple enough to require a
> keyword in front.

Tell me, which of these is a statement that "does nothing"?

foo
foo.bar
foo["bar"]
foo.__call__
foo()
int(foo)

All of them are expressions to be evaluated and the result discarded.
I'm sure you'll recognize "foo()" as useful code, but to the
interpreter, they're all the same. And any one of them could raise an
exception rather than emit a value; for instance, consider these code
blocks:

# Personally, I prefer doing it the other way, but
# if you have a big Py2 codebase, this will help
# port it to Py3.
try: raw_input
except NameError: raw_input = input

try: int(sys.argv[1])
except IndexError:
print("No argument given")
except ValueError:
print("Not an integer")

In each case, the "dummy evaluation" of an expression is used as a way
of asking "Will this throw?". That's why this has to be squarely in
the hands of linters, not the main interpreter; there's nothing that
can't in some way be useful.

>> The main reason the C int has undefined behaviour is that it's
>> somewhere between "fixed size two's complement signed integer" and
>> "integer with plenty of room". A C compiler is generally free to use a
>> larger integer than you're expecting, which will cause numeric
>> overflow to not happen. That's (part of[1]) why overflow of signed
>> integers is undefined - it'd be too costly to emulate a smaller
>> integer. So tell me... what happens in CPython if you incref an object
>> more times than the native integer will permit? Are you bothered by
>> this possibility, or do you simply assume that nobody will ever do
>> that?
>
>
> (On a ref-counted scheme I use, with 32-bit counts (I don't think it matters
> if they are signed or not), each reference implies a 16-byte object
> elsewhere. For the count to wrap around back to zero, that would mean 64GB
> of RAM being needed. On a 32-bit system, something else will go wrong first.
>
> Even on 64-bits, it's a possibility I suppose although you might notice
> memory problems sooner.)

C code can claim references to Python objects without having actual
pointers anywhere. A naive object traversal algorithm could claim
temporary references on all the objects it moves past (to ensure they
don't get garbage collected in the middle), and then get stuck in an
infinite loop traversing a reference loop, thus infinitely increasing
reference counts. Yeah, it can happen... I've had bugs like that in my
code...

Point is, CPython can generally assume that bug-free code will never
get anywhere *near* the limit of a signed integer. Consequently, C's
undefined behaviour isn't a problem; it does NOT mean we need to be
scared of signed integers.

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


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread BartC

On 26/03/2016 13:22, Chris Angelico wrote:

On Sat, Mar 26, 2016 at 11:21 PM, Steven D'Aprano  wrote:

In plain English, if the programmer had an intention for the code, and it
was valid C syntax, it's not hard to conclude that the code has some
meaning. Even if that meaning isn't quite what the programmer expected.
Compilers are well known for only doing what you tell them to do, not what
you want them to do. But in the case of C and C++ they don't even do what
you tell them to do.



Does this Python code have meaning?

x = 5
while x < 10:
 print(x)
 ++x


It's a fairly direct translation of perfectly valid C code, and it's
syntactically valid. When the C spec talks about accidentally doing
what you intended, that would be to have the last line here increment
x. But that's never a requirement; compilers/interpreters are not
mindreaders.


I'm surprised that both C and Python allow statements that apparently do 
nothing. In both, an example is:


  x

on a line by itself. This expression is evaluated, but then any result 
discarded. If there was a genuine use for this (for example, reporting 
any error with the evaluation), then it would be simple enough to 
require a keyword in front.


Not allowing these standalone expressions allows extra errors to be 
picked up including '++x' and 'next' in Python.


(I think simply translating '++x' in Python to 'x+=1' has already been 
discussed in the past.)




The main reason the C int has undefined behaviour is that it's
somewhere between "fixed size two's complement signed integer" and
"integer with plenty of room". A C compiler is generally free to use a
larger integer than you're expecting, which will cause numeric
overflow to not happen. That's (part of[1]) why overflow of signed
integers is undefined - it'd be too costly to emulate a smaller
integer. So tell me... what happens in CPython if you incref an object
more times than the native integer will permit? Are you bothered by
this possibility, or do you simply assume that nobody will ever do
that?


(On a ref-counted scheme I use, with 32-bit counts (I don't think it 
matters if they are signed or not), each reference implies a 16-byte 
object elsewhere. For the count to wrap around back to zero, that would 
mean 64GB of RAM being needed. On a 32-bit system, something else will 
go wrong first.


Even on 64-bits, it's a possibility I suppose although you might notice 
memory problems sooner.)


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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread cl
Thomas 'PointedEars' Lahn  wrote:
> c...@isbd.net wrote:
> 
> > Occasionally I have to make forays into Javascript, can anyone
> > recommend a place similar to this list where Javascript questions can
> > be asked?  The trouble is that there are very many usenet Javascript
> > lists and it's difficult to guess which one[es] might be good.
> 
> There is no Javascript. 
> 
> There are no Usenet lists.
> 
> This is not only a Python *mailing* list, it is also mirrored as an 
> international Usenet _newsgroup_,  (which I am 
> reading).
> 
Which is what (OP) do too.  Life's too short to go into detail about
how one is accessing a group/list in the context of a question like my
original question.

It's quite fun following all the resulting flak though!  :-)

> If you can accept all of that, then the international Usenet _newsgroup_ 
>  (where I am posting primarily) is for you.
> So are other national/language-specific newsgroups on the JavaScripts and 
> other ECMAScript implementations.  In your newsreader, search for newsgroups 
> whose name contains “javascript”.
> 
> Next time, read  and STFW first, and get a real name.
> 
Ay?  

Thanks anyway, comp.lang.javascript it is, or I'll try it anyway.

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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread cl
Ned Batchelder  wrote:
> On Friday, March 25, 2016 at 5:17:21 PM UTC-4, Thomas 'PointedEars' Lahn 
> wrote:
> > c...@isbd.net wrote:
> > 
> > > Occasionally I have to make forays into Javascript, can anyone
> > > recommend a place similar to this list where Javascript questions can
> > > be asked?  The trouble is that there are very many usenet Javascript
> > > lists and it's difficult to guess which one[es] might be good.
> > 
> > There is no Javascript. 
> > 
> > There are no Usenet lists.
> > 
> > This is not only a Python *mailing* list, it is also mirrored as an 
> > international Usenet _newsgroup_,  (which I am 
> > reading).
> > 
> > If you can accept all of that, then the international Usenet _newsgroup_ 
> >  (where I am posting primarily) is for you.
> > So are other national/language-specific newsgroups on the JavaScripts and 
> > other ECMAScript implementations.  In your newsreader, search for 
> > newsgroups 
> > whose name contains "javascript".
> > 
> > Next time, read  and STFW first, and get a real name.
> 
> Chris, I apologize for Thomas.  His main goal on this list seems to be
> pointing out when people are wrong, over the smallest details.  His
> secondary goal is enforcing some imaginary rule about real names, though
> he couldn't be bothered to read your post thoroughly enough to discover yours.
> 
> Thomas is not typical of the Python community. We are mostly nice people. :)
> 
Yes, I know, this is one of my favourite groups/lists.  Just about
every question I have ever asked here has received really helpful
replies.  Even this one has, though it does seem to have stirred a bit
of a hornet's nest at the same time.  :-)

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


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Chris Angelico
On Sat, Mar 26, 2016 at 11:21 PM, Steven D'Aprano  wrote:
> In plain English, if the programmer had an intention for the code, and it
> was valid C syntax, it's not hard to conclude that the code has some
> meaning. Even if that meaning isn't quite what the programmer expected.
> Compilers are well known for only doing what you tell them to do, not what
> you want them to do. But in the case of C and C++ they don't even do what
> you tell them to do.
>

Does this Python code have meaning?

x = 5
while x < 10:
print(x)
++x


It's a fairly direct translation of perfectly valid C code, and it's
syntactically valid. When the C spec talks about accidentally doing
what you intended, that would be to have the last line here increment
x. But that's never a requirement; compilers/interpreters are not
mindreaders.

The main reason the C int has undefined behaviour is that it's
somewhere between "fixed size two's complement signed integer" and
"integer with plenty of room". A C compiler is generally free to use a
larger integer than you're expecting, which will cause numeric
overflow to not happen. That's (part of[1]) why overflow of signed
integers is undefined - it'd be too costly to emulate a smaller
integer. So tell me... what happens in CPython if you incref an object
more times than the native integer will permit? Are you bothered by
this possibility, or do you simply assume that nobody will ever do
that? Does C's definition of undefined behaviour mean that this code
can be optimized away, thus achieving nothing?

typedef struct _object {
_PyObject_HEAD_EXTRA
Py_ssize_t ob_refcnt;
struct _typeobject *ob_type;
} PyObject;

#define Py_INCREF(op) ( \
_Py_INC_REFTOTAL  _Py_REF_DEBUG_COMMA   \
((PyObject *)(op))->ob_refcnt++)

The reftotal and debug comma are both empty in non-debug builds. The
meat of this is simply a double-plus increment of a Py_ssize_t
integer, which is defined in pyport.h as a signed integer.

Of course this won't be optimized away, though. The only part that's
undefined is "what exactly happens if you overflow an integer?". And
you shouldn't be doing that at all; if you do, it's a bug, one way or
another. The compiler cannot be expected to magically know what you
intended to happen, so it's allowed to assume that this isn't what
your code meant to do. If you care about capping refcounts, you need
to do that yourself, somehow - don't depend on the compiler, because
you can't even know exactly how wide that refcount is.

ChrisA

[1] The other part being that C didn't want to mandate two's
complement, although I'm pretty sure that could be changed today
without breaking any modern architectures.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Steven D'Aprano
On Sat, 26 Mar 2016 01:59 pm, Paul Rubin wrote:

> Steven D'Aprano  writes:
>> Culturally, C compiler writers have a preference for using undefined
>> behaviour to allow optimizations, even if it means changing the semantics
>> of your code.
> 
> If your code has UB then by definition it has no semantics to change.
> Code with UB has no meaning.

Ah, a language lawyer, huh? :-P


By the rules of the C standard, you're right, but those rules make use of a
rather specialised definition of "no meaning" or "meaningless". I'm using
the ordinary English sense. For example, would you consider that this
isolated C code is "meaningless"?

int i = n + 1;

I'm not talking about type errors where n is not an int. We can assume that
n is also an int. I bet that you know exactly what that line of code means.
But according to the standard, it's "meaningless", since it might overflow,
and signed int overflow is Undefined Behaviour.

Even the C FAQ (as quoted by John Regehr) implies that code which is defined
as "meaningless" may have meaning in the ordinary English sense:

[quote]
Anything at all can happen; the Standard imposes no requirements.
The program may fail to compile, or it may execute incorrectly
(either crashing or silently generating incorrect results), or it
may fortuitously do EXACTLY WHAT THE PROGRAMMER INTENDED.

[Emphasis added.]

http://blog.regehr.org/archives/213

If the code is "meaningless", how can we say that it does what the
programmer intended?

In plain English, if the programmer had an intention for the code, and it
was valid C syntax, it's not hard to conclude that the code has some
meaning. Even if that meaning isn't quite what the programmer expected.
Compilers are well known for only doing what you tell them to do, not what
you want them to do. But in the case of C and C++ they don't even do what
you tell them to do.

When I talk about changing the semantics of the code you write, I'm using a
plain English sense of "meaning". Start with a simple-minded, non-
optimizing C compiler -- what Raymond Chen refers to as a "classical
compiler". For example:

int table[4];
bool exists_in_table(int v)
{
for (int i = 0; i <= 4; i++) {
if (table[i] == v) return true;
}
return false;
}

There's an out-of-bounds error there, but as Chen puts it, a classical
compiler would mindlessly generate code that reads past the end of the
array. A bug, but a predictable one: you can reason about it, and the
effect will be dependent on whatever arbitrary value happens to be in that
memory location. A better compiler would generate an error and refuse to
compile code for it. Either way, in plain English, the meaning is obvious:


* Create an array of four ints, naming it "table".

* Declare a function named "exists_in_table", which takes an int "v" as
argument and returns a bool.

* This function iterates over i = 0 to 4 inclusive, returning true if the
i-th item of table equals the given v, and false if none of those items
equals the given v.


I don't believe for a second that you can't read that code well enough to
infer the intended meaning of it. Even I can read C well enough to do that.
Yet according to the C standard, that perfectly understandable code snippet
is deemed to be gibberish, and instead of returning true or false, the
compiler is permitted to erase your hard disk, or turn off your life-
support, if it so chooses. And as Raymond Chen describes, a post-classical
compiler will probably optimize that function to one which always returns
true.

As far as I know, there is no other language apart from C and C++ that takes
such a cavalier approach.

I cannot emphasis enough that the treatment of "undefined behaviour" is
intentional by the C standards committee. Given the absolutely catastrophic
effect it has had on the reliability, safety and security of code written
in C, in my opinion the C standard borders on professional negligence.
Programming in C becomes a battle to defeat the compiler and force it to do
what you tell it to do, all because the C standard was written by a bunch
of people whose number one priority was being able to make their benchmarks
look good.

Imagine a bridge builder who discovers a tiny, technical ambiguity or error
in the blueprints for a bridge. On one page, the documentation states that
there should be four rivets per metre in the supporting beams, but on
another page, it is described as five rivets per metre. What should the
builder do?

- ask for clarification and get the blueprints and documentation corrected?

- play it safe and use five rivets?

- declare that therefore the entire blueprints are meaningless, and so he is
free to optimize the bridge and reduce costs by using steel of a cheaper
grade, half the thickness, and one rivet per metre?

When the bridge collapses under the load of normal traffic, killing hundreds
of people, what comfort should we take from the fact that the builder was
able to optimize it so that it was hal

Re: How to make Python interpreter a little more strict?

2016-03-26 Thread Chris Angelico
On Fri, Mar 25, 2016 at 11:06 PM, Aleksander Alekseev  wrote:
> Recently I spend half an hour looking for a bug in code like this:
>
> eax@fujitsu:~/temp$ cat ./t.py
> #!/usr/bin/env python3
>
> for x in range(0,5):
> if x % 2 == 0:
> next
> print(str(x))
>
> eax@fujitsu:~/temp$ ./t.py
> 0
> 1
> 2
> 3
> 4
>
> Is it possible to make python complain in this case? Or maybe solve
> such an issue somehow else?

I think what you're looking for here is an acknowledgement that
evaluating the name "next" accomplishes nothing. That's not really
something the Python interpreter should be looking at (hey, you might
have good reason for doing that), but there are linters that can
detect this kind of dead code. Some of them tie into programmer's
editors, so you could get a nice little warning message right in the
window where you're typing your code. Look into some of the top-end
editors (free or commercial) and see what you think of them - they can
save you no end of time.

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


Re: How to make Python interpreter a little more strict?

2016-03-26 Thread Steven D'Aprano
On Fri, 25 Mar 2016 11:06 pm, Aleksander Alekseev wrote:

> Is it possible to make python complain in this case? Or maybe solve
> such an issue somehow else?

This is a job for a "linter", such as pychecker, pylint or pyflakes. Google
for more if you are interested.

A linter will check your code for things which are *legal* code, but might
not do what you expect, or are a sign of a potential error. For instance,
dead code that will never be reached, or variables that are defined and
then never used, or functions (such as next) which are named but not used.

Another thing you can do is use an editor which colours functions
like "next" differently from statements like "continue".



-- 
Steven

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


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Chris Angelico
On Sat, Mar 26, 2016 at 9:39 PM, Steven D'Aprano  wrote:
> It is an accident of history that Python's first and major implementation
> happens to be written in C. (Although its use as a glue language, allowing
> people to safely use libraries written in C, probably played a role in
> ensuring Python's success.)

Your parenthesis is more important than you may be giving it credit
for, so IMO C is more than "an accident of history" in Python's
success. There's a massive network effect surrounding programming
languages, particularly glue languages. Suppose I were to develop a
brand-new library of awesomeness, distributed as a Java .class file.
Python (via Jython) could now use that, but many MANY other languages
could not, ergo my library would languish. But if I design my library
to have C bindings instead, Java programs can't use it, but any
language that is able to connect to C code can. Conversely, if I'm
developing a new language, I can look at the available C libraries and
say "hey, look, access to C bindings gives me GUI toolkits, bignums,
etc, etc, etc", so it's worth my while to connect to that. C may
itself be immaterial, but the network surrounding it has been, and
continues to be. Thanks to CPython, Python can be easily compiled for
any CPU or OS that has the standard C build tools ported to it; that's
a huge dependency, but it's a dependency of *so* many other programs
that it's a high priority for OS developers.

Python's success comes partly through leveraging that portability and
power. The same could have been accomplished with any other language
at the center of the network, but the same wasn't accomplished with
any other language at the center of the network. It was done with C.

Of course, that doesn't mean that C's *behaviour* has anything to do
with Python's *behaviour*. That's a completely separate point.

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


Re: PLEASE HELP -- TOTALLY NEW TO PYTHON

2016-03-26 Thread Ned Batchelder
On Saturday, March 26, 2016 at 5:59:30 AM UTC-4, Juan Dent wrote:
> I am trying to run 'python cppdep.py' but get the following:
> 
> 
> analyzing dependencies among all components ...
> Traceback (most recent call last):
>   File "cppdep.py", line 675, in 
> main()
>   File "cppdep.py", line 643, in main
> calculate_graph(digraph)
>   File "cppdep.py", line 570, in calculate_graph
> (cycles, dict_node2cycle) = make_DAG(digraph, key_node)
>   File "/Users/juandent/Downloads/cppdep-master/networkx_ext.py", line 79, in 
> make_DAG
> for ind in range(len(subgraphs)-1, -1, -1):
> TypeError: object of type 'generator' has no len()
> 
> 
> Please, I know no python and am in a hurry to get this working... Please help

It looks like you are not the first to encounter this:
https://github.com/yuzhichang/cppdep/issues/2

I don't see a quick fix to this in the code.  If you fix this one spot,
likely there will be other problem.

It looks to me like you should install NetworkX 1.7 to get it to work.

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


Re: PLEASE HELP -- TOTALLY NEW TO PYTHON

2016-03-26 Thread Steven D'Aprano
On Sat, 26 Mar 2016 04:31 pm, Juan Dent wrote:

> 
> I am trying to run ‘python cppdep.py’ but get the following:
> 
>

> analyzing dependencies among all components ...
> Traceback (most recent call last):
>   File "cppdep.py", line 675, in 
> main()
>   File "cppdep.py", line 643, in main
> calculate_graph(digraph)
>   File "cppdep.py", line 570, in calculate_graph
> (cycles, dict_node2cycle) = make_DAG(digraph, key_node)
>   File "/Users/juandent/Downloads/cppdep-master/networkx_ext.py", line 79,
>   in make_DAG
> for ind in range(len(subgraphs)-1, -1, -1):
> TypeError: object of type 'generator' has no len()
> 
> 
> Please, I know no python and am in a hurry to get this working… 

Left your homework for the very last day, did you? I'm sorry that you are in
a hurry, but that's not our problem.

Look at the last two lines of the error traceback. The second last tells you
the line that failed:

for ind in range(len(subgraphs)-1, -1, -1):

and the last line tells you the error:

TypeError: object of type 'generator' has no len()

The error tells you that "subgraphs" is a "generator", not a list. So you
have two choices:

- you can change "subgraphs" to be a list;

- or you can change the for-loop to not need the length of subgraphs, or the
index.


The smaller change would probably be the first, changing subgraphs. But the
better change would probably be to change the for-loop.




-- 
Steven

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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Larry Martell
On Sat, Mar 26, 2016 at 7:37 AM, Ned Batchelder  wrote:
> Thomas, you don't have to choose between correct and nice.  It's
> possible to be both.

"I'm not good, I'm not nice, I'm just right."

That was written by Stephen Sondheim and it's from his musical Into
The Woods. It's said by the witch. That used to be my sig back in
usenet days, and more then one person said "Who said that? Rush
Limbaugh?"

> I can see that you are knowledgeable, and I really appreciate the energy
> you put into answering questions.  You are very generous with your time.
> But when you bark correct things at people, they don't hear you.  Your
> helpful energy is being overshadowed by your blunt rude manner.

As my wife once said, "If you start with 'Listen, asshole, ...' they
probably won't hear what you have to say after that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I need help

2016-03-26 Thread Steven D'Aprano
On Sat, 26 Mar 2016 05:52 am, matthew thiel wrote:

> So I downloaded python and made an account but when I run it all it does
> is give me 3 options repair modify and uninstall I have clicked repair and
> modify and let them run but at the end it just exit out so how do I get it
> to work???

You made an account? An account where? What does this account have to do
with Python?

Where did you download Python from? Please give the actual URL.

What operating system are you using? I can guess from the following that it
is probably Windows 10:

> Sent from Mail for Windows
> 10

is that correct? 32-bit or 64-bit?




-- 
Steven

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-26 Thread Steven D'Aprano
On Sat, 26 Mar 2016 11:18 am, Marco Sulla wrote:

>> That's a very superficial similarity: a list ['a', 'b', 'x', 'y'] is
>> something like a mapping {0: 'a', 1: 'b', 2: 'x', 3: 'y'}. Seems logical,
>> since in both cases we write collection[2] and get 'x' back.

Marco, it is considered polite to give attribution to the person you are
quoting. In this case, that would be me. But it is still polite to say so.


>> But think about it a bit more, and you will see that the behaviour is in
>> fact *very different*. For example:
>>
>> the_list = ['a', 'b', 'x', 'y']
>> # the_list is equivalent to {0: 'a', 1: 'b', 2: 'x', 3: 'y'}
>> the_list.insert(0, 'z')
>> # the_list is now equivalent to {0: 'z', 1: 'a', 2: 'b', 3: 'x', 4: 'y'}
>>
>> Every existing "key:value" pair has changed! What sort of mapping
>> operates like that?
> 
> It's like you said: "Animals with four legs can usually run, eat etc. But
> birds can fly! What sort of animal flies?"
> Well. birds.

Er... okay. What's that got to do with what we are discussing?


The point you might have missed is that treating lists as if they were
mappings violates at least one critical property of mappings: that the
relationship between keys and values are stable.

Consider a simple address book, mapping between (let's say) a person's name
and their address:

address_book = {
'Fred': '123 Smiths Road',
'Ishmael': '37a Penny Lane',
'Jane': '2019 Short Street',
'Sam': '48 Main Road',
}

Now we add a new item:

address_book['Annette'] = '97 The Boulevard'

and then retrieve Jane's address. With a real mapping, like dict, then we
know what will happen:

print(address_book['Jane'])
=> prints '2019 Short Street'


Adding or deleting entries in a mapping does not affect the remaining
key:value pairs. It is absolutely critical and fundamental to mappings that
the key:value pairs are stable.

But suppose we had a mapping which lacked that stability:


print(address_book['Jane'])  # fundamentally broken mapping
=> prints '37a Penny Lane'   # the address has mysteriously changed


Do you think this would be reasonable behaviour for a mapping? I hope you
would say "No".


Now, let's imagine that we treat lists as if they were mappings, where the
index is the key:

address_book = [
'123 Smiths Road',# key = 0, Fred
'37a Penny Lane', # key = 1, Ishmael
'2019 Short Street',  # key = 2, Jane
'48 Main Road',   # key = 3, Sam
]


Now we add a new item:

address_book.insert(0, '97 The Boulevard')  # Annette

and retrieve Jane's address, using Jane's "key":

print(address_book[2])
=> prints '37a Penny Lane'


This is exactly the behaviour which (I hope) we have agreed would be broken
for a dict or other mapping. We do not have stability of "key":value pairs.
This violates the property that mapping key:value pairs should be stable.
Inserting new entries into a mapping, or deleting them, shouldn't affect
the remaining entries. But with a sequence, it can effect the relationship
between index and item.

That means that indexes are not keys, and sequences are not mappings.

For a sequence, this does not matter. There is no promise that items will
always be found at the same index you put them in. Many operations on
sequences will move items around:

sort
reverse
pop
insert
delete an item or slice
some slice assignments
shuffle

and more.




-- 
Steven

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


Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-26 Thread Ned Batchelder
On Friday, March 25, 2016 at 11:37:34 PM UTC-4, Thomas 'PointedEars' Lahn wrote:
> Chris Angelico wrote:
> 
> > On Sat, Mar 26, 2016 at 12:36 PM, Thomas 'PointedEars' Lahn
> >  wrote:
> >>> Thomas is not typical of the Python community. We are mostly nice
> >>> people.
> >>> :)
> >>
> >> You do not even know me.  I *am* a nice person, if only for the fact that
> >> I do not let people suffer from their own ignorance, and I encourage them
> >> to educate and enlighten themselves in order not be dependent on people
> >> like you who tell them what they should think.
> >>
> >> So *evidentially*, *you* are not a nice person.  According to your own
> >> "logic", *you* do not belong in the Python community.  Go away.
> > 
> > King Gama is a nicer person than you are, and in very similar ways.
> 
> I do not know a person called "King Gama", I do not think I need to know 
> them, I do not think that he is on-topic here either, and I think that you 
> should keep in mind that this is not a niceness contest, but a technical 
> newsgroup/mailing list.  I for one prefer a direct, if blunt, correct answer 
> over a nice, evading or incorrect one any time.

Thomas, you don't have to choose between correct and nice.  It's
possible to be both.

Even more important than being nice is being effective.  Do you think
your answers are achieving your goal?  Are people learning from you? Are
there ways more people could?

I can see that you are knowledgeable, and I really appreciate the energy
you put into answering questions.  You are very generous with your time.
But when you bark correct things at people, they don't hear you.  Your
helpful energy is being overshadowed by your blunt rude manner.

If your goal is to help people, you are missing the mark.  You say you
"encourage them to educate and enlighten themselves."  I haven't seen
encouragement. I've seen scolding and sneering and shaming. 

Has anyone ever thanked you for, "There is no Javascript"?  It's not
helpful, it's just pedantic.  Correct, yes; helpful? No.  Was "STFW
first" meant to be encouraging?  You have a different definition of that
word than I do.

I understand the desire to be right, and to point out incorrect things.
Heck, in writing this post I'm partly motivated by that desire.  But how
you say things has a huge effect on whether they are heard.

If you don't care if you are heard or not, then why say anything?  And
if you *do* care if you are heard or not, then you have to take into
account how people perceive you and your message.

Has anyone ever said to you, "Thanks, Thomas! Lots of people were giving
me answers, but they were all so kind and polite about it, I couldn't
see what they were saying.  Finally, your blunt direct manner got
through to me, so now I understand."  Of course not. It's absurd.
Bluntness doesn't help learning.  It just makes *you* feel good.  

Points of correctness are useless without points of connection.  You
have to talk to people in a way that they will hear.  If you can't be
bothered, then you are just wasting your time, and earning a negative
reputation for yourself.

But worse, you are tainting the reputation of this community.  Someone
comes here looking for an answer, or perhaps just comraderie, and they
get greeted by a rude condescending technocrat.  They don't just think,
"Thomas is a jerk," they think, "Python people are jerks."  That matters
a lot to me.


> See also: 

An excellent link! Have you read it? It applies to this very case. You
screwed up on this community forum.  I am telling you how you screwed
up. And what you just did is "whine about the experience, claim to have
been verbally assaulted, demand apologies, scream, ..."

ESR's post exactly describes this situation, except you don't understand
how we map onto the roles he describes.

Perhaps you (and ESR) think that because this is a technical forum, all
that matters is technical correctness.  That's wrong.  This is a place
that people communicate, and how they communicate matters.  In fact, if
they can't communicate well, then none of the technical content matters
at all.

I'm sure you've heard this criticism before.  You seem to have made up
your mind that your way is right and that all of us criticizing you are
wrong.  I hope you'll take some of these points to heart anyway.  We can
use all the helpful knowledgable people we can get.

I know I can't change you.  But I can help set the tone in this forum.
Mostly by modeling good behavior, but occasionally by directly
addressing bad behavior.

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


Re: How to make Python interpreter a little more strict?

2016-03-26 Thread Mark Lawrence

On 25/03/2016 12:06, Aleksander Alekseev wrote:

Hello

Recently I spend half an hour looking for a bug in code like this:

eax@fujitsu:~/temp$ cat ./t.py
#!/usr/bin/env python3

for x in range(0,5):
 if x % 2 == 0:
 next
 print(str(x))

eax@fujitsu:~/temp$ ./t.py
0
1
2
3
4

Is it possible to make python complain in this case? Or maybe solve
such an issue somehow else?



How does the interpreter work out that you've typed 'next' instead of 
'continue'?


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


Urgent Question Please

2016-03-26 Thread sanaaabdullah21
Hi Python developers, I am trying to click on the testInstance button using 
pywinauto but I couldn't do it, even it returns empty list when I try to print 
the controllers . Here is what I tried:
app = application.Application()
app=app.Connect(path = 
r"C:\\hdmt\\tos_2.5.2.0_release\\tosrelease\\bin\\release\\HdstSiteGuiWPF.exe")

#app.PrintControlIdentifiers()
#app['Site Controller GUI Command Center - Version 2.5.2.0 
OfflineLSM'].MenuSelect('Tools->TestInstance')

#app.top_window_().PrintControlIdentifiers()
#app.HdstSiteGuiWPF.MenuSelect("Tools->TestInstance")
#app.HdstSiteGuiWPF.PrintControlIdentifiers()
app['Site Controller GUI Command Center - Version: 2.5.2.0 
OfflineLSM'].ToolsCenter.TestInstance.Click()
#app.MenuSelect("Tools")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to make Python interpreter a little more strict?

2016-03-26 Thread Chris Warrick
On 25 March 2016 at 13:06, Aleksander Alekseev  wrote:
> Hello
>
> Recently I spend half an hour looking for a bug in code like this:
>
> eax@fujitsu:~/temp$ cat ./t.py
> #!/usr/bin/env python3
>
> for x in range(0,5):
> if x % 2 == 0:
> next
> print(str(x))
>
> eax@fujitsu:~/temp$ ./t.py
> 0
> 1
> 2
> 3
> 4
>
> Is it possible to make python complain in this case? Or maybe solve
> such an issue somehow else?
>
> --
> Best regards,
> Aleksander Alekseev
> http://eax.me/
> --
> https://mail.python.org/mailman/listinfo/python-list

You were probably looking for `continue`. This is just bad memory on
your part, and Python can’t help. In the REPL, typing an object name
is legal and helpful. Other languages might crash, sure — but they
usually don’t have a REPL like Python does.

That said, this code is designed badly. Here’s a better idea (also,
note the fixed print statement):

for x in range(0, 5):
if x % 2 != 0:
print(x)

Or even with a more suitable range() that adds 2 instead of 1 in each step:

for x in range(1, 5, 2):
print(x)

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PLEASE HELP -- TOTALLY NEW TO PYTHON

2016-03-26 Thread Mark Lawrence

On 26/03/2016 05:31, Juan Dent wrote:


I am trying to run ‘python cppdep.py’ but get the following:


analyzing dependencies among all components ...
Traceback (most recent call last):
   File "cppdep.py", line 675, in 
 main()
   File "cppdep.py", line 643, in main
 calculate_graph(digraph)
   File "cppdep.py", line 570, in calculate_graph
 (cycles, dict_node2cycle) = make_DAG(digraph, key_node)
   File "/Users/juandent/Downloads/cppdep-master/networkx_ext.py", line 79, in 
make_DAG
 for ind in range(len(subgraphs)-1, -1, -1):
TypeError: object of type 'generator' has no len()

Please, I know no python and am in a hurry to get this working… Please help

Regards,
Juan



for ind in range(len(list(subgraphs))-1, -1, -1):

However please note that the above is often a code smell in Python.  The 
usual style is:-


for item in container:
doSomething(item)

Your actual problem would translate into something like:-

for subgraph in reversed(subgraphs):
doSomething(subgraph)

--
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: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Steven D'Aprano
On Sat, 26 Mar 2016 04:30 pm, Rustom Mody wrote:

> For one thing its good to remember that we wouldn't be here without python
> Python wouldn't be what it is without CPython

There is nothing about Python that relies on the C standard being as it is.
There are Python implementations that are not written in C or C++:

Jython (Java)
IronPython (C# for .Net or Mono)
CLPython (Lisp)
Berp (Haskell)

I haven't included others (such as PyPy), as I'm not sure whether the
language they are implemented in are self-hosting or not.and  But those
four at least (in principle) don't rely on C/C++ in any way, shape or form
(except perhaps inspiration).

It is an accident of history that Python's first and major implementation
happens to be written in C. (Although its use as a glue language, allowing
people to safely use libraries written in C, probably played a role in
ensuring Python's success.)


-- 
Steven

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-26 Thread Mark Lawrence

On 26/03/2016 00:35, Marco Sulla wrote:


I'd like to see vdict implemented anyway. It can't break old code and add a
map type that has a common interface with sequences.



I cannot see this happening unless you provide a patch on the bug 
tracker.  However I suspect you can get the same thing by subclassing 
dict.  Why don't you try it and let us know how you get on?


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

2016-03-26 Thread Mark Lawrence

On 25/03/2016 16:33, Dennis Ngeno wrote:

My programs have never combile, they keep telling me , systax error even
after copy pasting



Please show us your code and the exact syntax error.  What Python 
version and OS are you using?


--
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: How to make Python interpreter a little more strict?

2016-03-26 Thread Nick Sarbicki
On Sat, Mar 26, 2016 at 9:59 AM Aleksander Alekseev 
wrote:

> Hello
>
> Recently I spend half an hour looking for a bug in code like this:
>
> eax@fujitsu:~/temp$ cat ./t.py
> #!/usr/bin/env python3
>
> for x in range(0,5):
> if x % 2 == 0:
> next
> print(str(x))
>
> eax@fujitsu:~/temp$ ./t.py
> 0
> 1
> 2
> 3
> 4
>
> Is it possible to make python complain in this case? Or maybe solve
> such an issue somehow else?
>
> --
> Best regards,
> Aleksander Alekseev
> http://eax.me/
> --
> https://mail.python.org/mailman/listinfo/python-list


What would it be complaining about?

I don't see any issues, it does what I would expect.
-- 
https://mail.python.org/mailman/listinfo/python-list


PLEASE HELP -- TOTALLY NEW TO PYTHON

2016-03-26 Thread Juan Dent

I am trying to run ‘python cppdep.py’ but get the following:


analyzing dependencies among all components ...
Traceback (most recent call last):
  File "cppdep.py", line 675, in 
main()
  File "cppdep.py", line 643, in main
calculate_graph(digraph)
  File "cppdep.py", line 570, in calculate_graph
(cycles, dict_node2cycle) = make_DAG(digraph, key_node)
  File "/Users/juandent/Downloads/cppdep-master/networkx_ext.py", line 79, in 
make_DAG
for ind in range(len(subgraphs)-1, -1, -1):
TypeError: object of type 'generator' has no len()


Please, I know no python and am in a hurry to get this working… Please help


Regards,
Juan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-03-26 Thread Marco Sulla
Peter Otten wrote:

>> I noticed that the sequence types does not have these methods that the
map
>> types  has: get(), items(), keys(), values().
>> It could seem useless to have them for sequences, but I think it will
ease
>> the creation of functions and methods that allow you to input a generic
>> iterable as parameter, but needs to use one of these methods in case the
>> parameter is a map.

> It will also break existing uses of duck typing.

Yes, I suppose it's too late to introduce these methods to sequences.

I'd like to see vdict implemented anyway. It can't break old code and add a
map type that has a common interface with sequences.
-- 
https://mail.python.org/mailman/listinfo/python-list


I need help

2016-03-26 Thread matthew thiel
So I downloaded python and made an account but when I run it all it does is 
give me 3 options repair modify and uninstall I have clicked repair and modify 
and let them run but at the end it just exit out so how do I get it to work???


Sent from Mail for Windows 10

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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-26 Thread Marco Sulla
> That's a very superficial similarity: a list ['a', 'b', 'x', 'y'] is
> something like a mapping {0: 'a', 1: 'b', 2: 'x', 3: 'y'}. Seems logical,
> since in both cases we write collection[2] and get 'x' back.
>
> But think about it a bit more, and you will see that the behaviour is in
> fact *very different*. For example:
>
> the_list = ['a', 'b', 'x', 'y']
> # the_list is equivalent to {0: 'a', 1: 'b', 2: 'x', 3: 'y'}
> the_list.insert(0, 'z')
> # the_list is now equivalent to {0: 'z', 1: 'a', 2: 'b', 3: 'x', 4: 'y'}
>
> Every existing "key:value" pair has changed! What sort of mapping operates
> like that?

It's like you said: "Animals with four legs can usually run, eat etc. But
birds can fly! What sort of animal flies?"
Well. birds.


You can easily extend dict and create a new class that imitate list, tuple
or str without any problem. Sequences are an extension of maps.


> Have you ever actually wanted to use sequences or maps indifferently? To
do
> what?

Not my code, but this is an example:
https://github.com/thieman/dagobah/blob/master/dagobah/daemon/daemon.py
def replace_nones(dict_or_list), line 27

On 23 March 2016 at 12:26, Steven D'Aprano  wrote:

> On Wed, 23 Mar 2016 06:54 am, Marco S. wrote:
>
> > I noticed that the sequence types does not have these methods that the
> map
> > types  has: get(), items(), keys(), values().
> >
> > It could seem useless to have them for sequences,
>
> That's putting it mildly.
>
> > but I think it will ease
> > the creation of functions and methods that allow you to input a generic
> > iterable as parameter, but needs to use one of these methods in case the
> > parameter is a map.
>
> Perhaps it would. But countering that is the disadvantage that you're
> adding
> methods to sequences that have no sensible meaning for a sequence.
>
> Strings and floats are quite different things, but occasionally it makes
> sense to write a function that accepts either a string or a float. Perhaps
> we could introduce methods to strings and floats to blur the difference,
> to "ease the creation of functions and methods that allow you to input a
> generic scalar (string, float, int) as parameter..."?
>
> Some of these methods would be easy:
>
> class float:
> def upper(self):
> return self
>
>
> Some a bit more work:
>
> def find(self, substring, start, end):
> s = str(self)
> return s.find(substring, start, end)
>
> but some perplex me. What would (27.25).expand_tabs() do?
>
>
> Of course this is silly. Even Perl and Javascript don't go this far in
> making floats and strings interchangeable. This is a good thing: if you're
> calling some_float.upper(), you've almost certainly made a programming
> error, and you don't want this nonsensical method call to silently succeed.
>
> So it is with sequences and mappings. They are *not* the same sort of
> thing,
> even though they have a few superficial similarities, and they shouldn't
> try to behave as the same thing.
>
> What should some_dict.append(None) do? The very concept is nonsense: dicts
> aren't *ordered sequences*, you can't append to a dict. Maybe you could
> give dicts a method *called* "append", but it wouldn't mean the same thing
> as list.append, and it probably wouldn't have the same signature:
>
>
> list.append(value)
> Appends value to the end of the list.
>
> dict.append(key, value)
> Adds a new key to the dict, with the given value.
> Same as dict[key] = value.
>
>
> Forcing these two completely different methods to have the same name
> doesn't
> do anything useful. That's like putting a door handle on your iPhone, in
> case some day you want to treat your iPhone as a door.
>
>
> > In one word, it will facilitate duck typing.
>
> I think you have misunderstood the purpose and meaning of duck-typing.
>
> Duck-typing is not about forcing unrelated, dissimilar types to have the
> same interface just in case you want to write a function that will accept
> either type.
>
> Duck-typing is about accepting anything which "quacks like a duck". If all
> you need is something which lays an egg, you shouldn't care whether it is a
> chicken or a goose or a duck. It doesn't mean that dogs and cats should
> have a "lay_egg" method, just in case somebody wants to accept a duck or a
> dog.
>
>
> > For the same reason, I would suggest the introduction of a new map type,
> > vdict, a dict that by default iterates over values instead over keys. So
> a
> > vdict object "d" wiil have iter(d) == iter(d.values()), and should also
> > have a count() method, like sequence types.
>
> I don't really see the point in this. What sort of function will expect to
> iterate over a mapping, but not care whether it is getting keys or values?
>
> Sure, there are generic functions that will iterate over *any iterable*,
> and
> you can pass dict.keys() or dict.values(), and both will work fine. That's
> exactly what duck-typing is about.
>
> But let's imagine this hypothetical function that will accept any

How to make Python interpreter a little more strict?

2016-03-26 Thread Aleksander Alekseev
Hello

Recently I spend half an hour looking for a bug in code like this:

eax@fujitsu:~/temp$ cat ./t.py 
#!/usr/bin/env python3

for x in range(0,5):
if x % 2 == 0:
next
print(str(x))

eax@fujitsu:~/temp$ ./t.py 
0
1
2
3
4

Is it possible to make python complain in this case? Or maybe solve
such an issue somehow else?

-- 
Best regards,
Aleksander Alekseev
http://eax.me/
-- 
https://mail.python.org/mailman/listinfo/python-list


Interpretation

2016-03-26 Thread Dennis Ngeno
My programs have never combile, they keep telling me , systax error even
after copy pasting
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Marko Rauhamaa
Steven D'Aprano :

> On Sat, 26 Mar 2016 03:57 am, Marko Rauhamaa wrote:
>> Yes, although the same could be true for Python as well.
>
> Is this a philosophical question? Yes, it *could* be true, in some
> alternate universe, but it isn't actually true.
>
> Python does not have undefined behaviour in the C sense. [...]

>> For example, you could have this program:
>> 
>> ===begin poof.py
>> assert 1 < 0
>> ===end poof.py==
>
> The semantics of "assert condition" are equivalent to:
>
> if __debug__:
> if not condition:
> raise AssertionError
>
> so assert is intentionally a no-op when Python runs with debug mode disabled
> (the -O command-line switch).

Thing is, some aggressive JITters might make extensive optimization
decisions based on assertions. An assertion is a developers declaration
of certain knowledge. It is there mainly to document design principles
to fellow developers (including the original coder), but since the
assertions have a formal content, the VM could allow itself to rely on
them.

For example,

def g(n):
assert type(n) is int
assert 0 <= n < 256
return (n + 1) % 256

def f(n):
return g(n)**2

The optimizer can optimize f() *knowing* its argument is an unsigned
byte.

Essentially, the JIT would boldly decide that AssertionError is never
raised.

(Although I would hate seeing such assertions routinely sprinkled
everywhere.)

> Anything else would be a bug in the interpreter or compiler.

We'll see what the JITters cook up.


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