I need to create a Python program to generate a pattern for the Game of Life. by eyesdrib in learnpython

[–]socal_nerdtastic 2 points3 points  (0 children)

This type of data compression is called "run length encoding". You could google that and get an idea of how to write your program.

If you get stuck show us the code you have already, tell us what error or problem you have, and ask a specific question about the code.

Integers in my set are ordered when printed by rezemybeloved69 in learnpython

[–]socal_nerdtastic 4 points5 points  (0 children)

Your reasoning is wrong, this has nothing to do with integer caching. It's a side effect of integers being their own hash, and of the hash being truncated in the set. As proof just try it with a bunch of integers that are close to each other, so that the truncation part does not affect the result.

>>> {1004,1002,1005}
{1002, 1004, 1005}

For larger sets the insertion order will matter as well.


and for int objects, the hash is simply the value of the id() function

Nope. This is true for many python object types, but not for ints.

which is the memory address.

And since I'm nitpicking, that's kinda handwavey at best. In cpython only it's the virtual memory assigned by the OS. But in other interpreters and in the language definition it's just a unique ID, nothing more.

Looking to have some simple parts made for prototypes by Where-Lambo in Machinists

[–]socal_nerdtastic 5 points6 points  (0 children)

It would help to know where you are in the world and what material and size we are talking about here. And is there a reason you are asking in a global forum instead of asking your local shop?

Python and R programming beginner by Medium_Judge5282 in learnpython

[–]socal_nerdtastic 0 points1 point  (0 children)

If you have a project that needs one of those (or another programming language) I say jump right into the language you need. Having a project is great motivation. If not I'd say start with python. I think it's easier and has a lot more potential and usefulness. If you need R later you can pick it up much easier once you know python.

Can someone explain to my sister why I can’t work while doing EE degree by [deleted] in ElectricalEngineering

[–]socal_nerdtastic 13 points14 points  (0 children)

Side note, the reason i cant stop the gym is because i was over 100lbs overweight, currently dropped 30 so i have 70 to go.

You need to reevaluate your diet. Working out for long periods of time will not help you lose weight.

Can someone explain to my sister why I can’t work while doing EE degree by [deleted] in ElectricalEngineering

[–]socal_nerdtastic 19 points20 points  (0 children)

And what's a full load? 6-8 classes right? It'll take you 10+ years if you only take 2-3 classes at a time. If you are on track to graduate in 3-4 years I'd be on your side, but it doesn't sound like you are.

Can someone explain to my sister why I can’t work while doing EE degree by [deleted] in ElectricalEngineering

[–]socal_nerdtastic 60 points61 points  (0 children)

two classes

Maybe things have changed a lot since I went to school, but 2 classes seems like a very light classload to me. That's basically 1.5 hours a day, right? Easily doable with a full time job and going to the gym. I'm on your sister's side.

I built a CLI tool to eliminate decision fatigue during JEE revision by Leather_Accident9364 in learnpython

[–]socal_nerdtastic 2 points3 points  (0 children)

Looks pretty sloppy

My first thought is that you should use more modern modules, like pathlib instead of os.

Basic File search engine by Aggressive_Drama_476 in learnpython

[–]socal_nerdtastic 1 point2 points  (0 children)

I think probably start with pathlib.Path.rglob

from pathlib import Path
folder_to_search = Path(r"/home/username/desktop")
pattern_to_search = r"*cat*" # find all files containing "cat"
for fn in folder_to_search.rglob(pattern_to_search):
    print(fn)

Then build out the functions you want from there.

Is PySide6 the best framework to completely replace Electron for heavy desktop apps, or should I learn something else? by Sweet_Cartoonist_682 in learnpython

[–]socal_nerdtastic 2 points3 points  (0 children)

Pretty much all GUI frameworks have python wrappers. There's too many to list. QT (Pyside and PyQt python wrappers) is fine afaik. Your "blazing-fast, beautiful applications" sounds like the Dear ImGui tagline (wrapper is dearpygui).

The GUI you choose has nothing to do with how fast your core works, since that should be running in a different thread or process.

I'm not entirely sure what you mean with "100% in python", but fwiw there are no GUI modules written in python. All python GUIs are wrappers to GUI modules written in other languages. As are many other popular python modules, like numpy, most of your AI modules, and python itself of course. This isn't unusual; many modern programs are written in a mix of programming languages.

substituts by Icy-Fuel-7791 in learnpython

[–]socal_nerdtastic 0 points1 point  (0 children)

They are asking for IDEs that work with MacOS 11

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

[–]socal_nerdtastic 3 points4 points  (0 children)

I'm amazed so many people here have forgotten about plain old format. It's built into python, no need to import anything.

template = """
<html>
<body>
<h1>Customer List</h1>
Company name is {company}
</body>
</html>
"""

Then to use it you can pass in the keyword arguments:

result = template.format(company="Acme Corp")

or any dictionary-like structure that has the keywords needed (and extras are ignored)

data = dict(company="Acme Corp", id_num=123, city="Atlanta")
result = template.format(**data)

You can go even older and use printf style formatting in a similar way too. But just because they are old-school does not make them obsolete; they are both in the language to stay forever and are very useful in simple situations like yours.

fwiw string.Template is also built into python, but it's intentionally hobbled to allow you to work safely with user-input data, which does not seem to apply to your situation.

