Coding a game /u/ArtistName Python Education

Coding a game /u/ArtistName Python Education

Me and my friend are making a little space shooter games for our end of semester school project. We are using codeHS. Although, our game ends after we score once. It just freezes.

This is our code: import tkinter as tk import random

Constants

WIDTH = 600 HEIGHT = 800 PLAYER_WIDTH = 50 PLAYER_HEIGHT = 50 ENEMY_WIDTH = 50 ENEMY_HEIGHT = 50 BULLET_WIDTH = 5 BULLET_HEIGHT = 10 PLAYER_SPEED = 20 BULLET_SPEED = 15 ENEMY_SPEED = 5 POWERUP_WIDTH = 20 POWERUP_HEIGHT = 20 POWERUP_SPEED = 3

class ShootingGame: def init(self, root): self.root = root self.root.resizable(False, False) # Added this line self.canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg=”black”) self.canvas.pack() self.powerups = [] self.power_active = False self.power_timer = 0 self.power_type = None

 # Player setup with adjusted position self.player = self.canvas.create_rectangle( WIDTH // 2 - PLAYER_WIDTH // 2, # X start HEIGHT - PLAYER_HEIGHT - 20, # Y start - moved higher up WIDTH // 2 + PLAYER_WIDTH // 2, # X end HEIGHT - 20, # Y end fill="yellow", outline="white", width=3 ) # Debug print for player coordinates player_coords = self.canvas.coords(self.player) print(f"Player coordinates: {player_coords}") # List for bullets and enemies self.bullets = [] self.enemies = [] # Score self.score = 0 self.score_text = self.canvas.create_text( 10, 10, anchor="nw", text=f"Score: {self.score}", fill="white", font=("Arial", 16) ) # Controls self.root.bind("<Left>", self.move_left) self.root.bind("<Right>", self.move_right) self.root.bind("<space>", self.shoot_bullet) # Start game loop self.running = True self.update_game() def move_left(self, event): if self.canvas.coords(self.player)[0] > 0: self.canvas.move(self.player, -PLAYER_SPEED, 0) def move_right(self, event): if self.canvas.coords(self.player)[2] < WIDTH: self.canvas.move(self.player, PLAYER_SPEED, 0) def shoot_bullet(self, event): x1, y1, x2, y2 = self.canvas.coords(self.player) bullet = self.canvas.create_rectangle( (x1 + x2) // 2 - BULLET_WIDTH // 2, y1 - BULLET_HEIGHT, (x1 + x2) // 2 + BULLET_WIDTH // 2, y1, fill="white" ) self.bullets.append(bullet) def spawn_enemy(self): x = random.randint(0, WIDTH - ENEMY_WIDTH) enemy = self.canvas.create_rectangle( x, 0, x + ENEMY_WIDTH, ENEMY_HEIGHT, fill="red" ) self.enemies.append(enemy) def update_bullets(self): for bullet in self.bullets[:]: self.canvas.move(bullet, 0, -BULLET_SPEED) if self.canvas.coords(bullet)[1] < 0: self.canvas.delete(bullet) self.bullets.remove(bullet) def update_enemies(self): for enemy in self.enemies[:]: self.canvas.move(enemy, 0, ENEMY_SPEED) if self.canvas.coords(enemy)[3] >= HEIGHT: self.running = False self.canvas.create_text( WIDTH // 2, HEIGHT // 2, text="GAME OVER", fill="white", font=("Arial", 40) ) for bullet in self.bullets[:]: if self.check_collision(enemy, bullet): self.canvas.delete(enemy) self.canvas.delete(bullet) self.enemies.remove(enemy) self.bullets.remove(bullet) self.score += 1 self.canvas.itemconfig(self.score_text, text=f"Score: {self.score}") def check_collision(self, enemy, bullet): e_coords = self.canvas.coords(enemy) b_coords = self.canvas.coords(bullet) return not ( e_coords[2] < b_coords[0] or e_coords[0] > b_coords[2] or e_coords[3] < b_coords[1] or e_coords[1] > b_coords[3] ) def update_game(self): if not self.running: return if random.randint(1, 50) == 1: self.spawn_enemy() self.update_bullets() self.update_enemies() self.root.after(50, self.update_game) # Different power-up types and their colors self.powerup_types = { "double_shot": "blue", "speed_boost": "green", "shield": "purple" } def spawn_powerup(self): x = random.randint(0, WIDTH - POWERUP_WIDTH) power_type = random.choice(list(self.powerup_types.keys())) color = self.powerup_types[power_type] powerup = self.canvas.create_oval( x, 0, x + POWERUP_WIDTH, POWERUP_HEIGHT, fill=color, outline="white" ) self.powerups.append({"item": powerup, "type": power_type}) def update_powerups(self): for powerup in self.powerups[:]: self.canvas.move(powerup["item"], 0, POWERUP_SPEED) # Check if powerup is off screen if self.canvas.coords(powerup["item"])[3] >= HEIGHT: self.canvas.delete(powerup["item"]) self.powerups.remove(powerup) continue # Check collision with player if self.check_collision_with_player(powerup["item"]): self.activate_powerup(powerup["type"]) self.canvas.delete(powerup["item"]) self.powerups.remove(powerup) def check_collision_with_player(self, item): p_coords = self.canvas.coords(self.player) i_coords = self.canvas.coords(item) return not ( i_coords[2] < p_coords[0] or i_coords[0] > p_coords[2] or i_coords[3] < p_coords[1] or i_coords[1] > p_coords[3] ) def activate_powerup(self, power_type): self.power_active = True self.power_type = power_type self.power_timer = 100 # Power-up lasts for 100 game ticks if power_type == "speed_boost": global PLAYER_SPEED PLAYER_SPEED *= 2 def update_power_status(self): if self.power_active: self.power_timer -= 1 if self.power_timer <= 0: self.deactivate_powerup() 

