Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Steve D'Aprano
On Sat, 8 Oct 2016 05:29 pm, Cai Gengyang wrote:

> Unfortunately, in this case, it is 100% of the information I am giving
> you. 

Exactly. That's the problem. You need to give us more information, like how
you are trying to run this code. Are you using an IDE? Which IDE?


> You can try it yourself. The code is in the first section (8.1) of 
> 
>
http://programarcadegames.com/index.php?chapter=introduction_to_animation&lang=en#section_8
> 
> Just copy and paste it into your Python IDLE and let me know what you get


I don't normally use IDLE, and you shouldn't assume that everyone does.
*That* is the extra information we need to solve the problem:

The IDLE interactive interpreter in Python 3 does not seem to allow you to
paste multiple lines at once. If you do, it highlights the first line of
code with a red background and prints the error:

SyntaxError: multiple statements found while compiling a single statement



For example:


Python 3.3.0rc3 (default, Sep 27 2012, 18:44:58) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux
Type "copyright", "credits" or "license()" for more information.
>>> # Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
SyntaxError: multiple statements found while compiling a single statement
>>> 



I can't show the colour highlighting, but the line BLACK = ... is
highlighted in red.


You can either copy and paste one line at a time, or you can use the File >
Open menu command to open a complete script.






-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Cai Gengyang
This is the result when I copy and paste it one line at a time :

>>> rect_x = 50
>>> rect_y = 50
>>> while not done: 
>>> 
  for event in pygame.event.get():  
 
  if event.type == pygame.QUIT:
  done = True
SyntaxError: invalid syntax








