u/Nefthys

Remote Play on PS4 without internet connection?

I use RP to stream my PS4 (regular) to my Win 11 PC. They're both in the same network but currently my internet isn't working properly. I can still successfully ping the PS4 on my PC but when I try to connect it with the RP app, it just tries and tries and tries but never succeeds (the PS4 is on and I'm in my account).

In another thread people say that it should be possible to use RP with a PS5, as long as they're in the same network and they had an internet connection once while setting RP up. Is this not the case with the PS4? Is there a way to get it to work on the PS4 (without using mobile data)?

reddit.com
u/Nefthys — 9 days ago

Replace underscore for PascalCase

I've got three classes:

class MyClass_Parent():
class MyClass_Version1(MyClass_Parent):
class MyClass_Version2(MyClass_Parent):

Pylint complains that this isn't true PascalCase. I know that Pylint doesn't always know what's best but I sadly have to use it for this project and reach a certain score.

I could probably rename MyClass_Parent to just MyClass, which isn't great (but acceptable, I guess). But, removing the underscore for both child classes would turn them into MyClassVersion1 and MyClassVersion2, which is so much less clear than the version with underscore. "Real" PascalCase apparently also doesn't use hyphens.

How would you fix this? Is there a better name that tells you exactly what the child classes are (version 1 and version 2) on first glance?

Edit: "MyClass" is just a stand-in because I can't post the real name here and couldn't come up with anything better. So are "Version1" and "Version2": They are two different versions that are used independently, think of it more like version A and version B. One doesn't derive from the other but they share some code, that's why I added the parent.

Edit 2: A better example:

Let's say your code reads files. You might have .txt files and .abc files and .xyz files, so you've got a TxtReader and an AbcReader,... but you might also have two versions because one .abc file could contain a shopping list and the other contains an essay, so you'd have AbcReader_ShoppingList and AbcReader_Essay. AbcReaderShopping and AbcReaderEssay are bad names imo because you don't see the difference on first glance and just Shopping and Essay don't show that they're only meant to be used with .abc files.

reddit.com
u/Nefthys — 21 days ago

Import .module vs. package.module

This has probably been asked a hundred times already but I'm not sure how to search for this (google doesn't like dots in search queries, even with quotation marks) and this long stackexchange answer didn't fully answer it for me.

I've got this file structure:

myfolder/
    __init__.py
    classa.py
    classb.py

classa.py contains only ClassA and classb.py only contains ClassB.

  • ClassA/ClassB = class
  • classa.py/classb.py = module
  • myfolder = package (because of the __init__.py file)

from classa import ClassA throws an error if I do it in __init__.py and also load that file because, according to the answer, classa isn't part of a/the package because it doesn't contain any dots, so __init__.py can't see it.

It doesn't seem to matter if I do

from .classa import ClassA

or

from myfolder.classa import ClassA

What's the difference? I know that .. steps up one level but there's only one dot here and both versions seem to work the same way.

u/Nefthys — 26 days ago

Reload other class from init

I'm having problems with old code being cached and old errors being thrown, even though I've already fixed them, so I'm using reload to reload all classes that are imported later. Both files are in the same folder.

This works:

from classb import ClassB
from importlib import reload
import classb as classb
reload(classb)

class ClassA(): #classa.py
    def init(self,doreload):
        #Some other code

class ClassB(): #classb.py
    def init(self):
        #Do something

However, I want to use doreload to decide if ClassB should be reloaded, so I tried to move the code to __init__:

from classb import ClassB

class ClassA(): #classa.py
    def init(self,doreload):
        from importlib import reload
        import classb as classb
        reload(classb)
        #Some other code

This throws an error at the reload line:

>ModuleNotFoundError: spec not found for the module 'classb'

I already tried to keep import reload outside the class and also used reload(ClassB) instead but that threw another error:

>ImportError: module ClassB not in sys.modules

How do I reload another class from within __init__?

Edit: The problem is simply the app I have to use to test my code: It caches old code at unexpected times (at least when I don't expect it) and without using reload I'd have to restart the app pretty much every 5 minutes while testing, which is quite annoying. Reloading itself seems to be working fine.

reddit.com
u/Nefthys — 27 days ago

Circular import with inheritance

I've got three classes:

  • ClassA
  • ClassB1(ClassA)
  • ClassB2(ClassA)

ClassA reads a file and passes the contents to either ClassB1 or ClassB2 for further processing. The code is kind of similar but still too different require a lot of if/elif that would make it a lot harder to read, so I decided to split it into two classes that each do their own version. ClassA also contains functions that are used by both ClassB1 and ClassB2.

All three files are in the same folder but they can't see each other and class ClassB1(ClassA) throws an exception:

>NameError: name 'ClassA' is not defined

If I add from classa import ClassA, then it works, however when I do b1 = ClassB1() in ClassA.readFile(), then it complains that it can't find that ClassB1, so I have to do from classb1 import ClassB1. This causes a circular import, which is obviously not good.

How do I fix this?

Can you not create an instance of the child class within the parent class in Python?

reddit.com
u/Nefthys — 2 months ago