RE: Python Libraries: Expanding the Functions

avatar
(Edited)

You are viewing a single comment's thread:

It's all good fun. Python and beem is a powerful combination, but it can be hard to work out what functions to use. I need to play with them some more. I could do some stuff around tenkminnows to make it more useful.

You could check the length of posts as part of deciding if they are worthy of a vote. I know some bots count words.

A couple of Python things. If a function returns a list you can check if something is in there like this rather than looping:

from beem.account import Account
print('steevc' in Account("slobberchops").get_following())

You can do a lot in one line. It may be quicker than a loop if that matters.

When checking a boolean you don't really need the == True, but it does no harm if you find it easier to read.



0
0
0.000
4 comments
avatar

You could check the length of posts as part of deciding if they are worthy of a vote. I know some bots count words.

This was something I was going to incorporate into the next change. I have yet to find an example in Holger's docs.

You can do a lot in one line. It may be quicker than a loop if that matters.

I once wrote a VB6 Forms app when working for HBOS (Now Lloyds Banking Group), and had to hand over the source when I left. I feel sorry for the person who had to dissect what I had done. It worked but even I struggled to read it!

When checking a boolean you don't really need the == True, but it does no harm if you find it easier to read.

image.png

This I do know and the function calls rely on True using the just the If statement, but on other occasions its stated more obviously.

In the proper coding world, I guess it has to conform all one way or another?

0
0
0.000
avatar

There has to be a compromise between being concise and being readable, but doing things in one line can be more efficient. There's a lot you can do with lists without resorting to a loop. Can always add a comment to make it clear what was intended.

0
0
0.000
avatar

There's a lot you can do with lists without resorting to a loop.

I know, still learning. I come from a VBS background and it shows.

0
0
0.000
avatar

I like that Python gives you options. You can write in the same style as some other languages, but you gradually learn the more 'Pythonic' ways.

0
0
0.000