On Saturday, October 8, 2016 at 3:02:09 PM UTC+8, Steve D'Aprano wrote:
> On Sat, 8 Oct 2016 05:29 pm, Cai Gengyang wrote:
> 
> > Unfortunately, in this case, it is 100% of the information I am giving
> > you. 
> 
> Exactly. That's the problem. You need to give us more information, like how
> you are trying to run this code. Are you using an IDE? Which IDE?
> 
> 
> > You can try it yourself. The code is in the first section (8.1) of 
> > 
> >
> http://programarcadegames.com/index.php?chapter=introduction_to_animation&lang=en#section_8
> > 
> > Just copy and paste it into your Python IDLE and let me know what you get
> 
> 
> I don't normally use IDLE, and you shouldn't assume that everyone does.
> *That* is the extra information we need to solve the problem:
> 
> The IDLE interactive interpreter in Python 3 does not seem to allow you to
> paste multiple lines at once. If you do, it highlights the first line of
> code with a red background and prints the error:
> 
> SyntaxError: multiple statements found while compiling a single statement
> 
> 
> 
> For example:
> 
> 
> Python 3.3.0rc3 (default, Sep 27 2012, 18:44:58) 
> [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux
> Type "copyright", "credits" or "license()" for more information.
> >>> # Define some colors
> BLACK = (0, 0, 0)
> WHITE = (255, 255, 255)
> GREEN = (0, 255, 0)
> RED = (255, 0, 0)
> SyntaxError: multiple statements found while compiling a single statement
> >>> 
> 
> 
> 
> I can't show the colour highlighting, but the line BLACK = ... is
> highlighted in red.
> 
> 
> You can either copy and paste one line at a time, or you can use the File >
> Open menu command to open a complete script.
> 
> 
> 
> 
> 
> 
> -- 
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.

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


Re: define variables in the txt file using python

2016-10-08 Thread Peter Otten
Xristos Xristoou wrote:

> hello
> 
> 
> i have one .txt file and i want to create python script with sys.argv or
> argparse or other package to define some variables in the txt file and i
> take some result.
> 
> 
> 
> txt file maybe like this :
> 
> input number 1= %var1%
> input number 2= %var2%
> result = %vresult(var1-var2)%
> 
> how can i write a python script to update dynamic variables in the txt
> file ? i dont want with replace i thing so arguments is the better.

$ cat xristos.txt 
input number 1= %var1%
input number 2= %var2%
result = %vresult(var1-var2)%
$ cat xristos2.py
import argparse
import sys

parser = argparse.ArgumentParser()
parser.add_argument("infile")
parser.add_argument("vars", nargs="*")
parser.add_argument("--outfile", type=argparse.FileType("w"))
args = parser.parse_args()

ns = {}
exec("\n".join(args.vars), ns)

with open(args.infile) as f:
text = f.read()

parts = text.split("%")
for i in range(1, len(parts), 2):
parts[i] = str(eval(parts[i], ns))

print("".join(parts), file=args.outfile, end="")

$ python3 xristos2.py xristos.txt var1=42 var2=33 'def vresult(a): return 
a*a' --outfile -
input number 1= 42
input number 2= 33
result = 81

Be warned that the text file is now basically a Python script and can do 
everything a script can do -- including wiping your hard drive.

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


how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread meInvent bbird
how to refactor nested for loop into smaller for loop assume each of them 
independent?

because memory is not enough

for ii in range(1,2000):
 for jj in range(1,2000):
  for kk in range(1,2000):
print run(ii,jj,kk)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread Chris Angelico
On Sat, Oct 8, 2016 at 8:58 PM, meInvent bbird  wrote:
> how to refactor nested for loop into smaller for loop assume each of them 
> independent?
>
> because memory is not enough
>
> for ii in range(1,2000):
>  for jj in range(1,2000):
>   for kk in range(1,2000):
> print run(ii,jj,kk)

Since you're using Python 2, you could try xrange instead of range.
But it won't make a lot of difference. You're trying to call your run
function 8,000,000,000 times... that is a *lot* of function calls.
Consider a faster algorithm instead!

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


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread BartC

On 08/10/2016 11:03, Chris Angelico wrote:

On Sat, Oct 8, 2016 at 8:58 PM, meInvent bbird  wrote:

how to refactor nested for loop into smaller for loop assume each of them 
independent?

because memory is not enough

for ii in range(1,2000):
 for jj in range(1,2000):
  for kk in range(1,2000):
print run(ii,jj,kk)


Since you're using Python 2, you could try xrange instead of range.
But it won't make a lot of difference. You're trying to call your run
function 8,000,000,000 times... that is a *lot* of function calls.
Consider a faster algorithm instead!


Printing even one character 8 billion times is likely to take quite a 
few hours too.


The OP's code however is a good demonstration of how crazy Python's 
original for-range loop was: you need to construct a list of N elements 
just to be able to count to N. How many years was it until xrange was 
introduced?


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


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread Chris Angelico
On Sat, Oct 8, 2016 at 9:12 PM, BartC  wrote:
> On 08/10/2016 11:03, Chris Angelico wrote:
>>
>> On Sat, Oct 8, 2016 at 8:58 PM, meInvent bbird 
>> wrote:
>>>
>>> how to refactor nested for loop into smaller for loop assume each of them
>>> independent?
>>>
>>> because memory is not enough
>>>
>>> for ii in range(1,2000):
>>>  for jj in range(1,2000):
>>>   for kk in range(1,2000):
>>> print run(ii,jj,kk)
>>
>>
>> Since you're using Python 2, you could try xrange instead of range.
>> But it won't make a lot of difference. You're trying to call your run
>> function 8,000,000,000 times... that is a *lot* of function calls.
>> Consider a faster algorithm instead!
>
>
> Printing even one character 8 billion times is likely to take quite a few
> hours too.
>
> The OP's code however is a good demonstration of how crazy Python's original
> for-range loop was: you need to construct a list of N elements just to be
> able to count to N. How many years was it until xrange was introduced?

Hardly matters in this case. The memory usage of a list of 2000 ints is:

>>> sys.getsizeof(range(2000))
16072
>>> 2000 * sys.getsizeof(1999)
48000

About 64KB. Not overly significant. (A bit less than the naive figure
of 64,072 bytes, because the low integers are cached.) Even if run()
is defined as merely returning an empty string, it's going to take a
long time to print eight billion newlines...

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


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Rustom Mody
On Saturday, October 8, 2016 at 1:21:50 PM UTC+5:30, Cai Gengyang wrote:
> This is the result when I copy and paste it one line at a time :
> 
> >>> rect_x = 50
> >>> rect_y = 50
> >>> while not done:   
> >>> 
>  for event in ...


There's sure something strange about your formatting

you want something like this I think:

rect_x = 50
rect_y = 50
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True

On a related note in addition to Steven's 2 suggestions
- paste 1 line at a time
- Write the code in a py file

you could also try it out without Idle
ie start python at your shell (or terminal or cmd.exe or whatever)
And try it there
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread BartC

On 08/10/2016 11:54, Chris Angelico wrote:

On Sat, Oct 8, 2016 at 9:12 PM, BartC  wrote:

On 08/10/2016 11:03, Chris Angelico wrote:


On Sat, Oct 8, 2016 at 8:58 PM, meInvent bbird 
wrote:


how to refactor nested for loop into smaller for loop assume each of them
independent?

because memory is not enough

for ii in range(1,2000):
 for jj in range(1,2000):
  for kk in range(1,2000):
print run(ii,jj,kk)



Since you're using Python 2, you could try xrange instead of range.
But it won't make a lot of difference. You're trying to call your run
function 8,000,000,000 times... that is a *lot* of function calls.
Consider a faster algorithm instead!



Printing even one character 8 billion times is likely to take quite a few
hours too.

The OP's code however is a good demonstration of how crazy Python's original
for-range loop was: you need to construct a list of N elements just to be
able to count to N. How many years was it until xrange was introduced?


Hardly matters in this case. The memory usage of a list of 2000 ints is:


sys.getsizeof(range(2000))

16072

2000 * sys.getsizeof(1999)

48000



About 64KB. Not overly significant.


Well, there'll be three lots. But it's true there won't be 8 billion 
elements which is what I immediately thought when the OP said they'd run 
out of memory. So perhaps something is going on inside run() to account 
for it.


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


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread Steve D'Aprano
On Sat, 8 Oct 2016 09:12 pm, BartC wrote:

> The OP's code however is a good demonstration of how crazy Python's
> original for-range loop was: you need to construct a list of N elements
> just to be able to count to N. How many years was it until xrange was
> introduced?

Python 1.4 (that's 1996) had xrange, but I don't know when it was added.

https://docs.python.org/release/1.4/lib/node26.html#SECTION0033


The oldest version I have access to is the *extremely* primitive 0.9. Not
surprisingly, it doesn't have xrange -- but it lacks a lot of things,
including globals(), map(), named exceptions, "" strings ('' is okay),
exponentiation, and more.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread Alain Ketterlin
meInvent bbird  writes:

> how to refactor nested for loop into smaller for loop assume each of them 
> independent?
>
> because memory is not enough
>
> for ii in range(1,2000):
>  for jj in range(1,2000):
>   for kk in range(1,2000):
> print run(ii,jj,kk)

n = 0
while n < 2000*2000*2000:
ii = n // (2000*2000)
jj = ( n % (2000*2000) ) // 2000
kk = n % 2000
run(ii,jj,kk)
n += 1

or:

for n in xrange(2000*2000*2000):
ii,rr = divmod(n,2000*2000)
jj,kk = divmod(rr,2000)
run(ii,jj,kk)

(I think CPython wll fold the constants, but I haven't checked).

Are you sure this is your (real) problem?

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


Re: define variables in the txt file using python

2016-10-08 Thread Xristos Xristoou
Τη Σάββατο, 8 Οκτωβρίου 2016 - 12:25:28 π.μ. UTC+3, ο χρήστης Xristos Xristoou 
έγραψε:
> hello
> 
> 
> i have one .txt file and i want to create python script with sys.argv or 
> argparse or other package to define some variables in the txt file and i take 
> some result.
> 
> 
> 
> txt file maybe like this :
> 
> input number 1= %var1%
> input number 2= %var2%
> result = %vresult(var1-var2)%
> 
> how can i write a python script to update dynamic variables in the txt file ?
> i dont want with replace i thing so arguments is the better.

thanks Mr.Peter your code look nice,i have one question,must be running from 
cmd line ?i cant to run your code in the python script ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Cai Gengyang
Somehow it still doesnt work --- it keeps giving the syntaxerror, inconsistent 
use of tabs and indentation message EVEN though i use only the enter and space 
buttons and never touched the tab button a single time. Im pretty sure there is 
something wrong with the program itself. Gonna download pycharm and start 
testing the programs in it --- heard that it gives a better user experience 
with indentations




On Saturday, October 8, 2016 at 7:46:57 PM UTC+8, bream...@gmail.com wrote:
> On Saturday, October 8, 2016 at 12:07:47 PM UTC+1, Rustom Mody wrote:
> > On Saturday, October 8, 2016 at 1:21:50 PM UTC+5:30, Cai Gengyang wrote:
> > > This is the result when I copy and paste it one line at a time :
> > > 
> > > >>> rect_x = 50
> > > >>> rect_y = 50
> > > >>> while not done:   
> > > >>> 
> > >  for event in ...
> > 
> > 
> > There's sure something strange about your formatting
> > 
> > you want something like this I think:
> > 
> > rect_x = 50
> > rect_y = 50
> > while not done:
> > for event in pygame.event.get():
> > if event.type == pygame.QUIT:
> > done = True
> > 
> > On a related note in addition to Steven's 2 suggestions
> > - paste 1 line at a time
> > - Write the code in a py file
> > 
> > you could also try it out without Idle
> > ie start python at your shell (or terminal or cmd.exe or whatever)
> > And try it there
> 
> The easiest way is to use the ipython %paste magic command.
> 
> Kindest regards.
> 
> Mark Lawrence.

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


[ANN] aioxmpp 0.7.1 (sic!) released

2016-10-08 Thread Jonas Wielicki
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Dear subscribers,

I am pleased to announce the release of aioxmpp 0.7.1 (footnote 1). The 
current release can be obtained from GitHub [1] (check out the v0.6.0 tag or 
the master branch) or PyPI [2]. The HTML documentation can be found at [3]. 
Examples can be found in the GitHub repository, in the examples subdirectory.


aioxmpp is a Python library based on asyncio. It implements the client side of 
the XMPP protocol (RFC 6120 and others). For a more detailed description of 
the package, please review the README of the package on GitHub [1] or on PyPI 
[2]. For more information on XMPP, please see [9]. It is licensed under the 
terms of the GNU Lesser General Public License Version 3.0 or later.


The most important change in this release is the change of the license from 
GPLv3+ to LGPLv3+! (the same holds for aiosasl, which just had its v0.2.1 
release)


The functional highlights of this release are base support for Data Forms 
[XEP-0004] and a first application of those in the Multi User Chats [XEP-0045] 
implementation. Aside from that, the examples have been refactored and 
rewritten. A Quickstart section was added to the documentation [4], hopefully 
helping people to get started with aioxmpp easier.


Bugs, feature requests, patches and questions can be directed to either the
aioxmpp mailing list [5], the GitHub issue tracker [6] or the XMPP Multi-User
chat [7], whatever floats your boat. Please direct security-relevant issue
reports directly to me (jo...@wielicki.name), preferrably encrypted using my
GPG public key [8].

best regards and happy-asyncio-ing,
Jonas Wielicki


footnote 1: 0.7.0 and 0.7.1 are functionally identical. I messed up the 0.7.0 
release by forgetting to change the license in the setup.py to LGPLv3+, which 
made PyPI show the incorrect GPLv3 license.


   [1]: https://github.com/horazont/aioxmpp
   [2]: https://pypi.python.org/pypi/aioxmpp
   [3]: https://docs.zombofant.net/aioxmpp/0.7/
   [4]: https://docs.zombofant.net/aioxmpp/0.7/user-guide/quickstart.html
   [5]: https://lists.zombofant.net/mailman/listinfo/aioxmpp-devel
   [6]: https://github.com/horazont/aioxmpp/issues
   [7]: aiox...@conference.zombofant.net
   [8]: https://sks-keyservers.net/pks/lookup?op=get&search=0xE5EDE5AC679E300F
AA5A 78FF 508D 8CF4 F355  F682 E5ED E5AC 679E 300F
   [9]: https://xmpp.org/
   [XEP-0004]: https://xmpp.org/extensions/xep-0004.html
   [XEP-0045]: https://xmpp.org/extensions/xep-0045.html

-BEGIN PGP SIGNATURE-

iQIcBAEBCgAGBQJX+QpbAAoJEMBiAyWXYliKcscQALcWdCreg8kz5xxwAPq3JiiD
4K8kVL605h2JVvSFDJ83XqrR23A56gYattyg+D3jJ5/ek5ckTJwvmc39gnJOlQj+
N0KN4QqkikC5ivqSSvJItOKvBowRvCJ3qs5hdKJ93COTVPX+jbRo4swgGhLf8txj
zIQApIeKU09YiFqWZjI4WT84ovG/jmVuqAE5QWhl8Hxc6+taKNpgAgwwT/2uSF0q
wJkcbHekEeygET4xk6W858k0zNW88ybhBLS31boxsRRqcvHWyyb2DWprb4mWtI9K
aJVUJGaq+kPdyWwCctdzpEc8Pvm3yb+s34SWx0eYhNVEOmFEPc5y+D++pzIyiue1
njDl7KURTHRHyCuKxd75ekWjzB7bkdXyr1mAAn6NlUMuIYOU0Nmf6Df8BWrCO/st
vP4rPzWOOnCN30E6Q+hl1CZql68rDqoon2Le2zJe+2osljc4lm98hBwsxEXXm9ay
u4SkvTuh3GYQmjtcW4AIU5aA8s9PpusJYKLkBZOZV1vx5hSwe8ZoSEHXPOdbhdkm
25b4Vk7yLM6M4JtVn7Iq0KK9wb1pisvEFlkhpVmAMqPNhYEpjvT4nGkV98NfKKla
PpCqXiLh7Q+vD7yE7tW3Ss190QlqklMwIg2wZ/OlsJFcsTOlp0WHCgRyzKdhLcAW
1LbrAlB27J4X5NBZTK3a
=srny
-END PGP SIGNATURE-

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


Re: define variables in the txt file using python

2016-10-08 Thread Peter Otten
Xristos Xristoou wrote:

> Τη Σάββατο, 8 Οκτωβρίου 2016 - 12:25:28 π.μ. UTC+3, ο χρήστης Xristos
> Xristoou έγραψε:
>> hello
>> 
>> 
>> i have one .txt file and i want to create python script with sys.argv or
>> argparse or other package to define some variables in the txt file and i
>> take some result.
>> 
>> 
>> 
>> txt file maybe like this :
>> 
>> input number 1= %var1%
>> input number 2= %var2%
>> result = %vresult(var1-var2)%
>> 
>> how can i write a python script to update dynamic variables in the txt
>> file ? i dont want with replace i thing so arguments is the better.
> 
> thanks Mr.Peter your code look nice,i have one question,must be running
> from cmd line ?i cant to run your code in the python script ?

You said

> i have one .txt file and i want to create python script with sys.argv or
> argparse or other package to define some variables in the txt file and i
> take some result.

in your original post, so I assumed you wanted to take the arguments from 
the command line. 

Generally speaking: expect hints and code samples on this list rather than 
ready-to-use programs. If you make an effort to adapt the example script we 
will gladly help you with the parts you cannot solve yourself.

To get you started here's the gist of my previous post cast into a function:

>>> def fill_template(template, ns):
... parts = template.split("%")
... for i in range(1, len(parts), 2):
... parts[i] = str(eval(parts[i], ns))
... return "".join(parts)
... 
>>> print(fill_template("x = %var1%\ny = %var1**2%", dict(var1=22)))
x = 22
y = 484


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


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread breamoreboy
On Saturday, October 8, 2016 at 12:07:47 PM UTC+1, Rustom Mody wrote:
> On Saturday, October 8, 2016 at 1:21:50 PM UTC+5:30, Cai Gengyang wrote:
> > This is the result when I copy and paste it one line at a time :
> > 
> > >>> rect_x = 50
> > >>> rect_y = 50
> > >>> while not done: 
> > >>> 
> >  for event in ...
> 
> 
> There's sure something strange about your formatting
> 
> you want something like this I think:
> 
> rect_x = 50
> rect_y = 50
> while not done:
> for event in pygame.event.get():
> if event.type == pygame.QUIT:
> done = True
> 
> On a related note in addition to Steven's 2 suggestions
> - paste 1 line at a time
> - Write the code in a py file
> 
> you could also try it out without Idle
> ie start python at your shell (or terminal or cmd.exe or whatever)
> And try it there

The easiest way is to use the ipython %paste magic command.

Kindest regards.

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


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread Random832
On Sat, Oct 8, 2016, at 06:12, BartC wrote:
> The OP's code however is a good demonstration of how crazy Python's 
> original for-range loop was: you need to construct a list of N elements 
> just to be able to count to N. How many years was it until xrange was 
> introduced?

Python 1.4 had it, and that's the earliest version of the documentation
that exists on the website.

Python 1.0.1 does include rangeobject, with a timestamp on rangeobject.h
of 1994-01-01.

Python 0.9.1 does not.

So it was added some time between the original alt.sources posting
(February 1991) and version 1.0 (January 1994). And one could argue that
1.0 was the first "real" release of the language.

And of course, you were always free to write:

i = 0
while i < 99:
i = i + 1
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread Random832
On Sat, Oct 8, 2016, at 07:29, Steve D'Aprano wrote:
> The oldest version I have access to is the *extremely* primitive 0.9. Not
> surprisingly, it doesn't have xrange -- but it lacks a lot of things,
> including globals(), map(), named exceptions, "" strings ('' is okay),
> exponentiation, and more.

Really? I'm not sure exactly what you mean by "named exceptions", but
0.9.1 has RuntimeError, EOFError, TypeError, MemoryError, NameError,
SystemError, and KeyboardInterrupt... but exceptions aren't objects,
they're strings.

They're caught by identity, though - "except 'type error'" fails to
catch TypeError, and vice versa.

The most interesting thing that I remember noticing about python 0.9.1
is that == and != don't exist - the equality comparison operators were
<> and a context-sensitive =.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Terry Reedy

On 10/8/2016 2:56 AM, Steve D'Aprano wrote:


Just copy and paste it into your Python IDLE and let me know what you get



I don't normally use IDLE, and you shouldn't assume that everyone does.
*That* is the extra information we need to solve the problem:

The IDLE interactive interpreter in Python 3 does not seem to allow you to
paste multiple lines at once.


Actually, it does.  I pasted the following multiline statement.

>>> while not done:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop

Traceback (most recent call last):
  File "", line 1, in 
while not done:
NameError: name 'done' is not defined

ie, the single statement was compiled.


# Define some colors

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)



SyntaxError: multiple statements found while compiling a single statement


Here you pasted multiple *statements* (on separate lines).  This is a 
known difference between console and IDLE Shell.  It is partly related 
to being line versus statement oriented, partly due to window paste 
being handled by system console versus tk => tkinter => IDLE run by 
python.  Note that in a console, each line is preceded by the primary 
prompt ('>>> ').  Ditto if one types the lines into IDLE.


There has been some discussion of changing IDLE, but it would not be 
trivial.  The console splits pasted text into lines and feeds a line at 
a time to Python.  IDLE would have to intercept the pasted text before 
tk displays it, parse (split) the paste into statements (rather than 
lines), and display and run one statement at a time. I would rather 
spend the effort on making it possible to run code in a new editor 
window without explicitly saving it.


--
Terry Jan Reedy

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


delete pixel from the raster image with specific range value

2016-10-08 Thread chrischris201444
any idea how to delete pixel from the raster image with 
specific range value using numpy/scipy or gdal?

for example i have a raster image with the
5 class :

1. 0-100
2. 100-200
3. 200-300
4. 300-500
5. 500-1000

and i want to delete class 1 range value
or maybe class 1,2,4,5
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Gregory Ewing

Cai Gengyang wrote:

Somehow it still doesnt work --- it keeps giving the syntaxerror,
inconsistent use of tabs and indentation message EVEN though i use only the
enter and space buttons and never touched the tab button a single time.


There was another thread about this a short time ago.
It turns out that when you press enter in the IDLE REPL,
it auto-indents the next line -- but it does it using
*tabs*, not spaces. So if you do your manual indentation
with spaces, or paste something in that uses spaces, you
can easily end up with invalid tab/space mixtures.

The solution is to always use the tab key for indentation
when working interactively in IDLE.

I think this should be reported as a bug in IDLE, because
it's very unintuitive behaviour, and a beginner has little
chance of figuring out what's going on by themselves.

--
Greg

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


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread Chris Angelico
On Sun, Oct 9, 2016 at 5:45 AM, Random832  wrote:
> On Sat, Oct 8, 2016, at 07:29, Steve D'Aprano wrote:
>> The oldest version I have access to is the *extremely* primitive 0.9. Not
>> surprisingly, it doesn't have xrange -- but it lacks a lot of things,
>> including globals(), map(), named exceptions, "" strings ('' is okay),
>> exponentiation, and more.
>
> Really? I'm not sure exactly what you mean by "named exceptions", but
> 0.9.1 has RuntimeError, EOFError, TypeError, MemoryError, NameError,
> SystemError, and KeyboardInterrupt... but exceptions aren't objects,
> they're strings.
>
> They're caught by identity, though - "except 'type error'" fails to
> catch TypeError, and vice versa.

Fascinating! What about: except sys.intern('type error') ? Or does
interning of strings not exist yet :)

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


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread Steve D'Aprano
On Sun, 9 Oct 2016 05:45 am, Random832 wrote:

> On Sat, Oct 8, 2016, at 07:29, Steve D'Aprano wrote:
>> The oldest version I have access to is the *extremely* primitive 0.9. Not
>> surprisingly, it doesn't have xrange -- but it lacks a lot of things,
>> including globals(), map(), named exceptions, "" strings ('' is okay),
>> exponentiation, and more.
> 
> Really? I'm not sure exactly what you mean by "named exceptions", but
> 0.9.1 has RuntimeError, EOFError, TypeError, MemoryError, NameError,
> SystemError, and KeyboardInterrupt... but exceptions aren't objects,
> they're strings.

Yes, that's what I mean. I may have worded it poorly, but if you look at a
modern Python, and compare it to 0.9.1:

py> globls
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'globls' is not defined


>>> globls
Unhandled exception: undefined name: globls
Stack backtrace (innermost last):
  File "", line 1


the exception handling is different. As you say, exceptions are just
strings, and there's no exception hierarchy.


> The most interesting thing that I remember noticing about python 0.9.1
> is that == and != don't exist - the equality comparison operators were
> <> and a context-sensitive =.

And very limited choice for string delimiters: no raw strings, triple-quote
strings, or "".




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: how to refactor nested for loop into smaller for loop assume each of them independent?

2016-10-08 Thread Steve D'Aprano
On Sun, 9 Oct 2016 12:53 pm, Chris Angelico wrote:

>> They're caught by identity, though - "except 'type error'" fails to
>> catch TypeError, and vice versa.
> 
> Fascinating! What about: except sys.intern('type error') ? Or does
> interning of strings not exist yet :)

