玩心态

文章 评论 浏览 30

玩心态 2025-02-17 13:44:49

您创建一个请求模型:

public class ReqModel
{
    public string client_id{ get; set; }
    public string  scope{ get; set; }
    public string  client_secret{ get; set; }
    public string grant_type{ get; set; }
}

然后,您尝试创建以下邮政编码:

    ReqModel reqModel = new()
        {
            client_id = "65577dd2-cc76-46af-a1ac-71582eac6af2",
            scope = "https://graph.microsoft.com/.default",
            client_secret = "my_client_secret",
            grant_type = "client_credentials"
        };


        string postData = JsonConvert.SerializeObject(reqModel, Newtonsoft.Json.Formatting.Indented);

You create a request model:

public class ReqModel
{
    public string client_id{ get; set; }
    public string  scope{ get; set; }
    public string  client_secret{ get; set; }
    public string grant_type{ get; set; }
}

Then you try to create postData like this:

    ReqModel reqModel = new()
        {
            client_id = "65577dd2-cc76-46af-a1ac-71582eac6af2",
            scope = "https://graph.microsoft.com/.default",
            client_secret = "my_client_secret",
            grant_type = "client_credentials"
        };


        string postData = JsonConvert.SerializeObject(reqModel, Newtonsoft.Json.Formatting.Indented);

Graph API-获取“远程服务器返回错误:(400)不良请求。

玩心态 2025-02-17 12:04:26

BodyParts 如何实例化?是一个州吗?如果是,则默认为空数组 []

,或者您可以在映射之前添加支票。我添加了在调用 map()函数之前检查,因为它仅适用于数组。

附加信息

可能是数据尚未填充由于等待API调用以完成或其他原因。在这种情况下,由于检查,我的修复程序只会在第一次渲染期间渲染一个空的DIV,并防止控制台错误。在数据准备就绪时,在下一个渲染过程中,在这种情况下,数据将是适当的数组类型,支票将通过( array.isarray(data)),项目将渲染 box < /代码>正确组件。

import React from 'react';
import {Box} from '@mui/material';

const HorizontalScrollbar = ({data}) => {
    return (
        <div> 
           {Array.isArray(data) && data.map((item) => ( 
            <Box 
            key = {item.id || item}
            itemId = {item.id || item}
            title = {item.id || item}
            m = "0 40px"
            >
            {item}
            </Box>
            )
        )
            
    }
        </div>
)
}

export default HorizontalScrollbar;

How is bodyParts instantiated? Is it a state? If it is it should default to an empty array []

Or you could add a check before mapping through. I added an Array.isArray() check before invoking the map() function as it is only for Arrays.

Additional Info

It could be that data is not yet populated due to waiting for an API call to complete or some other reason. In this case my fix would simply render an empty div during first render due to the check and prevent the console error. During next render when the data is ready the data in this case would be a proper Array type, the check would pass (Array.isArray(data)) and the items would render the Box component properly.

import React from 'react';
import {Box} from '@mui/material';

const HorizontalScrollbar = ({data}) => {
    return (
        <div> 
           {Array.isArray(data) && data.map((item) => ( 
            <Box 
            key = {item.id || item}
            itemId = {item.id || item}
            title = {item.id || item}
            m = "0 40px"
            >
            {item}
            </Box>
            )
        )
            
    }
        </div>
)
}

export default HorizontalScrollbar;

错误:data.map不是函数。每当我运行React组件时,此错误就会丢弃

玩心态 2025-02-17 09:10:56

您可以创建或编辑/users/yimingliu/.zshrc file(如果您的macOS比Macos Catalina 10.15都老,则文件为/users/yimingliu/.bash_profile ),并添加一条线以将Python bin文件夹添加到您的路径:

export PATH=/Users/yimingliu/Library/Python/3.8/bin:$PATH

You can create or edit your /Users/yimingliu/.zshrc file (if your macOS is older than macOS Catalina 10.15, then the file is /Users/yimingliu/.bash_profile), and add a line to add the python bin folder to your path:

export PATH=/Users/yimingliu/Library/Python/3.8/bin:$PATH

有问题可以运行PIP在MacOS终端安装的Python命令

玩心态 2025-02-17 07:39:53
def my_function(my_list):
    final = ""
    for i in my_list:
        final = final + str(i)
    return int(final)

integer = my_function([5, 6])  # My function will output 56
def my_function(my_list):
    final = ""
    for i in my_list:
        final = final + str(i)
    return int(final)

integer = my_function([5, 6])  # My function will output 56

如何从数字/数字列表中获取整数?

玩心态 2025-02-17 06:03:15

您可以用 pygame.quit()在每个帧中退出游戏。在应用程序循环之后而不是在应用程序循环中退出游戏。另外,为什么在其他情况下更新游戏? break 语句在 event.type == pygame.quit 仅断开事件循环,而不是应用程序循环。更改代码的控制流:

# application loop
run = True
while run:
    # event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT: run = False
        if event.type == pygame.USEREVENT: message.update()
        
    # redraw in every frame
    screen.fill(pygame.color.Color('black'))
    message.draw(screen)
    pygame.display.flip()
    clock.tick(60)

# quit after the application loop
pygame.quit()

You quit the game in every frame with pygame.quit(). quit the game after the application loop instead of in the application loop. Also why do you update the game just in the else case? The break statement in case of event.type == pygame.QUIT only breaks the event loop, but not the application loop. Change the control flow of your code:

# application loop
run = True
while run:
    # event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT: run = False
        if event.type == pygame.USEREVENT: message.update()
        
    # redraw in every frame
    screen.fill(pygame.color.Color('black'))
    message.draw(screen)
    pygame.display.flip()
    clock.tick(60)

# quit after the application loop
pygame.quit()

错误:pygame.error:视频系统未初始化

玩心态 2025-02-16 23:21:35

请用调试信息编译您的小精灵。例如,如果GCC添加编译器标志 -G

当您的ELF包含调试信息时,它将包含指向所有源文件的链接,并且调试器将自动打开这些文件,并在 list 窗口。

list 窗口的按钮“模式”允许您在“ HLL模式”(仅C代码)和“混合模式”(C Plus Assembler)之间切换