if name == “main“: root = tk.Tk() root.title(“Shooting Game”) game = ShootingGame(root) root.mainloop()

Any tips?

submitted by /u/ArtistName
[link] [comments]

​r/learnpython Me and my friend are making a little space shooter games for our end of semester school project. We are using codeHS. Although, our game ends after we score once. It just freezes. This is our code: import tkinter as tk import random Constants WIDTH = 600 HEIGHT = 800 PLAYER_WIDTH = 50 PLAYER_HEIGHT = 50 ENEMY_WIDTH = 50 ENEMY_HEIGHT = 50 BULLET_WIDTH = 5 BULLET_HEIGHT = 10 PLAYER_SPEED = 20 BULLET_SPEED = 15 ENEMY_SPEED = 5 POWERUP_WIDTH = 20 POWERUP_HEIGHT = 20 POWERUP_SPEED = 3 class ShootingGame: def init(self, root): self.root = root self.root.resizable(False, False) # Added this line self.canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg=”black”) self.canvas.pack() self.powerups = [] self.power_active = False self.power_timer = 0 self.power_type = None # Player setup with adjusted position self.player = self.canvas.create_rectangle( WIDTH // 2 – PLAYER_WIDTH // 2, # X start HEIGHT – PLAYER_HEIGHT – 20, # Y start – moved higher up WIDTH // 2 + PLAYER_WIDTH // 2, # X end HEIGHT – 20, # Y end fill=”yellow”, outline=”white”, width=3 ) # Debug print for player coordinates player_coords = self.canvas.coords(self.player) print(f”Player coordinates: {player_coords}”) # List for bullets and enemies self.bullets = [] self.enemies = [] # Score self.score = 0 self.score_text = self.canvas.create_text( 10, 10, anchor=”nw”, text=f”Score: {self.score}”, fill=”white”, font=(“Arial”, 16) ) # Controls self.root.bind(“<Left>”, self.move_left) self.root.bind(“<Right>”, self.move_right) self.root.bind(“<space>”, self.shoot_bullet) # Start game loop self.running = True self.update_game() def move_left(self, event): if self.canvas.coords(self.player)[0] > 0: self.canvas.move(self.player, -PLAYER_SPEED, 0) def move_right(self, event): if self.canvas.coords(self.player)[2] < WIDTH: self.canvas.move(self.player, PLAYER_SPEED, 0) def shoot_bullet(self, event): x1, y1, x2, y2 = self.canvas.coords(self.player) bullet = self.canvas.create_rectangle( (x1 + x2) // 2 – BULLET_WIDTH // 2, y1 – BULLET_HEIGHT, (x1 + x2) // 2 + BULLET_WIDTH // 2, y1, fill=”white” ) self.bullets.append(bullet) def spawn_enemy(self): x = random.randint(0, WIDTH – ENEMY_WIDTH) enemy = self.canvas.create_rectangle( x, 0, x + ENEMY_WIDTH, ENEMY_HEIGHT, fill=”red” ) self.enemies.append(enemy) def update_bullets(self): for bullet in self.bullets[:]: self.canvas.move(bullet, 0, -BULLET_SPEED) if self.canvas.coords(bullet)[1] < 0: self.canvas.delete(bullet) self.bullets.remove(bullet) def update_enemies(self): for enemy in self.enemies[:]: self.canvas.move(enemy, 0, ENEMY_SPEED) if self.canvas.coords(enemy)[3] >= HEIGHT: self.running = False self.canvas.create_text( WIDTH // 2, HEIGHT // 2, text=”GAME OVER”, fill=”white”, font=(“Arial”, 40) ) for bullet in self.bullets[:]: if self.check_collision(enemy, bullet): self.canvas.delete(enemy) self.canvas.delete(bullet) self.enemies.remove(enemy) self.bullets.remove(bullet) self.score += 1 self.canvas.itemconfig(self.score_text, text=f”Score: {self.score}”) def check_collision(self, enemy, bullet): e_coords = self.canvas.coords(enemy) b_coords = self.canvas.coords(bullet) return not ( e_coords[2] < b_coords[0] or e_coords[0] > b_coords[2] or e_coords[3] < b_coords[1] or e_coords[1] > b_coords[3] ) def update_game(self): if not self.running: return if random.randint(1, 50) == 1: self.spawn_enemy() self.update_bullets() self.update_enemies() self.root.after(50, self.update_game) # Different power-up types and their colors self.powerup_types = { “double_shot”: “blue”, “speed_boost”: “green”, “shield”: “purple” } def spawn_powerup(self): x = random.randint(0, WIDTH – POWERUP_WIDTH) power_type = random.choice(list(self.powerup_types.keys())) color = self.powerup_types[power_type] powerup = self.canvas.create_oval( x, 0, x + POWERUP_WIDTH, POWERUP_HEIGHT, fill=color, outline=”white” ) self.powerups.append({“item”: powerup, “type”: power_type}) def update_powerups(self): for powerup in self.powerups[:]: self.canvas.move(powerup[“item”], 0, POWERUP_SPEED) # Check if powerup is off screen if self.canvas.coords(powerup[“item”])[3] >= HEIGHT: self.canvas.delete(powerup[“item”]) self.powerups.remove(powerup) continue # Check collision with player if self.check_collision_with_player(powerup[“item”]): self.activate_powerup(powerup[“type”]) self.canvas.delete(powerup[“item”]) self.powerups.remove(powerup) def check_collision_with_player(self, item): p_coords = self.canvas.coords(self.player) i_coords = self.canvas.coords(item) return not ( i_coords[2] < p_coords[0] or i_coords[0] > p_coords[2] or i_coords[3] < p_coords[1] or i_coords[1] > p_coords[3] ) def activate_powerup(self, power_type): self.power_active = True self.power_type = power_type self.power_timer = 100 # Power-up lasts for 100 game ticks if power_type == “speed_boost”: global PLAYER_SPEED PLAYER_SPEED *= 2 def update_power_status(self): if self.power_active: self.power_timer -= 1 if self.power_timer <= 0: self.deactivate_powerup() if name == “main”: root = tk.Tk() root.title(“Shooting Game”) game = ShootingGame(root) root.mainloop() Any tips? submitted by /u/ArtistName [link] [comments] 