>>> intern
Unhandled exception: undefined name: intern
Stack backtrace (innermost last):
  File "", line 1
>>> import sys
>>> sys.intern
Unhandled exception: undefined name: intern
Stack backtrace (innermost last):
  File "", line 1


There's no `is` operator, or id() function, so it's impossible to tell
whether small ints and strings are interned/cached except by reading the
source. No longs (let alone unified int/long).

The weirdest thing seems to be that {} exists (and is called a dictionary,
not dict) but there's no dict builder syntax:

>>> type({})


>>> d = {'a': 1}
Parsing error: file , line 1:
d = {'a': 1}
^
Unhandled exception: run-time error: syntax error


and keys have to be strings:

>>> d = {}
>>> d[1] = 2
Unhandled exception: type error: illegal argument type for built-in
operation
Stack backtrace (innermost last):
  File "", line 1
>>> d['1'] = 2
>>> print d
{'1': 2}

There are functions (def) but not lambda, but no `class` statement.

Primitive days indeed. And yet already usable.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Cai Gengyang
This is my latest result : I copy and pasted one line at a time into the IDLE 
and used ONLY the "enter-return" button to move on to the next line and this 
time I didnt get an indentation error but instead a traceback error 

>>> rect_x = 50
>>> rect_y = 50
>>> while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True