Please compile your ELF with debug information. E.g. in case of GCC add the compiler flag -g

When your ELF contains debug information it will contain links to all of your source files and the debugger will open those files automatically for your and display the source code in the List window.

The button "mode" of the List window allows you to toggle between "HLL mode" (C code only) and "Mixed mode" (C code plus assembler)

如何与汇编一起在Trace32上提出整个项目源代码?

玩心态 2025-02-16 17:21:25

您可以使用SyncFusion Multi-column Combox,

c#的代码(检查VB的

 query = "SELECT ID, Descricao FROM tab_tasks";

 adapter = new OleDbDataAdapter(query, connection);
 adapter.Fill(ds, "idtask");

 DataTable dataTable1 = ds.Tables["idtask"];

 sfComboBox2.DataSource = dataTable1;
 sfComboBox2.DisplayMember = "ID";

文档它将数据设置为数据表,并将其用作ComboBox的数据源。

DisplayMember 是您选择其中一个值时显示的成员。

You can use SyncFusion multi-column combobox for it, Documentation here, it includes small examples and is simple to use.

Code for C# (check documentation for VB)

 query = "SELECT ID, Descricao FROM tab_tasks";

 adapter = new OleDbDataAdapter(query, connection);
 adapter.Fill(ds, "idtask");

 DataTable dataTable1 = ds.Tables["idtask"];

 sfComboBox2.DataSource = dataTable1;
 sfComboBox2.DisplayMember = "ID";

This being the base of it, set your data as a datatable and use it as DataSource to your ComboBox.

DisplayMember is the member displayed when you choose one of the values.

多柱组合vb.net

玩心态 2025-02-15 08:20:44

为什么凹痕很重要?

在Python中,凹痕用于定界代码的块。这与使用Curly Braces {} 的许多其他语言不同,例如Java,JavaScript和C等块。因为空格很重要。

当Python遇到程序缩进问题时,它要么提出一个例外,称为 indentationError /代码> 。也可以获得 syntaxerror 来自不正确的凹痕。

一个历史记录的

历史原因是为什么Python使用凹痕与更常见的更常见的卷曲括号 {} {} 02/早期语言设计和开发。

Python的凹痕使用直接来自ABC,但这个想法并非源于ABC - 它已经由Donald Knuth推广,并且是著名的编程风格概念。 (OCCAM编程语言也使用了。)但是,ABC的作者确实发明了将引导条款与凹痕区块分开的结肠的使用。在没有结肠的早期用户测试之后,发现缩进的含义尚不清楚初学者被教导的第一步。结肠的添加显着澄清了:结肠以某种方式提请注意以下内容并以正确的方式将其在其前后的短语联系在一起。

我如何缩进我的代码?

缩进Python代码的基本规则是:基本块中的每个语句必须缩进相同的金额。

因此,从技术上讲,以下Python程序是正确的:

def perm(l):
        # Compute the list of all permutations of l
    if len(l) <= 1:
                  return [l]
    r = []
    for i in range(len(l)):
             s = l[:i] + l[i+1:]
             p = perm(s)
             for x in p:
              r.append(l[i:i+1] + x)
    return r

但是,正如您可以从上面看出的那样,随机缩进您的代码使您的代码非常困难读取和遵循程序的流程。最好保持一致并遵循一种风格。

pep 8- python样式指南 - 说::

每个凹痕级别使用4个空间。

也就是说,每个正在启动新块的语句,并且在新块中的每个后续语句都应从当前的压痕层缩进四个空间。这是根据PEP8样式指南缩进的上述程序:

def perm(l):
    # Compute the list of all permutations of l
    if len(l) <= 1:
        return [l]
    r = []
    for i in range(len(l)):
        s = l[:i] + l[i+1:]
        p = perm(s)
        for x in p:
            r.append(l[i:i+1] + x)
    return r

我仍然可以使用选项卡吗?

Python意识到,有些人仍然喜欢选项卡而不是空间,而旧的代码可能使用选项卡而不是空格,因此它允许使用标签作为凹痕。 pep8 topy thit this主题

空格是首选的凹痕方法。

标签应仅用于与已经与选项卡缩进的代码保持一致。

注意,但是,一个大警告是不使用两个选项卡空间进行凹痕。这样做可能会导致各种奇怪的难以调试压痕错误。 python 将选项卡扩展到下一个8th列,但是如果您的编辑器设置为4列的选项卡,或者您使用的空格是除选项卡外,您还可以轻松地生成编辑器中 file的缩进代码,但是Python会拒绝运行。 Python 3编译器显式拒绝任何包含标签和空格混合物的程序,通常是通过提高 taberror 。但是,默认情况下,Python 2中仍然允许混合选项卡和空格,但是强烈建议不要使用此“功能”。使用 -t -tt 命令行标志迫使Python 2分别提出警告或(最好)(优选)错误。 <

python 3不允许混合使用标签和空间用于凹痕的使用。

Python 2代码与标签和空间的混合物缩进,应专门使用空间。

使用-t选项调用Python 2命令行解释器时,它会发出有关非法混合选项卡和空格的代码的警告。使用-tt时,这些警告成为错误。强烈建议这些选项!

“缩进:意外缩进”是什么意思?

问题是

,当语句不必要地缩进或其缩进不符合同一块中以前的语句的缩进时,就会发生这种错误。例如,以下程序中的第一个语句是不必要的:

>>>  print('Hello')  # this is indented 
  File "<stdin>", line 1
    print('Hello')  # this is indented 
    ^
IndentationError: unexpected indent

在此示例中, can_drive = true line 中的行,如果 block block不符合任何以前的语句的缩进:

>>> age = 10
>>> can_drive = None
>>> 
>>> if age >= 18:
...     print('You can drive')
...      can_drive = True  # incorrectly indented
  File "<stdin>", line 3
    can_drive = True  # incorrectly indented
    ^
IndentationError: unexpected indent

修复

此错误的修复程序是首先确保有问题的线甚至需要缩进。例如,可以修复上面的示例可以修复该行:

>>> print('Hello')  # simply unindent the line
Hello

但是,如果您确定该行确实需要缩进,则凹痕需要匹配该行中的以前语句的凹痕相同的块。在上面的第二个示例中,使用,我们可以通过确保使用 can_drive = true 的行来解决错误>如果正文:

