甜警司

文章 评论 浏览 30

甜警司 2025-02-21 01:43:26

Python将有效地找到从任何点开始的字符串的子字符串。

def positions(dnalist, substr):
    dna = "".join(dnalist) # make single string
    st = 0
    pos = []
    while True: 
        a_pos = dna.find(substr, st)
        if a_pos < 0:
            return pos
        pos.append(a_pos)
        st = a_pos + 1

测试用法:

>>> testdna = ['A', 'G', 'C', 'G', 'T', 'A', 'G', 'T', 'C', 'G', 'A', 'T', 'C', 'A', 'A', 'T', 'T', 'A', 'T', 'A', 'C', 'G', 'A', 'T', 'C', 'G', 'G', 'G', 'T', 'A', 'T']
>>> positions(testdna, "AT")
[10, 14, 17, 22, 29]

Python will efficiently find a substring of a string starting from any point.

def positions(dnalist, substr):
    dna = "".join(dnalist) # make single string
    st = 0
    pos = []
    while True: 
        a_pos = dna.find(substr, st)
        if a_pos < 0:
            return pos
        pos.append(a_pos)
        st = a_pos + 1

Test usage:

>>> testdna = ['A', 'G', 'C', 'G', 'T', 'A', 'G', 'T', 'C', 'G', 'A', 'T', 'C', 'A', 'A', 'T', 'T', 'A', 'T', 'A', 'C', 'G', 'A', 'T', 'C', 'G', 'G', 'G', 'T', 'A', 'T']
>>> positions(testdna, "AT")
[10, 14, 17, 22, 29]

调整Fucntion以找到一个以上的位置

甜警司 2025-02-19 19:42:25

我不确定Arquicklook是否可行。但是,我们可以使用SceneKit或RealityKit Arview并在运行时修改模型义。您可以使用RealityKit中的Arview进行类似的操作:

@IBOutlet var arView: ARView!


override func viewDidLoad() {
    super.viewDidLoad()

    let modelURL = URL(string: "https://developer.apple.com/augmented-reality/quick-look/models/drummertoy/toy_drummer.usdz")!

    guard let entity = try? ModelEntity.loadModel(contentsOf: modelURL!) else {
        print("Entity download failed")
        return
    }
    

    for child in entity.children {
                    
        var newMaterial = SimpleMaterial()
        newMaterial.color.tint = UIColor.cyan
        
        child.model?.materials = [newMaterial]
    }  

    let anchor = AnchorEntity(plane: .horizontal)
    anchor.addChild(entity)

    arView.scene.addAnchor(anchor)
      
}
   

请记住,您必须手动添加使用Arquicklook自动获得的变换/规模动作。

I'm not sure if this is doable with ARQuickLook. But we can use either SceneKit or RealityKit ARView and modify the ModelEntity at runtime. You could do something like this, Using ARView in RealityKit:

@IBOutlet var arView: ARView!


override func viewDidLoad() {
    super.viewDidLoad()

    let modelURL = URL(string: "https://developer.apple.com/augmented-reality/quick-look/models/drummertoy/toy_drummer.usdz")!

    guard let entity = try? ModelEntity.loadModel(contentsOf: modelURL!) else {
        print("Entity download failed")
        return
    }
    

    for child in entity.children {
                    
        var newMaterial = SimpleMaterial()
        newMaterial.color.tint = UIColor.cyan
        
        child.model?.materials = [newMaterial]
    }  

    let anchor = AnchorEntity(plane: .horizontal)
    anchor.addChild(entity)

    arView.scene.addAnchor(anchor)
      
}
   

Please keep in mind that you will have to manually add the transform/scale actions that you get automatically with ARQuickLook.

有没有办法将模型性传递给Arquicklook Preview Controller?

甜警司 2025-02-19 14:41:39

如果您打算发送字符串的倒字节而不是其十六进制表示,则可以更简单:

stbin = bytes(ord(x)^255 for x in s)
socket_instance.sendall(stbin)

If you meant to send the string's inverted bytes rather than their hexadecimal representation, you can do it even simpler:

stbin = bytes(ord(x)^255 for x in s)
socket_instance.sendall(stbin)

钻头倒转弦并将其发送到插座

甜警司 2025-02-18 17:24:22

似乎主要是对basename prop在路由器中应用,特别是hashrouter中的误解。使用Hashrouter basename prop是一个针对应用程序正在处理的路径的值,而不是针对应用程序/运行应用程序的域路径。

示例:

