instance

How do I assign a property to an instance in Python?

本秂侑毒 提交于 2021-02-07 13:12:23
问题 Using python, one can set an attribute of a instance via either of the two methods below: >>> class Foo(object): pass >>> a = Foo() >>> a.x = 1 >>> a.x 1 >>> setattr(a, 'b', 2) >>> a.b 2 One can also assign properties via the property decorator. >>> class Bar(object): @property def x(self): return 0 >>> a = Bar() >>> a.x 0 My question is, how can I assign a property to an instance? My intuition was to try something like this... >>> class Doo(object): pass >>> a = Doo() >>> def k(): return 0 >

Multiple instances of a class being overwritten at the same time? (Python)

为君一笑 提交于 2021-02-07 06:27:05
问题 Here's a very simple code I made to demonstrate the problem I'm encountering. What's happening here is that I'm creating two different instances of the same class but changing an attribute of one will change the corresponding attribute of the other instance. I'm not sure why this is. Is this normal in Python or am I encountering something being totally messed up? class exampleClass(object): attribute1=0 attribute2="string" x=exampleClass x.attribute1=20 x.attribute2="Foo" y=exampleClass y

AWS instance change to https

扶醉桌前 提交于 2021-02-05 11:21:28
问题 We now use AWS to set up our website, we're recently trying to set up a page that will allow our customers to send emails to us. We set up an EC2 instance to work as an email server, but it runs on HTTP. Since our website works on HTTPS, ajax can't send HTTP messages and we have to make the EC2 instance run on HTTPS, but I don't know how to do that. $.ajax({ type: "POST", url: "https://ec2-*-*-*-*.*.compute.amazonaws.com/send", contentType: "application/json; charset=utf-8", beforeSend:

AWS instance change to https

风流意气都作罢 提交于 2021-02-05 11:21:12
问题 We now use AWS to set up our website, we're recently trying to set up a page that will allow our customers to send emails to us. We set up an EC2 instance to work as an email server, but it runs on HTTP. Since our website works on HTTPS, ajax can't send HTTP messages and we have to make the EC2 instance run on HTTPS, but I don't know how to do that. $.ajax({ type: "POST", url: "https://ec2-*-*-*-*.*.compute.amazonaws.com/send", contentType: "application/json; charset=utf-8", beforeSend:

How can I grab a reference of a game-object in a scene from a prefab

旧街凉风 提交于 2021-02-05 08:48:09
问题 currently I am working on a Equipment system that will Instantiate Game objects into the scene from a list, prior to this I was not using a Instantiation system with just keeping the Game Objects Active in the scene at all time. Now with Instantiating the Game Object(Prefab) I am running into the error of Loosing the References when I instantiate them, I have looked at various other articles before such as this Discussion here: However I am looking at alternative ways other than using Tags as

Java how to call method in another class

戏子无情 提交于 2021-02-04 21:39:15
问题 Sorry for the basic question but I'm learning, new to programming. I am trying to call a method that is in another class but I'm unable to without passing in the required values for the constructor of Cypher class. Do i really need a new instance of Cypher class each time i use a method in the Menu class and want to call a method of the Cypher class or how do I rewrite to avoid below. public class Runner { private static Cypher c; public static void main(String[] args) { Menu m = new Menu();

Meaning of the Private visibility modifier

断了今生、忘了曾经 提交于 2021-02-04 20:59:16
问题 In the class 'Tosee' below, hiddenInt is visible when I call s.hiddenInt. However, when I create a "ToSee" object in another class, 'CantSee', the private variable isn't visible. Why is this so? I was under the impression that private means that in any instance of a class, the client cant see that particular instance variable or method? Why then am I able to see hiddenInt in the main method of 'ToSee'? public class ToSee { private int hiddenInt = 5; public static void main(String[] args) {

Accessing typedef from the instance

余生颓废 提交于 2021-02-04 16:57:28
问题 As in stl containers, why can't we access a typedef inside the class from the class instance? Is there a particular insight into this? When value_type was a template parameter it could help making more general code if there wasn't the need to specify the template parameters as in vector::value_type Example: class T { public: typedef int value_type; value_type i; }; T t; T::value_type i; // ok t.value_type i; // won't work 回答1: The answer is use decltype to get the class first. E.g., decltype

django signals, how to use “instance”

末鹿安然 提交于 2021-02-04 13:09:12
问题 I am trying to create a system which enables user to upload a zipfile, and then extract it using post_save signal. class Project: .... file_zip=FileField(upload_to='projects/%Y/%m/%d') @receiver(post_save, sender=Project) def unzip_and_process(sender, **kwargs): #project_zip = FieldFile.open(file_zip, mode='rb') file_path = sender.instance.file_zip.path with zipfile.ZipFile(file_path, 'r') as project_zip: project_zip.extractall(re.search('[^\s]+(?=\.zip)', file_path).group(0)) project_zip

django signals, how to use “instance”

ε祈祈猫儿з 提交于 2021-02-04 13:08:06
问题 I am trying to create a system which enables user to upload a zipfile, and then extract it using post_save signal. class Project: .... file_zip=FileField(upload_to='projects/%Y/%m/%d') @receiver(post_save, sender=Project) def unzip_and_process(sender, **kwargs): #project_zip = FieldFile.open(file_zip, mode='rb') file_path = sender.instance.file_zip.path with zipfile.ZipFile(file_path, 'r') as project_zip: project_zip.extractall(re.search('[^\s]+(?=\.zip)', file_path).group(0)) project_zip