>>> age = 10
>>> can_drive = None
>>> 
>>> if age >= 18:
...     print('You can drive')
...     can_drive = True  # indent this line at the same level.
... 

“凹痕:预期的缩进块”是什么意思?

(这也可能以的语法:在Python 3.8或更低的解析时出现EOF。)

Python看到“标头”的“标头”的复合语句,例如 if&lt;条件&gt;: while&lt; condition&gt;:,但从未定义化合物语句的身体或 。例如,在下面的代码中,我们启动了如果语句,但是我们从不为语句定义一个正文:

>>> if True:
... 
  File "<stdin>", line 2
    
    ^
IndentationError: expected an indented block

在第二个示例中,我们开始为循环编写,但是我们忘记缩进循环主体的。因此,python仍然期望循环主体的缩进块:

>>> names = ['sarah', 'lucy', 'michael']
>>> for name in names:
... print(name)
  File "<stdin>", line 2
    print(name)
        ^
IndentationError: expected an indented block

注释不算为主体:

>>> if True:
...     # TODO
... 
  File "<stdin>", line 3

    ^
IndentationError: expected an indented block

修复

此错误的修复就是简单地包含一个化合物语句的主体。

如上所示,新用户的一个常见错误是他们忘记了身体的缩进。如果是这种情况,请确保在化合物语句的开始下,将每个语句包含在化合物的主体中。这是以上示例修复的示例:

>>> names = ['sarah', 'lucy', 'michael']
>>> for name in names:
...     print(name)  # The for loop body is now correctly indented.
... 
sarah
lucy
michael

另一个常见的情况是,出于某种原因,用户可能不想为复合语句定义实际主体,否则可能会评论身体。在这种情况下,可以使用通过语句。来自文档

通行证是一个无效的操作 - 执行时,什么也不会发生。当需要语法要求语句时,它作为占位符很有用,但是无需执行代码,例如:

  def f(arg):传递#一个无需执行的函数(尚未执行)

C级:通过没有方法的#班级(尚未)
 

以上示例在上使用语句使用 pass 关键字:

>>> if True:
...     pass  # We don't want to define a body.
... 
>>> 

“ IndentationError:不符合任何外部压痕级别”的意思是什么?

问题

当您不明智的语句时,会发生这个错误,但是现在该语句的缩进级别与任何以前的语句中的缩进级别都不匹配。例如,在以下代码中,我们将第二个调用打印。但是,凹痕级别不符合任何以前的语句:

>>> if True:
...     if True:
...         print('yes')
...    print()
  File "<stdin>", line 4
    print()
          ^
IndentationError: unindent does not match any outer indentation level

此错误尤其难以捕获,因为即使一个空间也会导致您的代码失败。

修复

该修复程序是为了确保当您不明智的说明时,缩进级别与以前的语句的级别相匹配。再次考虑上述示例。在示例中,我希望第二个呼叫打印在第一个语句主体中。因此,如果语句的正文,我需要确保该行的缩进级别与第一个中的前者语句相匹配:

>>> if True:
...     if True:
...         print('yes')
...     print()  # indentation level now matches former statement's level.
... 
yes

>>> 

我仍然得到缩进,但我的程序似乎正确缩进了。我该怎么办?

如果您的程序在视觉上似乎具有正确的凹痕,但是您仍获得 IndentationError ,您很可能有带空格的混合选项卡。这有时会导致Python引起奇怪的错误。请参阅 特殊情况 下的小节:“ taberror:不一致地使用标签和空间”。对于问题的更深入的解释。

“ Taberror:不一致的使用标签和空间不一致”是什么意思?

问题

只有在尝试将选项卡和空格作为凹痕字符混合时,才会发生这种错误。如上所述,Python将不允许您的程序包含选项卡和空格的混合物,并且如果发现您有特定的例外 Taberror 。例如,在下面的程序中,将选项卡和空格的混合物用于凹痕:

>>> if True:
...     if True:
...         print()
...     print()
...     print()
  File "<stdin>", line 5
    print()
          ^
TabError: inconsistent use of tabs and spaces in indentation

但是,由于许多编辑器渲染标签和空格相同,因此通常无法视觉看到。请注意,一些编辑器确实提供设置为具有不同符号的标签和空格,这可能会有所帮助。

在上面的示例中,这里是空格的表示。点是空间,箭头是选项卡:

if·True:
····if·True:
  → ····print()
····print()
  → print()

我们可以看到我们确实具有混合空间和缩进的标签。

特殊案例

注意Python 如果将选项卡和空格混合到程序中,则不会 始终始终提高 taberror 。如果程序凹痕是明确的,则Python将允许将选项卡和空间混合。例如:

>>> if True:
...     if True: # tab
...         pass # tab, then 4 spaces
... 
>>> 

有时Python只是在标签和空间的混合物上窒息,然后错误地提出 IndentationError 异常时, Taberror 更合适。另一个例子:

>>> if True:
...     print('a') # tab
...     print('b') # 4 spaces
  File "<stdin>", line 3
    print('b') # 4 spaces
                ^
IndentationError: unindent does not match any outer indentation level

如您所见,以这种方式运行代码可以创建神秘的错误。即使该程序视觉上似乎很好,但Python也变得困惑,试图解析用于凹痕的标签和空间,并出现了错误。

使用 -t -tt 使用Python 2时

这些是很好的示例,可以证明为什么永远不要混合选项卡和空格并

。 ,可能最简单,最快的修复方法就是简单地重新指出程序。确保每个陈述均由每个冲突级别的四个空间缩进(请参见 我如何缩进我的代码? )。

但是,如果您已经有一个将选项卡和空格混合到的大型程序,则可以使用自动化工具将所有凹痕转换为只有空格。

许多编辑,例如 pycharm sublimetext 具有自动将选项卡转换为空格的选项。还有几种在线工具,例如到空格 browserling ,您可以快速重新指示代码。还有一些用Python编写的工具。 autopep8

即使是最好的工具,有时也无法解决您的所有缩进错误,您也必须手动修复它们。这就是为什么从一开始就始终正确缩小代码很重要的原因。

关于 syntaxerror 相关的缩进问题的注释

