Should Python class filenames also be camelCased?

The following answer is largely sourced from this answer. If you’re going to follow PEP 8, you should stick to all-lowercase names, with optional underscores. To quote PEP 8’s naming conventions for packages & modules: Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. And for classes: Class … Read more

OperationalError: database is locked

From django doc: SQLite is meant to be a lightweight database, and thus can’t support a high level of concurrency. OperationalError: database is locked errors indicate that your application is experiencing more concurrency than sqlite can handle in default configuration. This error means that one thread or process has an exclusive lock on the database … Read more

Python Coin Toss

You need a loop to do this. I suggest a for loop: I suggest you read this on for loops. Also, you could pass number as a parameter to the function: Then, you need to call the function in the end: coinToss().

How can I create an object and add attributes to it?

You could use my ancient Bunch recipe, but if you don’t want to make a “bunch class”, a very simple one already exists in Python — all functions can have arbitrary attributes (including lambda functions). So, the following works: Whether the loss of clarity compared to the venerable Bunch recipe is OK, is a style decision I will of … Read more

What’s the difference between “virtualenv” and “-m venv” in creating Virtual environments(Python)

venv is a package shipped directly with python 3. So you don’t need to pip install anything. virtualenv instead is an independent library available at https://virtualenv.pypa.io/en/stable/ and can be install with pip. They solve the same problem and work in a very similar manner. If you use python3 I suggest to avoid an “extra” dependancy and just stick with venv Your error is … Read more

‘virtualenv’ is not recognized as an internal or external command, operable program or batch file

steps: – go to where you want create django app on that folder. then run this command on command prompt : python -m virtualenv . (eg. C:\Users\gshiv\Desktop\django>python -m virtualenv .) where django is the my folder i want run virtualenv and .(dot) indicates virtualenv install all it’s folder in django folder otherwise you can use other … Read more

JSON object must be str, bytes or bytearray, not dict

json.loads take a string as input and returns a dictionary as output. json.dumps take a dictionary as input and returns a string as output. With json.loads({“(‘Hello’,)”: 6, “(‘Hi’,)”: 5}), You are calling json.loads with a dictionary as input. You can fix it as follows (though I’m not quite sure what’s the point of that):