talha06 talha06 - 2 years ago 115
Python Question

adb - How to remove the invisible new line character from a Python variable?

I use the

tool which provides an API in order to manage an Android emulator or device through a script written in
. I have assigned a
of an application using
pid = device.shell('pidof [s] PACKAGE_NAME')
command. When I concatenate the
with another string and print the result, I get a string which has 2 lines. I need to remove the reason for breaking new line from the variable
. How can I trim the result in order to get the raw data of

Answer Source

Use the string method strip(). It will remove whitespace characters from either end of the string.

pid = device.shell('pidof [s] PACKAGE_NAME').strip()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download