有时某些 SyntaxError 异常由于不正确的凹痕而提高。例如,查看下面的代码:

if True:
    print('x')
print('y')  # oops! this statement should be indented!.
else:
    print('z')

运行上述代码时,提高了 syntaxerror

Traceback (most recent call last):
  File "python", line 4
    else:
       ^
SyntaxError: invalid syntax

尽管Python提出了 syntaxerror ,但上述代码的问题是 print('y')应缩进。由于没有缩进,Python并未意识到,如果语句和 else 语句的语句是要连接的。

此类错误的修复是简单地正确重新指示您的代码。要查看如何正确缩进您的代码,请参见“ ”部分,如何缩进我的代码?

我仍然很难使用Python的缩进语法。我该怎么办?

如果您仍在挣扎,不要灰心。可能需要时间来习惯
Python的Whitespace语法规则。以下是一些可以提供帮助的提示:

  • 获取一个编辑器,该编辑器会在缩进错误时告诉您。某些商品如上所述, pycharm sublimetext jupyter Notebook
  • 当您缩进代码时,请大声算出您自己按太空杆(或TAB键)的次数。例如,如果您需要在四个空间上缩进一行,则大声说“ 一个”每次同时按空间杆时,四个”。这听起来很愚蠢,但它有助于训练您的大脑,思考您对代码的缩进。
  • 如果您有编辑器,请查看它是否具有自动将选项卡转换为空格的选项。
  • 查看他人的代码。浏览 github
  • 只需写代码即可。那是变得更好的唯一最佳方法。您编写Python代码越多,您会得到的越好。

使用

Why does indentation matter?

In Python, indentation is used to delimit blocks of code. This is different from many other languages that use curly braces {} to delimit blocks such as Java, Javascript, and C. Because of this, Python users must pay close attention to when and how they indent their code because whitespace matters.

When Python encounters a problem with the indentation of your program, it either raises an exception called IndentationError or TabError. It's also possible to get a SyntaxError from incorrect indentation.

A little history

The historical reasons for why Python uses indentation vs the arguably more commonly accepted curly braces {} is outlined in an article of the history of Python by Guido van Rossum - the creator of Python:

Python’s use of indentation comes directly from ABC, but this idea didn’t originate with ABC--it had already been promoted by Donald Knuth and was a well-known concept of programming style. (The occam programming language also used it.) However, ABC’s authors did invent the use of the colon that separates the lead-in clause from the indented block. After early user testing without the colon, it was discovered that the meaning of the indentation was unclear to beginners being taught the first steps of programming. The addition of the colon clarified it significantly: the colon somehow draws attention to what follows and ties the phrases before and after it together in just the right way.

How do I indent my code?

The basic rule for indenting Python code is: Each statement in a basic block must be indented by the same amount.

So technically the following Python program is correct:

def perm(l):
        # Compute the list of all permutations of l
    if len(l) <= 1:
                  return [l]
    r = []
    for i in range(len(l)):
             s = l[:i] + l[i+1:]
             p = perm(s)
             for x in p:
              r.append(l[i:i+1] + x)
    return r

However, as you can probably tell from above, randomly indenting your code makes is extremely hard to read and follow the flow of the program. It's better to be consistent and follow a style.

PEP 8 -- the Python style guide -- says:

Use 4 spaces per indentation level.

That is, each statement that is starting a new block and each subsequent statement in the new block, should be indented four spaces from the current indentation level. Here is the above program indented according to the PEP8 style guide:

def perm(l):
    # Compute the list of all permutations of l
    if len(l) <= 1:
        return [l]
    r = []
    for i in range(len(l)):
        s = l[:i] + l[i+1:]
        p = perm(s)
        for x in p:
            r.append(l[i:i+1] + x)
    return r

Can I still use tabs?

Python realizes that some people still prefer tabs over spaces and that legacy code may use tabs rather than spaces, so it allows the use of tabs as indentation. PEP8 touches on this topic:

Spaces are the preferred indentation method.

Tabs should be used solely to remain consistent with code that is already indented with tabs.

Note however the one big caveat is not to use both tabs and spaces for indentation. Doing so can cause all kinds of strange hard to debug indentation errors. Python expands tabs to the next 8th column, but if your editor is set to a tab size of 4 columns, or you you use spaces as well as tabs, you can easily produce indented code that looks fine in your editor, but Python will refuse to run. The Python 3 compiler explicitly rejects any program containing an ambiguous mixture of tabs and spaces, usually by raising a TabError. However, by default, mixing tabs and spaces is still allowed in Python 2, but it is highly recommended not to use this "feature". Use the -t and -tt command line flags to force Python 2 to raise a warning or (preferably) an error respectively. PEP8 also discusses this topic:

Python 3 disallows mixing the use of tabs and spaces for indentation.

Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.

When invoking the Python 2 command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!

What does "IndentationError: unexpected indent" mean?

Problem

This error occurs when a statement is unnecessarily indented or its indentation does not match the indentation of former statements in the same block. For example, the first statement in the program below is unnecessarily indented:

>>>  print('Hello')  # this is indented 
  File "<stdin>", line 1
    print('Hello')  # this is indented 
    ^
IndentationError: unexpected indent

In this example, the can_drive = True line in the if block does not match the indentation of any former statement:

>>> age = 10
>>> can_drive = None
>>> 
>>> if age >= 18:
...     print('You can drive')
...      can_drive = True  # incorrectly indented
  File "<stdin>", line 3
    can_drive = True  # incorrectly indented
    ^
IndentationError: unexpected indent

Fix

The fix for this error is to first make sure the problematic line even needs to be indented. For example, the above example using print can be fixed simply be unindenting the line:

>>> print('Hello')  # simply unindent the line
Hello

However, if you are sure the line does need to be indented, the indentation needs to match that of a former statement in the same block. In the second example above using if, we can fix the error by making sure the line with can_drive = True is indented at the same level as the former statements in the if body:

>>> age = 10
>>> can_drive = None
>>> 
>>> if age >= 18:
...     print('You can drive')
...     can_drive = True  # indent this line at the same level.
... 

What does "IndentationError: expected an indented block" mean?

(This might also occur as SyntaxError: unexpected EOF while parsing in Python 3.8 or lower.)

