这是令人尴尬的问题,但我试图将所有常量分离到一个新文件中并导入它,以保持干净。然而,我尝试过的任何方法都不起作用,而且这里的所有其他问题似乎都围绕着导入类和函数。
我有一个名为 的文件constants.tsx,其中声明了所有常量:
export const default_bg = "#2456a5"
export const default_light_font_color = "white"
export const default_lg_font_size = 11
export const default_md_font_size = 10
export const default_sm_font_size = 9
export const default_dark_font_color = "#000028"
export const default_font = "arial"
Run Code Online (Sandbox Code Playgroud)
以及迄今为止具有所有功能的主文件App.tsx:
import * as React from 'react';
import { Header } from './Header';
import { Body } from './Body';
import * as defaults from 'constants'
...
Run Code Online (Sandbox Code Playgroud)
但是,defaults(或我为导入指定的任何其他名称)似乎不包含常量。写作defaults.default_bg给了我这个错误:
TS2339:类型“typeof import("constants")”上不存在属性“default_bg”。
并console.log(defaults)打印:
我知道这可能非常简单,但我不知道如何做到这一点。总的来说,我对 Typescript …
我正在尝试编写一个简单的“服务器”,它继承BaseHTTPRequestHandler并能够接收 GET 和 POST 请求。server.py到目前为止,我有一个文件,如下所示:
from http.server import BaseHTTPRequestHandler, HTTPServer
from cgi import parse_header, parse_multipart
from urllib.parse import parse_qs
host = "localhost"
port = 8080
hello_msg = "Server running..."
class Server(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_GET(self):
self.respond_OK(hello_msg)
def do_POST(self):
print("Post")
data = self.parse_POST()
print(data)
print(type(data))
self.respond_OK("End post")
def parse_POST(self):
ctype, pdict = parse_header(self.headers['content-type'])
if ctype == 'multipart/form-data':
postvars = parse_multipart(self.rfile, pdict)
elif ctype == 'application/x-www-form-urlencoded':
length = int(self.headers['content-length'])
postvars = parse_qs(
self.rfile.read(length),
keep_blank_values=1) …Run Code Online (Sandbox Code Playgroud) 这段代码:
for (std::list<point>::const_iterator it = controlPoints->begin();
it != controlPoints->end();
++it) {
...
}
Run Code Online (Sandbox Code Playgroud)
对应于:
for (int i = 0; i < controlPoints->size; i++) {
...
}
Run Code Online (Sandbox Code Playgroud)
意思是,如果我每次循环获得一个元素,它将迭代列表中的所有元素.
什么对应于:
for (int i = 0; i < controlPoints->size-1; i++) {
...
}
Run Code Online (Sandbox Code Playgroud)
我的意思是,如何使用迭代器循环大小1次?
我正在尝试运行sudo apt-get purge postgresql*,但是我遇到了一个依赖性错误和一个运行的建议sudo apt-get -f install,所以我尝试运行它给了我:
Unpacking linux-image-3.13.0-63-generic (3.13.0-63.104~precise1) over (3.13.0-63.103) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-3.13.0-63-generic_3.13.0-63.104~precise1_amd64.deb (--unpack):
trying to overwrite '/lib/modules/3.13.0-63-generic/kernel/mm/hwpoison-inject.ko', which is also in package linux-image-extra-3.13.0-63-generic 3.13.0-63.103
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.13.0-63-generic /boot/vmlinuz-3.13.0-63-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.13.0-63-generic /boot/vmlinuz-3.13.0-63-generic
Errors were encountered while processing:
/var/cache/apt/archives/linux-image-3.13.0-63-generic_3.13.0-63.104~precise1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)
我是14.04
我有一个.html.erb文件,它应该在某个参数为"true"时打印一条消息,而在另一个参数为"false"时打印一条消息.这是文件的代码:
<%= if params[:result] == "true" %>
<h1>Success</h1>
<p>The words <%=params[:first] %> and <%= params[:second] %> are anagrams! <br>
<%= else %>
<h1>Oh no!</h1>
<p>The words <%=params[:first] %> and <%= params[:second] %> are not anagrams. <br>
<br>
<%= link_to 'Try another pair', welcome_index_path%>
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:3: syntax error, unexpected ')', expecting keyword_then or ';' or '\n' if @result == "true" );@output_buffer.safe_append='
/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:6: syntax error, unexpected keyword_else '.freeze;@output_buffer.append=( else );@output_buffer.safe_append='
/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:11: syntax error, unexpected keyword_ensure, expecting ')'
/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:13: syntax error, unexpected keyword_end, …Run Code Online (Sandbox Code Playgroud) c++ ×1
c++11 ×1
for-loop ×1
iterator ×1
linux ×1
post ×1
python ×1
python-3.x ×1
server ×1
typescript ×1
ubuntu ×1
ubuntu-14.04 ×1