Python Forum
reading lines from a string [Solved]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading lines from a string [Solved]
#11
That would not work. Why are you counting newlines? I would expect the count to be 0 or then number of newlines.

Does text.count('Bluetooth:') work? Isn't that the information you want?
ebolisa likes this post
Reply
#12
(Mar-27-2021, 04:39 PM)deanhystad Wrote: That would not work. Why are you counting newlines? I would expect the count to be 0 or then number of newlines.

Does text.count('Bluetooth:') work? Isn't that the information you want?

I'm iterating through the number of lines and yes, it's the hard way even though it works.
text.count('Bluetooth:')
works as well and it's definitely the shortest way ;) Thank you!
Reply
#13
Now when the code is sorted out we can focus on algorithm

Is there particular reason why to drop out from shell and go through all this resource consuming write-read-delete file process? Why not just use the power of shell and let it do all the work? Something like this should deliver count of matches:

dmesg -T | grep -o -i bluetooth | wc -l

Flags used:
-o: output each match on separate output line
-i: ignore case
-l: count lines

Why there is need to use -T flag (timestamp) if it is not used anywhere?
ebolisa likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#14
(Mar-28-2021, 05:13 PM)perfringo Wrote: Now when the code is sorted out we can focus on algorithm

Is there particular reason why to drop out from shell and go through all this resource consuming write-read-delete file process? Why not just use the power of shell and let it do all the work? Something like this should deliver count of matches:

dmesg -T | grep -o -i bluetooth | wc -l

Flags used:
-o: output each match on separate output line
-i: ignore case
-l: count lines

Why there is need to use -T flag (timestamp) if it is not used anywhere?

Many roads lead to Rome. Thank you!

The idea behind this is to count the Under-voltage messages and send the total and it's registered time to an email once a day.

where's that info? This' what I get:

Usage:
 dmesg [options]

Display or control the kernel ring buffer.

Options:
 -C, --clear                 clear the kernel ring buffer
 -c, --read-clear            read and clear all messages
 -D, --console-off           disable printing messages to console
 -E, --console-on            enable printing messages to console
 -F, --file <file>           use the file instead of the kernel log buffer
 -f, --facility <list>       restrict output to defined facilities
 -H, --human                 human readable output
 -k, --kernel                display kernel messages
 -L, --color[=<when>]        colorize messages (auto, always or never)
                               colors are enabled by default
 -l, --level <list>          restrict output to defined levels
 -n, --console-level <level> set level of messages printed to console
 -P, --nopager               do not pipe output into a pager
 -p, --force-prefix          force timestamp output on each line of multi-line messages
 -r, --raw                   print the raw message buffer
 -S, --syslog                force to use syslog(2) rather than /dev/kmsg
 -s, --buffer-size <size>    buffer size to query the kernel ring buffer
 -u, --userspace             display userspace messages
 -w, --follow                wait for new messages
 -x, --decode                decode facility and level to readable string
 -d, --show-delta            show time delta between printed messages
 -e, --reltime               show local time and time delta in readable format
 -T, --ctime                 show human-readable timestamp (may be inaccurate!)
 -t, --notime                don't show any timestamp with messages
     --time-format <format>  show timestamp using the given format:
                               [delta|reltime|ctime|notime|iso]
Suspending/resume will make ctime and iso timestamps inaccurate.

 -h, --help                  display this help
 -V, --version               display version
Reply
#15
(Mar-28-2021, 06:09 PM)ebolisa Wrote: The idea behind this is to count the Under-voltage messages and send the total and it's registered time to an email once a day.

It seems to me that your code in it's current state accomplishes counting 'Bluetooth' in dmesg output. I am not qualified to judge whether it's the same as 'count the Under-voltage messages'. As you only count and return count of 'Bluetooth' there is no timestamp passed along with it so it is not possible to include it in e-mail.

"where's that info?" - about what is this question?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  trouble reading string/module from excel as a list popular_dog 0 432 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  [SOLVED] [Windows] Fails reading strings with accents Winfried 1 843 Apr-23-2023, 05:27 PM
Last Post: Larz60+
  reading a table which is of type string saisankalpj 2 965 Dec-03-2022, 11:19 AM
Last Post: saisankalpj
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into &lt;/&gt;? Winfried 0 1,536 Sep-03-2022, 11:21 PM
Last Post: Winfried
  [SOLVED] [BeautifulSoup] Turn select() into comma-separated string? Winfried 0 1,126 Aug-19-2022, 08:07 PM
Last Post: Winfried
  Adding string after every 3rd charater [SOLVED] AlphaInc 2 1,265 Jul-11-2022, 09:22 AM
Last Post: ibreeden
  Editing text between two string from different lines Paqqno 1 1,324 Apr-06-2022, 10:34 PM
Last Post: BashBedlam
  I want to simplify this python code into fewer lines, it's about string mandaxyz 5 2,137 Jan-15-2022, 01:28 PM
Last Post: mandaxyz
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 2,238 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  Replace String in multiple text-files [SOLVED] AlphaInc 5 8,168 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

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