Problem

This error occurs when Python sees the 'header' for a compound statement, such as if <condition>: or while <condition>: but the compound statement's body or block is never defined. For example in the code below we began an if statement, but we never define a body for the statement:

>>> if True:
... 
  File "<stdin>", line 2
    
    ^
IndentationError: expected an indented block

In this second example, we began writing a for loop, but we forget to indent the for loop body. So Python still expects an indented block for the for loop body:

>>> names = ['sarah', 'lucy', 'michael']
>>> for name in names:
... print(name)
  File "<stdin>", line 2
    print(name)
        ^
IndentationError: expected an indented block

Comments don't count as bodies:

>>> if True:
...     # TODO
... 
  File "<stdin>", line 3

    ^
IndentationError: expected an indented block

Fix

The fix for this error is to simply include a body for the compound statement.

As shown above, a common mistake by new users is that they forget to indent the body. If this is the case, make sure each statement meant to be included in the compound statement's body is indented at the same level under the compound statement's beginning. Here is the above example fixed:

>>> names = ['sarah', 'lucy', 'michael']
>>> for name in names:
...     print(name)  # The for loop body is now correctly indented.
... 
sarah
lucy
michael

Another common case is that, for some reason, a user may not want to define an actual body for the compound statement, or the body may be commented out. In this case, the pass statement can be used. From the documentation:

pass is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed, for example:

def f(arg): pass    # a function that does nothing (yet)

class C: pass       # a class with no methods (yet)

Here is the above example with the if statement fixed by using the pass keyword:

>>> if True:
...     pass  # We don't want to define a body.
... 
>>> 

What does "IndentationError: unindent does not match any outer indentation level" mean?

Problem

This error occurs when you unindent a statement, but now the indentation level of that statement does not match that of any former statement. For example, in the below code we unindent the second call to print. However, the indentation level does not match that of any former statement:

>>> if True:
...     if True:
...         print('yes')
...    print()
  File "<stdin>", line 4
    print()
          ^
IndentationError: unindent does not match any outer indentation level

This error is especially hard to catch because even one space will cause your code to fail.

Fix

The fix is to ensure that when you unindent a statement, the indentation level matches that of a former statement. Consider the above example once again. In the example, I want the second call to print to be in the first if statements body. So I need to make sure that that line's indentation level matches that of the former statements in the first if statement's body:

>>> if True:
...     if True:
...         print('yes')
...     print()  # indentation level now matches former statement's level.
... 
yes

>>> 

I'm still getting an IndentationError but my program appears to be correctly indented. What do I do?

If your program visually appears to have correct indentation, but you're still getting an IndentationError you have most likely mixed tabs with spaces. This will sometimes cause Python to raises strange errors. See the subsection Special cases under What does "TabError: inconsistent use of tabs and spaces in indentation" mean? for an more in-depth explanation of the problem.

What does "TabError: inconsistent use of tabs and spaces in indentation" mean?

Problem

This error only occurs when you attempt to mix tabs and spaces as indentation characters. As said above, Python will not allow your program to contain a mix of tabs and spaces, and will raise the specific exception TabError if it finds you have. For example, in the program below, a mix of tabs and spaces is used for indentation:

>>> if True:
...     if True:
...         print()
...     print()
...     print()
  File "<stdin>", line 5
    print()
          ^
TabError: inconsistent use of tabs and spaces in indentation

But this often can't be seen visually since many editors render tabs and spaces the same. Note some editors do offer settings to render tabs and spaces with distinct symbols, which may be helpful.

For the above example, here is a representation of the whitespace. Dots are spaces, and arrows are tabs:

if·True:
····if·True:
  → ····print()
····print()
  → print()

We can see we have indeed mixed spaces and tabs for indentation.

Special cases

Note Python will not always raise a TabError if you mix tabs and spaces into your program. If the program indentation is unambiguous, Python will allow tabs and spaces to be mixed. For example:

>>> if True:
...     if True: # tab
...         pass # tab, then 4 spaces
... 
>>> 

And sometimes Python simply chokes on the mixture of tabs and spaces and erroneously raises an IndentationError exception when a TabError would be more appropriate. Another example:

>>> if True:
...     print('a') # tab
...     print('b') # 4 spaces
  File "<stdin>", line 3
    print('b') # 4 spaces
                ^
IndentationError: unindent does not match any outer indentation level

As you can see, running your code this way can create mysterious errors. Even though the program visually appears to be fine, Python became confused trying to parse the tabs and spaces used for indention and errored out.

These are excellent examples that demonstrate why to never mix tabs and spaces and make use of the -t and -tt interpreter flags when using Python 2.

Fix

If your program is short, probably the easiest and quickest fix is to simply re-indent the program. Make sure each statement is indented by four spaces per indention level (see How do I indent my code?).

However, if you already have a large program that you've mixed tabs and spaces into, there are automated tools that can be used to convert all of your indentation to just spaces.

Many editors such as PyCharm and SublimeText have options to automatically convert tabs to spaces. There are also several on-line tools such as Tabs To Spaces or Browserling that allow you to quickly re-indent your code. There are also tools written in Python. autopep8 for example can automatically re-indent your code and fix other indentation errors as well.

Even the best tools though will sometimes not be able to fix all of your indentation errors and you'll have to fix them manually. That's why it's important to always properly indent your code from the start.

A note about SyntaxError related indentation problems

Sometimes certain SyntaxError exceptions are raised due to incorrect indentation. For example, look at the code below:

if True:
    print('x')
print('y')  # oops! this statement should be indented!.
else:
    print('z')

When the above code is run, a SyntaxError is raised:

Traceback (most recent call last):
  File "python", line 4
    else:
       ^
SyntaxError: invalid syntax

Although Python raises a SyntaxError, the real problem with the above code is that print('y') should be indented. Because it isn't indented, Python doesn't realize that the previous if statement and the else statement are meant to be connected.

The fix for this type of error is to simply correctly re-indent your code. To see how to properly indent your code, see the section How do I indent my code?.

I'm still having a hard time with Python's indentation syntax. What do I do?