Me and my friend are making a little space shooter games for our end of semester school project. We are using codeHS. Although, our game ends after we score once. It just freezes.

This is our code: import tkinter as tk import random

Constants

WIDTH = 600 HEIGHT = 800 PLAYER_WIDTH = 50 PLAYER_HEIGHT = 50 ENEMY_WIDTH = 50 ENEMY_HEIGHT = 50 BULLET_WIDTH = 5 BULLET_HEIGHT = 10 PLAYER_SPEED = 20 BULLET_SPEED = 15 ENEMY_SPEED = 5 POWERUP_WIDTH = 20 POWERUP_HEIGHT = 20 POWERUP_SPEED = 3

class ShootingGame: def init(self, root): self.root = root self.root.resizable(False, False) # Added this line self.canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg=”black”) self.canvas.pack() self.powerups = [] self.power_active = False self.power_timer = 0 self.power_type = None

 # Player setup with adjusted position self.player = self.canvas.create_rectangle( WIDTH // 2 - PLAYER_WIDTH // 2, # X start HEIGHT - PLAYER_HEIGHT - 20, # Y start - moved higher up WIDTH // 2 + PLAYER_WIDTH // 2, # X end HEIGHT - 20, # Y end fill="yellow", outline="white", width=3 ) # Debug print for player coordinates player_coords = self.canvas.coords(self.player) print(f"Player coordinates: {player_coords}") # List for bullets and enemies self.bullets = [] self.enemies = [] # Score self.score = 0 self.score_text = self.canvas.create_text( 10, 10, anchor="nw", text=f"Score: {self.score}", fill="white", font=("Arial", 16) ) # Controls self.root.bind("<Left>", self.move_left) self.root.bind("<Right>", self.move_right) self.root.bind("<space>", self.shoot_bullet) # Start game loop self.running = True self.update_game() def move_left(self, event): if self.canvas.coords(self.player)[0] > 0: self.canvas.move(self.player, -PLAYER_SPEED, 0) def move_right(self, event): if self.canvas.coords(self.player)[2] < WIDTH: self.canvas.move(self.player, PLAYER_SPEED, 0) def shoot_bullet(self, event): x1, y1, x2, y2 = self.canvas.coords(self.player) bullet = self.canvas.create_rectangle( (x1 + x2) // 2 - BULLET_WIDTH // 2, y1 - BULLET_HEIGHT, (x1 + x2) // 2 + BULLET_WIDTH // 2, y1, fill="white" ) self.bullets.append(bullet) def spawn_enemy(self): x = random.randint(0, WIDTH - ENEMY_WIDTH) enemy = self.canvas.create_rectangle( x, 0, x + ENEMY_WIDTH, ENEMY_HEIGHT, fill="red" ) self.enemies.append(enemy) def update_bullets(self): for bullet in self.bullets[:]: self.canvas.move(bullet, 0, -BULLET_SPEED) if self.canvas.coords(bullet)[1] < 0: self.canvas.delete(bullet) self.bullets.remove(bullet) def update_enemies(self): for enemy in self.enemies[:]: self.canvas.move(enemy, 0, ENEMY_SPEED) if self.canvas.coords(enemy)[3] >= HEIGHT: self.running = False self.canvas.create_text( WIDTH // 2, HEIGHT // 2, text="GAME OVER", fill="white", font=("Arial", 40) ) for bullet in self.bullets[:]: if self.check_collision(enemy, bullet): self.canvas.delete(enemy) self.canvas.delete(bullet) self.enemies.remove(enemy) self.bullets.remove(bullet) self.score += 1 self.canvas.itemconfig(self.score_text, text=f"Score: {self.score}") def check_collision(self, enemy, bullet): e_coords = self.canvas.coords(enemy) b_coords = self.canvas.coords(bullet) return not ( e_coords[2] < b_coords[0] or e_coords[0] > b_coords[2] or e_coords[3] < b_coords[1] or e_coords[1] > b_coords[3] ) def update_game(self): if not self.running: return if random.randint(1, 50) == 1: self.spawn_enemy() self.update_bullets() self.update_enemies() self.root.after(50, self.update_game) # Different power-up types and their colors self.powerup_types = { "double_shot": "blue", "speed_boost": "green", "shield": "purple" } def spawn_powerup(self): x = random.randint(0, WIDTH - POWERUP_WIDTH) power_type = random.choice(list(self.powerup_types.keys())) color = self.powerup_types[power_type] powerup = self.canvas.create_oval( x, 0, x + POWERUP_WIDTH, POWERUP_HEIGHT, fill=color, outline="white" ) self.powerups.append({"item": powerup, "type": power_type}) def update_powerups(self): for powerup in self.powerups[:]: self.canvas.move(powerup["item"], 0, POWERUP_SPEED) # Check if powerup is off screen if self.canvas.coords(powerup["item"])[3] >= HEIGHT: self.canvas.delete(powerup["item"]) self.powerups.remove(powerup) continue # Check collision with player if self.check_collision_with_player(powerup["item"]): self.activate_powerup(powerup["type"]) self.canvas.delete(powerup["item"]) self.powerups.remove(powerup) def check_collision_with_player(self, item): p_coords = self.canvas.coords(self.player) i_coords = self.canvas.coords(item) return not ( i_coords[2] < p_coords[0] or i_coords[0] > p_coords[2] or i_coords[3] < p_coords[1] or i_coords[1] > p_coords[3] ) def activate_powerup(self, power_type): self.power_active = True self.power_type = power_type self.power_timer = 100 # Power-up lasts for 100 game ticks if power_type == "speed_boost": global PLAYER_SPEED PLAYER_SPEED *= 2 def update_power_status(self): if self.power_active: self.power_timer -= 1 if self.power_timer <= 0: self.deactivate_powerup() 

