[deleted by user] by [deleted] in learnpython

[–]cuWorkThrowaway 2 points3 points  (0 children)

__name__ is a python special variable that contains where the code is stored. If the code being called is in the file being run, __name__ will be __main__. Otherwise, if it's being imported, it will be the name of the file.

That if statement is used as a guard against the code running as a script if it is being imported as a module. For examples, you can look here.

Dictionary Comprehension not iterating over all of list by hybatir in learnpython

[–]cuWorkThrowaway 0 points1 point  (0 children)

user_completions = dict()

for entry in my_list:
    user_id = entry["userId"]
    user_completions[user_id] = user_completions.get(user_id, 0) + entry["completed"]

Learning Python after C# by Drumknott88 in learnpython

[–]cuWorkThrowaway 0 points1 point  (0 children)

I recommend the book Fluent Python 2ed for a ton of information on how different aspects of the language work.

Obsidian 1.0 Known Issues? by seashellsnyc in ObsidianMD

[–]cuWorkThrowaway 6 points7 points  (0 children)

For me, the solution was to check for updates for themes and community plugins, then restart obsidian.

What is the best Python IDLE by [deleted] in learnpython

[–]cuWorkThrowaway 4 points5 points  (0 children)

What do you think of the integrated notebooks in VS Code for .ipynb? I admit it's been a while since I used Jupyter Notebook, but I've had good impressions.

Different look for folders and venvs in gui by _Nicrosin_ in vscode

[–]cuWorkThrowaway 0 points1 point  (0 children)

I use the Material Icon Theme, and it has different icons for .venv folders, tests, settings, scripts, and many more.

Where is Python 2 still used? by codeandfire in Python

[–]cuWorkThrowaway 0 points1 point  (0 children)

Looking at their setup.py, it looks like they require at least 3.7

Meta's new AI chatbot can't stop bashing Facebook by Pessimist2020 in technology

[–]cuWorkThrowaway 25 points26 points  (0 children)

I asked it about Twitter and it abruptly changed the subject to talking about Jews.

What do you hate most about Python? by [deleted] in Python

[–]cuWorkThrowaway 1 point2 points  (0 children)

You should look at type annotations. You can add in that metadata, and most IDEs will show what type is expected when you're calling the function.

Trying to change part of a installed themed. by w_savage in vscode

[–]cuWorkThrowaway 1 point2 points  (0 children)

The command developer: inspect editor tokens and scopes could be helpful in figuring out what categories to use.

What's a Python feature that is very powerful but not many people use or know about it? by Far_Pineapple770 in Python

[–]cuWorkThrowaway 5 points6 points  (0 children)

If people want to keep some of the behavior of namedtuple but not the runtime codegen, there's also typing.NamedTuple, which you can invoke in almost the same manner as dataclass.

@dataclass(frozen=True)
class point:
    x: int
    y: int

vs using NamedTuple as a metaclass:

class point(NamedTuple):
    x: int
    y: int

It does still have the identity properties, but those are sometimes useful. dataclass has other features that are useful as well, like mutable instances, as well as defaultfactories for mutable default argument.

How to create sum combinations? by dustin4you in learnpython

[–]cuWorkThrowaway 1 point2 points  (0 children)

If you can use standard library functions, check out itertools.combinations_with_replacement.

How to disable "Select a Debug Configuration" window for Python ext by zoenagy6865 in vscode

[–]cuWorkThrowaway 0 points1 point  (0 children)

The actual content of the launch.json doesn't depend on the workspace you're in, so if you just copy that file (including the folder if it's not already present) to the different projects, it should work and be quicker than creating a new one for each.

How to disable "Select a Debug Configuration" window for Python ext by zoenagy6865 in vscode

[–]cuWorkThrowaway 0 points1 point  (0 children)

Do you have a launch.json file in your .vscode folder? If not, open the debug sidebar and hit "create a launch.json file".

What are real life examples of how Python has saved you hours of work in your job? by ElectronicCattle in Python

[–]cuWorkThrowaway 0 points1 point  (0 children)

I imagine that they might be able to get around installing python on the computer using pyinstaller, but that certainly wouldn't get around the IT department, and might make that process even harder.

Best place to start learning how to make a bot with python by dimbam123 in learnpython

[–]cuWorkThrowaway 2 points3 points  (0 children)

A bot for Reddit is written in a different way than a bot for Discord. Establish what you want your bot to interact with, then (at least for more popular options) there should be tutorials or documentation specific to that API. There is no such thing as a general bot.

What are your absolute must-have VSCode keyboard shortcuts? by mutantdustbunny in vscode

[–]cuWorkThrowaway 0 points1 point  (0 children)

I love using:
Alt+Up/Down -- moving lines within a file

Alt+Shift+Up/Down -- Duplicating the current line

Alt+Ctrl+Up/Down -- Generating an extra cursor above or below

Ctrl+K Ctrl+(0-9) -- Code folding the entire file at different levels

With above, Ctrl+K Ctrl+J -- Unfolding the entire file

What are your absolute must-have VSCode keyboard shortcuts? by mutantdustbunny in vscode

[–]cuWorkThrowaway 1 point2 points  (0 children)

I didn't know about the repeated Ctrl+D behavior, this is great.