avoid using print() function
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Mở brping/device.py và kiểm tra connect_serial(), bao gồm cả hai lệnh gọi print và nhánh ngoại lệ hiện có. Thực hiện các trường hợp thiết bị bị thiếu và mở thành công để xác nhận rằng trường hợp đầu tiên phát sinh ngoại lệ như mô tả và trường hợp thứ hai không còn ghi vào stdout.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
This is just a copy of connect_serial() method from brping/device.py (ver 0.1.5)
def connect_serial(self, device_name: str, baudrate: int =115200):
if device_name is None:
print("Device name is required")
return
try:
print("Opening %s at %d bps" % (device_name, baudrate))
## Serial object for device communication
# write_timeout fixes it getting stuck forever atempting to write to
# /dev/ttyAMA0 on Raspberry Pis, this raises an exception instead.
self.iodev = serial.Serial(device_name, baudrate, write_timeout=1.0)
self.iodev.send_break()
time.sleep(0.001)
self.iodev.write("U".encode("ascii"))
except Exception as exception:
raise Exception("Failed to open the given serial port: {0}".format(exception))
The request here is:
Kindly avoid using the print function in a library like this. If the device name is required, it should be handled as an exception, not with a print and return:
raise ValueError("Device name is required")
And the next print is indeed a logging:
logger.info("Opening %s at %d bps", device_name, baudrate)
I've had to use workarounds to prevent these prints from being sent to my app's stdout:
def brping_muted_print(*args, **kw):
if len(args) == 1:
args = args[0]
log('brping: %s', args)
# brping module uses raw print statements for logging
# with this trick, we turn them into proper logs
brping.device.print = brping_muted_print
Thanks
- Ngôn ngữ chính
- Python
- Star
- 60
- Fork
- 39
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bluerobotics/ping-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
bluerobotics/ping-python#74 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
bluerobotics/ping-python#171 ·
-
set sound speed Đang mở
bluerobotics/ping-python#169 · 2 bình luận · 1 người được giao ·
-
Code after return Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 48/100
bluerobotics/ping-python#167 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 32/100
bluerobotics/ping-python#159 ·
Tất cả issue của bluerobotics/ping-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100