Don't get discouraged if you're still struggling. It can take time to get use to
Python's whitespace syntax rules. Here are some tips to help:

  • Get an editor that will tell you when you have an indentation error. Some goods ones are as said above are, PyCharm, SublimeText, and Jupyter Notebook.
  • When you indent your code, count out loud to yourself how many times you press the space-bar (or tab key). For example, if you needed to indent a line by four spaces, you would say out loud "one, two, three, four" while simultaneously pressing the space-bar each time. It sounds silly, but it helps train your brain to think about how deep you're indenting your code.
  • If you have an editor, see if it has an option to automatically convert tabs to spaces.
  • View others' code. Browse GitHub or Stack Overflow and see examples of Python code.
  • Just write code. That's the single best way to get better. The more you write Python code, the better you'll get.

Resources used

我得到了一个凹痕(或taberror)。我该如何修复?

玩心态 2025-02-15 07:30:55

您可以通过安装 shadow-utils 包装添加 groupAdd userAdd 命令。

FROM registry.access.redhat.com/ubi8/ubi-minimal
RUN microdnf install shadow-utils
RUN groupadd -r -g 1000 myuser \
  && useradd -r -u 1000 -g myuser -m -d /opt/myuser -s /bin/bash myuser
RUN mkdir /deployments \
  && chmod 755 /deployments \
  && chown -R myuser /deployments

You can add the groupadd and useradd commands by installing the shadow-utils package like this

FROM registry.access.redhat.com/ubi8/ubi-minimal
RUN microdnf install shadow-utils
RUN groupadd -r -g 1000 myuser \
  && useradd -r -u 1000 -g myuser -m -d /opt/myuser -s /bin/bash myuser
RUN mkdir /deployments \
  && chmod 755 /deployments \
  && chown -R myuser /deployments

搬到红帽Ubi-Minimal

玩心态 2025-02-14 18:15:51

static_cast

static_cast 是您应该尝试使用的第一个演员。它可以执行类型之间的隐式转换(例如 int to float ,或指向 void*)的指针,也可以调用显式转换功能(或隐式)。在许多情况下,明确说明 static_cast 不是必需的,但是重要的是要注意, t(sothings)语法等于(t)代码>并应避免(稍后再详细介绍)。但是,A t(某物,某种东西)是安全的,并且保证调用构造函数。

static_cast 也可以通过继承层次结构施放。在向上施放(向基类)时,这是不必要的,但是当向下铸造时,只要它不通过 virtual 继承施放,就可以使用它。但是,它不进行检查,并且它是 static_cast 将层次结构降低到实际上不是对象类型的类型的不确定的行为。

const_cast

const_cast 可用于删除或添加 const 到变量;没有其他C ++铸件能够将其删除(甚至 reinterpret_cast )。重要的是要注意,仅当原始变量为 const 时,修改以前的 const 值才能不确定。如果您使用它来将 const 删除对未用 const 声明的内容的引用,则是安全的。例如,在基于 const 的过载函数过载时,这可能很有用。它也可用于将 const 添加到对象中,例如调用成员功能超载。

const_cast volatile 上也类似地工作,尽管这不太常见。

dynamic_cast

dynamic_cast 专门用于处理多态性。您可以将指针或对任何多态性类型的引用施放到任何其他类型类型(多态性类型具有至少一个虚拟功能,已声明或继承)。您不仅可以将其用于向下铸造,还可以将其用于侧面,甚至可以向上施放另一个链条。 dynamic_cast 将寻找所需的对象并在可能的情况下返回。如果不能,则在指针的情况下,它将返回 nullptr ,或者在参考的情况下投掷 std :: bad_cast

dynamic_cast 有一些限制。如果继承层次结构中有相同类型的多个对象(所谓的“可怕的钻石”),并且您不使用 virtual 继承,则无效。它还只能通过公共继承 - 它总是无法通过受保护 private 继承。但是,这很少是一个问题,因为这种继承形式很少见。

reinterpret_cast

reinterpret_cast 是最危险的铸件,应非常谨慎地使用。它直接将一种类型变成另一种类型,例如将价值从一个指针转换为另一种指针,或将指针存储在 int 中,或其他各种讨厌的东西。在很大程度上,您唯一可以保证 reinterpret_cast 通常,如果将结果归还给原始类型,则将获得完全相同的值(但是 not> not 如果中间类型小于原始类型)。 reinterpret_cast 也无法做到许多转换。通常会滥用它,特别是将原始数据流转换为实际数据,或将数据存储在调整后数据的指针的低位中。对于这些情况,请参阅 std :: bit_cast

C风格的铸造和功能风格的铸造

C风格铸造和功能风格的铸件是使用(type)对象 type> type(object),并且在功能上是相等的。它们定义为成功的以下第一个:

  • const_cast
  • static_cast (尽管忽略访问限制)
  • static_cast (请参阅上文),然后 const_cast
  • reinterpret_cast
  • reinterpret_cast ,然后 const_cast

因此,它可以用作在某些情况下的替换,但是可以是由于能够将 reinterpret_cast 延伸到需要显式铸造时,因此非常危险,除非您确定 static_cast 将获得成功或 reinterpret_cast,否则应首选。 将失败。即使那样,请考虑更长,更明确的选项。

执行 static_cast 时,C风格的铸件也忽略了访问控制,这意味着他们有能力执行其他铸件无法执行的操作。但是,这主要是一个笨拙的人,在我看来,这只是避免C风格的另一个原因。

std :: bit_cast [C ++ 20]

std :: bit_cast 将源对象(其表示)的位和字节直接复制到目标类型的新对象中。这是一种符合标准的方式进行类型的双调。如果您发现自己写*reinterpret_cast&lt; lye stype*&gt;(&amp; x),您可能应该使用 std :: bit_cast&lt;(x)代替。

std :: bit_cast &lt; bit&gt; 中声明。对象必须具有相同的尺寸,并且可以琐碎地复制。如果您还不能使用C ++ 20,请使用 memcpy 将源值复制到所需类型的变量中。

static_cast

static_cast is the first cast you should attempt to use. It does things like implicit conversions between types (such as int to float, or pointer to void*), and it can also call explicit conversion functions (or implicit ones). In many cases, explicitly stating static_cast isn't necessary, but it's important to note that the T(something) syntax is equivalent to (T)something and should be avoided (more on that later). A T(something, something_else) is safe, however, and guaranteed to call the constructor.

