call

When I call two methods, one from the parent class and one from the child class, only the first call returns

When I call two methods, one from the parent class and one from the child class, only the first call returns Question: class Smarthphone(): def __init__(self, tamanho, interface): self.tamanho = tamanho self.interface = interface def print_test(self): return "testing parent class" class MP3Player(Smarthphone): def __init__(self, tamanho, interface, capacidade): super().__init__(tamanho, interface) self.capacidade = capacidade def print_MP3Player(self): return …

Total answers: 1

Python – Unable to call static method inside another static method

Unable to call static method inside another static method Question: I have a class which has static methods and I want to have another static method within this class to call the method but it returns NameError: name ”method_name’ is not defined Example of what I’m trying to do. class abc(): @staticmethod def method1(): print(‘print …

Total answers: 2

subprocess.call() arguments ignored when using shell=True w/ list

subprocess.call() arguments ignored when using shell=True w/ list Question: I am trying to get python’s subprocess.call method to accept some args commands through a list (consisting of a sequence of strings) as advised in the python documentation. To explore this behavior before putting it into my actual script, I opened up IPython, ran some commands …

Total answers: 2

Calling R script from python using rpy2

Calling R script from python using rpy2 Question: I’m very new to rpy2, as well as R. I basically have a R script, script.R, which contains functions, such as rfunc(folder). It is located in the same directory as my python script. I want to call it from Python, and then launch one of its functions. …

Total answers: 1

How do you call an instance of a class in Python?

How do you call an instance of a class in Python? Question: This is inspired by a question I just saw, “Change what is returned by calling class instance”, but was quickly answered with __repr__ (and accepted, so the questioner did not actually intend to call the instance). Now calling an instance of a class …

Total answers: 3

Running bash script from within python

Running bash script from within python Question: I have a problem with the following code: callBash.py: import subprocess print “start” subprocess.call(“sleep.sh”) print “end” sleep.sh: sleep 10 I want the “end” to be printed after 10s. (I know that this is a dumb example, I could simply sleep within python, but this simple sleep.sh file was …

Total answers: 7

Python – how do I call external python programs?

Python – how do I call external python programs? Question: I’ll preface this by saying it’s a homework assignment. I don’t want code written out for me, just to be pointed in the right direction. We’re able to work on a project of our choice so I’m working on a program to be a mini …

Total answers: 4

Calling private function within the same class python

Calling private function within the same class python Question: How can i call a private function from some other function within the same class? class Foo: def __bar(arg): #do something def baz(self, arg): #want to call __bar Right now, when i do this: __bar(val) from baz(), i get this: NameError: global name ‘_Foo__createCodeBehind’ is not …

Total answers: 2

Python __call__ special method practical example

Python __call__ special method practical example Question: I know that __call__ method in a class is triggered when the instance of a class is called. However, I have no idea when I can use this special method, because one can simply create a new method and perform the same operation done in __call__ method and …

Total answers: 16