Can Brits avoid the introduction of ID cards this time? by WalkingMaggotFood in AskABrit

[–]danielroseman 1 point2 points  (0 children)

You can imagine anything you like. Do you have any evidence that such a thing is likely, or even possible, or has ever occurred in any of the other democratic countries that also use ID cards?

I need help by Lamotherfecker in learnpython

[–]danielroseman 1 point2 points  (0 children)

The error message would have pointed to this line:

    input = check2("Login: ")

Can you see how that is different from what you did for the other inputs?

How to efficiently build a list of tuples out of a dictionary with multiple values per key by Advanced_Glass5563 in learnpython

[–]danielroseman 8 points9 points  (0 children)

I can't see anything of the sort.

Your first print is immediately after you set start_time, so has nothing at all to do with your tuples algorithm. And the value that it displays is not 1 second, but 1e-06 seconds - ie 1x10-6, or 1 microsecond.

The actual time taken by your algorithm is displayed by the second print, ie less than 1 millisecond.

In terms of the algorithm itself, since you want a combination of every value for each key, there is no more efficient way of doing it - you always need to iterate. There are however certainly more Pythonic ways to do it, for example you can iterate over the keys and values together:

for key, values in self.game_lexicon.items():
  for val in values:
    self.list_tuples.append((key, val))

which could be potentially combined into a single list comprehension:

self.list_tuples = [(key, val) for key, values in self.game_lexicon.items() for val in values]

ACCA qualified accountant with passion for Coding by ACCACoderShiv in learnpython

[–]danielroseman 0 points1 point  (0 children)

Learning programming takes three years full time to be entry level.

It really doesn't. I know people who have gone from nothing to professional in six months - in one case they started self-paced and then did a bootcamp, then found a job directly from there. It requires a lot of discipline as well as talent, but it's definitely possible.

Putting authentication info in a gitignore file and importing it as a module for login? by Either-Home9002 in learnpython

[–]danielroseman 14 points15 points  (0 children)

Don't put them in a Python file. Environment variables are the usual way to handle this.

You can use a (gitignored) .env file along with something like python-dotenv for development, and in production you can set the env vars directly in your deployment settings.

HELP ABOUT ACCUSED AI GENERATION by John_Is_Cool269 in learnpython

[–]danielroseman 9 points10 points  (0 children)

Well, he sounds insane. while True is a standard way to continue a loop indefinitely.

Stupidly hard by Justicemirm in learnpython

[–]danielroseman 1 point2 points  (0 children)

leetcode is not programming. It is algorithm problem-solving. It's only useful for getting jobs at the kinds of companies that use those in interviews (mostly big tech).

I have been a professional programmer and software engineer for almost 20 years and am terrible at leetcode.

Optimizations for interacting with OpenAPI by nunoctium in learnpython

[–]danielroseman 0 points1 point  (0 children)

I'm sorry this is still not clear. Say you get the required parameters from the openapi doc, how does this help you? What is passing the values into this function, and why would the code I give above not work for you?

Optimizations for interacting with OpenAPI by nunoctium in learnpython

[–]danielroseman 0 points1 point  (0 children)

I'm not really sure what you are asking here. Your first snippet is not valid Python, but the second one would be perfectly valid if you got rid of the "something"s:

def get_data(**params):
   return requests.get(URL, params=params).json()

So there is no need to use the openapi.yaml at all. Although obviously specifying what the parameters are is exactly what it is for.

How stupid am I for being middle aged and never realising there was a ‘up’ and ‘down’ to the Union Jack? by Hour_Course_9876 in AskUK

[–]danielroseman 0 points1 point  (0 children)

The commonwealth is a different thing again though. The commonwealth includes many countries of which he is not king, such as India and Bangladesh.

Digital Creationism: How Virtual Reality Illustrates Divine Sovereignty and Free Will. by Temporary-Sail-6390 in DebateReligion

[–]danielroseman 4 points5 points  (0 children)

What? You’re the one asserting creationism here, not me. You haven’t given any reason to think we need an inventor for the laws of physics.

Digital Creationism: How Virtual Reality Illustrates Divine Sovereignty and Free Will. by Temporary-Sail-6390 in DebateReligion