static_cast can also cast through inheritance hierarchies. It is unnecessary when casting upwards (towards a base class), but when casting downwards it can be used as long as it doesn't cast through virtual inheritance. It does not do checking, however, and it is undefined behavior to static_cast down a hierarchy to a type that isn't actually the type of the object.

const_cast

const_cast can be used to remove or add const to a variable; no other C++ cast is capable of removing it (not even reinterpret_cast). It is important to note that modifying a formerly const value is only undefined if the original variable is const; if you use it to take the const off a reference to something that wasn't declared with const, it is safe. This can be useful when overloading member functions based on const, for instance. It can also be used to add const to an object, such as to call a member function overload.

const_cast also works similarly on volatile, though that's less common.

dynamic_cast

dynamic_cast is exclusively used for handling polymorphism. You can cast a pointer or reference to any polymorphic type to any other class type (a polymorphic type has at least one virtual function, declared or inherited). You can use it for more than just casting downwards – you can cast sideways or even up another chain. The dynamic_cast will seek out the desired object and return it if possible. If it can't, it will return nullptr in the case of a pointer, or throw std::bad_cast in the case of a reference.

dynamic_cast has some limitations, though. It doesn't work if there are multiple objects of the same type in the inheritance hierarchy (the so-called 'dreaded diamond') and you aren't using virtual inheritance. It also can only go through public inheritance - it will always fail to travel through protected or private inheritance. This is rarely an issue, however, as such forms of inheritance are rare.

reinterpret_cast

reinterpret_cast is the most dangerous cast, and should be used very sparingly. It turns one type directly into another — such as casting the value from one pointer to another, or storing a pointer in an int, or all sorts of other nasty things. Largely, the only guarantee you get with reinterpret_cast is that normally if you cast the result back to the original type, you will get the exact same value (but not if the intermediate type is smaller than the original type). There are a number of conversions that reinterpret_cast cannot do, too. It's often abused for particularly weird conversions and bit manipulations, like turning a raw data stream into actual data, or storing data in the low bits of a pointer to aligned data. For those cases, see std::bit_cast.

C-Style Cast and Function-Style Cast

C-style cast and function-style cast are casts using (type)object or type(object), respectively, and are functionally equivalent. They are defined as the first of the following which succeeds:

  • const_cast
  • static_cast (though ignoring access restrictions)
  • static_cast (see above), then const_cast
  • reinterpret_cast
  • reinterpret_cast, then const_cast

It can therefore be used as a replacement for other casts in some instances, but can be extremely dangerous because of the ability to devolve into a reinterpret_cast, and the latter should be preferred when explicit casting is needed, unless you are sure static_cast will succeed or reinterpret_cast will fail. Even then, consider the longer, more explicit option.

C-style casts also ignore access control when performing a static_cast, which means that they have the ability to perform an operation that no other cast can. This is mostly a kludge, though, and in my mind is just another reason to avoid C-style casts.

std::bit_cast [C++20]

std::bit_cast copies the bits and bytes of the source object (its representation) directly into a new object of the target type. It's a standards-compliant way to do type punning. If you find yourself writing *reinterpret_cast<SomeType*>(&x), you probably should use std::bit_cast<SomeType>(x) instead.

std::bit_cast is declared in <bit>. The objects must be the same size and be trivially copyable. If you can't yet use C++20, use memcpy to copy the source value into a variable of the desired type.

何时使用static_cast,dynamic_cast,const_cast和reinterpret_cast?

玩心态 2025-02-14 16:29:04

我们无法提供全面的答案,没有:

  1. 知道它是独立的还是分布式模式< /a>
  2. 什么 stdout> stdout> stdout
  3. 什么是什么://jmeter.apache.org/usermanual/get- started.html#logging“ rel =” nofollow noreferrer“> jmeter.log.log 在所有机器上说

等待可能的等待可能的关闭/posteptestnow/stoptestestnow/heapdump /threaddump消息在端口4445 消息是绝对正常,这只是jmeter正在听的信息,

您还应该看到 summariser 每30秒输出一次,并具有一些基线统计指标。喜欢:

summary +      5 in 00:00:26 =    0.2/s Avg:   246 Min:    59 Max:   498 Err:     0 (0.00%) Active: 1 Started: 1 Finished: 0
summary +      1 in 00:00:10 =    0.1/s Avg:   128 Min:   128 Max:   128 Err:     0 (0.00%) Active: 0 Started: 1 Finished: 1

演示:

We are not able to provide a comprehensive answer without:

  1. Knowing whether it is standalone or distributed mode
  2. What does STDOUT say
  3. What does jmeter.log say on all machines

If the Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445 message is absolutely normal, it's just an information that JMeter is listening for shutdown or dump signals

You should also see Summariser output once per 30 seconds with some baseline statistical metrics looking like:

summary +      5 in 00:00:26 =    0.2/s Avg:   246 Min:    59 Max:   498 Err:     0 (0.00%) Active: 1 Started: 1 Finished: 0
summary +      1 in 00:00:10 =    0.1/s Avg:   128 Min:   128 Max:   128 Err:     0 (0.00%) Active: 0 Started: 1 Finished: 1

Demo:

enter image description here

在Jmeter 5.4.3中,V使用了stoptest.sh命令。现在无法运行任何测试套件。有人可以帮助解决吗

玩心态 2025-02-14 07:18:11

您的程序抛出了例外,并且在我运行时对我没有正常工作。这是我的修改

    int number, aanet1, isoin;
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter the number of candidates:");
    number = scanner.nextInt();

    int[] votes = new int[number];
    String[] ehdokkaat = new String[number];
    for (int i = 0; i < number; i++) {

        System.out.print("Enter candidate's name:");
        String x = scanner.next();
        ehdokkaat[i] = x;
        System.out.print("Enter " + ehdokkaat[i] + "'s votes:");
        int c = scanner.nextInt();
        votes[i] = c;

    }
    isoin = votes[0];
    int kohta = 0;
    for (int i = 1; i < votes.length; i++) {
        if (isoin < votes[i]) {
            isoin = votes[i];
            kohta = i;
        }
    }
    System.out.println();
    System.out.println(ehdokkaat[kohta] + " is the winner with " + isoin + " votes!");
}
  • for循环之前删除了重复的逻辑,
  • 在kohta中的
  • 您不能保存索引,但是获胜者的选票for loop符合票数


