若水微香

文章 评论 浏览 27

若水微香 2025-02-03 08:49:52

在查看了python asyncio文档之后,我发现的最接近的例子是:

请注意一个环内的asyncio.sleep,类似于绕阻塞函数的无限环路的传统模式。

async def main():
    nc = await nats.connect(nats_url)
    js = nc.jetstream()

    await js.add_stream(name=stream, subjects=[subject])

    await js.subscribe(subject, qgroup, cb=do_work)

    while True:
        print("loop")
        await asyncio.sleep(10)


if __name__ == "__main__":
    asyncio.run(main())

After looking at the Python asyncio docs, the closest example i found is this:

Note the asyncio.sleep inside a loop, similar to the traditional pattern of an infinite loop around a blocking function.

async def main():
    nc = await nats.connect(nats_url)
    js = nc.jetstream()

    await js.add_stream(name=stream, subjects=[subject])

    await js.subscribe(subject, qgroup, cb=do_work)

    while True:
        print("loop")
        await asyncio.sleep(10)


if __name__ == "__main__":
    asyncio.run(main())

在Python Asyncio中保持长期运行客户端的首选方法

若水微香 2025-02-03 00:50:32

您需要从乌龟中导入所有东西。使用:

from turtle import *

color('red')
bgcolor('black')
speed(20)
b = 200
while b > 0:
    left(b)
    forward(b+3)
    b -= 1

You need to import everything from the turtle. Use:

from turtle import *

color('red')
bgcolor('black')
speed(20)
b = 200
while b > 0:
    left(b)
    forward(b+3)
    b -= 1

