我知道如何通过在编辑器中运行它来在vim中打开和关闭语法高亮:
:syntax on/off
Run Code Online (Sandbox Code Playgroud)
但是我希望默认情况下启用语法突出显示,所以每次运行vim时都不必打开它.
我该怎么做呢?
我知道,Python中没有'真正的'私有/受保护方法.这种方法并不意味着隐藏任何东西; 我只是想了解Python的作用.
class Parent(object):
def _protected(self):
pass
def __private(self):
pass
class Child(Parent):
def foo(self):
self._protected() # This works
def bar(self):
self.__private() # This doesn't work, I get a AttributeError:
# 'Child' object has no attribute '_Child__private'
Run Code Online (Sandbox Code Playgroud)
那么,这种行为是否意味着,"受保护"方法将被继承,但"私有"根本不会被继承?
或者我错过了什么?
我想使用日志记录模块而不是打印调试信息和文档.目标是在控制台上使用DEBUG级别打印并登录到具有INFO级别的文件.
我阅读了很多关于日志记录模块的文档,食谱和其他教程,但无法弄清楚,我怎么能按照我想要的方式使用它.(我在python25上)
我想要在日志文件中写入日志的模块名称.
文档说我应该使用logger = logging.getLogger(__name__)但是如何声明其他模块/包中的类中使用的记录器,所以它们使用像主记录器一样的处理程序?要识别'父母'我可以使用,logger = logging.getLogger(parent.child)但我知道哪些人,谁调用了类/方法?`
下面的例子显示了我的问题,如果我运行它,输出将只有__main__登录并忽略日志Class
这是我的主文件:
# main.py
import logging
from module import Class
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# create file handler which logs info messages
fh = logging.FileHandler('foo.log', 'w', 'utf-8')
fh.setLevel(logging.INFO)
# create console handler with a debug log level
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# creating a formatter
formatter = logging.Formatter('- %(name)s - %(levelname)-8s: %(message)s')
# setting handler format
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the …Run Code Online (Sandbox Code Playgroud) 有更优雅的方式做以下事情吗?
private getHeaders(): Observable<any> {
let version;
let token;
return this.appInfo.getVersion()
.pipe(
tap(appVersion => version = appVersion),
mergeMap(() => this.storage.get('access_token')),
tap(accessToken => token = accessToken),
mergeMap(accessToken => of(this.createHeaders(version, token)))
);
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能更流畅地记住两个返回值,this.appInfo.getVersion()而this.storage.get('access_token')不是用rxjs的强大功能将它们写入临时变量?
也许将一些可观测量合并为一个?rxjs有很多运算符和东西......
运行以下代码时出现此错误
let foo = ' foo '
console.log(foo.trimLeft())
//foo.trimStart() works neither
Run Code Online (Sandbox Code Playgroud)
我知道互联网上的大多数解决方案都说,我必须修复我的tsconfig.json以包含 es20whatever。
有趣的是,我可以使用 es2018 的东西,比如 Promise.prototype.finally 和 rest spread 等。VSCode 也会自动完成trimStart(),这很奇怪,因为项目和编辑器应该使用相同的tsconfig.json. 但是这段特定的代码无法编译。
这是我的 tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "./",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"],
"plugins": [
{
"name": "tslint-language-service",
"configFile": "./tslint.json"
}
],
"paths": {
"foo": ["projects/foo/src/public_api.ts"],
"bar": ["projects/bar/src/public_api.ts"],
"baz": ["dist/baz"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在 monorepo 角度文件夹中运行它(如您所见)。也许这有问题,我不知道。
我是 Bottle 等框架的新手,正在阅读文档/教程。现在我遇到了模板引擎的问题:
我的文件index.tpl夹中有一个文件views。(它是纯 html)
当我使用以下代码时,它可以显示我的 html:
from bottle import Bottle, SimpleTemplate, run, template
app = Bottle()
@app.get('/')
def index():
return template('index')
run(app, debug=True)
Run Code Online (Sandbox Code Playgroud)
现在我想在我的项目中实现这个引擎并且不想使用template()
我想在文档中使用它,例如:
tpl = SimpleTemplate('index')
@app.get('/')
def index():
return tpl.render()
Run Code Online (Sandbox Code Playgroud)
但是如果我这样做,浏览器只会显示一个带有单词的白页
指数
写入,而不是加载模板。
在文档中,没有关于我如何使用这种 OO 方法的更多信息。我只是无法弄清楚为什么会发生这种情况以及我必须如何正确地做到这一点......
使用 .jscs 文件时,我经常在 Webstorm 中遇到以下错误。
JSCS: JSCS process timeout
这意味着什么?通常,如果我的 Javascript 代码未通过样式检查,我会收到错误标记并显示不正确的内容。但这种行为看起来像是一个更深层次的问题......
如何从客户那里混淆/隐藏我的Python代码,以便他无法改变他喜欢的来源?
我知道没有有效的方法可以隐藏Python代码,因此无法读取它.我只想要一个简单的保护,一个不知道自己在做什么的人不能只用文本编辑器打开源文件,并且不费吹灰之力地进行更改或轻松理解所有内容.因为我的代码编写得非常容易理解,所以我想隐藏我在第一时使用的主要原则.
如果有人真的想了解我做了什么,他会的.我知道.
那么你有一个常用的方法来为python代码提供简单的保护吗?
有没有简单的方法#从参数替换的bash变量中剥离/替换第一次出现的字符?我尝试了以下但它不起作用:
$ VERSION=0.11.3-issue#18.6a0b43d.123
$ echo ${VERSION#'#'}
$ echo ${VERSION#\#}
Run Code Online (Sandbox Code Playgroud)
我希望我的输出是:
0.11.3-issue18.6a0b43d.123
# ^
# no #
Run Code Online (Sandbox Code Playgroud)
对此有什么简单的解决方案 也许是以完全不同的方式?
python ×3
typescript ×2
bash ×1
bottle ×1
inheritance ×1
jscs ×1
logging ×1
methods ×1
namespaces ×1
obfuscation ×1
observable ×1
private ×1
protected ×1
rxjs ×1
substitution ×1
tsc ×1
vim ×1
webstorm ×1