Traceback (most recent call last):
  File "", line 1, in 
while not done:
NameError: name 'done' is not defined

















On Sunday, October 9, 2016 at 8:15:07 AM UTC+8, Gregory Ewing wrote:
> Cai Gengyang wrote:
> > Somehow it still doesnt work --- it keeps giving the syntaxerror,
> > inconsistent use of tabs and indentation message EVEN though i use only the
> > enter and space buttons and never touched the tab button a single time.
> 
> There was another thread about this a short time ago.
> It turns out that when you press enter in the IDLE REPL,
> it auto-indents the next line -- but it does it using
> *tabs*, not spaces. So if you do your manual indentation
> with spaces, or paste something in that uses spaces, you
> can easily end up with invalid tab/space mixtures.
> 
> The solution is to always use the tab key for indentation
> when working interactively in IDLE.
> 
> I think this should be reported as a bug in IDLE, because
> it's very unintuitive behaviour, and a beginner has little
> chance of figuring out what's going on by themselves.
> 
> -- 
> Greg

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


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Steve D'Aprano
On Sun, 9 Oct 2016 01:51 pm, Cai Gengyang wrote:

> This is my latest result : I copy and pasted one line at a time into the
> IDLE and used ONLY the "enter-return" button to move on to the next line
> and this time I didnt get an indentation error but instead a traceback
> error:

> Traceback (most recent call last):
>   File "", line 1, in 
> while not done:
> NameError: name 'done' is not defined

Right. 

That's because 'done' is not defined.

Why don't you try my suggestion of saving the code into a .py file, then
using the File > Open command to open it?




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Cai Gengyang
I defined both done and pygame in this piece of code, but now i get a new error 
that i have never seen before, an AttributeError


>>> rect_x = 50
>>> rect_y = 50
>>> done = False
>>> pygame = True
>>> while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
   done = True

   
Traceback (most recent call last):
  File "", line 2, in 
for event in pygame.event.get():
AttributeError: 'bool' object has no attribute 'event'









On Sunday, October 9, 2016 at 11:42:33 AM UTC+8, Steve D'Aprano wrote:
> On Sun, 9 Oct 2016 01:51 pm, Cai Gengyang wrote:
> 
> > This is my latest result : I copy and pasted one line at a time into the
> > IDLE and used ONLY the "enter-return" button to move on to the next line
> > and this time I didnt get an indentation error but instead a traceback
> > error:
> 
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > while not done:
> > NameError: name 'done' is not defined
> 
> Right. 
> 
> That's because 'done' is not defined.
> 
> Why don't you try my suggestion of saving the code into a .py file, then
> using the File > Open command to open it?
> 
> 
> 
> 
> -- 
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.

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


