How can i limit length string? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How can i limit length string? (/thread-24349.html) |
How can i limit length string? - perrfect - Feb-10-2020 Hi. I'm not python developer, but i need change some python script. I use this script in my zabbix-server for rabbitMQ https://github.com/jasonmcintosh/rabbitmq-zabbix/blob/master/scripts/rabbitmq/api.py And names on my rabbitMQ-server queues are long, more then 128 symbols and i can't write them to my database on zabbix-server. So i need change the script for limit value queue['name'] to 128 symbols. How can i change the script? Please, help me Thank you. RE: How can i limit length string? - Jendker - Feb-10-2020 variable = queue['name'][:128]will give you a string variable variable which is queue['name'] truncated to 128 first characters. If it is less it will still work fine.
RE: How can i limit length string? - perrfect - Feb-10-2020 (Feb-10-2020, 12:11 PM)Jendker Wrote:variable = queue['name'][:128]will give you a string variable Thank you for the reply. It is working, but in which part my api.py file should i add this line? I don't know.... RE: How can i limit length string? - Jendker - Feb-10-2020 Just replace queue['name'] everywhere with queue['name'][:128] and probably you will be fine.Or even better: try to learn some Python, it is not that difficult |