如何修复颜色(Red')名称:name' color'未定义

若水微香 2025-02-02 22:17:48

这与您如何处理道具输入有关。

当在打字稿中破坏 {儿童:reactnode} 破坏儿童属性中的属性,将其分配给称为 react> react Node 的变量。然后,与其调用 react node (这也是一个错误,因为您也导入了它),而是使用 props.Children ,该尚未定义。

而是使用语法: {children}:{children:reactnode} ,尽管使用接口会更容易。

import React, { Dispatch, ReactNode, SetStateAction, createContext } from "react"

export interface StateGlobalContextType {
    loading: boolean
    setLoading: Dispatch<SetStateAction<boolean>>
}

export const StateGlobalContext = createContext<StateGlobalContextType>({} as StateGlobalContextType)

interface StateGlobalProviderProps {
    children: ReactNode
}
const StateGlobalProvider: React.FC<StateGlobalProviderProps> = ({ children }: StateGlobalProviderProps) => {
    const [loading, setLoading] = React.useState<boolean>(false)

    return <StateGlobalContext.Provider value={{ loading, setLoading }}>{children}</StateGlobalContext.Provider>
}

export default StateGlobalProvider

另外,与其将函数的返回类型声明为 react.fc&lt; reactnode&gt; ,不如将组件本身声明为type react.fc&lt; stateglobalproviderprops&gt;

This is an error to do with how you're handling your props input.

When destructuring in Typescript doing { children: ReactNode } destructures the children attribute from props, assigning it to a variable called ReactNode. Then, rather than calling ReactNode (which would still be an error because you've imported it too), you're using props.children, which is not defined.

Instead use the syntax: { children }: { children: ReactNode }, although this is easier if you use an interface.

import React, { Dispatch, ReactNode, SetStateAction, createContext } from "react"

export interface StateGlobalContextType {
    loading: boolean
    setLoading: Dispatch<SetStateAction<boolean>>
}

export const StateGlobalContext = createContext<StateGlobalContextType>({} as StateGlobalContextType)

interface StateGlobalProviderProps {
    children: ReactNode
}
const StateGlobalProvider: React.FC<StateGlobalProviderProps> = ({ children }: StateGlobalProviderProps) => {
    const [loading, setLoading] = React.useState<boolean>(false)

    return <StateGlobalContext.Provider value={{ loading, setLoading }}>{children}</StateGlobalContext.Provider>
}

export default StateGlobalProvider

Also, rather than declaring the return type of function as React.FC<ReactNode>, declare the component itself as type React.FC<StateGlobalProviderProps>

使用thexpript使用createContext时获取错误

若水微香 2025-02-02 11:09:52

我找到了与创建自定义过滤器相关的解决方案。在过滤器内部,您可以访问请求并从中获取标题。
标题包含加密的登录和密码。您可以将其降低并获取登录和密码。

I found the solution which is related with creation of custom filter. Inside the filter you can get access to the request and get the header from it.
The header contains encrypted login and password. You can decript it and get login and password.

如何获取登录并从春季启动中的基本验证

若水微香 2025-02-02 09:09:33
<body>
    <table width=100% border=0 cellspacing=0 cellpadding=0><tr><td>
    <div id="f1" style="background-color:red;">{{ f1|safe }}</div>
    </td><td>
    <div id="f2" style="background-color:green;">{{ f2|safe }}</div>
    </td></tr><tr><td>
    <div id="f3" style="background-color:blue;">{{ f3|safe }}</div>
    </td><td>
    <div id="f4">{{ f4|safe }}</div>
    </td></tr></table>
</body>
<body>
    <table width=100% border=0 cellspacing=0 cellpadding=0><tr><td>
    <div id="f1" style="background-color:red;">{{ f1|safe }}</div>
    </td><td>
    <div id="f2" style="background-color:green;">{{ f2|safe }}</div>
    </td></tr><tr><td>
    <div id="f3" style="background-color:blue;">{{ f3|safe }}</div>
    </td><td>
    <div id="f4">{{ f4|safe }}</div>
    </td></tr></table>
</body>

如何将4个Div 2放在每行上?

若水微香 2025-02-02 08:38:39

尝试删除文件夹中的文件:

{yourWorkspace}\{project}\.metadata\.plugins\org.eclipse.m2e.core\nexus

Try removing the files inside the folder:

{yourWorkspace}\{project}\.metadata\.plugins\org.eclipse.m2e.core\nexus

内部错误在:“存储库注册初始化”期间。 Java.lang.ArrayIndexoutofBoundSexception

若水微香 2025-02-02 01:56:59

不幸的是,使用Linux OS的App Service计划的免费和基本层次不支持Visual Studio的发布。似乎可以与Windows计划一起使用。

Unfortunately, publishing from Visual Studio is not supported in the Free and Basic Tiers of App Service Plan with Linux OS. Is does seem to work with Windows plans.

Visual Studio 2022不会发布到现有的免费层托管计划

若水微香 2025-02-01 21:20:49

一个简单的解决方案是将第一个 target1 重命名为其他东西,然后在 target2 规则之前调用它。类似:

.PHONY: target1 target1_cmd
target1_cmd:
    command1
target1: target1_cmd target2
    command2

这将运行 command1 ,无论 target2 中的任何内容,然后运行 command2

我不确定我会想做的一切,但让我知道您是否需要更多细节和解释。

A simple solution would be to rename the first target1 to something else and call it before the target2 rule. Something like:

.PHONY: target1 target1_cmd
target1_cmd:
    command1
target1: target1_cmd target2
    command2

This will run command1, whatever is in target2 and then run the command2.

I'm not sure I get everything that you are trying to do but let me know if you need more details and explanation.

在makefile中重新排序命令

若水微香 2025-02-01 19:44:08

这不是 @html 或所示代码的问题。您需要确保正确设置所有内容。

  1. 注册字典/字典
  2. 注册本地
  3. 等待语言环境

使用您的数据加载,这是完全有效的示例:

<script>
  import { register, init, waitLocale, getLocaleFromNavigator, _ } from 'svelte-i18n';

  register('en', () => Promise.resolve({   
      "page": {
          "faq": {
              "frequent_questions": "<span>{numberOfQuestions} frequently asked </span>questions"
          }
      }
  }));
  init({ initialLocale: getLocaleFromNavigator(), fallbackLocale: 'en' });
</script>

{#await waitLocale() then}
  <p>
    {@html ($_("page.faq.frequent_questions", { values: { numberOfQuestions: '4' } }))}
  </p>
{/await}

repl

This is not a problem with @html or the code shown. You need to make sure to set up everything correctly.

  1. Register the dictionary/dictionaries
  2. Init the locale
  3. Wait for locale to have loaded

Using your data, here is fully working example:

<script>
  import { register, init, waitLocale, getLocaleFromNavigator, _ } from 'svelte-i18n';

  register('en', () => Promise.resolve({   
      "page": {
          "faq": {
              "frequent_questions": "<span>{numberOfQuestions} frequently asked </span>questions"
          }
      }
  }));
  init({ initialLocale: getLocaleFromNavigator(), fallbackLocale: 'en' });
</script>

{#await waitLocale() then}
  <p>
    {@html ($_("page.faq.frequent_questions", { values: { numberOfQuestions: '4' } }))}
  </p>
{/await}

REPL

Svelte-i18n:如何使用@html格式化消息

若水微香 2025-02-01 17:54:39

您可以使用 shgetnoichfolderpath(folderID_Downloads),以所需用户帐户的令牌传递。诀窍将在于知道您想要哪个用户。可能有多个用户同时登录。可能根本没有登录的用户。如果您的服务在系统帐户下运行,则可以通过 wtsenumerateessions()列举活动用户会话,并通过 wtsqueryusertoken()获得其用户令牌。

You can use SHGetKnownFolderPath(FOLDERID_Downloads), passing in a token for the desired user account. The trick will be in knowing which user you want. There may be more than one user logged in at the same time. There may be no users logged in at all. If your service is running under the SYSTEM account, it can enumerate active user sessions via WTSEnumerateSessions() and get their user token via WTSQueryUserToken().

访问当前记录的用户下载文件夹中的文件夹中的C#Windows服务中的文件夹

若水微香 2025-02-01 17:28:03

机器上运行的过程数量可能大于核心数量或处理器数量。两者之间没有直接的链接。

流程可以具有一个或多个软件线程,该线程已安排在操作系统(OS)上的处理单元上。此类处理单元称为硬件线程。 1个硬件线程一次只能执行1个线程。操作系统使用先发制人,以便在同一硬件线程上执行多个软件线程。更具体地说,每个软件线程都安排在给定时间(例如称为Quantum,在Windows上持续几毫秒)。当量子时间结束时或软件线程执行阻止操作时(例如,等待另一个软件线程,读取文件等),或者当具有更高优先级的线程准备就绪时(例如,如@MartinJames提到的,即准备好的阻止操作)。确切的算法可以从一个平台更改为另一个平台。对于Windows,您可以在

在大多数处理器上,内核都有2个硬件线程(在英特尔处理器上,这称为超线程)。这意味着每个核心都可以并行执行两个软件线程(尽管它们共享了一些硬件资源)。可以并行运行的线程数量由硬件线程的数量定义。任务管理器将其报告为“逻辑处理器”。 16个线程可以在您的计算机上并行运行,但由于优先考虑,更多的线程可以同时运行。

请注意,大多数软件线程通常都在等待,因此它们没有由硬件线程上的操作系统安排。操作系统只能在需要时唤醒它们。因此,只要没有积极运行(更确切地说,它们的软件线程),拥有200个过程就不是一个问题。

请注意,过程是不是绑定到给定处理器的。一个过程可以在多个处理器上执行多个线程。

产卵过程非常昂贵(与软件线程相反)。通常,它需要100秒至10毫秒(有关OS,目标机器和连接的附件程序)。产生软件线程的速度要快得多。通常,它不超过1 ms(但这同样是非常依赖平台的)。要使用多个软件线程来使用所有可用的内核/硬件线程。

The number of process running on a machine can be bigger than the number of core or the number of processor. There is no direct link between the two.

Processes can have one or multiple software threads that are scheduled on processing units by the operating system (OS). Such processing units are called hardware threads. 1 hardware thread can only execute 1 thread at a time. The OS use preemption so to execute multiple software threads on the same hardware thread. More specifically, each software thread is scheduled for a given time (eg. called quantum, lasting few milliseconds on Windows). The OS performs a context switch when the quantum time is over, or if the software thread perform blocking operations (eg. waiting for another software thread, reading a file, etc.), or also if a thread with a higher priority becomes ready (eg. a blocking operation is ready, as mentioned by @MartinJames). The exact algorithm can change from one platform to another. For Windows, you can get some information about that in the Microsoft documentation.

On most processors cores have 2 hardware threads (on Intel processor, this is called Hyper-Threading). This means each core can execute two software threads truly in parallel (though they share some hardware resources). The number of threads that can truly run in parallel is defined by the number of hardware threads. The Task Manager reports this as "logical processors". 16 threads can run in parallel on your machine but more can run concurrently thanks to preemption.

Note that most software threads are generally waiting and thus they are not scheduled by the OS on hardware threads. The OS will wake them up only when needed. Consequently, having 200 processes is not an issue as long as they are not actively running (to be more precise, their software threads).

Note that processes are not bound to a given processor. One process can have several threads executed on multiple processors.

Spawning a process is quite expensive (as opposed to a software thread). It generally take from 100 us to 10 ms (regarding the OS, the target machine and the attached program to run). Spawning a software thread is much faster. It generally does not take more than 1 ms (but again this is very dependant of the platform). Spawning multiple software threads is required to use all the available cores/hardware-threads.

当过程比核心更多的过程时会发生什么?

若水微香 2025-02-01 04:21:37

我在这里要考虑的方法是:

,所以

SELECT Employee FROM Table GROUP BY Employee, datepart('year', Date), datepart('week', DATE) HAVING COUNT(*) >=5

要让所有具有至少2个活跃周的员工就是这样

SELECT Employee, COUNT(*) as ActiveWeeks FROM (
SELECT Employee, datepart('year', Date), datepart('week', DATE) FROM Table GROUP BY Employee, datepart('year', Date), datepart('week', DATE) HAVING COUNT(*) >=5) as activeWeeks
GROUP BY activeWeeks.Employee HAVING COUNT(*) >= 2

The approach I would consider here is:

So something like

SELECT Employee FROM Table GROUP BY Employee, datepart('year', Date), datepart('week', DATE) HAVING COUNT(*) >=5

To then get all Employees having atleast 2 active weeks is like this

SELECT Employee, COUNT(*) as ActiveWeeks FROM (
SELECT Employee, datepart('year', Date), datepart('week', DATE) FROM Table GROUP BY Employee, datepart('year', Date), datepart('week', DATE) HAVING COUNT(*) >=5) as activeWeeks
GROUP BY activeWeeks.Employee HAVING COUNT(*) >= 2

在派生表上进行自定义计数

若水微香 2025-02-01 00:38:12

在这种情况下,过滤现有的QuerySet确实对数据库进行了附加调用,因为第一个QuerySet已通过.count()评估。但是,count()比完整查询更有效,因此开销并不好。除非您受到效率的伤害,否则这可能还可以。

但是,当您使用相同的循环项目并经常对相同的内容进行测试时,多次循环循环循环是有些低效的。以下仅通过一次循环,然后将一些if语句分组,这使得更容易看到模式:

def overview_view(request):
细菌=细菌.objects.all()
bacteria_count = bacteria.count()

bacteriaFilter = BacteriaFilter(request.GET, queryset=bacteria)
bacteria = bacteriaFilter.qs
remaining = bacteria.count()

glucose = []
not_glucose = []
pure_glucose = []
fructose = []
not_fructose = []
pure_fructose = []

for bug in bacteria:
    if (bug.glucose_acid_from is not None):
        if (bug.glucose_acid_from != 'neg'):
            glucose.append(bug.species)

        if (bug.glucose_use is not None) and (bug.glucose_use == 'neg')  and (bug.glucose_acid_from == 'neg'):
            not_glucose.append(bug.species)            
        if (bug.glucose_acid_from == '+'):
            pure_glucose.append(bug.species)
        
    if (bug.glucose_use is not None): 
        if (bug.glucose_use != 'neg'):
            glucose.append(bug.species)
        
        if (bug.glucose_use == '+'):
            pure_glucose.append(bug.species)


        
    if (bug.fructose_acid_from is not None): 
        if (bug.fructose_acid_from != 'neg'):
            fructose.append(bug.species)
        
        if (bug.fructose_use is not None) and (bug.fructose_use == 'neg') and (bug.fructose_acid_from == 'neg'):
            not_fructose.append(bug.species)
        
        if (bug.fructose_acid_from == '+'):
            pure_fructose.append(bug.species)               

    if (bug.fructose_use is not None):
         if (bug.fructose_use != 'neg'):
            fructose.append(bug.species)     
            
        if  (bug.fructose_use == '+'):
            pure_fructose.append(bug.species)


        
any_glucose = len(set(glucose))        
no_glucose = len(set(not_glucose))
mix_glucose = any_glucose - len(set(pure_glucose))
nonr_glucose = bacteria_count - any_glucose        
any_fructose = len(set(fructose))  
no_fructose = len(set(not_fructose))      
mix_fructose = any_fructose - len(set(pure_fructose))
nonr_fructose = bacteria_count - any_fructose ...etc.

用于动态现场名称,您可以尝试:

str_variable = "glucose_acid_from"
bacteria = Bacteria.objects.all.values()
for bug in bacteria:
    if bug[str_variable] is not None:

Filtering an existing queryset does make an additional call to the database in this case, because the first queryset has been evaluated via .count(). However, count() is more efficient than a full query, so the overhead isn't that great. Unless you are hurting for efficiency, this is probably OK.

However, it is somewhat inefficient to cycle through the recordset multiple times when you are using the same looped items and often testing for the same things. the below only loops through once, and groups some If statements which makes it easier to see patterns:

def overview_view(request):
bacteria = Bacteria.objects.all()
bacteria_count = bacteria.count()

bacteriaFilter = BacteriaFilter(request.GET, queryset=bacteria)
bacteria = bacteriaFilter.qs
remaining = bacteria.count()

glucose = []
not_glucose = []
pure_glucose = []
fructose = []
not_fructose = []
pure_fructose = []

for bug in bacteria:
    if (bug.glucose_acid_from is not None):
        if (bug.glucose_acid_from != 'neg'):
            glucose.append(bug.species)

        if (bug.glucose_use is not None) and (bug.glucose_use == 'neg')  and (bug.glucose_acid_from == 'neg'):
            not_glucose.append(bug.species)            
        if (bug.glucose_acid_from == '+'):
            pure_glucose.append(bug.species)
        
    if (bug.glucose_use is not None): 
        if (bug.glucose_use != 'neg'):
            glucose.append(bug.species)
        
        if (bug.glucose_use == '+'):
            pure_glucose.append(bug.species)


        
    if (bug.fructose_acid_from is not None): 
        if (bug.fructose_acid_from != 'neg'):
            fructose.append(bug.species)
        
        if (bug.fructose_use is not None) and (bug.fructose_use == 'neg') and (bug.fructose_acid_from == 'neg'):
            not_fructose.append(bug.species)
        
        if (bug.fructose_acid_from == '+'):
            pure_fructose.append(bug.species)               

    if (bug.fructose_use is not None):
         if (bug.fructose_use != 'neg'):
            fructose.append(bug.species)     
            
        if  (bug.fructose_use == '+'):
            pure_fructose.append(bug.species)


        
any_glucose = len(set(glucose))        
no_glucose = len(set(not_glucose))
mix_glucose = any_glucose - len(set(pure_glucose))
nonr_glucose = bacteria_count - any_glucose        
any_fructose = len(set(fructose))  
no_fructose = len(set(not_fructose))      
mix_fructose = any_fructose - len(set(pure_fructose))
nonr_fructose = bacteria_count - any_fructose ...etc.

For dynamic fieldnames, you might try:

str_variable = "glucose_acid_from"
bacteria = Bacteria.objects.all.values()
for bug in bacteria:
    if bug[str_variable] is not None:

相同的QuerySet评估代码,Django视图中的不同字段名称

若水微香 2025-01-31 22:50:38

仅关注当前代码...

假设/理解:

  • 变量 Profseq 是包含来自函数 echo echo 呼叫的输出;我们可以通过替换 echo echo“ ...” 用<)消除子过程呼叫( profseq = $(... subprocess call ...))。代码> profseq =“ ...” (即,使该函数直接填充 profseq
  • 可以通过消除对split varheaderline varheaderline varheaderline < /code>( $(echo ... | cut ...)), bash/read 内置的

一个函数重写的想法:

ParseCOTHeader () {

local varHeaderLine=$1
local -l varType=$2                                # force to all lowercase
local ignore1 ignore2 in_seq in_date in_count rc

# split varHeaderLine into 5 variables based on '|' delimiter:
# NOTE: assumes varHeaderLine has exactly 5x '|' delimited fields otherwise OP
#       may want to add some code to validate the structure of varHeaderLine

IFS='|' read -r ignore1 ignore2 in_seq in_date in_count <<< "${varHeaderLine}"

# reset variables:

ProfSeq=
rc=0

if [[ -z "${varType}" ]]
then
    ProfSeq="Cannot find! - ($2)"                  # since varType=$2 is empty at this point we will always print '()' ... ?
    rc=1
else
    case "${varType}" in
         seq)    ProfSeq="Sequence: ${in_seq}" ;;
         date)   ProfSeq="Date: ${in_date}" ;;
         count)  ProfSeq="Line Count: ${in_count}" ;;
         *)      ProfSeq="Invalid input! Your Header is: '$varHeaderLine'"
                 rc=1 ;;
    esac
fi

return "${rc}"
}

通过其速度将功能放置:

$ sequence='SWHHR|H|1|20220429|9999'

$ ParseCOTHeader "${sequence}" 'seq'
$ echo "$? : ${ProfSeq}"
0 : Sequence: 1

$ ParseCOTHeader "${sequence}" 'DaTe'
$ echo "$? : ${ProfSeq}"
0 : Date: 20220429

$ ParseCOTHeader "${sequence}" 'COUNT'
$ echo "$? : ${ProfSeq}"
0 : Line Count: 9999

$ ParseCOTHeader "${sequence}" 'fire-truck'
$ echo "$? : ${ProfSeq}"
1 : Invalid input! Your Header is: 'SWHHR|H|1|20220429|9999'

$ ParseCOTHeader "${sequence}" ''
$ echo "$? : ${ProfSeq}"
1 : Cannot find! - ()

如果重复调用该函数需要在不同变量中保存消息字符串:

  • 添加行 local -n myOutput = $ 3 在该函数的顶部(这定义了local nameref variable > 变量名称的指针
  • MyOutput 用作$ 3中传递的 该函数
  • 删除行 profseq = (可变重置),以

获取新功能以进行测试旋转:

$ sequence='SWHHR|H|1|20220429|9999'

$ ParseCOTHeader "${sequence}" 'seq' ProfSeq
$ echo "$? : ${ProfSeq}"
0 : Sequence: 1

$ ParseCOTHeader "${sequence}" 'DaTe' ProfSeq
$ echo "$? : ${ProfSeq}"
0 : Date: 20220429

$ ParseCOTHeader "${sequence}" 'COUNT' ProfSeq
$ echo "$? : ${ProfSeq}"
0 : Line Count: 9999

$ ParseCOTHeader "${sequence}" 'fire-truck' SomeOtherVar
$ echo "$? : ${SomeOtherVar}"
1 : Invalid input! Your Header is: 'SWHHR|H|1|20220429|9999'

$ ParseCOTHeader "${sequence}" '' YetAnotherVar
$ echo "$? : ${YetAnotherVar}"
1 : Cannot find! - ()

Focusing solely on the current piece of code ...

Assumptions/Understandings:

  • the variable ProfSeq is to contain the output from the function's echo calls; we can eliminate the subprocess call (ProfSeq=$( ... subprocess call ...)) by having the function replace the echo "..." calls with ProfSeq="..." (ie, have the function directly populate the ProfSeq variable
  • additional performance improvements can be derived from eliminating the double subprocess calls to split varHeaderLine ($(echo ... | cut ...)) with the bash/read builtin

One idea for a function rewrite:

ParseCOTHeader () {

local varHeaderLine=$1
local -l varType=$2                                # force to all lowercase
local ignore1 ignore2 in_seq in_date in_count rc

# split varHeaderLine into 5 variables based on '|' delimiter:
# NOTE: assumes varHeaderLine has exactly 5x '|' delimited fields otherwise OP
#       may want to add some code to validate the structure of varHeaderLine

IFS='|' read -r ignore1 ignore2 in_seq in_date in_count <<< "${varHeaderLine}"

# reset variables:

ProfSeq=
rc=0

if [[ -z "${varType}" ]]
then
    ProfSeq="Cannot find! - ($2)"                  # since varType=$2 is empty at this point we will always print '()' ... ?
    rc=1
else
    case "${varType}" in
         seq)    ProfSeq="Sequence: ${in_seq}" ;;
         date)   ProfSeq="Date: ${in_date}" ;;
         count)  ProfSeq="Line Count: ${in_count}" ;;
         *)      ProfSeq="Invalid input! Your Header is: '$varHeaderLine'"
                 rc=1 ;;
    esac
