Module imported in one function NameError in another function called afterward

I have a Python3 script that installs pip3 and and a digitalocean module for creating droplets.

I have broken up the script into 3 functions, Install(), Run(), and Uninstall. In the Install function I can install pip3 and the digitalocean module.

I have multiple functions that I want to call in the Run() function. At the beginning of Run() I import the digitalocean module. When I call another function that uses this module I get “NameError: name ‘digitalocean’ is not defined”.

Everything I have read says that I can import in a function and then use that import in another function. I don’t know if Python3 is diffrent? Something I am missing?(has to be)

Here is relevant code that has the bulk pulled out. Let me know if you need more.

#!/usr/bin/python3  import importlib.util from subprocess import Popen, PIPE, STDOUT import sys import subprocess import time   accessToken                 = 'ABC' dropletName                 = 'newDropletAndTag' tagName                     = dropletName  def Install():     pass     #This function installs the package and other things if they are not already present.    def CreateDroplet():     newDroplet = digitalocean.Droplet(  token       = accessToken,                                          name        = dropletName,                                         region      = 'NYC1',                                         image       = 'ubuntu-16-04-x64',                                         size_slug   = 's-1vcpu-1gb',                                         ssh_keys    = sshKeysList,                                          backups     = False                                         )      def Run():     import digitalocean     myManager = digitalocean.Manager(token=accessToken)     myDroplets = myManager.get_all_droplets(tag_name=tagName)      Install()      CreateDroplet()   def Main():     #START OF SCRIPT     print('\n\n\n')     print('---- Start Of Script ----')     Run()     print('---- End Of Script ----')     print('\n\n\n')     #END OF SCRIPT if __name__ == '__main__':     Main() 

Create List Item in Another Site Collection Using REST API from Visual Studio Workflow

I have developed a List Workflow in Visual Studio 2013.

In this, I am trying to read the current item’s Title and create an item in another list in another site collection.

Please read the last part clearly. I have to create an item in a list in a different site collection. But, both the site collections have the same user with contribute permissions. Since I have to create a list item in another site collection, I have no option than to use REST API to create a list Item. But to create a list item using REST API, I need to post a request to http://{siteName}/_api/web/lists/getbytitle('listTitle')/items URL and post the type, Title and other columns and X-RequestDisgest attributes in the payload. I am not sure, how to get the X-RequestDigest in my workflow.

If I skip this digest, I get an unauthorized exception upon checking it in Fiddler. Can anyone please help?

Drupal 8 Image moving to another location when entity update

I have an image field in my content type and when I upload image it will save to a location as expected. Now I want to move that saved image to another location when entity inserting or updating process. Can anyone help?

I tried using image->save($ newlocation) but when the entity loading it will give an error as can’t find source image.

Can I use whatsapp with a number belonging to another phone

I currently have a Samsung S5 phone but find it bulky to carry and as I use it mainly for old fashioned calls I was thinking of moving my simcard (and therefore phone number) to my old Motorola Razr. I understand that the S5 will effectively become like a small tablet and the email will still work on the S5 but will whatsapp if I am using the number on another phone?
Will my whatsapp contacts notice any difference or will it work exactly as it currently does? Thanks

Migrating mounted ntfs folders to another installation

I’m using server 2012 r2 + drivepool + jbod 4u60, the drives are mounted to 20ish ntfs mount folders, and now i want to migrate to another machine with better specs. The idea is just to swap the sas card and then i hope i dont have to remount the drives again because i want to minimize downtime. Is there anyway to copy these mount folders to the new machine? Or do i have to recreate and re-mount them again one by one? Cause when i tried to copy them, its actually copying the entire drive…

Route Docker container traffic through another container

I’m trying to route tcp traffic of container B (10.10.1.2, custom binary using mysql and running on port 4242) through container A (10.10.1.3, haproxy, setup in transparent proxy mode) to the outside world, they share the same user defined docker network 10.10.1.0/24 in bridge mode

Container B doesn’t expose ports, only container A.

On container B:

# ip route show default via 10.10.1.1 dev eth0 10.10.1.0/24 dev eth0 proto kernel scope link src 10.10.1.2 # ip route replace default via 10.10.1.3 # ip route show default via 10.10.1.3 dev eth0 10.10.1.0/24 dev eth0 proto kernel scope link src 10.10.1.2 

On container A (haproxy):

sysctl -w net.ipv4.ip_forward=1 sysctl -w net.ipv4.ip_nonlocal_bind=1 iptables -t mangle -N DIVERT iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT iptables -t mangle -A PREROUTING -p tcp -s 10.10.1.0/24 --sport 4242 -j DIVERT iptables -t mangle -A DIVERT -j MARK --set-mark 1 iptables -t mangle -A DIVERT -j ACCEPT ip rule add fwmark 1 lookup 100 ip route add local 0.0.0.0/0 dev lo table 100 

