u/PercyJackson235
PercyJackson235
PercyJackson235
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.
PercyJackson235
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.
PercyJackson235
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.
PercyJackson235
Because it would probably cause the same issue in the other direction if await had the same precedence as attribute access.
PercyJackson235
Would you be willing to share the question and answer if you remember it? I am kind of interested.
PercyJackson235
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.
PercyJackson235
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)
PercyJackson235
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.
PercyJackson235
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.
PercyJackson235
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...
PercyJackson235
They are the CLIENT side of the client/server dynamic for both MySQL and FTP.
PercyJackson235
It sounds like you were using either IPython or Jupyter Notebook. Maybe Jupyer-Lab?
PercyJackson235
Did you get someone to help you?
PercyJackson235
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.
PercyJackson235
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.
PercyJackson235
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.
PercyJackson235
Windows doesn't allow that level of control from the python sockets library. You'll need a third party library or write one yourself.
PercyJackson235
Are you on Windows?
PercyJackson235
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.
PercyJackson235
They have a community edition. I'm pretty sure that is free.
PercyJackson235
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.
PercyJackson235
I'm not so sure about that. Could you name an object that is not an instance?
PercyJackson235
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.
PercyJackson235
Fair. I don't how expansive the anaconda repos are, so I'll take it. Just slightly surprising.
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.