Re: PyQt5, OpenGL, where to start, minimal example code?

2016-10-08 Thread John Ladasky
Well, I've made some progress.  My program doesn't draw any 3D objects yet, but 
it creates an OpenGL rendering window, binds the OpenGL functions, and 
generates no errors.  Here's the corrected initializeGL method:


def initializeGL(self):
c = self.context()
f = QSurfaceFormat() # The default
p = QOpenGLVersionProfile(f)
self.GL = c.versionFunctions(p)
super().initializeGL()



On Tuesday, October 4, 2016 at 12:56:53 AM UTC-7, Phil Thompson wrote:
> On 4 Oct 2016, at 5:57 am, John Ladasky  wrote:
> > 
> > On Monday, October 3, 2016 at 1:30:29 AM UTC-7, Phil Thompson wrote:
> >> On 3 Oct 2016, at 4:29 am, John Ladasky  wrote:
> > If I ever understand a GUI like PyQt5 well enough, I'd like to contribute 
> > to its documentation.  Sigh.
> 
> If you are an OpenGL expert 

Ha!  

While I have experience with quite a few scientific computing Python tools 
(numpy, scipy, matplotlib, pandas, scikit-learn), I know less about OpenGL than 
I do PyQt5.  There's always more to learn.

>then you could help a lot by answering my questions about how individual 
>functions should be bound.

