Python Forum
[split] Bad magic number. What is it ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Bad magic number. What is it ?
#1
I have the same problem as Sylas has described although I am not interested what a bad magic number is unless the information leads to a solution.
I am following a tutorial topic 'How To Import Modules in Python 3' at https://www.digitalocean.com/community/t...n-python-3 All went well until, following instructions, I moved the module file hello.py from the same directory as the file which imports the module, main_program.py, to one of the directories listed by print(sys.path), namely, /home/<myusername>/.local/lib/python3.5/site-packages/hello.py
hello.py
# Define a function
def world():
    print("Hello, World!") 

main_program.py
# Import hello module
import hello

# Call function
hello.world()
This results in the same error message as reported my Sylas.
Error:
Traceback (most recent call last): File "main_program.py", line 2, in <module> import hello ImportError: bad magic number in 'hello': b'\x03\xf3\r\n'
I am running Python 3.6.5 (default, Sep 6 2018, 17:29:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux 3.10.0-862.3.2.el7.x86_64.
Reply
#2
https://stackoverflow.com/a/514395/4046632
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you buran. As mentioned in https://stackoverflow.com/a/514395/4046632 there was a .pyc file in the calling program's directory and deleting it fixed the 'ImportError: bad magic number' error.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Split a number to list and list sum must be number sunny9495 5 2,197 Apr-28-2022, 09:32 AM
Last Post: Dexty
  magic related field in Django model sonh 1 1,202 Apr-24-2022, 12:37 PM
Last Post: sonh
  Need a little help with numpy array magic. pmf71 0 1,126 Dec-01-2021, 02:51 AM
Last Post: pmf71
  Magic Method Arithmetic Operators ClownPrinceOfCrime 3 2,280 Jan-10-2021, 03:24 PM
Last Post: ndc85430
  How to eliminate magic squares formed by the same numbers, but permuted frame 7 3,554 May-09-2019, 11:28 AM
Last Post: frame
  Split Column Text by Number of Characters cgoldstein 3 2,948 Mar-11-2019, 01:45 PM
Last Post: perfringo
  Magic method __str__ dan789 16 7,076 Dec-23-2018, 03:59 PM
Last Post: ichabod801
  How to add metakernel magic for python rikaki__ 0 1,993 Jul-04-2018, 02:49 AM
Last Post: rikaki__
  Split docx document by page number sage 1 8,567 May-15-2018, 06:17 PM
Last Post: buran
  Split string at specific number TimeMen 6 3,955 May-01-2018, 07:09 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020