Hướng dẫn source code of print function in python - mã nguồn của chức năng in trong python

Tôi đang cố gắng để có được mã nguồn in python bằng cách sử dụng kiểm tra nhưng đó là lỗi. Ai đó có thể vui lòng cho tôi biết cách lấy mã nguồn của câu lệnh in Python2.7.

inspect.getsourcefile[print]
---------------------------------------------------------------------------
TypeError                                 Traceback [most recent call last]
 in []
----> 1 inspect.getsourcefile[print]

/usr/lib/python3.4/inspect.py in getsourcefile[object]
    569     Return None if no way can be identified to get the source.
    570     """
--> 571     filename = getfile[object]
    572     all_bytecode_suffixes = importlib.machinery.DEBUG_BYTECODE_SUFFIXES[:]
    573     all_bytecode_suffixes += importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES[:]

/usr/lib/python3.4/inspect.py in getfile[object]
    534         return object.co_filename
    535     raise TypeError['{!r} is not a module, class, method, '
--> 536                     'function, traceback, frame, or code object'.format[object]]
    537 
    538 ModuleInfo = namedtuple['ModuleInfo', 'name suffix mode module_type']

TypeError:  is not a module, class, method, function, traceback, frame, or code object

In [86]: inspect.getsourcefile[builtin.print]
---------------------------------------------------------------------------
NameError                                 Traceback [most recent call last]
 in []
----> 1 inspect.getsourcefile[builtin.print]

NameError: name 'builtin' is not defined

Tệp này chứa văn bản unicode hai chiều có thể được giải thích hoặc biên dịch khác với những gì xuất hiện dưới đây. Để xem xét, hãy mở tệp trong một trình soạn thảo cho thấy các ký tự Unicode ẩn. Tìm hiểu thêm về các ký tự unicode hai chiều

Defprint _ [*args, ** kwargs]: print_[*args, **kwargs]:
"" "Chức năng in kiểu mới từ PY3K." ""
fp = kwargs.pop ["tệp", sys.stdout] = kwargs.pop["file", sys.stdout]
iffpisnone: fp is None:
return
defwrite [dữ liệu]: write[data]:
ifnotisInstance [dữ liệu, basestring]: not isinstance[data, basestring]:
data = str [dữ liệu] = str[data]
fp.write [dữ liệu].write[data]
want_unicode=False = False
sep = kwargs.pop ["sep", none] = kwargs.pop["sep", None]
ifsepisnotnone: sep is not None:
ifisInstance [sep, unicode]: isinstance[sep, unicode]:
want_unicode=True = True
ElifnotisInstance [SEP, STR]: not isinstance[sep, str]:
RaisetypeError ["SEP phải là không có hoặc một chuỗi"] TypeError["sep must be None or a string"]
end = kwargs.pop ["end", none] = kwargs.pop["end", None]
ifendisnotnone: end is not None:
ifisInstance [end, unicode]: isinstance[end, unicode]:
want_unicode=True = True
ElifnotisInstance [end, str]: not isinstance[end, str]:
RaisetypeError ["Kết thúc phải là không có hoặc một chuỗi"] TypeError["end must be None or a string"]
ifkwargs: kwargs:
raisetypeError ["đối số từ khóa không hợp lệ để in []"] TypeError["invalid keyword arguments to print[]"]
ifnotwant_unicode: not want_unicode:
forarginargs: arg in args:
ifisInstance [arg, unicode]: isinstance[arg, unicode]:
want_unicode=True = True
break
ifwant_unicode: want_unicode:
newline = u "\ n" = u"\n"
không gian = u "" = u" "
khác::
newline = "\ n" = "\n"
không gian = "" = " "
ifsepisnone: sep is None:
sep=space = space
ifendisnone: end is None:
end=newline = newline
fori, arginenumerate [args]: i, arg in enumerate[args]:
nếu tôi: i:
Viết [SEP][sep]
viết [arg][arg]
Viết [kết thúc][end]

Mã để in trong Python là gì?

Python print [] hàm hàm in [] in thông báo được chỉ định vào màn hình hoặc thiết bị đầu ra tiêu chuẩn khác. Thông báo có thể là một chuỗi hoặc bất kỳ đối tượng nào khác, đối tượng sẽ được chuyển đổi thành một chuỗi trước khi được ghi vào màn hình.print[] Function The print[] function prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen.

Mã nguồn trong Python ở đâu?

Nguồn cho bản thân Python 2.7 có thể được tìm thấy tại //hg.python.org/cpython.Các phiên bản khác của Python đã có nguồn được nhập vào Launchpad.Bạn có thể thấy chúng ở đây.Nhấp vào một cái bạn muốn xem và sau đó bạn có thể nhấp vào "Duyệt mã".//hg.python.org/cpython. Other versions of python have had their source imported onto Launchpad. You can see them here. Click on one you want to see and you can then click "Browse the Code".

Python có mã nguồn không?

Bởi vì các ứng dụng Python thường được phân phối dưới dạng mã nguồn, vai trò của thời gian chạy Python là chuyển đổi mã nguồn Python và thực thi nó trong một bước.Trong nội bộ, thời gian chạy Cpython không biên dịch mã của bạn.Một quan niệm sai lầm phổ biến là Python là một ngôn ngữ được giải thích.Nó thực sự được biên soạn.Python applications are typically distributed as source code, the role of the Python runtime is to convert the Python source code and execute it in one step. Internally, the CPython runtime does compile your code. A popular misconception is that Python is an interpreted language. It is actually compiled.

Print [] là một python được xây dựng trong chức năng?

Bạn đã sử dụng một số hàm tích hợp Python, ví dụ, hàm in [] được sử dụng để xuất một chuỗi trên bảng điều khiển.Đến bây giờ, phiên bản mới nhất của Python 3.8 có 69 chức năng tích hợp.the print[] function is used to output a string on the console. As of now, the latest version of Python 3.8 has 69 built-in functions.

Bài Viết Liên Quan

Chủ Đề