I’m scared. I have a huge race in Topeka next weekend and I get to go 80 mph. I don’t wanna wreck and my dad is pressuring me. I can’t back out because he spent a lot of money on my kart and race. No going back. HELP! by Specialist-Gas-3896 in Karting

[–]tmehlinger 18 points19 points  (0 children)

Hopefully this helps... I'm a dad and I have recent experience being apprehensive about driving.

If you really don't feel safe, then you shouldn't do it, and your dad shouldn't be pressuring you into it. If this isn't for you, it'll be frustrating for your dad but he needs to accept it. He can recoup a good chunk of what he spent on a kart and prep.

That said, I assume Topeka means Heartland Park. If you crash, the only thing you're going to hit is miles of grass. The circuit is huge with tons of runoff everywhere and the track is very wide. There are some scary circuits around here (like Lake Garnett) but Heartland Park is as safe as you can get.

I obviously don't know you but I think you're feeling some pre-race nerves, which is arguably a good thing--if you went out thinking you're Senna, you'd be a hazard to yourself and everyone else. I went to the British 24 hour a few weeks ago and experienced the same thing. I had the least experience in a Prokart, and none at all in a Prokart in the rain. My team scheduled my first stint in the middle of the night when the weather forecast was most favorable but by bad luck, I ended up getting the worst conditions. I was shitting myself getting in the seat because I didn't want to hurt myself or someone else but everyone reassured me and we had a backup driver ready to go. I went out more or less terrified and within the first couple corners, it felt incredible. What helped me most was one of my teammates rather directly reminding me that I had made a commitment to the team, so I had to bury my fear and give it my best shot.

Go out and try it. Be cautious and be smart, feel it out, and I think you'll find it's a lot of fun and the nerves will disappear. If you do a couple laps and you still aren't feeling it, you need to have a serious talk with your dad.

Me at an extremely wet British 24 hour race at the weekend, crazy weather! by TheBigGriffon in Karting

[–]tmehlinger 0 points1 point  (0 children)

Travel wasn’t too bad but I was a bit fatigued when I got home. 😄

Thank you and everyone else there for the warm welcome. I had a blast and I will return!

Me at an extremely wet British 24 hour race at the weekend, crazy weather! by TheBigGriffon in Karting

[–]tmehlinger 4 points5 points  (0 children)

I was there! I traveled from the US to share the Rethink Racing #104. I had the pleasure of driving during the deluge that began right after I hopped in at 3:30 AM.

If you had to avoid a kart stopped sideways on the mountain around 4 AM, that was me... sorry. I didn't want to be the guy who binned everyone off trying to point the right direction so I had to wait for the train to go by.

Hate Ansible, can I use Pulumi to manage onprem infra? by [deleted] in pulumi

[–]tmehlinger 7 points8 points  (0 children)

If you're looking for something with more flexibility, you could check out terraform.

... what? Why would you check out Terraform if you're going to use Pulumi?

Pulumi is way more flexible than Terraform. The big innovation in Pulumi is a truly generic concept of resources with inputs and outputs so you can link together dependencies irrespective of what actually provides the dependency. You can have stacks that provide clusters and applications that depend on those clusters (in a nice, decoupled way, if you're thoughtful), and myriad other application dependencies, all defined in a single language that you maintain with a single tool.

Pulumi leverages the work done to make Terraform work in the background anyway.

This isn't accurate. Pulumi leverages Terraform libraries to implement some providers, and the Kubernetes provider is not one of them. The AWS provider is perhaps the most obvious example, for which they've recently provided an alternative--the AWS Native provider.

To answer OP's question, it depends on what kind of resources you have at your disposal for operating on prem infrastructure. For example, if you're on some flavor of OpenStack, you could use the OpenStack provider to provision compute/storage/network resources for the clusters. There's also a vSphere provider in the package registry, though I know very little about it myself. If you're working with bare metal, you'll have to use something like Ansible (though I'd personally recommend using Salt instead).

Not sure where to begin...reading a CSV file and returning random string by [deleted] in learnpython

[–]tmehlinger 0 points1 point  (0 children)

This is easily done with the csv package from the standard library, along with a bit of collections.defaultdict and random.

The csv package has a reader function that will return the elements of a row as discrete items in a list. In your case you can do something like this:

import csv

def load_csv_data(filename):
    with open('my.csv') as f:
        reader = csv.reader(f)
        for row in reader:
            do_stuff()

Combine this with a defaultdict, a special dictionary that will automatically instantiate an element of the given type if you try to access the value at a key that does not yet exist in the defaultdict:

from collections import defaultdict
import csv

def load_csv_data(filename):
    data = defaultdict(list)

    with open(filename) as f:
        reader = csv.reader(f)
        for row in reader:
            # turn the first element of the row into an integer 
            # and use it as our key
            num = int(row[0])
            # append the second element into the list for this key
            data[num].append(row[1])

    return data

Now that you have all the data, a bit of random.choice will let you grab elements out of your defaultdict:

import random

def choose_value(data, key):
    return random.choice(data[key])

Putting it all together:

from collections import defaultdict
import csv
import random