if name == “main“: root = tk.Tk() root.title(“Shooting Game”) game = ShootingGame(root) root.mainloop()

Any tips?

submitted by /u/ArtistName
[link] [comments]  Me and my friend are making a little space shooter games for our end of semester school project. We are using codeHS. Although, our game ends after we score once. It just freezes. This is our code: import tkinter as tk import random Constants WIDTH = 600 HEIGHT = 800 PLAYER_WIDTH = 50 PLAYER_HEIGHT = 50 ENEMY_WIDTH = 50 ENEMY_HEIGHT = 50 BULLET_WIDTH = 5 BULLET_HEIGHT = 10 PLAYER_SPEED = 20 BULLET_SPEED = 15 ENEMY_SPEED = 5 POWERUP_WIDTH = 20 POWERUP_HEIGHT = 20 POWERUP_SPEED = 3 class ShootingGame: def init(self, root): self.root = root self.root.resizable(False, False) # Added this line self.canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg=”black”) self.canvas.pack() self.powerups = [] self.power_active = False self.power_timer = 0 self.power_type = None # Player setup with adjusted position self.player = self.canvas.create_rectangle( WIDTH // 2 – PLAYER_WIDTH // 2, # X start HEIGHT – PLAYER_HEIGHT – 20, # Y start – moved higher up WIDTH // 2 + PLAYER_WIDTH // 2, # X end HEIGHT – 20, # Y end fill=”yellow”, outline=”white”, width=3 ) # Debug print for player coordinates player_coords = self.canvas.coords(self.player) print(f”Player coordinates: {player_coords}”) # List for bullets and enemies self.bullets = [] self.enemies = [] # Score self.score = 0 self.score_text = self.canvas.create_text( 10, 10, anchor=”nw”, text=f”Score: {self.score}”, fill=”white”, font=(“Arial”, 16) ) # Controls self.root.bind(“<Left>”, self.move_left) self.root.bind(“<Right>”, self.move_right) self.root.bind(“<space>”, self.shoot_bullet) # Start game loop self.running = True self.update_game() def move_left(self, event): if self.canvas.coords(self.player)[0] > 0: self.canvas.move(self.player, -PLAYER_SPEED, 0) def move_right(self, event): if self.canvas.coords(self.player)[2] < WIDTH: self.canvas.move(self.player, PLAYER_SPEED, 0) def shoot_bullet(self, event): x1, y1, x2, y2 = self.canvas.coords(self.player) bullet = self.canvas.create_rectangle( (x1 + x2) // 2 – BULLET_WIDTH // 2, y1 – BULLET_HEIGHT, (x1 + x2) // 2 + BULLET_WIDTH // 2, y1, fill=”white” ) self.bullets.append(bullet) def spawn_enemy(self): x = random.randint(0, WIDTH – ENEMY_WIDTH) enemy = self.canvas.create_rectangle( x, 0, x + ENEMY_WIDTH, ENEMY_HEIGHT, fill=”red” ) self.enemies.append(enemy) def update_bullets(self): for bullet in self.bullets[:]: self.canvas.move(bullet, 0, -BULLET_SPEED) if self.canvas.coords(bullet)[1] < 0: self.canvas.delete(bullet) self.bullets.remove(bullet) def update_enemies(self): for enemy in self.enemies[:]: self.canvas.move(enemy, 0, ENEMY_SPEED) if self.canvas.coords(enemy)[3] >= HEIGHT: self.running = False self.canvas.create_text( WIDTH // 2, HEIGHT // 2, text=”GAME OVER”, fill=”white”, font=(“Arial”, 40) ) for bullet in self.bullets[:]: if self.check_collision(enemy, bullet): self.canvas.delete(enemy) self.canvas.delete(bullet) self.enemies.remove(enemy) self.bullets.remove(bullet) self.score += 1 self.canvas.itemconfig(self.score_text, text=f”Score: {self.score}”) def check_collision(self, enemy, bullet): e_coords = self.canvas.coords(enemy) b_coords = self.canvas.coords(bullet) return not ( e_coords[2] < b_coords[0] or e_coords[0] > b_coords[2] or e_coords[3] < b_coords[1] or e_coords[1] > b_coords[3] ) def update_game(self): if not self.running: return if random.randint(1, 50) == 1: self.spawn_enemy() self.update_bullets() self.update_enemies() self.root.after(50, self.update_game) # Different power-up types and their colors self.powerup_types = { “double_shot”: “blue”, “speed_boost”: “green”, “shield”: “purple” } def spawn_powerup(self): x = random.randint(0, WIDTH – POWERUP_WIDTH) power_type = random.choice(list(self.powerup_types.keys())) color = self.powerup_types[power_type] powerup = self.canvas.create_oval( x, 0, x + POWERUP_WIDTH, POWERUP_HEIGHT, fill=color, outline=”white” ) self.powerups.append({“item”: powerup, “type”: power_type}) def update_powerups(self): for powerup in self.powerups[:]: self.canvas.move(powerup[“item”], 0, POWERUP_SPEED) # Check if powerup is off screen if self.canvas.coords(powerup[“item”])[3] >= HEIGHT: self.canvas.delete(powerup[“item”]) self.powerups.remove(powerup) continue # Check collision with player if self.check_collision_with_player(powerup[“item”]): self.activate_powerup(powerup[“type”]) self.canvas.delete(powerup[“item”]) self.powerups.remove(powerup) def check_collision_with_player(self, item): p_coords = self.canvas.coords(self.player) i_coords = self.canvas.coords(item) return not ( i_coords[2] < p_coords[0] or i_coords[0] > p_coords[2] or i_coords[3] < p_coords[1] or i_coords[1] > p_coords[3] ) def activate_powerup(self, power_type): self.power_active = True self.power_type = power_type self.power_timer = 100 # Power-up lasts for 100 game ticks if power_type == “speed_boost”: global PLAYER_SPEED PLAYER_SPEED *= 2 def update_power_status(self): if self.power_active: self.power_timer -= 1 if self.power_timer <= 0: self.deactivate_powerup() if name == “main”: root = tk.Tk() root.title(“Shooting Game”) game = ShootingGame(root) root.mainloop() Any tips? submitted by /u/ArtistName [link] [comments]

