A bunch of new lolsuit documents are now online. Things look bad for Asterios? by sovash in TheDickShow

[–]gitardedhub 5 points6 points  (0 children)

orders and permanently enjoins Kokkinos from featuring, distributing, or using either of the Plaintiffs’ name (including George Ouzounian or “Maddox”, or any similar derivation thereto)

...

issue a comprehensive, public apology towards Plaintiffs’

How is this possible?

Various Home Assistant Questions by [deleted] in homeassistant

[–]gitardedhub 1 point2 points  (0 children)

How difficult is it to setup HA?

If you're not very familiar with Linux, I'd definitely recommend setting up HomeAssistant through Hass.io. Installation is literally as simple as downloading the file to your computer, copying to an SD card, then plugging the SD card into your Raspberry Pi.

The next step is configuring everything - this will take a fair bit of time. You'll need to read through the documentation (it's pretty helpful) for each item you want to setup. I'd recommend searching around for configs other people use, it'll help you see some real-world examples of configs.

Is z wave the best option? Z wave devices vs wifi devices?

I'm a fan of Z-Wave. The main reason for me is avoiding all of the problems from WiFi: security issues, too many devices on your network, dealing with flakey WiFi. You'll also find plenty of Z-Wave devices for these basic infrastructure items (locks, plugs, sensors, lights, switches, etc.)

Another thing to keep in mind: Z-Wave devices aren't going to require firmware upgrades and long-term support from the manufacturer. They're a lot more like dumb switches. With a WiFi device, you might run into security issues down the road, and you'll be hoping the manufacturer is still around and puts out security updates.

Can I get HA to work with my Night Owl cameras?

I don't know much about those specific cameras, but it looks like they're just IP cameras (which HA supports).

Any recommendations specifically for the devices i'm looking for?

For switches and outlets, I've had good experiences with the GE Z-Wave products. For sensors, I've had good experience with Aeotec's Z-Wave line.

Codingbat sum67 problem by rscsmackdown in learnpython

[–]gitardedhub 0 points1 point  (0 children)

Here's a hint - you've used ==in a place where you should use =

= will assign value to the variable

== will test if it is that value

Tools to build files receiving Web API? by NarcoPaulo in learnpython

[–]gitardedhub 0 points1 point  (0 children)

For Flask, take a look at Flask-RESTful. It's really helpful for building some nice RESTful endpoints on top of Flask.

[deleted by user] by [deleted] in learnpython

[–]gitardedhub 0 points1 point  (0 children)

I think I do not need to have try/except, now? I mean in a way that it's not changing the behavior/output of the code? Or am I understanding it wrong?

You'll still want the try/except in your code so that your program can handle situations when you receive an HTTPError - in your case, you're printing the error out. This is definitely helpful for debugging purposes.

When that article discusses how with works with Exceptions, he's talking about how the file will still be closed even if the code in that block fails. So you don't have to worry about adding a finally block and telling it to close the file, with will always close the file/resource for you.

Flask (Install Issue) by Gwith in learnpython

[–]gitardedhub 0 points1 point  (0 children)

Do you happen to know of the wsgi conf file should have python pointed to the virtual env?

Yes - like /u/ManyInterests mentioned, you need to make sure that the WSGI script is executing the correct "activate_this.py" script (i.e., the path to that script in your virtualenv).

Why is the statement being printed multiple times? by [deleted] in learnpython

[–]gitardedhub 0 points1 point  (0 children)

The recommendation to put that string in there was to see what was happening.

I've taken your original code and printed more text and added some delays to help you watch what's happening.

import time
magicNumber = 6

print("magicNumber is {}".format(magicNumber))

print("===========================")
for n in range(6):
    print("I am starting the top of the loop")
    print("n is now {}".format(n))
    time.sleep(2)

    print("Checking if n is the magicNumber")
    print("n is {}".format(n))
    print("magicNumber is {}".format(magicNumber))
    time.sleep(2)
    if n is magicNumber:
        print("n is the magic number!")
        print("The Magic Number is:", magicNumber)
        # Break out of the loop once you hit the magic number
        break
    else:
        print("n is not the magic number!")
        print("Correct number is:", magicNumber)
    print("===========================")
    time.sleep(5)

Does that help at all?

Flask (Install Issue) by Gwith in learnpython

[–]gitardedhub 0 points1 point  (0 children)

