有没有办法替换C+的宏函数之类的数字+;用python? 当我开发C++应用程序时,我更喜欢使用宏函数来表示常量。它确实提高了代码的可读性
我一直在寻找在python上应用的方法,但找不到它 如果python语法中存在类似的函数,请告诉我如何执行,如果python语法中不存在类似的函数,请告诉我为什么python语法中不存在类似的函数有没有办法替换C+的宏函数之类的数字+;用python? 当我开发C++应用程序时,我更喜欢使用宏函数来表示常量。它确实提高了代码的可读性,python,macros,constants,Python,Macros,Constants,我一直在寻找在python上应用的方法,但找不到它 如果python语法中存在类似的函数,请告诉我如何执行,如果python语法中不存在类似的函数,请告诉我为什么python语法中不存在类似的函数 谢谢。您希望非程序员能够更改这些值,所以这是一种配置 您可以创建一个单独的文件,其中只包含对全局变量的分配,然后导入该文件,或者读取并执行该文件 示例(如中所用): C++宏的属性是什么?您想解决什么问题?为什么不将它们作为全局变量添加?但是,小心,它们不会让任何错误都被混淆,因为如何使常数宏(尤其是
谢谢。您希望非程序员能够更改这些值,所以这是一种配置 您可以创建一个单独的文件,其中只包含对全局变量的分配,然后导入该文件,或者读取并执行该文件 示例(如中所用):
C++宏的属性是什么?您想解决什么问题?为什么不将它们作为全局变量添加?但是,小心,它们不会让任何错误都被混淆,因为如何使常数宏(尤其是宏函数)在C++中有助于读取,所以我不知道如何在Python中复制它。在C++中,通常应该使用<代码> const <代码>变量,而不是宏,来表示常量。
#====================================================================================================
# General options
# All options have default value False
#====================================================================================================
obfuscate_strings = True # Don't rely on this for sensitive information
obfuscated_name_tail = '_opy_' # Will be added to all obfuscated names to avoid clashes with plain names
plain_marker = '_opy_' # Strings or comments containing this marker will not be obfuscated
pep8_comments = True # If True, only inline comments of the form <blank><blank>#<blank>
# will be recognized, allowing # to appear in strings as long as
# it doesn't have that particular form
#====================================================================================================
# Extensions of files that should be obfuscated
# Typically these are files containing Python source code
# Other files are just copied to the target directory
#====================================================================================================
source_extensions = '''
py
pyx
'''
#====================================================================================================
# Extensions of files that should neither be obfuscated nor copied to the target directory
# Typically these are .pyc files, which could easily be decompiled, breaking obfuscation
#====================================================================================================
skip_extensions = '''
pyc
'''
#====================================================================================================
# Fragments that, when occuring in the path of a file, will cause this file to be ignored
# In other words, such files will neither be ofuscated nor copied
# Use this to exclude complete directories from any processing by Opy
# N.B. Use forward slashes rather than backslashes, also on Windows!
#====================================================================================================
skip_path_fragments = '''
test_dummy
'''
#====================================================================================================
# Modules in sys.path containing identifiers that should not be obfuscated
# Typically these are installed standard or 3rd party modules of which you have no source code
# Use dotted names if needed, e.g. include both matplotlib and matplotlib.pyplot
#====================================================================================================
external_modules = '''
re
os
sys
errno
keyword
importlib
random
codecs
shutil
'''
#====================================================================================================
# Relative path + name of Python source files containing identifiers that should not be obfuscated
# Typically these are human readable settings files loaded and exec'ed at runtime by your program
# Do not use this facility for files that are imported, that's what external_modules is for
# Also don't use it to keep the original file name for your main module, that what plain_names is for
#====================================================================================================
plain_files = '''
opy_config.txt
'''
#====================================================================================================
# Extra identifiers and module names (as opposed to contents) that should not be obfuscated
# Probably at least the names of your main modules (so not their filenames) go here
# If e.g. your main module is in my_main_module.py, include my_main_module in plain_names
#====================================================================================================
plain_names = '''
opy
poly_walker_test
'''
# =========== Read config file
try:
configFile = open (configFilePath)
except Exception as exception:
print (exception)
printHelpAndExit (1)
exec (configFile.read ())
configFile.close ()
def getConfig (parameter, default):
try:
return eval (parameter)
except:
return default
obfuscateStrings = getConfig ('obfuscate_strings', False)
asciiStrings = getConfig ('ascii_strings', False)
obfuscatedNameTail = getConfig ('obfuscated_name_tail', '_{}_'.format (programName))
plainMarker = getConfig ('plain_marker', '_{}_'.format (programName))
pep8Comments = getConfig ('pep8_comments', True)
sourceFileNameExtensionList = getConfig ('source_extensions.split ()', ['py', 'pyx'])
skipFileNameExtensionList = getConfig ('skip_extensions.split ()', ['pyc'])
skipPathFragmentList = getConfig ('skip_path_fragments.split ()', [])
externalModuleNameList = getConfig ('external_modules.split ()', [])
plainFileRelPathList = getConfig ('plain_files.split ()', [])
extraPlainWordList = getConfig ('plain_names.split ()', [])