Read more

Setting up dev env /u/finnicus Python Education

Setting up dev env /u/finnicus Python Education

Hi, I’m a seasoned programmer but haven’t work with python. I’m trying to set up an open source project on my machine and running into issues with the dev environment. I was able to get it working with venv but it added an entire directory into the project. Without that directory, I couldn’t access any of the dependencies (flask, etc) despite using pip to add those.

I could git ignore the venv directory and move on but it seemed like a hackey solution.

Is there a common approach for setting up a dev env for python? In JavaScript you use either yarn or npm install dependencies then start a dev server and it works. It seems like there are more steps to getting things up and running with python. Are there any tried and true approaches for developing apps with python? It seems like python has a wider array of options for that and thus the answer is “it depends” rather than “install this thing.”

Googling produce a lot of options so I’m bringing the question here in the hopes of getting more clarity.

I want code for an existing python app using a local development environment. How would you recommend I get development environment set up?

submitted by /u/finnicus
[link] [comments]

​r/learnpython Hi, I’m a seasoned programmer but haven’t work with python. I’m trying to set up an open source project on my machine and running into issues with the dev environment. I was able to get it working with venv but it added an entire directory into the project. Without that directory, I couldn’t access any of the dependencies (flask, etc) despite using pip to add those. I could git ignore the venv directory and move on but it seemed like a hackey solution. Is there a common approach for setting up a dev env for python? In JavaScript you use either yarn or npm install dependencies then start a dev server and it works. It seems like there are more steps to getting things up and running with python. Are there any tried and true approaches for developing apps with python? It seems like python has a wider array of options for that and thus the answer is “it depends” rather than “install this thing.” Googling produce a lot of options so I’m bringing the question here in the hopes of getting more clarity. I want code for an existing python app using a local development environment. How would you recommend I get development environment set up? submitted by /u/finnicus [link] [comments] 