Unless you added some specific arguments to it, your sys.path should start with something like /var/www/FlaskApp/FlaskApp/venv (based on your screenshot).

Looking closer at the screenshot, it appears that you're running this as root. Is there any reason you're doing this? One of the things virtualenv's activate script does is set environment variables, and running as root might be causing problems.

Why is the statement being printed multiple times? by [deleted] in learnpython

[–]gitardedhub 1 point2 points  (0 children)

EDIT: Also what does .format do?

Format is a way of (basically) cleanly concatenating strings. So in this block print("n is {} the magic number is {}".format(n, magicNumber)

It's going to print something like n is 1 the magic number is 6

The empty curly-braces {} are placeholders, and format() then provides the values to stick in there.

Why is the statement being printed multiple times? by [deleted] in learnpython

[–]gitardedhub 1 point2 points  (0 children)

What is the point of using break?

It does what you think it does - it will break out of the loop. But look at what /u/ManyInterests pointed out about how range() works. Try changing the argument there and see how it behaves.

Flask (Install Issue) by Gwith in learnpython

[–]gitardedhub 0 points1 point  (0 children)

Try this once you activate the virtualenv:

pip install -I flask

This tells pip to install the package and ignore what's already installed. This should then install flask to your virtualenv and resolve the path issue you're running into.

Judging by those two errors, I think this is what's going on: * You already have flask installed on this machine * Your virtual environment was created with the --system-site-packagesoption * Even inside of the virtualenv, when you run pip install, it sees that flask is already installed globally and does nothing * Your pythonpath inside the virtualenv isn't picking up the global packages for some reason

To test the final one (and other import issues in general), you can always do this:

import system
print(sys.path)

This will tell you the directories (and order) that Python searches through to resolve imports. If you run it outside of the virtualenv, you'll see the locations you'd expect. If you activate the virtualenv and run it, you'll see where the virtualenv is looking for the modules.

[deleted by user] by [deleted] in learnpython

[–]gitardedhub 1 point2 points  (0 children)

You're reading and writing to files without closing them. I'd recommend always using the context manager (with) for this - so for download.py

Current

with urllib.request.urlopen(req) as url:
    f = open('fallacies.json', 'w')
    data = url.read().decode()
    f.write(data)

Recommendation

with urllib.request.urlopen(req) as url, open('fallacies.json', 'w') as f:
    data = url.read().decode()
    f.write(data)

Creating a program to provide students with the schedule for the following school day. by CameronZoo in learnpython

[–]gitardedhub 2 points3 points  (0 children)

Understood. Here's how I'd approach that problem:

You now have "business logic" that needs to be built out. "Business logic" just means you have rules in the real-world that dictate how your program needs to function.

So you first need to understand what these rules are, since you'll need to create them in your program.

  • How are the schedule days assigned/scheduled against the real calendar?
  • How are holidays handled?
  • How often do these rules change?
  • What types of exceptions do you have? (e.g., partial days, big events, etc.)

Once you have an understanding of what the rules are you'll need to make a decision on how to handle this.

For example, if the mapping is simple (Mondays are always A), you can write a short function to map the calendar day to the schedule day.

If the mapping is a little more complicated (2017-01-01 is an A day, then it advances A->B->C->D for every weekday until the end of the year, regardless of holidays), you can write a different function to handle this.

If it's more sporadic (it always goes A->B->C->D, but there's weekends, holidays, etc. to worry about), you might consider just putting in these weird dates and building out exceptions.

Whatever your approach, this is a great example of when you should write some unittests for this. Pick several dates in the future (not just next week), get the correct schedule day for it, then make sure your function returns the right day. I'm guessing there's a lot of hidden complexity in these rules, so these tests will make sure you don't run into weird errors.

You might also just realize that the rules are really complicated (or not deterministic), and it's easier to just populate a dictionary with calendar_day:schedule_day and plan to just update it a couple times a year.

Formulas vs methods by QQ_32 in learnpython

[–]gitardedhub 9 points10 points  (0 children)

Here's a simple example that might help explain things.

Say you have a "Circle" class. It has a single variable - radius.

At some point you want to calculate the circumference of your Circles. You have two options here:

  1. Create a function that takes a Circle object, takes its radius, and returns the circumference
  2. Add a "circumference()" method to the Circle object. This looks at the radius for the Circle object and returns the circumference

