title: Need Help Unpickling as String on Python
body: <p>I need help unpickling using Python 3.4.3, and I need to do it as an integer. However it results in an error. How do I unpickle data that I saved before as an integer. The error is posted below.</p>
  
  <pre><code>import pickle
  import shelve
  f = open('p.pickle', 'wb')
  d = open('p.pickle', 'rb')
  
  def CreatePickle():
      global shop_revenue
      global stock_coke
      global stock_mint
      global stock_sandwich
      pickle.dump(shop_revenue, f)
      pickle.dump(stock_coke, f)
      pickle.dump(stock_mint, f)
      pickle.dump(stock_sandwich, f)
  
  def LoadPickle(file):
      global shop_revenue
      global stock_coke
      global stock_mint
      global stock_sandwich
      shop_revenue = pickle.Unpickler(file)
      stock_coke = pickle.Unpickler(file)
      stock_mint =  pickle.Unpickler(file)
      stock_sandwich = pickle.Unpickler(file)
  
  shop_revenue = 10000
  total = 0.0
  sales_cash = 0.0
  sales_creditcard = 0.0
  sales_octopus = 0.0
  cost_sandwich = 5.0
  cost_coke = 3.0
  cost_mint = 6.0
  stock_sandwich = 20
  stock_coke = 20
  stock_mint = 20
  password_manager = ""
  password = ""
  accounts = ["0","0","0","0","0","0","0"]
  names = ["0","0","0","0","0","0","0"]
  def StartUp():
      global names
      global accounts
      global password
      global password_manager
      global shop_revenue
      global stock_coke
      global stock_mint
      global stock_sandwich
      LoadPickle(d)
      userselect = input("1: Cashier \n \n 2: Manager \n \n 3: Quit")
      if userselect == "1":
          password = input("Enter cashier's password")
          if password == "4123":
           print("Hello Michael")
           Cashier()
          elif password == accounts[i]:
              print("Hello", names[i])
              Cashier()
          else:
              print("Invalid Input")
              StartUp()
      elif userselect == "2":
          password_manager = input("Enter manager password")
          if password_manager == "123456":
              Manager()
          else:
              print("Invalid Input")
              StartUp()
      elif userselect == "3":
          CreatePickle()
          quit()
      else:
          print("Invalid input")
          StartUp()
  def Cashier():
      global total
      c_optionselect = input("1: Start sale \n \n 2: Quit")
      if c_optionselect == "2":
              StartUp()
      elif c_optionselect == "1":
              print("----Welcome to Star Store----")
              Sale()
      else:
          print("Invalid input")
          Cashier()
  def Sale():
      global cost_coke
      global cost_mint
      global cost_sandwich
      global stock_sandwich
      global stock_mint
      global stock_coke
      global sales_cash
      global sales_creditcard
      global sales_octopus
      global total
      global shop_revenue
      addsale = int(input("1: Sandwich \n \n 2: Coke \n \n 3: Mint" \
                           "\n \n 4: Remove Previous \n \n 5:Display Receipt"))
      if addsale == 1 and stock_sandwich &gt;= 1:
          total = total + cost_sandwich
          stock_sandwich = stock_sandwich - 1
          shop_revenue = shop_revenue + cost_sandwich
          print("Sandwich    $",cost_sandwich)
          Sale()
      elif addsale == 2 and stock_coke &gt;= 1:
          total = total + cost_coke
          stock_coke = stock_coke - 1
          shop_revenue = shop_revenue + cost_coke
          print("Coke        $",cost_coke)
          Sale()
      elif addsale == 3 and stock_mint &gt;= 1:
          total = total + cost_mint
          stock_mint = stock_mint - 1
          shop_revenue = shop_revenue + cost_mint
          print("Mint        $",cost_mint)
          Sale()
      elif addsale == 5:
          print("Total is: $", total)
          print("---Thank you for Shopping---")
          method_payment = int(input("Select method of payment \n \n" \
                      "1: Cash \n \n 2: Octopus \n \n 3: Credit Card"))
          if method_payment == 1:
              sales_cash = total + sales_cash
          elif method_payment == 2:
              sales_octopus = total + sales_octopus
          elif method_payment == 3:
              sales_creditcard = total + sales_creditcard
          total = 0
          Cashier()
      else:
          print("Invalid input")
          Sale()
  
  def Manager():
      global sales_cash
      global sales_creditcard
      global sales_octopus
      global cost_coke
      global cost_mint
      global cost_sandwich
      global stock_sandwich
      global stock_mint
      global stock_coke
      global accounts
      global i
      global names
      global shop_revenue
      m_optionselect = input("1: Stock Price \n \n 2: Check inventory" \
                  "\n \n 3: Check Sales \n \n 4: Create new account" \
                           "\n \n 5: Buy stock \n \n " \
                           "6: Check Revenue \n \n 7: Quit")
      if m_optionselect == "7":
              StartUp()
      elif m_optionselect == "3":
          print("Sales by cash: $",sales_cash)
          print("Sales by octopus: $",sales_octopus)
          print("Sales by credit card: $",sales_creditcard)
          Manager()
      elif m_optionselect == "2":
              print("Number of sandwiches", stock_sandwich)
              print("Number of cokes", stock_coke)
              print("Number of mint", stock_mint)
              Manager()
      elif m_optionselect == "1":
          stock_change = input("Select item to change price: \n \n" \
                      "1: Sandwich \n \n 2: Coke \n \n 3:Mint")
          if stock_change == "1":
                  sandwich_change = float(input("Enter new price"))
                  cost_sandwich = 0 + sandwich_change
                  Manager()
          elif stock_change == "2":
                  coke_change = float(input("Enter new price"))
                  cost_coke = 0 + coke_change
                  Manager()
          elif stock_change == "3":
                  mint_change = float(input("Enter new price"))
                  cost_mint = 0 + mint_change
                  Manager()
          else:
              print("Invalid input")
              Manager()
      elif m_optionselect == "4":
          number_accounts = int(input("How many new accounts"))
          for i in range(0,number_accounts):
              temp2 = input("Enter names of the account holder")
              temp = input("Enter account password here")
              names[i] = temp2
              accounts[i] = temp
          Manager()
      elif m_optionselect == "5":
          add_stock_choice = input("1: Sandwich \n \n 2: Coke \n \n 3: Mint")
          if add_stock_choice == "1" and shop_revenue &gt;= 4:
              add_stock_sandwich = int(input("$4.00/sandwich \n \n Enter amount"))
              stock_sandwich = add_stock_sandwich + stock_sandwich
              shop_revenue = shop_revenue - 4*(add_stock_sandwich)
              Manager()
          elif add_stock_choice == "2" and shop_revenue &gt;= 2.5:
              add_stock_coke = int(input("$2.50/coke \n \n Enter amount"))
              stock_coke = add_stock_coke + stock_coke
              shop_revenue = shop_revenue - 2.5*(add_stock_coke)
              Manager()
          elif add_stock_choice == "3" and shop_revenue &gt;= 5:
              add_stock_mint = int(input("$5.00/mint \n \n Enter amount"))
              stock_mint = add_stock_mint + stock_mint
              shop_revenue = shop_revenue - 5*(add_stock_mint)
              Manager()
          else:
              print("Invalid Input")
              Manager()
      elif m_optionselect == "6":
          print("The revenue is $",shop_revenue)
          print("Total profit is $",shop_revenue-10000)
          Manager()
      else:
          print("Invalid input")
          Manager()
  CreatePickle()
  StartUp()
  </code></pre>
  
  <p>Here is the full error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;string&gt;", line 420, in run_nodebug
    File "C:\Users\User\Desktop\Culminating 2.py", line 232, in &lt;module&gt;
      StartUp()
    File "C:\Users\User\Desktop\Culminating 2.py", line 68, in StartUp
      Cashier()
    File "C:\Users\User\Desktop\Culminating 2.py", line 95, in Cashier
      Sale()
    File "C:\Users\User\Desktop\Culminating 2.py", line 113, in Sale
      if addsale == 1 and stock_sandwich &gt;= 1:
  TypeError: unorderable types: _pickle.Unpickler() &gt;= int()
  </code></pre>
  
  <p>I assume the error says that the data type is not an integer. How do I make it so that pickle loads the file as an integer?</p>