Python Forum
problem in output of a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem in output of a function
#8
(Sep-28-2023, 06:59 AM)akbarza Wrote: ? what does co_names do? where can I get more info about it?
It's an attribute(method) of built-in compile().
So if want look more at it has to look tutorials about compile(),
and not .co_names alone which is just one method.
>>> code = compile('print(55)', 'test', 'eval')
>>> exec(code)
55

# Use a couple of methods 
>>> code.co_names
('print',)
>>> code.co_code
b'\x97\x00\x02\x00e\x00d\x00\xa6\x01\x00\x00\xab\x01\x00\x00\x00\x00\x00\x00\x00\x00S\x00'

# All 
>>> [i for i in dir(code) if not i.startswith('__')]
['_co_code_adaptive', '_varname_from_oparg', 'co_argcount', 'co_cellvars', 'co_code',
'co_consts', 'co_exceptiontable', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars',
'co_kwonlyargcount', 'co_lines', 'co_linetable', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals',
'co_positions', 'co_posonlyargcount', 'co_qualname', 'co_stacksize', 'co_varnames', 'replace']

# look at help for compile
>>> help(compile)
Help on built-in function compile in module builtins:

compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1, *, _feature_version=-1)
    Compile source into a code object that can be executed by exec() or eval().

    The source code may represent a Python module, statement or expression.
    The filename will be used for run-time error messages.
    The mode must be 'exec' to compile a module, 'single' to compile a
    single (interactive) statement, or 'eval' to compile an expression.
    The flags argument, if present, controls which future statements influence
    the compilation of the code.
    The dont_inherit argument, if true, stops the compilation inheriting
    the effects of any future statements in effect in the code calling
    compile; if absent or false these statements do influence the compilation,
    in addition to any features explicitly specified.
akbarza likes this post
Reply


Messages In This Thread
problem in output of a function - by akbarza - Sep-27-2023, 06:34 AM
RE: problem in output of a function - by deanhystad - Sep-27-2023, 12:47 PM
RE: problem in output of a function - by akbarza - Sep-27-2023, 08:02 PM
RE: problem in output of a function - by deanhystad - Sep-27-2023, 08:14 PM
RE: problem in output of a function - by akbarza - Sep-27-2023, 08:20 PM
RE: problem in output of a function - by deanhystad - Sep-27-2023, 08:30 PM
RE: problem in output of a function - by akbarza - Sep-28-2023, 06:59 AM
RE: problem in output of a function - by snippsat - Sep-28-2023, 03:26 PM
RE: problem in output of a function - by akbarza - Sep-29-2023, 07:31 AM
RE: problem in output of a function - by snippsat - Sep-29-2023, 11:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 454 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  output shape problem with np.arange alan6690 5 825 Dec-26-2023, 05:44 PM
Last Post: deanhystad
  Python Pandas Syntax problem? Wrong Output, any ideas? Gbuoy 2 993 Jan-18-2023, 10:02 PM
Last Post: snippsat
  Facing problem with Pycharm - Not getting the expected output amortal03 1 903 Sep-09-2022, 05:44 PM
Last Post: Yoriz
  How to print the output of a defined function bshoushtarian 4 1,405 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  output correction using print() function afefDXCTN 3 11,304 Sep-18-2021, 06:57 PM
Last Post: Sky_Mx
  python prints none in function output chairmanme0wme0w 3 2,298 Jul-07-2021, 05:18 PM
Last Post: deanhystad
  print function output wrong with strings. mposwal 5 3,249 Feb-12-2021, 09:04 AM
Last Post: DPaul
  Output with none, print(x) in function Vidar567 3 2,592 Nov-24-2020, 05:40 PM
Last Post: deanhystad
  single input infinite output problem Chase91 2 2,028 Sep-23-2020, 10:01 PM
Last Post: Chase91

Forum Jump:

User Panel Messages

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