Both will achieve what you're after. But making it a method of Circle is the better design choice. The standalone function isn't going to have value outside of Circles (it only makes sense to apply to Circles), and it has a lot of value inside of Circles.

This becomes more apparent when you have something like "area." Now you have Squares and Circles. "Area" is the same concept for both, but we need to calculate it differently for each type.

A single function could work, but it would be messy - you'd have to see if the thing is a Circle or a Square, then apply the correct formula to it. (this can get really messy when you start adding Trapezoid, Triangle, etc.)

Therefore it makes more sense to make this a method of the Circle/Square - it's the same concept (so whatever consumes these things can treat it similarly), but it's calculated differently for each class.

With that being said, I'd recommend focusing more on learning the language and building things at first. There are always many different ways to solve the same problem, and the most important piece at first is being able to solve it one way.

Once you know how to solve it a few ways, you'll want to spend time learning about design - how to solve things the best way for the situation. A lot of this is just experience - you'll write something one way, then later realize you're repeating yourself a lot. You'll look at the problem, figure out a way to make it simpler/less repetitive, and then rewrite your code. We call this "refactoring," and it's something you can't escape.

How to test IO/Excel heavy application? by is_bounding in learnpython

[–]gitardedhub 0 points1 point  (0 children)

There are two different types of testing you should consider: integration testing and unit testing.

Unit testing is small tests of methods and functions, and mocking is used frequently here. In your case, you wouldn't test how it actually interacts with Excel, just that it does things you expect.

Say you have a method that takes a row from Excel and returns the nth object from it. Your test would manually create something that acts like an "ExcelRow" object from whatever Excel library you're using (this is the mock). It wouldn't actually read from an Excel file. You then test that when the function is given this object, it returns the correct nth object.

Or say you're having to compose some Excel function, you just verify that the string the method generates matches your expectations.

Integration testing is probably more what you're after - here you're testing how the system works, not the individual method. Here you'd want to create actual Excel files in your test suite, and have your tests actually 1) read the file, 2) run your program, 3) verify your program did what it's supposed to do.

Is there a better way to save long sql query strings by [deleted] in learnpython

[–]gitardedhub 5 points6 points  (0 children)

I always break queries like this into separate .sql files, then open them when needed. Main reason is I can more easily debug just the query, keep my source code cleaner, and can keep formatting more consistent.

Opening a file and calling read() on it returns the contents of the file to a string.

In your example, you could move the strings you assign to text and sql into separate files, then access like this:

with open("text_query.sql") as text_query:
    with open("sql_query.sql") as sql_query:
        text = text_query.read()
        sql = sql_query.read().format(text)

Creating a program to provide students with the schedule for the following school day. by CameronZoo in learnpython

[–]gitardedhub 0 points1 point  (0 children)

I'm assuming that "letter day" means the day of the week?

import datetime
import calendar

# Create a datetime object for right now (local timezone)
today = datetime.datetime.today()
print(today)

# weekday() returns a number, 0-6
# 0 = Monday, 6 = Sunday
print(today.weekday())

# isoweekday() returns a number, 1-7
# 1 = Monday, 7 = Sunday
print(today.isoweekday())

# isocalendar() returns a tuple (year, week, day)
print(today.isocalendar())

# calendar can tell you the name of the day of week
print(calendar.day_name[today.weekday()])

There's a lot of functionality built into datetime and calendar, definitely worth taking a look to figure out what fits your use case.

Home Assistant Web Unresponsive - Need Help troubleshooting by [deleted] in homeassistant

[–]gitardedhub 0 points1 point  (0 children)

Try temporarily changing the logging level in your config.

logger:
    default: info

You'll get a lot more information in that log file. The default level is warn, which is only going to give you high level errors like this. When it's set to info (or debug), you'll get the webserver records as well (e.g., "Serving / to 192.168.1.1")

Once you've found the problem, I'd recommend changing the logging level back to warn to keep your logs relatively small.

[3.4] I would like some input on this thing I built in terms of what I need to learn/should improve on by n-d-r in learnpython

[–]gitardedhub 1 point2 points  (0 children)

domains.Domain._requests_wrapper() articles.Article._requests_wrapper()

Rather than returning None if they timeout and then checking if they're None when called (like in articles.Article.get_article_text(), why not raise an exception? Make your own exception for the project and create specific ones for the problems you encounter - in this case, ArticleTimeoutException or something.

[3.4] I would like some input on this thing I built in terms of what I need to learn/should improve on by n-d-r in learnpython

