在 中Python 3.5,我想使用locale.atof以下代码将德语数字字符串转换为浮点数:
import locale
from locale import atof
locale.setlocale(locale.LC_ALL, 'de_DE')
number = atof('17.907,08')
Run Code Online (Sandbox Code Playgroud)
然而,这提出了一个ValueError:
ValueError: could not convert string to float: '17.907.08'
Run Code Online (Sandbox Code Playgroud)
atof()为了这个而生的吗? 我有时会引发此异常:
System.InvalidOperationException: 'The ConnectionString property has not been initialized.'
Run Code Online (Sandbox Code Playgroud)
我使用内置的依赖注入:
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IDbConnection>(db => new SqlConnection(
Configuration.GetConnectionString("AppConnectionString")));
services.AddScoped<IAppConfigurationRepository, AppConfigurationRepository>();
services.AddScoped<IHomeworkingRequestRepository, HomeworkingRequestRepository>();
services.AddScoped<IEmployeeRepository, EmployeeRepository>();
services.AddScoped<IEmployeeService, EmployeeService>();
services.AddScoped<IHomeworkingRequestService, HomeworkingRequestService>();
services.AddMvc();
}
Run Code Online (Sandbox Code Playgroud)
之前,我已经有这个错误了。services.AddScoped<IDbConnection>我改成的代码services.AddTransient<IDbConnection>解决了这个问题。但现在我又犯了这个错误。
编辑
请查找发生异常时的代码:
public class EmployeeRepository : IEmployeeRepository
{
private readonly IDbConnection _connection;
public EmployeeRepository(IDbConnection connection)
{
_connection = connection;
}
public IEnumerable<Employee> GetAllActiveEmployees()
{
string query = @"
SELECT
FirstName
,LastName
,BusinessUnit
FROM Employees";
using (var db = _connection)
{
_connection.Open(); …Run Code Online (Sandbox Code Playgroud) 我有一个表,其中的'Preference'列存储 JSON 字符串。
a)我想type从rowscompanytype中获取。在我对sqlfiddle的尝试中,我得到了五行,但其中没有数据。
SELECT z.[Type]
FROM FinPreferences p
CROSS APPLY OPENJSON(Preference,'$.companytype.type') WITH (
[Type] INT
) z
WHERE PreferenceID=1
Run Code Online (Sandbox Code Playgroud)
b)如何获得一行字符串的结果,即
1,2,3,4,5
Preference这是列内的数据
{
"companysize":{"min":0,"max":5},
"distance":{"min":100,"max":200},
"companytype":{"type":[1,2,3,4,5]},
"budget":{"min":1000,"max":2000}
}
Run Code Online (Sandbox Code Playgroud)
如何在后台的计时器上写入数据库。例如,检查邮件并将新字母添加到数据库。在示例中,我在写入数据库之前简化了代码。
Microsoft示例中的类名称。录音课本身:
namespace EmailNews.Services
{
internal interface IScopedProcessingService
{
void DoWork();
}
internal class ScopedProcessingService : IScopedProcessingService
{
private readonly ApplicationDbContext _context;
public ScopedProcessingService(ApplicationDbContext context)
{
_context = context;
}
public void DoWork()
{
Mail mail = new Mail();
mail.Date = DateTime.Now;
mail.Note = "lala";
mail.Tema = "lala";
mail.Email = "lala";
_context.Add(mail);
_context.SaveChangesAsync();
}
}
}
Run Code Online (Sandbox Code Playgroud)
计时器类:
namespace EmailNews.Services
{
#region snippet1
internal class TimedHostedService : IHostedService, IDisposable
{
private readonly ILogger _logger;
private Timer _timer;
public TimedHostedService(IServiceProvider services, ILogger<TimedHostedService> …Run Code Online (Sandbox Code Playgroud) c# async-await asp.net-core asp.net-core-2.1 asp.net-core-hosted-services
我想知道 await 和 .then 是否可以在同一个异步函数中使用?这是我的功能:
uploadImageToImgur: async function (file) {
return new Promise(function(resolve, reject) {
const url = 'https://api.imgur.com/3/image',
reader = new FileReader();
if (file) {
reader.readAsDataURL(file);
}
reader.onloadend = async function () {
let { result } = reader;
try {
const request = await fetch(url, {
method: 'POST',
headers: {
"Authorization": 'my auth',
},
body: result.replace(/^data:image\/(png|jpg|jpeg|gif);base64,/, "")
})
.then((response) => {
response.json()
.then(data => {
resolve(data.data.link)
})
});
} catch (e) {
reject(e);
}
}
});
},
Run Code Online (Sandbox Code Playgroud)
然后我在另一个函数中调用这个函数,在那里我使用我从 …
在 C# 8.0 中,我们有一个新功能,可以在接口中提供默认方法实现,该方法也可以被其实现类覆盖。
我们曾经使用带有实例方法的抽象类来为其所有实现类提供通用功能。
现在我可以将那些具有实例方法的抽象类替换为具有 C# 8.0 中的默认方法实现的接口吗?
我们有这样的代码:
var intList = new List<int>{1,2,3};
var asyncEnumerables = intList.Select(Foo);
private async IAsyncEnumerable<int> Foo(int a)
{
while (true)
{
await Task.Delay(5000);
yield return a;
}
}
Run Code Online (Sandbox Code Playgroud)
我需要await foreach为每个asyncEnumerable条目开始。每次循环迭代都应该相互等待,每次迭代完成后,我需要收集每次迭代的数据并通过另一种方法对其进行处理。
我可以通过 TPL 以某种方式实现吗?否则,你不能给我一些想法吗?
我使用的Visual Studio Code版本1.42我Ubuntu 18.04。我刚刚sudo dotnet add package Google.Apis.Drive.v3通过终端成功安装,但我找不到System.Web在我的C#项目上安装的方法。在做了一些研究之后,我发现了这个,它基本上解释了,我需要访问一个IHostingEnvironment env objectASP.NET Core 会处理的。
我在解析本地文件路径时遇到问题。我的问题是我不熟悉这种类型的方法,想问问,鉴于下面的代码,有人可以告诉我如何修改它以使用IHostingEnvironment env object.
问题出现在包含以下内容的行中:
HttpContext.Current.Server.MapPath("~/GoogleDriveFiles")
Run Code Online (Sandbox Code Playgroud)
这是代码的其余部分:
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
//using System.Web;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
namespace WebApi2.Models
{
public class GoogleDriveFilesRepository
{
//defined scope.
public static string[] Scopes = { DriveService.Scope.Drive };
// Operations....
//create Drive API service.
public static DriveService GetService()
{
//Operations....
public …Run Code Online (Sandbox Code Playgroud) 我正在计划制作一个应用程序(专门的存档系统),其中,我的应用程序可以访问打印机/扫描仪以扫描文档并将其存储到数据库并访问打印机/扫描仪以打印所请求的文档.有什么建议?只需一个简单的扫描文档 - >存储到数据库类型的解决方案就行了.谢谢!:)
我正在编写一个Windows批处理文件,batch file应该在特定文件夹中输出一个文件。我希望文件名写成如下:
filename-yyyymmdd.csv
Run Code Online (Sandbox Code Playgroud)
其中 yyyymmdd 代表当前日期。
我的batch file代码如下:
cd:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn
bcp "SELECT TOP 100 * FROM xxxx.dbo.xxxxx" queryout c:\test\csv\confirmed.csv -t, -c -S xxxx\xxxxx -U xxx -P xxxxxxxxxx
set mydate=%date:~10,4%%date:~4,2%%date:~7,2%
echo %mydate%
copy c:\test\csv\confirmed.csv c:\test\csvwithdates\confirmed-%mydate%.csv
Run Code Online (Sandbox Code Playgroud)
我得到以下文件名作为输出: confirmed-ay18.csv
期望的输出: confirmed-20180528.csv
我查看了以下问题,StackOverflow但我很难实施建议的答案:
在 Windows 批处理文件中以 YYYYMMDD 格式获取日期
我究竟做错了什么?
c# ×5
asp.net-core ×2
async-await ×2
c#-8.0 ×2
sql-server ×2
.net ×1
.net-core ×1
archiving ×1
asp.net-core-hosted-services ×1
asynchronous ×1
batch-file ×1
bcp ×1
date ×1
javascript ×1
oop ×1
promise ×1
python ×1
python-3.5 ×1
scanning ×1
sql ×1
windows ×1