Python Forum
Error on import: SyntaxError: source code string cannot contain null bytes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error on import: SyntaxError: source code string cannot contain null bytes
#1
I am following a Python tutorial and have created the following module(from the tutorial) in Notepad under Windows 11:

def fib(n):    # write Fibonacci series up to n
    a, b = 0, 1
    while a < n:
        print(a, end=' ')
        a, b = b, a+b
    print()

def fib2(n):   # return Fibonacci series up to n
    result = []
    a, b = 0, 1
    while a < n:
        result.append(a)
        a, b = b, a+b
    return result
I have saved the module as fibo.py. When I attempt to import the module(import fibo), Python returns the error:
Error:
SyntaxError: source code string cannot contain null bytes
Now when I save the module as kw.py or kirk.py, the import works and calls to the functions in the module also work.

What am I missing here?
Gribouillis write Aug-01-2023, 03:54 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Error on import: SyntaxError: source code string cannot contain null bytes - by kirkwilliams2049 - Aug-01-2023, 03:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  delivery exe without source code py loky62 2 377 Apr-04-2024, 05:47 PM
Last Post: loky62
  Algorithm for extracting comments from Python source code Pavel1982 6 618 Feb-28-2024, 09:52 PM
Last Post: Pavel1982
  How to express null value klatlap 3 882 Mar-25-2023, 10:40 AM
Last Post: klatlap
  import module error tantony 5 3,542 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Cryptic Error with import statement Led_Zeppelin 2 2,590 Jan-11-2022, 01:13 PM
Last Post: Led_Zeppelin
  Install any library via pip get an error cannot import name 'SCHEME_KEYS' from 'pip. Anldra12 2 10,739 Jan-04-2022, 01:05 PM
Last Post: Anldra12
  value null when update in json file 3lnyn0 6 3,383 Dec-30-2021, 05:52 PM
Last Post: ndc85430
  No Module found in other directory than source code [SOLVED] AlphaInc 1 2,101 Nov-10-2021, 04:34 PM
Last Post: AlphaInc
  Generating classes diagram from source code Pavel_47 3 5,750 Oct-01-2021, 03:31 AM
Last Post: Lou
  How do I open the Source code of a library? JaneTan 1 2,315 Aug-18-2021, 02:12 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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