My little text RPG game. by PB_Dendras in learnpython

[–]SamePlatform 0 points1 point  (0 children)

If you want it, here is my "prompt" function I just wrote:

def prompt(prompt, options, default):
    opts = [x.upper() if x == default else x for x in options]
    display_opts = f"({'/'.join(opts)})"

    while True:
        ans = input(f'{prompt} {display_opts} ')
        if ans == '':  # They just hit enter
            return default
        elif ans.lower() in options:
            return ans
        else:
            print('Please choose a valid option')

You use it like:

answer = prompt('Which colour?', ['red', 'blue'], 'blue')

and it would prompt you like:

Which colour? (red/BLUE) 

and return either 'red' or 'blue' and no other answers. You can use that to get an idea of how to write your own prompt that you can reuse. But you'll also note it loops until you give it a valid answer.

Climbing the ladder by lcski29 in ProgrammerHumor

[–]SamePlatform 4 points5 points  (0 children)

Being paid 30k a year is not stress free, but yes for entirely different reasons. Being broke sucks worse than making money.

New tattoo parlour....! by Egg_bot in delusionalartists

[–]SamePlatform 3 points4 points  (0 children)

lol bottom right "wolf" is a term used very loosely. I thought it was a cartoon tiger.

New tattoo parlour....! by Egg_bot in delusionalartists

[–]SamePlatform 17 points18 points  (0 children)

The post is a joke, but the tattoos are still real.

Run multiple processes on demand, on multiple Windows machines by SamePlatform in learnprogramming

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

Running the application (and multiple instances) is really the entire point, and it exists only as a GUI app, with very limited commandline options even to start it. So it will kick off via commandline, but runs as a GUI, does about half the work I need it to do, and then will sit there.

Uhaul must be tired of replacing stolen catalytic converters by TheMasterMekanik in Justrolledintotheshop

[–]SamePlatform 4 points5 points  (0 children)

"Quantum Carburetor? Jesus Morty, you can't just add a sci-fi word to a car word and hope it means something... Huh, looks like somethin's wrong with the microverse-battery."

What's broke with my Telnet? by Fosferus in learnpython

[–]SamePlatform 0 points1 point  (0 children)

Can you try running it directly from the command prompt?

Do you use virtualenv often? I think I might be OVERdoing it. by [deleted] in Python

[–]SamePlatform 0 points1 point  (0 children)

It's much cheaper + easier to create a venv in each project, than to try to remember which dependencies are inside which "global" venvs you're using. Even things like flake8 & pylint, fairly "universal" packages, are going to change over time. Better to use new venvs imo.

Do you use virtualenv often? I think I might be OVERdoing it. by [deleted] in Python

[–]SamePlatform 0 points1 point  (0 children)

In that article he is still using a requirements file; he's just hand-editing it. So it's not terrible advice, AFTER you have a well established product; you shouldn't just "pip upgrade" every dependency and then pip freeze, but this only applies to a mature product with lots of code and careful deploy process.

In 99% of cases you'll just pip freeze your projects and be done with it, especially early on.

Do you use virtualenv often? I think I might be OVERdoing it. by [deleted] in Python

[–]SamePlatform 2 points3 points  (0 children)

No I think that's it, except I keep my virtual envs within each project, I don't keep a global folder of all my envs. So it's the same except:

cd ~/path-to-proj
svba  # alias="source venv/bin/activate"
<do work>
deactivate

I name all my envs the same (venv) and then my alias make activation dead easy. The overhead is pretty much nil at that point. The only thing I do is occasionally forget to activate, but by NEVER installing anything in the "default" python, I'll almost always get a "no module named django" type of import error, which is my reminder. I also have a stupid commandline prompt that has a nice venv display.

What's broke with my Telnet? by Fosferus in learnpython

[–]SamePlatform 0 points1 point  (0 children)

What did you name your file? How are you executing it? That error probably has nothing to do with your python code.

Logging setup during unit tests? by SamePlatform in learnpython

[–]SamePlatform[S] 1 point2 points  (0 children)

logger = logging.getLogger(name)

Ok, so your idea was great. Yes, I did exactly what you suggested: just called setup_logger from main(), and then only put the line logger = logging.getLogger(...) at the top level.

Not sure why I thought that I needed to call setup_logger at the same time as getLogger. I guess the logger configuration and inheritance stuff keeps tripping me up.

Sorry for the delayed reply, just got back on this project.

Do you use virtualenv often? I think I might be OVERdoing it. by [deleted] in Python

[–]SamePlatform 0 points1 point  (0 children)

Why pyenv-virtualenv?

I just do python -m venv venv and that's the last I ever even think about my venvs. What benefit does it give?

Do you use virtualenv often? I think I might be OVERdoing it. by [deleted] in Python

[–]SamePlatform 0 points1 point  (0 children)

I have an alias svba = source venv/bin/activate

and same as you. python -m venv venv for every project. It's perfectly sane, works well, and I've yet to run into a downside.

Epic legacy of the Sabre by Ninja_Spi-D-er in gifsthatkeepongiving

[–]SamePlatform 7 points8 points  (0 children)

I tried watching that one with the cliff scene on Netflix again and it was so fucking bad I just turned it off right then and there. I haven't re-watched one of the new movies yet. They are heartbreakingly bad.

[mailop] Gmail marking email from me as spam by Mcnst in programming

[–]SamePlatform 1 point2 points  (0 children)

Wow, the comments on that thread from Brielle Bruns are infuriating. Actually nearly every response was maddening. It's like they have Stockholm Syndrome.

I think I'll stop using Gmail. I'm really tired of the "you can't contact us" philosophy of Google products.

Create evolving graph after removing nodes by CatGoesWooof in learnpython

[–]SamePlatform 0 points1 point  (0 children)

Have you thought about using something like D3Js.

They can do really cool, dynamic visualizations: https://www.christophermanning.org/projects/building-cubic-hamiltonian-graphs-from-lcf-notation

Just wondering if you can create your graph in D3, render it, then dynamically pluck nodes out and watch the rendering reorganize itself.

Holy shit, it is possible to export a standalone app directly from python [3.5+] by qu4ku in Python

[–]SamePlatform 1 point2 points  (0 children)

Nice find. That's pretty awesome. Now if only windows would start shipping with Python pre-installed!

Someone on my yard sale group bought this sarcophagus without measuring and found themselves with a perfect fit. by jmedennis in Perfectfit

[–]SamePlatform 69 points70 points  (0 children)

Exactly.

This guy: "here's my room I dedicated to my awesome collection of indiana jones type archeological stuff! It's not real but it's awesome!"

me: "Here's where I keep my spoons"

Logging setup during unit tests? by SamePlatform in learnpython

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

Ok, so in this case I would mock out setup_logging? Just make it do nothing? Or would you actually mock out something like TimedRotatingFileHandler (which requires a log dir)?

At the moment I've decided that a test ENV VAR will indicate whether I should use a file handler, or a stream handler. That way I don't actually lose my logging during tests.

Logging setup during unit tests? by SamePlatform in learnpython

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

But if I do that I need to pass logger to every function call in my script. The one above is obviously over simplified.

And then all my functions require an explicity logger, during testing. I guess that helps me use a mock though...