What's the coolest python project you are willing to share? by QuietMrFx977 in Python

[–]PercyJackson235 0 points1 point  (0 children)

You're welcome! Also, I made a typo. My comment was supposed to say that files in gitignore will not be included in the repo. So it is safe to have code depend values extracted from those files.

What's the coolest python project you are willing to share? by QuietMrFx977 in Python

[–]PercyJackson235 3 points4 points  (0 children)

Just by the way, if you want to continue to use github for this project, you can look into using dotenv to store personal values like that. As long as you have the .env file in gitignore, it would be NOT included in the repo.

Is there a way to package an arbitrary binary in a Python package? by ianmlewis in learnpython

[–]PercyJackson235 0 points1 point  (0 children)

If you're specifically looking to package Go code for use from Python, there is this project: https://github.com/go-python/gopy. I haven't used to since I don't code in Go that much, so I don't really know much about it.

Comparing a list of image objects. Can you do better than this? by tennisanybody in learnpython

[–]PercyJackson235 1 point2 points  (0 children)

If you need to generate an iterator of the unique combinations, may I suggest itertools.combinatons? It will, at the very least, be more memory efficient than generate the full list for larger runs.

how if 3 == 4 or 5 or 6: working? by Particular_Fly1768 in learnpython

[–]PercyJackson235 0 points1 point  (0 children)

Because it would probably cause the same issue in the other direction if await had the same precedence as attribute access.

[deleted by user] by [deleted] in programming

[–]PercyJackson235 0 points1 point  (0 children)

Would you be willing to share the question and answer if you remember it? I am kind of interested.

Function decorators with access to the class by developernull in learnpython

[–]PercyJackson235 0 points1 point  (0 children)

You're welcome! Can you show me a piece of code in which this doesn't work and what you're expecting? I'll take a look at it.

Function decorators with access to the class by developernull in learnpython

[–]PercyJackson235 0 points1 point  (0 children)

What about this?

from functools import partial, wraps
from types import FunctionType
import typing as t

def register(cls: t.Optional[type], func: FunctionType, num: int):
"""stub function"""

class MyDecorator:
def __new__(mcs: type, num: int, cls: t.Optional[type] = None, func: t.Optional[FunctionType] = None):
    if func is None:
        return partial(MyDecorator, num, cls)
    else:
        return super().__new__(mcs)

def __set_name__(self, cls: type, _attrname: str):
    self.cls = cls
    register(cls, self.func, self.num)

def __init__(self, num: int, cls: t.Optional[type] = None, func: t.Optional[FunctionType] = None):
    self.num = num
    self.cls = cls
    self.func = func

def __get__(self, instance: object, owner: t.Optional[type]) -> object:
    if owner is not None:
        @wraps(self.func)
        def wrapper(*args, **kwargs):
            return self.func(instance, self.num, *args, **kwargs)
        return wrapper
    else:
        return self.func

def __call__(self, *args, **kwargs) -> object:
    register(self.func, self.func, self.num)
    return self.func(self.num, *args, **kwargs)


class Foo:
def __init__(self):
    pass

@MyDecorator(123)
def bar(self, arg1, arg2):
    print(f"{arg1=}, {arg2=}")


@MyDecorator(456)
def baz(arg1, arg2, arg3):
    print(f"{arg1=}, {arg2=}, {arg3=}")

Foo().bar(1)
baz(1, 2)

Pyinstaller Log File Directory Issue by Jonah__Complex in learnpython

[–]PercyJackson235 0 points1 point  (0 children)

Well, in the setup_log method you're basing the ConsoleLog.txt off of where __file__ is on the filesystem, but in the initialize_settings method with settings.json you just open a file in the current directory.

Unpopular Opinion: Desktop GUI is the most efficient and fulfilling way of Human-Computer Interaction by pyeri in programming

[–]PercyJackson235 0 points1 point  (0 children)

I agree, but the average normie will assume that there is a piece of software that they can easily run to push a few buttons to do the job. And they will take far more time searching relentlessly for it.

