Tagged Questions
0
votes
1answer
17 views
Invoking a callback of another class in python
I am at the beginner level in Python. I went through some similar questions asked in this topic.
My requirement is i my class invokes a member of another class passing its callback function. The other ...
0
votes
3answers
23 views
Set Python class variable equal to the output of class function
Is it possible to set a variable equal to the value that a function returns? In the example below I would want foo.baz to be equivalent to calling foo._baz(). Wondering if it's possible to have baz ...
0
votes
1answer
10 views
SQLAlchemy reflected classes in separate files
I'm new the Alchemy so forgive me if this is a basic question. I have table classes that are reflected from an existing database and I would like to store them in a separate file. Right now I have my ...
0
votes
1answer
22 views
Get all methods of a class, but not those of superclasses
How would I get the methods of an instance of a class, but not those of its superclass?
Example:
class A:
def a(self):
pass
class B(A):
def b(self):
pass
def c(self):
...
0
votes
1answer
31 views
Generating separate instances; passing list of instances as *args
I have created 5 instances of a class and need to call another class with arguments from the instances like so:
class Class2:
...
def __init__(self, arg1, arg2):
self.time = 0
...
1
vote
1answer
49 views
Does a class have to be an object, can it be an action?
I'm writing some kind of text based game and I have some thoughts about classes and initializing and so on.
I know that I can use classes if I'm making a "blueprint" for a thing. I'm a bit unsure ...
1
vote
3answers
49 views
How to reference a static attribute from within a class in Python?
I have the following python snippet:
class myClass:
myVar = 'a'
def __init__(self):
self.myOtherVar = 'b'
myVar = 'c' # Gets assigned but only as a local variable.
...
0
votes
0answers
36 views
Object has no attribute 'lower'
I'm working on a problem set from the MIT OpenCourseWare course (with no credit whatsoever) and came across this problem. I'm trying to create an RSS Feed filter.
I first created an object that ...
-2
votes
1answer
26 views
Python subclassing: adding properties
I have several classes where I want to add a single property to each class (its md5 hash value) and calculate that hash value when initializing objects of that class, but otherwise maintain everything ...
0
votes
1answer
43 views
Pass array into class in Python
I'm a php guy and I don't understand python very well... so .. excuse me if my question is stupid.
I have 2 php scripts (client.php and worker.php) using Gearman, that I need to convert to python ...
-3
votes
1answer
59 views
Python Classes - No calls? One Loop?
I have recently started using classes and have two questions.
I know that like a function, python has to read through all class lines once before any calls are made or initiated.
>
EDIT>>>So I ...
0
votes
1answer
51 views
Assigning classes as variables
Ok, I'm still a beginner when it comes to object oriented programming, but I'm not sure why my code is completely altering the attributes of the class when assigning a temporary variable equivalent to ...
1
vote
1answer
17 views
Python: tkinter delete object from class and make it invisible
I would like to delete an object from another class and make it invisible.
For example a class with a button called Button 1.
Another class with a button called Button 2.
When I click on Button 2 I ...
0
votes
1answer
28 views
Trouble understanding python inheritance arguments
I've tried reading a few different tutorials, but I still can't figure it out. I have two simple classes. Animal and cat.
class Animal:
def __init__(self, name):
self.name = name
class ...
0
votes
0answers
22 views
How to tell to Python to not to import classes which are imported inside an imported class
Look at this pseudocode:
#a.py
from x import X
class A:
#contents
#b.py
from a import A
In b.py I can access X which is imported in a.py and I'm importing A in b.py. Is it possible to prevent ...
0
votes
2answers
23 views
Class definition parameter vs. Normal class definition [duplicate]
What is the difference between the two? Don't both of these have the same functionality? I don't understand the whole point of the object parameter.
class Car(object): # object parameter
def ...
1
vote
4answers
69 views
How can I have a variable be changed throughout multiple Python modules?
I've been stuck on trying to get this to work for hours now. I'm very inexperienced with programming, so I'm sorry if what I'm trying to do is completely ridiculous. If at all possible, I would like ...
0
votes
0answers
20 views
python cuda, adding @autojit before class functions
I can see from here: NumbaPro Example that the easiest way to speed up python while working in Anaconda is to simply do the following:
from numba import autojit
@autojit
def myfunction(params):
...
0
votes
2answers
53 views
What's wrong with my python classes?
Can anyone tell me what's wrong with my class code? When I executed it, the program just pop up "Indentation Error: unindent does not match any outer indentation level"
The following is my code:
...
0
votes
0answers
36 views
Python duplicating objects? [duplicate]
I have an issue with object creation with a Python programme I'm trying to make. I'm new to classes so not sure if this an obvious issue or not.
I have two classes:
class transaction():
def ...
0
votes
0answers
20 views
Link two classes together by variables
I am learning python from a couple different books but mainly from learn python the hard way.
I am trying to better understand classes and ran into an example like :
class Dog(object):
def ...
-1
votes
0answers
24 views
Python: Log File Import from one module to another module not working
I have two module
First Moduke: SharFile, Another Module: logcreation. I am creating a log file in Module SharFile and trying to access & update the same log file when a method in sharefile ...
1
vote
1answer
30 views
Exposing a class with a constructor that has an array argument with Boost Python
I am trying to export a class using Boost Python that looks like this:
struct bool_array
{
bool_array(bool constructor_bool[7])
{
for(unsigned int i=0; i < 7; i++)
...
3
votes
2answers
42 views
Python shorthand for a tuple of a set of class attributes
Say i am using a class from some python package that looks like the following
class foo(object):
def __init__(self):
self.a = None
self.b = None
self.c = None
...
1
vote
1answer
19 views
Python - AttributeError: 'OnDemand' object has no attribute 'calc'
Something is really happening and i couldnt resolve for a day almost
Examples are below: Trying a simple method calling from one class to another class to figure out the problem as i have experienced ...
0
votes
1answer
23 views
TypeError: 'Game' object is not callable
I am just starting out with object-oriented programming and I am trying to make a game about taking care of a character.
Here is part of my code:
class Game(object):
def __init__(self):
...
0
votes
1answer
33 views
Check whether class variable has been defined
I am dealing with a scenario where I have a python class Foo. Foo, among other things does many big calculations, which I would not do unless required. So, when I define the getter method for one of ...
-1
votes
0answers
31 views
Copy a Python class (not an instance) [duplicate]
This may be difficult to explain, but since classes in python are themselves objects, many of which have the metaclass of type, how can I clone an actual class object, in particular a class that is ...
0
votes
0answers
42 views
Variable 'self' in action [duplicate]
Am starting to learn python's classes and objects! I read alone from an ebook.
The book has the following example:
class Person:
def sayHi(self):
print('Hello, how are you?')
p = ...
0
votes
1answer
24 views
Sprites aren't appearing
My sprites(tokens) aren't appearing on the screen. I included all of my code incase something in the body of the code is messing it up. I put in stars the code that directly had to do with the token ...
1
vote
1answer
36 views
Is it possible to add an attribute to an imported class in python?
I will explain my situation so that my question makes more sense.
I am programming a game using python and pygame. It is a pretty minimalist game without a lot of graphics, and I want each level to ...
1
vote
1answer
32 views
Initialize dictionary with tuple of parsed data
I'm parsing a file with Register description information and trying to build a tool around these register descriptions and bit fields for reading/writing to registers on this device. I had a text ...
1
vote
1answer
29 views
Call a method in an instance that a calling class implements - but is otherwise unrelated
Say I have this file structure:
project
gui
gui.py
widgets
base_widg.py
midi
main.py
main.py contains a class called Engine, and a method inside that, called midi_out
...
0
votes
1answer
17 views
Python Detect shape over another shape
I need to know how to detect if an oval that is being draged with the mouse enter over another shape(rectangle).
class Bloque(): # Creates a block
def __init__(self, lista, ventana):
...
0
votes
2answers
57 views
How to read order of declared members in Python class with use reflection or parsing (metaclass replace is forbidden)?
Important notes to avoid too fast/invalid duplicate tagging - please read it before answer.
Please do not suggest any solution changing original class code - not changing code reflection and parsing ...
1
vote
1answer
47 views
inserting variables and looping over a python class call
I'm using flask-sqlalchemy and flask-wtf. Basically I want to take the string produced by my "row.form_field" query and place it into my wtf form class call. Any ideas on how I can pull this off?
...
0
votes
1answer
26 views
How can I call the metaclass's __call__?
Given the following example on an instance of a X class:
class X():
def __call__(self, incoming_list):
print incoming_list
X()([x for x in range(10)])
How can I obtain the same output ...
0
votes
4answers
30 views
Add attribute to class list to return all objects with specific attribute
I have the following problem:
Let's set the scene!
Say I have a class Person with a few basic attributes:
class Person(object):
def __init__(self, name=None, gender=None, single=None):
...
-1
votes
1answer
45 views
How to catch the name of a function that creates an instance of a class?
I have been using this so far to get the name of a function that is being called:
functionId = sys._getframe(1).f_code.co_name
However, if I am using a class, things get a bit complicated. For ...
1
vote
0answers
31 views
Can I use mixed classes (strings vs. integers) when evaluating if statements in Python? [duplicate]
I want to use an IF statement with a Boolean OR to evaluate a variable's value using both strings and integer classes. Here is my code for one of several different switches:
if (autoSelect_mode == ...
0
votes
0answers
16 views
Static method in Python/Classes [duplicate]
class Employee:
numberOfEmployees = 0
maxEmployees = 10
def isCrowded():
return Employee.numberOfEmployees > Employee.maxEmployees
isCrowded = staticmethod( isCrowded )
...
-1
votes
1answer
24 views
class property not recognized when imported
I've run into an issue where an imported class is not able to recognize some of its own properties. The following describes the class in stringmanager.py
class String_Manager:
def ...
-3
votes
1answer
44 views
class and functions in python [closed]
I'm new to Python and I'm trying classes and objects, I have this script:
#!/usr/bin/env python
class test:
def __init__(self, username):
self.username = username
def ...
-2
votes
1answer
41 views
Python: Creating instances of a class based on user input [closed]
I need create more than one instances of a class based on user input. But after getting the userInput, I do not know what to do with it.
class Monster():
def __init__(self):
self.hp = 25
...
0
votes
0answers
39 views
special handling of a list attributes in interdependent classes in python
I'm defining some objects that essentially have list attributes that can point to each other. For instance,
class Child(object):
def __init__(self, parents=[]):
self.name = name
...
0
votes
1answer
17 views
Python requests library usage inside class initialization usage confusion
First and foremost let me apologize for the perhaps horrendous question title, but it is late and searching hasn't yielded any results on how to phrase this more aptly.
I have stumbled upon this ...
0
votes
3answers
49 views
Calling instance of a class in Python
Hi I am trying to call instance of a my class but don't know how to do that, at this stage it only works if I pre specify everything in newContact and ignores class AddContact. I would like to be able ...
1
vote
1answer
24 views
On-demand creation of member methods using __getattr__()
Given a class MyClass(object), how can I programmatically define class member methods using some template and the MyClass.__getattr__ mechanism? I'm thinking of something along the lines of
class ...
0
votes
2answers
42 views
Understanding objects in python (reverse function)
Could anyone explain, why self.C is returned reversed after execution ?
class Digits:
def __init__(self, A, B):
self.C = [0] * 10
self.A = [1 if digits == '1' else 0 ...
0
votes
1answer
33 views
Creating a class the have a “list creation” method and an “append to the list” method?
I am trying to create a class that can handle a string-to-list conversion and also is capable of adding to the created list. However I am not sure how to do that. If I provide the class with an ...