Hi, I’m a seasoned programmer but haven’t work with python. I’m trying to set up an open source project on my machine and running into issues with the dev environment. I was able to get it working with venv but it added an entire directory into the project. Without that directory, I couldn’t access any of the dependencies (flask, etc) despite using pip to add those.

I could git ignore the venv directory and move on but it seemed like a hackey solution.

Is there a common approach for setting up a dev env for python? In JavaScript you use either yarn or npm install dependencies then start a dev server and it works. It seems like there are more steps to getting things up and running with python. Are there any tried and true approaches for developing apps with python? It seems like python has a wider array of options for that and thus the answer is “it depends” rather than “install this thing.”

Googling produce a lot of options so I’m bringing the question here in the hopes of getting more clarity.

I want code for an existing python app using a local development environment. How would you recommend I get development environment set up?

submitted by /u/finnicus
[link] [comments]  Hi, I’m a seasoned programmer but haven’t work with python. I’m trying to set up an open source project on my machine and running into issues with the dev environment. I was able to get it working with venv but it added an entire directory into the project. Without that directory, I couldn’t access any of the dependencies (flask, etc) despite using pip to add those. I could git ignore the venv directory and move on but it seemed like a hackey solution. Is there a common approach for setting up a dev env for python? In JavaScript you use either yarn or npm install dependencies then start a dev server and it works. It seems like there are more steps to getting things up and running with python. Are there any tried and true approaches for developing apps with python? It seems like python has a wider array of options for that and thus the answer is “it depends” rather than “install this thing.” Googling produce a lot of options so I’m bringing the question here in the hopes of getting more clarity. I want code for an existing python app using a local development environment. How would you recommend I get development environment set up? submitted by /u/finnicus [link] [comments]

Read more

please help: multi task download /u/sdyxz Python Education

please help: multi task download /u/sdyxz Python Education

I’v been working on this code for days, trying to download okx crypto market candle data. The server has some limits:

1, rate limit: 40 requests max / 2 seconds.

2, pagination: for each symbol, could only download 1440 candles at most, and have to use pagination since each request has 300 candles max limit.

This code can deal with pagination correctly in fetch(). And I tried to make multi thread download as fast as possible while meeting rate limit, in fetchall().

I guess the problem is: using pagination, each symbol’s one request turned into several requests, thus sabotaged my effort of meeting rate limit? Now I got many ‘429, {“msg”:”Too Many Requests”,”code”:”50011″}’ error for many symbols, but not all.

I tried lowering max_requests value from 40 to 20 or 25, it can improve, but no guaranty that it will have no error, considering in a different environment or different time. I want a reasonable/scientific solution.

I also tried give it more tries if a symbol fetch got 429, but maybe more tries means sabotage rate limit even more?

Could anybody please help me fix this?

code is here

submitted by /u/sdyxz
[link] [comments]