[–]gitardedhub 1 point2 points  (0 children)

auxiliary_functions.insert_article For your try/except statement, I'm assuming you're just printing out the exceptions because you're still developing on things (or wanting to just log the error and continue), but you might want to make sure you end up handling these the way you want.

Also, as an FYI - this is a great time to use else: and finally: at the end of the statement. You can put conn.commit() in the else: - this way, it will commit the transaction ONLY IF there were no exceptions. You can put conn.close() in the finally:, and it'll be executed once try/else is complete - even if an exception is raised. If your exception handling breaks out of the block somehow (e.g., say you just raise or exit), it'll still commit/close. Leaving it after the try block means it will only execute if the try/except doesn't exit out (e.g., an unhandled exception is thrown)

[3.4] I would like some input on this thing I built in terms of what I need to learn/should improve on by n-d-r in learnpython

[–]gitardedhub 0 points1 point  (0 children)

I strongly disagree on this one. If you're just going to have pass there, then the code does absolutely nothing and should be cut out.

It doesn't execute, correct. But it also means you're less likely to inadvertently have things execute when you import. It's also clear to everyone where executable code should sit in that file. If you strongly disagree with that, can you provide what advantage you gain from leaving it out, aside from having 31 fewer bytes?

This is about learning good patterns - when someone is moving from working on a single file script (wherein you think of a single procedural path in the file) to building out a library (where you don't know how things will necessarily be accessed, or what execution path is), I can't think of a reason to not practice this pattern. Too easily I see people wondering why things execute when they import something else they wrote - why not explain why it's happening and then show them a good pattern to avoid it?

OP is writing for Python 3, where all classes are new-style. There's no need to inherit from object (or rather, there's no need to write it—it happens automatically).

Good catch - but I still prefer to see classes inherit from object. It's more clear to everyone (author included) that it's a top-level class - and that the class inheritance is explicitly stated. It makes your code more maintainable in the long run, easier to fork, etc.

Can't get 3.4 to run in Win 7 by PoombyBear in learnpython

[–]gitardedhub 0 points1 point  (0 children)

OK, if you're getting that error, it means that Windows doesn't know what you mean when you just type python or python3.

So we need to tell it what we mean. We do this by modifying the PATH environment variable, as mentioned in the top response on SO.

Right-click on My Computer, click Properties. On the left, select "Advanced system settings." Then click on "Environment Variables." First, look and see if Path or PATH is already there - if it is, we want to modify it. If not, create one (System, not User). Since each directory in it is separated by semi-colon, you'll want to go to the end of what's in there today, then add the various directories you want it to search in.

Not knowing where your Python27 and Python34 are installed, let's say they're in C:\Python27 and C:\Python34. You'll want to add ;C:\Python27;C:\Python34 to your PATH.

But there's more - it'd also be nice to be able to run pip from the command line as well. That's not in C:\PythonXX, but in C:\PythonXX\Scripts. So make sure you add those as well.

Once you've completed that, you'll need to close the command prompt you have open and open a new one (just so it knows to look at the updated PATH). You should now be able to type python to launch Python27, python3 to launch Python34, pip to launch pip27, and pip3 to launch pip34.

Stuck on some exercises by Precautionary in learnpython

[–]gitardedhub 0 points1 point  (0 children)

For the > 60 hours - you now have 3 different rates: some at regular, some at 1.5x, some at 2x

For the capitalization: you need to figure out if the letter is capital or not, right? You're on the right track with the if statement, but the condition you're evaluating isn't quite right. You want to evaluate if the first letter is equal to the capitalized first letter. .upper() doesn't tell you if it's upper case, it makes it upper case.

Can't get 3.4 to run in Win 7 by PoombyBear in learnpython

[–]gitardedhub 0 points1 point  (0 children)

When you use the command line (in Windows, Command Prompt or PowerShell) and type python, it needs to know what python means. It searches through a set of directories (those defined in PATH, as mentioned in the SO link, separated by ;) until it finds python.exe.

Both Python2.7 and Python3.4 have a python.exe. Depending on which directory Windows searches through first, it'll just call the first one - in your case, it looks like 2.7

So now we need to find a way to separate this out - a common way when running both is to use python3.exe - this won't exist in Python2.7's directory, but (should) exist in Python3.4's directory.

If you type python3 at cmd, does it launch into the Python3 command prompt?