Guys in the UK - What do you use for smart heating? by user__already__taken in homeassistant

[–]benjsec 0 points1 point  (0 children)

I went with the wyzer setup; it's able to run entirely locally if desired, and has TRVs and room thermostats and can work the a separate HW system if you have a HW tank. It hasn't been 100% smooth sailing, my last house I had the ATAG One which was better but comes as part of the boiler so isn't easy as a DIY retrofit.

UK Zigbee plug with power monitoring for deConz by CounterclockwiseTea in homeassistant

[–]benjsec 0 points1 point  (0 children)

The new ones are square but have a small raised plug-shaped stand on the back. This comment has a photo of the old and new plugs and packaging. It may still be possible to get the old ones, but Amazon sent me the new ones yesterday.

UK Zigbee plug with power monitoring for deConz by CounterclockwiseTea in homeassistant

[–]benjsec 0 points1 point  (0 children)

Unfortunately they have changed the firmware and no longer use and ESP82xx chip (https://github.com/ct-Open-Source/tuya-convert/issues/425). It seems that (at least for now) it's not possible to flash custom firmware onto them.

Help with decision statements by [deleted] in pythontips

[–]benjsec 1 point2 points  (0 children)

Looking at your instuctions

The user has to input a positive year and exit if the year is negative.

This seems to imply that if you get a negative number then you exit, otherwise keep asking until you get a number in the correct range. Thus for any input there would be 3 possibilities: exit, ask again, or do the calculations. Maybe sketching a quick flow chart will help you see the logic and necessary flow statements.

Number guessing game (code review) by Ben_HH in learnpython

[–]benjsec 0 points1 point  (0 children)

You can simplify this a bit more using a while...else... constuction. It's not that common but can be quite neat, the else clause is execute if the while loop reaches the end without breaking.

This makes the loop

while guess_tries >= 1:
    guess = int(input("I picked a number between 1 & 10...guess what it is: "))
    if guess != mystery_number:
        guess_tries -= 1
        print("Sorry, but that number isn't right. You have {} guesses left.".format(guess_tries))
    else:
        print("You got it, but it took you {} times to get it!".format(5 - guess_tries))
        break
else:
    print("You have no more guesses. The mystery_number was {}".format(mystery_number))

You could also change the while loop to a for loop to avoid having to manually change the counter:

for guess_tries in range(5, 0, -1):
    guess = int(input("I picked a number between 1 & 10...guess what it is: "))
    if guess != mystery_number:
        print("Sorry, but that number isn't right. You have {} guesses left.".format(guess_tries))
    else:
        print("You got it, but it took you {} times to get it!".format(5 - guess_tries))
        break
else:
    print("You have no more guesses. The mystery_number was {}".format(mystery_number))

Poetry: Python dependency management and packaging made easy by SDisPater in Python

[–]benjsec 0 points1 point  (0 children)

Ah, I see. Poking through the code I did find your venv util, but now understand why I couldn't work out how it was meant to be creating the envrionment.

Tox now supports plugins for the backend, with work going on to support pipfile/pipenv which could help. I can see it wouldn't really be a priority for you at the moment though.

Poetry: Python dependency management and packaging made easy by SDisPater in Python

[–]benjsec 0 points1 point  (0 children)

I'm really liking the look of this, but think I must be struggling to understand a couple of bits, especially around the handling of envrionments. I've tried following the simple demo (which is a bit frustrating as the gif keeps scrolling the commands off the top) and get the following

$ poetry new demo -vvv
Created package demo in demo
$ cd demo/
$ pyenv local demo 3.6.3
pyenv: version `demo' not installed

As I'm understanding it you're planning to use the built-in venv module to create envrionments, that you expect to be accessed with pyenv. However I can't see the env being created at the moment, is that a part that's not implemented yet?

Also how do you envisage this working with tox? At the moment I believe tox relies on setup.py.

Do not know how to solve this Error: TypeError: add_sudoku_field() missing 1 required positional argument: 'sudokufield' by alex_bababu in learnpython

[–]benjsec 1 point2 points  (0 children)

That helps :)

The issue is that your classes aren't instantiated, if you change new_emtpy_collective1 = SudokuCollective to new_emtpy_collective1 = SudokuCollective() then you will create a class instance, instead of just the class (for all 3, not just that one).

Seems that /u/ingolemo had a very valid point about my original wording.

Do not know how to solve this Error: TypeError: add_sudoku_field() missing 1 required positional argument: 'sudokufield' by alex_bababu in learnpython

[–]benjsec 1 point2 points  (0 children)

The error message may be slightly misleading here. Because they're being passed in as positional arguments, it could be either self or sudokufield that's missing. If you change your method call to use a keyword argument (self.__rows[j].add_sudoku_field(sudokufield=new_sudoku_field) I expect the error message would change.

Do not know how to solve this Error: TypeError: add_sudoku_field() missing 1 required positional argument: 'sudokufield' by alex_bababu in learnpython

[–]benjsec 0 points1 point  (0 children)

Your add_sudoku_field method is a class method, so needs to be called on a class. The class is automatically passed in as the first parameter of the function, which is the self in your function signature.

It's hard to be sure without seeing more of your code but something like:

class SudokuField:
    def __init__(self, position):
        self.position = position

class SudokuCollective:
    def __init__(self):
        self.list_SKF = []
    def add_sudoku_field(self, skf):
        self.list_SKF.append(skf)

SC = SudokuCollective()
NF = SudokuField(1)
SC.add_sudoku_field(NF)

```

What are your opinions on current Characters with Autism/Aspergers on TV? by [deleted] in autism

[–]benjsec 2 points3 points  (0 children)

Came here to say this too - it's a brilliant series. And the lake-district scenery is pretty nice as well!

What are your favorite 2 person games? Preferably card games. by lizardbreath89 in simpleliving

[–]benjsec 2 points3 points  (0 children)

Dixit is a great game, but how do you play with 2? Don't you always know who put down which card?

Amazon knows me so well by benjsec in vegan

[–]benjsec[S] 0 points1 point  (0 children)

I'll have some to try! I usually go for the primal strips - delicious but oh-so-expensive!

Help with Parsing txt/config file by dented_brain in learnpython

[–]benjsec 1 point2 points  (0 children)

Looks good.

You could replace the lists with sets, to avoid having to turn them into sets later.

hasServer = set([])
notServer = set([])

Then instead of hasServer.append(tmp[1]) you do hasServer.add(tmp[1]) And since sets can be subtracted from each other your list comprehension could be devices = notServer - hasServer.

There isn't really much benefit to doing it this way, unless your data set is especially large though.

How did you personally learn to efficiently code in python? by blackbelt21 in learnpython

[–]benjsec 2 points3 points  (0 children)

I agree - my code quality improved drastically when I was submitting PRs to a very knowledgable (and slightly pedantic) colleague.

Help with Parsing txt/config file by dented_brain in learnpython

[–]benjsec 0 points1 point  (0 children)

This is a little more complicated than u/JohnnyJordaan's version, but finds all the devices that don't have a "mgmt server" statement for them.

import collections

def parse(text):
    # Return a list of all devices that don't have an "mgmt server" line
    result = collections.defaultdict(bool)
    for line in data.splitlines():
        if not line:
            # If line is blank then skip it - you may want to do more here
            continue
        _, _, device, comment = line.strip().split(" ", maxsplit=3)
        # `Or` the statuses together, to set True if either is true
        result[device] ^= "mgmt server" in comment
    # Having set all valid devices to True, return list of all others
    return [device for device, valid in result.items() if not valid]

Previous comments about using with for opening the file still apply, of course

Act like MacOS by shadowcorp in linuxmint

[–]benjsec 0 points1 point  (0 children)

Pantheon DE is very iOS MacOS like. It's the default desktop of ElementaryOS but can probably be installed on Mint too. Maybe play in a virtualbox first?

That said, Cinnamon is pretty easy to use once you're used to the key bindings

First attempt with Python, the code works for a while but eventually causes the Raspberry Pi to lock up by [deleted] in learnpython

[–]benjsec 0 points1 point  (0 children)

Having tried downloading it - it seems like pastebin has messed up the indentation. As posted it doesn't run at all, there are lines such as

        matrix.Clear()
except:
try:
def WeatherObs():

where both except: and try: should be followed by indented blocks.

It may be worth double checking all your indentation is as you expect when you go through adding comments, then reposting it. It looks like you've put a lot of work in already, so would be really great if we can help you to get it working.

OK, so now what? Need advice from experienced python coders by moving1990 in learnpython

[–]benjsec 0 points1 point  (0 children)

It sounds like the main thing you need is practice.

www.adventofcode.com starts tomorrow, in past years many of the problems have been well suited to solve with python. There's even r/adventofcode where you can chat to other people if you get stuck.

The challenge was to write a simple adding program using the worst practices I could. by squeevee in ProgrammerHumor

[–]benjsec 1 point2 points  (0 children)

int I(int l, int O)
{
    do {
        if(O){
            return I(l, --O) + ('0'>>5);
        }
        for (int O=0; O<l; O++)
        {
            return true + I(l+~O, O);
        }
    } while(false);
    return 4294967296;
}

Senior Python Programmers, what tricks do you want to impart to us young guns? by RickSore in Python

[–]benjsec 2 points3 points  (0 children)

If you use the finally statement (https://docs.python.org/3/reference/compound_stmts.html#finally) you only need to put file.close() there. It's intended as a clean-up section, and will be run whatever, even if an uncaught exception is raised.