​r/learnpython I’v been working on this code for days, trying to download okx crypto market candle data. The server has some limits: 1, rate limit: 40 requests max / 2 seconds. 2, pagination: for each symbol, could only download 1440 candles at most, and have to use pagination since each request has 300 candles max limit. This code can deal with pagination correctly in fetch(). And I tried to make multi thread download as fast as possible while meeting rate limit, in fetchall(). I guess the problem is: using pagination, each symbol’s one request turned into several requests, thus sabotaged my effort of meeting rate limit? Now I got many ‘429, {“msg”:”Too Many Requests”,”code”:”50011″}’ error for many symbols, but not all. I tried lowering max_requests value from 40 to 20 or 25, it can improve, but no guaranty that it will have no error, considering in a different environment or different time. I want a reasonable/scientific solution. I also tried give it more tries if a symbol fetch got 429, but maybe more tries means sabotage rate limit even more? Could anybody please help me fix this? code is here submitted by /u/sdyxz [link] [comments] 

I’v been working on this code for days, trying to download okx crypto market candle data. The server has some limits:

1, rate limit: 40 requests max / 2 seconds.

2, pagination: for each symbol, could only download 1440 candles at most, and have to use pagination since each request has 300 candles max limit.

This code can deal with pagination correctly in fetch(). And I tried to make multi thread download as fast as possible while meeting rate limit, in fetchall().

I guess the problem is: using pagination, each symbol’s one request turned into several requests, thus sabotaged my effort of meeting rate limit? Now I got many ‘429, {“msg”:”Too Many Requests”,”code”:”50011″}’ error for many symbols, but not all.

I tried lowering max_requests value from 40 to 20 or 25, it can improve, but no guaranty that it will have no error, considering in a different environment or different time. I want a reasonable/scientific solution.

I also tried give it more tries if a symbol fetch got 429, but maybe more tries means sabotage rate limit even more?

Could anybody please help me fix this?

code is here

submitted by /u/sdyxz
[link] [comments]  I’v been working on this code for days, trying to download okx crypto market candle data. The server has some limits: 1, rate limit: 40 requests max / 2 seconds. 2, pagination: for each symbol, could only download 1440 candles at most, and have to use pagination since each request has 300 candles max limit. This code can deal with pagination correctly in fetch(). And I tried to make multi thread download as fast as possible while meeting rate limit, in fetchall(). I guess the problem is: using pagination, each symbol’s one request turned into several requests, thus sabotaged my effort of meeting rate limit? Now I got many ‘429, {“msg”:”Too Many Requests”,”code”:”50011″}’ error for many symbols, but not all. I tried lowering max_requests value from 40 to 20 or 25, it can improve, but no guaranty that it will have no error, considering in a different environment or different time. I want a reasonable/scientific solution. I also tried give it more tries if a symbol fetch got 429, but maybe more tries means sabotage rate limit even more? Could anybody please help me fix this? code is here submitted by /u/sdyxz [link] [comments]

Read more

Unit testing using pytest in bottle framework /u/Kubura33 Python Education

Unit testing using pytest in bottle framework /u/Kubura33 Python Education

I am trying to write unit tests that would test my bottle app. The problem is that I get KeyError wsgi.input which probablly means I am trying to avoid the bottle enviornment and that I need to mock the request? I am mocking the db engine and then in my test method I am trying to call the controller method and asserting them

Any idea how can I mock the request, anyone done this before?

submitted by /u/Kubura33
[link] [comments]

​r/learnpython I am trying to write unit tests that would test my bottle app. The problem is that I get KeyError wsgi.input which probablly means I am trying to avoid the bottle enviornment and that I need to mock the request? I am mocking the db engine and then in my test method I am trying to call the controller method and asserting them Any idea how can I mock the request, anyone done this before? submitted by /u/Kubura33 [link] [comments] 

I am trying to write unit tests that would test my bottle app. The problem is that I get KeyError wsgi.input which probablly means I am trying to avoid the bottle enviornment and that I need to mock the request? I am mocking the db engine and then in my test method I am trying to call the controller method and asserting them

Any idea how can I mock the request, anyone done this before?

submitted by /u/Kubura33
[link] [comments]  I am trying to write unit tests that would test my bottle app. The problem is that I get KeyError wsgi.input which probablly means I am trying to avoid the bottle enviornment and that I need to mock the request? I am mocking the db engine and then in my test method I am trying to call the controller method and asserting them Any idea how can I mock the request, anyone done this before? submitted by /u/Kubura33 [link] [comments]

Read more

Job runner that does not serialize/pickle python code? /u/DirectDemocracy84 Python Education

Job runner that does not serialize/pickle python code? /u/DirectDemocracy84 Python Education

I’ve used both Celery and RQ in the past but now I’m wondering if there is a piece of software that will allow me to consume much simpler values from a queue, like a string, and use the value as argument in a function on the task runner side.