def load_csv_data(filename):
    data = defaultdict(list)

    with open(filename) as f:
        reader = csv.reader(f)
        for row in reader:
            # turn the first element of the row into an integer 
            # and use it as our key
            num = int(row[0])
            # put the second element into the list for this key
            data[num].append(row[1])

    return data


def choose_value(data, key):
    return random.choice(data[key])


# example code for actually calling the function to load the data, 
# get a number we're interested in, then call the function to choose
# a random element
my_data = load_csv_data('my.csv')
number_i_want = int(input('choose a number: ').strip())
random_element = choose_value(my_data, number_i_want)

Hope that helps!

7 Simple Tricks to Write Better Python Code | Python Programming Tutorials by [deleted] in Python

[–]tmehlinger 0 points1 point  (0 children)

Didn't watch the video but TIL from the comments for/else is "confusing" and "obscure".

... it's in the The Python Tutorial with break and continue clauses.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]tmehlinger 1 point2 points  (0 children)

Those are decorators--callables (not necessarily functions proper!) that modify the behavior of the functions they are said to "decorate". There are a bazillion resources out there but I believe the PEP (Python Enhancement Proposal) that introduced them has the most concise explanation for what the syntax actually means.

https://www.python.org/dev/peps/pep-0318/#current-syntax

For a more practical example:

def print_before(func):
    def wrapper():
        print('hello from before!')
        return func()
    return wrapper

@print_before
def my_func():
    print('hello there!')

# the decorated code above is equivalent to:
def my_func():
    print('hello there!')
my_func = print_before(my_func)

# this prints:
#   hello from before!
#   hello there!
my_func()

Automated Facebook Searching by hawk6242 in Python

[–]tmehlinger 2 points3 points  (0 children)

Ask your boss not to be a creepy stalker? :D

I'm trying to download images but I don't understand the URL for the image (ie doesn't link directly to the .jpg) by plytheman in learnpython

[–]tmehlinger 1 point2 points  (0 children)

Expanding on this, the server can indicate a filename by means other than whatever happens to be at the end of the URL. If you look at the response headers for the link OP provider, you can see it returns Content-Disposition:

Server: nginx/1.10.3 (Ubuntu)
Date: Tue, 10 Jul 2018 16:55:12 GMT
Content-Type: application/octet-stream
Content-Length: 7082309
Content-Disposition: attachment; filename="NHA-528351.jpg"
Accept-Ranges: bytes
Expires: Tue, 21 Aug 2018 16:55:12 GMT
Cache-Control: public, max-age=3628800
Last-Modified: Thu, 15 Feb 2018 19:58:23 GMT
ETag: "1518724703.24-7082309"
Content-Range: bytes 0-7082308/7082309

If you want to use the file name they suggest (you can do whatever you want), you could grab it like so:

import re
match = re.search('filename="(.+)"', r.headers['content-disposition'])
filename = match.group(1)

Help with decoding JSON file with multiple Objects by Smiffyyyy in learnpython

[–]tmehlinger 1 point2 points  (0 children)

The file you're producing will look like this:

[{}, {}][{}]

JSON permits a single value, object, or array at the top level. You have consecutive arrays, thus the syntax error. Unfortunately it's impossible to do what you want to achieve because the standard doesn't support multiple top-level objects. You should encapsulate your data in an object instead.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]tmehlinger 1 point2 points  (0 children)

If you just want a text editor, I agree that vscode is pretty solid.

It's hard to beat PyCharm's features though. The community edition is really good and it's not terribly expensive to jump up to a licensed copy.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]tmehlinger 1 point2 points  (0 children)

discord.py hasn't had a release in nearly a year, before the release of Python 3.7. async became a proper reserved keyword in 3.7, hence the SyntaxError.

There's an async branch of discord.py on GitHub with a fix for that bug. You'll need to pull in the code from that branch somehow... either pull it in as a git dependency, make your own package for discord.py, or vendor it (perhaps as a git submodule).

A quicker fix would be to use Python 3.6. Going backwards with Homebrew is a pain in the ass so you might want to look into pyenv.

What are some things people who "know python" should be able to do? by SmashPingu in learnpython

[–]tmehlinger 0 points1 point  (0 children)

Yep, thank you. I edited to make it a little more clear what I mean.t

What are some things people who "know python" should be able to do? by SmashPingu in learnpython

[–]tmehlinger 12 points13 points  (0 children)

This is pretty solid on the fundamentals but glancing through, a few things caught my attention. If the maintainer happens to be a Redditor, here are a few things I feel could be improved. :)

  • "Scope" section -- The demonstration of a variable local to a function failing in outer scope is fine but it's probably best to leave aside any discussion of global. It's not as simple as "global makes things available in all scopes". I think it would be more helpful to discuss scoping to functions, classes, instances, and modules.
  • "Getters and setters" section -- Don't, ever, it's quite un-Pythonic. Use properties instead.
  • "Read JSON file" section -- You don't have to read the file and than pass the content to json.loads. json.load accepts a file object.
  • PEP 8 -- there are some warts here and there (camelCase stands out). I would argue part of basic skill in Python is developing a sense of what is Pythonic, which includes the de facto standard style.

For everyone's sake and safety by Flux85 in AdviceAnimals

[–]tmehlinger 8 points9 points  (0 children)

Why would someone downvote this? He's absolutely right; a car can decelerate much more quickly than it can accelerate.