7

I am trying to post a question on StackOverflow but it seems like this message "Your post appears to contain code that is not properly formatted as code" keeps me from posting. I have indented every code I wrote here but I couldn't find why this is keep happening. This is the post below I was going to post.


I have created a simple framework and I uploaded it to pip.
After downloading my own package with pip install testoy and trying to import the function I wrote, the ModuleNotFoundError was raised and I could not import my own function(module as well). I think this might have something to do with how I wrote __init__.py in my framework. Is there anything that I should fix to make it work?

Framework structure

testoy
-testoy
    -__init__.py
    -build_sort_case.py
    -test_sort.py
-.gitignore
-LICENSE
-README.md
-setup.cfg
-setup.py  

__init__.py

from testoy.test_sort import decorator_sort  

test.py

from testoy.test_sort import decorator_sort # ERROR!
  
@decorator_sort
def my_sort(arr):
    pass  

Error

Traceback (most recent call last): File "/home/matt/Desktop/CS/test.py", line 1, in from testoy.test_sort import decorator_sort ModuleNotFoundError: No module named 'testoy.test_sort'

10
  • 1
    Hmm, that's weird...the formatting of that post certainly looks fine to me. I pasted it into the Ask Question page and it said it was fine. If it still doesn't work, perhaps try enclosing the error in a code block as well (generally, either is fine for that sort of one-line error).
    – Ryan M Mod
    Jul 29, 2020 at 23:03
  • 4
    I supect your abuse of codeformatting is to blame. In that first paragraph remove all the codeformatting. Where you indicate files like test.py do ### test.py instead.
    – rene
    Jul 29, 2020 at 23:04
  • @RyanM Enclosing the error in a code block worked! Thank you! but why was that causing a problem though? Jul 29, 2020 at 23:05
  • @rene Thank you for the opinion! Just a quick quesion as a newbie, when I want to use ### instead of inline code block for __init__.py, it keeps making it italic because of __ in front of that name of the file. How can I get around with this? Jul 29, 2020 at 23:07
  • 3
    ...why was that causing a problem though? -- I would imagine because the quoted block above looks a lot like code. Jul 29, 2020 at 23:07
  • @RobertHarvey I edit posts to include that, and it doesn't give me an error. In fact, trying it now doesn't give me an error.
    – 10 Rep
    Jul 29, 2020 at 23:07
  • Read the edit help about inline & block formatting of quotes & code including about backslash as escape in non-code & special strings like ### & other special treatment for lists, html etc. PS Words in prose that happen to appear in code but aren't actually code where they appear don't need code format & code format can lead to very difficult reading, though you might want to do it. PS When an error message has long lines it can be helpful to introduce line breaks in a code block.
    – philipxy
    Jul 29, 2020 at 23:13
  • @Backrub32 ### \_\_init__.py seems to do the trick but otherwise it wouldn't hurt if you use text to introduce that file: ### The initialization file __init__.py
    – rene
    Jul 29, 2020 at 23:24
  • Worth mentioning that are some oddities with special characters at the state transitions for the commonmark parsers: meta.stackexchange.com/questions/349717/…
    – rene
    Jul 29, 2020 at 23:27
  • In this case it's better to format that error message as code, because the underlines and line breaks are preserved. Plus sometimes Python error messages quotes some lines in the code.
    – user202729
    Jul 30, 2020 at 10:48

0

You must log in to answer this question.

Browse other questions tagged .