fi

return "${rc}"
}

Putting the function through its paces:

$ sequence='SWHHR|H|1|20220429|9999'

$ ParseCOTHeader "${sequence}" 'seq'
$ echo "$? : ${ProfSeq}"
0 : Sequence: 1

$ ParseCOTHeader "${sequence}" 'DaTe'
$ echo "$? : ${ProfSeq}"
0 : Date: 20220429

$ ParseCOTHeader "${sequence}" 'COUNT'
$ echo "$? : ${ProfSeq}"
0 : Line Count: 9999

$ ParseCOTHeader "${sequence}" 'fire-truck'
$ echo "$? : ${ProfSeq}"
1 : Invalid input! Your Header is: 'SWHHR|H|1|20220429|9999'

$ ParseCOTHeader "${sequence}" ''
$ echo "$? : ${ProfSeq}"
1 : Cannot find! - ()

If repeated calls to the function need to save the message string in different variables:

  • add the line local -n myoutput=$3 in the top section of the function (this defines a local nameref variable myoutput to act as a pointer to the variable name passed in $3)
  • replace all ProfSeq="..." with myoutput="..." in the function
  • remove the line ProfSeq= (variable reset) in the function

Taking the new function for a test spin:

$ sequence='SWHHR|H|1|20220429|9999'

$ ParseCOTHeader "${sequence}" 'seq' ProfSeq
$ echo "$? : ${ProfSeq}"
0 : Sequence: 1

$ ParseCOTHeader "${sequence}" 'DaTe' ProfSeq
$ echo "$? : ${ProfSeq}"
0 : Date: 20220429

$ ParseCOTHeader "${sequence}" 'COUNT' ProfSeq
$ echo "$? : ${ProfSeq}"
0 : Line Count: 9999

$ ParseCOTHeader "${sequence}" 'fire-truck' SomeOtherVar
$ echo "$? : ${SomeOtherVar}"
1 : Invalid input! Your Header is: 'SWHHR|H|1|20220429|9999'

$ ParseCOTHeader "${sequence}" '' YetAnotherVar
$ echo "$? : ${YetAnotherVar}"
1 : Cannot find! - ()

从另一个变量中拉动变量中的值

若水微香 2025-01-31 17:39:24
    Edited working code and tested:

        Stack(
          children: [
          Container(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height-150,
            decoration: const BoxDecoration(
              image: DecorationImage(
                  image: AssetImage("assets/policyback.png"),
                  fit: BoxFit.fill),
            ),
          ),
            const Padding(
              padding: EdgeInsets.only(bottom: 70,right: 10),
              child: OverflowBox(
                alignment: Alignment.bottomRight,
                child: Icon(Icons.add_a_photo, color: Colors.green,size: 70),
              ),
            ),
          ]
      )

    Edited working code and tested:

        Stack(
          children: [
          Container(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height-150,
            decoration: const BoxDecoration(
              image: DecorationImage(
                  image: AssetImage("assets/policyback.png"),
                  fit: BoxFit.fill),
            ),
          ),
            const Padding(
              padding: EdgeInsets.only(bottom: 70,right: 10),
              child: OverflowBox(
                alignment: Alignment.bottomRight,
                child: Icon(Icons.add_a_photo, color: Colors.green,size: 70),
              ),
            ),
          ]
      )

[1]: https://i.sstatic.net/nqZDW.jpg

扑来添加容器左侧的编辑按钮

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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