<HashRouter basename="/admin">
  <Link to="/dashboard" className="link"> // renders <a href="#/admin/dashboard">
    Dashboard
  </Link>
  ...
  <Routes>
    <Route path="/configuration">
      <Route path="configure" element={<Configuration />} />
      <Route index element={<SummaryPage />} />
    </Route>
    <Route path="/dashboard" element={<Dashboard />} />
    <Route path="/appointments" element={<Appointments />} />
    <Route path="/" element={<Navigate replace to="/configuration" />} />
    <Route path="*" element={<NotFound />} />
  </Routes>
</HashRouter>

换句话说,basename Prop值应用于URL hash not < /em> URL路径,即它应用于哈希之后的所有内容

mysite.com/someSubdomain/#/admin   /something / ... more nested paths
|--domain-|--subdomain--|#|--------------hash-----------------|
|         |             | |basename| app path | ... app subpaths

如果您要在哈希之前出现“/admin”出现,则这是整个应用程序部署并从中提供的部分的一部分。在这种情况下,该应用需要在“/admin” subdirectory中部署到mysite.com。您也不需要指定basename =“/admin”如果您不希望其他“/admin”出现在应用程序路由中。

mysite.com/admin/#/something

...

<HashRouter>
  <Link to="/dashboard" className="link"> // renders <a href="#/dashboard">
    Dashboard
  </Link>
  ...
  <Routes>
    <Route path="/configuration">
      <Route path="configure" element={<Configuration />} />
      <Route index element={<SummaryPage />} />
    </Route>
    <Route path="/dashboard" element={<Dashboard />} />
    <Route path="/appointments" element={<Appointments />} />
    <Route path="/" element={<Navigate replace to="/configuration" />} />
    <Route path="*" element={<NotFound />} />
  </Routes>
</HashRouter>

There mostly seems to be a misunderstanding with how the basename prop is applied in the router, specifically the HashRouter. With the HashRouter the basename prop is a value that is applied against the paths the app is handling, not against the domain path where the app is served/running.

Example:

<HashRouter basename="/admin">
  <Link to="/dashboard" className="link"> // renders <a href="#/admin/dashboard">
    Dashboard
  </Link>
  ...
  <Routes>
    <Route path="/configuration">
      <Route path="configure" element={<Configuration />} />
      <Route index element={<SummaryPage />} />
    </Route>
    <Route path="/dashboard" element={<Dashboard />} />
    <Route path="/appointments" element={<Appointments />} />
    <Route path="/" element={<Navigate replace to="/configuration" />} />
    <Route path="*" element={<NotFound />} />
  </Routes>
</HashRouter>

In other words, the basename prop value is applied to the URL hash and not the URL path, i.e. it's applied to everything after the hash.

mysite.com/someSubdomain/#/admin   /something / ... more nested paths
|--domain-|--subdomain--|#|--------------hash-----------------|
|         |             | |basename| app path | ... app subpaths

If you are wanting the "/admin" to show up prior to the hash, then this is part of where the entire app is deployed to and served up from. In this case the app needs to be deployed to mysite.com in a "/admin" subdirectory. You also won't need to specify the basename="/admin" if you don't want an additional "/admin" to show up in the app's routing.

mysite.com/admin/#/something

...

<HashRouter>
  <Link to="/dashboard" className="link"> // renders <a href="#/dashboard">
    Dashboard
  </Link>
  ...
  <Routes>
    <Route path="/configuration">
      <Route path="configure" element={<Configuration />} />
      <Route index element={<SummaryPage />} />
    </Route>
    <Route path="/dashboard" element={<Dashboard />} />
    <Route path="/appointments" element={<Appointments />} />
    <Route path="/" element={<Navigate replace to="/configuration" />} />
    <Route path="*" element={<NotFound />} />
  </Routes>
</HashRouter>

React Router Router Dom V6 Hashrouter basename无法正常工作

甜警司 2025-02-18 17:11:32

我设法弄清楚了。可能不是最好的解决方案或最清洁的解决方案,但它起作用。

希望这对与Google PageSpeed API和R一起工作的其他人有帮助。


library(httr)
library(tidyverse)
library(tidyr)
library(purrr)
library(magrittr)
library(ggplot2)
library(reshape)

#URL to submit GET request to
url <- "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://www.google.com/"


# GET request returned as list
raw_list <- url %>% 
  httr::GET() %>% 
  httr::content()



#turning the list into a dataframe 
df_pagespeed <- as.data.frame(do.call(rbind, raw_list))

df_all_audit <- df_pagespeed["lighthouseResult", "audits"]

df_all_audit <- as.data.frame(do.call(rbind, df_all_audit))


#df for meaningful paint 
df_first_meaningful_paint <- df_all_audit["lighthouseResult", "first-meaningful-paint"]

