python-docx: Populating a docx file /u/lucas-tela Python Education

python-docx: Populating a docx file /u/lucas-tela Python Education

Has anyone used python-docx to populated a word docx file template that has pre-configured placeholder variables throughout the template? Some variables are simple numbers while others are full paragraphs.

If so, what is your experience? Does the final docx file come out formatted correctly? Have you had any issues?

I am currently creating this and want to know of any potential issues that I may encounter. Thank you in advance.

submitted by /u/lucas-tela
[link] [comments]

​r/learnpython Has anyone used python-docx to populated a word docx file template that has pre-configured placeholder variables throughout the template? Some variables are simple numbers while others are full paragraphs. If so, what is your experience? Does the final docx file come out formatted correctly? Have you had any issues? I am currently creating this and want to know of any potential issues that I may encounter. Thank you in advance. submitted by /u/lucas-tela [link] [comments] 

Has anyone used python-docx to populated a word docx file template that has pre-configured placeholder variables throughout the template? Some variables are simple numbers while others are full paragraphs.

If so, what is your experience? Does the final docx file come out formatted correctly? Have you had any issues?

I am currently creating this and want to know of any potential issues that I may encounter. Thank you in advance.

submitted by /u/lucas-tela
[link] [comments]  Has anyone used python-docx to populated a word docx file template that has pre-configured placeholder variables throughout the template? Some variables are simple numbers while others are full paragraphs. If so, what is your experience? Does the final docx file come out formatted correctly? Have you had any issues? I am currently creating this and want to know of any potential issues that I may encounter. Thank you in advance. submitted by /u/lucas-tela [link] [comments]

Read more

Reading docs /u/Piingtoh Python Education

Reading docs /u/Piingtoh Python Education

I’m currently learning python’s plotting libs (pandas, matplot, seaborn), but find myself struggling to use the documentation effectively. I’ve had this issue before with other libs/ languages.

I’m fairly new to programming, but does anyone else struggle with documentation? I feel like I’m constantly relying too much on stack overflow and other websites to learn.

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

​r/learnpython I’m currently learning python’s plotting libs (pandas, matplot, seaborn), but find myself struggling to use the documentation effectively. I’ve had this issue before with other libs/ languages. I’m fairly new to programming, but does anyone else struggle with documentation? I feel like I’m constantly relying too much on stack overflow and other websites to learn. submitted by /u/Piingtoh [link] [comments] 

I’m currently learning python’s plotting libs (pandas, matplot, seaborn), but find myself struggling to use the documentation effectively. I’ve had this issue before with other libs/ languages.

I’m fairly new to programming, but does anyone else struggle with documentation? I feel like I’m constantly relying too much on stack overflow and other websites to learn.

submitted by /u/Piingtoh
[link] [comments]  I’m currently learning python’s plotting libs (pandas, matplot, seaborn), but find myself struggling to use the documentation effectively. I’ve had this issue before with other libs/ languages. I’m fairly new to programming, but does anyone else struggle with documentation? I feel like I’m constantly relying too much on stack overflow and other websites to learn. submitted by /u/Piingtoh [link] [comments]

Read more

Legend has one entry for every combination of two parameters — how can I simplify the legend? /u/HoskinZo Python Education

Legend has one entry for every combination of two parameters — how can I simplify the legend? /u/HoskinZo Python Education

I have a pandas scatterplot with two parameters: type of intervention (ventilation, filtration, source control, or combination) and type of benefit (health, productivity, or both). Right now the legend is creating an entry to every combination of these parameters (so 15 entries)–how can I simplify my legend so it just shoes the dot colour for the intervention type and the dot shape for the benefit type (or two legends with just this)?

The legend is currently like:

ventilation – health

ventilation – productivity

ventilation – both

filtration – health

filtration – productivity

… and so on …

but I want it to be like:

ventilation

filtration

health

productivity

etc.

I want the legend to just have ventilation, filtration, source control, or combination, and health, productivity, or both (not all combinations of these parameters).

I tried using plt.close() before the loop in my code, but that didn’t fix the problem.

