Advertisement
Guest User

Untitled

a guest
Oct 24th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. Project
  2.   |-api
  3.   |   \_____  __init__.py
  4.   |   \_____  mailListener.py
  5.   |-tests
  6.       \_____  __init__.py
  7.       \_____  test.py
  8.      
  9. ########################      
  10. In mailListener I have:
  11. ########################
  12. class MailListener:
  13.  
  14.     def __init__(self):
  15.         pass
  16.  
  17.     @staticmethod
  18.     def get_messages_and_service():
  19.         do smth
  20.         return smth
  21.  
  22.     def get_mail_text(self):
  23.         do smth2
  24.         return smth2
  25.  
  26.     def get_url_from_mail(self):
  27.         do smth3
  28.         return smth3
  29.  
  30.     def mark_message_as_read(self):
  31.         do smth4
  32.         return smth4
  33.  
  34. ########################      
  35. In test.py I have:
  36. ########################
  37. import sys
  38. import os
  39. sys.path.append(os.path.join(os.path.dirname(__file__), '..')) # ANY BETTER WAY TO AVOID THIS?
  40. import api_.mail_listener as ml                                # TO IMPORT THIS???? ;)
  41.  
  42.  
  43. os.chdir(r'../api_')
  44. a = ml.MailListener()
  45. k = a.get_mail_text()
  46. f = a.get_url_from_mail()
  47. print(k)
  48. print(f)
  49. g = a.mark_message_as_read()
  50.  
  51. And the question is: Is there any more ellegant way to import things from api_ package?
  52. I tried many imports, but only this one seems to work.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement