<legend id='fphe1'><style id='fphe1'><dir id='fphe1'><q id='fphe1'></q></dir></style></legend>

    <small id='fphe1'></small><noframes id='fphe1'>

    <i id='fphe1'><tr id='fphe1'><dt id='fphe1'><q id='fphe1'><span id='fphe1'><b id='fphe1'><form id='fphe1'><ins id='fphe1'></ins><ul id='fphe1'></ul><sub id='fphe1'></sub></form><legend id='fphe1'></legend><bdo id='fphe1'><pre id='fphe1'><center id='fphe1'></center></pre></bdo></b><th id='fphe1'></th></span></q></dt></tr></i><div id='fphe1'><tfoot id='fphe1'></tfoot><dl id='fphe1'><fieldset id='fphe1'></fieldset></dl></div>
    <tfoot id='fphe1'></tfoot>
        • <bdo id='fphe1'></bdo><ul id='fphe1'></ul>

        是否可以在不使用变量的情况下解包元组?

        Is it possible to unpack a tuple without using variables?(是否可以在不使用变量的情况下解包元组?)
      1. <legend id='8H8HU'><style id='8H8HU'><dir id='8H8HU'><q id='8H8HU'></q></dir></style></legend>

        <small id='8H8HU'></small><noframes id='8H8HU'>

          • <bdo id='8H8HU'></bdo><ul id='8H8HU'></ul>
            <tfoot id='8H8HU'></tfoot>
              <i id='8H8HU'><tr id='8H8HU'><dt id='8H8HU'><q id='8H8HU'><span id='8H8HU'><b id='8H8HU'><form id='8H8HU'><ins id='8H8HU'></ins><ul id='8H8HU'></ul><sub id='8H8HU'></sub></form><legend id='8H8HU'></legend><bdo id='8H8HU'><pre id='8H8HU'><center id='8H8HU'></center></pre></bdo></b><th id='8H8HU'></th></span></q></dt></tr></i><div id='8H8HU'><tfoot id='8H8HU'></tfoot><dl id='8H8HU'><fieldset id='8H8HU'></fieldset></dl></div>

                  <tbody id='8H8HU'></tbody>
                1. 本文介绍了是否可以在不使用变量的情况下解包元组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在程序中的路径上使用 os.path.split() 函数来获取文件的文件名和路径名,然后将它们传递给另一个方法,但我目前的解决方案似乎相当难看:

                  I'm using the os.path.split() function on a path in my program to get the filename and pathname of a file then passing them into another method, but my current solution seems rather ugly:

                  path = os.path.split(somefile)
                  some_class(path[0], path[1])
                  

                  是否可以在调用 some_class 时以更简洁的方式解包路径元组?比如:

                  Is it possible to unpack the path tuple in a cleaner way within the call to some_class? Something like:

                  some_class(os.path.split(somefile).unpack())
                  

                  或者我应该以另一种方式来解决这个问题?也许是一种更 Pythonic 的方式?

                  Or should I simply be going about this another way? Maybe a more pythonic way?

                  推荐答案

                  是的,Python 有 参数列表解包.试试这个:

                  Yes, Python has argument list unpacking. Try this:

                  some_class(*os.path.split(somefile))
                  

                  这篇关于是否可以在不使用变量的情况下解包元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                    <tbody id='nvPbf'></tbody>

                  • <legend id='nvPbf'><style id='nvPbf'><dir id='nvPbf'><q id='nvPbf'></q></dir></style></legend>
                      <bdo id='nvPbf'></bdo><ul id='nvPbf'></ul>

                      <tfoot id='nvPbf'></tfoot>
                      <i id='nvPbf'><tr id='nvPbf'><dt id='nvPbf'><q id='nvPbf'><span id='nvPbf'><b id='nvPbf'><form id='nvPbf'><ins id='nvPbf'></ins><ul id='nvPbf'></ul><sub id='nvPbf'></sub></form><legend id='nvPbf'></legend><bdo id='nvPbf'><pre id='nvPbf'><center id='nvPbf'></center></pre></bdo></b><th id='nvPbf'></th></span></q></dt></tr></i><div id='nvPbf'><tfoot id='nvPbf'></tfoot><dl id='nvPbf'><fieldset id='nvPbf'></fieldset></dl></div>
                        1. <small id='nvPbf'></small><noframes id='nvPbf'>