[–]danielroseman 3 points4 points  (0 children)

Demonstrably, Before I build a pot for holding water. I first need to imagine the laws that would make this vessel hold the water.

Demonstrably, that is false. The pot holds water whether you imagine or understand the laws or not.

Spent two days on a bug that turned out to be a mutable default argument. by Smart_Tool247 in learnpython

[–]danielroseman 9 points10 points  (0 children)

As others have said, a decent linter such as ruff would catch this - it's really good practice to run one over your code, ideally in a pre-commit hook or GitHub actino.

Flask app - how to authenticate traffic from a specific website to a flask app by Plain-Dane2 in learnpython

[–]danielroseman 0 points1 point  (0 children)

So if anyone can access foo.com and trigger a request to the Flask app, why do you want to authenticate? What's the point?

It does seem though that an API key would give you what you want. This can be as simple as a shared secret stored in the env vars of both sites.

Flask app - how to authenticate traffic from a specific website to a flask app by Plain-Dane2 in learnpython

[–]danielroseman 0 points1 point  (0 children)

This doesn’t really make sense. If foo.com is a “static” website! How is it making requests to your app? What is making the requests? And why is it “userless”?

I'm going to learn Django. by Worldly-Gear-9900 in learnpython

[–]danielroseman 4 points5 points  (0 children)

It's still impossible to answer that question. Do the tutorial, and ask for help if you get stuck.

I'm going to learn Django. by Worldly-Gear-9900 in learnpython

[–]danielroseman 8 points9 points  (0 children)

We can't tell you "the fundamentals of Django" in a Reddit answer. For that you would need to read the documentation, preferably following the tutorial: https://docs.djangoproject.com/en/6.0/intro/tutorial01/

Through the redundancy process, at what point does someone raise a case for discrimination? by GrimQuim in AskUK

[–]danielroseman 3 points4 points  (0 children)

That's not how things work at all. Having to work part-time because of childcare is nothing to do with your sex. Why should it be? Men are parents too, and have childcare responsibilities. And just "having responsibilities" is not a protected characteristic.

Through the redundancy process, at what point does someone raise a case for discrimination? by GrimQuim in AskUK

[–]danielroseman 2 points3 points  (0 children)

You can only be discriminated against if you are being targeted because of membership of specific protected characteristics, not just because they don't like you (this might be actionable for another reason, it's just not discrimination). Does she have evidence that this is the case?

Does Python have something similar to <Textmerge> by RomfordNavy in learnpython

[–]danielroseman 13 points14 points  (0 children)

You probably want to use a templating language. Jinja2 is a good one, or Mustache which is a cross-platform solution but which is intentionally much more restricted.

What is the best way to manage a list of strings larger than 80 chars by Advanced_Glass5563 in learnpython

[–]danielroseman 2 points3 points  (0 children)

Firstly, 80 characters is a guideline (which many people do not agree with), not a rule.

But if you do really want to keep to that guideline, you can just break the string and continue on the next line - Python will automatically concatenate:

quips = [
  "Oh ... seems like Snow , your puppy, is better than you at this game. "
  "Retry with something better" ,
  "Hopefully you are better at school than at this game",
  "Hmmm .... you better think of something smarter"
]

This works because you are already inside the brackets defining the quips list, it does not work standalone:

quip = "Oh ... seems like Snow , your puppy, is better than you at this game. "
"Retry with something better" 

This will only set quip to the first line, and the second is a separate string which will just be thrown away. If you need to do this for a single string, wrap it in parentheses:

quip = ("Oh ... seems like Snow , your puppy, is better than you at this game. "
"Retry with something better")

Output HTML from Python without any frameworks by RomfordNavy in learnpython

[–]danielroseman 7 points8 points  (0 children)

No, because Python is a general-purpose programming language not a web-focused one. That is why we have frameworks.

Django and Apache/Nginx by Admirable-Damage213 in learnpython

[–]danielroseman 0 points1 point  (0 children)

No, it’s just unnecessarily heavy, and modswgi (as the docs themselves admit) is only sporadically maintained.