df_first_meaningful_paint <- as.data.frame(do.call(rbind, df_first_meaningful_paint))

df_first_meaningful_paint <- df_first_meaningful_paint$numericValue[1]



#df for largest content paint
df_largest_content_paint <- df_all_audit["lighthouseResult", "largest-contentful-paint"]

df_largest_content_paint <- as.data.frame(do.call(rbind, df_largest_content_paint))

df_largest_content_paint <- df_largest_content_paint$numericValue[1]



#df for total-blocking time
df_total_blocking_time <- df_all_audit["lighthouseResult", "total-blocking-time"]

df_total_blocking_time <- as.data.frame(do.call(rbind, df_total_blocking_time))

df_total_blocking_time <- df_total_blocking_time$numericValue[1]


#df for total-blocking time
df_speed_index <- df_all_audit["lighthouseResult", "speed-index"]

df_speed_index <- as.data.frame(do.call(rbind, df_speed_index ))

df_speed_index  <- df_speed_index$numericValue[1]



#df for content paint 
df_first_content_paint <- df_all_audit["lighthouseResult", "first-contentful-paint"]

df_first_content_paint <- as.data.frame(do.call(rbind, df_first_content_paint))

df_first_content_paint <- df_first_content_paint$numericValue[1]


#df for cumulative layout shift 
df_cumulative_shift <- df_all_audit["lighthouseResult", "cumulative-layout-shift"]

df_cumulative_shift <- as.data.frame(do.call(rbind, df_cumulative_shift))

df_cumulative_shift <- df_cumulative_shift$numericValue[1]



#df for server response time
df_server_response_time <- df_all_audit["lighthouseResult", "server-response-time"]

df_server_response_time<- as.data.frame(do.call(rbind, df_server_response_time))

df_server_response_time <- df_server_response_time$numericValue[1]



now <- Sys.time()
time <- data.frame(now)


#put all data frames into list
df_list <- bind_cols(time, df_first_content_paint, df_first_meaningful_paint, df_largest_content_paint, df_total_blocking_time, df_speed_index, df_cumulative_shift, df_server_response_time)

# renaming columns in dataframe
names(df_list)[1] <- "time"
names(df_list)[2] <- "first_content_paint"
names(df_list)[3] <- "first_meaningful_paint"
names(df_list)[4] <- "largest_content_paint"
names(df_list)[5] <- "total_blocking_time"
names(df_list)[6] <- "speed_index"
names(df_list)[7] <- "cumulative_shift"
names(df_list)[8] <- "server_response_time"

#assigning data to df_pagespeed_new
df_pagespeed_new <- df_list

# loading in old pagespeed file
df_pagespeed_old <- read_csv("pagespeed.csv")

#adding additional row to df page speed 
total <- rbind(df_pagespeed_old, df_pagespeed_new)

#writing the new new dataframe (larger more rows to dataframe)
write.csv(total,"pagespeed.csv", row.names = FALSE)


#plotting the graph
p <- ggplot()+
  geom_line(data=total,aes(y=first_content_paint,x= time,colour="first_content_paint"),size=1 )+
  geom_line(data=total,aes(y=largest_content_paint,x= time,colour="largest_content_paint"),size=1 )+
  geom_line(data=total,aes(y=total_blocking_time,x= time,colour="total_blocking_time"),size=1 )+
  geom_line(data=total,aes(y=speed_index,x= time,colour="speed_index"),size=1 )+
  geom_line(data=total,aes(y=cumulative_shift,x= time,colour="cumulative_shift"),size=1 )+
  geom_line(data=total,aes(y=server_response_time,x= time,colour="server_response_time"),size=1) +
  scale_color_manual(name = "Speed Metrics", values = c("first_content_paint" = "#008080", "largest_content_paint" = "#58508d", "total_blocking_time" = "#bc5090", "speed_index" = "#ff6361", "cumulative_shift" = "#ffa600", "server_response_time" = "#003f5c")) +
  xlab("Time & Date") +
  scale_y_continuous("Loadtime (milliseconds)") + 
  labs(title="www.google.com Page Speed Metrics")+ 
  theme(plot.title=element_text(hjust=0.5))

p + theme_classic() # Classic theme

I managed to figure it out. Probably not the best solution or cleanest, but it works.

Hopefully this helps someone else out, who is working with the Google Pagespeed API and R.


library(httr)
library(tidyverse)
library(tidyr)
library(purrr)
library(magrittr)
library(ggplot2)
library(reshape)

#URL to submit GET request to
url <- "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://www.google.com/"


# GET request returned as list
raw_list <- url %>% 
  httr::GET() %>% 
  httr::content()



#turning the list into a dataframe 
df_pagespeed <- as.data.frame(do.call(rbind, raw_list))

df_all_audit <- df_pagespeed["lighthouseResult", "audits"]

df_all_audit <- as.data.frame(do.call(rbind, df_all_audit))


#df for meaningful paint 
df_first_meaningful_paint <- df_all_audit["lighthouseResult", "first-meaningful-paint"]

df_first_meaningful_paint <- as.data.frame(do.call(rbind, df_first_meaningful_paint))

df_first_meaningful_paint <- df_first_meaningful_paint$numericValue[1]



#df for largest content paint
df_largest_content_paint <- df_all_audit["lighthouseResult", "largest-contentful-paint"]

df_largest_content_paint <- as.data.frame(do.call(rbind, df_largest_content_paint))

df_largest_content_paint <- df_largest_content_paint$numericValue[1]



#df for total-blocking time
df_total_blocking_time <- df_all_audit["lighthouseResult", "total-blocking-time"]

df_total_blocking_time <- as.data.frame(do.call(rbind, df_total_blocking_time))

df_total_blocking_time <- df_total_blocking_time$numericValue[1]


#df for total-blocking time
df_speed_index <- df_all_audit["lighthouseResult", "speed-index"]

df_speed_index <- as.data.frame(do.call(rbind, df_speed_index ))

df_speed_index  <- df_speed_index$numericValue[1]



#df for content paint 
df_first_content_paint <- df_all_audit["lighthouseResult", "first-contentful-paint"]

df_first_content_paint <- as.data.frame(do.call(rbind, df_first_content_paint))

df_first_content_paint <- df_first_content_paint$numericValue[1]


#df for cumulative layout shift 
df_cumulative_shift <- df_all_audit["lighthouseResult", "cumulative-layout-shift"]

df_cumulative_shift <- as.data.frame(do.call(rbind, df_cumulative_shift))

df_cumulative_shift <- df_cumulative_shift$numericValue[1]



#df for server response time
df_server_response_time <- df_all_audit["lighthouseResult", "server-response-time"]

df_server_response_time<- as.data.frame(do.call(rbind, df_server_response_time))

df_server_response_time <- df_server_response_time$numericValue[1]



now <- Sys.time()
time <- data.frame(now)


#put all data frames into list
df_list <- bind_cols(time, df_first_content_paint, df_first_meaningful_paint, df_largest_content_paint, df_total_blocking_time, df_speed_index, df_cumulative_shift, df_server_response_time)

# renaming columns in dataframe
names(df_list)[1] <- "time"
names(df_list)[2] <- "first_content_paint"
names(df_list)[3] <- "first_meaningful_paint"
names(df_list)[4] <- "largest_content_paint"
names(df_list)[5] <- "total_blocking_time"
names(df_list)[6] <- "speed_index"
names(df_list)[7] <- "cumulative_shift"
names(df_list)[8] <- "server_response_time"

#assigning data to df_pagespeed_new
df_pagespeed_new <- df_list

# loading in old pagespeed file
df_pagespeed_old <- read_csv("pagespeed.csv")

#adding additional row to df page speed 
total <- rbind(df_pagespeed_old, df_pagespeed_new)

#writing the new new dataframe (larger more rows to dataframe)
write.csv(total,"pagespeed.csv", row.names = FALSE)


#plotting the graph
p <- ggplot()+
  geom_line(data=total,aes(y=first_content_paint,x= time,colour="first_content_paint"),size=1 )+
  geom_line(data=total,aes(y=largest_content_paint,x= time,colour="largest_content_paint"),size=1 )+
  geom_line(data=total,aes(y=total_blocking_time,x= time,colour="total_blocking_time"),size=1 )+
  geom_line(data=total,aes(y=speed_index,x= time,colour="speed_index"),size=1 )+
  geom_line(data=total,aes(y=cumulative_shift,x= time,colour="cumulative_shift"),size=1 )+
  geom_line(data=total,aes(y=server_response_time,x= time,colour="server_response_time"),size=1) +
  scale_color_manual(name = "Speed Metrics", values = c("first_content_paint" = "#008080", "largest_content_paint" = "#58508d", "total_blocking_time" = "#bc5090", "speed_index" = "#ff6361", "cumulative_shift" = "#ffa600", "server_response_time" = "#003f5c")) +
  xlab("Time & Date") +
  scale_y_continuous("Loadtime (milliseconds)") + 
  labs(title="www.google.com Page Speed Metrics")+ 
  theme(plot.title=element_text(hjust=0.5))

p + theme_classic() # Classic theme

在r中解开列表中的列表中的列表,

甜警司 2025-02-18 01:23:04