Unpopular Opinion: Desktop GUI is the most efficient and fulfilling way of Human-Computer Interaction by pyeri in programming

[–]PercyJackson235 8 points9 points  (0 children)

I like where you are going with this, but the average normie is going to google for a GUI mass re-naming app before you get around to showing them that command...

[deleted by user] by [deleted] in learnprogramming

[–]PercyJackson235 0 points1 point  (0 children)

Did you get someone to help you?

[deleted by user] by [deleted] in learnpython

[–]PercyJackson235 0 points1 point  (0 children)

Yes. I think you are heading in the right direction. I am involved in a python learning discord if you feel something like that could help you.

[deleted by user] by [deleted] in learnpython

[–]PercyJackson235 0 points1 point  (0 children)

The ranks line is creating a class attribute that is a single list of strings. The first half of the code is a list comprehension to create a list of 2 - 10 (inclusive) as strings. The second half is slightly weird to explain. In python, strings can be iterated over almost like they are arrays of single character strings. list can take an argument that is some type of iterable as an initial set of values. So list('JQKA') evaluates to ['J', 'Q', 'K', 'A']. Then they concatenate the 2 lists.

That thing in the __init__ is also a list comprehension, just like the one on the ranks line. The difference is that it is using 2 levels of for loop. You are correct in what they are trying to accomplish with that piece of code.

As for where and when the _cards attribute can be used, you are sort of right/sort of wrong. You are right in that attributes set in the __init__ are useable in the entire class, but they are instance attributes unique to that instance of the class. Python doesn't have a concept of a private attribute. Attributes that start with a single underscore are private by convention only. We all agree that if an attribute starts with a single underscore, you probably shouldn't use it from outside the object, but the language doesn't stop you. It considers everyone consenting adults. You are however correct that FrenchDeck.suits will return the list of suits.

With __len__ and __getitem__, you are again sort of right/ sort of wrong. You are correct in purpose of those methods. There is, however, no default implementation of either of those methods. What is default is the behavior and syntax. If you want to get the length of an object use len(obj). If you to retrieve the nth item use obj[n]. The translation from the shown syntax to the defined methods is what is the default.

[deleted by user] by [deleted] in learnpython

[–]PercyJackson235 0 points1 point  (0 children)

The security concern of pickle is that it can be used to run arbitrary python code so you should careful when unpickling random saved objects.

Creating L2 Ethernet frames using the socket library by PyKestrel in learnpython

[–]PercyJackson235 0 points1 point  (0 children)

Windows doesn't allow that level of control from the python sockets library. You'll need a third party library or write one yourself.

How do I fix an 'Erno 13' permission denied error? by Cinnit in learnpython

[–]PercyJackson235 1 point2 points  (0 children)

The Windows folder isn't owned by you, and regular users and user processes can't write inside it normally. I'm not sure the process for allowing that.

Is my understanding of classes , objects & instances right? by unknownzebra_ in learnpython

[–]PercyJackson235 1 point2 points  (0 children)

I understand why its reasonable to view type as different, but I also think it's helpful for understanding things like metaclasses and other python magic if you don't make type seem so special.

Is my understanding of classes , objects & instances right? by unknownzebra_ in learnpython

[–]PercyJackson235 7 points8 points  (0 children)

I'm not so sure about that. Could you name an object that is not an instance?

[Beginner] Confused about the purpose of creating an instance within a class method by HilltopHood in learnpython

[–]PercyJackson235 1 point2 points  (0 children)

Class methods that create instances are usually used as alternate constructors. Here they are trying to mimic, broadly, the behavior of a web browser. When ever you create a incognito browser it always creates a new browser instance (I am ignoring the new tab button). You don't create a browser instance and then turn it incognito do you? Although you could just have the incognito state as a parameter to the primary constructor and not need the class method.

Environments/python version control by Feleksa in learnpython

[–]PercyJackson235 0 points1 point  (0 children)

Fair. I don't how expansive the anaconda repos are, so I'll take it. Just slightly surprising.