import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = pd.read_csv('merged_data.csv',index_col=False) sns.set_theme(style="ticks") x_values = [] y_values = [] errors = [] colors = [] markers = [] color_map = { 'ventilation': 'blue', 'filtration': 'green', 'filtration ': 'green', 'source control': 'orange', 'combination': 'purple' } marker_map = { 'health': 'o', # Circle 'productivity': 's', # Square 'both': '^' # Triangle } for idx, row in df.iterrows(): x_values.extend([row['citation']] * row['n']) y_values.extend([row['net']] * row['n']) colors.extend([color_map[row['type']]] * row['n']) markers.extend([marker_map[row['benefit']]] * row['n']) plt.figure(figsize=(10, 6)) for type_, color in color_map.items(): for benefit, marker in marker_map.items(): mask = (df['type'] == type_) & (df['benefit'] == benefit) plt.scatter(df['citation'][mask].repeat(df['n'][mask]).values, df['netnew'][mask].repeat(df['n'][mask]).values, color=color, marker=marker, zorder=1, alpha=0.6, s = 60, edgecolor=color, linewidth=0.8, label=f"{type_} - {benefit}") plt.xticks(rotation=90) plt.ylabel('Net Benefit ($/person/year)', fontsize=14) plt.title('Health and Indirect Benefits of Indoor Air Quality Interventions', fontsize=14) plt.legend(title='Type and Benefit', bbox_to_anchor=(1.05, 1), loc='upper left') plt.axhline(0, color='grey', linestyle='--', linewidth=1, label='y=0') plt.tight_layout() plt.show() 

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

​r/learnpython I have a pandas scatterplot with two parameters: type of intervention (ventilation, filtration, source control, or combination) and type of benefit (health, productivity, or both). Right now the legend is creating an entry to every combination of these parameters (so 15 entries)–how can I simplify my legend so it just shoes the dot colour for the intervention type and the dot shape for the benefit type (or two legends with just this)? The legend is currently like: ventilation – health ventilation – productivity ventilation – both filtration – health filtration – productivity … and so on … but I want it to be like: ventilation filtration health productivity etc. I want the legend to just have ventilation, filtration, source control, or combination, and health, productivity, or both (not all combinations of these parameters). I tried using plt.close() before the loop in my code, but that didn’t fix the problem. import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = pd.read_csv(‘merged_data.csv’,index_col=False) sns.set_theme(style=”ticks”) x_values = [] y_values = [] errors = [] colors = [] markers = [] color_map = { ‘ventilation’: ‘blue’, ‘filtration’: ‘green’, ‘filtration ‘: ‘green’, ‘source control’: ‘orange’, ‘combination’: ‘purple’ } marker_map = { ‘health’: ‘o’, # Circle ‘productivity’: ‘s’, # Square ‘both’: ‘^’ # Triangle } for idx, row in df.iterrows(): x_values.extend([row[‘citation’]] * row[‘n’]) y_values.extend([row[‘net’]] * row[‘n’]) colors.extend([color_map[row[‘type’]]] * row[‘n’]) markers.extend([marker_map[row[‘benefit’]]] * row[‘n’]) plt.figure(figsize=(10, 6)) for type_, color in color_map.items(): for benefit, marker in marker_map.items(): mask = (df[‘type’] == type_) & (df[‘benefit’] == benefit) plt.scatter(df[‘citation’][mask].repeat(df[‘n’][mask]).values, df[‘netnew’][mask].repeat(df[‘n’][mask]).values, color=color, marker=marker, zorder=1, alpha=0.6, s = 60, edgecolor=color, linewidth=0.8, label=f”{type_} – {benefit}”) plt.xticks(rotation=90) plt.ylabel(‘Net Benefit ($/person/year)’, fontsize=14) plt.title(‘Health and Indirect Benefits of Indoor Air Quality Interventions’, fontsize=14) plt.legend(title=’Type and Benefit’, bbox_to_anchor=(1.05, 1), loc=’upper left’) plt.axhline(0, color=’grey’, linestyle=’–‘, linewidth=1, label=’y=0’) plt.tight_layout() plt.show() submitted by /u/HoskinZo [link] [comments] 

I have a pandas scatterplot with two parameters: type of intervention (ventilation, filtration, source control, or combination) and type of benefit (health, productivity, or both). Right now the legend is creating an entry to every combination of these parameters (so 15 entries)–how can I simplify my legend so it just shoes the dot colour for the intervention type and the dot shape for the benefit type (or two legends with just this)?

The legend is currently like:

ventilation – health

ventilation – productivity

ventilation – both

filtration – health

filtration – productivity

… and so on …

but I want it to be like:

ventilation

filtration

health

productivity

etc.

I want the legend to just have ventilation, filtration, source control, or combination, and health, productivity, or both (not all combinations of these parameters).

I tried using plt.close() before the loop in my code, but that didn’t fix the problem.

import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = pd.read_csv('merged_data.csv',index_col=False) sns.set_theme(style="ticks") x_values = [] y_values = [] errors = [] colors = [] markers = [] color_map = { 'ventilation': 'blue', 'filtration': 'green', 'filtration ': 'green', 'source control': 'orange', 'combination': 'purple' } marker_map = { 'health': 'o', # Circle 'productivity': 's', # Square 'both': '^' # Triangle } for idx, row in df.iterrows(): x_values.extend([row['citation']] * row['n']) y_values.extend([row['net']] * row['n']) colors.extend([color_map[row['type']]] * row['n']) markers.extend([marker_map[row['benefit']]] * row['n']) plt.figure(figsize=(10, 6)) for type_, color in color_map.items(): for benefit, marker in marker_map.items(): mask = (df['type'] == type_) & (df['benefit'] == benefit) plt.scatter(df['citation'][mask].repeat(df['n'][mask]).values, df['netnew'][mask].repeat(df['n'][mask]).values, color=color, marker=marker, zorder=1, alpha=0.6, s = 60, edgecolor=color, linewidth=0.8, label=f"{type_} - {benefit}") plt.xticks(rotation=90) plt.ylabel('Net Benefit ($/person/year)', fontsize=14) plt.title('Health and Indirect Benefits of Indoor Air Quality Interventions', fontsize=14) plt.legend(title='Type and Benefit', bbox_to_anchor=(1.05, 1), loc='upper left') plt.axhline(0, color='grey', linestyle='--', linewidth=1, label='y=0') plt.tight_layout() plt.show() 

submitted by /u/HoskinZo
[link] [comments]  I have a pandas scatterplot with two parameters: type of intervention (ventilation, filtration, source control, or combination) and type of benefit (health, productivity, or both). Right now the legend is creating an entry to every combination of these parameters (so 15 entries)–how can I simplify my legend so it just shoes the dot colour for the intervention type and the dot shape for the benefit type (or two legends with just this)? The legend is currently like: ventilation – health ventilation – productivity ventilation – both filtration – health filtration – productivity … and so on … but I want it to be like: ventilation filtration health productivity etc. I want the legend to just have ventilation, filtration, source control, or combination, and health, productivity, or both (not all combinations of these parameters). I tried using plt.close() before the loop in my code, but that didn’t fix the problem. import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = pd.read_csv(‘merged_data.csv’,index_col=False) sns.set_theme(style=”ticks”) x_values = [] y_values = [] errors = [] colors = [] markers = [] color_map = { ‘ventilation’: ‘blue’, ‘filtration’: ‘green’, ‘filtration ‘: ‘green’, ‘source control’: ‘orange’, ‘combination’: ‘purple’ } marker_map = { ‘health’: ‘o’, # Circle ‘productivity’: ‘s’, # Square ‘both’: ‘^’ # Triangle } for idx, row in df.iterrows(): x_values.extend([row[‘citation’]] * row[‘n’]) y_values.extend([row[‘net’]] * row[‘n’]) colors.extend([color_map[row[‘type’]]] * row[‘n’]) markers.extend([marker_map[row[‘benefit’]]] * row[‘n’]) plt.figure(figsize=(10, 6)) for type_, color in color_map.items(): for benefit, marker in marker_map.items(): mask = (df[‘type’] == type_) & (df[‘benefit’] == benefit) plt.scatter(df[‘citation’][mask].repeat(df[‘n’][mask]).values, df[‘netnew’][mask].repeat(df[‘n’][mask]).values, color=color, marker=marker, zorder=1, alpha=0.6, s = 60, edgecolor=color, linewidth=0.8, label=f”{type_} – {benefit}”) plt.xticks(rotation=90) plt.ylabel(‘Net Benefit ($/person/year)’, fontsize=14) plt.title(‘Health and Indirect Benefits of Indoor Air Quality Interventions’, fontsize=14) plt.legend(title=’Type and Benefit’, bbox_to_anchor=(1.05, 1), loc=’upper left’) plt.axhline(0, color=’grey’, linestyle=’–‘, linewidth=1, label=’y=0’) plt.tight_layout() plt.show() submitted by /u/HoskinZo [link] [comments]

Read more

How to stop a Backgroundtask from SocketIO? /u/SatooYT Python Education

How to stop a Backgroundtask from SocketIO? /u/SatooYT Python Education

So I am currently trying to use Websocket so I can have a livestream from my ESP32-Cam to a React-Frontend. The current problem is that i cant find any solution to kill the background task that sends me messages in a loop (will later be replaced with images) and even after I terminate the running code in Pycharm my the code doesnt even stop and the Port is used up :/. Can somebody please help me. Not even ChatGPT has an answer for me and I dont know what to do now.

import eventlet import socketio from socketio import client eventlet.monkey_patch() import time from flask import Flask, request, jsonify from flask_cors import CORS from flask_socketio import SocketIO,emit from io import BytesIO from PIL import Image, UnidentifiedImageError app = Flask(__name__) CORS(app) socketio = SocketIO(app,cors_allowed_origins="*") clients = {} stream_on = False def send_livestream_data(): """This function runs in the background and sends data to the client every second.""" global stream_on while True: if stream_on: print("hello") socketio.emit('message', {'data': 'Hellooooo'}) else: break @socket.on('connect') def handle_connect(): sid = request.sid clients[sid] = {"status": "connected"} print(f"Client connected with SID: {sid}") socketio.emit('message', {'data': f'Connected with SID: {sid}'}) @socket.on('message') def handle_message(data): """event listener when client types a message""" print("Message from Client: ",data) @socket.on('start') def handle_start(data): print("Sent to start: ", data) global stream_on stream_on = True socketio.start_background_task(send_livestream_data) @socket.on('stop') def handle_stop(data): print("Sent to stop: ", data) global stream_on stream_on = False @socket.on('disconnect') def handle_disconnect(): sid = request.sid # Get the session ID if sid in clients: del clients[sid] # Remove the session ID from the dictionary print(f"Client disconnected with SID: {sid}") if __name__ == '__main__': socketio.run(app, debug=True,port=5002) 

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

​r/learnpython So I am currently trying to use Websocket so I can have a livestream from my ESP32-Cam to a React-Frontend. The current problem is that i cant find any solution to kill the background task that sends me messages in a loop (will later be replaced with images) and even after I terminate the running code in Pycharm my the code doesnt even stop and the Port is used up :/. Can somebody please help me. Not even ChatGPT has an answer for me and I dont know what to do now. import eventlet import socketio from socketio import client eventlet.monkey_patch() import time from flask import Flask, request, jsonify from flask_cors import CORS from flask_socketio import SocketIO,emit from io import BytesIO from PIL import Image, UnidentifiedImageError app = Flask(__name__) CORS(app) socketio = SocketIO(app,cors_allowed_origins=”*”) clients = {} stream_on = False def send_livestream_data(): “””This function runs in the background and sends data to the client every second.””” global stream_on while True: if stream_on: print(“hello”) socketio.emit(‘message’, {‘data’: ‘Hellooooo’}) else: break @socket.on(‘connect’) def handle_connect(): sid = request.sid clients[sid] = {“status”: “connected”} print(f”Client connected with SID: {sid}”) socketio.emit(‘message’, {‘data’: f’Connected with SID: {sid}’}) @socket.on(‘message’) def handle_message(data): “””event listener when client types a message””” print(“Message from Client: “,data) @socket.on(‘start’) def handle_start(data): print(“Sent to start: “, data) global stream_on stream_on = True socketio.start_background_task(send_livestream_data) @socket.on(‘stop’) def handle_stop(data): print(“Sent to stop: “, data) global stream_on stream_on = False @socket.on(‘disconnect’) def handle_disconnect(): sid = request.sid # Get the session ID if sid in clients: del clients[sid] # Remove the session ID from the dictionary print(f”Client disconnected with SID: {sid}”) if __name__ == ‘__main__’: socketio.run(app, debug=True,port=5002) submitted by /u/SatooYT [link] [comments] 

So I am currently trying to use Websocket so I can have a livestream from my ESP32-Cam to a React-Frontend. The current problem is that i cant find any solution to kill the background task that sends me messages in a loop (will later be replaced with images) and even after I terminate the running code in Pycharm my the code doesnt even stop and the Port is used up :/. Can somebody please help me. Not even ChatGPT has an answer for me and I dont know what to do now.

import eventlet import socketio from socketio import client eventlet.monkey_patch() import time from flask import Flask, request, jsonify from flask_cors import CORS from flask_socketio import SocketIO,emit from io import BytesIO from PIL import Image, UnidentifiedImageError app = Flask(__name__) CORS(app) socketio = SocketIO(app,cors_allowed_origins="*") clients = {} stream_on = False def send_livestream_data(): """This function runs in the background and sends data to the client every second.""" global stream_on while True: if stream_on: print("hello") socketio.emit('message', {'data': 'Hellooooo'}) else: break @socket.on('connect') def handle_connect(): sid = request.sid clients[sid] = {"status": "connected"} print(f"Client connected with SID: {sid}") socketio.emit('message', {'data': f'Connected with SID: {sid}'}) @socket.on('message') def handle_message(data): """event listener when client types a message""" print("Message from Client: ",data) @socket.on('start') def handle_start(data): print("Sent to start: ", data) global stream_on stream_on = True socketio.start_background_task(send_livestream_data) @socket.on('stop') def handle_stop(data): print("Sent to stop: ", data) global stream_on stream_on = False @socket.on('disconnect') def handle_disconnect(): sid = request.sid # Get the session ID if sid in clients: del clients[sid] # Remove the session ID from the dictionary print(f"Client disconnected with SID: {sid}") if __name__ == '__main__': socketio.run(app, debug=True,port=5002) 

submitted by /u/SatooYT
[link] [comments]  So I am currently trying to use Websocket so I can have a livestream from my ESP32-Cam to a React-Frontend. The current problem is that i cant find any solution to kill the background task that sends me messages in a loop (will later be replaced with images) and even after I terminate the running code in Pycharm my the code doesnt even stop and the Port is used up :/. Can somebody please help me. Not even ChatGPT has an answer for me and I dont know what to do now. import eventlet import socketio from socketio import client eventlet.monkey_patch() import time from flask import Flask, request, jsonify from flask_cors import CORS from flask_socketio import SocketIO,emit from io import BytesIO from PIL import Image, UnidentifiedImageError app = Flask(__name__) CORS(app) socketio = SocketIO(app,cors_allowed_origins=”*”) clients = {} stream_on = False def send_livestream_data(): “””This function runs in the background and sends data to the client every second.””” global stream_on while True: if stream_on: print(“hello”) socketio.emit(‘message’, {‘data’: ‘Hellooooo’}) else: break @socket.on(‘connect’) def handle_connect(): sid = request.sid clients[sid] = {“status”: “connected”} print(f”Client connected with SID: {sid}”) socketio.emit(‘message’, {‘data’: f’Connected with SID: {sid}’}) @socket.on(‘message’) def handle_message(data): “””event listener when client types a message””” print(“Message from Client: “,data) @socket.on(‘start’) def handle_start(data): print(“Sent to start: “, data) global stream_on stream_on = True socketio.start_background_task(send_livestream_data) @socket.on(‘stop’) def handle_stop(data): print(“Sent to stop: “, data) global stream_on stream_on = False @socket.on(‘disconnect’) def handle_disconnect(): sid = request.sid # Get the session ID if sid in clients: del clients[sid] # Remove the session ID from the dictionary print(f”Client disconnected with SID: {sid}”) if __name__ == ‘__main__’: socketio.run(app, debug=True,port=5002) submitted by /u/SatooYT [link] [comments]

Read more

Need a help with Telebot states /u/Dzhama_Omarov Python Education

Need a help with Telebot states /u/Dzhama_Omarov Python Education

I know it’s not directly a python question, but at the same time it is, since the bot is written in python.

So if you could help me to understand why changed states doesn’t trigger handlers or callbacks it would be awesome.

I’ve tried asking ChatGPT but it wasn’t helpful.

My problem is that the handler ‘set_name’ is not executed when WAITING_FOR_NAME state is active and user sends a message. States do change, according to logs and everything works without this ‘state filter’, but I need to use states

here is my Github with code. Ill be happy to provide you with anything you need

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

​r/learnpython I know it’s not directly a python question, but at the same time it is, since the bot is written in python. So if you could help me to understand why changed states doesn’t trigger handlers or callbacks it would be awesome. I’ve tried asking ChatGPT but it wasn’t helpful. My problem is that the handler ‘set_name’ is not executed when WAITING_FOR_NAME state is active and user sends a message. States do change, according to logs and everything works without this ‘state filter’, but I need to use states here is my Github with code. Ill be happy to provide you with anything you need submitted by /u/Dzhama_Omarov [link] [comments] 

I know it’s not directly a python question, but at the same time it is, since the bot is written in python.

So if you could help me to understand why changed states doesn’t trigger handlers or callbacks it would be awesome.

I’ve tried asking ChatGPT but it wasn’t helpful.

My problem is that the handler ‘set_name’ is not executed when WAITING_FOR_NAME state is active and user sends a message. States do change, according to logs and everything works without this ‘state filter’, but I need to use states

here is my Github with code. Ill be happy to provide you with anything you need

submitted by /u/Dzhama_Omarov
[link] [comments]  I know it’s not directly a python question, but at the same time it is, since the bot is written in python. So if you could help me to understand why changed states doesn’t trigger handlers or callbacks it would be awesome. I’ve tried asking ChatGPT but it wasn’t helpful. My problem is that the handler ‘set_name’ is not executed when WAITING_FOR_NAME state is active and user sends a message. States do change, according to logs and everything works without this ‘state filter’, but I need to use states here is my Github with code. Ill be happy to provide you with anything you need submitted by /u/Dzhama_Omarov [link] [comments]

Read more

How to create virtual environment for python with different version in windows? /u/Ok-Tree-8159 Python Education

How to create virtual environment for python with different version in windows? /u/Ok-Tree-8159 Python Education

I want to create a virtual environment for python 3.13. How to do it if I have to versions of python in my laptop. 3.12 and 3.13. I know the command is

Python -m venv myenv

But, I think the above command will create it for 3.12. I want to create it for 3.13.

submitted by /u/Ok-Tree-8159
[link] [comments]

​r/learnpython I want to create a virtual environment for python 3.13. How to do it if I have to versions of python in my laptop. 3.12 and 3.13. I know the command is Python -m venv myenv But, I think the above command will create it for 3.12. I want to create it for 3.13. submitted by /u/Ok-Tree-8159 [link] [comments] 

I want to create a virtual environment for python 3.13. How to do it if I have to versions of python in my laptop. 3.12 and 3.13. I know the command is

Python -m venv myenv

But, I think the above command will create it for 3.12. I want to create it for 3.13.

submitted by /u/Ok-Tree-8159
[link] [comments]  I want to create a virtual environment for python 3.13. How to do it if I have to versions of python in my laptop. 3.12 and 3.13. I know the command is Python -m venv myenv But, I think the above command will create it for 3.12. I want to create it for 3.13. submitted by /u/Ok-Tree-8159 [link] [comments]

Read more