In all the examples I've encountered on the Net (most of which are written in 
C++ -- or if they are PyQt examples, they're binding older versions of OpenGL), 
the preferred approach seems to be the one that I've taken above.  If you want 
to call an OpenGL function, you have to look it up in the self.GL namespace.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Terry Reedy

On 10/8/2016 11:51 PM, Cai Gengyang wrote:


pygame = True
while not done:

for event in pygame.event.get():



Traceback (most recent call last):
  File "", line 2, in 
for event in pygame.event.get():
AttributeError: 'bool' object has no attribute 'event'


pygame == True and True has not attribute 'event'.  Believe the error 
messages until you have real reason to question them.  They are perhaps 
99.9% accurate by now/


--
Terry Jan Reedy

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


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Steve D'Aprano
On Sun, 9 Oct 2016 02:51 pm, Cai Gengyang wrote:

> I defined both done and pygame in this piece of code, but now i get a new
> error that i have never seen before, an AttributeError

AttributeError usually means you have the wrong kind of object:

py> mylist = {}  # oops, a dict not a list
py> mylist.append(1)
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'dict' object has no attribute 'append'


or sometimes you have the right object but misspelled the attribute or
method:

py> mylist = []
py> mylist.apend(1)  # oops, spelling error
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'list' object has no attribute 'apend'
py> mylist.append(1)
py> print(mylist)
[1]



 rect_x = 50
 rect_y = 50
 done = False
 pygame = True

