Tagged Questions
0
votes
2answers
25 views
Making individual comparisons?
Hi all a little help if you may assist in any way.
I have data sets
Name, Age,
Mark, 19,
John, 19,
Jess, 25,
Jonty, 21,
I run a calculation that compares a distance to work to get this ...
1
vote
3answers
57 views
What good are python classes?
It seems their only value is storing attributes. Even then, those can't be changed or the changes get reflected across all instances!
If I have a class here:
# Vertex
class Vertex:
label = ...
1
vote
2answers
56 views
sort list of class instances according to master list
I have a list of class instances like so:
classes = [A(someval), B(someval), C(someval)]
I would like to sort this list using a "master" list.
master_list = [B, A]
This would sort the list with ...
0
votes
1answer
28 views
Python package using multiple modules — how to implement logging that's easy for user?
Original Question
I have a package, qualysapi which I have successfully implemented package-level logging, but I'm looking for module-level granularity transparent to the user. I modeled my ...
12
votes
3answers
285 views
Dynamically choosing class to inherit from
My Python knowledge is limited, I need some help on the following situation.
Assume that I have two classes A and B, is it possible to do something like the following (conceptually) in Python:
...
1
vote
1answer
46 views
How can I call a class with type (type)
I'm making a game, and in the code two classes. One that defines the question, and the other that defines the 4 multiple choice answers. This is what I have:
class new_question(type):
""" The ...
-1
votes
1answer
33 views
Create Django Objects outside of Admin
I'm new to django and while the admin site is useful I need to be able to do simple functions without it. I would like to automatically manage my objects.
Is it possible to create objects outside of ...
-1
votes
2answers
45 views
Using objects other class created [on hold]
I have python file that has a user interface, that mainly create objects of some class.
That file will be used by my colleagues, on their own computers.
In another file, from my computer, I'm willing ...
1
vote
1answer
36 views
Python class @property: use setter but evade getter?
In python classes, the @property is a nice decorator that avoids using explicit setter and getter functions. However, it comes at a cost of an overhead 2-5 times that of a "classical" class function. ...
1
vote
1answer
46 views
Dont understand code behaviour
I have the folowing code:
from random import randint
from medical_room import *
from Library import *
from basement import *
from End import *
class start_Game(object):
def __init__(self):
...
0
votes
3answers
78 views
Find if 2 vectors are equal in python
Ok so here is my class:
class Vec:
"""
A vector has two fields:
D - the domain (a set)
f - a dictionary mapping (some) domain elements to field elements
elements of D not appearing in f are ...
1
vote
0answers
17 views
File structure for organizing hierarchical classes in python
I'm trying to organize some hierarchical classes in python with an eye to reusing the subclasses elsewhere---but still with one canonical representation. I understand this is part of what subclassing ...
0
votes
2answers
43 views
config dict construction pattern, using a helper class?
Someone suggested to me that as a convention, one could support construction of a config dict in Python with the help of an "options" class, like so:
...
config = {Options.A: 10, Options.B: 20} # ...
0
votes
0answers
15 views
How do I save class items from a list to a any file file and then load from that file back into the list?
Say I have a list of items of a CreditCard class,
list = [Card#99909(Money(0, USD), 3000), Card#68189(Money(0, RON), 3000)]
I want to be able to save this list into a file and, if the file does not ...
2
votes
2answers
32 views
Can't use iadd within a python class
I am trying to understand why I can't use iadd (+=) within a class on the self object.
For example, if I define a class with iadd and a function which uses iadd (addA):
class A(object):
def ...
0
votes
1answer
40 views
How to correctly work with derived immutable class?
I got some difficulties in writing a simple unit converter using derived class of build-in type float.
attempt 1:
I try to return a new copy of the instance, instead of change the state of it. ...
0
votes
1answer
26 views
How do I make an elif command which occurs in a for loop only register for certain instances of an item within the list?
Below is part of my code. Basically what this does is when run it creates credit cards with a random number and a given currency code and credit card limit. The Credit Card is a class and the money it ...
-1
votes
1answer
40 views
Python class Inheritance with Imported Methods [closed]
I've run into a bit of an issue with python class objects/attributes. The code I'm trying to run looks a little like the following:
from import_thing import imported_method
class MyClass(object):
...
0
votes
0answers
50 views
understanding proper python code organization [duplicate]
Well i am planning on making image processing program using python language. I am still very new to python so i have not yet looked into the various image libraries available. (i will plan to do so ...
0
votes
2answers
25 views
Python 2: export class attributes from a local variable to the class itself
I'm not really sure how best to explain what I want, so I'll just show some code:
class Stuffclass():
def add(self, x, y):
return x + y
def subtract(self, x, y):
return x - y
...
2
votes
2answers
114 views
Passing function to a class
I have created a class that can take a function with a set of arguments. I would like to run the passed function every time the event handler signals.
I am attaching my code below which runs when I ...
6
votes
3answers
54 views
Create List Object Class in Python
It is a basic question. I am trying the following code:
class SMS_store:
def __init__(self):
self=[] #probably something is wrong here
def ...
-1
votes
1answer
44 views
Object Oriented approach to rooms and dungeons in an rpg [closed]
As part of a project for school I have to write a program that involves the use of classes and a GUI, and because I did a similar, non-Object oriented version last year; I'm re-creating a text based ...
0
votes
3answers
51 views
How to return the same class object in Python
It is a basic question.
I have written the following code:
class Point:
def __init__(self,x=0,y=0):
self.x=x
self.y=y
def __str__(self):
return '({0} , ...
0
votes
1answer
56 views
confusion about class instances [duplicate]
I create several instances of my class in a loop and expect those to be independent. But to my confusion, when I create a new instance with the same name, it keeps properties of the instance created ...
1
vote
2answers
54 views
Child method is run instead of parent's?
I have following class inheritance schema:
object <- A <- B <- Z
Now each class will have public setup() method, which calls other "private" method _configure(), which contains loading ...
0
votes
1answer
70 views
When I access a list on an object it incorrectly returns as empty list
I am writing a code for a computational physics project.
I'd like to know how I can implement a class in python by adding an array to the instances of the class.
Here is my original part of code:
...
0
votes
1answer
50 views
Get class object from string
I'm writing the following to generate URLs for my urls.py:
urls = {
'overview': {
r'^$': [ 'Index' ],
r'^/account$': [ 'Account' ],
},
'content': {
...
3
votes
1answer
107 views
How to prevent Numpy from splitting up an array-like object
If I consider the following simple class:
class Quantity(object):
def __init__(self, value, unit):
self.unit = unit
self.value = value
def __getitem__(self, key):
...
1
vote
1answer
61 views
Working in and out of classes and functions
Quick question... I've been working on a little program that will calculate the final grade percentage based on 'Homework', 'Quizzes', and 'Tests' along with the earned letter grade. This is a program ...