net.ipv4.ip_forward is set to 1 everywhere, Docker run with default options.

But when I change the route; because it must answer back to container A; container B can’t reach anything, a simple ping google.com timeout.

I’m not a specialist but according to the tcpdump commands I have ran on the 3 parts, there is an exchange between them. Maybe some paquets are not passing through ?

I’m I missing nothing? it should be pretty simple but I can’t get I working I don’t understand why.

Thank you

How to add objects to arraylist with another class?

Basically my professor told me to make use of arraylist? I don’t get his point to be honest.. i think he wants me to add objects to arraylist? which right now, I really have no idea how to do it..

My code is running and is really fine. However, he still wanted me to make use of arraylist to make it look better?

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package ahaprogram2;

   import java.util.ArrayList;    import java.util.Scanner;     public class AhaProgram {    public static Container container1 = new Container("Container 1: "); public static Container container2 = new Container("Container 2: "); public static Container container3 = new Container("Container 3: "); public static Container container4 = new Container("Container 4: "); public static Container container5 = new Container("Container 5: "); public static boolean loop = false;  public static void main(String[] args) {        Scanner reader = new Scanner(System.in);     System.out.println("Hello! This is the AHA Program of Jalosjos,     Parreno and Alfonso");     System.out.println("Please type the letter of your option");        while (loop != true) {          showOptions();         InputHandler();      } }  public static void InputHandler() {      Scanner reader = new Scanner(System.in);      String optionletter = reader.nextLine();     if (optionletter.equals("A")) {  // OPTION A             System.out.println("There are 5 containers.. What container      will you name? ");             System.out.print("Type the number of your container: ");             String contInput = reader.nextLine();              if (contInput.equals("1")) {                 System.out.print("Input the name of Container 1: ");                 String ContInp1 = reader.nextLine();                 container1.renameCont(ContInp1);                                     container1.printContainer();              } else if (contInput.equals("2")) {                 System.out.print("Input the name of Container 2: ");                 String ContInp2 = reader.nextLine();                 container2.renameCont(ContInp2);                                     container2.printContainer();             } else if (contInput.equals("3")) {                 System.out.print("Input the name of Container 3: ");                 String ContInp3 = reader.nextLine();                 container3.renameCont(ContInp3);                                     container3.printContainer();             } else if (contInput.equals("4")) {                 System.out.print("Input the name of Container 4: ");                 String ContInp4 = reader.nextLine();                 container4.renameCont(ContInp4);                                     container4.printContainer();              } else if (contInput.equals("5")) {                 System.out.print("Input the name of Container 5: ");                 String ContInp5 = reader.nextLine();                 container5.renameCont(ContInp5);                                     container5.printContainer();             }          }          if (optionletter.equals("B")) {    // for option B             System.out.println("Which container will you use?");             System.out.print("Type a number for the container: ");             String contforAdd = reader.nextLine();              if (contforAdd.equals("1")) {                  System.out.print("How many cans will you add?: ");                 int numofCans1 = Integer.parseInt(reader.nextLine());                  for (int i = 0; i < numofCans1; i++) {                     System.out.print("Enter the name of Can " + (i + 1) +            " : ");                     String CanName = reader.nextLine();                     container1.AddCan(CanName);                  }                 System.out.println("**CANS ADDED SUCCESSFULLY**");             }              if (contforAdd.equals("2")) {                  System.out.print("How many cans will you add?: ");                 int numofCans2 = Integer.parseInt(reader.nextLine());                  for (int i = 0; i < numofCans2; i++) {                     System.out.print("Enter the name of Can " + (i + 1) +             " : ");                     String CanName = reader.nextLine();                     container2.AddCan(CanName);                  }                 System.out.println("**CANS ADDED SUCCESSFULLY**");             }              if (contforAdd.equals("3")) {                  System.out.print("How many cans will you add?: ");                 int numofCans3 = Integer.parseInt(reader.nextLine());                  for (int i = 0; i < numofCans3; i++) {                     System.out.print("Enter the name of Can " + (i + 1) +            " : ");                     String CanName = reader.nextLine();                     container3.AddCan(CanName);                  }                 System.out.println("**CANS ADDED SUCCESSFULLY**");             }             if (contforAdd.equals("4")) {                  System.out.print("How many cans will you add?: ");                 int numofCans4 = Integer.parseInt(reader.nextLine());                  for (int i = 0; i < numofCans4; i++) {                     System.out.print("Enter the name of Can " + (i + 1) +              " : ");                     String CanName = reader.nextLine();                     container4.AddCan(CanName);                  }                 System.out.println("**CANS ADDED SUCCESSFULLY**");             }              if (contforAdd.equals("5")) {                  System.out.print("How many cans will you add?: ");                 int numofCans5 = Integer.parseInt(reader.nextLine());                  for (int i = 0; i < numofCans5; i++) {                     System.out.print("Enter the name of Can " + (i + 1) +                " : ");                     String CanName = reader.nextLine();                     container5.AddCan(CanName);                  }                 System.out.println("**CANS ADDED SUCCESSFULLY**");             }          }          if (optionletter.equals("C")) {                             System.out.println("Which container will you use?");             System.out.print("Type a number for the container: ");             String contforRemove = reader.nextLine();              if (contforRemove.equals("1")) {                                     System.out.print("What can will you remove?: ");                 String canRemove = reader.nextLine();                 container1.RemoveCan(canRemove);             }              if (contforRemove.equals("2")) {                                     System.out.print("What can will you remove?: ");                 String canRemove = reader.nextLine();                 container2.RemoveCan(canRemove);             }              if (contforRemove.equals("3")) {                                     System.out.print("What can will you remove?: ");                 String canRemove = reader.nextLine();                 container3.RemoveCan(canRemove);             }              if (contforRemove.equals("4")) {                                     System.out.print("What can will you remove?: ");                 String canRemove = reader.nextLine();                 container4.RemoveCan(canRemove);             }              if (contforRemove.equals("5")) {                                     System.out.print("What can will you remove?: ");                 String canRemove = reader.nextLine();                 container5.RemoveCan(canRemove);             }           }            if (optionletter.equals("D")) {             showOptionsDisplay();             System.out.print("Type a letter: ");             String letterDisplay = reader.nextLine();              if (letterDisplay.equals("A")) {                 container1.printContents();                 System.out.println("");             }              if (letterDisplay.equals("B")) {                 container2.printContents();                 System.out.println("");             }              if (letterDisplay.equals("C")) {                 container3.printContents();                 System.out.println("");             }              if (letterDisplay.equals("D")) {                 container4.printContents();                 System.out.println("");             }              if (letterDisplay.equals("E")) {                 container5.printContents();                 System.out.println("");             }              if (letterDisplay.equals("F")) {                 container1.printContents();                 System.out.println("");                 container2.printContents();                 System.out.println("");                 container3.printContents();                 System.out.println("");                 container4.printContents();                 System.out.println("");                 container5.printContents();                 System.out.println("");             }         }          if (optionletter.equals("E")) {             System.out.println("");             System.out.println("");             System.out.println("");             System.out.println("Thank you for using our program. MWAH!");             loop = true;         }           }         public static void showOptions() {     System.out.println("A = Name Containers");     System.out.println("B = Add Cans");     System.out.println("C = Remove Cans");     System.out.println("D = Display Cans");     System.out.println("E = Quit");     System.out.print("Type a Letter: ");      }      public static void showOptionsDisplay() {     System.out.println("Pick an Option");     System.out.println("A = Display container 1");     System.out.println("B = Display container 2");     System.out.println("C = Display container 3");     System.out.println("D = Display container 4");     System.out.println("E = Display container 5");     System.out.println("F = Display all containers");      }       } 

Here is the other class

     package ahaprogram2;       import java.util.ArrayList;      import java.util.Scanner;    public class Container {  Scanner reader  = new Scanner(System.in);  public ArrayList<String> CanContainer = new ArrayList<String>();  public int Contsizep;  public String contName;  public String changeName;     public Container(String contname){      this.contName = contname;   }   public void AddCan(String CantoAdd) {      this.CanContainer.add(CantoAdd);  }   public void RemoveCan(String CantoRemove) {       if (this.CanContainer.contains(CantoRemove)) {          this.CanContainer.remove(CantoRemove);             System.out.println("** " + CantoRemove + " Can removed       successfully**");      }       else {           System.out.println("Can cannot be found.. make sure to put the        exact name!!");       }          }      public void renameCont(String changename) {     this.contName += changename;     }       public void printContents() {      System.out.println("Here are the contents of " + contName);      System.out.println("");      for(String counter : this.CanContainer){          System.out.println(counter); }          }        public void printContainer() {  // for OPTION A ONLY      System.out.println("CONTAINER NAME SUCCESSFUL: ** " + contName +     "**");    }    } 

I just would like to put everything to an arraylist please help.. again my professor doesn’t teach us face to face that’s why I’m really trying my best to watch videos in youtube and to ask here also..