Python Forum
How can i limit length string?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can i limit length string?
#1
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/rabbitm...tmq/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.
Reply
#2
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.
Reply
#3
(Feb-10-2020, 12:11 PM)Jendker Wrote:
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.

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.... Sad
Reply
#4
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 Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python gives wrong string length and wrong character thienson30 2 1,317 Oct-15-2019, 08:54 PM
Last Post: Gribouillis
  Highlight/Underline a string | ValueError: zero length field name in format searching1 1 1,653 Jul-01-2019, 03:06 AM
Last Post: metulburr
  calculating length of string desul 12 5,864 May-22-2019, 10:50 AM
Last Post: ankit
  Python - Limit Sentence Length to 10 Words - Text file dj99 2 3,071 Jul-21-2018, 02:24 PM
Last Post: dj99
  Python find the minimum length of string to differentiate dictionary items zydjohn 3 1,996 Mar-03-2018, 05:23 PM
Last Post: Gribouillis
  Get string length RedSkeleton007 3 2,984 Dec-04-2017, 03:19 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020