小编ess*_*sse的帖子

如何在 dotty 中解压元组中的元素类型?

假设我有一个类定义为:

case class Box[A](a: A)
Run Code Online (Sandbox Code Playgroud)

我想编写一个通用方法,(Box[A1](a1), .., Box[An](an))将元组解包为(a1, .., an)类型为 的元组(A1, .., An)

我试过Match Types没有运气:

scala> type Unpack[Bs <: Tuple] <: Tuple = Bs match {
     |   case Unit => Unit
     |   case Box[a] *: bs => a *: Unpack[bs]
     | }

scala> def unpack[Bs <: Tuple](bs: Bs): Unpack[Bs] = bs match {
     |   case () => ()
     |   case Box(a) *: as => a *: unpack(as)
     | }
2 |  case …
Run Code Online (Sandbox Code Playgroud)

scala dotty scala-3

6
推荐指数
1
解决办法
407
查看次数

python 3.9 之后输入提示的最佳实践是什么?

python3.9之后,至少有三种方式使用输入提示。以内置集合set为例:

# way 1
def f(s: set[str]) -> str:
    pass

# way 2
def f(s: typing.Set[str]) -> str:
    pass

# way 3
def f(s: collections.abc.Set[str]) -> str:
    pass

# way 3': or arguable collections.abc.MutableSet vs collections.abc.Set
def f(s: collections.abc.MutableSet[str]) -> str:
    pass
Run Code Online (Sandbox Code Playgroud)

typing此外,对于某些抽象类型,和中有两个版本collections.abcMapping例如:

def f(m: typing.Mapping[str, int]) -> int:
    pass

def f(m: collections.abc.Mapping[str, int]) -> int:
    pass
Run Code Online (Sandbox Code Playgroud)

根据Python 之禅

应该有一种——最好只有一种——明显的方法来做到这一点。

我很困惑哪一个最好?

python type-hinting python-3.x

6
推荐指数
1
解决办法
2107
查看次数

Java 中的 `x &gt; 0` 和 `x &gt; 0.0D` 之间有什么区别吗?

以下代码来自Math.javajava标准库:

public static double abs(double a) {
    return (a <= 0.0D) ? 0.0D - a : a;
}
Run Code Online (Sandbox Code Playgroud)

我有以下问题:

  1. 代码是否等于 return (a <= 0) ? 0.0D - a : a;
  2. 此外,代码是否等于 return (a <= 0) ? - a : a;

谢谢你的帮助!

java floating-point

6
推荐指数
1
解决办法
75
查看次数

如何设置pandas的read_xml的`xpath`?

我想从其部分的xml 文件Component中解析数据:

\n
<Component>\n  <UnderlyingSecurityID>300001</UnderlyingSecurityID>\n  <UnderlyingSecurityIDSource>102</UnderlyingSecurityIDSource>\n  <UnderlyingSymbol>\xe7\x89\xb9\xe9\x94\x90\xe5\xbe\xb7</UnderlyingSymbol>\n  <ComponentShare>300.00</ComponentShare>\n  <SubstituteFlag>1</SubstituteFlag>\n  <PremiumRatio>0.25000</PremiumRatio>\n  <CreationCashSubstitute>0.0000</CreationCashSubstitute>\n  <RedemptionCashSubstitute>0.0000</RedemptionCashSubstitute>\n</Component>\n<Component>\n  <UnderlyingSecurityID>300003</UnderlyingSecurityID>\n  <UnderlyingSecurityIDSource>102</UnderlyingSecurityIDSource>\n  <UnderlyingSymbol>\xe4\xb9\x90\xe6\x99\xae\xe5\x8c\xbb\xe7\x96\x97</UnderlyingSymbol>\n  <ComponentShare>600.00</ComponentShare>\n  <SubstituteFlag>1</SubstituteFlag>\n  <PremiumRatio>0.25000</PremiumRatio>\n  <CreationCashSubstitute>0.0000</CreationCashSubstitute>\n  <RedemptionCashSubstitute>0.0000</RedemptionCashSubstitute>\n</Component>\n
Run Code Online (Sandbox Code Playgroud)\n

我已经安装了最新版本的 lxml 和 pandas,尝试了以下代码但没有成功。

\n
Python 3.9.4 (tags/v3.9.4:1f2e308, Apr  6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)]\nType \'copyright\', \'credits\' or \'license\' for more information\nIPython 7.25.0 -- An enhanced Interactive Python. Type \'?\' for help.\n\nIn [1]: import pandas as pd\n\nIn [2]: pd.__version__\nOut[2]: \'1.3.0\'\n\nIn [3]: xml = pd.read_xml(\'https://www.huaan.com.cn/etf/159949/etffiledownload.jsp?etffilename=pcf_159949_20210707.xml\', xpath=\'//component\')\n---------------------------------------------------------------------------\nValueError                                Traceback (most recent call last)\n<ipython-input-3-67d228028cc9> in <module>\n----> 1 xml …
Run Code Online (Sandbox Code Playgroud)

python xml pandas

5
推荐指数
1
解决办法
7026
查看次数

标签 统计

python ×2

dotty ×1

floating-point ×1

java ×1

pandas ×1

python-3.x ×1

scala ×1

scala-3 ×1

type-hinting ×1

xml ×1