Why have you defined pygame = True? Is that what the code on the website
does?

My guess is that you are supposed to say:

import pygame



Why don't you try my suggestion of saving the code into a .py file, then
using the File > Open command to open it?




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: SyntaxError: multiple statements found while compiling a single statement

2016-10-08 Thread Rustom Mody
On Sunday, October 9, 2016 at 12:12:06 PM UTC+5:30, Steve D'Aprano wrote:
> On Sun, 9 Oct 2016 02:51 pm, Cai Gengyang wrote:
> 
> > I defined both done and pygame in this piece of code, but now i get a new
> > error that i have never seen before, an AttributeError
> 
> AttributeError usually means you have the wrong kind of object:
> 
> py> mylist = {}  # oops, a dict not a list
> py> mylist.append(1)
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'dict' object has no attribute 'append'
> 
> 
> or sometimes you have the right object but misspelled the attribute or
> method:
> 
> py> mylist = []
> py> mylist.apend(1)  # oops, spelling error
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'list' object has no attribute 'apend'
> py> mylist.append(1)
> py> print(mylist)
> [1]
> 
> 
> 
>  rect_x = 50
>  rect_y = 50
>  done = False
>  pygame = True
> 
> Why have you defined pygame = True? Is that what the code on the website
> does?
> 
> My guess is that you are supposed to say:
> 
> import pygame
> 
> 
> 
> Why don't you try my suggestion of saving the code into a .py file, then
> using the File > Open command to open it?

One meta-suggestion: 
It may be that with python you can go further in less time than with
older languages like C++, Java etc.

But less time doesn’t mean no time — You still need to learn, to walk the 
learning curve

In short: Dont skimp on the tutorial: https://docs.python.org/3/tutorial/
even (especially) if you find the examples uninteresting/irrelevant
-- 
https://mail.python.org/mailman/listinfo/python-list