I suspect I have to write this myself using asyncio but I want to check with the community first.

I’m picturing an asyncio process on the job runner side that consumes these string values and for each string it runs a function. The goal is simply to minimize the complexity of data I’m passing between the producer and the consumer, so it’s easily validated.

submitted by /u/DirectDemocracy84
[link] [comments]

​r/learnpython I’ve used both Celery and RQ in the past but now I’m wondering if there is a piece of software that will allow me to consume much simpler values from a queue, like a string, and use the value as argument in a function on the task runner side. I suspect I have to write this myself using asyncio but I want to check with the community first. I’m picturing an asyncio process on the job runner side that consumes these string values and for each string it runs a function. The goal is simply to minimize the complexity of data I’m passing between the producer and the consumer, so it’s easily validated. submitted by /u/DirectDemocracy84 [link] [comments] 

I’ve used both Celery and RQ in the past but now I’m wondering if there is a piece of software that will allow me to consume much simpler values from a queue, like a string, and use the value as argument in a function on the task runner side.

I suspect I have to write this myself using asyncio but I want to check with the community first.

I’m picturing an asyncio process on the job runner side that consumes these string values and for each string it runs a function. The goal is simply to minimize the complexity of data I’m passing between the producer and the consumer, so it’s easily validated.

submitted by /u/DirectDemocracy84
[link] [comments]  I’ve used both Celery and RQ in the past but now I’m wondering if there is a piece of software that will allow me to consume much simpler values from a queue, like a string, and use the value as argument in a function on the task runner side. I suspect I have to write this myself using asyncio but I want to check with the community first. I’m picturing an asyncio process on the job runner side that consumes these string values and for each string it runs a function. The goal is simply to minimize the complexity of data I’m passing between the producer and the consumer, so it’s easily validated. submitted by /u/DirectDemocracy84 [link] [comments]

Read more

What to learn in python /u/OldRestaurant1537 Python Education

What to learn in python /u/OldRestaurant1537 Python Education

I want to learn python for AI independently, since I’m majoring in a different thing, if possible do you know what are the general topics to focus on in advance, I learned many other programming languages, so its not about learning python but what to do and focus in it that relates to AI. Thanks in advance!

submitted by /u/OldRestaurant1537
[link] [comments]

​r/learnpython I want to learn python for AI independently, since I’m majoring in a different thing, if possible do you know what are the general topics to focus on in advance, I learned many other programming languages, so its not about learning python but what to do and focus in it that relates to AI. Thanks in advance! submitted by /u/OldRestaurant1537 [link] [comments] 

I want to learn python for AI independently, since I’m majoring in a different thing, if possible do you know what are the general topics to focus on in advance, I learned many other programming languages, so its not about learning python but what to do and focus in it that relates to AI. Thanks in advance!

submitted by /u/OldRestaurant1537
[link] [comments]  I want to learn python for AI independently, since I’m majoring in a different thing, if possible do you know what are the general topics to focus on in advance, I learned many other programming languages, so its not about learning python but what to do and focus in it that relates to AI. Thanks in advance! submitted by /u/OldRestaurant1537 [link] [comments]

Read more

What is the problem with “pip install -e”? /u/Turbulent-Heart-5888 Python Education

What is the problem with “pip install -e”? /u/Turbulent-Heart-5888 Python Education

When I run python from the terminal, everything works correctly with the package installed in editable mode using -e. However, for some reason, in a .py file within PyCharm, it shows “unresolved reference” errors. If I install the package without -e, the issue disappears, and everything works fine.

I have followed everything the AI suggested, but the “unresolved reference” error still appears.

submitted by /u/Turbulent-Heart-5888
[link] [comments]

​r/learnpython When I run python from the terminal, everything works correctly with the package installed in editable mode using -e. However, for some reason, in a .py file within PyCharm, it shows “unresolved reference” errors. If I install the package without -e, the issue disappears, and everything works fine. I have followed everything the AI suggested, but the “unresolved reference” error still appears. submitted by /u/Turbulent-Heart-5888 [link] [comments] 

When I run python from the terminal, everything works correctly with the package installed in editable mode using -e. However, for some reason, in a .py file within PyCharm, it shows “unresolved reference” errors. If I install the package without -e, the issue disappears, and everything works fine.

I have followed everything the AI suggested, but the “unresolved reference” error still appears.

submitted by /u/Turbulent-Heart-5888
[link] [comments]  When I run python from the terminal, everything works correctly with the package installed in editable mode using -e. However, for some reason, in a .py file within PyCharm, it shows “unresolved reference” errors. If I install the package without -e, the issue disappears, and everything works fine. I have followed everything the AI suggested, but the “unresolved reference” error still appears. submitted by /u/Turbulent-Heart-5888 [link] [comments]

Read more