有多种方法可以解决。
最简单的是通过投票数组迭代并找到最大值。

然后,您再次迭代,然后保存具有值的数组的索引。

然后,您使用Ehdokkaat阵列中的这些索引来找到获胜者。

您可以查看是否有领带,阵列,列表中的项目数量或使用的任何内容。因此,如果是一个,您将有赢家,否则会有领带。

更新:
我为您写了它,没有进行非常广泛的测试,我使用了数组,希望您对此一切都好。

    int number, aanet1, isoin;
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter the number of candidates:");
    number = scanner.nextInt();
    Integer[] votes = new Integer[number];
    String[] ehdokkaat = new String[number];
    for (int i = 0; i < number; i++) {

        System.out.print("Enter candidate's name:");
        String x = scanner.next();
        ehdokkaat[i] = x;
        System.out.print("Enter " + ehdokkaat[i] + "'s votes:");
        int c = scanner.nextInt();
        votes[i] = c;

    }
    int max = Collections.max(Arrays.asList(votes));
    List<Integer> winners = new ArrayList();
    for (int i = 0; i < votes.length; i++) {
        if (max == votes[i]) {
            winners.add(i);
        }
    }

    if (winners.size() > 1) {
        System.out.println();
        System.out.println(String.format("Tie (with %d votes) between:", max));
        for (Integer index : winners) {
            System.out.println(ehdokkaat[index]);
        }
    } else {
        System.out.println();
        System.out.println(ehdokkaat[winners.get(0)] + " is the winner with " + max + " votes!");
    }

Your program threw exceptions and did not work as expected for me I when I ran it. Here are my modifications

    int number, aanet1, isoin;
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter the number of candidates:");
    number = scanner.nextInt();

    int[] votes = new int[number];
    String[] ehdokkaat = new String[number];
    for (int i = 0; i < number; i++) {

        System.out.print("Enter candidate's name:");
        String x = scanner.next();
        ehdokkaat[i] = x;
        System.out.print("Enter " + ehdokkaat[i] + "'s votes:");
        int c = scanner.nextInt();
        votes[i] = c;

    }
    isoin = votes[0];
    int kohta = 0;
    for (int i = 1; i < votes.length; i++) {
        if (isoin < votes[i]) {
            isoin = votes[i];
            kohta = i;
        }
    }
    System.out.println();
    System.out.println(ehdokkaat[kohta] + " is the winner with " + isoin + " votes!");
}
  • Removed the duplicate logic before the for loop
  • In the kohta you do not save the index but the votes of the winner
  • The for loop was up to votes.length and although it is correct it is a bit confusing

Now for your question
There are multiple ways to go about it.
The simplest is to iterate through the votes array and find the max value.

Then you iterate again and you save the indexes of the array that have the value .

And then you use those indexes in the ehdokkaat array to find the winners.

You can see if you have a tie, by the amount of items in the array, list or whatever you use. So if it is one you have a winner otherwise there is a tie.

UPDATE:
I wrote it for you, did not test very extensively, I used arrays I hope you are ok with it.

    int number, aanet1, isoin;
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter the number of candidates:");
    number = scanner.nextInt();
    Integer[] votes = new Integer[number];
    String[] ehdokkaat = new String[number];
    for (int i = 0; i < number; i++) {

        System.out.print("Enter candidate's name:");
        String x = scanner.next();
        ehdokkaat[i] = x;
        System.out.print("Enter " + ehdokkaat[i] + "'s votes:");
        int c = scanner.nextInt();
        votes[i] = c;

    }
    int max = Collections.max(Arrays.asList(votes));
    List<Integer> winners = new ArrayList();
    for (int i = 0; i < votes.length; i++) {
        if (max == votes[i]) {
            winners.add(i);
        }
    }

    if (winners.size() > 1) {
        System.out.println();
        System.out.println(String.format("Tie (with %d votes) between:", max));
        for (Integer index : winners) {
            System.out.println(ehdokkaat[index]);
        }
    } else {
        System.out.println();
        System.out.println(ehdokkaat[winners.get(0)] + " is the winner with " + max + " votes!");
    }

如果有领带,投票计划不起作用

玩心态 2025-02-13 11:13:13

从这里 psql

提示

获得与\ copy ... to相同结果的另一种方法是使用sql副本...用\ g fileName或\ g | program终止命令。与\ copy不同,此方法允许命令跨越多行;另外,可以使用可变的插值和反向引用扩展。

From here psql in \copy section:

Tip

Another way to obtain the same result as \copy ... to is to use the SQL COPY ... TO STDOUT command and terminate it with \g filename or \g |program. Unlike \copy, this method allows the command to span multiple lines; also, variable interpolation and backquote expansion can be used.

Postgres \ c与线路破裂

玩心态 2025-02-13 08:22:00

答案很容易。您分配了一系列指针,但是您没有为字符串分配任何空间。当您使用 calloc 时,所有指针均为空。

在此行中(以及在所有其他您使用 out [i] [j] >的地方),

out[i][j] = let;

您取消指针。它是 u ndefined b ehaviour(ub),在您的情况下,它将自己表示为segfault。

The answer is very easy. You allocate an array of pointers, but you do not allocate any space for the strings. As you use calloc all pointers are NULL.

In this line (and in all others where you use out[i][j])

out[i][j] = let;

you dereference NULL pointer. It is Undefined Behaviour (UB) and in your case it is expressing itself as SegFault.

细分线的分割故障

玩心态 2025-02-13 02:54:50

事实证明,将这些下拉词中的选定值复制到隐藏的CSS,而不是隐藏的字段中,然后将我的验证运行是必经之路。捕获的是,我需要用“可见性:隐藏”而不是“显示:无”隐藏它们,这是我以前尝试过的。

It turned out that copying the selected values in these drop-downs into TextBoxes hidden with CSS, instead of hidden fields, and then running my validation off those was the way to go. The catch was that I needed to hide them with "visibility: hidden", not "display: none", which I had tried previously.

jQuery验证未验证下拉列表

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文