尝试一下

 ContextCompat.getColor(applicationContext,R.color.banner_regular)

Try this

 ContextCompat.getColor(applicationContext,R.color.banner_regular)

Android Resources.getColor()冻结代码

甜警司 2025-02-17 14:22:15

NX(v20.0.0)和Angular(V18.1.1)项目的解决方案,

如果您使用类似于下面的项目结构,并且想在Angular应用程序和共享库中配置SCSS,则是工作设置,这是一个工作设置。

项目结构

- apps
  - app1
    - src
      - app
        - app.component.scss
      - styles.scss
    - project.json
- libs
  - shared
    - styles
      - src
        - lib
          - base
            - _variables.scss
            - _mixins.scss
            - index.scss
          - material
            - _button.scss
            - index.scss
          - styles.scss
      - project.json
    - ui
      - src
        - lib
          - ui.component.scss

配置步骤:

  1. 在您的应用程序中更新project.json apps/app1/project.json < /code>)包括共享样式路径:

      {
      “目标”:{
        “建造”: {
          “ executor”:“@angular-devkit/build-angular:application”,
          “选项”: {
            “ Inlinestylanguage”:“ SCSS”,
            “资产”:[...],,
            “ stylepreprocessoroptions”:{
              “ includepaths”:[“ libs/shared/styles/src/lib”] //&lt;  - 确保此路径正确
            },,
            “样式”:[[
              “ node_modules/@angular/material/prebuilt-themes/azure-blue.css”,
              “ apps/app1/src/styles.scss”,
              “ libs/shared/styles/src/lib/styles.scss” //&lt;  - 在此处确保正确的路径
            这是给出的
          }
        }
      }
    }
     

  2. 在共享库中设置SCSS

    • 在共享库的SCSS文件中,转发必要的文件。例如:

      • libs/shared/styles/src/lib/base/index.scss.scss

         @forward'./ variables';
        @forward'./mixins';
         
      • libs/shared/styles/src/lib/材料/index.scss.scss

         @forward'./button';
         
      • libs/shared/styles/src/lib/styles.scss

         @forward'./base/index';
        @forward'./material/index';
         
  3. 在应用程序样式中引用SCSS变量和Mixins

    • 在您的全局样式中

        @ues'base/variables'as *;
      @USE'base/mixins'as *;
       


    • 同样,在您的组件样式中apps/app1/src/src/app/app.component.scss),使用相同的引用:

        @ues'base/variables'as *;
      @USE'base/mixins'as *;
       


  4. 同样,在您的 和其他共享库中的混音

    • 在您的 UI组件样式中

      @ues'base/variables'as *;
    @USE'base/mixins'as *;
     

Solution for Nx (v20.0.0) and Angular (v18.1.1) Project with SCSS Configuration

If you're working with a project structure similar to the one below and want to configure SCSS across your Angular apps and shared libraries, here's a working setup.

Project Structure:

- apps
  - app1
    - src
      - app
        - app.component.scss
      - styles.scss
    - project.json
- libs
  - shared
    - styles
      - src
        - lib
          - base
            - _variables.scss
            - _mixins.scss
            - index.scss
          - material
            - _button.scss
            - index.scss
          - styles.scss
      - project.json
    - ui
      - src
        - lib
          - ui.component.scss

Configuration Steps:

  1. Update the project.json in your application (apps/app1/project.json) to include the shared style paths:

    {
      "targets": {
        "build": {
          "executor": "@angular-devkit/build-angular:application",
          "options": {
            "inlineStyleLanguage": "scss",
            "assets": [...],
            "stylePreprocessorOptions": {
              "includePaths": ["libs/shared/styles/src/lib"]  // <-- Make sure this path is correct
            },
            "styles": [
              "node_modules/@angular/material/prebuilt-themes/azure-blue.css",
              "apps/app1/src/styles.scss",
              "libs/shared/styles/src/lib/styles.scss" // <-- Ensure correct path here as well
            ]
          }
        }
      }
    }
    
  2. Setting Up SCSS in the Shared Library:

    • In the shared library’s SCSS files, forward the necessary files. For instance:

      • libs/shared/styles/src/lib/base/index.scss:

        @forward './variables';
        @forward './mixins';
        
      • libs/shared/styles/src/lib/material/index.scss:

        @forward './button';
        
      • libs/shared/styles/src/lib/styles.scss:

        @forward './base/index';
        @forward './material/index';
        
  3. Referencing SCSS Variables and Mixins in Application Styles:

    • In your global styles (apps/app1/src/styles.scss), include the shared SCSS files:

      @use 'base/variables' as *;
      @use 'base/mixins' as *;
      
    • Similarly, in your component styles (apps/app1/src/app/app.component.scss), use the same references:

      @use 'base/variables' as *;
      @use 'base/mixins' as *;
      
  4. Referencing SCSS Variables and Mixins in other shared libraries:

    • In your ui component styles (libs/shared/ui/src/lib/ui.component.scss), use the same references:
    @use 'base/variables' as *;
    @use 'base/mixins' as *;
    

如何在我的NX Monorepo中的Libs之间共享sass样式?

甜警司 2025-02-17 08:30:52

最好使用控制字典完成此类操作。另外,无需编写添加,减去函数,因为它们都在 ocerator 模块中可用。

这简化了很大的重要性:

import operator

history = []

control = {
    '+': (operator.add, 'Add'),
    '-': (operator.sub, 'Subtract'),
    '*': (operator.mul, 'Multiply'),
    '/': (operator.truediv, 'Divide'),
    '^': (operator.pow, 'Power'),
    '%': (operator.mod, 'Remainder'),
    '#': (None, 'Terminate'),
    '
: (None, 'Reset'),
    '?': (None, 'History')
}

while True:
    for i, (k, v) in enumerate(control.items(), 1):
        print(f'{i}. {v[1]:<10}: {k} ')
    option = input(f'Choose option ({",".join(control)}): ')
    match option:
        case '#':
            break
        case '
:
            history = []
        case '?':
            print(*history, sep='\n')
        case _:
            if t := control.get(option):
                a = input('Input first value: ')
                b = input('Input second value: ')
                try:
                    r = t[0](float(a), float(b))
                    print(res := f'{a} {option} {b} = {r}')
                    history.append(res)
                except (ValueError, ZeroDivisionError) as e:
                    print(e)
            else:
                print('Invalid option\x07')

This sort of thing is best done using a control dictionary. Also, there's no need to write the add, subtract etc functions as they're all available in the operator module.

This simplifies matters considerably:

import operator

history = []

control = {
    '+': (operator.add, 'Add'),
    '-': (operator.sub, 'Subtract'),
    '*': (operator.mul, 'Multiply'),
    '/': (operator.truediv, 'Divide'),
    '^': (operator.pow, 'Power'),
    '%': (operator.mod, 'Remainder'),
    '#': (None, 'Terminate'),
    '
: (None, 'Reset'),
    '?': (None, 'History')
}

while True:
    for i, (k, v) in enumerate(control.items(), 1):
        print(f'{i}. {v[1]:<10}: {k} ')
    option = input(f'Choose option ({",".join(control)}): ')
    match option:
        case '#':
            break
        case '
:
            history = []
        case '?':
            print(*history, sep='\n')
        case _:
            if t := control.get(option):
                a = input('Input first value: ')
                b = input('Input second value: ')
                try:
                    r = t[0](float(a), float(b))
                    print(res := f'{a} {option} {b} = {r}')
                    history.append(res)
                except (ValueError, ZeroDivisionError) as e:
                    print(e)
            else:
                print('Invalid option\x07')

Python计算器,包括使用列表的历史记录检查

甜警司 2025-02-17 07:33:02

首先,计算机的IP和您连接到的设备的IP必须相同。例如,
192.168.2.20(您的PC)
192.168.2.10(设备)

您可以从网络连接中执行此操作。

然后,在连接部分,而不是本地主机,您必须键入设备的IP。如果您确定电缆连接并且网关正常工作,则可以无问题连接。

First of all, the ip of your computer and the ip of the device you are connected to must be the same. For example,
192.168.2.20 (your pc)
192.168.2.10 (device)

You can do this from the network connections.

Then in the connection section, instead of localhost, you must type the ip of the device. If you are sure of your cable connection and your gateway is working correctly, you can connect without any problems.

连接到Codesys中的目标设备

甜警司 2025-02-17 07:22:10

我制作了一件代码将文件资源管理器文件路径转换为python文件格式:

rawpath = input("PATH: ")
ds = "\\"

def CF(path):
    if ds in path:
        path = rawpath.replace("\\", "\\\"")
        rpath = repr(path).replace("\"", "")
        print(rpath)
        
CF(rawpath)

I made a piece of code to convert File Explorer file path into a python file format:

rawpath = input("PATH: ")
ds = "\\"

def CF(path):
    if ds in path:
        path = rawpath.replace("\\", "\\\"")
        rpath = repr(path).replace("\"", "")
        print(rpath)
        
CF(rawpath)

将带有变量转换为Python String的Windows路径的简便方法

甜警司 2025-02-17 06:48:46

正在遇到这个问题,测试长双打,las,我遇到了一个修复程序!您必须使用-d__use_mingw_ansi_stdio编译项目:

Jason Huntley@centurian/home/developer/dependerencies/python-2.7.3/test
$ gcc main.c

Jason Huntley@centurian/home/developer/dependerencies/python-2.7.3/test
$ A.EXE C = 0.000000

Jason Huntley@centurian/home/developer/dependerencies/python-2.7.3/test
$ gcc main.c -d__use_mingw_ansi_stdio

Jason Huntley@centurian/home/developer/dependerencies/python-2.7.3/test
$ A.EXE C = 42.000000

代码:

Jason Huntley@centurian /home/developer/dependencies/Python-2.7.3/test
$ cat main.c
#include <stdio.h>

int main(int argc, char **argv)
{
   long double c=42;

   c/3;

   printf("c=%Lf\n",c);

   return 0;
}

Was having this issue testing long doubles, and alas, I came across a fix! You have to compile your project with -D__USE_MINGW_ANSI_STDIO:

Jason Huntley@centurian /home/developer/dependencies/Python-2.7.3/test
$ gcc main.c

Jason Huntley@centurian /home/developer/dependencies/Python-2.7.3/test
$ a.exe c=0.000000

Jason Huntley@centurian /home/developer/dependencies/Python-2.7.3/test
$ gcc main.c -D__USE_MINGW_ANSI_STDIO

Jason Huntley@centurian /home/developer/dependencies/Python-2.7.3/test
$ a.exe c=42.000000

Code:

Jason Huntley@centurian /home/developer/dependencies/Python-2.7.3/test
$ cat main.c
#include <stdio.h>

int main(int argc, char **argv)
{
   long double c=42;

   c/3;

   printf("c=%Lf\n",c);

   return 0;
}

printf和长双人

甜警司 2025-02-16 21:04:41

请求格式在一行中 - 没有库,没有日期方法,只有正则是:

var d = (new Date()).toString().replace(/\S+\s(\S+)\s(\d+)\s(\d+)\s.*/,'$2-$1-$3');
// date will be formatted as "14-Oct-2015" (pass any date object in place of 'new Date()')

在我的测试中,这在主要浏览器(Chrome,Safari,firefox和ie。)中可靠地工作,如@ROBG所指出的,Date.prototype的输出。 ToString()是与实现有关的,因此对于国际或非浏览器实现,只需测试输出即可确保其在JavaScript引擎中正常工作。您甚至可以添加一些代码来测试字符串输出,并确保在进行正则替换之前,它与您的期望匹配。

Requested format in one line - no libraries and no Date methods, just regex:

var d = (new Date()).toString().replace(/\S+\s(\S+)\s(\d+)\s(\d+)\s.*/,'$2-$1-$3');
// date will be formatted as "14-Oct-2015" (pass any date object in place of 'new Date()')

In my testing, this works reliably in the major browsers (Chrome, Safari, Firefox and IE.) As @RobG pointed out, the output of Date.prototype.toString() is implementation-dependent, so for international or non-browser implementations, just test the output to be sure it works right in your JavaScript engine. You can even add some code to test the string output and make sure it's matching what you expect before you do the regex replace.

如何在JavaScript中格式化日期?

甜警司 2025-02-16 19:58:34

我真的不知道您是灰色部分的意思。
一般而言,网站由HTML Elements &lt; html&gt;组成。当您想更改元素的外观时,请使用链接到它的CSS文件&lt; link rel =“ stylesheet” href =“ style.css”/&gt;(在大多数情况下)
如果您知道什么是容器,则可以使用类似的内容编辑CSS文件:

container-you-are-speaking-of{
    background-color: white;
}

如果这没有帮助,我将需要一些额外的信息或至少有一些代码才能使用。
祝你有美好的一天

I don't really know what you mean by grey part.
Generally speaking, a website is composed of HTML elements <html> like this. When you want to change the look of an element you use the CSS file linked to it <link rel="stylesheet" href="style.css"/> (in most cases)
if you know what is the container you can edit the css file with something like this:

container-you-are-speaking-of{
    background-color: white;
}

if this was not helpful I will need some extra information or at least a bit of code to work with.
Have a good day

如何在我的网站上更改部分的背景颜色?

甜警司 2025-02-16 13:11:03

我能够调整ArmedWithTheword的代码来提出这一点。

import arcpy
mxd = arcpy.mapping.MapDocument(path_to_mxd)

fieldNames = ['name', 'date']
with arcpy.da.SearchCursor(WS, fieldNames) as sc:
 for row in sc:
    if(row[0]) is not None:
        field1Value = (row[0])
    if(row[0]) is None:
        field1Value = 'Null'
    if(row[1]) is not None:
        field2Value = (row[1])
    if(row[1]) is None:
        field2Value = 'Null'

fieldName = ['CTY_NAME']
with arcpy.da.SearchCursor(overview, fieldName) as sc:
 for row in sc:
    if(row[0]) is not None:
        field3Value = (row[0])
    if(row[0]) is None:
        field3Value = 'Null'



# Assign the attribute value to the layout text element
for textElem in arcpy.mapping.ListLayoutElements(mxd,'TEXT_ELEMENT'):
    if textElem.name == 'title':
        textElem.text = field1Value + " words"
    if textElem.name == 'subtitle':
        textElem.text = "WS -0"+ ID + " -more words"
    if textElem.name == 'city':
        textElem.text = city
    if textElem.name == 'county':
        textElem.text = field3Value
    if textElem.name == 'date':
        textElem.text = field2Value

I was able to tweak armedwiththeword's code to come up with this.

import arcpy
mxd = arcpy.mapping.MapDocument(path_to_mxd)

fieldNames = ['name', 'date']
with arcpy.da.SearchCursor(WS, fieldNames) as sc:
 for row in sc:
    if(row[0]) is not None:
        field1Value = (row[0])
    if(row[0]) is None:
        field1Value = 'Null'
    if(row[1]) is not None:
        field2Value = (row[1])
    if(row[1]) is None:
        field2Value = 'Null'

fieldName = ['CTY_NAME']
with arcpy.da.SearchCursor(overview, fieldName) as sc:
 for row in sc:
    if(row[0]) is not None:
        field3Value = (row[0])
    if(row[0]) is None:
        field3Value = 'Null'



# Assign the attribute value to the layout text element
for textElem in arcpy.mapping.ListLayoutElements(mxd,'TEXT_ELEMENT'):
    if textElem.name == 'title':
        textElem.text = field1Value + " words"
    if textElem.name == 'subtitle':
        textElem.text = "WS -0"+ ID + " -more words"
    if textElem.name == 'city':
        textElem.text = city
    if textElem.name == 'county':
        textElem.text = field3Value
    if textElem.name == 'date':
        textElem.text = field2Value

使用Arcpy从字段获取变量

甜警司 2025-02-16 12:01:39

使用变量作为国家代码,并将其分配给 initialCountryCode

String countryISOCode = 'IN';

对于国家代码文本样式,您可以使用。

dropdownTextStyle: TextStyle(),

完成代码。

 Container(
                      padding: EdgeInsets.all(20),
                      child: Column(
                        children: <Widget>[
                          Container(
                              child: IntlPhoneField(
                            showCountryFlag: false,
                            showDropdownIcon: false,
                            dropdownTextStyle: TextStyle(
                                color: Colors.grey,
                                fontFamily: 'DMSans',
                                fontSize: 25,
                                fontWeight: FontWeight.bold),
                            keyboardType: TextInputType.number,
                            style: TextStyle(
                                color: Colors.grey,
                                fontFamily: 'DMSans',
                                fontSize: 25,
                                fontWeight: FontWeight.bold),
                            decoration: InputDecoration(
                                counterText: '', border: InputBorder.none),
                            initialCountryCode: 'IN',
                            onChanged: (phone) {
                              print(phone.completeNumber);
                              print(phone.countryCode);
                              print(phone.number);
                            },
                          )),
                        ],
                      )),

Use a variable for country code and assign it to initialCountryCode.

String countryISOCode = 'IN';

For country code text style, you can use.

dropdownTextStyle: TextStyle(),

Complete code.

 Container(
                      padding: EdgeInsets.all(20),
                      child: Column(
                        children: <Widget>[
                          Container(
                              child: IntlPhoneField(
                            showCountryFlag: false,
                            showDropdownIcon: false,
                            dropdownTextStyle: TextStyle(
                                color: Colors.grey,
                                fontFamily: 'DMSans',
                                fontSize: 25,
                                fontWeight: FontWeight.bold),
                            keyboardType: TextInputType.number,
                            style: TextStyle(
                                color: Colors.grey,
                                fontFamily: 'DMSans',
                                fontSize: 25,
                                fontWeight: FontWeight.bold),
                            decoration: InputDecoration(
                                counterText: '', border: InputBorder.none),
                            initialCountryCode: 'IN',
                            onChanged: (phone) {
                              print(phone.completeNumber);
                              print(phone.countryCode);
                              print(phone.number);
                            },
                          )),
                        ],
                      )),

如何更改国家代码的字体?我不是在UI中更改Country Code字体样式的安倍。我正在使用“ intl_phone_field 3.1.0”这个包

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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