我正在编写一个终端应用程序,在传入-v
选项之后,毫不奇怪地得到了详细信息.我想在终端中提供输出,以便于测试(无论如何,当它作为cron运行时,它会被重定向到日志文件).
但是,python logging
模块不允许我在使用格式化程序时写出具有相应级别的消息.(格式化程序直接从Python Logging Cookbok复制)
此行为不仅限于Python3.Python2.7在给定条件下引发相同的异常.
one.py
from sys import stdout
import logging
if __name__ == '__main__':
level = 20
log = logging.getLogger()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler = logging.StreamHandler(stdout).setFormatter(formatter)
log.addHandler(handler)
log.setLevel(level)
log.info("Blah")
Run Code Online (Sandbox Code Playgroud)
one.py输出
Traceback (most recent call last):
File "/home/tlevi/PycharmProjects/untitled/main.py", line 14, in <module>
log.info("Blah")
File "/usr/lib/python3.4/logging/__init__.py", line 1279, in info
self._log(INFO, msg, args, **kwargs)
File "/usr/lib/python3.4/logging/__init__.py", line 1414, in _log
self.handle(record)
File "/usr/lib/python3.4/logging/__init__.py", line 1424, in handle
self.callHandlers(record) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将一些 Vue.js 单文件组件从::v-deep
语法迁移到:deep()
,如此处所述。但是,我不确定如何使其与嵌套SCSS 规则一起使用&__*
。没有工作的规则&__*
也很好。
我们使用的 SCSS 编译器是dart-sass。
例如,有这个原始片段:
::v-deep .wrapper {
display: flex;
&__element {
display: block
}
}
Run Code Online (Sandbox Code Playgroud)
正确地将代码编译为
[data-v-S0m3Ha5h] .wrapper__element {
display: block;
}
Run Code Online (Sandbox Code Playgroud)
并抛出警告:[@vue/compiler-sfc] ::v-deep usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead.
:deep()
在顶层规则中我尝试将其转换为:deep()
这样:
:deep(.wrapper) {
display: flex;
&__element {
display: block
}
}
Run Code Online (Sandbox Code Playgroud)
这会导致编译器错误,因为:deep(wrapper)__element
不是有效的选择器。
:deep()
在嵌套规则中所以我将 移至:deep
嵌套规则:
.wrapper …
Run Code Online (Sandbox Code Playgroud) TL; DR一段Javascript代码在Linux上完美运行,同时在Windows上表现不一致.
我正在编写一个Electron应用程序,使用Vue.js作为前端,使用Vuex进行数据管理,使用LokiJS进行持久性存储(在后台使用文件系统适配器).我在Linux上开发这个应用程序,但我不得不切换到Windows为客户端创建Windows构建.Linux构建总是完美无缺,Windows一个行为不端.我认为这是一个LokiJS问题,然而,在LokiJS特定代码被隔离后,它甚至在Windows上也能正常工作.
这是简化store.js
文件,其中包含我的应用程序中所有相关的Vuex和LokiJS相关代码.
import loki from 'lokijs'
import LokiSFSAdapter from 'lokijs/src/loki-fs-structured-adapter'
import MainState from '../index' // a Vuex.Store object
const state = {
ads: [],
profiles: []
}
var sfsAdapter = new LokiSFSAdapter('loki')
var db = new loki('database.json', {
autoupdate: true,
autoload: true,
autoloadCallback: setupHandler,
adapter: sfsAdapter
})
function setupCollection (collectionName) {
var collection = db.getCollection(collectionName)
if (collection === null) {
collection = db.addCollection(collectionName)
}
}
function setupHandler () {
setupCollection('ads')
setupCollection('profiles')
MainState.commit('updateAds')
MainState.commit('updateProfiles')
}
window.onbeforeunload …
Run Code Online (Sandbox Code Playgroud) 我想根据main()的输入定义全局数组(在其他函数中使用); (具体地说是数组大小).该EXTERN关键字没有帮助.
#include <iostream>
using namespace std;
void gen_sieve_primes(void);
int main() {
int MaxNum;
cin >> MaxNum;
int *primes = new int[MaxNum];
delete[] primes;
return 0;
}
//functions where variable MaxNum is used
Run Code Online (Sandbox Code Playgroud) 我的代码:
window.cpp
Window::Window(int w, int h, const char *title, const char *icon)
{
height = h;
width = w;
if(SDL_Init( SDL_INIT_EVERYTHING ) == 0)
{
SDL_WM_SetCaption(title, NULL);
SDL_WM_SetIcon(SDL_LoadBMP(icon),NULL);
screen = SDL_SetVideoMode(width, height, 32,
SDL_SWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF);
if(screen == NULL)
{
running = false;
return;
}
fullscreen = false;
}
else
running = false;
return;
}
Window::Window()
{
const SDL_VideoInfo* info = SDL_GetVideoInfo();
screenWidth = info->current_w;
screenHeight = info->current_h;
Window(640, 480, "Flatgu game", "rsc/img/icon.bmp");
}
Run Code Online (Sandbox Code Playgroud)在window.h
class Window
{ …
Run Code Online (Sandbox Code Playgroud)这是我的(好吧不是我的:))代码:
/*
* This Code Was Created By Jeff Molofee 2000
* A HUGE Thanks To Fredric Echols For Cleaning Up
* And Optimizing This Code, Making It More Flexible!
* If You've Found This Code Useful, Please Let Me Know.
* Visit My Site At nehe.gamedev.net
*/
#include <windows.h> // Header File For Windows
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\GLaux.h> // Header File For The …
Run Code Online (Sandbox Code Playgroud) 基本上我想做的是转换这种格式的表格
result={{id="abcd",dmg=1},{id="abcd",dmg=1},{id="abcd",dmg=1}}
Run Code Online (Sandbox Code Playgroud)
到这种格式的表:
result={{id="abcd",dmg=1, qty=3}}
Run Code Online (Sandbox Code Playgroud)
所以我需要知道{id="abcd",dmg=1}
表中发生了多少次。有没有人知道比嵌套for
循环更好的方法?
有没有可以帮助我从(La)TeX生成PDF文件的C/C++ 编程库?如果没有这样的东西,还有其他方法可以从(La)TeX生成PDF吗?
在我的GUI系统中,主要构建块是Container
类,可以绘制(=可绘制).然而,Container
它本身就是一种" 一种表 " - 它包含细胞.
Cell
class用于布局.容器具有的单元格数由行数和列数定义.Cell
对象不可见.
这就是问题所在.Cell
无法绘制Container
对象- 它们包含对象,这些Cell
对象在调用时由对象中定义的规则(对齐,填充等)绘制cell.draw()
.
我知道这可以通过使用原始指针来避免在这里创建的循环依赖关系轻松解决,但我想使用智能指针,如果可能的话.但是,根据我得到的错误,显然智能指针必须知道对象的大小,不像原始指针.
Unique_ptr错误
/usr/include/c++/4.8/bits/unique_ptr.h:65:22: error: invalid application of ‘sizeof’ to incomplete type ‘Container’
static_assert(sizeof(_Tp)>0,
Run Code Online (Sandbox Code Playgroud)
Container.hpp
#include <Cell.hpp> // Causes circular dependency
class Cell; // Causes error: invalid application of ‘sizeof’
class Container
{
// ...
private:
std::vector<std::unique_ptr<Cell>> cells;
// ...
}
Run Code Online (Sandbox Code Playgroud)
Cell.hpp
#include <Container.hpp> //Causes circular dependency
class Container; // Causes error: …
Run Code Online (Sandbox Code Playgroud) 假设我已经实现了一种编程语言(我们现在将其称为A )。A与C非常相似。
我希望我的用户能够访问现有 C 库中的函数和数据结构。这可能吗?如果是的话,一个幼稚的实现会是什么样子?
A
我用Javascript编写了一个前端 SPA。它使用 Ember 及其路由、虚假 URL、身份验证和 Ember 几乎隐式处理的所有惊人的东西。
后端是用 PHP 编写的,页面应由 Apache 服务器提供服务。
现在,如果请求被发送到根文件(又名索引)并且一切都从这里处理,则页面工作正常。但是,如果我在比方说重新加载页面localhost/login
,Apache 会尝试找到一个名为 login 的文件,该文件自然不存在,因为所有内容都是在 Javascript 中处理的,并且我得到了广为人知的 404 -The requested URL /login was not found on this server.
我如何告诉 Apache 始终服务index.php
,无论 URL 中是什么?
我一直在寻找比我自己更好的解决方案,而且我真的找不到一个我理解或对我有用的解决方案.
我做了一个简单的游戏,计算机随机生成一个数字然后你猜一个数字,如果它更高,计算机说更高,等等..
问题是我的随机生成的数字,查找有关的信息很多后<random>
,uniform_int_distribution
和default_random_engine
.我发现计算机生成一个随机数,但如果再次运行程序,将生成相同的随机数.
我的解决方案
uniform_int_distribution<unsigned> u(0,100); // code to randomly generate numbers between 0 and 100
default_random_engine e; // code to randomly generate numbers
size_t userInput; // User input to find out where to look in the vector
vector<int> randomNumbers; //vector to hold the random numbers
unsigned start = 0, ending = 101, cnt = 0; // used in the game not important right now
cout << "Please enter a number between …
Run Code Online (Sandbox Code Playgroud) c++ ×7
.htaccess ×1
apache ×1
c ×1
containment ×1
count ×1
dart-sass ×1
ffi ×1
fullscreen ×1
generator ×1
javascript ×1
latex ×1
logging ×1
lokijs ×1
lua ×1
lua-table ×1
mod-rewrite ×1
node.js ×1
opengl ×1
pdf ×1
python ×1
random ×1
rewrite ×1
sass ×1
sdl ×1
stdout ×1
vue-sfc ×1
vue.js ×1
vuex ×1
windows ×1