Attibute Error: Two methods in a class, one I can reach, the other not (phantom file? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Attibute Error: Two methods in a class, one I can reach, the other not (phantom file? (/thread-12497.html) |
Attibute Error: Two methods in a class, one I can reach, the other not (phantom file? - GaryKuipers - Aug-27-2018 This is my first post so ... forgive any faux pas. Python3.6 asyncioThis seems straightforward, right? The name must be wrong: The calling program: Note that the first line causes a problem. If that line is commented the second line succeeeds. import asyncio import logging import json from Database.database import Database from Database.database_processes import DatabaseProcess ... self.dbprocess = DatabaseProcess(self.log, self.database) --- await self.dbprocess.update_card_in_information_from_card_number(request.requestor, request.card_number) request.card_record = await self.dbprocess.get_card_record_from_card_number(request.card_number)Here is the class(callee): import asyncio import logging class DatabaseProcess(object): def __init__(self, log, database): self.database = database ... async def get_card_record_from_card_number(self, card_number): stmt = "select * from cards where card_number = '{}' and dt_inactivated is null".format(card_number) ... async def update_card_in_information_from_card_number(self, machine_id, card_number): exec_stmt = "update cards set dt_last_inserted = now(), last_machine_id = %s where card_number = %s" ...Here is where it goes bonkers: if I go to the file database_processes.py which contains the DatabaseProcess class and mangle the second name, the one that works, it keeps working. Aha! we say, must be a duplicate file somewhere in teh path where this class is defined as well ... It seems not! grep 'class DatabaseProcess' find / -name 'database*.py' grep 'a' find . -name 'database*.py' root@glaptop:/home/.../Database# grep 'class DatabaseProcess' find .../projects/ -name '*.py*' /home/gary/projects/Brix/Database/database_processes.py:class DatabaseProcess(object): FINDS IT, that is where I expect it to be. The search starts very high in the directory tree, high enough to find it anywhere. But this finds nothing in dist-packages (and I wuld not exepct it to becasue this is a dev box) root@gary-laptop:/home/.../Database# grep 'class DatabaseProcess' find /usr/lib/python3/dist-packages/ -name '*.py*' What am I missing? Thanks for helpting! RE: Attibute Error: Two methods in a class, one I can reach, the other not (phantom file? - GaryKuipers - Aug-27-2018 Explained in a more abstract way, a program is finding a class in a place that i can't determine: Datum 1: have a program P that instantiates a class C in file c.py with two methods, A and B import the_dir_where_C_is.C import C from P: A is called before B this produces an error: Attribute Error: 'C' object has no attribute 'A' if I comment the call to A, B executes w/o problem Datum 2: if I go to file c.py and mangle the 'B' method (by giving it name X), the progra P still runs Conclusion 1: program P is NOT using c.py to get class C. Datum 3: The prohect only has one If B is being obtained elsewhere then there must be a file "z.py" which contains it greping for 'B' should find the file I used find from / and it only found one c.py I grepped huge chunks of the computer for "def B" and found nothing $PYTHONPATH is empty The Pycharm IDE finds the missing "def A" without problems RE: Attibute Error: Two methods in a class, one I can reach, the other not (phantom file? - GaryKuipers - Aug-27-2018 It seems to be a problme when I switch from the dev user to runnig under sudo (root). Has to do with paths ... I can get that, what I don;t understand is where is it getting the "phantom file" that contains update_card_in_information_from_card_number but not update_card_in_information_from_card_number. RE: Attibute Error: Two methods in a class, one I can reach, the other not (phantom file? - Gribouillis - Aug-28-2018 You could try import inspect print('HERE --> ', inspect.getsourcefile(DatabaseProcess)) RE: Attibute Error: Two methods in a class, one I can reach, the other not (phantom file? - GaryKuipers - Aug-28-2018 The problem was that I keep the programs and the classes at the same level. I found the solution in creating a run file just above the directories: top directory run.py import programs.my_prog programs.my_prog.main() {/python] programs [python] from classes.myclass import ...classes This link helps: https://stackoverflow.com/questions/2325923/how-to-fix-importerror-no-module-named-error-in-python I think this solves the problme |