0

I am writing a python program on banking and am currently testing out whether I can successfully process a .txt file for processing. In visual studio 2019, attempting to execute the following classes below gives me an exception that the Queue module has no attribute 'get,' then later 'put' after handling the exception.

#INTEFERFACE CLASS
from Queue import Queue
from BankAccount import BankAccount
from BankAccount import Funds
from Transaction import Transaction

transaction = Transaction()
transaction.process_file()
transaction.add_transaction()
transaction.print_queue()

#TRANSACTION CLASS
from Queue import Queue

class Transaction:
    def __init__(self):
        self._transactions_list = []
        self._queue_list = Queue()

    #Open the file and process every line
    def process_file(self):
        temp = []
        #file_input = input("Enter the file ")
        #data_file = open(file_input, "r")
        data_file = open(r"C:\Users\manga\Downloads\BankTansIn.txt", "r")
        for line in data_file:
            word = line.split()
            for element in word:
                temp.append(element)
            self._transactions_list.append(temp)

    def add_transaction(self):
        #Process everything on the list then input into the queue
        process_file()
        list_copy = self._transactions_list[:]
        for word in list_copy:
            #Case checking; how many numbers are input?
            if len(word) == 2:
                self._queue_list.add_queue(word[0], word[1])
            elif len(word) == 3:
                self._queue_list.add_queue(word[0], word[1], word[2])
            elif len(word) == 4:
                self._queue_list.add_queue(word[0], word[1], word[2], word[3])

    #Call the Queue and create bank accounts and store in the binary tree as needed
    #Do account acctions as required
    #def process_all_transactions():
    
    def print_queue(self):
        temp_copy = self._queue_list._list
        for current_list in temp_copy:
            for current_item in (range(current_list)):
                print(current_item),

#QUEUE CLASS
class Queue:
    def __init__(self):
    #The main interface will be using a for loop to navigate a txt file for all processing
    def add_queue(self, item1 = "-1", item2 = "-1", item3 = "-1", item4 = "-1"):
        temp_list = []
        temp_list.append(item1)
        temp_list.append(item2)
        temp_list.append(item3)
        temp_list.append(item4)
        self._list.append(temp_list)

    def get_queue(self):
        return self._list
    
    def __str__(self):
        for curr_list in self._list:
            for each in range(len(list)):
                print(str(list[each])),

#TEXT FILE I AM TRYING TO READ
O Cash Johnny 1001
D 10010 542
D 10011 1542
D 10012 5442
D 10013 7540
D 10017 5442
D 10016 7542
D 10011 1500
D 10012 5000
D 10013 7000
D 10017 6543
D 10016 7576
W 10017 1000
W 10016 65
W 10010 72
T 10017 54 10015
W 10017 20000
H 1001
O Williams Hank 1253
D 12530 10000
D 12531 10000
D 12532 10000
D 12533 10000
D 12534 10000
D 12535 10000
D 12536 10000
D 12537 10000
D 12538 10000
D 12539 10000
H 12534
W 12532 15000
H 1253
T 12539 765 43567
O Nelson Willie 9876
O Willis Bob 9876

TRACEBACK
Traceback (most recent call last):
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 258, in _on_run
    self.process_net_command_json(self.py_db, json_contents)
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_process_net_command_json.py", line 190, in process_net_command_json
    py_db.writer.add_command(cmd)
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 329, in add_command
    self._cmd_queue.put(cmd, False)
AttributeError: 'Queue' object has no attribute 'put'
Traceback (most recent call last):
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\pydevd.py", line 1564, in process_internal_commands
    int_cmd = queue.get(False)
AttributeError: 'Queue' object has no attribute 'get'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 252, in run_file
    start_debugging(options.target)
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 243, in start_debugging
    debugpy.connect(options.address, access_token=options.adapter_access_token)
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\common\compat.py", line 210, in kwonly_f
    return f(*args, **kwargs)
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\__init__.py", line 135, in connect
    return api.connect(address, access_token=access_token)
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\api.py", line 143, in debug
    log.reraise_exception("{0}() failed:", func.__name__, level="info")
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\api.py", line 141, in debug
    return func(address, settrace_kwargs, **kwargs)
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\api.py", line 276, in connect
    _settrace(host=host, port=port, client_access_token=access_token, **settrace_kwargs)
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\api.py", line 47, in _settrace
    return pydevd.settrace(*args, **kwargs)
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\pydevd.py", line 2623, in settrace
    notify_stdin=notify_stdin,
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\pydevd.py", line 2715, in _locked_settrace
    py_db.wait_for_ready_to_run()
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\pydevd.py", line 682, in wait_for_ready_to_run
    self.process_internal_commands()
  File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\pydevd.py", line 1581, in process_internal_commands
    except _queue.Empty:  # @UndefinedVariable
AttributeError: module 'Queue' has no attribute 'Empty'
Press any key to continue . . .
小苹果
  • 11
  • 3
  • Please post the full traceback so that we can spot the failing line. – tdelaney Jun 02 '22 at 19:04
  • What is the name of this .py file? You `from Queue import Queue` but then create a class called `Queue`. Is that a different file? How does it relate to the standard `Queue` Module? – tdelaney Jun 02 '22 at 19:07
  • I gave the classes the same name as the classes- was I not supposed to do that? – 小苹果 Jun 02 '22 at 19:09
  • I made a mistake there, the standard module is "queue" and it has a class `queue.Queue`. Using "Queue" as a class name can be confusing so best avoided. The problem you have is that there is some module named "Queue" that we don't know anything about. And your module, after `from Queue import Queue` just overwrites it with the class definition. ... or maybe you are showing two different .py files here. That's why I asked. Is this one file or two? What are their names? What is the full traceback message? You don't call "get" in this code, so it would help to see where it is called. – tdelaney Jun 02 '22 at 19:47
  • The files are just one each. I am attempting to obtain the Queue class from the Queue module. – 小苹果 Jun 02 '22 at 19:55
  • I attempted to use https://stackoverflow.com/questions/3702675/how-to-catch-and-print-the-full-exception-traceback-without-halting-exiting-the inside of my interface module BUT I only get the same message as before when I put my code in between "try:" and "except Exception:" – 小苹果 Jun 02 '22 at 20:07
  • Its a challenging problem. The error is in `python\core\debugpy\_vendored\pydevd\pydevd.py`. I'm not sure what that module is, but it looks like a builtin part of the Visual Studio debugger. It seems like this code wanted to import the standard `queue.Queue` but got something different. This would happen if your script is called `queue.py`. Anyone wanting `queue.Queue` would get your version of Queue, not the standard lib version. I'm still not sure what `from Queue import Queue` does. There isn't a standard module called `Queue` ( capital Q) in python 3 - but there was one in python 2. – tdelaney Jun 02 '22 at 20:28
  • If you had a file called queue.py in your script's directory, that would explain the problem. – tdelaney Jun 02 '22 at 20:28
  • 1
    This solved the issue. It turned out my program confused a built-in VS object instead of using my class. Renamed Queue to queue_class and that solved the problem. – 小苹果 Jun 02 '22 at 20:35

0 Answers0