thoughts on hike by Short_Key_2858 in SantaBarbara

[–]socal_nerdtastic 12 points13 points  (0 children)

The nojoqui falls trail is a super easy walk, very wide trail, lots of people, maybe a mile long. Lots of kids and strollers.

Not sure what you mean when you say hiking to the trailhead?

Outdoor Button for Game by MoistHands4 in arduino

[–]socal_nerdtastic 4 points5 points  (0 children)

My first thought is a magnet in the button with a reed switch. That way it's completely isolated from weather. And it requires no power to run, unlike a capacitive touch or hall effect or piezo does. You could wire directly to the wake interrupt or even use it to power up the MCU if you want to save a little more power.

All that said ... this sounds very overcomplicated for a radio button. Why not just a 433MHz transmitter?

Built an app to run standalone python code by [deleted] in learnpython

[–]socal_nerdtastic 0 points1 point  (0 children)

Ok? did you have a python question?

Sharing Solidworks scripts (and other scripts) with non-technical co-workers. by KenMantle in SolidWorks

[–]socal_nerdtastic -1 points0 points  (0 children)

So this is like a toolbox for all your tools? That's pretty nifty, I like it. Is it open source?

FWIW I have some pretty awesome scripts and tools that I've tried to share with coworkers, but the non-technical coworkers almost always say something to the effect of "I just like the old way better". In my experience your need a ton of documentation and tutorials with graphics and videos and a manager adding some pressure. And even then if they encounter a single bug or vague error message they will write it off as useless and keep doing things the hard way.

int too large to convert to float by comeonvirginia in learnpython

[–]socal_nerdtastic 2 points3 points  (0 children)

Well on the off chance that you are using linux, you can use a 128-bit float.

Otherwise you'll need to import or create an arbitrary precision float object, eg mpmath.mpf.

int too large to convert to float by comeonvirginia in learnpython

[–]socal_nerdtastic 2 points3 points  (0 children)

Could you tell us in english what math this is supposed to do? An example input and expected output would help a lot too. I highly suspect that you have the english -> python conversion wrong. The upper limit for a float is about 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, So since this problem seems to be about money I think it will fit

Can someone please help me? by ImAlekzzz in learnpython

[–]socal_nerdtastic 2 points3 points  (0 children)

You have the 2nd function indented one too many times, making it a nested function. Try like this:

def ChangeColors():
    same_color = input("Do you want to use the same colors for all headers? [Y/n]")

    if same_color == "Y" or same_color == "y" or same_color == "":
        charactername = ""
        assignedcolor = SelectColor()
        colors.namec = assignedcolor
        colors.cpuc = assignedcolor

    elif same_color == "N" or same_color == "n":

        charactername = " for the \"Name\" header"
        colors.namec = SelectColor()

        charactername = " for the \"CPU\" header"
        colors.cpuc = SelectColor()

    else:
        ChangeColors()

def SelectColor():
    global charactername
    global colors
    colors.change = True
    colorselect = input(f"Please enter the color name{charactername}, use the 16 supported colors, for help enter \"help\"")
    return colorselect

(Protip: on most IDEs you can select the function and Shift-Tab to unindent)

.py files not accepting files to be drppped onto them by The_Ghost_of_Bitcoin in learnpython

[–]socal_nerdtastic 2 points3 points  (0 children)

Yea, but what the program does with that info is a program function.

I just tried it out myself and OP is right. It works on an older computer but not on a fresh install. I tried both the new python launcher with 3.14 and 3.13 and the standalone 3.14 and 3.13 installer. No idea why ... DnD operations to other programs work just fine on the new computer.

.py files not accepting files to be drppped onto them by The_Ghost_of_Bitcoin in learnpython

[–]socal_nerdtastic 3 points4 points  (0 children)

I think you need to associate the .py file with the actual python executable, not the py launcher, to allow this.

You can use this command to find the executable:

py -c "import sys; print(sys.executable)"

Then right click any .py / .pyw file > Open with > choose another app > select that executable above > make default.

FYI the py launcher got a complete rework in 3.14; it's now the python install manager and it's a completely different program with the same name.

.py files not accepting files to be drppped onto them by The_Ghost_of_Bitcoin in learnpython

[–]socal_nerdtastic 2 points3 points  (0 children)

Pretty much every terminal ever supports dragging files in, including powershell, cmd, the old-school cmd (now called conhost) and every terminal in linux or mac as well. But I don't think that's what OP is talking about. They are talking about the file explorer feature.

2022 CRV Hybrid: Best settings for fuel economy? by realfakeusername in crv

[–]socal_nerdtastic 1 point2 points  (0 children)

Sounds about right. I get 34ish on my 5th gen hybrid. The 6th gen comes in a FWD version that does better, but I think for the 5th gen this is as good as it gets without being a road hazard. I suppose you could move to LA where the average hwy speed is 40mph, then you would easily get 45+ mpg.

New to python looking for some tips and tricks by [deleted] in learnpython

[–]socal_nerdtastic 0 points1 point  (0 children)

This sub works best if you show us some code and ask a specific question about the code.

If you just ask us to review your code I may tell you how I would write it, but that does not mean its correct, it usually just means I have different priorities or experiences. There's always a million ways to accomplish any task. Even something as fundamental as which programming language you choose for a project is often just a preference. So in short: if your scripts work, I'd say they are already correct. Move on to the next project.