Re: Not found in the documentation

2021-04-30 Thread elas tica


> > the docs are wrong when they say: 
> > 
> > .. 
> > using a backslash). A backslash is illegal elsewhere on a line outside a 
> > string literal. 
> > .. 
> >
> You're not passing a backslash. Try print(s). 
> It would be different with a raw string 
> 
> s=r"""42 not\ 
> in [42]""" 
> 

Good catch Christian. Here the complete corrected code:

# --
from tokenize import tokenize
from io import BytesIO

s = r"""42 not\
 in [42]"""
g = tokenize(BytesIO(s.encode('utf-8')).readline)
print(*(g), sep='\n')
# --

outputting now:

..
TokenInfo(type=57 (ENCODING), string='utf-8', start=(0, 0), end=(0, 0), line='')
TokenInfo(type=2 (NUMBER), string='42', start=(1, 0), end=(1, 2), line='42 not 
in [42]')
TokenInfo(type=1 (NAME), string='not', start=(1, 3), end=(1, 6), line='42 not 
in [42]')
TokenInfo(type=1 (NAME), string='in', start=(1, 7), end=(1, 9), line='42 not in 
[42]')
TokenInfo(type=53 (OP), string='[', start=(1, 10), end=(1, 11), line='42 not in 
[42]')
TokenInfo(type=2 (NUMBER), string='42', start=(1, 11), end=(1, 13), line='42 
not in [42]')
TokenInfo(type=53 (OP), string=']', start=(1, 13), end=(1, 14), line='42 not in 
[42]')
TokenInfo(type=4 (NEWLINE), string='', start=(1, 14), end=(1, 15), line='')
TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='')
..

but this doesn't seem to change the conclusion.
-- 
https://mail.python.org/mailman/listinfo/python-list


text displays on screen only when I click to exit the program

2021-04-30 Thread Quentin Bock
code with comments for context:

#Create a text based game where the user must find 3 items before
completing a level
#imports and variables for game
import pygame
from pygame import mixer
running = True
#initializes pygame
pygame.init()

#creates the pygame window
screen = pygame.display.set_mode((1200, 800))

#Title and Icon of window
pygame.display.set_caption("3.02 Project")
icon = pygame.image.load('3.02 icon.png')
pygame.display.set_icon(icon)

#setting up font
pygame.font.init()
font = pygame.font.Font('C:\Windows\Fonts\OCRAEXT.ttf', 16)
font_x = 10
font_y = 40
items_picked_up = 0
items_left = 3

#functions to be called later in program
def display_instruction(x, y):
instructions = font.render("Each level contains 3 items you must pick
up in each room."
   "When you have picked up 3 items, you will
advance to the next room, there are 3 rooms.", True, (255, 255, 255))
screen.blit(instructions, (10, 40))

def main():
global running

#Game Loop
while running:
#sets screen color to black
screen.fill((0, 0, 0))

#checks if the user quits or exits the window
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

display_instruction(font_x, font_y)
pygame.display.update()


main()



please excuse the def main() thing, this doesn't follow a tutorial this is
all on my own, and I don't know why the text displays when I close the
python window.
I appreciate all help :)


Virus-free.
www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: text displays on screen only when I click to exit the program

2021-04-30 Thread Mirko via Python-list
Am 30.04.2021 um 20:55 schrieb Quentin Bock:
> code with comments for context:
> 
> #Create a text based game where the user must find 3 items before
> completing a level
> #imports and variables for game
> import pygame
> from pygame import mixer
> running = True
> #initializes pygame
> pygame.init()
> 
> #creates the pygame window
> screen = pygame.display.set_mode((1200, 800))
> 
> #Title and Icon of window
> pygame.display.set_caption("3.02 Project")
> icon = pygame.image.load('3.02 icon.png')
> pygame.display.set_icon(icon)
> 
> #setting up font
> pygame.font.init()
> font = pygame.font.Font('C:\Windows\Fonts\OCRAEXT.ttf', 16)
> font_x = 10
> font_y = 40
> items_picked_up = 0
> items_left = 3
> 
> #functions to be called later in program
> def display_instruction(x, y):
> instructions = font.render("Each level contains 3 items you must pick
> up in each room."
>"When you have picked up 3 items, you will
> advance to the next room, there are 3 rooms.", True, (255, 255, 255))
> screen.blit(instructions, (10, 40))
> 
> def main():
> global running
> 
> #Game Loop
> while running:
> #sets screen color to black
> screen.fill((0, 0, 0))
> 
> #checks if the user quits or exits the window
> for event in pygame.event.get():
> if event.type == pygame.QUIT:
> running = False
> 
> display_instruction(font_x, font_y)
> pygame.display.update()
> 
> 
> main()
> 
> 
> 
> please excuse the def main() thing, this doesn't follow a tutorial this is
> all on my own, and I don't know why the text displays when I close the
> python window.
> I appreciate all help :)


Because you are calling display_instruction() and
pygame.display.update() outside of the game loop. Try to indent
those two lines one level more.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Start Python programming

2021-04-30 Thread Russell via Python-list
Gazoo  wrote:
> 
> 
> I'd like to start learning Python programming. What sites/tutorials
> could you recommend for beginner, please.
> 

I liked the book found at https://automatetheboringstuff.com/

You can read the whole book online. I think you used to be able to
download a copy too. It has lots of practical examples and is easy to
read/follow.

-- 
rust
0x68caecc97f6a90122e51c0692c88d9cb6b58a3dc
-- 
https://mail.python.org/mailman/listinfo/python-list


Decoratored functions parsed differently by ast stdlib between 3.7 and 3.8

2021-04-30 Thread Mike Lee Williams
This trivial bit of code is parsed differently by the ast module between python
3.7 and python 3.8. I'm trying to figure out what changed and why, and once I
know that, if it's possible and desirable to retain the 3.7 behavior for my use
case (which needs to give the same result for this input on 3.7 and 3.8).

Here's the bit of python code:

@hello
def f(): pass

And here's a script to parse it with ast from the standard library

import ast

code = "@hello\ndef f(): pass"

p = ast.parse(code)

for t in p.body:
print(t.lineno)

And here's the problem

$ python3.8 parse.py
2

$ python3.7 parse.py
1

I don't understand why this output differs between 3.7 and 3.8. It seems 3.8 is
ignoring the decorator somehow? The node has hello in decorator_list, so it's
there in the ast. But it's counting lines differently.

Passing the new passing feature_version=(3, 7) keyword argument introduced to
3.7 to ast.parse does not restore the 3.7 behavior in 3.8 so I'm assuming this
is not a python language grammar change but rather an ast API change (or a
bug?!)

The release notes for 3.8 mention AST, but none of the changes look relevant
as they all refer to typing https://docs.python.org/3/whatsnew/3.8.html#ast

So: what changed? Why? Can I and should I try to get the old behavior back?

Thanks!
Mike Lee Williams
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Decoratored functions parsed differently by ast stdlib between 3.7 and 3.8

2021-04-30 Thread Mike Lee Williams
On Friday, April 30, 2021 at 7:55:10 PM UTC-7, Mike Lee Williams wrote:
> This trivial bit of code is parsed differently by the ast module between 
> python 
> 3.7 and python 3.8. I'm trying to figure out what changed and why, and once I 
> know that, if it's possible and desirable to retain the 3.7 behavior for my 
> use 
> case (which needs to give the same result for this input on 3.7 and 3.8). 

Answering my own question: the behavior was changed by 
https://github.com/python/cpython/pull/9731.
-- 
https://mail.python.org/mailman/listinfo/python-list